summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testsuite/ChangeLog5
-rw-r--r--testsuite/systemtap.samples/gtod.c26
-rw-r--r--testsuite/systemtap.samples/gtod.exp40
-rwxr-xr-xtestsuite/systemtap.samples/gtod.sh4
-rw-r--r--testsuite/systemtap.samples/gtod.stp8
5 files changed, 83 insertions, 0 deletions
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog
index 06efa796..a95ebca0 100644
--- a/testsuite/ChangeLog
+++ b/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-09-27 Masami Hiramatsu <mhiramat@redhat.com>
+
+ PR3916
+ * systemtap.sample/gtod.*: New test for gettimeofday accuracy.
+
2007-09-25 Martin Hunt <hunt@redhat.com>
* systemtap.context/backtrace.tcl: Handle single line timer.profile
diff --git a/testsuite/systemtap.samples/gtod.c b/testsuite/systemtap.samples/gtod.c
new file mode 100644
index 00000000..abc08543
--- /dev/null
+++ b/testsuite/systemtap.samples/gtod.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+int main (int argc, char *argv[])
+{
+ int i;
+ struct timeval tv[100][2];
+ int us = 0;
+ if (argc == 2) us = atoi(argv[1]);
+ for (i=0; i<100; i++) {
+ gettimeofday(&tv[i][0], NULL);
+ setsid();
+ gettimeofday(&tv[i][1], NULL);
+ if (us) usleep(us);
+ }
+ for (i=0; i<100; i++) {
+ // change last 4 chars for correctly sorting even if the
+ // time stamps are completely same.
+ printf("%8d%06d :%02d appl\n", tv[i][0].tv_sec, tv[i][0].tv_usec, i);
+ printf("%8d%06d :%02d prog\n", tv[i][1].tv_sec, tv[i][1].tv_usec, i);
+ }
+ return 0;
+}
+
diff --git a/testsuite/systemtap.samples/gtod.exp b/testsuite/systemtap.samples/gtod.exp
new file mode 100644
index 00000000..a8f3c9d6
--- /dev/null
+++ b/testsuite/systemtap.samples/gtod.exp
@@ -0,0 +1,40 @@
+# test for checking monotonic timer (PR3916)
+set test "gtod"
+if {![installtest_p]} { untested $test; continue }
+
+set wd [pwd]
+set filename "$srcdir/$subdir/gtod.c"
+
+target_compile $filename $wd/gtod executable ""
+
+# non interval (check timer drift in short range)
+spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod
+set ok 0
+expect {
+ -timeout 120
+ -re {^[0-9]+ \:([0-9]+) appl\r\n[0-9]+ \:\1 kern\r\n[0-9]+ \:\1 prog\r\n} { incr ok; exp_continue }
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+wait
+#10ms interval (check timer drift in middle range)
+spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod 10000
+expect {
+ -timeout 120
+ -re {^[0-9]+ \:([0-9]+) appl\r\n[0-9]+ \:\1 kern\r\n[0-9]+ \:\1 prog\r\n} { incr ok; exp_continue }
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+wait
+#100ms interval (calm down processors and CPU freq might be changed)
+spawn $srcdir/$subdir/gtod.sh $srcdir/$subdir/gtod.stp $wd/gtod 100000
+expect {
+ -timeout 120
+ -re {^[0-9]+ \:([0-9]+) appl\r\n[0-9]+ \:\1 kern\r\n[0-9]+ \:\1 prog\r\n} { incr ok; exp_continue }
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+wait
+exec rm -f $wd/gtod
+if {$ok == 300} { pass "$test ($ok)" } { fail "$test ($ok)" }
+
diff --git a/testsuite/systemtap.samples/gtod.sh b/testsuite/systemtap.samples/gtod.sh
new file mode 100755
index 00000000..4d4a28c2
--- /dev/null
+++ b/testsuite/systemtap.samples/gtod.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+stap $1 -c "$2 $3" | sort
+
diff --git a/testsuite/systemtap.samples/gtod.stp b/testsuite/systemtap.samples/gtod.stp
new file mode 100644
index 00000000..f252dc0a
--- /dev/null
+++ b/testsuite/systemtap.samples/gtod.stp
@@ -0,0 +1,8 @@
+global count = 0
+
+probe syscall.setsid {
+ if (pid() == target()) {
+ printf("%014d :%02d kern\n", gettimeofday_us(), count);
+ count ++;
+ }
+}