]> granicus.if.org Git - strace/commitdiff
tests: rewrite utimensat.test without relying on libc utimensat wrapper
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 16 Apr 2017 17:28:00 +0000 (17:28 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 16 Apr 2017 17:28:00 +0000 (17:28 +0000)
The new test also does more rigorous testing.

* tests/utimensat.c: Stop including <assert.h> and <errno.h>, include
<unistd.h> and <asm/unistd.h>, check __NR_utimensat instead
of HAVE_UTIMENSAT.
(errstr): New variable.
(k_utimensat): New function, a thin wrapper around
syscall(__NR_utimensat).
(main): Use them instead of utimensat.
* tests/gen_tests.in (utimensat): New entry.
* tests/utimensat.test: Remove.
* tests/Makefile.am (DECODER_TESTS): Remove it.

tests/Makefile.am
tests/gen_tests.in
tests/utimensat.c
tests/utimensat.test [deleted file]

index 75ade3e48a98652e58dee0ae2428f0dae052daf0..739d3f1b02b91959955d37475eefb91b929854dc 100644 (file)
@@ -556,7 +556,6 @@ DECODER_TESTS = \
        uname.test \
        unix-pair-send-recv.test \
        unix-pair-sendto-recvfrom.test \
-       utimensat.test \
        # end of DECODER_TESTS
 
 MISC_TESTS = \
index 6936dd8d7f5ccd275d3633688f515b31e00fe017..3b499d33b8d8d6d590c4d76a0a13d13c5503b5ba 100644 (file)
@@ -308,7 +308,8 @@ unlinkat    -a35
 unshare        -a11
 userfaultfd    -a38
 ustat  -a33
-utime  -a 16 -e trace=utime
+utime  -a16
+utimensat      -a33
 utimes -a21
 vfork-f        -a26 -qq -f -e signal=none -e trace=chdir
 vhangup        -a10
index e1ebc97a87a2d943610807934615849fb1c78a4d..e6154925fadb90b87cf5715b7a80d4d0f2079ee7 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * This file is part of utimensat strace test.
+ * Check decoding of utimensat syscall.
  *
- * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  */
 
 #include "tests.h"
-#include <assert.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <unistd.h>
+#include <asm/unistd.h>
 
-#if defined HAVE_UTIMENSAT \
- && defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW \
- && defined UTIME_NOW && defined UTIME_OMIT
+#if defined __NR_utimensat && defined UTIME_NOW && defined UTIME_OMIT
 
 static void
 print_ts(const struct timespec *ts)
@@ -47,42 +45,118 @@ print_ts(const struct timespec *ts)
                (uintmax_t) ts->tv_nsec);
 }
 
+static const char *errstr;
+
+static long
+k_utimensat(const kernel_ulong_t dirfd,
+           const kernel_ulong_t pathname,
+           const kernel_ulong_t times,
+           const kernel_ulong_t flags)
+{
+       long rc = syscall(__NR_utimensat, dirfd, pathname, times, flags);
+       errstr = sprintrc(rc);
+       return rc;
+}
+
 int
 main(void)
 {
-       static const char fname[] = "utimensat\nfilename";
+       static const kernel_ulong_t bogus_fd =
+               (kernel_ulong_t) 0xbadc0deddeadbeef;
+       static const kernel_ulong_t kfdcwd =
+               (kernel_ulong_t) 0xdefaced00000000 | -100U;
+       static const char proto_fname[] = "utimensat\nfilename";
+       static const char qname[] = "\"utimensat\\nfilename\"";
+
+       char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
+       const kernel_ulong_t kfname = (uintptr_t) fname;
+       struct timespec *const ts = tail_alloc(sizeof(*ts) * 2);
+
+       (void) close(0);
+
+       /* dirfd */
+       k_utimensat(0, kfname, 0, 0);
+       printf("utimensat(0, %s, NULL, 0) = %s\n", qname, errstr);
+
+       k_utimensat(bogus_fd, kfname, 0, 0);
+       printf("utimensat(%d, %s, NULL, 0) = %s\n",
+              (int) bogus_fd, qname, errstr);
+
+       k_utimensat(-100U, kfname, 0, 0);
+       printf("utimensat(AT_FDCWD, %s, NULL, 0) = %s\n", qname, errstr);
+
+       k_utimensat(kfdcwd, kfname, 0, 0);
+       printf("utimensat(AT_FDCWD, %s, NULL, 0) = %s\n", qname, errstr);
 
-       assert(utimensat(AT_FDCWD, fname, NULL, 0) == -1);
-       if (ENOENT != errno)
-               error_msg_and_skip("utimensat");
+       /* pathname */
+       k_utimensat(kfdcwd, 0, 0, 0);
+       printf("utimensat(AT_FDCWD, NULL, NULL, 0) = %s\n", errstr);
 
-       #define PREFIX "utimensat(AT_FDCWD, \"utimensat\\nfilename\", "
-       printf(PREFIX "NULL, 0) = -1 ENOENT (%m)\n");
+       k_utimensat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0, 0);
+       printf("utimensat(AT_FDCWD, \"\", NULL, 0) = %s\n", errstr);
+
+       fname[sizeof(proto_fname) - 1] = '+';
+       k_utimensat(kfdcwd, kfname, 0, 0);
+       fname[sizeof(proto_fname) - 1] = '\0';
+       printf("utimensat(AT_FDCWD, %p, NULL, 0) = %s\n", fname, errstr);
+
+       if (F8ILL_KULONG_SUPPORTED) {
+               k_utimensat(kfdcwd, f8ill_ptr_to_kulong(fname), 0, 0);
+               printf("utimensat(AT_FDCWD, %#jx, NULL, 0) = %s\n",
+                      (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
+       }
+
+       /* times */
+       k_utimensat(kfdcwd, kfname, (uintptr_t) (ts + 1), 0);
+       printf("utimensat(AT_FDCWD, %s, %p, 0) = %s\n",
+              qname, ts + 1, errstr);
+
+       k_utimensat(kfdcwd, kfname, (uintptr_t) (ts + 2), 0);
+       printf("utimensat(AT_FDCWD, %s, %p, 0)"
+              " = %s\n", qname, ts + 2, errstr);
 
-       struct timespec ts[2];
        ts[0].tv_sec = 1492358706;
        ts[0].tv_nsec = 123456789;
        ts[1].tv_sec = 1492357068;
        ts[1].tv_nsec = 234567890;
 
-       printf(PREFIX "[");
+       k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
+       printf("utimensat(AT_FDCWD, %s, [", qname);
        print_ts(&ts[0]);
        printf(", ");
        print_ts(&ts[1]);
-       printf("], AT_SYMLINK_NOFOLLOW) = -1 ENOENT ");
-
-       assert(utimensat(AT_FDCWD, fname, ts, AT_SYMLINK_NOFOLLOW) == -1);
-       if (ENOENT != errno)
-               error_msg_and_skip("utimensat");
-       printf("(%m)\n");
+       printf("], AT_SYMLINK_NOFOLLOW) = %s\n", errstr);
 
        ts[0].tv_nsec = UTIME_NOW;
        ts[1].tv_nsec = UTIME_OMIT;
-       assert(utimensat(AT_FDCWD, fname, ts, AT_SYMLINK_NOFOLLOW) == -1);
-       if (ENOENT != errno)
-               error_msg_and_skip("utimensat");
-       printf(PREFIX "[UTIME_NOW, UTIME_OMIT], AT_SYMLINK_NOFOLLOW)"
-              " = -1 ENOENT (%m)\n");
+       k_utimensat(kfdcwd, kfname, (uintptr_t) ts, 0x100);
+       printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
+              ", AT_SYMLINK_NOFOLLOW) = %s\n", qname, errstr);
+
+       if (F8ILL_KULONG_SUPPORTED) {
+               k_utimensat(kfdcwd, kfname, f8ill_ptr_to_kulong(ts), 0);
+               printf("utimensat(AT_FDCWD, %s, %#jx, 0) = %s\n",
+                      qname, (uintmax_t) f8ill_ptr_to_kulong(ts), errstr);
+       }
+
+       /* flags */
+       k_utimensat(kfdcwd, kfname, (uintptr_t) ts,
+                   (kernel_ulong_t) 0xdefaced00000200);
+       printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
+              ", AT_REMOVEDIR) = %s\n",
+              qname, errstr);
+
+       k_utimensat(kfdcwd, kfname, (uintptr_t) ts,
+                   (kernel_ulong_t) 0xdefaced00000600);
+       printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
+              ", AT_REMOVEDIR|AT_SYMLINK_FOLLOW) = %s\n",
+              qname, errstr);
+
+       k_utimensat(kfdcwd, kfname, (uintptr_t) ts, (kernel_ulong_t) -1ULL);
+       printf("utimensat(AT_FDCWD, %s, [UTIME_NOW, UTIME_OMIT]"
+              ", AT_SYMLINK_NOFOLLOW|AT_REMOVEDIR|AT_SYMLINK_FOLLOW"
+              "|AT_NO_AUTOMOUNT|AT_EMPTY_PATH|0xffffe0ff) = %s\n",
+              qname, errstr);
 
        puts("+++ exited with 0 +++");
        return 0;
@@ -90,7 +164,6 @@ main(void)
 
 #else
 
-SKIP_MAIN_UNDEFINED("HAVE_UTIMENSAT && AT_FDCWD && AT_SYMLINK_NOFOLLOW"
-                   " && UTIME_NOW && UTIME_OMIT")
+SKIP_MAIN_UNDEFINED("__NR_utimensat && UTIME_NOW && UTIME_OMIT")
 
 #endif
diff --git a/tests/utimensat.test b/tests/utimensat.test
deleted file mode 100755 (executable)
index e6e2fd3..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# Check decoding of utimensat syscall.
-
-. "${srcdir=.}/init.sh"
-
-run_prog > /dev/null
-run_strace -e $NAME $args > "$EXP"
-
-check_prog grep
-LC_ALL=C grep -x "$NAME(.*" "$LOG" > /dev/null ||
-        skip_ "../$NAME executable does not use $NAME syscall"
-
-match_diff "$LOG" "$EXP"