2 * Check decoding of utimes/osf_utimes syscall.
4 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef TEST_SYSCALL_NR
31 # error TEST_SYSCALL_NR must be defined
34 #ifndef TEST_SYSCALL_STR
35 # error TEST_SYSCALL_STR must be defined
39 # error TEST_STRUCT must be defined
48 print_tv(const TEST_STRUCT *const tv)
50 printf("{tv_sec=%ju, tv_usec=%ju}",
51 (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
54 static const char *errstr;
57 k_utimes(const kernel_ulong_t pathname, const kernel_ulong_t times)
59 long rc = syscall(TEST_SYSCALL_NR, pathname, times);
60 errstr = sprintrc(rc);
67 static const char proto_fname[] = TEST_SYSCALL_STR "_sample";
68 static const char qname[] = "\"" TEST_SYSCALL_STR "_sample\"";
70 char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
71 const kernel_ulong_t kfname = (uintptr_t) fname;
72 TEST_STRUCT *const tv = tail_alloc(sizeof(*tv) * 2);
76 printf("%s(NULL, NULL) = %s\n", TEST_SYSCALL_STR, errstr);
78 k_utimes(kfname + sizeof(proto_fname) - 1, 0);
79 printf("%s(\"\", NULL) = %s\n", TEST_SYSCALL_STR, errstr);
82 printf("%s(%s, NULL) = %s\n", TEST_SYSCALL_STR, qname, errstr);
84 fname[sizeof(proto_fname) - 1] = '+';
86 fname[sizeof(proto_fname) - 1] = '\0';
87 printf("%s(%p, NULL) = %s\n", TEST_SYSCALL_STR, fname, errstr);
89 if (F8ILL_KULONG_SUPPORTED) {
90 k_utimes(f8ill_ptr_to_kulong(fname), 0);
91 printf("%s(%#jx, NULL) = %s\n", TEST_SYSCALL_STR,
92 (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
96 k_utimes(kfname, (uintptr_t) (tv + 1));
97 printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
98 qname, tv + 1, errstr);
100 k_utimes(kfname, (uintptr_t) (tv + 2));
101 printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
102 qname, tv + 2, errstr);
104 tv[0].tv_sec = 1492358607;
105 tv[0].tv_usec = 345678912;
106 tv[1].tv_sec = 1492356078;
107 tv[1].tv_usec = 456789023;
109 k_utimes(kfname, (uintptr_t) tv);
110 printf("%s(%s, [", TEST_SYSCALL_STR, qname);
114 printf("]) = %s\n", errstr);
116 tv[0].tv_usec = 345678;
117 tv[1].tv_usec = 456789;
119 k_utimes(kfname, (uintptr_t) tv);
120 printf("%s(%s, [", TEST_SYSCALL_STR, qname);
124 printf("]) = %s\n", errstr);
126 if (F8ILL_KULONG_SUPPORTED) {
127 k_utimes(kfname, f8ill_ptr_to_kulong(tv));
128 printf("%s(%s, %#jx) = %s\n", TEST_SYSCALL_STR,
129 qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
132 puts("+++ exited with 0 +++");