From ff0dba8fb7c752a10d64258d3cc1350893139929 Mon Sep 17 00:00:00 2001 From: hiramatu Date: Thu, 27 Sep 2007 16:28:28 +0000 Subject: 2007-09-27 Masami Hiramatsu PR3916 * systemtap.sample/gtod.*: New test for gettimeofday accuracy. --- testsuite/ChangeLog | 5 +++++ testsuite/systemtap.samples/gtod.c | 26 +++++++++++++++++++++++ testsuite/systemtap.samples/gtod.exp | 40 ++++++++++++++++++++++++++++++++++++ testsuite/systemtap.samples/gtod.sh | 4 ++++ testsuite/systemtap.samples/gtod.stp | 8 ++++++++ 5 files changed, 83 insertions(+) create mode 100644 testsuite/systemtap.samples/gtod.c create mode 100644 testsuite/systemtap.samples/gtod.exp create mode 100755 testsuite/systemtap.samples/gtod.sh create mode 100644 testsuite/systemtap.samples/gtod.stp 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 + + PR3916 + * systemtap.sample/gtod.*: New test for gettimeofday accuracy. + 2007-09-25 Martin Hunt * 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 +#include +#include +#include + +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 ++; + } +} -- cgit