From e44cf9f078d5180120a87d74b4b06c2daf0f5c1f Mon Sep 17 00:00:00 2001 From: William Cohen Date: Fri, 16 Dec 2011 14:47:00 -0500 Subject: [PATCH] Add a test for the speculative.stp tapset A simple test to make sure that the speculative.stp tapset can be compiled and used. --- testsuite/systemtap.speculate/speculate.c | 34 ++++++++++++++++ testsuite/systemtap.speculate/speculate.exp | 27 +++++++++++++ testsuite/systemtap.speculate/speculate.stp | 44 +++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 testsuite/systemtap.speculate/speculate.c create mode 100644 testsuite/systemtap.speculate/speculate.exp create mode 100644 testsuite/systemtap.speculate/speculate.stp diff --git a/testsuite/systemtap.speculate/speculate.c b/testsuite/systemtap.speculate/speculate.c new file mode 100644 index 000000000..6eadec11a --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.c @@ -0,0 +1,34 @@ +/* program to exercise spec_example.stp */ + +#include +#include +#include + +#include +#include +#include + +#define BOGUS NULL +#define MAXSIZE 512 +static char buf1[MAXSIZE]; +static char buf2[MAXSIZE]; + +main (int argc, char ** argv) +{ + int fbad = open("/tmp/junky_bad", O_CREAT|O_RDWR, 0660); + int fokay = open("/tmp/junky_good", O_CREAT|O_RDWR, 0660); + + if (fbad < 0) return(EXIT_FAILURE); + if (fokay < 0) return(EXIT_FAILURE); + + write(fokay, buf1, MAXSIZE); + write(fokay, buf1, MAXSIZE); + write(fbad, buf2, MAXSIZE); + write(fokay, buf2, MAXSIZE); + write(fokay, buf1, MAXSIZE); + write(fbad, buf1, MAXSIZE); + write(fbad, BOGUS, MAXSIZE); + write(fokay, buf1, MAXSIZE); + + return(EXIT_SUCCESS); +} diff --git a/testsuite/systemtap.speculate/speculate.exp b/testsuite/systemtap.speculate/speculate.exp new file mode 100644 index 000000000..8e484bb1e --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.exp @@ -0,0 +1,27 @@ +set test speculate + +catch {exec gcc -g -o $test $srcdir/$subdir/$test.c} err +if {$err == "" && [file exists $test]} then { pass "$test compile" } else { fail "$test compile" } + +set rc [stap_run_batch $srcdir/$subdir/$test.stp] +if {$rc == 0} then { pass "$test -p4" } else { fail "$test -p4" } + +if {! [installtest_p]} { + catch {exec rm -f $test} + untested "$test -p5" + return +} + +spawn stap $srcdir/$subdir/$test.stp -c ./$test +set ok 0 +expect { + -timeout 60 + -re {^open[^\r\n]*\r\n} { incr ok; exp_continue } + -re {^write[^\r\n]*\r\n} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +catch { close } +wait +if {$ok == 4} then { pass "$test -p5" } else { fail "$test -p5 ($ok)" } +exec rm -f $test diff --git a/testsuite/systemtap.speculate/speculate.stp b/testsuite/systemtap.speculate/speculate.stp new file mode 100644 index 000000000..c2ba22919 --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.stp @@ -0,0 +1,44 @@ +#! stap -p4 + +# test to exercise the speculative.stp tapset +# shows file operations for a file that later had a read or write problem. + +global file_desc + +probe syscall.open.return +{ + if (pid() != target()) next + file_desc[$return] = speculation() + speculate(file_desc[$return], sprintf("open(%s) = %d\n", + user_string($filename), $return)) +} + +probe syscall.close.return +{ + if (pid() != target()) next + if (! ($fd in file_desc)) next + + if ($return < 0) + commit(file_desc[$fd]) + else + discard(file_desc[$fd]) + delete file_desc[$fd] +} + +probe syscall.read.return { + if (pid() != target()) next + if (! ($fd in file_desc)) next + + speculate(file_desc[$fd], sprintf("read(%d, %p, %d) = %d\n", + $fd, $buf, $count, $return)) + if ($return < 0) commit(file_desc[$fd]) +} + +probe syscall.write.return { + if (pid() != target()) next + if (! ($fd in file_desc)) next + + speculate(file_desc[$fd], sprintf("write(%d, %p, %d) = %d\n", + $fd, $buf, $count, $return)) + if ($return < 0) commit(file_desc[$fd]) +} -- 2.43.5