From: Dmitry V. Levin Date: Sun, 16 Apr 2017 18:47:29 +0000 (+0000) Subject: tests: do more rigorous testing of futimesat syscall parser X-Git-Tag: v4.17~85 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01fff8d56bca3ab64ad71ac2b2153ecda2cf2aec;p=strace tests: do more rigorous testing of futimesat syscall parser * tests/futimesat.c (errstr): New variable. (print_ts, k_futimesat): New functions. (main): Use them to do more rigorous testing of futimesat syscall parser. --- diff --git a/tests/futimesat.c b/tests/futimesat.c index 37425efd..ae83988e 100644 --- a/tests/futimesat.c +++ b/tests/futimesat.c @@ -37,40 +37,108 @@ # include # include +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_futimesat(const kernel_ulong_t dirfd, + const kernel_ulong_t pathname, + const kernel_ulong_t times) +{ + long rc = syscall(__NR_futimesat, dirfd, pathname, times); + errstr = sprintrc(rc); + return rc; +} int main(void) { - static const char sample[] = "futimesat_sample"; - unsigned long dirfd = (unsigned long) 0xdeadbeef00000000ULL | -100U; + static const kernel_ulong_t bogus_fd = + (kernel_ulong_t) 0xbadfaceddeadbeaf; + static const kernel_ulong_t kfdcwd = + (kernel_ulong_t) 0xdefaced00000000 | -100U; + static const char proto_fname[] = "futimesat_sample"; + static const char qname[] = "\"futimesat_sample\""; - long rc = syscall(__NR_futimesat, dirfd, sample, 0); - printf("futimesat(AT_FDCWD, \"%s\", NULL) = %s\n", - sample, sprintrc(rc)); + 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); - struct timeval *const ts = tail_alloc(sizeof(*ts) * 2); - dirfd = (unsigned long) 0xdeadbeefffffffffULL; + (void) close(0); - ts[0].tv_sec = 1492356708; - ts[0].tv_usec = 567891234; - ts[1].tv_sec = 1492357086; - ts[1].tv_usec = 678902345; + /* dirfd */ + k_futimesat(0, kfname, 0); + printf("futimesat(0, %s, NULL) = %s\n", qname, errstr); - rc = syscall(__NR_futimesat, dirfd, 0, ts + 2); - printf("futimesat(%d, NULL, %p) = %s\n", - (int) dirfd, ts + 2, sprintrc(rc)); + k_futimesat(bogus_fd, kfname, 0); + printf("futimesat(%d, %s, NULL) = %s\n", (int) bogus_fd, qname, errstr); - rc = syscall(__NR_futimesat, dirfd, 0, ts + 1); - printf("futimesat(%d, NULL, %p) = %s\n", - (int) dirfd, ts + 1, sprintrc(rc)); + k_futimesat(-100U, kfname, 0); + printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr); - (void) close(0); - rc = syscall(__NR_futimesat, 0, "", ts); - printf("futimesat(0, \"\", [{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)); + k_futimesat(kfdcwd, kfname, 0); + printf("futimesat(AT_FDCWD, %s, NULL) = %s\n", qname, errstr); + + /* pathname */ + k_futimesat(kfdcwd, 0, 0); + printf("futimesat(AT_FDCWD, NULL, NULL) = %s\n", errstr); + + k_futimesat(kfdcwd, kfname + sizeof(proto_fname) - 1, 0); + printf("futimesat(AT_FDCWD, \"\", NULL) = %s\n", errstr); + + fname[sizeof(proto_fname) - 1] = '+'; + k_futimesat(kfdcwd, kfname, 0); + fname[sizeof(proto_fname) - 1] = '\0'; + printf("futimesat(AT_FDCWD, %p, NULL) = %s\n", fname, errstr); + + if (F8ILL_KULONG_SUPPORTED) { + k_futimesat(kfdcwd, f8ill_ptr_to_kulong(fname), 0); + printf("futimesat(AT_FDCWD, %#jx, NULL) = %s\n", + (uintmax_t) f8ill_ptr_to_kulong(fname), errstr); + } + + /* times */ + k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 1)); + printf("futimesat(AT_FDCWD, %s, %p) = %s\n", + qname, tv + 1, errstr); + + k_futimesat(kfdcwd, kfname, (uintptr_t) (tv + 2)); + printf("futimesat(AT_FDCWD, %s, %p) = %s\n", + qname, tv + 2, errstr); + + tv[0].tv_sec = 1492356708; + tv[0].tv_usec = 567891234; + tv[1].tv_sec = 1492357086; + tv[1].tv_usec = 678902345; + + k_futimesat(kfdcwd, kfname, (uintptr_t) tv); + printf("futimesat(AT_FDCWD, %s, [", qname); + print_tv(&tv[0]); + printf(", "); + print_tv(&tv[1]); + printf("]) = %s\n", errstr); + + tv[0].tv_usec = 567891; + tv[1].tv_usec = 678902; + + k_futimesat(kfdcwd, kfname, (uintptr_t) tv); + printf("futimesat(AT_FDCWD, %s, [", qname); + print_tv(&tv[0]); + printf(", "); + print_tv(&tv[1]); + printf("]) = %s\n", errstr); + + if (F8ILL_KULONG_SUPPORTED) { + k_futimesat(kfdcwd, kfname, f8ill_ptr_to_kulong(tv)); + printf("futimesat(AT_FDCWD, %s, %#jx) = %s\n", + qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr); + } puts("+++ exited with 0 +++"); return 0;