summaryrefslogtreecommitdiffstats
path: root/runtime/tests
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/tests')
-rw-r--r--runtime/tests/Makefile3
-rw-r--r--runtime/tests/README4
-rw-r--r--runtime/tests/all.tcl11
-rw-r--r--runtime/tests/map.test385
-rw-r--r--runtime/tests/shellsnoop/Makefile9
-rw-r--r--runtime/tests/shellsnoop/README70
-rw-r--r--runtime/tests/shellsnoop/buildit1
-rw-r--r--runtime/tests/shellsnoop/dtr.c130
-rw-r--r--runtime/tests/test.h233
-rw-r--r--runtime/tests/test4_probe/Makefile9
-rw-r--r--runtime/tests/test4_probe/README23
-rw-r--r--runtime/tests/test4_probe/buildit1
-rw-r--r--runtime/tests/test4_probe/dtr.c108
-rw-r--r--runtime/tests/testl64.c134
-rw-r--r--runtime/tests/testl64R.c50
-rw-r--r--runtime/tests/testl64_alloc.c139
-rw-r--r--runtime/tests/testlist.c63
-rw-r--r--runtime/tests/testll64.c111
-rw-r--r--runtime/tests/testlongstr.c120
-rw-r--r--runtime/tests/teststat.c72
-rw-r--r--runtime/tests/teststr.c117
-rw-r--r--runtime/tests/teststrlong.c114
-rw-r--r--runtime/tests/teststrstr.c103
-rw-r--r--runtime/tests/teststrstrstr.c121
24 files changed, 2131 insertions, 0 deletions
diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile
new file mode 100644
index 00000000..4e744d25
--- /dev/null
+++ b/runtime/tests/Makefile
@@ -0,0 +1,3 @@
+tests:
+ tclsh all.tcl
+
diff --git a/runtime/tests/README b/runtime/tests/README
new file mode 100644
index 00000000..a9457011
--- /dev/null
+++ b/runtime/tests/README
@@ -0,0 +1,4 @@
+The *.c files test associative arrays (maps). "make tests" to run.
+
+test4_probe and shellsnoop are sample probes that use the new runtime.
+
diff --git a/runtime/tests/all.tcl b/runtime/tests/all.tcl
new file mode 100644
index 00000000..2d44d6bb
--- /dev/null
+++ b/runtime/tests/all.tcl
@@ -0,0 +1,11 @@
+package require tcltest
+namespace import -force tcltest::*
+
+puts "Running all SystemTap tests"
+
+#puts [tcltest::configure]
+#puts [tcltest::configure -file]
+
+tcltest::runAllTests
+
+puts "All tests completed"
diff --git a/runtime/tests/map.test b/runtime/tests/map.test
new file mode 100644
index 00000000..1cbb7367
--- /dev/null
+++ b/runtime/tests/map.test
@@ -0,0 +1,385 @@
+package require tcltest
+namespace import -force tcltest::*
+
+set CFLAGS {-O3}
+
+test long_int64_1 {Test of long keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test testl64.c
+} -body {
+ exec ./test
+} -result {mymap[1]=2
+mymap[101]=202 mymap[1]=2 mymap[42]=83
+mymap[42]=84
+mymap[1024]=2048
+mymap[1024]=0
+mymap[10]=0
+
+mymap[1] = 2
+mymap[42] = 84
+mymap[101] = 202
+
+mymap[42] = 84
+mymap[101] = 202
+
+mymap[101] = 202
+
+
+mymap[10]=20
+mymap[0] = 100
+mymap[1] = 102
+mymap[2] = 104
+mymap[3] = 106
+
+mymap[5] = 1005
+mymap[382] = 1382
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[5] = 1005
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[526] = 1526
+}
+
+test long_int64_2 {Range test of long keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test testl64R.c
+} -body {
+ exec ./test
+} -result {mymap[1] = -9223372036854775808
+mymap[2] = 9223372036854775807
+mymap[4] = -1
+mymap[5] = 5
+mymap[999996] = 1999992
+mymap[999997] = 1999994
+mymap[999998] = 1999996
+mymap[999999] = 1999998}
+
+# same test as long_int64_1, except dynamic alloc
+test long_int64_3 {Test of long keys and int64 values, dynamic allocation} -setup {
+ exec gcc $CFLAGS -o test testl64_alloc.c
+} -body {
+ exec ./test
+} -result {mymap[1]=2
+mymap[101]=202 mymap[1]=2 mymap[42]=83
+mymap[42]=84
+mymap[1024]=2048
+mymap[1024]=0
+mymap[10]=0
+
+mymap[1] = 2
+mymap[42] = 84
+mymap[101] = 202
+
+mymap[42] = 84
+mymap[101] = 202
+
+mymap[101] = 202
+
+
+mymap[10]=20
+mymap[10] = 20
+mymap[0] = 100
+mymap[1] = 102
+mymap[2] = 104
+mymap[3] = 106
+
+mymap[5] = 1005
+mymap[382] = 1382
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[5] = 1005
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[526] = 1526
+mymap[903] = 1903
+
+mymap[526] = 1526
+}
+
+test long_long_int64_1 {Test of long,long keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test testll64.c
+} -body {
+ exec ./test
+} -result {mymap[1,1]=1
+mymap[1,2]=2
+mymap[2,1]=3
+mymap[1,1] = 1
+mymap[1,2] = 2
+mymap[2,1] = 3}
+
+test str_int64_4 {Test of string keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test teststr.c
+} -body {
+ exec ./test
+} -result {mymap[two]=2
+mymap[two-oh-two]=202 mymap[two]=2 mymap[eighty-four]=83
+mymap[eighty-four]=84
+
+mymap[two] = 2
+mymap[eighty-four] = 84
+mymap[two-oh-two] = 202
+mymap[0123456789] = 1000000
+mymap[2048]=2048
+mymap[2048]=0
+mymap[10]=0
+
+mymap[eighty-four] = 84
+mymap[two-oh-two] = 202
+mymap[0123456789] = 1000000
+
+mymap[eighty-four] = 84
+mymap[0123456789] = 1000000
+
+mymap[0123456789] = 1000000
+
+
+mymap[Ohio]=10123456
+mymap[Ohio] = 10123456
+
+mymap[test_number_0] = 1000
+mymap[test_number_1] = 1001
+mymap[test_number_2] = 1002
+mymap[test_number_3] = 1003}
+
+test str_str_int64_1 {Test of string,string keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test teststrstr.c
+} -body {
+ exec ./test
+} -result {mymap[two,three]=6
+mymap[two-oh-two,four]=808 mymap[two,three]=6 mymap[eighty-four,two]=167
+mymap[eighty-four,two]=168
+
+mymap[two,three] = 6
+mymap[eighty-four,two] = 168
+mymap[two-oh-two,four] = 808
+mymap[0123456789,foo] = 1000000
+mymap[2048,2]=4096
+mymap[2048,2]=0
+mymap[10,six]=0
+
+mymap[eighty-four,two] = 168
+mymap[two-oh-two,four] = 808
+mymap[0123456789,foo] = 1000000
+
+mymap[eighty-four,two] = 168
+mymap[0123456789,foo] = 1000000
+
+mymap[eighty-four,two] = 168
+mymap[0123456789,foo] = 1000000
+mymap[Ohio,1801] = 10123456
+
+mymap[test_number_2,**test number 4**] = 8
+mymap[test_number_3,**test number 9**] = 27
+mymap[test_number_4,**test number 16**] = 64
+mymap[test_number_5,**test number 25**] = 125}
+
+
+test str_long_int64_1 {Test of string,long keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test teststrlong.c
+} -body {
+ exec ./test
+} -result {map[two,3]=6
+map[two-oh-two,4]=808
+map[two,3]=6
+map[eighty-four,2]=167
+map[eighty-four,2]=168
+
+map[two,3] = 6
+map[eighty-four,2] = 168
+map[two-oh-two,4] = 808
+map[0123456789,4444] = 1000000
+
+map[2048,2]=4096
+mymap[2048,2]=0
+mymap[six,10]=0
+
+map[eighty-four,2] = 168
+map[two-oh-two,4] = 808
+map[0123456789,4444] = 1000000
+
+
+map[eighty-four,2] = 168
+map[0123456789,4444] = 1000000
+
+
+map[eighty-four,2] = 168
+map[0123456789,4444] = 1000000
+map[Ohio,1801] = 10123456
+
+
+map[test_number_2,2] = 8
+map[test_number_3,3] = 27
+map[test_number_4,4] = 64
+map[test_number_5,5] = 125
+
+Should be empty:
+}
+
+
+test long_str_int64_1 {Test of long,string keys and int64 values} -setup {
+ exec gcc $CFLAGS -o test testlongstr.c
+} -body {
+ exec ./test
+} -result {map[3,two]=6
+map[4,two-oh-two]=808
+map[3,two]=6
+map[2,eighty-four]=167
+map[2,eighty-four]=168
+
+map[3,two] = 6
+map[2,eighty-four] = 168
+map[4,two-oh-two] = 808
+map[4444,0123456789] = 1000000
+
+map[2048,2]=4096
+mymap[2048,2]=0
+mymap[10,six]=0
+
+map[2,eighty-four] = 168
+map[4,two-oh-two] = 808
+map[4444,0123456789] = 1000000
+
+
+map[2,eighty-four] = 168
+map[4444,0123456789] = 1000000
+
+
+map[2,eighty-four] = 168
+
+
+
+
+map[1801,Ohio] = 10123456
+
+
+map[2,test_number_2] = 8
+map[3,test_number_3] = 27
+map[4,test_number_4] = 64
+map[5,test_number_5] = 125
+
+Should be empty:
+}
+
+test str_str_str_1 {Test of string,string keys and string values} -setup {
+ exec gcc $CFLAGS -o test teststrstrstr.c
+} -body {
+ exec ./test
+} -result {map[two,2]=four
+map[two-two-one-B,Baker Street]=7% solution
+map[two,2]=four
+map[eighty-four,nineteen hundred]=nineteen hundred and eighty-three
+map[eighty-four,nineteen hundred]=nineteen hundred and eighty-four
+
+map[two,2] = four
+map[eighty-four,nineteen hundred] = nineteen hundred and eighty-four
+map[two-two-one-B,Baker Street] = 7% solution
+map[0123456789,4444] = 1000000
+
+map[2048,2]=4096
+mymap[2048,2]=(null)
+mymap[six,10]=(null)
+
+map[eighty-four,nineteen hundred] = nineteen hundred and eighty-four
+map[two-two-one-B,Baker Street] = 7% solution
+map[0123456789,4444] = 1000000
+
+
+map[eighty-four,nineteen hundred] = nineteen hundred and eighty-four
+map[0123456789,4444] = 1000000
+
+
+map[eighty-four,nineteen hundred] = nineteen hundred and eighty-four
+map[0123456789,4444] = 1000000
+map[abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,(null)] = TESTING 1,2,3
+map[abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZhiasdhgfiudsgfiusdgfisdugfisdugfsdiufgsdfiugsdifugsdiufgsdiufgisdugfisdugfigsdfiusdgfiugsdifu sdfigsdifugsdifugsdiufgsdiufgisdugfiudsgfisudgfiusdgfiusdgfisdugfisdufgiusdfgsdiufgdsiufgsdiufgsdiufgsdiufgwiugfw89e4rf98yf897ywef98wyef98wyf98wyf89ys9d8yfsd sdfysd98fy9s8fyds98fy98dsfy89sdfy,yw98fty98sfts98d7fts89d7f9sdfoooooooooooooooooooooooooooooooooooooooooooof8eo7stfew87fwet8tw87rf7fpowft7ewfptpwefpwetfpwepwfwetfp8we] = TESTING 1,2,3 ***************************************************************************************************************************************************************************************************************************************************************************** 4,5,6
+
+
+map[test_number_2,TEST_NUMBER_4] = TEST_NUMBER_8
+map[test_number_3,TEST_NUMBER_9] = TEST_NUMBER_27
+map[test_number_4,TEST_NUMBER_16] = TEST_NUMBER_64
+map[test_number_5,TEST_NUMBER_25] = TEST_NUMBER_125
+
+Should be empty:
+}
+
+test stat_1 {Test of string,long keys and stat values} -setup {
+ exec gcc $CFLAGS -o test teststat.c
+} -body {
+ exec ./test
+} -result {map[created with set,2001] = [c=5 s=125 minmax =2,42]
+map[created with set,2001] = [c=6 s=142 minmax =2,42]
+map[created with add,2020] = [c=1 s=1700 minmax =1700,1700]
+map[created with add,2020] = [c=2 s=1702 minmax =2,1700]
+map[created with add,2020] = [c=3 s=4047 minmax =2,2345]
+
+map[created with set,2001] = [c=6 s=142 minmax =2,42]
+map[created with add,2020] = [c=3 s=4047 minmax =2,2345]
+
+
+map[created with add,2020] = [c=3 s=4047 minmax =2,2345]
+
+
+map[created with add,2020] = [c=5 s=123456 minmax =2,42]
+
+
+
+map[created with add,1234] = [c=2 s=100 minmax =42,58]
+
+map[created with add,1234] = [c=2 s=100 minmax =42,58]
+}
+
+test list_1 {Test of List of string values} -setup {
+ exec gcc $CFLAGS -o test testlist.c
+} -body {
+ exec ./test
+} -result {map[0] = Item0
+map[1] = Item1
+map[2] = Item2
+map[3] = Item3
+map[4] = Item4
+map[5] = Item5
+map[6] = Item6
+map[7] = Item7
+map[8] = Item8
+map[9] = Item9
+
+size is 10
+map[0] = Item0
+map[1] = Item1
+map[2] = Item2
+map[3] = Item3
+map[4] = Item4
+map[5] = Item5
+map[6] = Item6
+map[7] = Item7
+map[8] = Item8
+map[9] = Item9
+
+map[0] = Item0
+map[1] = Item1
+map[2] = Item2
+map[3] = Item3
+map[4] = Item4
+map[5] = Item5
+map[6] = Item6
+map[7] = Item7
+map[8] = Item8
+map[9] = Item9
+
+
+map[0] = Item50
+map[1] = Item51
+map[2] = Item52
+map[3] = Item53
+map[4] = Item54
+}
+
+exec rm test
+
+cleanupTests
diff --git a/runtime/tests/shellsnoop/Makefile b/runtime/tests/shellsnoop/Makefile
new file mode 100644
index 00000000..86d61266
--- /dev/null
+++ b/runtime/tests/shellsnoop/Makefile
@@ -0,0 +1,9 @@
+# Makefile
+#
+# make -C path/to/kernel/src M=`pwd` modules
+
+obj-m := dtr.o
+
+
+
+
diff --git a/runtime/tests/shellsnoop/README b/runtime/tests/shellsnoop/README
new file mode 100644
index 00000000..ce37a2db
--- /dev/null
+++ b/runtime/tests/shellsnoop/README
@@ -0,0 +1,70 @@
+Sample probe.
+
+To build, edit the path in buildit and the addresses in struct dtr_probes
+in dtr.c Then "source buildit"
+
+This is a translation of on an old dtr probe:
+
+# shellsnoop.probe - snoop shell execution as it occurs.
+# clone of dtrace shellsnoop example
+
+global {
+ long @pids[long];
+}
+
+probe do_execve:entry {
+ char __user *vstr;
+ char str[256];
+ int len;
+
+ /* watch shells only */
+ /* FIXME: detect more shells, like csh, tcsh, zsh */
+
+ if (!strcmp(current->comm,"bash") || !strcmp(current->comm,"sh") || !strcmp(current->comm, "zsh")
+ || !strcmp(current->comm, "tcsh") || !strcmp(current->comm, "pdksh"))
+ {
+ dlog ("%d\t%d\t%d\t%s ", current->uid, current->pid, current->parent->pid, filename);
+ @pids[current->pid] = 1;
+
+ /* print out argv, ignoring argv[0] */
+ if (argv) argv++;
+ while (argv != NULL)
+ {
+ if (get_user (vstr, argv))
+ break;
+ if (!vstr)
+ break;
+ len = dtr_strncpy_from_user(str, vstr, 256);
+ str[len] = 0;
+ printk ("%s ", str);
+ argv++;
+ }
+ printk ("\n");
+ }
+}
+
+# use filp_open because copy_from_user not needed there
+probe filp_open:entry {
+ if (@pids[current->pid])
+ dlog ("%d\t%d\t%s\tO %s\n", current->pid, current->parent->pid, current->comm, filename);
+}
+
+probe sys_read:entry {
+ if (@pids[current->pid])
+ dlog ("%d\t%d\t%s\tR %d\n", current->pid, current->parent->pid, current->comm, fd);
+}
+
+probe sys_write:entry {
+ size_t len;
+ char str[256];
+ if (@pids[current->pid])
+ {
+ if (count < 64) len = count;
+ else len = 64;
+ if (len = dtr_strncpy_from_user(str, buf, len)) {
+ str[len] = 0;
+ dlog ("%d\t%d\t%s\tW %s\n", current->pid, current->parent->pid, current->comm, str);
+ }
+ }
+}
+
diff --git a/runtime/tests/shellsnoop/buildit b/runtime/tests/shellsnoop/buildit
new file mode 100644
index 00000000..8d90a0ec
--- /dev/null
+++ b/runtime/tests/shellsnoop/buildit
@@ -0,0 +1 @@
+make -C /lib/modules/2.6.10-1.770_FC3smp/build M=`pwd`
diff --git a/runtime/tests/shellsnoop/dtr.c b/runtime/tests/shellsnoop/dtr.c
new file mode 100644
index 00000000..790a907a
--- /dev/null
+++ b/runtime/tests/shellsnoop/dtr.c
@@ -0,0 +1,130 @@
+#define HASH_TABLE_BITS 8
+#define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS)
+#define BUCKETS 16 /* largest histogram width */
+#include "../../runtime.h"
+
+#include "../../io.c"
+#include "../../map.c"
+#include "../../copy.c"
+
+MODULE_PARM_DESC(dtr, "\n");
+
+MAP pids, arglist ;
+
+int inst_do_execve (char * filename, char __user *__user *argv, char __user *__user *envp, struct pt_regs * regs)
+{
+ struct map_node_str *ptr;
+
+ /* watch shells only */
+ /* FIXME: detect more shells, like csh, tcsh, zsh */
+
+ if (!strcmp(current->comm,"bash") || !strcmp(current->comm,"sh") || !strcmp(current->comm, "zsh")
+ || !strcmp(current->comm, "tcsh") || !strcmp(current->comm, "pdksh"))
+ {
+ dlog ("%d\t%d\t%d\t%s ", current->uid, current->pid, current->parent->pid, filename);
+
+ _stp_map_key_long (pids, current->pid);
+ _stp_map_set_int64 (pids, 1);
+
+ _stp_copy_argv_from_user (arglist, argv);
+ foreach (arglist, ptr)
+ printk ("%s ", ptr->str);
+ printk ("\n");
+ }
+ jprobe_return();
+ return 0;
+}
+
+struct file * inst_filp_open (const char * filename, int flags, int mode)
+{
+ _stp_map_key_long (pids, current->pid);
+ if (_stp_map_get_int64 (pids))
+ dlog ("%d\t%d\t%s\tO %s\n", current->pid, current->parent->pid, current->comm, filename);
+
+ jprobe_return();
+ return 0;
+}
+
+asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count)
+{
+ _stp_map_key_long (pids, current->pid);
+ if (_stp_map_get_int64 (pids))
+ dlog ("%d\t%d\t%s\tR %d\n", current->pid, current->parent->pid, current->comm, fd);
+
+ jprobe_return();
+ return 0;
+}
+
+asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count)
+{
+ size_t len;
+ char str[256];
+ _stp_map_key_long (pids, current->pid);
+ if (_stp_map_get_int64 (pids))
+ {
+ if (count < 64)
+ len = count;
+ else
+ len = 64;
+ len = _stp_strncpy_from_user(str, buf, len);
+ if (len < 0) len = 0;
+ str[len] = 0;
+ dlog ("%d\t%d\t%s\tW %s\n", current->pid, current->parent->pid, current->comm, str);
+ }
+
+ jprobe_return();
+ return 0;
+}
+
+static struct jprobe dtr_probes[] = {
+ {
+ .kp.addr = (kprobe_opcode_t *)0xffffffff8017b034,
+ .entry = (kprobe_opcode_t *) inst_do_execve
+ },
+ {
+ .kp.addr = (kprobe_opcode_t *)0xffffffff80170706,
+ .entry = (kprobe_opcode_t *) inst_filp_open
+ },
+ {
+ .kp.addr = (kprobe_opcode_t *)0xffffffff801711dd,
+ .entry = (kprobe_opcode_t *) inst_sys_read
+ },
+ {
+ .kp.addr = (kprobe_opcode_t *)0xffffffff8017124b,
+ .entry = (kprobe_opcode_t *) inst_sys_write
+ },
+};
+
+#define MAX_DTR_ROUTINE (sizeof(dtr_probes)/sizeof(struct jprobe))
+
+static int init_dtr(void)
+{
+ int i;
+
+ pids = _stp_map_new (10000, INT64);
+ arglist = _stp_list_new (10, STRING);
+
+ for (i = 0; i < MAX_DTR_ROUTINE; i++) {
+ printk("DTR: plant jprobe at %p, handler addr %p\n",
+ dtr_probes[i].kp.addr, dtr_probes[i].entry);
+ register_jprobe(&dtr_probes[i]);
+ }
+ printk("DTR: instrumentation is enabled...\n");
+ return 0;
+}
+
+static void cleanup_dtr(void)
+{
+ int i;
+
+ for (i = 0; i < MAX_DTR_ROUTINE; i++)
+ unregister_jprobe(&dtr_probes[i]);
+
+ _stp_map_del (pids);
+ printk("DTR: EXIT\n");
+}
+
+module_init(init_dtr);
+module_exit(cleanup_dtr);
+MODULE_LICENSE("GPL");
+
diff --git a/runtime/tests/test.h b/runtime/tests/test.h
new file mode 100644
index 00000000..8eed16bd
--- /dev/null
+++ b/runtime/tests/test.h
@@ -0,0 +1,233 @@
+/* include file for testing maps without running in the kernel */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+
+static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+{
+ unsigned long hash = val;
+
+#if __WORDSIZE == 64
+ /* Sigh, gcc can't optimise this alone like it does for 32 bits. */
+ unsigned long n = hash;
+ n <<= 18;
+ hash -= n;
+ n <<= 33;
+ hash -= n;
+ n <<= 3;
+ hash += n;
+ n <<= 3;
+ hash -= n;
+ n <<= 4;
+ hash += n;
+ n <<= 2;
+ hash += n;
+#else
+ /* On some cpus multiply is faster, on others gcc will do shifts */
+ hash *= 0x9e370001UL;
+#endif
+
+ /* High bits are more random, so use them. */
+ return hash >> (8*sizeof(long) - bits);
+}
+
+
+#define STRINGLEN 128
+#define HASH_ELEM_NUM 5000
+#define HASH_TABLE_BITS 8
+#define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS)
+#define BUCKETS 16 /* largest histogram width */
+#define PK 0 /* sprinkle debug printk into probe code */
+
+#define LIST_POISON1 ((void *) 0x00100100)
+#define LIST_POISON2 ((void *) 0x00200200)
+
+struct list_head {
+ struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT(name)
+
+#define INIT_LIST_HEAD(ptr) do { \
+ (ptr)->next = (ptr); (ptr)->prev = (ptr); \
+} while (0)
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_add(struct list_head *new,
+ struct list_head *prev,
+ struct list_head *next)
+{
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
+}
+
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head, head->next);
+}
+
+
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
+{
+ __list_add(new, head->prev, head);
+}
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head * prev, struct list_head * next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+static inline void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
+}
+
+static inline int list_empty(const struct list_head *head)
+{
+ return head->next == head;
+}
+
+static inline void list_move_tail(struct list_head *list,
+ struct list_head *head)
+{
+ __list_del(list->prev, list->next);
+ list_add_tail(list, head);
+}
+
+
+struct hlist_head {
+ struct hlist_node *first;
+};
+
+struct hlist_node {
+ struct hlist_node *next, **pprev;
+};
+#define HLIST_HEAD_INIT { .first = NULL }
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
+
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+ struct hlist_node *first = h->first;
+ n->next = first;
+ if (first)
+ first->pprev = &n->next;
+ h->first = n;
+ n->pprev = &h->first;
+}
+
+#define hlist_for_each(pos, head) \
+ for (pos = (head)->first; pos; pos = pos->next)
+
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
+
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+static inline void __hlist_del(struct hlist_node *n)
+{
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+ *pprev = next;
+ if (next)
+ next->pprev = pprev;
+}
+
+static inline void hlist_del(struct hlist_node *n)
+{
+ __hlist_del(n);
+ n->next = LIST_POISON1;
+ n->pprev = LIST_POISON2;
+}
+
+static inline void hlist_del_init(struct hlist_node *n)
+{
+ if (n->pprev) {
+ __hlist_del(n);
+ INIT_HLIST_NODE(n);
+ }
+}
+
+static inline void hlist_add_before(struct hlist_node *n,
+ struct hlist_node *next)
+{
+ n->pprev = next->pprev;
+ n->next = next;
+ next->pprev = &n->next;
+ *(n->pprev) = n;
+}
+
+#define GFP_ATOMIC 0
+
+void *kmalloc (size_t len, int flags)
+{
+ return malloc (len);
+}
+
+void *vmalloc (size_t len)
+{
+ return malloc (len);
+}
+
+#define kfree(x) free(x)
+#define vfree(x) free(x)
+
+/***** END OF KERNEL STUFF ********/
+
+#ifdef DEBUG
+#define dbug(args...) \
+ { \
+ printf("%s:%d: ", __FUNCTION__, __LINE__); \
+ printf(args); \
+ }
+#else
+#define dbug(args...) ;
+#endif
+
+#define dlog(args...) printf(args);
+
+#include "../alloc.h"
+#include "../map.h"
+#include "../map.c"
+
+/* handle renamed functions */
+#define map_new _stp_map_new
+#define map_key_del _stp_map_key_del
+#define map_start _stp_map_start
+#define map_iter _stp_map_iter
+#define map_get_str _stp_map_get_str
+#define map_set_int64 _stp_map_set_int64
+#define map_get_int64 _stp_map_get_int64
+#define map_key_str_str _stp_map_key_str_str
+#define map_key_str _stp_map_key_str
+#define map_key_long _stp_map_key_long
+#define map_key_long_long _stp_map_key_long_long
+#define map_set_stat _stp_map_set_stat
diff --git a/runtime/tests/test4_probe/Makefile b/runtime/tests/test4_probe/Makefile
new file mode 100644
index 00000000..86d61266
--- /dev/null
+++ b/runtime/tests/test4_probe/Makefile
@@ -0,0 +1,9 @@
+# Makefile
+#
+# make -C path/to/kernel/src M=`pwd` modules
+
+obj-m := dtr.o
+
+
+
+
diff --git a/runtime/tests/test4_probe/README b/runtime/tests/test4_probe/README
new file mode 100644
index 00000000..a503c28e
--- /dev/null
+++ b/runtime/tests/test4_probe/README
@@ -0,0 +1,23 @@
+Sample probe.
+
+To build, edit the path in buildit and the addresses in struct dtr_probes
+in dtr.c Then "source buildit"
+
+This is a translation of on an old dtr probe:
+
+global {
+ long @opens[string];
+ sum @reads[string], @writes[string];
+}
+
+probe sys_open:entry {
+ @opens[current->comm]++;
+}
+
+probe sys_read:entry {
+ @reads[current->comm] << count;
+}
+
+probe sys_write:entry {
+ @writes[current->comm] << count;
+}
diff --git a/runtime/tests/test4_probe/buildit b/runtime/tests/test4_probe/buildit
new file mode 100644
index 00000000..8d90a0ec
--- /dev/null
+++ b/runtime/tests/test4_probe/buildit
@@ -0,0 +1 @@
+make -C /lib/modules/2.6.10-1.770_FC3smp/build M=`pwd`
diff --git a/runtime/tests/test4_probe/dtr.c b/runtime/tests/test4_probe/dtr.c
new file mode 100644
index 00000000..0396da89
--- /dev/null
+++ b/runtime/tests/test4_probe/dtr.c
@@ -0,0 +1,108 @@
+#define HASH_TABLE_BITS 8
+#define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS)
+#define BUCKETS 16 /* largest histogram width */
+#include "../../runtime.h"
+
+#include "../../io.c"
+#include "../../map.c"
+
+
+MODULE_PARM_DESC(dtr, "\n");
+
+MAP opens, reads, writes;
+
+asmlinkage long inst_sys_open (const char __user * filename, int flags, int mode)
+{
+ _stp_map_key_str (opens, current->comm);
+ _stp_map_set_int64 (opens, _stp_map_get_int64(opens) + 1);
+ jprobe_return();
+ return 0;
+}
+
+asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count)
+{
+ _stp_map_key_str (reads, current->comm);
+ _stp_map_stat_add (reads, count);
+ jprobe_return();
+ return 0;
+}
+
+asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count)
+{
+ _stp_map_key_str (writes, current->comm);
+ _stp_map_stat_add (writes, count);
+ jprobe_return();
+ return 0;
+}
+
+static struct jprobe dtr_probes[] = {
+ {
+ .kp.addr = (kprobe_opcode_t *)0xc0166f32,
+ .entry = (kprobe_opcode_t *) inst_sys_open
+ },
+ {
+ .kp.addr = (kprobe_opcode_t *)0xc0167b93,
+ .entry = (kprobe_opcode_t *) inst_sys_read
+ },
+ {
+ .kp.addr = (kprobe_opcode_t *)0xc0167bf5,
+ .entry = (kprobe_opcode_t *) inst_sys_write
+ },
+};
+
+#define MAX_DTR_ROUTINE (sizeof(dtr_probes)/sizeof(struct jprobe))
+
+static int init_dtr(void)
+{
+ int i;
+
+ opens = _stp_map_new (1000, INT64);
+ reads = _stp_map_new (1000, STAT);
+ writes = _stp_map_new (1000, STAT);
+
+ for (i = 0; i < MAX_DTR_ROUTINE; i++) {
+ printk("DTR: plant jprobe at %p, handler addr %p\n",
+ dtr_probes[i].kp.addr, dtr_probes[i].entry);
+ register_jprobe(&dtr_probes[i]);
+ }
+ printk("DTR: instrumentation is enabled...\n");
+ return 0;
+}
+
+static void cleanup_dtr(void)
+{
+ int i;
+ struct map_node_stat *st;
+ struct map_node_int64 *ptr;
+
+ for (i = 0; i < MAX_DTR_ROUTINE; i++)
+ unregister_jprobe(&dtr_probes[i]);
+
+ for (ptr = (struct map_node_int64 *)_stp_map_start(opens); ptr;
+ ptr = (struct map_node_int64 *)_stp_map_iter (opens,(struct map_node *)ptr))
+ dlog ("opens[%s] = %lld\n", key1str(ptr), ptr->val);
+ dlog ("\n");
+
+ for (st = (struct map_node_stat *)_stp_map_start(reads); st;
+ st = (struct map_node_stat *)_stp_map_iter (reads,(struct map_node *)st))
+ dlog ("reads[%s] = [count=%lld sum=%lld min=%lld max=%lld]\n", key1str(st), st->stats.count, st->stats.sum,
+ st->stats.min, st->stats.max);
+ dlog ("\n");
+
+ for (st = (struct map_node_stat *)_stp_map_start(writes); st;
+ st = (struct map_node_stat *)_stp_map_iter (writes,(struct map_node *)st))
+ dlog ("writes[%s] = [count=%lld sum=%lld min=%lld max=%lld]\n", key1str(st), st->stats.count, st->stats.sum,
+ st->stats.min, st->stats.max);
+ dlog ("\n");
+
+ _stp_map_del (opens);
+ _stp_map_del (reads);
+ _stp_map_del (writes);
+
+ printk("DTR: EXIT\n");
+}
+
+module_init(init_dtr);
+module_exit(cleanup_dtr);
+MODULE_LICENSE("GPL");
+
diff --git a/runtime/tests/testl64.c b/runtime/tests/testl64.c
new file mode 100644
index 00000000..62b43641
--- /dev/null
+++ b/runtime/tests/testl64.c
@@ -0,0 +1,134 @@
+#include "test.h"
+
+/* testl64.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - long
+ val - INT64
+
+ Testing circular buffers, set, get
+*/
+
+int main ()
+{
+ MAP mymap = map_new(4, INT64);
+
+ map_key_long (mymap, 1);
+ map_set_int64 (mymap, 2);
+ printf ("mymap[%d]=%ld\n", 1, map_get_int64(mymap));
+
+ map_key_long (mymap, 42);
+ map_set_int64 (mymap, 83);
+
+ map_key_long (mymap, 101);
+ map_set_int64 (mymap, 202);
+ /* at this point, we have 1, 42, and 101 in the array */
+
+ printf ("mymap[%d]=%ld ", 101, map_get_int64(mymap));
+ map_key_long (mymap, 1);
+ printf ("mymap[%d]=%ld ", 1, map_get_int64(mymap));
+ map_key_long (mymap, 42);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ map_set_int64 (mymap, 84);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ map_key_long (mymap, 0);
+ map_key_del (mymap);
+ map_key_long (mymap, 77);
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,1000000);
+
+ /* create and delete a key */
+ map_key_long (mymap, 1024);
+ map_set_int64 (mymap, 2048);
+ map_key_long (mymap, 1024);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_del (mymap);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_long (mymap, 10);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ printf ("\n");
+ struct map_node_int64 *ptr;
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 1); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ printf ("\n");
+ map_key_long (mymap, 42); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 101); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ printf ("\n");
+
+ map_key_long (mymap, 10); map_set_int64 (mymap, 20);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ /* add 4 new entries, pushing "10" out */
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ map_key_long (mymap, i);
+ map_set_int64 (mymap, 100 + 2 * i);
+ }
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ printf ("\n");
+ /* 5, 382, 526, and 903 all hash to the same value (23) */
+ /* use them to test the hash chain */
+ map_key_long (mymap, 5); map_set_int64 (mymap, 1005);
+ map_key_long (mymap, 382); map_set_int64 (mymap, 1382);
+ map_key_long (mymap, 526); map_set_int64 (mymap, 1526);
+ map_key_long (mymap, 903); map_set_int64 (mymap, 1903);
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 382); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 5); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 903); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 526); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ return 0;
+}
diff --git a/runtime/tests/testl64R.c b/runtime/tests/testl64R.c
new file mode 100644
index 00000000..b5db7228
--- /dev/null
+++ b/runtime/tests/testl64R.c
@@ -0,0 +1,50 @@
+#include "test.h"
+
+#define LLONG_MAX 9223372036854775807LL
+#define LLONG_MIN (-LLONG_MAX - 1LL)
+
+/* testl64R.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - long
+ val - INT64
+
+ Testing range of values
+*/
+
+int main ()
+{
+ struct map_node_int64 *ptr;
+ MAP mymap = map_new(4, INT64);
+
+ map_key_long (mymap, 1);
+ map_set_int64 (mymap, LLONG_MIN);
+ map_key_long (mymap, 2);
+ map_set_int64 (mymap, LLONG_MAX);
+ map_key_long (mymap, 3);
+ map_set_int64 (mymap, 0); /* will not be saved */
+ map_key_long (mymap, 4);
+ map_set_int64 (mymap, -1);
+ map_key_long (mymap, 5);
+ map_set_int64 (mymap, 5);
+
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %lld\n", key1int(ptr), (long long)ptr->val);
+
+
+ /* stress test - create a million entries then print last 4 */
+ int i;
+ for (i = 0; i < 1000000; i++)
+ {
+ map_key_long (mymap, i);
+ map_set_int64 (mymap, i+i);
+ }
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %lld\n", key1int(ptr), (long long)ptr->val);
+
+ return 0;
+}
diff --git a/runtime/tests/testl64_alloc.c b/runtime/tests/testl64_alloc.c
new file mode 100644
index 00000000..fcfa6cf5
--- /dev/null
+++ b/runtime/tests/testl64_alloc.c
@@ -0,0 +1,139 @@
+#include "test.h"
+
+/* testl64_alloc.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - long
+ val - INT64
+ uses kalloc to allocate buffers dynamically. No circular buffers
+*/
+
+int main ()
+{
+ MAP mymap = map_new(0, INT64);
+
+ map_key_long (mymap, 1);
+ map_set_int64 (mymap, 2);
+ printf ("mymap[%d]=%ld\n", 1, map_get_int64(mymap));
+
+ map_key_long (mymap, 42);
+ map_set_int64 (mymap, 83);
+
+ map_key_long (mymap, 101);
+ map_set_int64 (mymap, 202);
+ /* at this point, we have 1, 42, and 101 in the array */
+
+ printf ("mymap[%d]=%ld ", 101, map_get_int64(mymap));
+ map_key_long (mymap, 1);
+ printf ("mymap[%d]=%ld ", 1, map_get_int64(mymap));
+ map_key_long (mymap, 42);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ map_set_int64 (mymap, 84);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ map_key_long (mymap, 0);
+ map_key_del (mymap);
+ map_key_long (mymap, 77);
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,1000000);
+
+ /* create and delete a key */
+ map_key_long (mymap, 1024);
+ map_set_int64 (mymap, 2048);
+ map_key_long (mymap, 1024);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_del (mymap);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_long (mymap, 10);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ printf ("\n");
+ struct map_node_int64 *ptr;
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 1); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ printf ("\n");
+ map_key_long (mymap, 42); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 101); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ printf ("\n");
+
+ map_key_long (mymap, 10); map_set_int64 (mymap, 20);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ /* add 4 new entries, NOT pushing "10" out */
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ map_key_long (mymap, i);
+ map_set_int64 (mymap, 100 + 2 * i);
+ }
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 10); map_key_del (mymap);
+ map_key_long (mymap, 3); map_key_del (mymap);
+ map_key_long (mymap, 2); map_key_del (mymap);
+ map_key_long (mymap, 1); map_key_del (mymap);
+ map_key_long (mymap, 0); map_key_del (mymap);
+
+ /* 5, 382, 526, and 903 all hash to the same value (23) */
+ /* use them to test the hash chain */
+ map_key_long (mymap, 5); map_set_int64 (mymap, 1005);
+ map_key_long (mymap, 382); map_set_int64 (mymap, 1382);
+ map_key_long (mymap, 526); map_set_int64 (mymap, 1526);
+ map_key_long (mymap, 903); map_set_int64 (mymap, 1903);
+
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 382); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 5); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 903); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ map_key_long (mymap, 526); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", key1int(ptr), (int)ptr->val);
+
+ return 0;
+}
diff --git a/runtime/tests/testlist.c b/runtime/tests/testlist.c
new file mode 100644
index 00000000..7086ff9b
--- /dev/null
+++ b/runtime/tests/testlist.c
@@ -0,0 +1,63 @@
+#include "test.h"
+
+/* testliat.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ Tests maps acting as Lists
+*/
+
+
+
+static void
+map_dump (MAP map)
+{
+ struct map_node_str *ptr;
+ foreach (map, ptr)
+ printf ("map[%ld] = %s\n", key1int(ptr), ptr->str);
+ printf ("\n");
+}
+
+
+int main ()
+{
+ char buf[32];
+ int i;
+ MAP map = _stp_list_new(10, STRING);
+
+ for (i = 0; i < 10; i++)
+ {
+ sprintf (buf, "Item%d", i);
+ _stp_list_add_str (map, buf);
+ }
+
+ map_dump(map);
+ printf ("size is %d\n", _stp_list_size(map));
+
+ /* we set a limit of 10 elements so these push */
+ /* the first entries out of the list */
+ for (i = 50; i < 55; i++)
+ {
+ sprintf (buf, "Item%d", i);
+ _stp_list_add_str (map, buf);
+ }
+
+ map_dump(map);
+
+ for (i = 0; i < 10; i++)
+ {
+ sprintf (buf, "Item%d", i);
+ _stp_list_add_str (map, buf);
+ }
+
+ map_dump(map);
+ _stp_list_clear (map);
+ map_dump(map);
+ for (i = 50; i < 55; i++)
+ {
+ sprintf (buf, "Item%d", i);
+ _stp_list_add_str (map, buf);
+ }
+ map_dump(map);
+ _stp_map_del (map);
+ return 0;
+}
diff --git a/runtime/tests/testll64.c b/runtime/tests/testll64.c
new file mode 100644
index 00000000..bfe4ae94
--- /dev/null
+++ b/runtime/tests/testll64.c
@@ -0,0 +1,111 @@
+#include "test.h"
+
+/* testll64.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - long,long
+ val - INT64
+
+ Testing circular buffers, set, get
+*/
+
+int main ()
+{
+ struct map_node_int64 *ptr;
+ MAP mymap = map_new(4, INT64);
+
+ map_key_long_long (mymap, 1,1);
+ map_set_int64 (mymap, 1);
+ map_key_long_long (mymap, 1,2);
+ map_set_int64 (mymap, 2);
+ map_key_long_long (mymap, 2,1);
+ map_set_int64 (mymap, 3);
+
+ map_key_long_long (mymap, 1,1);
+ printf ("mymap[1,1]=%ld\n", map_get_int64(mymap));
+ map_key_long_long (mymap, 1,2);
+ printf ("mymap[1,2]=%ld\n", map_get_int64(mymap));
+ map_key_long_long (mymap, 2,1);
+ printf ("mymap[2,1]=%ld\n", map_get_int64(mymap));
+
+#if 0
+ map_key_long (mymap, 42);
+ map_set_int64 (mymap, 83);
+
+ map_key_long (mymap, 101);
+ map_set_int64 (mymap, 202);
+ /* at this point, we have 1, 42, and 101 in the array */
+
+ printf ("mymap[%d]=%ld ", 101, map_get_int64(mymap));
+ map_key_long (mymap, 1);
+ printf ("mymap[%d]=%ld ", 1, map_get_int64(mymap));
+ map_key_long (mymap, 42);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ map_set_int64 (mymap, 84);
+ printf ("mymap[%d]=%ld\n", 42, map_get_int64(mymap));
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ map_key_long (mymap, 0);
+ map_key_del (mymap);
+ map_key_long (mymap, 77);
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,1000000);
+
+ /* create and delete a key */
+ map_key_long (mymap, 1024);
+ map_set_int64 (mymap, 2048);
+ map_key_long (mymap, 1024);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_del (mymap);
+ printf ("mymap[%d]=%ld\n", 1024, map_get_int64(mymap));
+ map_key_long (mymap, 10);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", ptr->key1.val, (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 1); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", ptr->key1.val, (int)ptr->val);
+
+ printf ("\n");
+ map_key_long (mymap, 42); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", ptr->key1.val, (int)ptr->val);
+
+
+ printf ("\n");
+ map_key_long (mymap, 101); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld] = %d\n", ptr->key1.val, (int)ptr->val);
+
+ printf ("\n");
+
+ map_key_long (mymap, 10); map_set_int64 (mymap, 20);
+ printf ("mymap[%d]=%ld\n", 10, map_get_int64(mymap));
+
+ /* add 4 new entries, pushing "10" out */
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ map_key_long (mymap, i);
+ map_set_int64 (mymap, 100 + 2 * i);
+ }
+#endif
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%ld,%ld] = %d\n", key1int(ptr), key2int(ptr),(int)ptr->val);
+
+ return 0;
+}
diff --git a/runtime/tests/testlongstr.c b/runtime/tests/testlongstr.c
new file mode 100644
index 00000000..6dcfaf8b
--- /dev/null
+++ b/runtime/tests/testlongstr.c
@@ -0,0 +1,120 @@
+#include "test.h"
+
+/* testlongstr.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - long,str
+ val - INT64
+*/
+
+
+
+static void
+map_dump (MAP map)
+{
+ struct map_node_int64 *ptr;
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(map); ptr;
+ ptr = (struct map_node_int64 *)map_iter (map, (struct map_node *)ptr))
+ printf ("map[%ld,%s] = %lld\n", key1int(ptr), key2str(ptr),
+ (long long)ptr->val);
+ printf ("\n");
+}
+
+static void m_print (MAP map)
+{
+ struct map_node_int64 *m = (struct map_node_int64 *)map->key;
+ printf ("map[%ld,%s]=%lld\n", key1int(m), key2str(m),
+ (long long)map_get_int64(map));
+}
+int main ()
+{
+ MAP mymap = map_new(4, INT64);
+
+ _stp_map_key2 (mymap, 3, "two");
+ _stp_map_set (mymap, 6);
+ m_print (mymap);
+
+ _stp_map_key2 (mymap, 2, "eighty-four");
+ map_set_int64 (mymap, 167);
+
+ _stp_map_key2 (mymap, 4, "two-oh-two");
+ map_set_int64 (mymap, 808);
+ /* at this point, we have 6, 167, and 808 in the array */
+
+ m_print (mymap);
+ _stp_map_key2 (mymap, 3, "two");
+ m_print (mymap);
+ _stp_map_key2 (mymap, 2, "eighty-four");
+ m_print (mymap);
+
+ map_set_int64 (mymap, 168);
+ m_print (mymap);
+
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ _stp_map_key2 (mymap, 0, NULL);
+ map_key_del (mymap);
+
+ _stp_map_key2 (mymap, 4444, "0123456789");
+ map_set_int64 (mymap,1000000);
+
+ map_dump (mymap);
+
+ _stp_map_key2 (mymap, 77, "66");
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,99999999);
+
+ /* create and delete a key */
+ _stp_map_key2 (mymap, 2048, "2");
+ map_set_int64 (mymap, 4096);
+
+ _stp_map_key2 (mymap, 2048, "2");
+ m_print (mymap);
+ map_key_del (mymap);
+
+ printf ("mymap[2048,2]=%ld\n", map_get_int64(mymap));
+ _stp_map_key2 (mymap, 10, "six");
+ printf ("mymap[10,six]=%ld\n", map_get_int64(mymap));
+
+ map_dump(mymap);
+
+ _stp_map_key2 (mymap, 4, "two-oh-two"); map_key_del (mymap);
+ map_dump(mymap);
+
+ _stp_map_key2 (mymap, 4444, "0123456789"); map_key_del (mymap);
+ map_dump(mymap);
+
+ _stp_map_key2 (mymap, 2, "eighty-four"); map_key_del (mymap);
+ map_dump(mymap);
+
+
+ _stp_map_key2 (mymap, 1801, "Ohio"); map_set_int64 (mymap, 10123456);
+ map_dump(mymap);
+
+ /* add 4 new entries, pushing "Ohio" out */
+ int i;
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32];
+ sprintf (buf, "test_number_%d", i);
+ _stp_map_key2 (mymap, (long)i, buf);
+ _stp_map_set_int64 (mymap, i*i*i);
+ }
+ map_dump (mymap);
+
+ /* delete all entries */
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32];
+ sprintf (buf, "test_number_%d", i);
+ _stp_map_key2 (mymap, (long)i, buf);
+ map_key_del (mymap);
+ }
+
+ printf ("Should be empty: ");
+ map_dump (mymap);
+ return 0;
+}
diff --git a/runtime/tests/teststat.c b/runtime/tests/teststat.c
new file mode 100644
index 00000000..d204a585
--- /dev/null
+++ b/runtime/tests/teststat.c
@@ -0,0 +1,72 @@
+#include "test.h"
+
+/* teststat.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - str,long
+ val - stat
+*/
+
+
+
+static void
+map_dump (MAP map)
+{
+ struct map_node_stat *ptr;
+ printf ("\n");
+ foreach (map, ptr)
+ printf ("map[%s,%ld] = [c=%lld s=%lld minmax =%lld,%lld]\n", key1str(ptr),
+ key2int(ptr), ptr->stats.count, ptr->stats.sum, ptr->stats.min, ptr->stats.max);
+ printf ("\n");
+}
+
+static void m_print (MAP map)
+{
+ struct map_node_stat *m = (struct map_node_stat *)map->key;
+ stat *st = _stp_map_get_stat (map);
+ printf ("map[%s,%ld] = [c=%ld s=%ld minmax =%ld,%ld]\n", key1str(m), key2int(m),
+ (long)st->count, (long)st->sum, (long)st->min, (long)st->max);
+}
+int main ()
+{
+ stat st, *stp;
+
+ MAP mymap = map_new(4, STAT);
+
+ st.count = 5; st.sum = 125; st.min = 2; st.max = 42;
+ _stp_map_key2 (mymap, "created with set", 2001 );
+ map_set_stat (mymap, &st);
+ m_print (mymap);
+
+ _stp_map_stat_add (mymap, 17);
+ m_print (mymap);
+
+ _stp_map_key2 (mymap, "created with add", 2020 );
+ _stp_map_stat_add (mymap, 1700);
+ m_print (mymap);
+ _stp_map_stat_add (mymap, 2);
+ m_print (mymap);
+ _stp_map_stat_add (mymap, 2345);
+ m_print (mymap);
+
+ map_dump(mymap);
+ _stp_map_key2 (mymap, "created with set", 2001 ); map_key_del (mymap);
+ map_dump(mymap);
+ _stp_map_key2 (mymap, "created with add", 2020 );
+ st.sum=123456;
+ map_set_stat (mymap, &st);
+ map_dump(mymap);
+ map_key_del (mymap);
+ map_dump(mymap);
+
+ mymap = map_new(4, STAT);
+ _stp_map_key2 (mymap, "created with add", 1234 );
+ _stp_map_stat_add (mymap, 42);
+ _stp_map_stat_add (mymap, 58);
+ stp = _stp_map_get_stat (mymap);
+ m_print(mymap);
+ map_dump(mymap);
+ _stp_map_del (mymap);
+
+ return 0;
+}
diff --git a/runtime/tests/teststr.c b/runtime/tests/teststr.c
new file mode 100644
index 00000000..e7b06a17
--- /dev/null
+++ b/runtime/tests/teststr.c
@@ -0,0 +1,117 @@
+#include "test.h"
+
+/* teststr.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - str
+ val - INT64
+
+ Testing circular buffers, set, get
+*/
+
+int main ()
+{
+ struct map_node_int64 *ptr;
+
+ MAP mymap = map_new(4, INT64);
+
+ map_key_str (mymap, "two");
+ map_set_int64 (mymap, 2);
+ printf ("mymap[two]=%ld\n", map_get_int64(mymap));
+
+ map_key_str (mymap, "eighty-four");
+ map_set_int64 (mymap, 83);
+
+ map_key_str (mymap, "two-oh-two");
+ map_set_int64 (mymap, 202);
+ /* at this point, we have 2, 83, and 202 in the array */
+
+ printf ("mymap[two-oh-two]=%ld ",map_get_int64(mymap));
+ map_key_str (mymap, "two");
+ printf ("mymap[two]=%ld ", map_get_int64(mymap));
+ map_key_str (mymap, "eighty-four");
+ printf ("mymap[eighty-four]=%ld\n", map_get_int64(mymap));
+
+ map_set_int64 (mymap, 84);
+ printf ("mymap[eighty-four]=%ld\n", map_get_int64(mymap));
+
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ map_key_str (mymap, NULL);
+ map_key_del (mymap);
+
+ map_key_str (mymap, "0123456789");
+ map_set_int64 (mymap,1000000);
+
+ printf ("\n");
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ map_key_str (mymap, "77");
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,99999999);
+
+ /* create and delete a key */
+ map_key_str (mymap, "2048");
+ map_set_int64 (mymap, 2048);
+
+ //map_key_str (mymap, "2048");
+ printf ("mymap[2048]=%ld\n", map_get_int64(mymap));
+ map_key_del (mymap);
+
+ printf ("mymap[2048]=%ld\n", map_get_int64(mymap));
+ map_key_str (mymap, "10");
+ printf ("mymap[10]=%ld\n", map_get_int64(mymap));
+
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ printf ("\n");
+ map_key_str (mymap, "two-oh-two"); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ printf ("\n");
+ map_key_str (mymap, "eighty-four"); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ printf ("\n");
+ map_key_str (mymap, "0123456789"); map_key_del (mymap);
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ printf ("\n");
+
+ map_key_str (mymap, "Ohio"); map_set_int64 (mymap, 10123456);
+ printf ("mymap[Ohio]=%ld\n",map_get_int64(mymap));
+
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+ printf ("\n");
+
+ /* add 4 new entries, pushing "Ohio" out */
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ char buf[32];
+ sprintf (buf, "test_number_%d", i);
+ map_key_str (mymap, buf);
+ map_set_int64 (mymap, 1000 + i);
+ }
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s] = %d\n", key1str(ptr), (int)ptr->val);
+
+ return 0;
+}
diff --git a/runtime/tests/teststrlong.c b/runtime/tests/teststrlong.c
new file mode 100644
index 00000000..83301d12
--- /dev/null
+++ b/runtime/tests/teststrlong.c
@@ -0,0 +1,114 @@
+#include "test.h"
+
+/* teststrlong.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - str,long
+ val - INT64
+*/
+
+
+
+static void
+map_dump (MAP map)
+{
+ struct map_node_int64 *ptr;
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(map); ptr;
+ ptr = (struct map_node_int64 *)map_iter (map, (struct map_node *)ptr))
+ printf ("map[%s,%ld] = %lld\n", key1str(ptr), key2int(ptr),
+ (long long)ptr->val);
+ printf ("\n");
+}
+
+static void m_print (MAP map)
+{
+ struct map_node_int64 *m = (struct map_node_int64 *)map->key;
+ printf ("map[%s,%ld]=%lld\n", key1str(m), key2int(m),
+ (long long)map_get_int64(map));
+}
+int main ()
+{
+ MAP mymap = map_new(4, INT64);
+
+ _stp_map_key2 (mymap, "two", 3);
+ _stp_map_set (mymap, 6);
+ m_print (mymap);
+
+ _stp_map_key2 (mymap, "eighty-four", 2);
+ map_set_int64 (mymap, 167);
+
+ _stp_map_key2 (mymap, "two-oh-two", 4);
+ map_set_int64 (mymap, 808);
+ /* at this point, we have 6, 167, and 808 in the array */
+
+ m_print (mymap);
+ _stp_map_key2 (mymap, "two", 3);
+ m_print (mymap);
+ _stp_map_key2 (mymap, "eighty-four", 2);
+ m_print (mymap);
+
+ map_set_int64 (mymap, 168);
+ m_print (mymap);
+
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ _stp_map_key2 (mymap, NULL, 0);
+ map_key_del (mymap);
+
+ _stp_map_key2 (mymap, "0123456789", 4444);
+ map_set_int64 (mymap,1000000);
+
+ map_dump (mymap);
+
+ _stp_map_key2 (mymap, "77", 66);
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,99999999);
+
+ /* create and delete a key */
+ _stp_map_key2 (mymap, "2048", 2);
+ map_set_int64 (mymap, 4096);
+
+ _stp_map_key2 (mymap, "2048", 2);
+ m_print (mymap);
+ map_key_del (mymap);
+
+ printf ("mymap[2048,2]=%ld\n", map_get_int64(mymap));
+ _stp_map_key2 (mymap, "six", 10);
+ printf ("mymap[six,10]=%ld\n", map_get_int64(mymap));
+
+ map_dump(mymap);
+
+ _stp_map_key2 (mymap, "two-oh-two", 4); map_key_del (mymap);
+ map_dump(mymap);
+
+
+ _stp_map_key2 (mymap, "Ohio", 1801); map_set_int64 (mymap, 10123456);
+ map_dump(mymap);
+
+ /* add 4 new entries, pushing "Ohio" out */
+ int i;
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32];
+ sprintf (buf, "test_number_%d", i);
+ _stp_map_key2 (mymap, buf, (long)i);
+ _stp_map_set_int64 (mymap, i*i*i);
+ }
+ map_dump (mymap);
+
+ /* delete all entries */
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32];
+ sprintf (buf, "test_number_%d", i);
+ _stp_map_key2 (mymap, buf, (long)i);
+ map_key_del (mymap);
+ }
+
+ printf ("Should be empty: ");
+ map_dump (mymap);
+ return 0;
+}
diff --git a/runtime/tests/teststrstr.c b/runtime/tests/teststrstr.c
new file mode 100644
index 00000000..86a2419b
--- /dev/null
+++ b/runtime/tests/teststrstr.c
@@ -0,0 +1,103 @@
+#include "test.h"
+
+/* teststrstr.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - str,str
+ val - INT64
+
+ Testing circular buffers, set, get
+*/
+
+int main ()
+{
+ struct map_node_int64 *ptr;
+ MAP mymap = map_new(4, INT64);
+
+ map_key_str_str (mymap, "two", "three");
+ map_set_int64 (mymap, 6);
+ printf ("mymap[two,three]=%ld\n", map_get_int64(mymap));
+
+ map_key_str_str (mymap, "eighty-four", "two");
+ map_set_int64 (mymap, 167);
+
+ map_key_str_str (mymap, "two-oh-two", "four");
+ map_set_int64 (mymap, 808);
+ /* at this point, we have 6, 167, and 808 in the array */
+
+ printf ("mymap[two-oh-two,four]=%ld ",map_get_int64(mymap));
+ map_key_str_str (mymap, "two", "three");
+ printf ("mymap[two,three]=%ld ", map_get_int64(mymap));
+ map_key_str_str (mymap, "eighty-four", "two");
+ printf ("mymap[eighty-four,two]=%ld\n", map_get_int64(mymap));
+
+ map_set_int64 (mymap, 168);
+ printf ("mymap[eighty-four,two]=%ld\n", map_get_int64(mymap));
+
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ map_key_str_str (mymap, NULL, NULL);
+ map_key_del (mymap);
+
+ map_key_str_str (mymap, "0123456789", "foo");
+ map_set_int64 (mymap,1000000);
+
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s,%s] = %d\n", key1str(ptr), key2str(ptr), (int)ptr->val);
+
+ map_key_str_str (mymap, "77", "66");
+ map_key_del (mymap);
+ map_key_del (mymap);
+ map_set_int64 (mymap,99999999);
+
+ /* create and delete a key */
+ map_key_str_str (mymap, "2048", "2");
+ map_set_int64 (mymap, 4096);
+
+ map_key_str_str (mymap, "2048", "2");
+ printf ("mymap[2048,2]=%ld\n", map_get_int64(mymap));
+ map_key_del (mymap);
+
+ printf ("mymap[2048,2]=%ld\n", map_get_int64(mymap));
+ map_key_str_str (mymap, "10", "six");
+ printf ("mymap[10,six]=%ld\n", map_get_int64(mymap));
+
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s,%s] = %d\n", key1str(ptr), key2str(ptr), (int)ptr->val);
+
+ map_key_str_str (mymap, "two-oh-two", "four"); map_key_del (mymap);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s,%s] = %d\n", key1str(ptr), key2str(ptr), (int)ptr->val);
+
+
+ map_key_str_str (mymap, "Ohio", "1801"); map_set_int64 (mymap, 10123456);
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s,%s] = %d\n", key1str(ptr), key2str(ptr), (int)ptr->val);
+
+ /* add 4 new entries, pushing "Ohio" out */
+ int i;
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32], buf2[32];
+ sprintf (buf, "test_number_%d", i);
+ sprintf (buf2, "**test number %d**", i*i);
+ map_key_str_str (mymap, buf, buf2);
+ map_set_int64 (mymap, i*i*i);
+ }
+ printf ("\n");
+ for (ptr = (struct map_node_int64 *)map_start(mymap); ptr;
+ ptr = (struct map_node_int64 *)map_iter (mymap, (struct map_node *)ptr))
+ printf ("mymap[%s,%s] = %d\n", key1str(ptr), key2str(ptr), (int)ptr->val);
+
+
+ return 0;
+}
diff --git a/runtime/tests/teststrstrstr.c b/runtime/tests/teststrstrstr.c
new file mode 100644
index 00000000..95ffc1a2
--- /dev/null
+++ b/runtime/tests/teststrstrstr.c
@@ -0,0 +1,121 @@
+#include "test.h"
+
+/* teststrstrstr.c - DO NOT EDIT without updating the expected results in map.test. */
+
+/*
+ key - str,str
+ val - str
+*/
+
+
+
+static void
+map_dump (MAP map)
+{
+ struct map_node_str *ptr;
+ printf ("\n");
+ for (ptr = (struct map_node_str *)map_start(map); ptr;
+ ptr = (struct map_node_str *)map_iter (map, (struct map_node *)ptr))
+ printf ("map[%s,%s] = %s\n", key1str(ptr), key2str(ptr), ptr->str);
+ printf ("\n");
+}
+
+static void m_print (MAP map)
+{
+ struct map_node_str *m = (struct map_node_str *)map->key;
+ printf ("map[%s,%s]=%s\n", key1str(m), key2str(m), map_get_str(map));
+}
+int main ()
+{
+ MAP mymap = map_new(4, STRING);
+
+ _stp_map_key2 (mymap, "two", "2" );
+ _stp_map_set (mymap, "four");
+ m_print (mymap);
+
+ _stp_map_key2 (mymap, "eighty-four", "nineteen hundred");
+ _stp_map_set (mymap, "nineteen hundred and eighty-three");
+
+ _stp_map_key2 (mymap, "two-two-one-B", "Baker Street");
+ _stp_map_set (mymap, "7% solution");
+
+ m_print (mymap);
+ _stp_map_key2 (mymap, "two", "2");
+ m_print (mymap);
+ _stp_map_key2 (mymap, "eighty-four", "nineteen hundred");
+ m_print (mymap);
+
+ _stp_map_set (mymap, "nineteen hundred and eighty-four");
+ m_print (mymap);
+
+
+ /* now try to confuse things */
+ /* These won't do anything useful, but shouldn't crash */
+ _stp_map_key2 (mymap, NULL, NULL);
+ map_key_del (mymap);
+
+ _stp_map_key2 (mymap, "0123456789", "4444");
+ _stp_map_set (mymap,"1000000");
+
+ map_dump (mymap);
+
+ _stp_map_key2 (mymap, "77", "66");
+ map_key_del (mymap);
+ map_key_del (mymap);
+ _stp_map_set (mymap,"99999999");
+
+ /* create and delete a key */
+ _stp_map_key2 (mymap, "2048", "2");
+ _stp_map_set (mymap, "4096");
+
+ _stp_map_key2 (mymap, "2048", "2");
+ m_print (mymap);
+ map_key_del (mymap);
+
+ printf ("mymap[2048,2]=%s\n", map_get_str(mymap));
+ _stp_map_key2 (mymap, "six", "10");
+ printf ("mymap[six,10]=%s\n", map_get_str(mymap));
+
+ map_dump(mymap);
+
+ _stp_map_key2 (mymap, "two-two-one-B", "Baker Street"); map_key_del (mymap);
+ map_dump(mymap);
+
+
+ _stp_map_key2 (mymap, "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL);
+ _stp_map_set (mymap, "TESTING 1,2,3");
+
+ _stp_map_key2 (mymap, "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZhiasdhgfiudsgfiusdgfisdugfisdugfsdiufgsdfiugsdifugsdiufgsdiufgisdugfisdugfigsdfiusdgfiugsdifu sdfigsdifugsdifugsdiufgsdiufgisdugfiudsgfisudgfiusdgfiusdgfisdugfisdufgiusdfgsdiufgdsiufgsdiufgsdiufgsdiufgwiugfw89e4rf98yf897ywef98wyef98wyf98wyf89ys9d8yfsd sdfysd98fy9s8fyds98fy98dsfy89sdfy", "yw98fty98sfts98d7fts89d7f9sdfoooooooooooooooooooooooooooooooooooooooooooof8eo7stfew87fwet8tw87rf7fpowft7ewfptpwefpwetfpwepwfwetfp8we");
+
+ _stp_map_set (mymap, "TESTING 1,2,3 ***************************************************************************************************************************************************************************************************************************************************************************** 4,5,6");
+ map_dump(mymap);
+
+ /* add 4 new entries, pushing "Ohio" out */
+ int i;
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32], buf2[32], buf3[32];
+ sprintf (buf, "test_number_%d", i);
+ sprintf (buf2, "TEST_NUMBER_%d", i*i);
+ sprintf (buf3, "TEST_NUMBER_%d", i*i*i);
+ _stp_map_key2 (mymap, buf, buf2);
+ _stp_map_set_str (mymap, buf3);
+ }
+ map_dump (mymap);
+
+ /* delete all entries */
+ for (i = 2; i < 6; i++)
+ {
+ char buf[32], buf2[32], buf3[32];
+ sprintf (buf, "test_number_%d", i);
+ sprintf (buf2, "TEST_NUMBER_%d", i*i);
+ sprintf (buf3, "TEST_NUMBER_%d", i*i*i);
+ _stp_map_key2 (mymap, buf, buf2);
+ map_key_del (mymap);
+ }
+
+ printf ("Should be empty: ");
+ map_dump (mymap);
+ _stp_map_del (mymap);
+ return 0;
+}