]> sourceware.org Git - systemtap.git/commitdiff
2005-10-28 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Fri, 28 Oct 2005 19:20:28 +0000 (19:20 +0000)
committerhunt <hunt>
Fri, 28 Oct 2005 19:20:28 +0000 (19:20 +0000)
* 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.

runtime/tests/ChangeLog
runtime/tests/maps/iiss2.c
runtime/tests/maps/is2.c
runtime/tests/maps/keys.c [new file with mode: 0644]
runtime/tests/maps/map.test
runtime/tests/maps/setadd.c

index ebd243aff36a557b91e296808dd9fa7c7abbb086..5b0dd74cbdb90da09d6464a8d82706f21a101b26 100644 (file)
@@ -1,3 +1,14 @@
+2005-10-28  Martin Hunt  <hunt@redhat.com>
+       * 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  <hunt@redhat.com>
 
        * maps/map.test: Add results for iiiiii and ssssss.
index 56c3d186430f28e11e9f7d59d2b2e5ba605397c2..96369d564e15a9adb3edc09a53078249df558c5a 100644 (file)
@@ -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");
 
index b6537f06fc9e2e70d30635d650959f3a23be4f24..3008f70250bd6cf9280b3735ddbe5921cbe3e9de 100644 (file)
@@ -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 (file)
index 0000000..46bbc73
--- /dev/null
@@ -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;
+}
index bbf32b2022b97107f9915a4c4f340a144ab50c22..61b8185558ec92cdf661ab515aa085c1b242e38e 100644 (file)
@@ -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}
index 446875287580dbe57dada87ff68477e39e3f4fc8..8eedbaa94c3568e592647b6a75a5da4b5a07388e 100644 (file)
@@ -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);
     }
This page took 0.036729 seconds and 5 git commands to generate.