From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6940 invoked by alias); 17 Dec 2011 02:14:31 -0000 Received: (qmail 6933 invoked by uid 22791); 17 Dec 2011 02:14:30 -0000 X-SWARE-Spam-Status: No, hits=4.4 required=5.0 tests=AWL,BAYES_00,BOTNET,NO_DNS_FOR_FROM,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC X-Spam-Check-By: sourceware.org Received: from cpe-071-070-225-064.nc.res.rr.com (HELO localhost.localdomain) (71.70.225.64) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 17 Dec 2011 02:14:17 +0000 Received: from localhost.localdomain (cannondale [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.4) with ESMTP id pBGJptW6021370; Fri, 16 Dec 2011 14:51:55 -0500 Received: (from wcohen@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) id pBGJptie021369; Fri, 16 Dec 2011 14:51:55 -0500 From: William Cohen To: systemtap@sourceware.org Cc: William Cohen Subject: [PATCH 2/2] Add a test for the speculative.stp tapset Date: Sat, 17 Dec 2011 14:27:00 -0000 Message-Id: <1324065101-21332-2-git-send-email-wcohen@redhat.com> In-Reply-To: <1324065101-21332-1-git-send-email-wcohen@redhat.com> References: <1324065101-21332-1-git-send-email-wcohen@redhat.com> X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2011-q4/txt/msg00386.txt.bz2 A simple test to make sure that the speculative.stp tapset can be compiled and used. Signed-off-by: William Cohen --- testsuite/systemtap.speculate/speculate.c | 34 ++++++++++++++++++++ testsuite/systemtap.speculate/speculate.exp | 27 ++++++++++++++++ testsuite/systemtap.speculate/speculate.stp | 44 +++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 0 deletions(-) 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 0000000..6eadec1 --- /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 0000000..8e484bb --- /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 0000000..c2ba229 --- /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]) +} -- 1.7.1