diff options
-rw-r--r-- | runtime/tests/ChangeLog | 7 | ||||
-rw-r--r-- | runtime/tests/maps/README | 2 | ||||
-rw-r--r-- | runtime/tests/maps/ii.c | 1 | ||||
-rw-r--r-- | runtime/tests/maps/ii2.c | 96 | ||||
-rw-r--r-- | runtime/tests/maps/iiss.c | 1 | ||||
-rw-r--r-- | runtime/tests/maps/iiss2.c | 43 | ||||
-rw-r--r-- | runtime/tests/maps/is.c | 1 | ||||
-rw-r--r-- | runtime/tests/maps/is2.c | 119 | ||||
-rw-r--r-- | runtime/tests/maps/isx.c (renamed from runtime/tests/maps/ist.c) | 0 | ||||
-rw-r--r-- | runtime/tests/maps/isx2.c | 41 | ||||
-rw-r--r-- | runtime/tests/maps/map.test | 461 | ||||
-rw-r--r-- | runtime/tests/maps/map_format2.c | 72 | ||||
-rw-r--r-- | runtime/tests/maps/setadd.c | 213 | ||||
-rw-r--r-- | runtime/tests/maps/si.c | 1 | ||||
-rw-r--r-- | runtime/tests/maps/si2.c | 125 |
15 files changed, 1180 insertions, 3 deletions
diff --git a/runtime/tests/ChangeLog b/runtime/tests/ChangeLog index d18bfacf..91e6bb10 100644 --- a/runtime/tests/ChangeLog +++ b/runtime/tests/ChangeLog @@ -1,3 +1,10 @@ +2005-10-26 Martin Hunt <hunt@redhat.com> + + * maps/map.test: Update with results for new tests. + * maps/*2.c: Tests for the new API. + * maps/ist.c: Renamed isx.c. + * maps/setadd.c: New test of adding and setting. + 2005-09-23 Martin Hunt <hunt@redhat.com> * maps/map.test: Add sort results. diff --git a/runtime/tests/maps/README b/runtime/tests/maps/README index 02406464..3ff31703 100644 --- a/runtime/tests/maps/README +++ b/runtime/tests/maps/README @@ -1,2 +1,4 @@ +Read ../README first! + The *.c files test associative arrays (maps). "make tests" to run. diff --git a/runtime/tests/maps/ii.c b/runtime/tests/maps/ii.c index 2eb830cc..bae6a3ad 100644 --- a/runtime/tests/maps/ii.c +++ b/runtime/tests/maps/ii.c @@ -10,6 +10,7 @@ int main () { MAP map = _stp_map_new_int64(4, INT64); + map->wrap = 1; /* map[1] = 2 */ _stp_map_key_int64 (map, 1); diff --git a/runtime/tests/maps/ii2.c b/runtime/tests/maps/ii2.c new file mode 100644 index 00000000..51b0d766 --- /dev/null +++ b/runtime/tests/maps/ii2.c @@ -0,0 +1,96 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of int64 */ +#define VALUE_TYPE INT64 +#define KEY1_TYPE INT64 +#include "map-gen.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_ii(4); + int64_t x; + + dbug("Hello World\n"); + + /* map[1] = 2 */ + _stp_map_set_ii(map, 1, 2); + x = _stp_map_get_ii(map, 1); + printf ("map[1]=%lld\n", x); + + /* map[3] = 4 */ + _stp_map_set_ii(map, 3, 4); + _stp_map_print(map,"map[%1d] = %d"); + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + _stp_map_set_ii(0,1,100); + _stp_map_set_ii(map,0,0); + _stp_map_set_ii(map,100,0); + _stp_map_print(map,"map[%1d] = %d"); + + /* check that unset values are 0 */ + printf ("%lld (should be 0)\n", _stp_map_get_ii(map, 5)); + + /* map[5] = 6 */ + _stp_map_set_ii(map, 5, 6); + _stp_map_print(map,"map[%1d] = %d"); + + /* set wrap */ + map->wrap = 1; + /* add 4 new entries, pushing the others out */ + int i, res; + for (i = 6; i < 10; i++) { + res = _stp_map_set_ii (map, i, 100 + i); + if (res) + printf("WARNING: During wrap test, got result of %d when expected 0\n", res); + } + _stp_map_print(map,"map[%1d] = %d"); + + /* turn off wrap and repeat */ + map->wrap = 0; + for (i = 16; i < 20; i++) { + res = _stp_map_set_ii (map, i, 100 + i); + if (res != -1) + printf("WARNING: During wrap test, got result of %d when expected -1\n", res); + } + + map->wrap = 1; + + /* 5, 382, 526, and 903 all hash to the same value (23) */ + /* use them to test the hash chain */ + _stp_map_set_ii (map, 5, 1005); + _stp_map_set_ii (map, 382, 1382); + _stp_map_set_ii (map, 526, 1526); + _stp_map_set_ii (map, 903, 1903); + _stp_map_print(map,"map[%1d] = %d"); + + + /* now delete all 4 nodes, one by one */ + _stp_map_set_ii (map, 382, 0); + _stp_map_print(map,"map[%1d] = %d"); + + _stp_map_set_ii (map, 5, 0); + _stp_map_print(map,"map[%1d] = %d"); + + _stp_map_set_ii (map, 903, 0); + _stp_map_print(map,"map[%1d] = %d"); + + _stp_map_set_ii (map, 526, 0); + _stp_map_print(map,"map[%1d] = %d"); + + /* finally check clearing the map */ + for (i = 33; i < 77; i+=11) + _stp_map_set_ii (map, i, 100*i+i); + + _stp_map_print(map,"map[%1d] = %d"); + + _stp_map_clear(map); + _stp_map_print(map,"map[%1d] = %d"); + _stp_map_set_ii (map, 1970, 1799); + _stp_map_print(map,"map[%1d] = %d"); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/iiss.c b/runtime/tests/maps/iiss.c index 3321a329..218a0806 100644 --- a/runtime/tests/maps/iiss.c +++ b/runtime/tests/maps/iiss.c @@ -12,6 +12,7 @@ int main () { MAP map = _stp_map_new_int64_int64_str(4, STRING); + map->wrap = 1; _stp_map_key_int64_int64_str (map, 1,2,"Ohio"); _stp_map_set_str (map, "Columbus" ); diff --git a/runtime/tests/maps/iiss2.c b/runtime/tests/maps/iiss2.c new file mode 100644 index 00000000..56c3d186 --- /dev/null +++ b/runtime/tests/maps/iiss2.c @@ -0,0 +1,43 @@ +#include "runtime.h" + +/* test of maps with keys of int64,int64,string and value of string */ +#define VALUE_TYPE STRING +#define KEY1_TYPE INT64 +#define KEY2_TYPE INT64 +#define KEY3_TYPE STRING +#include "map-gen.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_iiss(4); + map->wrap = 1; + + _stp_map_set_iiss (map, 1,2,"Ohio", "Columbus" ); + _stp_map_set_iiss (map, 3,4,"California", "Sacramento" ); + _stp_map_set_iiss (map, 5,6,"Washington", "Seattle" ); + _stp_map_set_iiss (map, 7,8,"Oregon", "Salem" ); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_set_iiss (map, -9,-10,"Nevada", "Carson City" ); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_set_iiss (map, 5,6,"Washington", "Olymp" ); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_add_iiss (map, 5,6,"Washington", "is" ); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_set_iiss (map, 5,6,"Washington", "Olympia" ); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_set_iiss (map, -9,-10,"Nevada", 0); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_set_iiss(map, 0,0,"", ""); + _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/is.c b/runtime/tests/maps/is.c index 8bdc6591..6b4f22b7 100644 --- a/runtime/tests/maps/is.c +++ b/runtime/tests/maps/is.c @@ -10,6 +10,7 @@ int main () { MAP map = _stp_map_new_int64(4, STRING); + map->wrap = 1; /* map[1] = one */ _stp_map_key_int64 (map, 1); diff --git a/runtime/tests/maps/is2.c b/runtime/tests/maps/is2.c new file mode 100644 index 00000000..b6537f06 --- /dev/null +++ b/runtime/tests/maps/is2.c @@ -0,0 +1,119 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of string */ +#define KEY1_TYPE INT64 +#define VALUE_TYPE STRING +#include "map-gen.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_is(4); + map->wrap = 1; + + /* map[1] = one */ + _stp_map_set_is (map, 1, "one"); + + printf ("map[1]=%s\n", _stp_map_get_is(map,1)); + _stp_map_print(map,"map[%1d] = %s"); + + /* map[3] = "three" */ + _stp_map_set_is (map, 3, "three"); + _stp_map_print(map,"map[%1d] = %s"); + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + _stp_map_set_is(0,1,"foobar"); + _stp_map_set_is(map,0,0); + _stp_map_set_is(map,100,0); + _stp_map_print(map,"map[%1d] = %s"); + + /* create and delete a key */ + _stp_map_set_is (map, 1024, "2048"); + _stp_map_set_is (map, 1024, 0); + _stp_map_print(map,"map[%1d] = %s"); + + /* create and delete a key again*/ + _stp_map_set_is (map, 1024, "2048"); + _stp_map_print(map,"map[%1d] = %s"); + _stp_map_set_is (map, 1024, 0); + _stp_map_print(map,"map[%1d] = %s"); + + + /* check that unset values are 0 */ + if (_stp_map_get_is(map, 5)) + printf("ERROR: unset key has nonzero value\n"); + + /* map[5] = "five" */ + _stp_map_set_is (map, 5, "five"); + _stp_map_print(map,"map[%1d] = %s"); + + /* test empty string */ + _stp_map_set_is (map, 5, ""); + _stp_map_print(map,"map[%1d] = %s"); + + + /* add 4 new entries, pushing the others out */ + int i; + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf(buf, "value of %d", i); + _stp_map_set_is (map, i, buf); + } + _stp_map_print(map,"map[%1d] = %s"); + + /* 5, 382, 526, and 903 all hash to the same value (23) */ + /* use them to test the hash chain */ + _stp_map_set_is (map, 5, "1005"); + _stp_map_set_is (map, 382, "1382"); + _stp_map_set_is (map, 526, "1526"); + _stp_map_set_is (map, 903, "1903"); + + _stp_map_print(map,"map[%1d] = %s"); + + /* now delete all 4 nodes, one by one */ + _stp_map_set_is (map, 382, 0); + _stp_map_print(map,"map[%1d] = %s"); + + _stp_map_set_is (map, 5, 0); + _stp_map_print(map,"map[%1d] = %s"); + + _stp_map_set_is (map, 903, 0); + _stp_map_print(map,"map[%1d] = %s"); + + _stp_map_set_is (map, 526, 0); + _stp_map_print(map,"map[%1d] = %s"); + + /* test overflow errors */ + map->wrap = 0; + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf(buf, "value of %d", i); + _stp_map_set_is (map, i, buf); + } + + for (i = 6; i < 10; i++) + { + char buf[32]; + int res; + sprintf(buf, "new value of %d", i); + res = _stp_map_set_is (map, i, buf); + if (res) + printf("WARNING: During wrap test, got result of %d when expected 0\n", res); + } + for (i = 16; i < 20; i++) + { + char buf[32]; + int res; + sprintf(buf, "BAD value of %d", i); + res = _stp_map_set_is (map, i, buf); + if (res != -1) + printf("WARNING: During wrap test, got result of %d when expected -1\n", res); + } + _stp_map_print(map,"map[%1d] = %s"); + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/ist.c b/runtime/tests/maps/isx.c index 2418a20c..2418a20c 100644 --- a/runtime/tests/maps/ist.c +++ b/runtime/tests/maps/isx.c diff --git a/runtime/tests/maps/isx2.c b/runtime/tests/maps/isx2.c new file mode 100644 index 00000000..9003f522 --- /dev/null +++ b/runtime/tests/maps/isx2.c @@ -0,0 +1,41 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of stat */ +#define VALUE_TYPE STAT +#define KEY1_TYPE INT64 +#include "map-gen.c" +#include "map.c" + +int main () +{ + int i, j; + MAP map = _stp_map_new_ix (4, HIST_LINEAR, 0, 100, 10 ); + MAP map2 = _stp_map_new_ix(4, HIST_LOG, 11); + + for (i = 0; i < 100; i++) + for (j = 0; j <= i*10 ; j++ ) + _stp_map_add_ix (map, 3, i); + + for (i = 0; i < 10; i++) + for (j = 0; j < 10 ; j++ ) + _stp_map_add_ix (map, 2, j * i ); + + for (i = 0; i < 100; i += 10) + for (j = 0; j < i/10 ; j++ ) + _stp_map_add_ix (map, 1, i); + + for (i = 0; i < 128; i++) + for (j = 0; j < 128 ; j++ ) + _stp_map_add_ix (map2, 1, i); + + for (i = 0; i < 1024; i++) + for (j = 0; j < 1024 ; j++ ) + _stp_map_add_ix (map2, 2, i); + + _stp_map_print (map, "map[%1d] = count:%C sum:%S avg:%A min:%m max:%M\n%H"); + _stp_map_print (map2, "map2[%1d] = count:%C sum:%S avg:%A min:%m max:%M\n%H"); + + _stp_map_del (map); + _stp_map_del (map2); + return 0; +} diff --git a/runtime/tests/maps/map.test b/runtime/tests/maps/map.test index 118cb75e..d827a207 100644 --- a/runtime/tests/maps/map.test +++ b/runtime/tests/maps/map.test @@ -9,6 +9,7 @@ set MPATH "/lib/modules/[exec uname -r]/build/include/asm/mach-default" set PATH "../../user" test ii {Test of int64 keys and int64 values} -setup { + puts "gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test ii.c" exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test ii.c } -body { exec ./test @@ -165,8 +166,81 @@ map[526] = 1526 } -test ist {Test of int64 keys and stat values} -setup { - exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test ist.c +test isx {Test of int64 keys and stat values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test isx.c +} -body { + exec ./test +} -result {map[3] = count:49600 sum:3288450 avg:66 min:0 max:99 +value |-------------------------------------------------- count + 0 |@@ 460 + 10 |@@@@@@@ 1460 + 20 |@@@@@@@@@@@@ 2460 + 30 |@@@@@@@@@@@@@@@@@@ 3460 + 40 |@@@@@@@@@@@@@@@@@@@@@@@ 4460 + 50 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 5460 + 60 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6460 + 70 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 7460 + 80 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8460 + 90 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9460 + +map[2] = count:100 sum:2025 avg:20 min:0 max:81 +value |-------------------------------------------------- count + 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 + 10 |@@@@@@@@@@@@@@@@@ 17 + 20 |@@@@@@@@@@@@@ 13 + 30 |@@@@@@@@@ 9 + 40 |@@@@@@@@@ 9 + 50 |@@@@ 4 + 60 |@@@ 3 + 70 |@@ 2 + 80 |@ 1 + 90 | 0 + +map[1] = count:45 sum:2850 avg:63 min:10 max:90 +value |-------------------------------------------------- count + 0 | 0 + 10 |@ 1 + 20 |@@ 2 + 30 |@@@ 3 + 40 |@@@@ 4 + 50 |@@@@@ 5 + 60 |@@@@@@ 6 + 70 |@@@@@@@ 7 + 80 |@@@@@@@@ 8 + 90 |@@@@@@@@@ 9 + + +map2[1] = count:16384 sum:1040384 avg:63 min:0 max:127 +value |-------------------------------------------------- count + 0 | 128 + 1 | 128 + 2 |@ 256 + 4 |@@@ 512 + 8 |@@@@@@ 1024 + 16 |@@@@@@@@@@@@ 2048 + 32 |@@@@@@@@@@@@@@@@@@@@@@@@ 4096 + 64 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8192 + 128 | 0 + 256 | 0 + 512 | 0 + +map2[2] = count:1048576 sum:536346624 avg:511 min:0 max:1023 +value |-------------------------------------------------- count + 0 | 1024 + 1 | 1024 + 2 | 2048 + 4 | 4096 + 8 | 8192 + 16 |@ 16384 + 32 |@@@ 32768 + 64 |@@@@@@ 65536 + 128 |@@@@@@@@@@@@ 131072 + 256 |@@@@@@@@@@@@@@@@@@@@@@@@ 262144 + 512 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 524288 + +} +test isx2 {Test of int64 keys and stat values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test isx2.c } -body { exec ./test } -result {map[3] = count:49600 sum:3288450 avg:66 min:0 max:99 @@ -431,6 +505,91 @@ mapsst[ Riga, Latvia] = 322D82 mapsst[ Sofia, Bulgaria] = 7E9 mapsst[ Valletta, Malta] = B22} +test map_format2 {Torture test of map formatting} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test map_format2.c +} -body { + exec ./test +} -result {Columbus -> mapiis 1 2 Ohio +Sacramento -> mapiis 3 4 California +Olympia -> mapiis 5 6 Washington +Salem -> mapiis 7 8 Oregon + +Columbus % Ohio +Sacramento % California +Olympia % Washington +Salem % Oregon + +Columbus -> mapiis +Sacramento -> mapiis +Olympia -> mapiis +Salem -> mapiis + +The capitol of Riga is Latvia and the nerd population is 212063400820736 +The capitol of Sofia is Bulgaria and the nerd population is -2400999087387945352 +The capitol of Valletta is Malta and the nerd population is 1 +The capitol of Nicosia is Cyprus and the nerd population is -1 + +The capitol of Riga is Latvia and the nerd population is c0dedbad0000 +The capitol of Sofia is Bulgaria and the nerd population is deadf00d12345678 +The capitol of Valletta is Malta and the nerd population is 1 +The capitol of Nicosia is Cyprus and the nerd population is ffffffffffffffff + +The capitol of Riga is Latvia and the nerd population is C0DEDBAD0000 +The capitol of Sofia is Bulgaria and the nerd population is DEADF00D12345678 +The capitol of Valletta is Malta and the nerd population is 1 +The capitol of Nicosia is Cyprus and the nerd population is FFFFFFFFFFFFFFFF + +Bogons per packet for Riga +count:49600 sum:3288450 avg:66 min:0 max:99 +value |-------------------------------------------------- count + 0 |@@ 460 + 10 |@@@@@@@ 1460 + 20 |@@@@@@@@@@@@ 2460 + 30 |@@@@@@@@@@@@@@@@@@ 3460 + 40 |@@@@@@@@@@@@@@@@@@@@@@@ 4460 + 50 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 5460 + 60 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6460 + 70 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 7460 + 80 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8460 + 90 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9460 + +Bogons per packet for Sofia +count:100 sum:2025 avg:20 min:0 max:81 +value |-------------------------------------------------- count + 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 + 10 |@@@@@@@@@@@@@@@@@ 17 + 20 |@@@@@@@@@@@@@ 13 + 30 |@@@@@@@@@ 9 + 40 |@@@@@@@@@ 9 + 50 |@@@@ 4 + 60 |@@@ 3 + 70 |@@ 2 + 80 |@ 1 + 90 | 0 + +Bogons per packet for Valletta +count:45 sum:2850 avg:63 min:10 max:90 +value |-------------------------------------------------- count + 0 | 0 + 10 |@ 1 + 20 |@@ 2 + 30 |@@@ 3 + 40 |@@@@ 4 + 50 |@@@@@ 5 + 60 |@@@@@@ 6 + 70 |@@@@@@@ 7 + 80 |@@@@@@@@ 8 + 90 |@@@@@@@@@ 9 + + +49600 was the count for Riga, Latvia +100 was the count for Sofia, Bulgaria +45 was the count for Valletta, Malta + +mapsst[ Riga, Latvia] = 322D82 +mapsst[ Sofia, Bulgaria] = 7E9 +mapsst[ Valletta, Malta] = B22} + test map_issii {Test of int64,string,string,int64 keys and int64 values} -setup { exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test issii.c @@ -591,6 +750,302 @@ Valletta is the capitol of Malta and the nerd population is 1 Nicosia is the capitol of Cyprus and the nerd population is -1 } -exec rm test +test ii2 {Test of int64 keys and int64 values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test ii2.c +} -body { + exec ./test +} -result {map[1]=2 +map[1] = 2 +map[3] = 4 + +map[1] = 2 +map[3] = 4 + +0 (should be 0) +map[1] = 2 +map[3] = 4 +map[5] = 6 + +map[6] = 106 +map[7] = 107 +map[8] = 108 +map[9] = 109 + +map[5] = 1005 +map[382] = 1382 +map[526] = 1526 +map[903] = 1903 + +map[5] = 1005 +map[526] = 1526 +map[903] = 1903 + +map[526] = 1526 +map[903] = 1903 + +map[526] = 1526 + + +map[33] = 3333 +map[44] = 4444 +map[55] = 5555 +map[66] = 6666 + + +map[1970] = 1799 +} + +test is2 {Test of int64 keys and string values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test is2.c +} -body { + exec ./test +} -result {map[1]=one +map[1] = one + +map[1] = one +map[3] = three + +map[1] = one +map[3] = three + +map[1] = one +map[3] = three + +map[1] = one +map[3] = three +map[1024] = 2048 + +map[1] = one +map[3] = three + +map[1] = one +map[3] = three +map[5] = five + +map[1] = one +map[3] = three +map[5] = + +map[6] = value of 6 +map[7] = value of 7 +map[8] = value of 8 +map[9] = value of 9 + +map[5] = 1005 +map[382] = 1382 +map[526] = 1526 +map[903] = 1903 + +map[5] = 1005 +map[526] = 1526 +map[903] = 1903 + +map[526] = 1526 +map[903] = 1903 + +map[526] = 1526 + + +map[6] = new value of 6 +map[7] = new value of 7 +map[8] = new value of 8 +map[9] = new value of 9 +} + +test si2 {Test of string keys and int64 values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test si2.c +} -body { + exec ./test +} -result {map[Ohio]=1 +map[Ohio] = 1 + +map[Ohio] = 1 +map[Washington] = 2 + +map[Ohio] = 1 +map[Washington] = 2 + +map[Ohio] = 1 +map[Washington] = 2 +map[1024] = 2048 + +map[Ohio] = 1 +map[Washington] = 2 + +map[Ohio] = 1 +map[Washington] = 2 +map[1024] = 2048 + +map[Ohio] = 1 +map[Washington] = 2 + +map[Ohio] = 1 +map[Washington] = 2 +map[California] = 3 + +map[Ohio] = 1 +map[Washington] = 2 +map[California] = 3 +map[] = 7777 + +map[Ohio] = 1 +map[Washington] = 2 +map[California] = 3 +map[] = 8888 + +map[Ohio] = 1 +map[Washington] = 2 +map[California] = 3 + +map[String 6] = 106 +map[String 7] = 107 +map[String 8] = 108 +map[String 9] = 109 + +map[String 6] = 106 +map[String 7] = 107 +map[String 8] = 108 +map[String 9] = 109 + +map[String 6] = 6106 +map[String 7] = 7107 +map[String 8] = 8108 +map[String 9] = 9109 + +map[String 6] = 6 +map[String 7] = 7 +map[String 8] = 8 +map[String 9] = 9 + +} + +test iiss2 {Test of int64,int64,string keys and string values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test iiss2.c +} -body { + exec ./test +} -result {map[1, 2, Ohio] = Columbus +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Seattle +map[7, 8, Oregon] = Salem + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Seattle +map[7, 8, Oregon] = Salem +map[-9, -10, Nevada] = Carson City + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Olymp +map[7, 8, Oregon] = Salem +map[-9, -10, Nevada] = Carson City + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Olympis +map[7, 8, Oregon] = Salem +map[-9, -10, Nevada] = Carson City + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Olympia +map[7, 8, Oregon] = Salem +map[-9, -10, Nevada] = Carson City + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Olympia +map[7, 8, Oregon] = Salem + +map[3, 4, California] = Sacramento +map[5, 6, Washington] = Olympia +map[7, 8, Oregon] = Salem +map[0, 0, ] = +} + +test setadd {Test of setting and adding values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test setadd.c +} -body { + exec ./test +} -result {mapi[1] = 1 +mapi[2] = 4 +mapi[3] = 9 +mapi[4] = 16 + +maps[1] = value of 1 +maps[2] = value of 2 +maps[3] = value of 3 +maps[4] = value of 4 + +mapx[1] = count:1 sum:1 avg:1 min:1 max:1 +mapx[2] = count:1 sum:2 avg:2 min:2 max:2 +mapx[3] = count:1 sum:3 avg:3 min:3 max:3 +mapx[4] = count:1 sum:4 avg:4 min:4 max:4 + +mapi[1] = 2 +mapi[2] = 8 +mapi[3] = 18 +mapi[4] = 32 + +maps[1] = value of 1***** +maps[2] = value of 2***** +maps[3] = value of 3***** +maps[4] = value of 4***** + +mapx[1] = count:2 sum:3 avg:1 min:1 max:2 +mapx[2] = count:2 sum:6 avg:3 min:2 max:4 +mapx[3] = count:2 sum:9 avg:4 min:3 max:6 +mapx[4] = count:2 sum:12 avg:6 min:4 max:8 + +Adding 0 +mapi[1] = 2 +mapi[2] = 8 +mapi[3] = 18 +mapi[4] = 32 + +maps[1] = value of 1***** +maps[2] = value of 2***** +maps[3] = value of 3***** +maps[4] = value of 4***** + +mapx[1] = count:3 sum:3 avg:1 min:0 max:2 +mapx[2] = count:3 sum:6 avg:2 min:0 max:4 +mapx[3] = count:3 sum:9 avg:3 min:0 max:6 +mapx[4] = count:3 sum:12 avg:4 min:0 max:8 + +setting everything to 0 + + + +Adding 0 + + +mapx[1] = count:1 sum:0 avg:0 min:0 max:0 +mapx[2] = count:1 sum:0 avg:0 min:0 max:0 +mapx[3] = count:1 sum:0 avg:0 min:0 max:0 +mapx[4] = count:1 sum:0 avg:0 min:0 max:0 + +setting everything to -1 +mapi[1] = -1 +mapi[2] = -1 +mapi[3] = -1 +mapi[4] = -1 + +mapx[1] = count:1 sum:-1 avg:-1 min:-1 max:-1 +mapx[2] = count:1 sum:-1 avg:-1 min:-1 max:-1 +mapx[3] = count:1 sum:-1 avg:-1 min:-1 max:-1 +mapx[4] = count:1 sum:-1 avg:-1 min:-1 max:-1 + +adding -1 +mapi[1] = -2 +mapi[2] = -2 +mapi[3] = -2 +mapi[4] = -2 + +mapx[1] = count:2 sum:-2 avg:-1 min:-1 max:-1 +mapx[2] = count:2 sum:-2 avg:-1 min:-1 max:-1 +mapx[3] = count:2 sum:-2 avg:-1 min:-1 max:-1 +mapx[4] = count:2 sum:-2 avg:-1 min:-1 max:-1 +} + + + + +catch {exec rm test} cleanupTests diff --git a/runtime/tests/maps/map_format2.c b/runtime/tests/maps/map_format2.c new file mode 100644 index 00000000..184aa79a --- /dev/null +++ b/runtime/tests/maps/map_format2.c @@ -0,0 +1,72 @@ +#include "runtime.h" + +/* torture test of map formatting */ +#define VALUE_TYPE STRING +#define KEY1_TYPE INT64 +#define KEY2_TYPE INT64 +#define KEY3_TYPE STRING +#include "map-gen.c" + +#define VALUE_TYPE INT64 +#define KEY1_TYPE STRING +#define KEY2_TYPE STRING +#include "map-gen.c" + +#define VALUE_TYPE STAT +#define KEY1_TYPE STRING +#define KEY2_TYPE STRING +#include "map-gen.c" + +#include "map.c" + +int main () +{ + MAP mapiis = _stp_map_new_iiss(4); + _stp_map_set_iiss (mapiis, 1,2,"Ohio", "Columbus" ); + _stp_map_set_iiss (mapiis, 3,4,"California", "Sacramento" ); + _stp_map_set_iiss (mapiis, 5,6,"Washington", "Olympia" ); + _stp_map_set_iiss (mapiis, 7,8,"Oregon", "Salem" ); + _stp_map_print (mapiis, "%s -> mapiis %1d %2d %3s"); + + /* test printing of '%' */ + _stp_map_print (mapiis, "%s %% %3s"); + + /* very bad string. don't crash */ + _stp_map_print (mapiis, "%s -> mapiis %1s %2s %3d %4d"); + + MAP mapss = _stp_map_new_ssi(4); + _stp_map_set_ssi (mapss, "Riga", "Latvia", 0x0000c0dedbad0000LL); + _stp_map_set_ssi (mapss, "Sofia", "Bulgaria", 0xdeadf00d12345678LL); + _stp_map_set_ssi (mapss, "Valletta", "Malta", 1); + _stp_map_set_ssi (mapss, "Nicosia", "Cyprus", -1); + _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %d"); + _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %x"); + _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %X"); + + MAP mapsst = _stp_map_new_ssx (4, HIST_LINEAR, 0, 100, 10 ); + int i,j; + + for (i = 0; i < 100; i++) + for (j = 0; j <= i*10 ; j++ ) + _stp_map_add_ssx (mapsst, "Riga", "Latvia", i); + + for (i = 0; i < 10; i++) + for (j = 0; j < 10 ; j++ ) + _stp_map_add_ssx (mapsst, "Sofia", "Bulgaria", j * i ); + + for (i = 0; i < 100; i += 10) + for (j = 0; j < i/10 ; j++ ) + _stp_map_add_ssx (mapsst, "Valletta", "Malta", i); + + _stp_map_print (mapsst, "Bogons per packet for %1s\ncount:%C sum:%S avg:%A min:%m max:%M\n%H"); + + _stp_map_print (mapsst, "%C was the count for %1s, %2s"); + + /* here's how to print a map without using _stp_map_print(). */ + struct map_node *ptr; + foreach (mapsst, ptr) + _stp_printf ("mapsst[%09s,%09s] = %llX\n", key1str(ptr), key2str(ptr), _stp_get_stat(ptr)->sum); + _stp_print_flush(); + + return 0; +} diff --git a/runtime/tests/maps/setadd.c b/runtime/tests/maps/setadd.c new file mode 100644 index 00000000..44687528 --- /dev/null +++ b/runtime/tests/maps/setadd.c @@ -0,0 +1,213 @@ +#include "runtime.h" + +/* verify correct set and add behavior */ +#define VALUE_TYPE INT64 +#define KEY1_TYPE INT64 +#define STP_MAP_II +#include "map-gen.c" + +#define VALUE_TYPE STRING +#define KEY1_TYPE INT64 +#include "map-gen.c" + +#define VALUE_TYPE STAT +#define KEY1_TYPE INT64 +#include "map-gen.c" + +#include "map.c" + +int main () +{ + int i, res; + MAP mapi = _stp_map_new_ii(4); + MAP maps = _stp_map_new_is(4); + MAP mapx = _stp_map_new_ix(4, HIST_NONE); + + /* use add to set initial values */ + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ii (mapi, i, i*i); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + char buf[32]; + sprintf(buf, "value of %d", i); + res = _stp_map_add_is (maps, i, buf); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ix (mapx, i, i); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + /*************** now add some values *******************/ + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ii (mapi, i, i*i); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + char buf[32]; + sprintf(buf, "*****", i); + res = _stp_map_add_is (maps, i, buf); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ix (mapx, i, i+i); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + /*************** now add 0 *******************/ + printf ("Adding 0\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ii (mapi, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_is (maps, i, ""); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + for (i = 1; i < 5; i++) + { + res = _stp_map_add_is (maps, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ix (mapx, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + /*************** now set to 0 (clear) *******************/ + printf ("setting everything to 0\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_set_ii (mapi, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_set_is (maps, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_set_ix (mapx, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + /*************** now add 0 *******************/ + printf ("Adding 0\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ii (mapi, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_is (maps, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + for (i = 1; i < 5; i++) + { + res = _stp_map_add_is (maps, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ix (mapx, i, 0); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + + /*************** now set to -1 *******************/ + printf ("setting everything to -1\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_set_ii (mapi, i, -1); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_set_ix (mapx, i, -1); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + /*************** now add -1 *******************/ + printf ("adding -1\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ii (mapi, i, -1); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(mapi,"mapi[%1d] = %d"); + + for (i = 1; i < 5; i++) + { + res = _stp_map_add_ix (mapx, i, -1); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + + + _stp_map_del (mapi); + _stp_map_del (maps); + _stp_map_del (mapx); + return 0; +} diff --git a/runtime/tests/maps/si.c b/runtime/tests/maps/si.c index 5f95e0dd..1589649a 100644 --- a/runtime/tests/maps/si.c +++ b/runtime/tests/maps/si.c @@ -9,6 +9,7 @@ int main () { MAP map = _stp_map_new_str(4, INT64); + map->wrap = 1; /* map[Ohio] = 1 */ _stp_map_key_str (map, "Ohio"); diff --git a/runtime/tests/maps/si2.c b/runtime/tests/maps/si2.c new file mode 100644 index 00000000..d9db65d7 --- /dev/null +++ b/runtime/tests/maps/si2.c @@ -0,0 +1,125 @@ +#include "runtime.h" + +/* test of maps with keys of string and value of int64 */ +#define VALUE_TYPE INT64 +#define KEY1_TYPE STRING +#include "map-gen.c" +#include "map.c" + +int main () +{ + int res; + MAP map = _stp_map_new_si(4); + map->wrap = 1; + + /* map[Ohio] = 1 */ + _stp_map_set_si (map, "Ohio", 1); + printf ("map[Ohio]=%lld\n", _stp_map_get_si(map,"Ohio")); + _stp_map_print(map,"map[%1s] = %d"); + + /* map[Washington] = 2 */ + _stp_map_set_si (map, "Washington", 2); + _stp_map_print (map, "map[%1s] = %d"); + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + + /* bad map */ + res = _stp_map_set_si(0,"foo",100); + if (res != -2) + printf("WARNING: got result of %d when expected -2\n", res); + + /* bad key */ + res = _stp_map_set_si(map,0,0); + if (res != -2) + printf("WARNING: got result of %d when expected -2\n", res); + + /* bad key */ + res = _stp_map_set_si(map,0,42); + if (res != -2) + printf("WARNING: got result of %d when expected -2\n", res); + + res = _stp_map_set_si(map,"",0); + if (res) + printf("WARNING: got result of %d when expected 0\n", res); + _stp_map_print (map, "map[%1s] = %d"); + + /* create and delete a key */ + _stp_map_set_si (map, "1024", 2048); + _stp_map_print (map, "map[%1s] = %d"); + _stp_map_set_si (map, "1024", 0); + _stp_map_print (map, "map[%1s] = %d"); + _stp_map_set_si (map, "1024", 2048); + _stp_map_print (map, "map[%1s] = %d"); + _stp_map_set_si (map, "1024", 0); + _stp_map_print (map, "map[%1s] = %d"); + + /* check that unset values are 0 */ + res = _stp_map_get_si (map, "California"); + if (res) + printf("ERROR: map[California] = %d (should be 0)\n", res); + + /* map[California] = 3 */ + _stp_map_set_si (map, "California", 3); + _stp_map_print (map, "map[%1s] = %d"); + + /* test an empty string as key */ + _stp_map_set_si (map, "", 7777); + _stp_map_print (map, "map[%1s] = %d"); + _stp_map_set_si (map, "", 8888); + _stp_map_print (map, "map[%1s] = %d"); + _stp_map_set_si (map, "", 0); + _stp_map_print (map, "map[%1s] = %d"); + + + /* add 4 new entries, pushing the others out */ + int i; + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf (buf, "String %d", i); + res = _stp_map_set_si (map, buf, 100 + i); + if (res) + printf("WARNING: During wrap test, got result of %d when expected 0\n", res); + } + _stp_map_print (map, "map[%1s] = %d"); + + /* turn off wrap and repeat */ + map->wrap = 0; + for (i = 16; i < 20; i++) { + char buf[32]; + sprintf (buf, "BAD String %d", i); + res = _stp_map_set_si (map, buf, 100 + i); + if (res != -1) + printf("WARNING: During wrap test, got result of %d when expected -1\n", res); + } + _stp_map_print (map, "map[%1s] = %d"); + + /* test addition */ + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf (buf, "String %d", i); + res = _stp_map_add_si (map, buf, 1000 * i); + if (res) + printf("WARNING: During wrap test, got result of %d when expected 0\n", res); + } + _stp_map_print (map, "map[%1s] = %d"); + + /* reset all */ + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf (buf, "String %d", i); + res = _stp_map_set_si (map, buf, i); + if (res) + printf("WARNING: During wrap test, got result of %d when expected 0\n", res); + } + _stp_map_print (map, "map[%1s] = %d"); + + _stp_map_clear(map); + _stp_map_print (map, "map[%1s] = %d"); + + _stp_map_del (map); + return 0; +} |