This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] Add a test for the speculative.stp tapset


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]