summaryrefslogtreecommitdiffstats
path: root/runtime/tests/pmaps/size.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-12-08 18:55:45 +0000
committerhunt <hunt>2005-12-08 18:55:45 +0000
commita2872cffd4ecf7d2ef947cd5b86f9a67f5d2ddcb (patch)
tree56f9341bfd07eaad7d1b9d00d77d872272398f40 /runtime/tests/pmaps/size.c
parent71572ba8dfa3b045dfdcd0c8e0a2db168659ea10 (diff)
downloadsystemtap-steved-a2872cffd4ecf7d2ef947cd5b86f9a67f5d2ddcb.tar.gz
systemtap-steved-a2872cffd4ecf7d2ef947cd5b86f9a67f5d2ddcb.tar.xz
systemtap-steved-a2872cffd4ecf7d2ef947cd5b86f9a67f5d2ddcb.zip
2005-12-08 Martin Hunt <hunt@redhat.com>
* maps/map.test: Add size test. * pmaps/pmap.test: Add size test.
Diffstat (limited to 'runtime/tests/pmaps/size.c')
-rw-r--r--runtime/tests/pmaps/size.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/runtime/tests/pmaps/size.c b/runtime/tests/pmaps/size.c
new file mode 100644
index 00000000..be8b4590
--- /dev/null
+++ b/runtime/tests/pmaps/size.c
@@ -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;
+}
+