2 * Check decoding of utimes/osf_utimes syscall.
4 * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef TEST_SYSCALL_NR
11 # error TEST_SYSCALL_NR must be defined
14 #ifndef TEST_SYSCALL_STR
15 # error TEST_SYSCALL_STR must be defined
19 # error TEST_STRUCT must be defined
28 print_tv(const TEST_STRUCT *const tv)
30 printf("{tv_sec=%lld, tv_usec=%llu}",
31 (long long) tv->tv_sec,
32 zero_extend_signed_to_ull(tv->tv_usec));
33 print_time_t_usec(tv->tv_sec,
34 zero_extend_signed_to_ull(tv->tv_usec), 1);
37 static const char *errstr;
40 k_utimes(const kernel_ulong_t pathname, const kernel_ulong_t times)
42 long rc = syscall(TEST_SYSCALL_NR, pathname, times);
43 errstr = sprintrc(rc);
50 static const char proto_fname[] = TEST_SYSCALL_STR "_sample";
51 static const char qname[] = "\"" TEST_SYSCALL_STR "_sample\"";
53 char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
54 const kernel_ulong_t kfname = (uintptr_t) fname;
55 TEST_STRUCT *const tv = tail_alloc(sizeof(*tv) * 2);
59 printf("%s(NULL, NULL) = %s\n", TEST_SYSCALL_STR, errstr);
61 k_utimes(kfname + sizeof(proto_fname) - 1, 0);
62 printf("%s(\"\", NULL) = %s\n", TEST_SYSCALL_STR, errstr);
65 printf("%s(%s, NULL) = %s\n", TEST_SYSCALL_STR, qname, errstr);
67 fname[sizeof(proto_fname) - 1] = '+';
69 fname[sizeof(proto_fname) - 1] = '\0';
70 printf("%s(%p, NULL) = %s\n", TEST_SYSCALL_STR, fname, errstr);
72 if (F8ILL_KULONG_SUPPORTED) {
73 k_utimes(f8ill_ptr_to_kulong(fname), 0);
74 printf("%s(%#jx, NULL) = %s\n", TEST_SYSCALL_STR,
75 (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
79 k_utimes(kfname, (uintptr_t) (tv + 1));
80 printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
81 qname, tv + 1, errstr);
83 k_utimes(kfname, (uintptr_t) (tv + 2));
84 printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
85 qname, tv + 2, errstr);
87 tv[0].tv_sec = 0xdeadbeefU;
88 tv[0].tv_usec = 0xfacefeedU;
89 tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
90 tv[1].tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
92 k_utimes(kfname, (uintptr_t) tv);
93 printf("%s(%s, [", TEST_SYSCALL_STR, qname);
97 printf("]) = %s\n", errstr);
99 tv[0].tv_sec = 1492358607;
100 tv[0].tv_usec = 1000000;
101 tv[1].tv_sec = 1492356078;
102 tv[1].tv_usec = 1000001;
104 k_utimes(kfname, (uintptr_t) tv);
105 printf("%s(%s, [", TEST_SYSCALL_STR, qname);
109 printf("]) = %s\n", errstr);
111 tv[0].tv_usec = 345678;
112 tv[1].tv_usec = 456789;
114 k_utimes(kfname, (uintptr_t) tv);
115 printf("%s(%s, [", TEST_SYSCALL_STR, qname);
119 printf("]) = %s\n", errstr);
121 if (F8ILL_KULONG_SUPPORTED) {
122 k_utimes(kfname, f8ill_ptr_to_kulong(tv));
123 printf("%s(%s, %#jx) = %s\n", TEST_SYSCALL_STR,
124 qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
127 puts("+++ exited with 0 +++");