]> sourceware.org Git - systemtap.git/commitdiff
2005-12-08 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Thu, 8 Dec 2005 18:55:45 +0000 (18:55 +0000)
committerhunt <hunt>
Thu, 8 Dec 2005 18:55:45 +0000 (18:55 +0000)
* maps/map.test: Add size test.
* pmaps/pmap.test: Add size test.

runtime/tests/ChangeLog
runtime/tests/maps/map.test
runtime/tests/maps/size.c [new file with mode: 0644]
runtime/tests/pmaps/pmap.test
runtime/tests/pmaps/size.c [new file with mode: 0644]

index b9315fb2bc6bbaa22afa9113ef26957963b09c70..a3401404869ee5152b45b627bb1a6f50aa773be2 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-08  Martin Hunt  <hunt@redhat.com>
+
+       * maps/map.test: Add size test.
+       * pmaps/pmap.test: Add size test.
+
 2005-12-07  Martin Hunt  <hunt@redhat.com>
 
        * agg/agg.test: Adjust results to match
index d8083d5c89b65fdb75c141e620bf5f9a0f4affbb..51feca41c8dfa238faceef75bd7252de06c677c0 100644 (file)
@@ -988,6 +988,11 @@ Nicosia is the capitol of Cyprus and the nerd population is -1
 }
 
 
+test size {Test of _stp_map_size()} -setup {
+        exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test size.c
+} -body {
+       exec ./test
+} -result {}
 
 catch {exec rm test}
 
diff --git a/runtime/tests/maps/size.c b/runtime/tests/maps/size.c
new file mode 100644 (file)
index 0000000..2fb2575
--- /dev/null
@@ -0,0 +1,103 @@
+#include "runtime.h"
+
+/* test of _stp_map_size() */
+#define VALUE_TYPE INT64
+#define KEY1_TYPE INT64
+#include "map-gen.c"
+
+#include "map.c"
+
+#define check(map,num)                         \
+  {                                             \
+    int size = _stp_map_size(map);             \
+    if (size != num)                           \
+      printf("ERROR at line %d: expected size %d and got %d instead.\n", __LINE__, num, size); \
+  }
+
+int main ()
+{
+  MAP map = _stp_map_new_ii(4);
+  int64_t x;
+
+  check (map, 0);
+
+  /* map[1] = 2 */
+  _stp_map_set_ii(map, 1, 2);
+  check (map, 1);
+
+  /* map[3] = 4 */
+  _stp_map_set_ii(map, 3, 4);
+  check (map,2);
+
+  /* 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);  
+  check (map,2);
+
+  /* map[5] = 6 */
+  _stp_map_set_ii(map, 5, 6);
+  check (map,3);
+
+  /* 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);
+  }
+  check (map,4);
+
+  /* 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);
+  }
+  check (map,4);
+  
+  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);
+  check (map,4);
+
+  /* now delete all 4 nodes, one by one */
+  _stp_map_set_ii (map, 382, 0);
+  check (map,3);
+
+  _stp_map_set_ii (map, 5, 0);
+  check (map,2);
+
+  _stp_map_set_ii (map, 903, 0);
+  check (map,1);
+
+  _stp_map_set_ii (map, 526, 0);
+  check (map,0);
+
+  /* finally check clearing the map */
+  _stp_map_clear(map);
+  check (map,0);
+
+  map->wrap = 0;
+  for (i = 33; i < 99; i+=11)
+    _stp_map_set_ii (map, i, 100*i+i);
+  check (map,4);
+
+  _stp_map_clear(map);
+  check (map,0);
+
+  _stp_map_set_ii (map, 1970, 1799); 
+  check (map,1);
+
+  _stp_map_del (map);
+  return 0;
+}
index 04fbb20865b6242d5e7b049e20cfd7a19130fcad..fb5c3d0d5477f4f7574eed358e3de6ecbab20477 100644 (file)
@@ -667,6 +667,11 @@ map[4]  Sum = 8
 }
 
 
+test size {Test _stp_pmap_size()} -setup {
+        exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test size.c
+} -body {
+       exec ./test
+} -result {}
 
 catch {exec rm test}
 
diff --git a/runtime/tests/pmaps/size.c b/runtime/tests/pmaps/size.c
new file mode 100644 (file)
index 0000000..be8b459
--- /dev/null
@@ -0,0 +1,72 @@
+#include "runtime.h"
+
+/* test of _stp_pmap_size() */
+
+/* It's not clear this would ever be used in the systemtap language. 
+   It would be useful as an array of counters. */
+
+#define VALUE_TYPE INT64
+#define KEY1_TYPE INT64
+#include "pmap-gen.c"
+
+#include "map.c"
+
+#define check(map,num)                          \
+  {                                             \
+    int size = _stp_pmap_size(map);              \
+    if (size != num)                                                   \
+      printf("ERROR at line %d: expected size %d and got %d instead.\n", __LINE__, num, size); \
+  }
+
+int main ()
+{
+  PMAP map = _stp_pmap_new_ii(8);
+  int64_t x;
+
+  check(map,0);
+
+  /* put some data in. _processor_number is a global hack that allows */
+  /* us to set the current emulated cpu number for our userspace tests. */
+  /* Note that we set values based on the cpu number just to show that */
+  /* different values are stored in each cpu */
+  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
+    _stp_pmap_add_ii(map, 1, _processor_number);
+    _stp_pmap_add_ii(map, 2, 10 *_processor_number + 1);
+    _stp_pmap_add_ii(map, 3, _processor_number * _processor_number);
+    _stp_pmap_add_ii(map, 4, 1);
+  }  
+  _processor_number = 0;
+
+  check(map,4*NR_CPUS-2);
+
+  _stp_pmap_add_ii(map, 1, 1);
+  _stp_pmap_add_ii(map, 3, 1);
+  check(map,4*NR_CPUS);  
+
+  _stp_pmap_add_ii(map, 5, 100);
+  check(map,4*NR_CPUS+1);
+
+  _processor_number = 1;
+  _stp_pmap_add_ii(map, 5, 100);
+  check(map,4*NR_CPUS+2);
+
+  _stp_pmap_set_ii(map, 5, 0);
+  check(map,4*NR_CPUS+1);
+
+  _processor_number = 0;
+  _stp_pmap_set_ii(map, 5, 0);
+  check(map,4*NR_CPUS);
+
+  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
+    _stp_pmap_set_ii(map, 1, 0);
+    _stp_pmap_set_ii(map, 2, 0);
+    _stp_pmap_set_ii(map, 3, 0);
+    _stp_pmap_set_ii(map, 4, 0);
+  }  
+  _processor_number = 0;
+  check(map,0);
+
+  _stp_pmap_del (map);
+  return 0;
+}
+
This page took 0.034193 seconds and 5 git commands to generate.