diff options
Diffstat (limited to 'runtime/tests/maps')
-rw-r--r-- | runtime/tests/maps/Makefile | 3 | ||||
-rw-r--r-- | runtime/tests/maps/README | 2 | ||||
-rw-r--r-- | runtime/tests/maps/all.tcl | 12 | ||||
-rw-r--r-- | runtime/tests/maps/ii.c | 101 | ||||
-rw-r--r-- | runtime/tests/maps/iiss.c | 51 | ||||
-rw-r--r-- | runtime/tests/maps/is.c | 109 | ||||
-rw-r--r-- | runtime/tests/maps/ist.c | 50 | ||||
-rw-r--r-- | runtime/tests/maps/map.test | 269 | ||||
-rw-r--r-- | runtime/tests/maps/si.c | 112 |
9 files changed, 709 insertions, 0 deletions
diff --git a/runtime/tests/maps/Makefile b/runtime/tests/maps/Makefile new file mode 100644 index 00000000..4e744d25 --- /dev/null +++ b/runtime/tests/maps/Makefile @@ -0,0 +1,3 @@ +tests: + tclsh all.tcl + diff --git a/runtime/tests/maps/README b/runtime/tests/maps/README new file mode 100644 index 00000000..02406464 --- /dev/null +++ b/runtime/tests/maps/README @@ -0,0 +1,2 @@ +The *.c files test associative arrays (maps). "make tests" to run. + diff --git a/runtime/tests/maps/all.tcl b/runtime/tests/maps/all.tcl new file mode 100644 index 00000000..aa408eea --- /dev/null +++ b/runtime/tests/maps/all.tcl @@ -0,0 +1,12 @@ +package require tcltest +namespace import -force tcltest::* + +puts "Running all SystemTap tests" + +#puts [tcltest::configure] +#puts [tcltest::configure -file] + +tcltest::testsDirectory [file dir [info script]] +tcltest::runAllTests + +puts "All tests completed" diff --git a/runtime/tests/maps/ii.c b/runtime/tests/maps/ii.c new file mode 100644 index 00000000..64aa05ac --- /dev/null +++ b/runtime/tests/maps/ii.c @@ -0,0 +1,101 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of int64 */ + +#define KEY1_TYPE INT64 +#include "map-keys.c" + +#define VALUE_TYPE INT64 +#include "map-values.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_int64(4, INT64); + + /* map[1] = 2 */ + _stp_map_key_int64 (map, 1); + _stp_map_set_int64 (map, 2); + printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_int64(map)); + _stp_map_print(map,"map"); + + /* map[3] = 4 */ + /* try it with macros this time */ + _stp_map_key (map, 3); + _stp_map_set (map, 4); + _stp_map_print (map, "map"); + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + _stp_map_key_int64 (map, 0); + _stp_map_key_del (map); + _stp_map_key_int64 (map, 77); + _stp_map_key_del (map); + _stp_map_key_del (map); + _stp_map_set_int64 (map,1000000); + + _stp_map_print (map, "map"); + + /* create and delete a key */ + _stp_map_key_int64 (map, 1024); + _stp_map_set_int64 (map, 2048); + _stp_map_key_int64 (map, 1024); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* create and delete a key again*/ + _stp_map_key_int64 (map, 1024); + _stp_map_set_int64 (map, 2048); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* check that unset values are 0 */ + _stp_map_key_int64 (map, 5); + printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_int64(map)); + + /* map[5] = 6 */ + _stp_map_set (map, 6); + _stp_map_print (map, "map"); + + /* add 4 new entries, pushing the others out */ + int i; + for (i = 6; i < 10; i++) + { + _stp_map_key_int64 (map, i); + _stp_map_set_int64 (map, 100 + i); + } + + _stp_map_print (map, "map"); + + /* 5, 382, 526, and 903 all hash to the same value (23) */ + /* use them to test the hash chain */ + _stp_map_key_int64 (map, 5); _stp_map_set_int64 (map, 1005); + _stp_map_key_int64 (map, 382); _stp_map_set_int64 (map, 1382); + _stp_map_key_int64 (map, 526); _stp_map_set_int64 (map, 1526); + _stp_map_key_int64 (map, 903); _stp_map_set_int64 (map, 1903); + + _stp_map_print (map, "map"); + + /* now delete all 4 nodes, one by one */ + _stp_map_key_int64 (map, 382); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 5); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 903); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 526); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/iiss.c b/runtime/tests/maps/iiss.c new file mode 100644 index 00000000..e1ec2407 --- /dev/null +++ b/runtime/tests/maps/iiss.c @@ -0,0 +1,51 @@ +#include "runtime.h" + +/* test of maps with keys of int64,int64,string and value of string */ + +#define KEY1_TYPE INT64 +#define KEY2_TYPE INT64 +#define KEY3_TYPE STRING +#include "map-keys.c" + +#define VALUE_TYPE STRING +#include "map-values.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_int64_int64_str(4, STRING); + + _stp_map_key_int64_int64_str (map, 1,2,"Ohio"); + _stp_map_set_str (map, "Columbus" ); + _stp_map_key_int64_int64_str (map, 3,4,"California"); + _stp_map_add_str (map, "Sacramento" ); + _stp_map_key_int64_int64_str (map, 5,6,"Washington"); + _stp_map_set_str (map, "Seattle" ); + _stp_map_key_int64_int64_str (map, 7,8,"Oregon"); + _stp_map_set_str (map, "Salem" ); + + _stp_map_print (map, "map"); + + _stp_map_key_int64_int64_str (map, -9,-10,"Nevada"); + _stp_map_set_str (map, "Carson City" ); + _stp_map_print (map, "map"); + + _stp_map_key_int64_int64_str (map, 5,6,"Washington"); + _stp_map_set (map, "Olymp" ); + _stp_map_print (map, "map"); + + _stp_map_add_str (map, "ia" ); + _stp_map_print (map, "map"); + + _stp_map_key_int64_int64_str (map, -9,-10,"Nevada"); + _stp_map_key_del (map); + _stp_map_print (map, "map"); + + _stp_map_key_int64_int64_str (map, 0,0,""); + _stp_map_set_str (map, "XX" ); + _stp_map_print (map, "map"); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/is.c b/runtime/tests/maps/is.c new file mode 100644 index 00000000..69a0b842 --- /dev/null +++ b/runtime/tests/maps/is.c @@ -0,0 +1,109 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of string */ + +#define KEY1_TYPE INT64 +#include "map-keys.c" + +#define VALUE_TYPE STRING +#include "map-values.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_int64(4, STRING); + + /* map[1] = one */ + _stp_map_key_int64 (map, 1); + _stp_map_set_str (map, "one"); + printf ("map[%lld]=%s\n", key1int(map->key), _stp_map_get_str(map)); + _stp_map_print(map,"map"); + + /* map[3] = "three" */ + /* try it with macros this time */ + _stp_map_key (map, 3); + _stp_map_set (map, "three"); + _stp_map_print (map, "map"); + + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + _stp_map_key_int64 (map, 0); + _stp_map_key_del (map); + _stp_map_key_int64 (map, 77); + _stp_map_key_del (map); + _stp_map_key_del (map); + _stp_map_set_str (map,"1000000"); + + _stp_map_print (map, "map"); + + /* create and delete a key */ + _stp_map_key_int64 (map, 1024); + _stp_map_set_str (map, "2048"); + _stp_map_key_int64 (map, 1024); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* create and delete a key again*/ + _stp_map_key_int64 (map, 1024); + _stp_map_set_str (map, "2048"); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* check that unset values are 0 */ + _stp_map_key_int64 (map, 5); + printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_str(map)); + + /* map[5] = "five" */ + _stp_map_set (map, "five"); + _stp_map_print (map, "map"); + + /* test empty string */ + _stp_map_set (map, ""); + _stp_map_print (map, "map"); + + + /* 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_key_int64 (map, i); + _stp_map_set_str (map, buf); + } + + _stp_map_print (map, "map"); + + /* 5, 382, 526, and 903 all hash to the same value (23) */ + /* use them to test the hash chain */ + _stp_map_key_int64 (map, 5); _stp_map_set_str (map, "1005"); + _stp_map_key_int64 (map, 382); _stp_map_set_str (map, "1382"); + _stp_map_key_int64 (map, 526); _stp_map_set_str (map, "1526"); + _stp_map_key_int64 (map, 903); _stp_map_set_str (map, "1903"); + + _stp_map_print (map, "map"); + + /* now delete all 4 nodes, one by one */ + _stp_map_key_int64 (map, 382); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 5); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 903); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key_int64 (map, 526); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/ist.c b/runtime/tests/maps/ist.c new file mode 100644 index 00000000..24eb6f42 --- /dev/null +++ b/runtime/tests/maps/ist.c @@ -0,0 +1,50 @@ +#include "runtime.h" + +/* test of maps with keys of int64 and value of stat */ + +#define KEY1_TYPE INT64 +#include "map-keys.c" + +#define VALUE_TYPE STAT +#include "map-values.c" + +#include "map.c" + +int main () +{ + int i, j; + MAP map = _stp_map_new_int64(4, HSTAT_LINEAR, 0, 100, 10 ); + MAP map2 = _stp_map_new_int64(4, HSTAT_LOG, 11); + + _stp_map_key_int64 (map, 3); + for (i = 0; i < 100; i++) + for (j = 0; j <= i*10 ; j++ ) + _stp_map_add_int64_stat (map, i); + + _stp_map_key_int64 (map, 2); + for (i = 0; i < 10; i++) + for (j = 0; j < 10 ; j++ ) + _stp_map_add_int64_stat (map, j * i ); + + _stp_map_key_int64 (map, 1); + for (i = 0; i < 100; i += 10) + for (j = 0; j < i/10 ; j++ ) + _stp_map_add_int64_stat (map, i); + + _stp_map_key_int64 (map2, 1); + for (i = 0; i < 128; i++) + for (j = 0; j < 128 ; j++ ) + _stp_map_add_int64_stat (map2, i); + + _stp_map_key_int64 (map2, 2); + for (i = 0; i < 1024; i++) + for (j = 0; j < 1024 ; j++ ) + _stp_map_add_int64_stat (map2, i); + + _stp_map_print (map, "map"); + _stp_map_print (map2, "map2"); + + _stp_map_del (map); + _stp_map_del (map2); + return 0; +} diff --git a/runtime/tests/maps/map.test b/runtime/tests/maps/map.test new file mode 100644 index 00000000..4b72ffb7 --- /dev/null +++ b/runtime/tests/maps/map.test @@ -0,0 +1,269 @@ +package require tcltest +namespace import -force tcltest::* + +cd $tcltest::testsDirectory + +set CFLAGS "-Os" +set KPATH "/lib/modules/[exec uname -r]/build/include" +set PATH "../../user" + +test ii {Test of int64 keys and int64 values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -o test ii.c +} -body { + exec ./test +} -result {map[1]=2 +map[1] = 2 + +map[1] = 2 +map[3] = 4 + +map[1] = 2 +map[3] = 4 + +map[1] = 2 +map[3] = 4 + +map[1] = 2 +map[3] = 4 + +map[0]=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 + +} + +test is {Test of int64 keys and string values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -o test is.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[0]=0 +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 + +} + +test si {Test of string keys and int64 values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -o test si.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[Ohio] = 1 +map[Washington] = 2 + +map[0]=0 +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[String 6] = 106 +map[String 7] = 107 +map[String 8] = 108 +map[String 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 + +} + +test ist {Test of int64 keys and stat values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -o test ist.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 iiss {Test of int64,int64,string keys and string values} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -o test iiss.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] = 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, ] = XX +} + +exec rm test + +cleanupTests diff --git a/runtime/tests/maps/si.c b/runtime/tests/maps/si.c new file mode 100644 index 00000000..4f3e3f35 --- /dev/null +++ b/runtime/tests/maps/si.c @@ -0,0 +1,112 @@ +#include "runtime.h" + +/* test of maps with keys of string and value of int64 */ + +#define KEY1_TYPE STRING +#include "map-keys.c" + +#define VALUE_TYPE INT64 +#include "map-values.c" + +#include "map.c" + +int main () +{ + MAP map = _stp_map_new_str(4, INT64); + + /* map[Ohio] = 1 */ + _stp_map_key_str (map, "Ohio"); + _stp_map_set_int64 (map, 1); + printf ("map[%s]=%lld\n", key1str(map->key), _stp_map_get_int64(map)); + _stp_map_print(map,"map"); + + /* map[Washington] = 2 */ + /* try it with macros this time */ + _stp_map_key (map, "Washington"); + _stp_map_set (map, 2); + _stp_map_print (map, "map"); + + /* now try to confuse things */ + /* These won't do anything useful, but shouldn't crash */ + _stp_map_key_str (map, ""); + _stp_map_key_del (map); + _stp_map_key_str (map, "77"); + _stp_map_key_del (map); + _stp_map_key_del (map); + _stp_map_set_int64 (map,1000000); + + _stp_map_print (map, "map"); + + /* create and delete a key */ + _stp_map_key_str (map, "1024"); + _stp_map_set_int64 (map, 2048); + _stp_map_key_str (map, "1024"); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* create and delete a key again*/ + _stp_map_key_str (map, "1024"); + _stp_map_set_int64 (map, 2048); + _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + /* check that unset values are 0 */ + _stp_map_key_str (map, "California"); + printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_int64(map)); + + /* map[California] = 3 */ + _stp_map_set (map, 3); + _stp_map_print (map, "map"); + + /* test an empty string as key */ + _stp_map_key (map, ""); + _stp_map_set_int64 (map, 7777); + _stp_map_print (map, "map"); + _stp_map_key (map, ""); + _stp_map_set_int64 (map, 8888); + _stp_map_print (map, "map"); + + /* add 4 new entries, pushing the others out */ + int i; + for (i = 6; i < 10; i++) + { + char buf[32]; + sprintf (buf, "String %d", i); + _stp_map_key (map, buf); + _stp_map_set_int64 (map, 100 + i); + } + + _stp_map_print (map, "map"); + + + /* 5, 382, 526, and 903 all hash to the same value (23) */ + /* use them to test the hash chain */ + _stp_map_key (map, "5"); _stp_map_set_int64 (map, 1005); + _stp_map_key (map, "382"); _stp_map_set_int64 (map, 1382); + _stp_map_key (map, "526"); _stp_map_set_int64 (map, 1526); + _stp_map_key (map, "903"); _stp_map_set_int64 (map, 1903); + + _stp_map_print (map, "map"); + + /* now delete all 4 nodes, one by one */ + _stp_map_key (map, "382"); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key (map, "5"); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key (map, "903"); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_key (map, "526"); _stp_map_key_del (map); + + _stp_map_print (map, "map"); + + _stp_map_del (map); + return 0; +} |