summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2005-05-19 05:25:26 +0000
committerhunt <hunt>2005-05-19 05:25:26 +0000
commit7edfd9e24568502f54175b08da4168f2af6642fe (patch)
treeaa2d578a4d7d99fef111a179e51a90198be0f2c1
parent752870c4bea5f43859ec4e10ae2579018908bbe3 (diff)
downloadsystemtap-steved-7edfd9e24568502f54175b08da4168f2af6642fe.tar.gz
systemtap-steved-7edfd9e24568502f54175b08da4168f2af6642fe.tar.xz
systemtap-steved-7edfd9e24568502f54175b08da4168f2af6642fe.zip
Add String test files.
-rw-r--r--runtime/tests/string/Makefile5
-rw-r--r--runtime/tests/string/all.tcl12
-rw-r--r--runtime/tests/string/print_cstr.c56
-rw-r--r--runtime/tests/string/printf_A.c56
-rw-r--r--runtime/tests/string/printf_B.c37
-rw-r--r--runtime/tests/string/string.test88
-rw-r--r--runtime/tests/string/string1.c44
-rw-r--r--runtime/tests/string/string2.c68
-rw-r--r--runtime/tests/string/string3.c45
9 files changed, 411 insertions, 0 deletions
diff --git a/runtime/tests/string/Makefile b/runtime/tests/string/Makefile
new file mode 100644
index 00000000..c396c132
--- /dev/null
+++ b/runtime/tests/string/Makefile
@@ -0,0 +1,5 @@
+default: tests
+
+tests:
+ tclsh all.tcl
+
diff --git a/runtime/tests/string/all.tcl b/runtime/tests/string/all.tcl
new file mode 100644
index 00000000..aa408eea
--- /dev/null
+++ b/runtime/tests/string/all.tcl
@@ -0,0 +1,12 @@
+package require tcltest
+namespace import -force tcltest::*
+
+puts "Running all SystemTap tests"
+
+#puts [tcltest::configure]
+#puts [tcltest::configure -file]
+
+tcltest::testsDirectory [file dir [info script]]
+tcltest::runAllTests
+
+puts "All tests completed"
diff --git a/runtime/tests/string/print_cstr.c b/runtime/tests/string/print_cstr.c
new file mode 100644
index 00000000..2de0f592
--- /dev/null
+++ b/runtime/tests/string/print_cstr.c
@@ -0,0 +1,56 @@
+/* test of _stp_print_cstr() */
+
+/* use very small buffer size for testing */
+#define STP_PRINT_BUF_LEN 20
+#include "runtime.h"
+
+int main ()
+{
+ /* can we see output? */
+ _stp_print_cstr("ABCDE\n");
+ _stp_print_flush();
+
+
+ /* overflow */
+ _stp_print_cstr("1234567890123456789012345\n");
+ _stp_print_cstr("XYZZY\n");
+ _stp_print_flush();
+
+ /* small string then overflow string */
+ _stp_print_cstr("XYZZY\n");
+ _stp_print_cstr("1234567890123456789012345");
+ _stp_print_cstr("\n");
+ _stp_print_flush();
+
+ /* two small string that overflow */
+ _stp_print_cstr("abcdefghij");
+ _stp_print_cstr("1234567890");
+ _stp_print_cstr("\n");
+ _stp_print_flush();
+
+ /* two small string that overflow */
+ _stp_print_cstr("abcdefghij");
+ _stp_print_cstr("1234567890X");
+ _stp_print_cstr("\n");
+ _stp_print_flush();
+
+ _stp_print_cstr("12345\n");
+ _stp_print_cstr("67890\n");
+ _stp_print_cstr("abcde\n");
+ _stp_print_flush();
+ _stp_print_flush();
+ _stp_print_cstr("12345");
+ _stp_print_cstr("67890");
+ _stp_print_cstr("abcde");
+ _stp_print_cstr("fghij");
+ _stp_print_cstr("\n");
+ _stp_print_flush();
+
+ /* null string */
+ _stp_print_cstr("");
+ _stp_print_flush();
+ _stp_print_cstr("");
+ _stp_print_cstr("Q\n");
+ _stp_print_flush();
+ return 0;
+}
diff --git a/runtime/tests/string/printf_A.c b/runtime/tests/string/printf_A.c
new file mode 100644
index 00000000..e6c1a93f
--- /dev/null
+++ b/runtime/tests/string/printf_A.c
@@ -0,0 +1,56 @@
+/* basic printf tests */
+
+/* use very small buffer size for testing */
+#define STP_PRINT_BUF_LEN 20
+#include "runtime.h"
+
+int main ()
+{
+ /* can we see output? */
+ _stp_printf("ABCDE\n");
+ _stp_print_flush();
+
+
+ /* overflow */
+ _stp_printf("1234567890123456789012345\n");
+ _stp_printf("XYZZY\n");
+ _stp_print_flush();
+
+ /* small string then overflow string */
+ _stp_printf("XYZZY\n");
+ _stp_printf("1234567890123456789012345");
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ /* two small string that overflow */
+ _stp_printf("abcdefghij");
+ _stp_printf("1234567890");
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ /* two small string that overflow */
+ _stp_printf("abcdefghij");
+ _stp_printf("1234567890X");
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ _stp_printf("12345\n");
+ _stp_printf("67890\n");
+ _stp_printf("abcde\n");
+ _stp_print_flush();
+ _stp_print_flush();
+ _stp_printf("12345");
+ _stp_printf("67890");
+ _stp_printf("abcde");
+ _stp_printf("fghij");
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ /* null string */
+ _stp_printf("");
+ _stp_print_flush();
+ _stp_printf("");
+ _stp_printf("Q\n");
+ _stp_print_flush();
+ return 0;
+}
diff --git a/runtime/tests/string/printf_B.c b/runtime/tests/string/printf_B.c
new file mode 100644
index 00000000..b9bbe170
--- /dev/null
+++ b/runtime/tests/string/printf_B.c
@@ -0,0 +1,37 @@
+/* more printf tests */
+
+/* use very small buffer size for testing */
+#define STP_PRINT_BUF_LEN 20
+#include "runtime.h"
+
+#define LLONG_MAX 9223372036854775807LL
+#define LLONG_MIN (-LLONG_MAX - 1LL)
+
+
+int main ()
+{
+ int i;
+
+ /* a couple of loops showing continuous output */
+ for (i = 0; i < 20; i++)
+ _stp_sprintf(_stp_stdout, "i=%d ", i);
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ for (i = 0; i < 5; i++)
+ _stp_printf("[%d %d %d] ", i, i*i, i*i*i);
+ _stp_printf("\n");
+ _stp_print_flush();
+
+ int64_t x,y;
+ x = LLONG_MAX;
+ y = LLONG_MIN;
+
+ _stp_printf("%lld ",x);
+ _stp_printf("(%llx) ", x);
+ _stp_printf("%lld ",y);
+ _stp_printf("(%llx) ", y);
+ _stp_printf("\n");
+ _stp_print_flush();
+ return 0;
+}
diff --git a/runtime/tests/string/string.test b/runtime/tests/string/string.test
new file mode 100644
index 00000000..56d97760
--- /dev/null
+++ b/runtime/tests/string/string.test
@@ -0,0 +1,88 @@
+package require tcltest
+namespace import -force tcltest::*
+
+cd $tcltest::testsDirectory
+
+set CFLAGS "-Os"
+set KPATH "/lib/modules/[exec uname -r]/build/include"
+set PATH "../../user"
+
+test printf_A {Basic printf test} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test printf_A.c
+} -body {
+ exec ./test
+} -result {ABCDE
+12345678901234567890XYZZY
+XYZZY
+12345678901234567890
+abcdefghij1234567890
+abcdefghij1234567890X
+12345
+67890
+abcde
+1234567890abcdefghij
+Q}
+
+test printf_B {More printf test} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test printf_B.c
+} -body {
+ exec ./test
+} -result {i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 i=10 i=11 i=12 i=13 i=14 i=15 i=16 i=17 i=18 i=19
+[0 0 0] [1 1 1] [2 4 8] [3 9 27] [4 16 64]
+9223372036854775807 (7fffffffffffffff) -9223372036854775808(8000000000000000) }
+
+test print_cstr {Test of _stp_print_cstr()} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test print_cstr.c
+} -body {
+ exec ./test
+} -result {ABCDE
+12345678901234567890XYZZY
+XYZZY
+12345678901234567890
+abcdefghij1234567890
+abcdefghij1234567890X
+12345
+67890
+abcde
+1234567890abcdefghij
+Q}
+
+test string1 {Basic String test} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test string1.c
+} -body {
+ exec ./test
+} -result {Hello worldRed HatIntelIBM
+Hello world / Red Hat / Intel / IBM /
+Red Hat Inc.
+Hello world Red Hat
+IntelIBM}
+
+test string2 {More String tests} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test string2.c
+} -body {
+ exec ./test
+} -result {ABCDE
+1234567890123456789
+XYZZY
+1234567890123
+abcdefghij123456789
+abcdefghij123456789
+12345
+67890
+abcde
+1234567890abcdefghi
+Q}
+test string3 {Even More String tests} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -o test string3.c
+} -body {
+ exec ./test
+} -result {1234567890abcABCDEvwxyz
+abcde
+1234567890abcde
+1234567890abcdeABCD
+1234567890abcdeABCD
+ABCDEvwxyz}
+
+exec rm test
+
+cleanupTests
diff --git a/runtime/tests/string/string1.c b/runtime/tests/string/string1.c
new file mode 100644
index 00000000..48773e5f
--- /dev/null
+++ b/runtime/tests/string/string1.c
@@ -0,0 +1,44 @@
+/* test of Strings */
+
+/* use very small buffer size for testing */
+#define STP_PRINT_BUF_LEN 20
+#define STP_NUM_STRINGS 4
+#include "runtime.h"
+
+int main ()
+{
+ String str[4];
+ int i;
+
+ for (i = 0; i < 4; i++)
+ str[i] = _stp_string_init (i);
+
+ _stp_sprintf(str[0], "Hello world");
+ _stp_sprintf(str[1], "Red Hat");
+ _stp_sprintf(str[2], "Intel");
+ _stp_sprintf(str[3], "IBM");
+
+ for (i = 0; i < 4; i++)
+ _stp_print(str[i]);
+ _stp_print_cstr("\n");
+
+ for (i = 0; i < 4; i++) {
+ _stp_print(str[i]);
+ _stp_print(" / ");
+ }
+ _stp_print_cstr("\n");
+
+ _stp_string_cat_cstr (str[1], " Inc.");
+ _stp_print(str[1]);
+ _stp_print("\n");
+
+ _stp_string_cat_cstr (str[0], " ");
+ _stp_string_cat_string (str[0], str[1]);
+ _stp_print(str[0]);
+ _stp_print("\n");
+
+ _stp_sprintf(str[2], "%s\n", _stp_string_ptr(str[3]));
+ _stp_print(str[2]);
+ _stp_print_flush();
+ return 0;
+}
diff --git a/runtime/tests/string/string2.c b/runtime/tests/string/string2.c
new file mode 100644
index 00000000..ccf3997a
--- /dev/null
+++ b/runtime/tests/string/string2.c
@@ -0,0 +1,68 @@
+/* test of Strings */
+
+/* use very small buffer size for testing */
+#define STP_STRING_SIZE 20
+#define STP_NUM_STRINGS 1
+#include "runtime.h"
+
+int main ()
+{
+ String str = _stp_string_init (0);
+
+ /* can we see output? */
+ _stp_sprintf(str, "ABCDE\n");
+ _stp_print(str);
+
+
+ /* overflow */
+ str = _stp_string_init (0);
+ _stp_sprintf(str, "1234567890123456789012345\n");
+ _stp_sprintf(str, "XYZZY\n");
+ _stp_print(str);
+ _stp_printf("\n");
+
+ /* small string then overflow string */
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"XYZZY\n");
+ _stp_sprintf(str,"1234567890123456789012345");
+ _stp_print(str);
+ _stp_printf("\n");
+
+ /* two small string that overflow */
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"abcdefghij");
+ _stp_sprintf(str,"123456789");
+ _stp_print(str);
+ _stp_printf("\n");
+
+ /* two small string that overflow */
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"abcdefghij");
+ _stp_sprintf(str,"1234567890X");
+ _stp_print(str);
+ _stp_printf("\n");
+
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"12345\n");
+ _stp_sprintf(str,"67890\n");
+ _stp_sprintf(str,"abcde\n");
+ _stp_print(str);
+
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"12345");
+ _stp_sprintf(str,"67890");
+ _stp_sprintf(str,"abcde");
+ _stp_sprintf(str,"fghij");
+ _stp_print(str);
+ _stp_printf("\n");
+
+ /* null string */
+ str = _stp_string_init (0);
+ _stp_sprintf(str,"");
+ _stp_sprintf(str,"");
+ _stp_sprintf(str,"Q\n");
+ _stp_print(str);
+
+ _stp_print_flush();
+ return 0;
+}
diff --git a/runtime/tests/string/string3.c b/runtime/tests/string/string3.c
new file mode 100644
index 00000000..3982a8e1
--- /dev/null
+++ b/runtime/tests/string/string3.c
@@ -0,0 +1,45 @@
+/* test of Strings */
+
+/* use very small buffer size for testing */
+#define STP_STRING_SIZE 20
+#define STP_NUM_STRINGS 4
+#include "runtime.h"
+
+int main ()
+{
+ String str[4];
+ int i;
+
+ for (i = 0; i < 4; i++)
+ str[i] = _stp_string_init (i);
+
+ _stp_string_cat(str[0], "1234567890");
+ _stp_string_cat(str[1], "abc");
+ _stp_string_cat(str[2], "ABCDE");
+ _stp_string_cat(str[3], "vwxyz");
+
+ for (i = 0; i < 4; i++)
+ _stp_print(str[i]);
+ _stp_print("\n");
+
+ _stp_string_cat (str[1], "de");
+ _stp_print(str[1]);
+ _stp_print("\n");
+
+ _stp_string_cat(str[0], str[1]);
+ _stp_print(str[0]);
+ _stp_print("\n");
+
+ _stp_string_cat(str[0], str[2]);
+ _stp_print(str[0]);
+ _stp_print("\n");
+
+ _stp_string_cat(str[0], str[2]);
+ _stp_print(str[0]);
+ _stp_print("\n");
+
+ _stp_sprintf(str[2], "%s\n", _stp_string_ptr(str[3]));
+ _stp_print(str[2]);
+ _stp_print_flush();
+ return 0;
+}