summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testsuite/ChangeLog4
-rw-r--r--testsuite/systemtap.context/args.stp39
-rw-r--r--testsuite/systemtap.context/args.tcl53
-rw-r--r--testsuite/systemtap.context/backtrace.stp24
-rw-r--r--testsuite/systemtap.context/backtrace.tcl63
-rw-r--r--testsuite/systemtap.context/context.exp59
-rw-r--r--testsuite/systemtap.context/makefile18
-rw-r--r--testsuite/systemtap.context/makefile28
-rw-r--r--testsuite/systemtap.context/systemtap_test_module1.c99
-rw-r--r--testsuite/systemtap.context/systemtap_test_module2.c77
10 files changed, 434 insertions, 0 deletions
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog
index f70bcc7b..3998b10c 100644
--- a/testsuite/ChangeLog
+++ b/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2007-07-02 Martin Hunt <hunt@redhat.com>
+
+ * systemtap.context/*: New context tests.
+
2007-06-25 Martin Hunt <hunt@redhat.com>
* systemtap.maps/pmap_agg_overflow.exp: Rewrite
diff --git a/testsuite/systemtap.context/args.stp b/testsuite/systemtap.context/args.stp
new file mode 100644
index 00000000..5d5208a2
--- /dev/null
+++ b/testsuite/systemtap.context/args.stp
@@ -0,0 +1,39 @@
+probe module("systemtap_test_module2").function("yyy_int") {
+ printf("yyy_int %d %d %d\n", $a, $b, $c)
+}
+probe module("systemtap_test_module2").function("yyy_int").return {
+ printf("yyy_int returns %d\n", $return)
+}
+probe module("systemtap_test_module2").function("yyy_uint") {
+ printf("yyy_uint %d %d %d\n", $a, $b, $c)
+}
+probe module("systemtap_test_module2").function("yyy_uint").return {
+ printf("yyy_uint returns %d\n", $return)
+}
+probe module("systemtap_test_module2").function("yyy_long") {
+ printf("yyy_long %d %d %d\n", $a, $b, $c)
+}
+probe module("systemtap_test_module2").function("yyy_long").return {
+ printf("yyy_long returns %d\n", $return)
+}
+probe module("systemtap_test_module2").function("yyy_int64") {
+ printf("yyy_int64 %d %d %d\n", $a, $b, $c)
+}
+probe module("systemtap_test_module2").function("yyy_int64").return {
+ printf("yyy_int64 returns %d\n", $return)
+}
+probe module("systemtap_test_module2").function("yyy_char") {
+ printf("yyy_char %d %d %d\n", $a, $b, $c)
+}
+probe module("systemtap_test_module2").function("yyy_char").return {
+ printf("yyy_char returns %d\n", $return)
+}
+probe module("systemtap_test_module2").function("yyy_str") {
+ printf("yyy_str %s-%s-%s\n", kernel_string($a), kernel_string($b), kernel_string($c))
+}
+probe module("systemtap_test_module2").function("yyy_str").return {
+ printf("yyy_str returns %s\n", kernel_string($return))
+}
+probe begin {
+ printf("READY\n")
+}
diff --git a/testsuite/systemtap.context/args.tcl b/testsuite/systemtap.context/args.tcl
new file mode 100644
index 00000000..d6b776de
--- /dev/null
+++ b/testsuite/systemtap.context/args.tcl
@@ -0,0 +1,53 @@
+spawn stap args.stp
+expect {
+ -timeout 240
+ "READY" {
+ puts "READY"
+ exec echo 1 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_int -1 200 300\r\nyyy_int returns 499\r\n" {
+ pass "integer function arguments"
+ }
+ }
+ exec echo 2 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_uint 4294967295 200 300\r\nyyy_uint returns 499\r\n" {
+ pass "unsigned function arguments"
+ }
+ }
+ exec echo 3 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_long -1 200 300\r\nyyy_long returns 499\r\n" {
+ pass "long function arguments"
+ }
+ }
+ exec echo 4 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_int64 -1 200 300\r\nyyy_int64 returns 499\r\n" {
+ pass "int64 function arguments"
+ }
+ }
+ exec echo 5 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_char 97 98 99\r\nyyy_char returns 81\r\n" {
+ pass "char function arguments"
+ }
+ }
+ exec echo 6 > /proc/stap_test_cmd
+ expect {
+ -timeout 5
+ "yyy_str Hello-System-Tap\r\nyyy_str returns XYZZY\r\n" {
+ pass "string function arguments"
+ }
+ }
+ }
+ eof {}
+}
+send "\003"
+close
+wait
diff --git a/testsuite/systemtap.context/backtrace.stp b/testsuite/systemtap.context/backtrace.stp
new file mode 100644
index 00000000..8f02c174
--- /dev/null
+++ b/testsuite/systemtap.context/backtrace.stp
@@ -0,0 +1,24 @@
+function print_all_trace_info() {
+ printf("backtrace from %s:\n", pp())
+ print_backtrace()
+ print("--------\n")
+ bt = backtrace()
+ printf("the stack is %s\n", bt)
+ print("--------\n")
+ print_stack(bt);
+ print("--------\n")
+}
+
+probe begin {
+ print_backtrace()
+}
+
+probe end {
+ print_backtrace()
+}
+
+probe module("systemtap_test_module2").function("yyy_func3") {
+ print_all_trace_info()
+}
+
+
diff --git a/testsuite/systemtap.context/backtrace.tcl b/testsuite/systemtap.context/backtrace.tcl
new file mode 100644
index 00000000..98a765a2
--- /dev/null
+++ b/testsuite/systemtap.context/backtrace.tcl
@@ -0,0 +1,63 @@
+set m1 0
+set m2 0
+
+spawn stap backtrace.stp
+#exp_internal 1
+expect {
+ -timeout 240
+ "Systemtap probe: begin\r\n" {
+ pass "backtrace of begin probe"
+ exec echo 0 > /proc/stap_test_cmd
+ exp_continue
+ }
+ -re {^backtrace from module\(\"systemtap_test_module2\"\)\.function\(\"yyy_func3@[^\r\n]+\r\n} {
+ incr m1
+ expect {
+ -timeout 5
+ -re {^ 0x[a-f0-9]+ : yyy_func3[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m1 == 1} {incr m1}
+ exp_continue
+ }
+ -re {^ 0x[a-f0-9]+ : yyy_func2[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m1 == 2} {incr m1}
+ exp_continue
+ }
+ -re {^ 0x[a-f0-9]+ : yyy_func1[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m1 == 3} {incr m1}
+ }
+ }
+ exp_continue
+ }
+ -re {.*---\r\nthe stack is 0x[a-f0-9]+ [^\r\n]+\r\n} {
+ incr m2
+ expect {
+ -timeout 5
+ -re {.*0x[a-f0-9]+ : yyy_func3[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m2 == 1} {incr m2}
+ exp_continue
+ }
+ -re {^ 0x[a-f0-9]+ : yyy_func2[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m2 == 2} {incr m2}
+ exp_continue
+ }
+ -re {^ 0x[a-f0-9]+ : yyy_func1[^\[]+\[systemtap_test_module2\]\r\n} {
+ if {$m2 == 3} {incr m2}
+ }
+ }
+ }
+ eof {fail "backtrace of yyy_func3. unexpected EOF" }
+}
+send "\003"
+if {$m1 == 4} {
+ pass "backtrace of yyy_func3"
+} else {
+ fail "backtrace of yyy_func3"
+}
+if {$m2 == 4} {
+ pass "print_stack of yyy_func3"
+} else {
+ fail "print_stack of yyy_func3 ($m2)"
+}
+
+close
+wait
diff --git a/testsuite/systemtap.context/context.exp b/testsuite/systemtap.context/context.exp
new file mode 100644
index 00000000..f4b34fba
--- /dev/null
+++ b/testsuite/systemtap.context/context.exp
@@ -0,0 +1,59 @@
+set testlist {backtrace args}
+
+if {![installtest_p]} {
+ foreach test $testlist {
+ untested $test
+ }
+ return
+}
+
+proc cleanup {} {
+ catch {send "\003"}
+ foreach n {1 2} {
+ catch {exec sudo /bin/rm -f /lib/modules/$::uname/systemtap_test_module$n.ko}
+ catch {exec sudo /sbin/rmmod systemtap_test_module$n}
+ }
+}
+
+proc build_modules {} {
+ foreach n {1 2} {
+ exec cp makefile$n Makefile
+ if {[catch {exec make clean} res]} {
+ puts $res
+ return 0
+ }
+ catch {exec make} res
+ if {![file exists systemtap_test_module$n.ko]} {
+ puts $res
+ return 0
+ }
+ if {[catch {exec sudo cp systemtap_test_module$n.ko /lib/modules/$::uname} res]} {
+ puts $res
+ return 0
+ }
+ }
+ foreach n {2 1} {
+ catch {exec sudo /sbin/insmod systemtap_test_module$n.ko}
+ }
+ return 1
+}
+
+# first build the modules
+cd $srcdir/$subdir
+set uname [exec /bin/uname -r]
+
+if {[build_modules] == 0} {
+ puts "BUILD FAILED"
+ foreach test $testlist {
+ fail "$test - could not build modules"
+ }
+ return
+}
+
+foreach test $testlist {
+ source $test.tcl
+}
+
+
+
+
diff --git a/testsuite/systemtap.context/makefile1 b/testsuite/systemtap.context/makefile1
new file mode 100644
index 00000000..73b6f1a2
--- /dev/null
+++ b/testsuite/systemtap.context/makefile1
@@ -0,0 +1,8 @@
+obj-m := systemtap_test_module1.o
+KDIR := /lib/modules/$(shell uname -r)/build
+PWD := $(shell pwd)
+default:
+ $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+clean:
+ rm -f *.mod.c systemtap_test_module1.ko *.o .*.cmd Modules.symvers
+ rm -rf .tmp_versions
diff --git a/testsuite/systemtap.context/makefile2 b/testsuite/systemtap.context/makefile2
new file mode 100644
index 00000000..de87cc90
--- /dev/null
+++ b/testsuite/systemtap.context/makefile2
@@ -0,0 +1,8 @@
+obj-m := systemtap_test_module2.o
+KDIR := /lib/modules/$(shell uname -r)/build
+PWD := $(shell pwd)
+default:
+ $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+clean:
+ rm -f *.mod.c systemtap_test_module2.ko *.o .*.cmd Modules.symvers
+ rm -rf .tmp_versions
diff --git a/testsuite/systemtap.context/systemtap_test_module1.c b/testsuite/systemtap.context/systemtap_test_module1.c
new file mode 100644
index 00000000..cfa76cf0
--- /dev/null
+++ b/testsuite/systemtap.context/systemtap_test_module1.c
@@ -0,0 +1,99 @@
+/* -*- linux-c -*-
+ * Systemtap Test Module 1
+ * Copyright (C) 2007 Red Hat Inc.
+ *
+ * This file is part of systemtap, and is free software. You can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License (GPL); either version 2, or (at your option) any
+ * later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/compiler.h>
+#include <asm/uaccess.h>
+
+/* The purpose of this module is to provide a bunch of functions that */
+/* do nothing important, and then call them in different contexts. */
+/* We use a /proc file to trigger function calls from user context. */
+/* Then systemtap scripts set probes on the functions and run tests */
+/* to see if the expected output is received. This is better than using */
+/* the kernel because kernel internals frequently change. */
+
+/** These functions are in module 2 **/
+/* They are there to prevent compiler optimization from */
+/* optimizing away functions. */
+int yyy_func1 (int);
+int yyy_int (int,int,int);
+unsigned yyy_uint (unsigned,unsigned,unsigned);
+long yyy_long (long,long,long);
+int64_t yyy_int64 (int64_t,int64_t,int64_t);
+char yyy_char(char, char, char);
+char *yyy_str(char *, char *, char *);
+
+/************ Below are the functions to create this module ************/
+
+static struct proc_dir_entry *stm_ctl = NULL;
+
+static ssize_t stm_write_cmd (struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ char type;
+
+ if (get_user(type, (int __user *)buf))
+ return -EFAULT;
+
+ switch (type) {
+ case '0':
+ yyy_func1(1234);
+ break;
+ case '1':
+ yyy_int(-1, 200, 300);
+ break;
+ case '2':
+ yyy_uint((unsigned)-1, 200, 300);
+ break;
+ case '3':
+ yyy_long(-1L, 200L, 300L);
+ break;
+ case '4':
+ yyy_int64(-1, 200, 300);
+ break;
+ case '5':
+ yyy_char('a', 'b', 'c');
+ break;
+ case '6':
+ yyy_str("Hello", "System", "Tap");
+ break;
+ default:
+ printk ("systemtap_bt_test_module: invalid command type %d\n", type);
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static struct file_operations stm_fops_cmd = {
+ .owner = THIS_MODULE,
+ .write = stm_write_cmd,
+};
+
+int init_module(void)
+{
+
+ stm_ctl = create_proc_entry ("stap_test_cmd", 0666, NULL);
+ if (stm_ctl == NULL)
+ return -1;;
+ stm_ctl->proc_fops = &stm_fops_cmd;
+ return 0;
+}
+
+void cleanup_module(void)
+{
+ if (stm_ctl)
+ remove_proc_entry ("stap_test_cmd", NULL);
+}
+
+MODULE_DESCRIPTION("systemtap backtrace test module1");
+MODULE_LICENSE("GPL");
diff --git a/testsuite/systemtap.context/systemtap_test_module2.c b/testsuite/systemtap.context/systemtap_test_module2.c
new file mode 100644
index 00000000..35a28efb
--- /dev/null
+++ b/testsuite/systemtap.context/systemtap_test_module2.c
@@ -0,0 +1,77 @@
+/* -*- linux-c -*-
+ * Systemtap Test Module 2
+ * Copyright (C) 2007 Red Hat Inc.
+ *
+ * This file is part of systemtap, and is free software. You can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License (GPL); either version 2, or (at your option) any
+ * later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/compiler.h>
+
+/* The purpose of this module is to provide a bunch of functions that */
+/* do nothing important, and then call them in different contexts. */
+/* We use a /proc file to trigger function calls from user context. */
+/* Then systemtap scripts set probes on the functions and run tests */
+/* to see if the expected output is received. */
+
+/** Here are all the functions we will probe **/
+
+/* some nested functions to test backtraces */
+int noinline yyy_func3 (int foo) {
+ return foo + 1;
+}
+int noinline yyy_func2 (int foo) {
+ foo = yyy_func3(foo);
+ return foo + 1;
+}
+
+int noinline yyy_func1 (int foo) {
+ foo = yyy_func2(foo);
+ return foo + 1;
+}
+EXPORT_SYMBOL(yyy_func1);
+
+/* 1. int argument testing */
+int noinline yyy_int(int a, int b, int c)
+{
+ return a+b+c;
+}
+/* 2. uint argument testing */
+unsigned noinline yyy_uint(unsigned a, unsigned b, unsigned c)
+{
+ return a+b+c;
+}
+/* 3. long argument testing */
+long noinline yyy_long(long a, long b, long c)
+{
+ return a+b+c;
+}
+/* 4. int64_t argument testing */
+int noinline yyy_int64(int64_t a, int64_t b, int64_t c)
+{
+ return a+b+c;
+}
+/* 5. char argument testing */
+char noinline yyy_char(char a, char b, char c)
+{
+ return 'Q';
+}
+/* 5. string argument testing */
+char * noinline yyy_str(char *a, char *b, char *c)
+{
+ return "XYZZY";
+}
+
+EXPORT_SYMBOL(yyy_int);
+EXPORT_SYMBOL(yyy_uint);
+EXPORT_SYMBOL(yyy_long);
+EXPORT_SYMBOL(yyy_int64);
+EXPORT_SYMBOL(yyy_char);
+EXPORT_SYMBOL(yyy_str);
+
+MODULE_DESCRIPTION("systemtap backtrace test module2");
+MODULE_LICENSE("GPL");