diff --git a/tests/utime.c b/tests/utime.c index ea5ecc40..fdb48a70 100644 --- a/tests/utime.c +++ b/tests/utime.c @@ -1,5 +1,5 @@ /* - * This file is part of utime strace test. + * Check decoding of utime syscall. * * Copyright (c) 2015-2016 Dmitry V. Levin * All rights reserved. @@ -28,14 +28,17 @@ */ #include "tests.h" -#include -#include -#include -#include -#include - #include +#ifdef __NR_utime + +# include +# include +# include +# include +# include + + static void print_tm(const struct tm * const p) { @@ -44,33 +47,36 @@ print_tm(const struct tm * const p) p->tm_hour, p->tm_min, p->tm_sec); } +static long +k_utime(const void *const filename, const void *const times) +{ + return syscall(__NR_utime, filename, times); +} + int main(void) { - int rc = utime("", NULL); - printf("utime(\"\", NULL) = %s\n", sprintrc(rc)); + static const char *const dummy_str = "dummy filename"; const time_t t = time(NULL); const struct tm * const p = localtime(&t); const struct utimbuf u = { .actime = t, .modtime = t }; const struct utimbuf const *tail_u = tail_memdup(&u, sizeof(u)); - -#ifdef __NR_utime - static const char *const dummy_str = "dummy filename"; - char *const dummy_filename = + const char *const dummy_filename = tail_memdup(dummy_str, sizeof(dummy_str) - 1); - rc = syscall(__NR_utime, dummy_filename + sizeof(dummy_str), - tail_u + 1); + long rc = k_utime("", NULL); + printf("utime(\"\", NULL) = %s\n", sprintrc(rc)); + + rc = k_utime(dummy_filename + sizeof(dummy_str), tail_u + 1); printf("utime(%p, %p) = %s\n", dummy_filename + sizeof(dummy_str), tail_u + 1, sprintrc(rc)); - rc = syscall(__NR_utime, dummy_filename, (struct tm *) tail_u + 1); + rc = k_utime(dummy_filename, (struct tm *) tail_u + 1); printf("utime(%p, %p) = %s\n", dummy_filename, (struct tm *) tail_u + 1, sprintrc(rc)); -#endif /* __NR_utime */ - rc = utime("utime\nfilename", tail_u); + rc = k_utime("utime\nfilename", tail_u); const char *errstr = sprintrc(rc); printf("utime(\"utime\\nfilename\", {actime="); print_tm(p); @@ -81,3 +87,9 @@ main(void) puts("+++ exited with 0 +++"); return 0; } + +#else + +SKIP_MAIN_UNDEFINED("__NR_utime") + +#endif diff --git a/tests/utime.test b/tests/utime.test index 4cb95ea2..bd64c532 100755 --- a/tests/utime.test +++ b/tests/utime.test @@ -1,22 +1,6 @@ #!/bin/sh # Check decoding of utime syscall. - . "${srcdir=.}/init.sh" -$STRACE -e utime -h > /dev/null || - skip_ 'utime syscall is not supported on this architecture' - -run_prog > /dev/null -run_strace -a 16 -e utime $args > "$OUT" - -check_prog grep -LC_ALL=C grep -x "utime(.*" "$LOG" > /dev/null || { - rm -f "$OUT" - skip_ 'test executable does not use utime syscall' -} -match_diff "$LOG" "$OUT" - -rm -f "$OUT" - -exit 0 +run_strace_match_diff -a 16 -e trace=utime