From: hunt Date: Fri, 28 Oct 2005 19:20:28 +0000 (+0000) Subject: 2005-10-28 Martin Hunt X-Git-Tag: release-0.5~92 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=052d76119736a4b1d90190e37f45439ca1e57393;p=systemtap.git 2005-10-28 Martin Hunt * maps/keys.c: New file. Tests specific to _stp_key_get_*(). * maps/iiss2.c (main): Add some comments to make clear expected results. * maps/is2.c (main): _stp_map_get_*s() now returns "" instead of NULL when lookup fails. _stp_map_set_*s() now deletes a node when setting to "" (as well as NULL). * maps/setadd.c (main): Ditto. * maps/map.test: update results. --- diff --git a/runtime/tests/ChangeLog b/runtime/tests/ChangeLog index ebd243aff..5b0dd74cb 100644 --- a/runtime/tests/ChangeLog +++ b/runtime/tests/ChangeLog @@ -1,3 +1,14 @@ +2005-10-28 Martin Hunt + * maps/keys.c: New file. Tests specific to _stp_key_get_*(). + + * maps/iiss2.c (main): Add some comments to make clear expected + results. + * maps/is2.c (main): _stp_map_get_*s() now returns "" instead + of NULL when lookup fails. _stp_map_set_*s() now deletes a node + when setting to "" (as well as NULL). + * maps/setadd.c (main): Ditto. + * maps/map.test: update results. + 2005-10-26 Martin Hunt * maps/map.test: Add results for iiiiii and ssssss. diff --git a/runtime/tests/maps/iiss2.c b/runtime/tests/maps/iiss2.c index 56c3d1864..96369d564 100644 --- a/runtime/tests/maps/iiss2.c +++ b/runtime/tests/maps/iiss2.c @@ -32,9 +32,11 @@ int main () _stp_map_set_iiss (map, 5,6,"Washington", "Olympia" ); _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + /* delete */ _stp_map_set_iiss (map, -9,-10,"Nevada", 0); _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); + /* should add nothing */ _stp_map_set_iiss(map, 0,0,"", ""); _stp_map_print (map, "map[%1d, %2d, %3s] = %s"); diff --git a/runtime/tests/maps/is2.c b/runtime/tests/maps/is2.c index b6537f06f..3008f7025 100644 --- a/runtime/tests/maps/is2.c +++ b/runtime/tests/maps/is2.c @@ -41,15 +41,15 @@ int main () _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"); + /* check that unset values are "" */ + if (*_stp_map_get_is(map, 5)) + printf("ERROR: unset key has nonempty value\n"); /* map[5] = "five" */ _stp_map_set_is (map, 5, "five"); _stp_map_print(map,"map[%1d] = %s"); - /* test empty string */ + /* test empty string (should delete)*/ _stp_map_set_is (map, 5, ""); _stp_map_print(map,"map[%1d] = %s"); diff --git a/runtime/tests/maps/keys.c b/runtime/tests/maps/keys.c new file mode 100644 index 000000000..46bbc73d2 --- /dev/null +++ b/runtime/tests/maps/keys.c @@ -0,0 +1,41 @@ +#include "runtime.h" + +/* test of reading key values */ +#define VALUE_TYPE INT64 +#define KEY1_TYPE INT64 +#define KEY2_TYPE STRING +#define KEY3_TYPE STRING +#define KEY4_TYPE INT64 +#include "map-gen.c" + +#include "map.c" + +int main () +{ + struct map_node *ptr; + MAP map = _stp_map_new_issii(4); + + _stp_map_set_issii (map, 0, "Boston", "MA", 1970, 5224303 ); + _stp_map_set_issii (map, 1, "Chicago", "IL", 2000, 8272768 ); + _stp_map_set_issii (map, -1, "unknown", "", 2010, 1000000000 ); + + foreach (map, ptr) + printf ("map[%lld, %s, %s, %lld] = %lld\n", + _stp_key_get_int64(ptr,1), + _stp_key_get_str(ptr,2), + _stp_key_get_str(ptr,3), + _stp_key_get_int64(ptr,4), + _stp_get_int64(ptr)); + + /* get all the key and value types wrong */ + foreach (map, ptr) + printf ("map[%s, %lld, %lld, %s] = %s\n", + _stp_key_get_str(ptr,1), + _stp_key_get_int64(ptr,2), + _stp_key_get_int64(ptr,3), + _stp_key_get_str(ptr,4), + _stp_get_str(ptr)); + + _stp_map_del (map); + return 0; +} diff --git a/runtime/tests/maps/map.test b/runtime/tests/maps/map.test index bbf32b202..61b818555 100644 --- a/runtime/tests/maps/map.test +++ b/runtime/tests/maps/map.test @@ -836,7 +836,6 @@ map[5] = five map[1] = one map[3] = three -map[5] = map[6] = value of 6 map[7] = value of 7 @@ -967,7 +966,6 @@ 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 { @@ -1015,18 +1013,31 @@ maps[2] = value of 2***** maps[3] = value of 3***** maps[4] = value of 4***** +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 +Add 'X' to strings +maps[1] = value of 1*****X +maps[2] = value of 2*****X +maps[3] = value of 3*****X +maps[4] = value of 4*****X + 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 @@ -1083,9 +1094,16 @@ map[1XYZ, 2XYZ, 3XYZ, 4XYZ, 5XYZ] = 999 1XYZ and 2XYZ and 3XYZ and 4XYZ and 5XYZ ---> 999 } - - - +test keys {Test reading keys} -setup { + exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test keys.c +} -body { + exec ./test +} -result {map[0, Boston, MA, 1970] = 5224303 +map[1, Chicago, IL, 2000] = 8272768 +map[-1, unknown, , 2010] = 1000000000 +map[bad type, 0, 0, bad type] = bad type +map[bad type, 0, 0, bad type] = bad type +map[bad type, 0, 0, bad type] = bad type} catch {exec rm test} diff --git a/runtime/tests/maps/setadd.c b/runtime/tests/maps/setadd.c index 446875287..8eedbaa94 100644 --- a/runtime/tests/maps/setadd.c +++ b/runtime/tests/maps/setadd.c @@ -62,9 +62,7 @@ int main () for (i = 1; i < 5; i++) { - char buf[32]; - sprintf(buf, "*****", i); - res = _stp_map_add_is (maps, i, buf); + res = _stp_map_add_is (maps, i, "*****"); if (res) printf("ERROR: got result of %d when expected 0\n", res); } @@ -94,6 +92,9 @@ int main () if (res) printf("ERROR: got result of %d when expected 0\n", res); } + _stp_map_print(maps,"maps[%1d] = %s"); + + /* adding NULL should be same as adding "" for string values */ for (i = 1; i < 5; i++) { res = _stp_map_add_is (maps, i, 0); @@ -110,6 +111,16 @@ int main () } _stp_map_print (mapx, "mapx[%1d] = count:%C sum:%S avg:%A min:%m max:%M"); + /*************** now add X to strings *******************/ + printf ("Add 'X' to strings\n"); + for (i = 1; i < 5; i++) + { + res = _stp_map_add_is (maps, i, "X"); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + /*************** now set to 0 (clear) *******************/ printf ("setting everything to 0\n"); for (i = 1; i < 5; i++) @@ -120,6 +131,25 @@ int main () } _stp_map_print(mapi,"mapi[%1d] = %d"); + for (i = 1; i < 5; i++) + { + res = _stp_map_set_is (maps, i, ""); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + _stp_map_print(maps,"maps[%1d] = %s"); + + /* set it back to something */ + for (i = 1; i < 5; i++) + { + char buf[32]; + sprintf(buf, "%d", i); + res = _stp_map_set_is (maps, i, buf); + if (res) + printf("ERROR: got result of %d when expected 0\n", res); + } + + /* setting to NULL also deletes */ for (i = 1; i < 5; i++) { res = _stp_map_set_is (maps, i, 0); @@ -152,9 +182,11 @@ int main () 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_is (maps, i, 0); + res = _stp_map_add_is (maps, i, ""); if (res) printf("ERROR: got result of %d when expected 0\n", res); }