summaryrefslogtreecommitdiffstats
path: root/runtime/tests/maps
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/tests/maps')
-rw-r--r--runtime/tests/maps/ii.c24
-rw-r--r--runtime/tests/maps/iiss.c12
-rw-r--r--runtime/tests/maps/is.c26
-rw-r--r--runtime/tests/maps/ist.c4
-rw-r--r--runtime/tests/maps/map.test90
-rw-r--r--runtime/tests/maps/map_format.c87
-rw-r--r--runtime/tests/maps/si.c28
-rw-r--r--runtime/tests/maps/test_list_int64.c8
-rw-r--r--runtime/tests/maps/test_list_string.c8
9 files changed, 232 insertions, 55 deletions
diff --git a/runtime/tests/maps/ii.c b/runtime/tests/maps/ii.c
index 64aa05ac..afee14d4 100644
--- a/runtime/tests/maps/ii.c
+++ b/runtime/tests/maps/ii.c
@@ -18,13 +18,13 @@ int main ()
_stp_map_key_int64 (map, 1);
_stp_map_set_int64 (map, 2);
printf ("map[%lld]=%lld\n", key1int(map->key), _stp_map_get_int64(map));
- _stp_map_print(map,"map");
+ _stp_map_print(map,"map[%1d] = %d");
/* map[3] = 4 */
/* try it with macros this time */
_stp_map_key (map, 3);
_stp_map_set (map, 4);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* now try to confuse things */
/* These won't do anything useful, but shouldn't crash */
@@ -35,7 +35,7 @@ int main ()
_stp_map_key_del (map);
_stp_map_set_int64 (map,1000000);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* create and delete a key */
_stp_map_key_int64 (map, 1024);
@@ -43,14 +43,14 @@ int main ()
_stp_map_key_int64 (map, 1024);
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* create and delete a key again*/
_stp_map_key_int64 (map, 1024);
_stp_map_set_int64 (map, 2048);
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* check that unset values are 0 */
_stp_map_key_int64 (map, 5);
@@ -58,7 +58,7 @@ int main ()
/* map[5] = 6 */
_stp_map_set (map, 6);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* add 4 new entries, pushing the others out */
int i;
@@ -68,7 +68,7 @@ int main ()
_stp_map_set_int64 (map, 100 + i);
}
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* 5, 382, 526, and 903 all hash to the same value (23) */
/* use them to test the hash chain */
@@ -77,24 +77,24 @@ int main ()
_stp_map_key_int64 (map, 526); _stp_map_set_int64 (map, 1526);
_stp_map_key_int64 (map, 903); _stp_map_set_int64 (map, 1903);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
/* now delete all 4 nodes, one by one */
_stp_map_key_int64 (map, 382); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
_stp_map_key_int64 (map, 5); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
_stp_map_key_int64 (map, 903); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
_stp_map_key_int64 (map, 526); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %d");
_stp_map_del (map);
return 0;
diff --git a/runtime/tests/maps/iiss.c b/runtime/tests/maps/iiss.c
index e1ec2407..dc034c94 100644
--- a/runtime/tests/maps/iiss.c
+++ b/runtime/tests/maps/iiss.c
@@ -25,26 +25,26 @@ int main ()
_stp_map_key_int64_int64_str (map, 7,8,"Oregon");
_stp_map_set_str (map, "Salem" );
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_key_int64_int64_str (map, -9,-10,"Nevada");
_stp_map_set_str (map, "Carson City" );
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_key_int64_int64_str (map, 5,6,"Washington");
_stp_map_set (map, "Olymp" );
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_add_str (map, "ia" );
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_key_int64_int64_str (map, -9,-10,"Nevada");
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_key_int64_int64_str (map, 0,0,"");
_stp_map_set_str (map, "XX" );
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1d, %2d, %3s] = %s");
_stp_map_del (map);
return 0;
diff --git a/runtime/tests/maps/is.c b/runtime/tests/maps/is.c
index bfb21753..6b2cbb0e 100644
--- a/runtime/tests/maps/is.c
+++ b/runtime/tests/maps/is.c
@@ -18,13 +18,13 @@ int main ()
_stp_map_key_int64 (map, 1);
_stp_map_set_str (map, "one");
printf ("map[%lld]=%s\n", key1int(map->key), _stp_map_get_str(map));
- _stp_map_print(map,"map");
+ _stp_map_print(map,"map[%1d] = %s");
/* map[3] = "three" */
/* try it with macros this time */
_stp_map_key (map, 3);
_stp_map_set (map, "three");
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* now try to confuse things */
@@ -36,7 +36,7 @@ int main ()
_stp_map_key_del (map);
_stp_map_set_str (map,"1000000");
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* create and delete a key */
_stp_map_key_int64 (map, 1024);
@@ -44,14 +44,14 @@ int main ()
_stp_map_key_int64 (map, 1024);
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* create and delete a key again*/
_stp_map_key_int64 (map, 1024);
_stp_map_set_str (map, "2048");
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* check that unset values are 0 */
_stp_map_key_int64 (map, 5);
@@ -59,11 +59,11 @@ int main ()
/* map[5] = "five" */
_stp_map_set (map, "five");
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* test empty string */
_stp_map_set (map, "");
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* add 4 new entries, pushing the others out */
@@ -76,7 +76,7 @@ int main ()
_stp_map_set_str (map, buf);
}
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* 5, 382, 526, and 903 all hash to the same value (23) */
/* use them to test the hash chain */
@@ -85,24 +85,24 @@ int main ()
_stp_map_key_int64 (map, 526); _stp_map_set_str (map, "1526");
_stp_map_key_int64 (map, 903); _stp_map_set_str (map, "1903");
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
/* now delete all 4 nodes, one by one */
_stp_map_key_int64 (map, 382); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
_stp_map_key_int64 (map, 5); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
_stp_map_key_int64 (map, 903); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
_stp_map_key_int64 (map, 526); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print(map,"map[%1d] = %s");
_stp_map_del (map);
return 0;
diff --git a/runtime/tests/maps/ist.c b/runtime/tests/maps/ist.c
index 24eb6f42..be3ca87d 100644
--- a/runtime/tests/maps/ist.c
+++ b/runtime/tests/maps/ist.c
@@ -41,8 +41,8 @@ int main ()
for (j = 0; j < 1024 ; j++ )
_stp_map_add_int64_stat (map2, i);
- _stp_map_print (map, "map");
- _stp_map_print (map2, "map2");
+ _stp_map_print (map, "map[%1d] = count:%C sum:%S avg:%A min:%m max:%M\n%H");
+ _stp_map_print (map2, "map2[%1d] = count:%C sum:%S avg:%A min:%m max:%M\n%H");
_stp_map_del (map);
_stp_map_del (map2);
diff --git a/runtime/tests/maps/map.test b/runtime/tests/maps/map.test
index 14668a17..3684831b 100644
--- a/runtime/tests/maps/map.test
+++ b/runtime/tests/maps/map.test
@@ -338,6 +338,96 @@ newlist[3] = Item53
newlist[4] = Item54
}
+test map_format {Torture test of map formatting} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test map_format.c
+} -body {
+ exec ./test
+} -result {Columbus -> mapiis 1 2 Ohio
+Sacramento -> mapiis 3 4 California
+Olympia -> mapiis 5 6 Washington
+Salem -> mapiis 7 8 Oregon
+
+Columbus % Ohio
+Sacramento % California
+Olympia % Washington
+Salem % Oregon
+
+Columbus -> mapiis
+Sacramento -> mapiis
+Olympia -> mapiis
+Salem -> mapiis
+
+The capitol of Riga is Latvia and the nerd population is 212063400820736
+The capitol of Sofia is Bulgaria and the nerd population is -2400999087387945352
+The capitol of Valletta is Malta and the nerd population is 1
+The capitol of Nicosia is Cyprus and the nerd population is -1
+
+The capitol of Riga is Latvia and the nerd population is c0dedbad0000
+The capitol of Sofia is Bulgaria and the nerd population is deadf00d12345678
+The capitol of Valletta is Malta and the nerd population is 1
+The capitol of Nicosia is Cyprus and the nerd population is ffffffffffffffff
+
+The capitol of Riga is Latvia and the nerd population is C0DEDBAD0000
+The capitol of Sofia is Bulgaria and the nerd population is DEADF00D12345678
+The capitol of Valletta is Malta and the nerd population is 1
+The capitol of Nicosia is Cyprus and the nerd population is FFFFFFFFFFFFFFFF
+
+The capitol of Riga is Latvia and the nerd population is 0000c0dedbad0000
+The capitol of Sofia is Bulgaria and the nerd population is deadf00d12345678
+The capitol of Valletta is Malta and the nerd population is 0000000000000001
+The capitol of Nicosia is Cyprus and the nerd population is ffffffffffffffff
+
+Bogons per packet for Riga
+count:49600 sum:3288450 avg:66 min:0 max:99
+value |-------------------------------------------------- count
+ 0 |@@ 460
+ 10 |@@@@@@@ 1460
+ 20 |@@@@@@@@@@@@ 2460
+ 30 |@@@@@@@@@@@@@@@@@@ 3460
+ 40 |@@@@@@@@@@@@@@@@@@@@@@@ 4460
+ 50 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 5460
+ 60 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6460
+ 70 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 7460
+ 80 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8460
+ 90 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9460
+
+Bogons per packet for Sofia
+count:100 sum:2025 avg:20 min:0 max:81
+value |-------------------------------------------------- count
+ 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42
+ 10 |@@@@@@@@@@@@@@@@@ 17
+ 20 |@@@@@@@@@@@@@ 13
+ 30 |@@@@@@@@@ 9
+ 40 |@@@@@@@@@ 9
+ 50 |@@@@ 4
+ 60 |@@@ 3
+ 70 |@@ 2
+ 80 |@ 1
+ 90 | 0
+
+Bogons per packet for Valletta
+count:45 sum:2850 avg:63 min:10 max:90
+value |-------------------------------------------------- count
+ 0 | 0
+ 10 |@ 1
+ 20 |@@ 2
+ 30 |@@@ 3
+ 40 |@@@@ 4
+ 50 |@@@@@ 5
+ 60 |@@@@@@ 6
+ 70 |@@@@@@@ 7
+ 80 |@@@@@@@@ 8
+ 90 |@@@@@@@@@ 9
+
+
+49600 was the count for Riga, Latvia
+100 was the count for Sofia, Bulgaria
+45 was the count for Valletta, Malta
+
+mapsst[ Riga, Latvia] = 322D82
+mapsst[ Sofia, Bulgaria] = 7E9
+mapsst[ Valletta, Malta] = B22}
+
exec rm test
cleanupTests
diff --git a/runtime/tests/maps/map_format.c b/runtime/tests/maps/map_format.c
new file mode 100644
index 00000000..d6a848ab
--- /dev/null
+++ b/runtime/tests/maps/map_format.c
@@ -0,0 +1,87 @@
+#include "runtime.h"
+
+/* torture test of map formatting */
+
+#define KEY1_TYPE INT64
+#define KEY2_TYPE INT64
+#define KEY3_TYPE STRING
+#include "map-keys.c"
+
+#define KEY1_TYPE STRING
+#define KEY2_TYPE STRING
+#include "map-keys.c"
+
+#define VALUE_TYPE STRING
+#include "map-values.c"
+
+#define VALUE_TYPE INT64
+#include "map-values.c"
+
+#define VALUE_TYPE STAT
+#include "map-values.c"
+
+#include "map.c"
+
+int main ()
+{
+ MAP mapiis = _stp_map_new_int64_int64_str(4, STRING);
+ _stp_map_key_int64_int64_str (mapiis, 1,2,"Ohio");
+ _stp_map_set_str (mapiis, "Columbus" );
+ _stp_map_key_int64_int64_str (mapiis, 3,4,"California");
+ _stp_map_add_str (mapiis, "Sacramento" );
+ _stp_map_key_int64_int64_str (mapiis, 5,6,"Washington");
+ _stp_map_set_str (mapiis, "Olympia" );
+ _stp_map_key_int64_int64_str (mapiis, 7,8,"Oregon");
+ _stp_map_set_str (mapiis, "Salem" );
+ _stp_map_print (mapiis, "%s -> mapiis %1d %2d %3s");
+
+ /* test printing of '%' */
+ _stp_map_print (mapiis, "%s %% %3s");
+
+ /* very bad string. don't crash */
+ _stp_map_print (mapiis, "%s -> mapiis %1s %2s %3d %4d");
+
+ MAP mapss = _stp_map_new_str_str(4, INT64);
+ _stp_map_key_str_str (mapss, "Riga", "Latvia");
+ _stp_map_set_int64 (mapss, 0x0000c0dedbad0000);
+ _stp_map_key_str_str (mapss, "Sofia", "Bulgaria");
+ _stp_map_set_int64 (mapss, 0xdeadf00d12345678);
+ _stp_map_key_str_str (mapss, "Valletta", "Malta");
+ _stp_map_set_int64 (mapss, 1);
+ _stp_map_key_str_str (mapss, "Nicosia", "Cyprus");
+ _stp_map_set_int64 (mapss, -1);
+ _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %d");
+ _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %x");
+ _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %X");
+ _stp_map_print (mapss, "The capitol of %1s is %2s and the nerd population is %p");
+
+ MAP mapsst = _stp_map_new_str_str(4, HSTAT_LINEAR, 0, 100, 10 );
+ int i,j;
+
+ _stp_map_key_str_str (mapsst, "Riga", "Latvia");
+ for (i = 0; i < 100; i++)
+ for (j = 0; j <= i*10 ; j++ )
+ _stp_map_add_int64_stat (mapsst, i);
+
+ _stp_map_key_str_str (mapsst, "Sofia", "Bulgaria");
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10 ; j++ )
+ _stp_map_add_int64_stat (mapsst, j * i );
+
+ _stp_map_key_str_str (mapsst, "Valletta", "Malta");
+ for (i = 0; i < 100; i += 10)
+ for (j = 0; j < i/10 ; j++ )
+ _stp_map_add_int64_stat (mapsst, i);
+
+ _stp_map_print (mapsst, "Bogons per packet for %1s\ncount:%C sum:%S avg:%A min:%m max:%M\n%H");
+
+ _stp_map_print (mapsst, "%C was the count for %1s, %2s");
+
+ /* here's how to print a map without using _stp_map_print(). */
+ struct map_node *ptr;
+ foreach (mapsst, ptr)
+ _stp_printf ("mapsst[%09s,%09s] = %llX\n", key1str(ptr), key2str(ptr), _stp_get_stat(ptr)->sum);
+ _stp_print_flush();
+
+ return 0;
+}
diff --git a/runtime/tests/maps/si.c b/runtime/tests/maps/si.c
index 0e88bc4e..90544ed2 100644
--- a/runtime/tests/maps/si.c
+++ b/runtime/tests/maps/si.c
@@ -18,13 +18,13 @@ int main ()
_stp_map_key_str (map, "Ohio");
_stp_map_set_int64 (map, 1);
printf ("map[%s]=%lld\n", key1str(map->key), _stp_map_get_int64(map));
- _stp_map_print(map,"map");
+ _stp_map_print(map,"map[%1s] = %d");
/* map[Washington] = 2 */
/* try it with macros this time */
_stp_map_key (map, "Washington");
_stp_map_set (map, 2);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* now try to confuse things */
/* These won't do anything useful, but shouldn't crash */
@@ -35,7 +35,7 @@ int main ()
_stp_map_key_del (map);
_stp_map_set_int64 (map,1000000);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* create and delete a key */
_stp_map_key_str (map, "1024");
@@ -43,14 +43,14 @@ int main ()
_stp_map_key_str (map, "1024");
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* create and delete a key again*/
_stp_map_key_str (map, "1024");
_stp_map_set_int64 (map, 2048);
_stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* check that unset values are 0 */
_stp_map_key_str (map, "California");
@@ -58,15 +58,15 @@ int main ()
/* map[California] = 3 */
_stp_map_set (map, 3);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* test an empty string as key */
_stp_map_key (map, "");
_stp_map_set_int64 (map, 7777);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
_stp_map_key (map, "");
_stp_map_set_int64 (map, 8888);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* add 4 new entries, pushing the others out */
int i;
@@ -78,7 +78,7 @@ int main ()
_stp_map_set_int64 (map, 100 + i);
}
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* 5, 382, 526, and 903 all hash to the same value (23) */
@@ -88,24 +88,24 @@ int main ()
_stp_map_key (map, "526"); _stp_map_set_int64 (map, 1526);
_stp_map_key (map, "903"); _stp_map_set_int64 (map, 1903);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
/* now delete all 4 nodes, one by one */
_stp_map_key (map, "382"); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
_stp_map_key (map, "5"); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
_stp_map_key (map, "903"); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
_stp_map_key (map, "526"); _stp_map_key_del (map);
- _stp_map_print (map, "map");
+ _stp_map_print (map, "map[%1s] = %d");
_stp_map_del (map);
return 0;
diff --git a/runtime/tests/maps/test_list_int64.c b/runtime/tests/maps/test_list_int64.c
index 4355cb45..810a18b6 100644
--- a/runtime/tests/maps/test_list_int64.c
+++ b/runtime/tests/maps/test_list_int64.c
@@ -20,23 +20,23 @@ int main ()
_stp_list_add_int64 (map, (int64_t)i);
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %d");
printf ("size is %d\n\n", _stp_list_size(map));
/* we set a limit of 10 elements so these */
/* won't be added to the list */
for (i = 50; i < 55; i++)
_stp_list_add_int64 (map, i);
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %d");
_stp_list_clear (map);
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %d");
for (i = 50; i < 55; i++)
_stp_list_add_int64 (map, i);
- _stp_map_print(map, "newlist");
+ _stp_map_print(map, "newlist[%1d] = %d");
_stp_map_del (map);
diff --git a/runtime/tests/maps/test_list_string.c b/runtime/tests/maps/test_list_string.c
index 5edae41f..455e8537 100644
--- a/runtime/tests/maps/test_list_string.c
+++ b/runtime/tests/maps/test_list_string.c
@@ -24,7 +24,7 @@ int main ()
_stp_list_add_str (map, buf);
}
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %s");
printf ("size is %d\n\n", _stp_list_size(map));
/* we set a limit of 10 elements so these */
@@ -34,18 +34,18 @@ int main ()
sprintf (buf, "Item%d", i);
_stp_list_add_str (map, buf);
}
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %s");
_stp_list_clear (map);
- _stp_map_print(map, "list");
+ _stp_map_print(map, "list[%1d] = %s");
for (i = 50; i < 55; i++)
{
sprintf (buf, "Item%d", i);
_stp_list_add_str (map, buf);
}
- _stp_map_print(map, "newlist");
+ _stp_map_print(map, "newlist[%1d] = %s");
_stp_map_del (map);