From a4534db316c2b6bb0b10c06639c0f29b25a0307e Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Wed, 22 Apr 2015 19:43:02 +0200 Subject: [PATCH] PR18293: Test coverage improvements, tapset extension. * tapset/linux/aux_syscalls.stp: Add auxiliary functions for times and sysinfo. * tapset/linux/nd_syscalls2.stp: Extend argstr for sysinfo and times. * tapset/linux/syscalls2.stp: Likewise. * testsuite/buildok/nd_syscalls2-detailed.stp: New convenience var for times syscall. * testsuite/buildok/syscalls2-detailed.stp: Likewise for nd_syscall.times. * testsuite/systemtap.syscall/clock.c: Addo coverage for stime syscall. * testsuite/systemtap.syscall/syncfs.c: Extend and fix the testcase. * testsuite/systemtap.syscall/sysctl.c: New testcase. * testsuite/systemtap.syscall/sysinfo.c: Likewise. * testsuite/systemtap.syscall/times.c: Likewise. * testsuite/systemtap.syscall/unshare.c: Likewise. --- tapset/linux/aux_syscalls.stp | 56 +++++++++++++++++++++ tapset/linux/nd_syscalls2.stp | 5 +- tapset/linux/syscalls2.stp | 5 +- testsuite/buildok/nd_syscalls2-detailed.stp | 2 +- testsuite/buildok/syscalls2-detailed.stp | 2 +- testsuite/systemtap.syscall/clock.c | 15 +++++- testsuite/systemtap.syscall/syncfs.c | 15 ++++-- testsuite/systemtap.syscall/sysctl.c | 28 +++++++++++ testsuite/systemtap.syscall/sysinfo.c | 21 ++++++++ testsuite/systemtap.syscall/times.c | 20 ++++++++ testsuite/systemtap.syscall/unshare.c | 15 ++++++ 11 files changed, 172 insertions(+), 12 deletions(-) create mode 100644 testsuite/systemtap.syscall/sysctl.c create mode 100644 testsuite/systemtap.syscall/sysinfo.c create mode 100644 testsuite/systemtap.syscall/times.c create mode 100644 testsuite/systemtap.syscall/unshare.c diff --git a/tapset/linux/aux_syscalls.stp b/tapset/linux/aux_syscalls.stp index 20a8f58dd..caaa76b88 100644 --- a/tapset/linux/aux_syscalls.stp +++ b/tapset/linux/aux_syscalls.stp @@ -5539,3 +5539,59 @@ function _stp_compat_siginfo_u:string(uaddr:long) strlcat(STAP_RETVALUE, "}", MAXSTRINGLEN); #endif /* CONFIG_COMPAT */ %} + +%{ +#include +%} + +function _struct_tms_u:string(uaddr:long) +%{ /* pure */ + struct tms tm; + char *ptr = (char *)(unsigned long)STAP_ARG_uaddr; + if (ptr == NULL) + strlcpy (STAP_RETVALUE, "NULL", MAXSTRINGLEN); + else + { + if (_stp_copy_from_user((char*)&tm, ptr, + sizeof(struct tms)) == 0) + { + snprintf(STAP_RETVALUE, MAXSTRINGLEN, + "{tms_utime=%lu, tms_stime=%lu, tms_cutime=%lu, tms_cstime=%lu}", + tm.tms_utime, tm.tms_stime, tm.tms_cutime, tm.tms_cstime); + } + else + { + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "0x%lx", + (unsigned long)ptr); + } + } +%} + +%{ +#include +%} + +function _struct_sysinfo_u:string(uaddr:long) +%{ /* pure */ + struct sysinfo si; + char *ptr = (char *)(unsigned long)STAP_ARG_uaddr; + if (ptr == NULL) + strlcpy (STAP_RETVALUE, "NULL", MAXSTRINGLEN); + else + { + if (_stp_copy_from_user((char*)&si, ptr, + sizeof(struct sysinfo)) == 0) + { + snprintf(STAP_RETVALUE, MAXSTRINGLEN, + "{uptime=%ld, loads=[%lu, %lu, %lu], totalram=%lu, freeram=%lu, " + "sharedram=%lu, bufferram=%lu, totalswap=%lu, freeswap=%lu, procs=%u}", + si.uptime, si.loads[0], si.loads[1], si.loads[2], si.totalram, si.freeram, + si.sharedram, si.bufferram, si.totalswap, si.freeswap, si.procs); + } + else + { + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "0x%lx", + (unsigned long)ptr); + } + } +%} diff --git a/tapset/linux/nd_syscalls2.stp b/tapset/linux/nd_syscalls2.stp index 83f0e7391..e2fa7eee0 100644 --- a/tapset/linux/nd_syscalls2.stp +++ b/tapset/linux/nd_syscalls2.stp @@ -4372,7 +4372,7 @@ probe nd_syscall.sysinfo = kprobe.function("compat_sys_sysinfo") ?, name = "sysinfo" asmlinkage() info_uaddr = pointer_arg(1) - argstr = sprintf("%p", info_uaddr) + argstr = sprintf("%s", _struct_sysinfo_u(info_uaddr)) } probe nd_syscall.sysinfo.return = kprobe.function("compat_sys_sysinfo").return ?, kprobe.function("sys_sysinfo").return ? @@ -4775,7 +4775,8 @@ probe nd_syscall.times = kprobe.function("compat_sys_times") ?, { name = "times" asmlinkage() - argstr = sprintf("%p", pointer_arg(1)) + buf_uaddr = pointer_arg(1) + argstr = sprintf("%s", _struct_tms_u(buf_uaddr)) } probe nd_syscall.times.return = kprobe.function("compat_sys_times").return ?, kprobe.function("sys_times").return ? diff --git a/tapset/linux/syscalls2.stp b/tapset/linux/syscalls2.stp index 88e565ecd..5e50f9b52 100644 --- a/tapset/linux/syscalls2.stp +++ b/tapset/linux/syscalls2.stp @@ -4125,7 +4125,7 @@ probe syscall.sysinfo = kernel.function("compat_sys_sysinfo").call ?, { name = "sysinfo" info_uaddr = $info - argstr = sprintf("%p", $info) + argstr = sprintf("%s", _struct_sysinfo_u(info_uaddr)) } probe syscall.sysinfo.return = kernel.function("compat_sys_sysinfo").return ?, kernel.function("sys_sysinfo").return @@ -4510,7 +4510,8 @@ probe syscall.times = kernel.function("compat_sys_times").call ?, kernel.function("sys_times").call ? { name = "times" - argstr = sprintf("%p", $tbuf) + buf_uaddr = $tbuf + argstr = sprintf("%s", _struct_tms_u(buf_uaddr)) } probe syscall.times.return = kernel.function("compat_sys_times").return ?, kernel.function("sys_times").return ? diff --git a/testsuite/buildok/nd_syscalls2-detailed.stp b/testsuite/buildok/nd_syscalls2-detailed.stp index 61a366a34..0af6b9df9 100755 --- a/testsuite/buildok/nd_syscalls2-detailed.stp +++ b/testsuite/buildok/nd_syscalls2-detailed.stp @@ -1385,7 +1385,7 @@ probe nd_syscall.timerfd_settime.return ? probe nd_syscall.times { - printf("%s, %s\n", name, argstr) + printf("%s, %p, %s\n", name, buf_uaddr, argstr) } probe nd_syscall.times.return { diff --git a/testsuite/buildok/syscalls2-detailed.stp b/testsuite/buildok/syscalls2-detailed.stp index dccf2fc38..994037720 100755 --- a/testsuite/buildok/syscalls2-detailed.stp +++ b/testsuite/buildok/syscalls2-detailed.stp @@ -1381,7 +1381,7 @@ probe syscall.timerfd_settime.return ? probe syscall.times { - printf("%s, %s\n", name, argstr) + printf("%s, %p, %s\n", name, buf_uaddr, argstr) } probe syscall.times.return { diff --git a/testsuite/systemtap.syscall/clock.c b/testsuite/systemtap.syscall/clock.c index 38901b2d0..2c0d4a56a 100644 --- a/testsuite/systemtap.syscall/clock.c +++ b/testsuite/systemtap.syscall/clock.c @@ -1,4 +1,4 @@ -/* COVERAGE: gettimeofday settimeofday clock_gettime clock_settime clock_getres clock_nanosleep time */ +/* COVERAGE: gettimeofday settimeofday clock_gettime clock_settime clock_getres clock_nanosleep time stime */ #include #include #include @@ -30,6 +30,19 @@ int main() t = syscall(SYS_gettimeofday, &tv, NULL); //staptest// gettimeofday (XXXX, 0x[0]+) = 0 +#ifdef __NR_stime + tt = tv.tv_sec; + stime(&tt); + //staptest// stime (XXXX) = NNNN + + stime((time_t *)-1); +#ifdef __s390__ + //staptest// stime (0x[7]?[f]+) = -NNNN +#else + //staptest// stime (0x[f]+) = -NNNN +#endif +#endif + settimeofday(&tv, NULL); //staptest// settimeofday (\[NNNN.NNNN\], NULL) = diff --git a/testsuite/systemtap.syscall/syncfs.c b/testsuite/systemtap.syscall/syncfs.c index 3d79252a0..da1b30275 100644 --- a/testsuite/systemtap.syscall/syncfs.c +++ b/testsuite/systemtap.syscall/syncfs.c @@ -1,27 +1,32 @@ -/* COVERAGE: sync_file_range sync_file_range2 */ +/* COVERAGE: sync_file_range sync_file_range2 sync syncfs */ #define _GNU_SOURCE #include #include #include #include +#include int main() { int fd; char *string1 = "Hello world"; + sync(); + //staptest// sync () = 0 + // Create a test file. fd = creat("foobar", S_IREAD|S_IWRITE); write(fd, string1, sizeof(string1) - 1); - - syncfs(fd); + // We use syscall() to avoid link time problems +#ifdef __NR_syncfs + syscall(__NR_syncfs, fd); //staptest// syncfs (NNNN) = 0 - /* Limit testing. */ - syncfs(-1); + syscall(__NR_syncfs, (int)-1); //staptest// syncfs (-1) = -NNNN +#endif close(fd); return 0; diff --git a/testsuite/systemtap.syscall/sysctl.c b/testsuite/systemtap.syscall/sysctl.c new file mode 100644 index 000000000..936078dc1 --- /dev/null +++ b/testsuite/systemtap.syscall/sysctl.c @@ -0,0 +1,28 @@ +/* COVERAGE: sysctl */ + +#define _GNU_SOURCE +#include +#include +#include + +int main() +{ + // Man page states that this syscall is deprecated + // and is likely to disappear in future kernel versions. + +#ifdef SYS__sysctl + struct __sysctl_args args; + + syscall(SYS__sysctl, &args); + //staptest// sysctl (XXXX) = -NNNN + + syscall(SYS__sysctl, (struct __sysctl_args *)-1); +#ifdef __s390__ + //staptest// sysctl (0x[7]?[f]+) = -NNNN +#else + //staptest// sysctl (0x[f]+) = -NNNN +#endif +#endif + + return 0; +} diff --git a/testsuite/systemtap.syscall/sysinfo.c b/testsuite/systemtap.syscall/sysinfo.c new file mode 100644 index 000000000..4d45e12e6 --- /dev/null +++ b/testsuite/systemtap.syscall/sysinfo.c @@ -0,0 +1,21 @@ +/* COVERAGE: sysinfo */ + +#include + +int main() +{ + struct sysinfo si; + + sysinfo(&si); + //staptest// sysinfo ({uptime=NNNN, loads=[NNNN, NNNN, NNNN], totalram=NNNN, freeram=NNNN, sharedram=NNNN, bufferram=NNNN, totalswap=NNNN, freeswap=NNNN, procs=NNNN}) = 0 + + sysinfo((struct sysinfo *)-1); +#ifdef __s390__ + //staptest// sysinfo (0x[7]?[f]+) = -NNNN +#else + //staptest// sysinfo (0x[f]+) = -NNNN +#endif + + + return 0; +} diff --git a/testsuite/systemtap.syscall/times.c b/testsuite/systemtap.syscall/times.c new file mode 100644 index 000000000..9d39bfd53 --- /dev/null +++ b/testsuite/systemtap.syscall/times.c @@ -0,0 +1,20 @@ +/* COVERAGE: times */ + +#include + +int main() +{ + struct tms tms; + + times(&tms); + //staptest// times ({tms_utime=NNNN, tms_stime=NNNN, tms_cutime=NNNN, tms_cstime=NNNN}) = NNNN + + times((struct tms *)-1); +#ifdef __s390__ + //staptest// times (0x[7]?[f]+) = -NNNN +#else + //staptest// times (0x[f]+) = -NNNN +#endif + + return 0; +} diff --git a/testsuite/systemtap.syscall/unshare.c b/testsuite/systemtap.syscall/unshare.c new file mode 100644 index 000000000..7e2f7e936 --- /dev/null +++ b/testsuite/systemtap.syscall/unshare.c @@ -0,0 +1,15 @@ +/* COVERAGE: unshare */ + +#define _GNU_SOURCE +#include + +int main() +{ + unshare(CLONE_FILES); + //staptest// unshare (CLONE_FILES) = 0 + + unshare(-1); + //staptest// unshare (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_PTRACE|CLONE_VFORK|CLONE_PARENT|CLONE_THREAD|CLONE_NEWNS|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID[^)]+) = -NNNN + + return 0; +} -- 2.43.5