summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/systemtap.base')
-rw-r--r--testsuite/systemtap.base/array_string.exp45
-rw-r--r--testsuite/systemtap.base/global_end.exp3
-rw-r--r--testsuite/systemtap.base/global_end.stp4
-rw-r--r--testsuite/systemtap.base/overflow-get_argv.exp5
-rw-r--r--testsuite/systemtap.base/overflow-get_argv.stp62
-rw-r--r--testsuite/systemtap.base/procfs_write.exp135
6 files changed, 252 insertions, 2 deletions
diff --git a/testsuite/systemtap.base/array_string.exp b/testsuite/systemtap.base/array_string.exp
new file mode 100644
index 00000000..92df1149
--- /dev/null
+++ b/testsuite/systemtap.base/array_string.exp
@@ -0,0 +1,45 @@
+# PR 11220. Make sure we can store large strings in arrays.
+
+if {![installtest_p]} { untested $test; return }
+
+set test "ARRAY_STRING"
+
+set test_script {
+ global str
+ global str_array[1]
+
+ probe begin {
+ str = " 0:123456789+123456789+123456789+123456789+123456789+123456789 1:123456789+123456789+123456789+123456789+123456789+123456789 2:123456789+123456789+123456789+123456789+123456789+123456789 3:123456789+123456789+123456789+123456789+123456789+123456789 4:123456789+123456789+123456789+123456789+123456789+123456789 5:123456789+123456789+123456789+123456789+123456789+123456789 6:123456789+123456789+123456789+123456789+123456789+123456789 7:123456789+123456789+123456789+123456789+123456789+123456789"
+ str_array[0] = str
+ printf("systemtap starting probe\n")
+ }
+
+ probe end {
+ printf("systemtap ending probe\n")
+ if (strlen(str) < 500) {
+ printf("string str is too short: %d\n", strlen(str))
+ printf("%s\n", str)
+ }
+ if (strlen(str) == strlen(str_array[0])) {
+ printf("string lengths match\n")
+ }
+ else {
+ printf("string lengths *don't* match\n")
+ printf("str: %d\n", strlen(str))
+ printf("str_array[0]: %d\n", strlen(str_array[0]))
+ }
+ if (str_array[0] == str) {
+ printf("strings match\n")
+ }
+ else {
+ printf("strings *don't* match!\n")
+ printf("str: %s\n", str)
+ printf("str_array[0]: %s\n", str_array[0])
+ }
+ }
+}
+
+set output "string lengths match\r\nstrings match\r\n"
+
+# Set MAXSTRINGLEN to 512 to be sure we're testing what we intend.
+stap_run $test no_load $output -DMAXSTRINGLEN=512 -e $test_script
diff --git a/testsuite/systemtap.base/global_end.exp b/testsuite/systemtap.base/global_end.exp
index d245212f..9d9c8d9b 100644
--- a/testsuite/systemtap.base/global_end.exp
+++ b/testsuite/systemtap.base/global_end.exp
@@ -19,6 +19,7 @@ expect {
-re {epsilon."one",1. @count=0x4 @min=0x1 @max=0x4 @sum=0xa @avg=0x2} { incr ok; exp_continue }
-re {epsilon."two",2. @count=0x4 @min=0xa @max=0x28 @sum=0x64 @avg=0x19} { incr ok; exp_continue }
-re {phi @count=0x4 @min=0x1 @max=0x4 @sum=0xa @avg=0x2} { incr ok; exp_continue }
+ -re {var=0x1} { incr ok; exp_continue }
timeout { fail "$test (timeout)" }
eof { }
}
@@ -32,4 +33,4 @@ expect {
-re {Avg time = [1-9]} { incr ok; exp_continue }
}
-if {$ok == 12} { pass "$test ($ok)" } { fail "$test ($ok)" }
+if {$ok == 13} { pass "$test ($ok)" } { fail "$test ($ok)" }
diff --git a/testsuite/systemtap.base/global_end.stp b/testsuite/systemtap.base/global_end.stp
index 4a5baff7..1f707d54 100644
--- a/testsuite/systemtap.base/global_end.stp
+++ b/testsuite/systemtap.base/global_end.stp
@@ -1,4 +1,4 @@
-global alpha, beta, gamma, iota, epsilon, phi
+global alpha, beta, gamma, iota, epsilon, phi, var
probe begin {
gamma = "abcdefghijklmnopqrstuvwxyz"
@@ -29,6 +29,8 @@ probe begin {
epsilon["two",2] <<< 20
epsilon["two",2] <<< 30
epsilon["two",2] <<< 40
+
+ var++
}
probe timer.ms(100) {
diff --git a/testsuite/systemtap.base/overflow-get_argv.exp b/testsuite/systemtap.base/overflow-get_argv.exp
new file mode 100644
index 00000000..ac7fddc5
--- /dev/null
+++ b/testsuite/systemtap.base/overflow-get_argv.exp
@@ -0,0 +1,5 @@
+# PR11234: __get_argv can overflow its return buffer
+
+set test "overflow-get_argv"
+
+stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string -g -c "/bin/true /usr/bin/*"
diff --git a/testsuite/systemtap.base/overflow-get_argv.stp b/testsuite/systemtap.base/overflow-get_argv.stp
new file mode 100644
index 00000000..159ef4a8
--- /dev/null
+++ b/testsuite/systemtap.base/overflow-get_argv.stp
@@ -0,0 +1,62 @@
+// PR11234: __get_argv can overflow its return buffer
+
+// __get_argv has a signature like this:
+// struct function___get_argv_locals {
+// int64_t a;
+// int64_t first;
+// string_t __retvalue;
+// } function___get_argv;
+//
+// These functions are meant to have an overlap such that we can tell if
+// __get_argv overran its __retvalue.
+//
+// int64_t x;
+// int64_t y;
+// string_t z;
+// string_t __retvalue;
+//
+// NB: __retvalue[0] always gets cleared on call, but the rest should be
+// untouched, so we can use it as a sentinal.
+
+function clear:string(x:long, y:long, z:string) %{
+ memset(THIS->__retvalue, 0, MAXSTRINGLEN);
+%}
+
+function check:string(x:long, y:long, z:string) %{
+ int i, bad = 0;
+ for (i=1; i<MAXSTRINGLEN; ++i)
+ if (THIS->__retvalue[i])
+ ++bad;
+
+ if (bad)
+ snprintf(THIS->__retvalue, MAXSTRINGLEN, "%d non-zero bytes", bad);
+ else
+ strlcpy(THIS->__retvalue, "ok", MAXSTRINGLEN);
+%}
+
+global result = "untested"
+
+probe syscall.execve {
+ if (pid() != target())
+ next
+
+ clear(0, 0, "")
+ foo = __get_argv($argv, 0)
+ result = check(0, 0, "")
+
+ // ensure that foo isn't optimized away
+ if (foo == "foo")
+ next
+}
+
+probe begin {
+ println("systemtap starting probe")
+}
+
+probe end {
+ println("systemtap ending probe")
+ if (result == "ok")
+ println("systemtap test success")
+ else
+ println("systemtap test failure: ", result)
+}
diff --git a/testsuite/systemtap.base/procfs_write.exp b/testsuite/systemtap.base/procfs_write.exp
new file mode 100644
index 00000000..5bb35532
--- /dev/null
+++ b/testsuite/systemtap.base/procfs_write.exp
@@ -0,0 +1,135 @@
+# PR 11223. Make sure we can handle large amounts of procfs write data.
+
+set test "PROCFS_WRITE"
+
+if {![installtest_p]} { untested $test; return }
+
+proc proc_write_value { test path value} {
+ if [catch {open $path WRONLY} channel] {
+ fail "$test $channel"
+ } else {
+ puts $channel $value
+ close $channel
+ pass "$test wrote $value"
+ }
+}
+
+# This test string is ~4224 bytes long (66 lines of 64 chars). The
+# procfs kernel system will use a buffer of 4K. Our string of ~4224
+# should take around 9 trips through the write function (4224 chars /
+# 512 bytes per systemtap string = ~9 trips).
+#
+# The kernel reuses the 4K buffer for the 9th trip and doesn't null
+# terminate the string. Instead, it tells consumers how many bytes
+# are present.
+#
+# We want to make sure we can handle > 4K worth of data properly.
+set test_string \
+" 0:12345678901234567890123456789012345678901234567890123456789
+ 1:12345678901234567890123456789012345678901234567890123456789
+ 2:12345678901234567890123456789012345678901234567890123456789
+ 3:12345678901234567890123456789012345678901234567890123456789
+ 4:12345678901234567890123456789012345678901234567890123456789
+ 5:12345678901234567890123456789012345678901234567890123456789
+ 6:12345678901234567890123456789012345678901234567890123456789
+ 7:12345678901234567890123456789012345678901234567890123456789
+ 8:12345678901234567890123456789012345678901234567890123456789
+ 9:12345678901234567890123456789012345678901234567890123456789
+ 10:12345678901234567890123456789012345678901234567890123456789
+ 11:12345678901234567890123456789012345678901234567890123456789
+ 12:12345678901234567890123456789012345678901234567890123456789
+ 13:12345678901234567890123456789012345678901234567890123456789
+ 14:12345678901234567890123456789012345678901234567890123456789
+ 15:12345678901234567890123456789012345678901234567890123456789
+ 16:12345678901234567890123456789012345678901234567890123456789
+ 17:12345678901234567890123456789012345678901234567890123456789
+ 18:12345678901234567890123456789012345678901234567890123456789
+ 19:12345678901234567890123456789012345678901234567890123456789
+ 20:12345678901234567890123456789012345678901234567890123456789
+ 21:12345678901234567890123456789012345678901234567890123456789
+ 22:12345678901234567890123456789012345678901234567890123456789
+ 23:12345678901234567890123456789012345678901234567890123456789
+ 24:12345678901234567890123456789012345678901234567890123456789
+ 25:12345678901234567890123456789012345678901234567890123456789
+ 26:12345678901234567890123456789012345678901234567890123456789
+ 27:12345678901234567890123456789012345678901234567890123456789
+ 28:12345678901234567890123456789012345678901234567890123456789
+ 29:12345678901234567890123456789012345678901234567890123456789
+ 30:12345678901234567890123456789012345678901234567890123456789
+ 31:12345678901234567890123456789012345678901234567890123456789
+ 32:12345678901234567890123456789012345678901234567890123456789
+ 33:12345678901234567890123456789012345678901234567890123456789
+ 34:12345678901234567890123456789012345678901234567890123456789
+ 35:12345678901234567890123456789012345678901234567890123456789
+ 36:12345678901234567890123456789012345678901234567890123456789
+ 37:12345678901234567890123456789012345678901234567890123456789
+ 38:12345678901234567890123456789012345678901234567890123456789
+ 39:12345678901234567890123456789012345678901234567890123456789
+ 40:12345678901234567890123456789012345678901234567890123456789
+ 41:12345678901234567890123456789012345678901234567890123456789
+ 42:12345678901234567890123456789012345678901234567890123456789
+ 43:12345678901234567890123456789012345678901234567890123456789
+ 44:12345678901234567890123456789012345678901234567890123456789
+ 45:12345678901234567890123456789012345678901234567890123456789
+ 46:12345678901234567890123456789012345678901234567890123456789
+ 47:12345678901234567890123456789012345678901234567890123456789
+ 48:12345678901234567890123456789012345678901234567890123456789
+ 49:12345678901234567890123456789012345678901234567890123456789
+ 50:12345678901234567890123456789012345678901234567890123456789
+ 51:12345678901234567890123456789012345678901234567890123456789
+ 52:12345678901234567890123456789012345678901234567890123456789
+ 53:12345678901234567890123456789012345678901234567890123456789
+ 54:12345678901234567890123456789012345678901234567890123456789
+ 55:12345678901234567890123456789012345678901234567890123456789
+ 56:12345678901234567890123456789012345678901234567890123456789
+ 57:12345678901234567890123456789012345678901234567890123456789
+ 58:12345678901234567890123456789012345678901234567890123456789
+ 59:12345678901234567890123456789012345678901234567890123456789
+ 60:12345678901234567890123456789012345678901234567890123456789
+ 61:12345678901234567890123456789012345678901234567890123456789
+ 62:12345678901234567890123456789012345678901234567890123456789
+ 63:12345678901234567890123456789012345678901234567890123456789
+ 64:12345678901234567890123456789012345678901234567890123456789
+ 65:12345678901234567890123456789012345678901234567890123456789
+ 66:12345678901234567890123456789012345678901234567890123456789"
+
+# Now we need the version of the above string that expect will look
+# for. So, we need to convert all '\n' to '\r\n' and add a trailing
+# '\r\n'.
+regsub -all {\n} $test_string {\r\n} test_string2
+set test_string2 "$test_string2\\r\\n"
+
+proc proc_write_test {} {
+ global test test_string
+ set path "/proc/systemtap/$test/command"
+
+ proc_write_value $test $path $test_string
+ return 0;
+}
+
+set systemtap_write_script {
+ global iteration = 0
+ global saved_value[20]
+
+ probe procfs("command").write {
+ saved_value[iteration] = $value
+ iteration++
+ }
+
+ probe begin {
+ printf("systemtap starting probe\n")
+ }
+
+ probe end {
+ printf("systemtap ending probe\n")
+ for (i = 0; i < iteration; i++) {
+ printf("%s", saved_value[i])
+ }
+ }
+}
+
+# We're forcing the MAXSTRINGLEN to be 512 chars to make sure we know
+# what we're testing.
+stap_run $test proc_write_test $test_string2 -DMAXSTRINGLEN=512 \
+ -e $systemtap_write_script -m $test
+exec /bin/rm -f ${test}.ko