From: William Cohen <wcohen@redhat.com>
To: systemtap@sourceware.org
Cc: William Cohen <wcohen@redhat.com>
Subject: [PATCH 2/2] Add a test for the speculative.stp tapset
Date: Sat, 17 Dec 2011 14:27:00 -0000 [thread overview]
Message-ID: <1324065101-21332-2-git-send-email-wcohen@redhat.com> (raw)
In-Reply-To: <1324065101-21332-1-git-send-email-wcohen@redhat.com>
A simple test to make sure that the speculative.stp tapset can be compiled
and used.
Signed-off-by: William Cohen <wcohen@redhat.com>
---
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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#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
prev parent reply other threads:[~2011-12-17 2:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-17 2:14 [PATCH 1/2] Add " William Cohen
2011-12-17 14:27 ` William Cohen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324065101-21332-2-git-send-email-wcohen@redhat.com \
--to=wcohen@redhat.com \
--cc=systemtap@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).