]> sourceware.org Git - systemtap.git/commitdiff
PR18293: Test coverage improvements, tapset extension.
authorMartin Cermak <mcermak@redhat.com>
Wed, 22 Apr 2015 17:43:02 +0000 (19:43 +0200)
committerMartin Cermak <mcermak@redhat.com>
Wed, 22 Apr 2015 17:43:02 +0000 (19:43 +0200)
* 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
tapset/linux/nd_syscalls2.stp
tapset/linux/syscalls2.stp
testsuite/buildok/nd_syscalls2-detailed.stp
testsuite/buildok/syscalls2-detailed.stp
testsuite/systemtap.syscall/clock.c
testsuite/systemtap.syscall/syncfs.c
testsuite/systemtap.syscall/sysctl.c [new file with mode: 0644]
testsuite/systemtap.syscall/sysinfo.c [new file with mode: 0644]
testsuite/systemtap.syscall/times.c [new file with mode: 0644]
testsuite/systemtap.syscall/unshare.c [new file with mode: 0644]

index 20a8f58dd06bc68cf93cfbbc222749b5e0bd1094..caaa76b88a6c54196870aee1d456df01df38d57f 100644 (file)
@@ -5539,3 +5539,59 @@ function _stp_compat_siginfo_u:string(uaddr:long)
        strlcat(STAP_RETVALUE, "}", MAXSTRINGLEN);
 #endif /* CONFIG_COMPAT */
 %}
+
+%{
+#include <linux/times.h>
+%}
+
+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 <linux/kernel.h>
+%}
+
+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);
+               }
+       }
+%}
index 83f0e739130ad6815c3bafc93591b2d62e8dfbfe..e2fa7eee099b09fd7bacb5e718af3c26c9d6f69e 100644 (file)
@@ -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 ?
index 88e565ecde499e402e1eb02763218e7c56f49cf6..5e50f9b5230b789fd41e0651cce17b6b29f63cfd 100644 (file)
@@ -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 ?
index 61a366a34a24ee943f530392e6de27b37473fdc5..0af6b9df92a45390297bd6ce0651adc113e98b4d 100755 (executable)
@@ -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
 {
index dccf2fc38aef2df179e68c9cb77e2fe1139e9cbd..9940377204ae0a9e2514139ef0919b722cc281ed 100755 (executable)
@@ -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
 {
index 38901b2d0397a17ed4a01c275edd2c41659f0e8d..2c0d4a56aeaf3a03a63b9d862016572d0dfc9196 100644 (file)
@@ -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 <sys/types.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -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) =
 
index 3d79252a011c09543f676c7670e82769eb88810f..da1b302757d05edd931e5531d101b8781646e799 100644 (file)
@@ -1,27 +1,32 @@
-/* COVERAGE: sync_file_range sync_file_range2 */
+/* COVERAGE: sync_file_range sync_file_range2 sync syncfs */
 
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/syscall.h>
 
 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 (file)
index 0000000..936078d
--- /dev/null
@@ -0,0 +1,28 @@
+/* COVERAGE: sysctl */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <linux/sysctl.h>
+#include <sys/syscall.h>
+
+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 (file)
index 0000000..4d45e12
--- /dev/null
@@ -0,0 +1,21 @@
+/* COVERAGE: sysinfo */
+
+#include <sys/sysinfo.h>
+
+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 (file)
index 0000000..9d39bfd
--- /dev/null
@@ -0,0 +1,20 @@
+/* COVERAGE: times */
+
+#include <sys/times.h>
+
+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 (file)
index 0000000..7e2f7e9
--- /dev/null
@@ -0,0 +1,15 @@
+/* COVERAGE: unshare */
+
+#define _GNU_SOURCE
+#include <sched.h>
+
+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;
+}
This page took 0.04674 seconds and 5 git commands to generate.