Skip to content

Commit 78e48eb

Browse files
committed
tests: add utimensat.test
* tests/utimensat.c: New file. * tests/utimensat.test: New test. * tests/Makefile.am (check_PROGRAMS): Add utimensat. (TESTS): Add utimensat.test. * configure.ac (AC_CHECK_FUNCS): Add utimensat. * tests/.gitignore: Add utimensat.
1 parent b5a23ed commit 78e48eb

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ AC_CHECK_FUNCS(m4_normalize([
256256
stpcpy
257257
strerror
258258
strsignal
259+
utimensat
259260
]))
260261
AC_CHECK_HEADERS(m4_normalize([
261262
asm/cachectl.h

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ umovestr
5151
umovestr2
5252
unix-pair-send-recv
5353
utime
54+
utimensat
5455
xattr
5556
xet_robust_list
5657
*.log

tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ check_PROGRAMS = \
6464
umovestr2 \
6565
unix-pair-send-recv \
6666
utime \
67+
utimensat \
6768
xattr \
6869
xet_robust_list \
6970
# end of check_PROGRAMS
@@ -135,6 +136,7 @@ TESTS = \
135136
uid32.test \
136137
uio.test \
137138
utime.test \
139+
utimensat.test \
138140
xattr.test \
139141
xet_robust_list.test \
140142
count.test \

tests/utimensat.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifdef HAVE_CONFIG_H
2+
# include "config.h"
3+
#endif
4+
5+
#include <stdint.h>
6+
#include <fcntl.h>
7+
#include <stdio.h>
8+
#include <sys/stat.h>
9+
#include <sys/time.h>
10+
11+
#if defined HAVE_UTIMENSAT \
12+
&& defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW \
13+
&& defined UTIME_NOW && defined UTIME_OMIT
14+
15+
static void
16+
print_ts(const struct timespec *ts)
17+
{
18+
printf("{%ju, %ju}", (uintmax_t) ts->tv_sec, (uintmax_t) ts->tv_nsec);
19+
}
20+
21+
int
22+
main(void)
23+
{
24+
struct timeval tv;
25+
struct timespec ts[2];
26+
27+
if (gettimeofday(&tv, NULL))
28+
return 77;
29+
30+
ts[0].tv_sec = tv.tv_sec;
31+
ts[0].tv_nsec = tv.tv_usec;
32+
ts[1].tv_sec = tv.tv_sec - 1;
33+
ts[1].tv_nsec = tv.tv_usec + 1;
34+
if (!utimensat(AT_FDCWD, "utimensat\nfilename", ts,
35+
AT_SYMLINK_NOFOLLOW))
36+
return 77;
37+
38+
#define PREFIX "utimensat(AT_FDCWD, \"utimensat\\nfilename\", ["
39+
40+
printf(PREFIX);
41+
print_ts(&ts[0]);
42+
printf(", ");
43+
print_ts(&ts[1]);
44+
puts("], AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)");
45+
46+
ts[0].tv_nsec = UTIME_NOW;
47+
ts[1].tv_nsec = UTIME_OMIT;
48+
if (!utimensat(AT_FDCWD, "utimensat\nfilename", ts,
49+
AT_SYMLINK_NOFOLLOW))
50+
return 77;
51+
52+
printf(PREFIX);
53+
puts("UTIME_NOW, UTIME_OMIT], AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)");
54+
puts("+++ exited with 0 +++");
55+
56+
return 0;
57+
}
58+
59+
#else
60+
61+
int
62+
main(void)
63+
{
64+
return 77;
65+
}
66+
67+
#endif

tests/utimensat.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
# Check decoding of utimensat syscall.
4+
5+
. "${srcdir=.}/init.sh"
6+
7+
run_prog > /dev/null
8+
OUT="$LOG.out"
9+
run_strace -e utimensat $args > "$OUT"
10+
11+
check_prog grep
12+
LC_ALL=C grep -x "utimensat(.*" "$LOG" > /dev/null || {
13+
rm -f "$OUT"
14+
skip_ 'test executable does not use utimensat syscall'
15+
}
16+
17+
match_diff "$OUT" "$LOG"
18+
19+
rm -f "$OUT"
20+
21+
exit 0

0 commit comments

Comments
 (0)