diff options
Diffstat (limited to 'testsuite/systemtap.syscall')
34 files changed, 1740 insertions, 0 deletions
diff --git a/testsuite/systemtap.syscall/ChangeLog b/testsuite/systemtap.syscall/ChangeLog new file mode 100644 index 00000000..9f0bf54e --- /dev/null +++ b/testsuite/systemtap.syscall/ChangeLog @@ -0,0 +1,34 @@ +2006-07-21 Martin Hunt <hunt@redhat.com> + + * signal.c: Fix expected pattern. + +2006-06-26 Martin Hunt <hunt@redhat.com> + * stat.c: Add utime() test + +2006-06-15 Martin Hunt <hunt@redhat.com> + * chmod.c: Results for some archs have + 4294967295 instead of -1. Fix expected results + for now. + +2006-06-15 Martin Hunt <hunt@redhat.com> + * chmod.c: New test. + +2006-06-14 Martin Hunt <hunt@redhat.com> + * test.tcl: Escape "|". + * uid.c: Add setfsuid and setfsgid tests. + * uid16.c: Ditto. + * mmap.c, openclose.c, readwrite.c, stat.c: Fix + expected results for sys_open calls. + +2006-06-14 Martin Hunt <hunt@redhat.com> + * setgetgid.c: Renamed to uid.c. Added more syscalls. + * uid16.c: Add some more calls. + +2006-06-13 Martin Hunt <hunt@redhat.com> + * test.exp: Modify to recognize unsupported tests. + * test.tcl: Ditto. + * uid16.c: ifdef out for all but i386. + +2006-06-13 Martin Hunt <hunt@redhat.com> + * sys.stp: Add indentation for nested syscalls. + * uid16.c: New. diff --git a/testsuite/systemtap.syscall/README b/testsuite/systemtap.syscall/README new file mode 100644 index 00000000..41e6d895 --- /dev/null +++ b/testsuite/systemtap.syscall/README @@ -0,0 +1,52 @@ +How these tests work: + +Dejagnu finds all *.c files, compiles them and runs them in a temporary +directory while running the systemtap script sys.stp. To avoid +recompiling sys.stp over and over, the test.exp is smart enough to +compile sys.stp once and save the module. + + +You can run all the tests here with +> runtest test.exp + +You can run single tests with +> gcc -o testname testname.c +>./test.tcl testname + +OR, if you want to run multiple tests and don't want all the delays +with recompiling sys.stp each time, + +> stap -kp4 sys.stp +Keeping temporary directory "/tmp/stapPThTaQ" +> ./test.tcl testname /tmp/stapPThTaQ/*.ko +> ./test.tcl testname2 /tmp/stapPThTaQ/*.ko +... +> rm -rf /tmp/stapPThTaQ + +Finally, if you need to know why a test is failing, use +"test-debug.tcl" exactly as above. After running the test, it will open a +window with the results and expected results. + + + +HOW TO WRITE TESTS + +1. write a test case C file using some system calls. + +2. After each system call, put a comment on the next line starting with "//" +The comment should have the expected output. Where an arbitrary number +is expected, put "NNNN" (for decimal) or "XXXX" (for hex). Or you can +just write regular expressions. The "NNNN" and "XXXX" are just shorthand to +aid readability and are converted to regular expressions in test.tcl. + +3. Somewhere is your test program puts a comment line like this: +/* COVERAGE: syscall1 syscall2 ... */ +where you list the systemcalls that are tested. Then you can run +coverage.tcl and get a coverage report. + +You probably want to write your test case without the comments first. Make +sure it compiles and works as expected. Then try it with +"stap sys.stp -c ./testname" or test-debug.tcl to see the output. + +IMPORTANT: Note that the test scripts create a temporary directory for each +test program. Each program will run in an empty directory. diff --git a/testsuite/systemtap.syscall/access.c b/testsuite/systemtap.syscall/access.c new file mode 100644 index 00000000..065206b7 --- /dev/null +++ b/testsuite/systemtap.syscall/access.c @@ -0,0 +1,34 @@ +/* COVERAGE: access */ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd1; + + fd1 = creat("foobar1",S_IREAD|S_IWRITE); + + access("foobar1", F_OK); + // access ("foobar1", F_OK) = 0 + + access("foobar1", R_OK); + // access ("foobar1", R_OK) = 0 + + access("foobar1", W_OK); + // access ("foobar1", W_OK) = 0 + + access("foobar1", X_OK); + // access ("foobar1", X_OK) = -NNNN (EACCES) + + access("foobar1", R_OK|W_OK); + // access ("foobar1", W_OK |R_OK) = 0 + + access("foobar1", R_OK|W_OK|X_OK); + // access ("foobar1", X_OK |W_OK |R_OK) = -NNNN (EACCES) + + return 0; +} diff --git a/testsuite/systemtap.syscall/acct.c b/testsuite/systemtap.syscall/acct.c new file mode 100644 index 00000000..ec392793 --- /dev/null +++ b/testsuite/systemtap.syscall/acct.c @@ -0,0 +1,10 @@ +/* COVERAGE: acct */ +#include <unistd.h> + +int main() +{ + acct("foobar"); + // acct ("foobar") = -NNNN (EPERM) + + return 0; +} diff --git a/testsuite/systemtap.syscall/alarm.c b/testsuite/systemtap.syscall/alarm.c new file mode 100755 index 00000000..bae92253 --- /dev/null +++ b/testsuite/systemtap.syscall/alarm.c @@ -0,0 +1,44 @@ +/* COVERAGE: alarm nanosleep pause */ +#include <sys/types.h> +#include <unistd.h> +#include <time.h> +#include <string.h> +#include <signal.h> + +static void +sigrt_act_handler(int signo, siginfo_t *info, void *context) +{ +} + +int main() +{ + struct timespec rem, t = {0,789}; + struct sigaction sigrt_act; + memset(&sigrt_act, 0, sizeof(sigrt_act)); + sigrt_act.sa_handler = (void *)sigrt_act_handler; + sigaction(SIGALRM, &sigrt_act, NULL); + + alarm(1); + // alarm (1) = 0 + + pause(); + // pause () = + + alarm(0); + // alarm (0) = 0 + + sleep(1); + // nanosleep (\[1.000000000\], XXXX) = 0 + + usleep(1234); + // nanosleep (\[0.001234000\], 0x[0]+) = 0 + + nanosleep(&t, &rem); + // nanosleep (\[0.000000789\], XXXX) = 0 + + nanosleep(&t, NULL); + // nanosleep (\[0.000000789\], 0x[0]+) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/chmod.c b/testsuite/systemtap.syscall/chmod.c new file mode 100644 index 00000000..fd7473f4 --- /dev/null +++ b/testsuite/systemtap.syscall/chmod.c @@ -0,0 +1,81 @@ +/* COVERAGE: chmod fchmod chown fchown lchown */ +/* COVERAGE: chown16 fchown16 lchown16 */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/syscall.h> + +int main() +{ + int fd; + + fd = open("foobar",O_WRONLY|O_CREAT, 0666); + // open ("foobar", O_WRONLY|O_CREAT, 0666) = 4 + + chmod("foobar", 0644); + // chmod ("foobar", 0644) = 0 + + fchmod(fd, 0444); + // fchmod (4, 0444) = 0 + + chown("foobar", 5000, -1); +#ifdef __i386__ + // chown ("foobar", 5000, -1) = +#else + // chown ("foobar", 5000, NNNN) = +#endif + + chown("foobar", -1, 5001); +#ifdef __i386__ + // chown ("foobar", -1, 5001) = +#else + // chown ("foobar", NNNN, 5001) = +#endif + + fchown(fd, 5002, -1); +#ifdef __i386__ + // fchown (4, 5002, -1) = +#else + // fchown (4, 5002, NNNN) = +#endif + + fchown(fd, -1, 5003); +#ifdef __i386__ + // fchown (4, -1, 5003) = +#else + // fchown (4, NNNN, 5003) = +#endif + + lchown("foobar", 5004, -1); +#ifdef __i386__ + // lchown ("foobar", 5004, -1) = +#else + // lchown ("foobar", 5004, NNNN) = +#endif + + lchown("foobar", -1, 5005); +#ifdef __i386__ + // lchown ("foobar", -1, 5005) = +#else + // lchown ("foobar", NNNN, 5005) = +#endif + +#ifdef __i386__ + syscall(SYS_chown, "foobar", 5000, -1); + // chown16 ("foobar", 5000, -1) = + syscall(SYS_chown, "foobar", -1, 5001); + // chown16 ("foobar", -1, 5001) = + syscall(SYS_fchown, fd, 5002, -1); + // fchown16 (4, 5002, -1) = + syscall(SYS_fchown, fd, -1, 5003); + // fchown16 (4, -1, 5003) = + syscall(SYS_lchown, "foobar", 5004, -1); + // lchown16 ("foobar", 5004, -1) = + syscall(SYS_lchown, "foobar", -1, 5005); + // lchown16 ("foobar", -1, 5005) = +#endif + + close(fd); + return 0; +} diff --git a/testsuite/systemtap.syscall/clock.c b/testsuite/systemtap.syscall/clock.c new file mode 100644 index 00000000..c6b1302e --- /dev/null +++ b/testsuite/systemtap.syscall/clock.c @@ -0,0 +1,76 @@ +/* COVERAGE: gettimeofday settimeofday clock_gettime clock_settime clock_getres clock_nanosleep time */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <time.h> +#include <sys/syscall.h> + +int main() +{ + int t; + struct timeval tv; + struct timespec ts; + time_t tt; + + syscall(SYS_time, &tt); + // time (XXXX) = NNNN + + syscall(SYS_time, NULL); + // time (0x[0]+) = NNNN + + t = syscall(SYS_gettimeofday, &tv, NULL); + // gettimeofday (XXXX, 0x[0]+) = 0 + + settimeofday(&tv, NULL); + // settimeofday (\[NNNN.NNNN\], NULL) = + + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + // clock_gettime (CLOCK_REALTIME, XXXX) = 0 + + syscall(SYS_clock_settime, CLOCK_REALTIME, &ts); + // clock_settime (CLOCK_REALTIME, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_REALTIME, &ts); + // clock_getres (CLOCK_REALTIME, XXXX) = 0 + + syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts); + // clock_gettime (CLOCK_MONOTONIC, XXXX) = 0 + + syscall(SYS_clock_settime, CLOCK_MONOTONIC, &ts); + // clock_settime (CLOCK_MONOTONIC, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_MONOTONIC, &ts); + // clock_getres (CLOCK_MONOTONIC, XXXX) = 0 + + syscall(SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_gettime (CLOCK_PROCESS_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_settime, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_settime (CLOCK_PROCESS_CPUTIME_ID, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_getres (CLOCK_PROCESS_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_gettime (CLOCK_THREAD_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_settime, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_settime (CLOCK_THREAD_CPUTIME_ID, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_getres (CLOCK_THREAD_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + // clock_gettime (CLOCK_REALTIME, XXXX) = 0 + + ts.tv_sec++; + syscall(SYS_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME, &ts); + // clock_nanosleep (CLOCK_REALTIME, TIMER_ABSTIME, \[NNNN.NNNN\], XXXX) = 0 + + ts.tv_sec = 0; ts.tv_nsec = 10000; + syscall(SYS_clock_nanosleep, CLOCK_REALTIME, 0, &ts); + // clock_nanosleep (CLOCK_REALTIME, 0, \[NNNN.NNNN\], XXXX) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/coverage.tcl b/testsuite/systemtap.syscall/coverage.tcl new file mode 100755 index 00000000..559039c1 --- /dev/null +++ b/testsuite/systemtap.syscall/coverage.tcl @@ -0,0 +1,77 @@ +#!/usr/bin/env tclsh + +# List of systemcalls that may or may not be in kernels. Until we +# fix PR2645, we cannot implement syscall probes for these. + +set badlist { add_key tux } + +foreach f $badlist { + set funcname($f) -1 +} + +set cmd {stap -p2 -e "probe kernel.function(\"sys_*\"), kernel.function(\"sys32_*\") ? \{\}"} +if {[catch {eval exec $cmd} output]} { + puts "ERROR running stap: $output" + exit +} + + +foreach line [split $output "\n"] { + if {[regexp {kernel.function\(\"sys_([^@]+)} $line match fn]} { + if {![info exists funcname($fn)]} { + set funcname($fn) 0 + } + } + if {[regexp {kernel.function\(\"sys32_([^@]+)} $line match fn]} { + set fn "32_$fn" + if {![info exists funcname($fn)]} { + set funcname($fn) 0 + } + } +} + +foreach filename [glob *.c] { + if {[catch {open $filename r} fd]} { + puts "ERROR opening $filename: $fd" + exit + } + while {[gets $fd line] >= 0} { + if {[regexp {/* COVERAGE: ([^\*]*)\*/} $line match res]} { + foreach f [split $res] { + if {[info exists funcname($f)]} { + incr funcname($f) + } + } + } + } + close $fd +} + +set covlist {} +set uncovlist {} +set covered 0 +set uncovered 0 +foreach {func val} [array get funcname] { + if {$val > 0} { + incr covered + lappend covlist $func + } elseif {$val == 0} { + incr uncovered + lappend uncovlist $func + } +} + +set total [expr $covered + $uncovered] +puts "Covered $covered out of $total. [format "%2.1f" [expr ($covered * 100.0)/$total]]%" + +puts "\nUNCOVERED FUNCTIONS" +set i 0 +foreach f [lsort $uncovlist] { + puts -nonewline [format "%-24s" $f] + incr i + if {$i >= 3} { + puts "" + set i 0 + } +} +puts "\n" diff --git a/testsuite/systemtap.syscall/dir.c b/testsuite/systemtap.syscall/dir.c new file mode 100644 index 00000000..3609fecd --- /dev/null +++ b/testsuite/systemtap.syscall/dir.c @@ -0,0 +1,53 @@ +/* COVERAGE: mkdir chdir open fchdir close rmdir mkdirat */ +#define _GNU_SOURCE +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/syscall.h> + +int main() +{ + int fd; + + mkdir("foobar", 0765); + // mkdir ("foobar", 0765) = + + chdir("foobar"); + // chdir ("foobar") = 0 + + chdir(".."); + // chdir ("..") = 0 + + fd = open("foobar", O_RDONLY); + // open ("foobar", O_RDONLY) = 4 + + fchdir(fd); + // fchdir (4) = 0 + + chdir(".."); + // chdir ("..") = 0 + + close(fd); + // close (4) = 0 + + rmdir("foobar"); + // rmdir ("foobar") = 0 + + fd = open(".", O_RDONLY); + // open (".", O_RDONLY) = 4 + +#ifdef SYS_mkdirat + mkdirat(fd, "xyzzy", 0765); + // mkdirat (4, "xyzzy", 0765) = 0 + +#endif + + close(fd); + // close (4) = 0 + + rmdir("xyzzy"); + // rmdir ("xyzzy") = + + return 0; +} diff --git a/testsuite/systemtap.syscall/forkwait.c b/testsuite/systemtap.syscall/forkwait.c new file mode 100644 index 00000000..10f8d6ac --- /dev/null +++ b/testsuite/systemtap.syscall/forkwait.c @@ -0,0 +1,25 @@ +/* COVERAGE: fork wait4 */ +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <stdlib.h> +#include <unistd.h> + +int main () +{ + pid_t child; + int status; + + child = fork(); + // clone (CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID) = NNNN + if (!child) { + int i = 0xfffff; + while (i > 0) i--; + exit(0); + } + wait4(child, &status, WNOHANG, NULL); + // wait4 (NNNN, XXXX, WNOHANG, XXXX) = NNNN + + return 0; +} diff --git a/testsuite/systemtap.syscall/itimer.c b/testsuite/systemtap.syscall/itimer.c new file mode 100644 index 00000000..5cebc902 --- /dev/null +++ b/testsuite/systemtap.syscall/itimer.c @@ -0,0 +1,54 @@ +/* COVERAGE: getitimer setitimer */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <string.h> +#include <signal.h> + +static void +alarm_handler(int signo, siginfo_t *info, void *context) +{ +} + +int main() +{ + struct sigaction act; + struct itimerval itv, old_itv; + + memset(&act, 0, sizeof(act)); + act.sa_handler = (void *)alarm_handler; + sigaction(SIGALRM, &act, NULL); + sigaction(SIGVTALRM, &act, NULL); + sigaction(SIGPROF, &act, NULL); + + + memset(&itv, 0, sizeof(itv)); + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 500000; + itv.it_value.tv_sec = 1; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, &old_itv); + // setitimer (ITIMER_REAL, \[0.500000,1.000000\], XXXX) = 0 + + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); + // setitimer (ITIMER_REAL, \[0.500000,0.000000\], 0x[0]+) = 0 + + setitimer(ITIMER_VIRTUAL, &itv, NULL); + // setitimer (ITIMER_VIRTUAL, \[0.500000,0.000000\], 0x[0]+) = 0 + + setitimer(ITIMER_PROF, &itv, NULL); + // setitimer (ITIMER_PROF, \[0.500000,0.000000\], 0x[0]+) = 0 + + getitimer(ITIMER_REAL, &itv); + // getitimer (ITIMER_REAL, XXXX) = 0 + + getitimer(ITIMER_VIRTUAL, &itv); + // getitimer (ITIMER_VIRTUAL, XXXX) = 0 + + getitimer(ITIMER_PROF, &itv); + // getitimer (ITIMER_PROF, XXXX) = 0 + return 0; +} + diff --git a/testsuite/systemtap.syscall/link.c b/testsuite/systemtap.syscall/link.c new file mode 100644 index 00000000..072c2440 --- /dev/null +++ b/testsuite/systemtap.syscall/link.c @@ -0,0 +1,31 @@ +/* COVERAGE: link symlink readlink */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main() +{ + int fd; + char buf[128]; + + fd = open("foobar",O_WRONLY|O_CREAT, S_IRWXU); + close(fd); + + link("foobar", "foobar2"); + // link ("foobar", "foobar2") = 0 + + link("foobar", "foobar"); + // link ("foobar", "foobar") = -NNNN (EEXIST) + + link("nonexist", "foo"); + // link ("nonexist", "foo") = -NNNN (ENOENT) + + symlink("foobar", "Sfoobar"); + // symlink ("foobar", "Sfoobar") = 0 + + readlink("Sfoobar", buf, sizeof(buf)); + // readlink ("Sfoobar", XXXX, 128) = 6 + + return 0; +} diff --git a/testsuite/systemtap.syscall/mmap.c b/testsuite/systemtap.syscall/mmap.c new file mode 100644 index 00000000..75563854 --- /dev/null +++ b/testsuite/systemtap.syscall/mmap.c @@ -0,0 +1,53 @@ +/* COVERAGE: mmap2 munmap msync mlock mlockall munlock munlockall fstat open close */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> + +int main() +{ + int fd, ret; + struct stat fs; + void * r; + + /* create a file with something in it */ + fd = creat("foobar",S_IREAD|S_IWRITE); + // open ("foobar", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4 + lseek(fd, 1024, SEEK_SET); + write(fd, "abcdef", 6); + close(fd); + // close (4) = 0 + + fd = open("foobar", O_RDONLY); + // open ("foobar", O_RDONLY) = 4 + + /* stat for file size */ + ret = fstat(fd, &fs); + // fstat (4, XXXX) = 0 + + r = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, fd, 0); + // mmap[2]* (XXXX, 1030, PROT_READ, MAP_SHARED, 4, XXXX) = XXXX + + close(fd); + + mlock(r, fs.st_size); + // mlock (XXXX, 1030) = 0 + + msync(r, fs.st_size, MS_SYNC); + // msync (XXXX, 1030, MS_SYNC) = 0 + + munlock(r, fs.st_size); + // munlock (XXXX, 1030) = 0 + + mlockall(MCL_CURRENT); + // mlockall (MCL_CURRENT) = + + munlockall(); + // munlockall () = 0 + + munmap(r, fs.st_size); + // munmap (XXXX, 1030) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/mount.c b/testsuite/systemtap.syscall/mount.c new file mode 100644 index 00000000..57ae030f --- /dev/null +++ b/testsuite/systemtap.syscall/mount.c @@ -0,0 +1,35 @@ +/* COVERAGE: mount oldumount umount */ +#include <sys/types.h> +#include <sys/mount.h> + +#ifndef MNT_FORCE +#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ +#endif + +#ifndef MNT_DETACH +#define MNT_DETACH 0x00000002 /* Just detach from the tree */ +#endif + +#ifndef MNT_EXPIRE +#define MNT_EXPIRE 0x00000004 /* Mark for expiry */ +#endif + +int main() +{ + mount ("mount_source", "mount_target", "ext2", MS_BIND|MS_NOATIME|MS_NODIRATIME|MS_NOSUID, "some arguments"); + // mount ("mount_source", "mount_target", "ext2", MS_BIND|MS_NOATIME|MS_NODIRATIME|MS_NOSUID, "some arguments") = -NNNN (ENOENT) + + umount("umount_target"); + // umount ("umount_target", 0) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_FORCE); + // umount ("umount2_target", MNT_FORCE) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_DETACH); + // umount ("umount2_target", MNT_DETACH) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_EXPIRE); + // umount ("umount2_target", MNT_EXPIRE) = -NNNN (ENOENT) + + return 0; +} diff --git a/testsuite/systemtap.syscall/net1.c b/testsuite/systemtap.syscall/net1.c new file mode 100644 index 00000000..7ff9a294 --- /dev/null +++ b/testsuite/systemtap.syscall/net1.c @@ -0,0 +1,40 @@ +/* COVERAGE: socket fcntl fcntl64 bind listen accept */ +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <strings.h> + +int main() +{ + struct sockaddr_in sa; + int flags, listenfd, cfd; + + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + // socket (PF_INET, SOCK_STREAM, 0) = NNNN + + flags = fcntl(listenfd, F_GETFL, 0); + // fcntl[64]* (NNNN, F_GETFL, 0x[0]+) = NNNN + fcntl(listenfd, F_SETFL, flags | O_NONBLOCK); + // fcntl[64]* (NNNN, F_SETFL, XXXX) = 0 + + bzero(&sa, sizeof(sa)); + sa.sin_family=AF_INET; + sa.sin_addr.s_addr = htonl(INADDR_ANY); + sa.sin_port = htons(8765); + + bind(listenfd, (struct sockaddr *)&sa, sizeof(sa)); + // bind (NNNN, {AF_INET, 0.0.0.0, 8765}, 16) = 0 + + listen (listenfd, 7); + // listen (4, 7) = 0 + + cfd = accept(listenfd, (struct sockaddr *)NULL, NULL); + // accept (NNNN, 0x[0]+, 0x[0]+) = -NNNN (EAGAIN) + + close(cfd); + close(listenfd); + return 0; +} diff --git a/testsuite/systemtap.syscall/openclose.c b/testsuite/systemtap.syscall/openclose.c new file mode 100644 index 00000000..a35f1a59 --- /dev/null +++ b/testsuite/systemtap.syscall/openclose.c @@ -0,0 +1,58 @@ +/* COVERAGE: open close creat */ +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> + + +int main() +{ + int fd1, fd2; + + fd2 = creat("foobar1",S_IREAD|S_IWRITE); + // open ("foobar1", O_WRONLY|O_CREAT|O_TRUNC, 0600) = NNNN + + fd1 = open("foobar2",O_WRONLY|O_CREAT, S_IRWXU); + // open ("foobar2", O_WRONLY|O_CREAT, 0700) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_RDONLY); + // open ("foobar2", O_RDONLY) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_RDWR); + // open ("foobar2", O_RDWR) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_APPEND|O_WRONLY); + // open ("foobar2", O_WRONLY|O_APPEND) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_DIRECT|O_RDWR); + // open ("foobar2", O_RDWR|O_DIRECT) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_NOATIME|O_SYNC|O_RDWR); + // open ("foobar2", O_RDWR|O_NOATIME|O_SYNC) = NNNN + close(fd1); + // close (NNNN) = 0 + + /* Now test some bad opens */ + fd1 = open("/",O_WRONLY); + // open ("/", O_WRONLY) = -NNNN (EISDIR) + close (fd1); + // close (NNNN) = -NNNN (EBADF) + + fd1 = open("foobar2",O_WRONLY|O_CREAT|O_EXCL, S_IRWXU); + // open ("foobar2", O_WRONLY|O_CREAT|O_EXCL, 0700) = -NNNN (EEXIST) + + return 0; +} diff --git a/testsuite/systemtap.syscall/readwrite.c b/testsuite/systemtap.syscall/readwrite.c new file mode 100644 index 00000000..88f3a38a --- /dev/null +++ b/testsuite/systemtap.syscall/readwrite.c @@ -0,0 +1,85 @@ +/* COVERAGE: read write readv writev lseek llseek */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/unistd.h> +#include <sys/uio.h> + +#define STRING1 "red" +#define STRING2 "green" +#define STRING3 "blue" +int main() +{ + int fd; + struct iovec v[3], x[3]; + loff_t res; + char buf[64], buf1[32], buf2[32], buf3[32]; + + v[0].iov_base = STRING1; + v[0].iov_len = sizeof(STRING1); + v[1].iov_base = STRING2; + v[1].iov_len = sizeof(STRING2); + v[2].iov_base = STRING3; + v[2].iov_len = sizeof(STRING3); + + fd = open("foobar1",O_WRONLY|O_CREAT, 0666); + // open ("foobar1", O_WRONLY|O_CREAT, 0666) = 4 + + write(fd,"Hello world", 11); + // write (4, "Hello world", 11) = 11 + + write(fd,"Hello world abcdefghijklmnopqrstuvwxyz 01234567890", 50); + // write (4, "Hello world abc"..., 50) = 50 + + writev(fd, v, 3); + // writev (4, XXXX, 3) = 15 + + lseek(fd, 0, SEEK_SET); + // lseek (4, 0, SEEK_SET) = 0 + + lseek(fd, 1, SEEK_CUR); + // lseek (4, 1, SEEK_CUR) = 1 + + lseek(fd, -1, SEEK_END); + // lseek (4, -1, SEEK_END) = 75 + +#ifdef SYS__llseek + syscall(SYS__llseek, fd, 1, 0, &res, SEEK_SET); + // llseek (4, 0x1, 0x0, XXXX, SEEK_SET) = 0 + + syscall(SYS__llseek, fd, 0, 0, &res, SEEK_SET); + // llseek (4, 0x0, 0x0, XXXX, SEEK_SET) = 0 + + syscall(SYS__llseek, fd, 0, 12, &res, SEEK_CUR); + // llseek (4, 0x0, 0xc, XXXX, SEEK_CUR) = 0 + + syscall(SYS__llseek, fd, 8, 1, &res, SEEK_END); + // llseek (4, 0x8, 0x1, XXXX, SEEK_END) = 0 +#endif + + close (fd); + + fd = open("foobar1",O_RDONLY); + // open ("foobar1", O_RDONLY) = 4 + + read(fd, buf, 11); + // read (4, XXXX, 11) = 11 + + read(fd, buf, 50); + // read (4, XXXX, 50) = 50 + + x[0].iov_base = buf1; + x[0].iov_len = sizeof(STRING1); + x[1].iov_base = buf2; + x[1].iov_len = sizeof(STRING2); + x[2].iov_base = buf3; + x[2].iov_len = sizeof(STRING3); + readv(fd, x, 3); + // readv (4, XXXX, 3) = 15 + + close (fd); + + return 0; +} diff --git a/testsuite/systemtap.syscall/rt_signal.c b/testsuite/systemtap.syscall/rt_signal.c new file mode 100644 index 00000000..32eb9a92 --- /dev/null +++ b/testsuite/systemtap.syscall/rt_signal.c @@ -0,0 +1,44 @@ +/* COVERAGE: rt_sigprocmask rt_sigaction */ +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> +#include <sys/syscall.h> + + +static void +sig_act_handler(int signo) +{ +} + + +int main() +{ + sigset_t mask; + struct sigaction sa; + + sigemptyset(&mask); + sigaddset(&mask, SIGUSR1); + sigprocmask(SIG_BLOCK, &mask, NULL); + // rt_sigprocmask (SIG_BLOCK, XXXX, 0x[0]+, 8) = 0 + + sigprocmask(SIG_UNBLOCK, &mask, NULL); + // rt_sigprocmask (SIG_UNBLOCK, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGALRM); + sa.sa_flags = 0; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = SIG_DFL; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = sig_act_handler; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/sendfile.c b/testsuite/systemtap.syscall/sendfile.c new file mode 100644 index 00000000..06c6b260 --- /dev/null +++ b/testsuite/systemtap.syscall/sendfile.c @@ -0,0 +1,47 @@ +/* COVERAGE: sendfile */ +#include <fcntl.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/sendfile.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> + +int main () +{ + int fd, read_fd; + int write_fd; + struct stat stat_buf; + off_t offset = 0; + char buff[512]; + int ret; + + memset(buff, 5, sizeof(buff)); + + /* create a file with something in it */ + fd = creat("foobar",S_IREAD|S_IWRITE); + write(fd, buff, sizeof(buff)); + fsync(fd); + close(fd); + read_fd = open ("foobar", O_RDONLY); + if (read_fd < 0) + return 1; + fstat (read_fd, &stat_buf); + /* Open the output file for writing */ + write_fd = creat("foobar2",S_IREAD|S_IWRITE|S_IRWXO); + + /* + * For kernel2.6 the write_fd has to be a socket otherwise + * sendfile will fail. So we test for failure here. + */ + ret = sendfile (write_fd, read_fd, &offset, stat_buf.st_size); + // sendfile (NNNN, NNNN, XXXX, 512) = -22 (EINVAL) + + close (read_fd); + close (write_fd); + unlink("foobar"); + unlink("foobar2"); + + return 0; +} diff --git a/testsuite/systemtap.syscall/signal.c b/testsuite/systemtap.syscall/signal.c new file mode 100644 index 00000000..9c7ace95 --- /dev/null +++ b/testsuite/systemtap.syscall/signal.c @@ -0,0 +1,58 @@ +/* COVERAGE: signal kill tgkill sigprocmask sigaction getpid */ +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> +#include <sys/syscall.h> + +#ifdef SYS_signal + +static void +sig_act_handler(int signo) +{ +} + +int main() +{ + sigset_t mask; + struct sigaction sa; + pid_t pid; + + syscall(SYS_signal, SIGUSR1, SIG_IGN); + // signal (SIGUSR1, 0x00000001) = 0 + + syscall(SYS_signal, SIGUSR1, SIG_DFL); + // signal (SIGUSR1, 0x00000000) = 1 + + syscall(SYS_signal, SIGUSR1, sig_act_handler); + // signal (SIGUSR1, XXXX) = 0 + + sigemptyset(&mask); + sigaddset(&mask, SIGUSR1); + syscall(SYS_sigprocmask,SIG_BLOCK, &mask, NULL); + // sigprocmask (SIG_BLOCK, XXXX, 0x[0]+) = 0 + + syscall(SYS_sigprocmask,SIG_UNBLOCK, &mask, NULL); + // sigprocmask (SIG_UNBLOCK, XXXX, 0x[0]+) = 0 + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGALRM); + sa.sa_flags = 0; + syscall(SYS_sigaction,SIGUSR1, &sa, NULL); + // sigaction (SIGUSR1, XXXX, 0x[0]+) = 0 + + /* syscall(SYS_kill,0,SIGUSR1); + kill (0, SIGUSR1) = 0 + + pid = getpid(); + getpid () = NNNN + + + syscall(SYS_tgkill,pid,pid,SIGUSR1); + tgkill (NNNN, NNNN, SIGUSR1) = 0 + */ + + return 0; +} + +#endif diff --git a/testsuite/systemtap.syscall/stat.c b/testsuite/systemtap.syscall/stat.c new file mode 100644 index 00000000..16161093 --- /dev/null +++ b/testsuite/systemtap.syscall/stat.c @@ -0,0 +1,47 @@ +/* COVERAGE: getcwd fstat stat lstat utime */ +/* COVERAGE: fstat64 stat64 lstat64 */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <utime.h> +#include <string.h> +#include <time.h> +#include <stdio.h> + +int main() +{ + int fd; + char cwd[128]; + struct stat sbuf; + struct utimbuf ubuf; + + getcwd(cwd, 128); + // getcwd (XXXX, 128) = NNNN + + fd = creat("foobar",S_IREAD|S_IWRITE); + // open ("foobar", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4 + + fstat(fd, &sbuf); + // fstat (4, XXXX) = 0 + + close(fd); + + stat("foobar",&sbuf); + // stat ("foobar", XXXX) = 0 + + lstat("foobar",&sbuf); + // lstat ("foobar", XXXX) = 0 + + ubuf.actime = 1; + ubuf.modtime = 1135641600; + utime("foobar", &ubuf); + // utime ("foobar", \[1970/01/01-00:00:01, 2005/12/27-00:00:00\]) = 0 + + ubuf.actime = 1135690000; + ubuf.modtime = 1135700000; + utime("foobar", &ubuf); + // utime ("foobar", \[2005/12/27-13:26:40, 2005/12/27-16:13:20\]) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/statfs.c b/testsuite/systemtap.syscall/statfs.c new file mode 100644 index 00000000..791d49d3 --- /dev/null +++ b/testsuite/systemtap.syscall/statfs.c @@ -0,0 +1,33 @@ +/* COVERAGE: fstatfs statfs ustat statfs64 */ +#include <sys/types.h> +#include <unistd.h> +#include <ustat.h> +#include <sys/vfs.h> + +int main() +{ + + ustat(42, (struct ustat *)0x12345678); +#if __WORDSIZE == 64 + // ustat (42, 0x0000000012345678) = +#else + // ustat (42, 0x12345678) = +#endif + + statfs("abc", (struct statfs *)0x12345678); +#if __WORDSIZE == 64 + // statfs ("abc", 0x0000000012345678) = +#else + // statfs ("abc", 0x12345678) = +#endif + + fstatfs(77, (struct statfs *)0x12345678); +#if __WORDSIZE == 64 + // fstatfs (77, 0x0000000012345678) = +#else + // fstatfs (77, 0x12345678) = +#endif + + + return 0; +} diff --git a/testsuite/systemtap.syscall/swap.c b/testsuite/systemtap.syscall/swap.c new file mode 100755 index 00000000..a2db301e --- /dev/null +++ b/testsuite/systemtap.syscall/swap.c @@ -0,0 +1,29 @@ +/* COVERAGE: swapon swapoff */ +#include <unistd.h> +#include <asm/page.h> +#include <sys/swap.h> + + +int main() +{ + swapon("foobar_swap", 0); + // swapon ("foobar_swap", 0) = + + swapon("foobar_swap", ((1 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER); + // swapon ("foobar_swap", 32769) = + + swapon("foobar_swap", ((7 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER); + // swapon ("foobar_swap", 32775) = + + swapon(0, 0); + // swapon (NULL, 0) = + + swapoff("foobar_swap"); + // swapoff ("foobar_swap") = + + swapoff(0); + // swapoff (NULL) = + + return 0; +} + diff --git a/testsuite/systemtap.syscall/sync.c b/testsuite/systemtap.syscall/sync.c new file mode 100644 index 00000000..b23d68be --- /dev/null +++ b/testsuite/systemtap.syscall/sync.c @@ -0,0 +1,27 @@ +/* COVERAGE: fdatasync fsync sync */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd; + + fd = creat("foobar",S_IREAD|S_IWRITE); + + sync(); + // sync () = 0 + + fsync(fd); + // fsync (4) = 0 + + fdatasync(fd); + // fdatasync (4) = 0 + + close(fd); + + return 0; +} diff --git a/testsuite/systemtap.syscall/sys.stp b/testsuite/systemtap.syscall/sys.stp new file mode 100755 index 00000000..ab822ebb --- /dev/null +++ b/testsuite/systemtap.syscall/sys.stp @@ -0,0 +1,37 @@ +global indent, indent_str, entry + +probe begin { + indent = 0 + for (i=0; i<20; i++) { + if (i == 0) + indent_str[0] = "" + else + indent_str[i] = indent_str[i-1] . " " + } +} + + +probe syscall.* { + if (pid() == target()) { + if (entry) printf("\n") + printf("%s%s: %s (%s) = ", indent_str[indent], execname(), name, argstr) +# printf("%s%s: %s (%s) = ", indent_str[indent], execname(), probefunc(), argstr) + indent++ + entry = 1 + } +} + +probe syscall.*.return { + if (pid() == target()) { + if (indent) indent-- + if (entry) + printf("%s\n", retstr) + else + printf("%s%s\n", indent_str[indent],retstr) + entry = 0 + } +} + +probe end { + printf("\n") +} diff --git a/testsuite/systemtap.syscall/test-debug.tcl b/testsuite/systemtap.syscall/test-debug.tcl new file mode 100755 index 00000000..1eef509a --- /dev/null +++ b/testsuite/systemtap.syscall/test-debug.tcl @@ -0,0 +1,137 @@ +#!/usr/bin/env wish +package require Expect + +proc cleanup {} { + global dir current_dir + puts "cleanup" + if {$current_dir != ""} { + cd $current_dir + exec rm -rf $dir + set current_dir "" + } + exit 0 +} + +proc usage {progname} { + puts "Usage: $progname testname" + cleanup +} + +proc bgerror {error} { + puts "ERROR: $error" + cleanup +} +trap {cleanup} SIGINT +if {[catch {exec mktemp -d staptestXXXXX} dir]} { + puts "Failed to create temporary directory: $dir" + cleanup +} + +set current_dir "" +set testname [lindex $argv 0] +set modname [lindex $argv 1] + +if {$testname == ""} { + usage $argv0 + cleanup +} +set filename "${testname}.c" +set cmd "stap -c ../${testname} ../sys.stp" + +# extract the expected results +# Use the preprocessor so we can ifdef tests in and out + +set ccmd "gcc -E -C -P $filename" +catch {eval exec $ccmd} output + +set ind 0 +foreach line [split $output "\n"] { + if {[regsub {//} $line {} line]} { + set line "$testname: [string trimleft $line]" + + regsub -all {\(} $line {\\(} line + regsub -all {\)} $line {\\)} line + regsub -all {\|} $line {\|} line + + regsub -all NNNN $line {[\-0-9]+} line + regsub -all XXXX $line {[x0-9a-fA-F]+} line + + set results($ind) $line + incr ind + } +} + +if {$ind == 0} { + puts "UNSUPP" + exit +} + +set current_dir [pwd] +cd $dir +catch {eval exec $cmd} output + +set i 0 +foreach line [split $output "\n"] { + if {[regexp $results($i) $line]} { + incr i + if {$i >= $ind} {break} + } +} +if {$i >= $ind} { + puts "PASS" +} else { + puts "FAIL" +} + + +text .t1 -width 60 -height 20 -wrap none \ + -xscrollcommand {.x1bar set} \ + -yscrollcommand {.ybar set} +text .t2 -width 60 -height 20 -wrap none \ + -xscrollcommand {.x2bar set} \ + -yscrollcommand {.ybar set} + +scrollbar .x1bar -orient horizontal -command {.t1 xview} +scrollbar .x2bar -orient horizontal -command {.t2 xview} +scrollbar .ybar -orient vertical -command [list bindyview [list .t1 .t2]] + +proc bindyview {lists args} { + foreach l $lists { + eval {$l yview} $args + } +} + +grid .t1 .t2 .ybar -sticky nsew +grid .x1bar .x2bar -sticky nsew +grid columnconfigure . 0 -weight 1 +grid columnconfigure . 1 -weight 1 +grid rowconfigure . 0 -weight 1 +.t1 tag configure blue -foreground blue +.t2 tag configure blue -foreground blue +.t1 tag configure red -foreground red +.t2 tag configure red -foreground red + +set i 0 +foreach line [split $output "\n"] { + if {[regexp "${testname}: " $line]} { + if {[regexp $results($i) $line]} { + .t1 insert end ${line} blue + .t2 insert end $results($i) blue + incr i + if {$i >= $ind} {break} + } else { + .t1 insert end ${line} + } + .t1 insert end "\n" + .t2 insert end "\n" + } +} + +for {} {$i < $ind} {incr i} { + .t2 insert end $results($i) red + .t1 insert end "\n" + .t2 insert end "\n" +} + +bind . <Destroy> {cleanup} + diff --git a/testsuite/systemtap.syscall/test.exp b/testsuite/systemtap.syscall/test.exp new file mode 100644 index 00000000..98829cc4 --- /dev/null +++ b/testsuite/systemtap.syscall/test.exp @@ -0,0 +1,71 @@ +return ;# this will need more rework for obj!=src testing + +proc test_procedure {} { +global subdir +if {$subdir != ""} { + cd $subdir +} + +# compile sys.stp and keep it +catch {exec stap -kvvp4 sys.stp} res1 +set path "" +regexp {Keeping temporary directory "([^\"]*)"} $res1 match path +if {$path == ""} { + send_log "ERROR:\n$res1\n" + fail "ERROR:\n$res1\n" + return -1 +} +foreach line [split $res1 \n] { + if {[regexp {Pass 4: compiled C into "([^\"]*)"} $line match module]} { + break + } +} + +if {![info exists module]} { + send_log "Compiling sys.stp failed:\n$res1\n" + fail "Compiling sys.stp failed:\n$res1\n" + return -1 +} + +set flags "" +foreach filename [lsort [glob *.c]] { + set file [string range $filename 0 end-2] + target_compile $filename $file executable $flags + send_log "Testing ${file}\n" + set res [exec ./test.tcl $file $path/$module] + if {$res == "PASS"} { + pass "$file" + } elseif {$res == "UNSUPP"} { + unsupported "$file not supported on this arch" + } else { + fail "$file" + send_log "$res\n" + } +} + +if {$tcl_platform(machine) == "x86_64"} { + # on x86_64, test 32-bit and 64-bit binaries + set flags "additional_flags=-m32" + foreach filename [lsort [glob *.c]] { + set file [string range $filename 0 end-2] + target_compile $filename $file executable $flags + send_log "Testing 32-bit ${file}\n" + set res [exec ./test.tcl $file $path/$module] + if {$res == "PASS"} { + pass "32-bit $file" + } elseif {$res == "UNSUPP"} { + unsupported "$file not supported on this arch" + } else { + fail "32-bit $file" + send_log "$res\n" + } + } +} + +exec rm -rf $path +if {$subdir != ""} { + cd .. +} +} + +test_procedure diff --git a/testsuite/systemtap.syscall/test.tcl b/testsuite/systemtap.syscall/test.tcl new file mode 100755 index 00000000..a73e22c9 --- /dev/null +++ b/testsuite/systemtap.syscall/test.tcl @@ -0,0 +1,122 @@ +#!/usr/bin/env expect + +set dir "" +set current_dir "" + +proc cleanup {} { + global dir current_dir + if {$current_dir != ""} { + cd $current_dir + if {$dir != ""} {exec rm -rf $dir} + set current_dir "" + } + exit 0 +} + +proc usage {progname} { + puts "Usage: $progname testname [modulename]" +} + +proc bgerror {error} { + puts "ERROR: $error" + cleanup +} +trap {cleanup} SIGINT +set testname [lindex $argv 0] +set modname [lindex $argv 1] + +if {$testname == ""} { + usage $argv0 + exit +} +set filename "${testname}.c" + +if {$modname == ""} { + set cmd "stap -c ../${testname} ../sys.stp" +} else { + set stpd "" + set stpd_list "/usr/local/libexec/systemtap/stpd /usr/libexec/systemtap/stpd" + foreach path $stpd_list { + if {[file exists $path]} { + set stpd $path + break + } + } + if {$stpd == ""} { + puts "stpd not found!" + exit + } + set user $::tcl_platform(user) + set cmd "sudo $stpd -rmq -u $user -c ../${testname} ${modname}" +} + +# Extract the expected results +# Use the preprocessor so we can ifdef tests in and out + +set ccmd "gcc -E -C -P $filename" +catch {eval exec $ccmd} output + +set ind 0 +foreach line [split $output "\n"] { + if {[regsub {//} $line {} line]} { + set line "$testname: [string trimleft $line]" + + regsub -all {\(} $line {\\(} line + regsub -all {\)} $line {\\)} line + regsub -all {\|} $line {\|} line + + regsub -all NNNN $line {[\-0-9]+} line + regsub -all XXXX $line {[x0-9a-fA-F]+} line + + set results($ind) $line + incr ind + } +} + +if {$ind == 0} { + puts "UNSUPP" + cleanup + exit +} + +if {[catch {exec mktemp -d staptestXXXXX} dir]} { + puts "Failed to create temporary directory: $dir" + cleanup +} +set current_dir [pwd] +cd $dir + +catch {eval exec $cmd} output + +set i 0 +foreach line [split $output "\n"] { + if {[regexp $results($i) $line]} { + incr i + if {$i >= $ind} {break} + } +} +if {$i >= $ind} { + puts "PASS" +} else { + puts "$testname FAILED" + puts "RESULTS: (\'*\' = MATCHED EXPECTED)" + set i 0 + foreach line [split $output "\n"] { + if {[regexp "${testname}: " $line]} { + if {[regexp $results($i) $line]} { + puts "*$line" + incr i + if {$i >= $ind} {break} + } else { + puts "$line" + } + } + } + if {$i < $ind} { + puts "--------- EXPECTED and NOT MATCHED ----------" + } + for {} {$i < $ind} {incr i} { + puts "$results($i)" + } +} +cleanup diff --git a/testsuite/systemtap.syscall/timer.c b/testsuite/systemtap.syscall/timer.c new file mode 100644 index 00000000..27169b0a --- /dev/null +++ b/testsuite/systemtap.syscall/timer.c @@ -0,0 +1,32 @@ +/* COVERAGE: timer_create timer_gettime timer_settime timer_getoverrun timer_delete */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <string.h> +#include <signal.h> +#include <time.h> +#include <sys/syscall.h> + +int main() +{ + timer_t tid; + struct itimerspec val, oval; + + syscall(SYS_timer_create, CLOCK_REALTIME, NULL, &tid); + // timer_create (CLOCK_REALTIME, 0x[0]+, XXXX) + + syscall(SYS_timer_gettime, tid, &val); + // timer_gettime (0, XXXX) = 0 + + syscall(SYS_timer_settime, 0, tid, &val, &oval); + // timer_settime (0, 0, \[0.000000,0.000000\], XXXX) = 0 + + syscall(SYS_timer_getoverrun, tid); + // timer_getoverrun (0) = 0 + + syscall(SYS_timer_delete, tid); + // timer_delete (0) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/trunc.c b/testsuite/systemtap.syscall/trunc.c new file mode 100644 index 00000000..ff20cb39 --- /dev/null +++ b/testsuite/systemtap.syscall/trunc.c @@ -0,0 +1,23 @@ +/* COVERAGE: ftruncate truncate */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd; + + + fd = creat("foobar",S_IREAD|S_IWRITE); + ftruncate(fd, 1024); + // ftruncate (4, 1024) = 0 + close(fd); + + truncate("foobar", 2048); + // truncate ("foobar", 2048) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/uid.c b/testsuite/systemtap.syscall/uid.c new file mode 100644 index 00000000..3acb4cb8 --- /dev/null +++ b/testsuite/systemtap.syscall/uid.c @@ -0,0 +1,64 @@ +/* COVERAGE: getuid geteuid getgid getegid setuid setresuid getresuid setgid */ +/* COVERAGE: setresgid getresgid setreuid setregid setfsuid setfsgid */ +#define _GNU_SOURCE +#include <sys/types.h> +#include <unistd.h> +#include <sys/fsuid.h> + +int main () +{ + uid_t ruid, euid, suid; + gid_t rgid, egid, sgid; + + ruid = getuid(); + // getuid () = NNNN + + euid = geteuid(); + // geteuid () = NNNN + + rgid = getgid(); + // getgid () = NNNN + + egid = getegid(); + // getegid () = NNNN + + + + setuid(4096); + // setuid (4096) = NNNN + + seteuid(4097); + // setresuid (-1, 4097, -1) = NNNN + + getresuid(&ruid, &euid, &suid); + // getresuid (XXXX, XXXX, XXXX) = 0 + + setgid(4098); + // setgid (4098) = NNNN + + setegid(4099); + // setresgid (-1, 4099, -1) = NNNN + + getresgid(&rgid, &egid, &sgid); + // getresgid (XXXX, XXXX, XXXX) = 0 + + setreuid(-1, 5000); + // setreuid (NNNN, 5000) = + + setreuid(5001, -1); + // setreuid (5001, NNNN) = + + setregid(-1, 5002); + // setregid (NNNN, 5002) = + + setregid(5003, -1); + // setregid (5003, NNNN) = + + setfsuid(5004); + // setfsuid (5004) = + + setfsgid(5005); + // setfsgid (5005) = + + return 0; +} diff --git a/testsuite/systemtap.syscall/uid16.c b/testsuite/systemtap.syscall/uid16.c new file mode 100644 index 00000000..1c7f9df3 --- /dev/null +++ b/testsuite/systemtap.syscall/uid16.c @@ -0,0 +1,72 @@ +/* COVERAGE: getuid16 geteuid16 getgid16 getegid16 setuid16 setresuid16 */ +/* COVERAGE: getresuid16 setgid16 setresgid16 getresgid16 setreuid16 setregid16 */ +/* COVERAGE: setfsuid16 setfsgid16 */ + +#ifdef __i386__ + +/* These are all obsolete 16-bit calls that are still there for compatibility. */ + +#include <sys/types.h> +#include <unistd.h> +#include <pwd.h> +#include <sys/syscall.h> + +int main () +{ + uid_t uid, ruid, euid, suid; + gid_t gid, rgid, egid, sgid; + + uid = syscall(__NR_getuid); + // getuid16 () = NNNN + + uid = syscall(__NR_geteuid); + // geteuid16 () = NNNN + + gid = syscall(__NR_getgid); + // getgid16 () = NNNN + + gid = syscall(__NR_getegid); + // getegid16 () = NNNN + + + + syscall(__NR_setuid, 4096); + // setuid16 (4096) = + + syscall(__NR_setresuid, -1, 4097, -1); + // setresuid16 (-1, 4097, -1) = + + syscall(__NR_getresuid, &ruid, &euid, &suid); + // getresuid16 (XXXX, XXXX, XXXX) = + + syscall(__NR_setgid, 4098); + // setgid16 (4098) = + + syscall(__NR_setresgid, -1, 4099, -1); + // setresgid16 (-1, 4099, -1) = + + syscall(__NR_getresgid, &rgid, &egid, &sgid); + // getresgid16 (XXXX, XXXX, XXXX) = + + syscall(__NR_setreuid, -1, 5000); + // setreuid16 (-1, 5000) = + + syscall(__NR_setreuid, 5001, -1); + // setreuid16 (5001, -1) = + + syscall(__NR_setregid, -1, 5002); + // setregid16 (-1, 5002) = + + syscall(__NR_setregid, 5003, -1); + // setregid16 (5003, -1) = + + syscall(__NR_setfsuid, 5004); + // setfsuid16 (5004) = + + syscall(__NR_setfsgid, 5005); + // setfsgid16 (5005) = + + return 0; +} + +#endif /* __i386__ */ diff --git a/testsuite/systemtap.syscall/umask.c b/testsuite/systemtap.syscall/umask.c new file mode 100644 index 00000000..5d13575f --- /dev/null +++ b/testsuite/systemtap.syscall/umask.c @@ -0,0 +1,20 @@ +/* COVERAGE: umask */ +#include <sys/types.h> +#include <sys/stat.h> + +int main() +{ + umask (0); + // umask (00) = NNNN + umask (7); + // umask (07) = 00 + umask (077); + // umask (077) = 07 + umask (0666); + // umask (0666) = 077 + umask (0777); + // umask (0777) = 0666 + umask (01777); + // umask (01777) = 0777 + return 0; +} diff --git a/testsuite/systemtap.syscall/unlink.c b/testsuite/systemtap.syscall/unlink.c new file mode 100644 index 00000000..b0d00be8 --- /dev/null +++ b/testsuite/systemtap.syscall/unlink.c @@ -0,0 +1,35 @@ +/* COVERAGE: unlink */ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd1; + + fd1 = creat("foobar1",S_IREAD|S_IWRITE); + close (fd1); + + unlink("foobar1"); + // unlink ("foobar1") = 0 + + unlink("foobar1"); + // unlink ("foobar1") = -NNNN (ENOENT) + + unlink("foobar2"); + // unlink ("foobar2") = -NNNN (ENOENT) + + unlink(0); + // unlink (NULL) = -NNNN (EFAULT) + + unlink(".."); + // unlink ("..") = -NNNN (EISDIR) + + unlink(""); + // unlink ("") = -NNNN (ENOENT) + + return 0; +} |