]> granicus.if.org Git - strace/commitdiff
tests: do more rigorous testing of utimes syscall parser
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 16 Apr 2017 18:47:29 +0000 (18:47 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 16 Apr 2017 18:47:29 +0000 (18:47 +0000)
* tests/utimes.c (errstr): New variable.
(print_ts, k_utimes): New functions.
(main): Use them to do more rigorous testing of utimes syscall parser.
* tests/gen_tests.in (utimes): Update -a option.

tests/gen_tests.in
tests/utimes.c

index 3b499d33b8d8d6d590c4d76a0a13d13c5503b5ba..50fd11963c3e350826fa6d4568ea77055abafd3c 100644 (file)
@@ -310,7 +310,7 @@ userfaultfd -a38
 ustat  -a33
 utime  -a16
 utimensat      -a33
-utimes -a21
+utimes -a17
 vfork-f        -a26 -qq -f -e signal=none -e trace=chdir
 vhangup        -a10
 vmsplice       -ewrite=1
index c4909730bd3c426353cf84eadc51ac39e657ea48..1bea007424d87dd59ed5024d666e8a7c61a464a6 100644 (file)
 # include <sys/time.h>
 # include <unistd.h>
 
+static void
+print_tv(const struct timeval *tv)
+{
+       printf("{tv_sec=%ju, tv_usec=%ju}",
+              (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
+}
+
+static const char *errstr;
+
+static long
+k_utimes(const kernel_ulong_t pathname, const kernel_ulong_t times)
+{
+       long rc = syscall(__NR_utimes, pathname, times);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
 int
 main(void)
 {
-       static const char sample[] = "utimes_sample";
+       static const char proto_fname[] = "utimes_sample";
+       static const char qname[] = "\"utimes_sample\"";
+
+       char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
+       const kernel_ulong_t kfname = (uintptr_t) fname;
+       struct timeval *const tv = tail_alloc(sizeof(*tv) * 2);
+
+       /* pathname */
+       k_utimes(0, 0);
+       printf("utimes(NULL, NULL) = %s\n", errstr);
+
+       k_utimes(kfname + sizeof(proto_fname) - 1, 0);
+       printf("utimes(\"\", NULL) = %s\n", errstr);
+
+       k_utimes(kfname, 0);
+       printf("utimes(%s, NULL) = %s\n", qname, errstr);
+
+       fname[sizeof(proto_fname) - 1] = '+';
+       k_utimes(kfname, 0);
+       fname[sizeof(proto_fname) - 1] = '\0';
+       printf("utimes(%p, NULL) = %s\n", fname, errstr);
+
+       if (F8ILL_KULONG_SUPPORTED) {
+               k_utimes(f8ill_ptr_to_kulong(fname), 0);
+               printf("utimes(%#jx, NULL) = %s\n",
+                      (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
+       }
+
+       /* times */
+       k_utimes(kfname, (uintptr_t) (tv + 1));
+       printf("utimes(%s, %p) = %s\n",
+              qname, tv + 1, errstr);
 
-       long rc = syscall(__NR_utimes, sample, 0);
-       printf("utimes(\"%s\", NULL) = %s\n", sample, sprintrc(rc));
+       k_utimes(kfname, (uintptr_t) (tv + 2));
+       printf("utimes(%s, %p) = %s\n",
+              qname, tv + 2, errstr);
 
-       struct timeval *const ts = tail_alloc(sizeof(*ts) * 2);
+       tv[0].tv_sec = 1492358607;
+       tv[0].tv_usec = 345678912;
+       tv[1].tv_sec = 1492356078;
+       tv[1].tv_usec = 456789023;
 
-       ts[0].tv_sec = 1492358607;
-       ts[0].tv_usec = 345678912;
-       ts[1].tv_sec = 1492356078;
-       ts[1].tv_usec = 456789023;
+       k_utimes(kfname, (uintptr_t) tv);
+       printf("utimes(%s, [", qname);
+       print_tv(&tv[0]);
+       printf(", ");
+       print_tv(&tv[1]);
+       printf("]) = %s\n", errstr);
 
-       rc = syscall(__NR_utimes, 0, ts + 2);
-       printf("utimes(NULL, %p) = %s\n", ts + 2, sprintrc(rc));
+       tv[0].tv_usec = 345678;
+       tv[1].tv_usec = 456789;
 
-       rc = syscall(__NR_utimes, 0, ts + 1);
-       printf("utimes(NULL, %p) = %s\n", ts + 1, sprintrc(rc));
+       k_utimes(kfname, (uintptr_t) tv);
+       printf("utimes(%s, [", qname);
+       print_tv(&tv[0]);
+       printf(", ");
+       print_tv(&tv[1]);
+       printf("]) = %s\n", errstr);
 
-       rc = syscall(__NR_utimes, "", ts);
-       printf("utimes(\"\", [{tv_sec=%jd, tv_usec=%jd}, "
-              "{tv_sec=%jd, tv_usec=%jd}]) = %s\n",
-              (intmax_t) ts[0].tv_sec, (intmax_t) ts[0].tv_usec,
-              (intmax_t) ts[1].tv_sec, (intmax_t) ts[1].tv_usec,
-              sprintrc(rc));
+       if (F8ILL_KULONG_SUPPORTED) {
+               k_utimes(kfname, f8ill_ptr_to_kulong(tv));
+               printf("utimes(%s, %#jx) = %s\n",
+                      qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
+       }
 
        puts("+++ exited with 0 +++");
        return 0;