| 1 |
/* COVERAGE: gettimeofday settimeofday clock_gettime clock_settime clock_adjtime clock_getres clock_nanosleep time stime */ |
| 2 |
|
| 3 |
#define _DEFAULT_SOURCE |
| 4 |
|
| 5 |
#include <sys/types.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include <sys/time.h> |
| 8 |
#include <time.h> |
| 9 |
#include <sys/syscall.h> |
| 10 |
#include <sys/timex.h> |
| 11 |
#include <string.h> |
| 12 |
#include <sys/mman.h> |
| 13 |
|
| 14 |
int main() |
| 15 |
{ |
| 16 |
int t; |
| 17 |
struct timeval tv; |
| 18 |
struct timespec ts; |
| 19 |
struct timex tx; |
| 20 |
time_t tt; |
| 21 |
|
| 22 |
mlockall(MCL_CURRENT); |
| 23 |
|
| 24 |
#ifdef SYS_time |
| 25 |
syscall(SYS_time, &tt); |
| 26 |
//staptest// time (XXXX) = NNNN |
| 27 |
|
| 28 |
syscall(SYS_time, NULL); |
| 29 |
//staptest// time (0x[0]+) = NNNN |
| 30 |
|
| 31 |
syscall(SYS_time, -1); |
| 32 |
#ifdef __s390__ |
| 33 |
//staptest// time (0x[7]?[f]+) = -NNNN |
| 34 |
#else |
| 35 |
//staptest// time (0x[f]+) = -NNNN |
| 36 |
#endif |
| 37 |
#endif |
| 38 |
|
| 39 |
t = syscall(SYS_gettimeofday, &tv, NULL); |
| 40 |
//staptest// gettimeofday (XXXX, 0x[0]+) = 0 |
| 41 |
|
| 42 |
// The stime() was deprecated, and with modern glibc (glibc-2.34-88.el9.ppc64le) |
| 43 |
// isn't avail even with feature macros. Glibc upstream commit 12cbde1dae6fa4 . |
| 44 |
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ <= 30 |
| 45 |
#ifdef __NR_stime |
| 46 |
tt = tv.tv_sec; |
| 47 |
stime(&tt); |
| 48 |
//staptest// stime (XXXX) = NNNN |
| 49 |
|
| 50 |
stime((time_t *)-1); |
| 51 |
#ifdef __s390__ |
| 52 |
//staptest// stime (0x[7]?[f]+) = -NNNN |
| 53 |
#else |
| 54 |
//staptest// stime (0x[f]+) = -NNNN |
| 55 |
#endif |
| 56 |
#endif |
| 57 |
#endif |
| 58 |
|
| 59 |
settimeofday(&tv, NULL); |
| 60 |
//staptest// [[[[settimeofday (\[NNNN.NNNN\], NULL)!!!!clock_settime (CLOCK_REALTIME, \[NNNN.NNNN\])]]]] = NNNN |
| 61 |
|
| 62 |
// With modern glibc, the first arg of settimeofday is marked as restrict, |
| 63 |
// and this sub testcase SEGVs. |
| 64 |
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ <= 30 |
| 65 |
settimeofday((struct timeval *)-1, NULL); |
| 66 |
#ifdef __s390__ |
| 67 |
//staptest// settimeofday (0x[7]?[f]+, NULL) = -NNNN (EFAULT) |
| 68 |
#else |
| 69 |
//staptest// settimeofday (0x[f]+, NULL) = -NNNN (EFAULT) |
| 70 |
#endif |
| 71 |
#endif |
| 72 |
|
| 73 |
syscall(SYS_settimeofday, &tv, (struct timezone *)-1); |
| 74 |
#ifdef __s390__ |
| 75 |
//staptest// settimeofday (\[NNNN.NNNN\], 0x[7]?[f]+) = -NNNN (EFAULT) |
| 76 |
#else |
| 77 |
//staptest// settimeofday (\[NNNN.NNNN\], 0x[f]+) = -NNNN (EFAULT) |
| 78 |
#endif |
| 79 |
|
| 80 |
syscall(SYS_gettimeofday, -1, NULL); |
| 81 |
#ifdef __s390__ |
| 82 |
//staptest// gettimeofday (0x[7]?[f]+, 0x[0]+) = -NNNN (EFAULT) |
| 83 |
#else |
| 84 |
//staptest// gettimeofday (0x[f]+, 0x[0]+) = -NNNN (EFAULT) |
| 85 |
#endif |
| 86 |
|
| 87 |
syscall(SYS_gettimeofday, &tv, -1); |
| 88 |
#ifdef __s390__ |
| 89 |
//staptest// gettimeofday (XXXX, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 90 |
#else |
| 91 |
//staptest// gettimeofday (XXXX, 0x[f]+) = -NNNN (EFAULT) |
| 92 |
#endif |
| 93 |
|
| 94 |
syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); |
| 95 |
//staptest// clock_gettime (CLOCK_REALTIME, XXXX) = 0 |
| 96 |
|
| 97 |
syscall(SYS_clock_settime, CLOCK_REALTIME, &ts); |
| 98 |
//staptest// clock_settime (CLOCK_REALTIME, \[NNNN.NNNN\]) = |
| 99 |
|
| 100 |
syscall(SYS_clock_getres, CLOCK_REALTIME, &ts); |
| 101 |
//staptest// clock_getres (CLOCK_REALTIME, XXXX) = 0 |
| 102 |
|
| 103 |
// On s390x, the following probe doesn't get the return hit, skip it. |
| 104 |
#if !defined(__s390__) |
| 105 |
syscall(SYS_clock_getres, -1, &ts); |
| 106 |
//staptest// clock_getres (0xffffffff, XXXX) = -NNNN (EINVAL) |
| 107 |
#endif |
| 108 |
|
| 109 |
syscall(SYS_clock_getres, CLOCK_REALTIME, -1); |
| 110 |
#ifdef __s390__ |
| 111 |
//staptest// clock_getres (CLOCK_REALTIME, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 112 |
#else |
| 113 |
//staptest// clock_getres (CLOCK_REALTIME, 0x[f]+) = -NNNN (EFAULT) |
| 114 |
#endif |
| 115 |
|
| 116 |
syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts); |
| 117 |
//staptest// clock_gettime (CLOCK_MONOTONIC, XXXX) = 0 |
| 118 |
|
| 119 |
syscall(SYS_clock_settime, CLOCK_MONOTONIC, &ts); |
| 120 |
//staptest// clock_settime (CLOCK_MONOTONIC, \[NNNN.NNNN\]) = |
| 121 |
|
| 122 |
syscall(SYS_clock_getres, CLOCK_MONOTONIC, &ts); |
| 123 |
//staptest// clock_getres (CLOCK_MONOTONIC, XXXX) = 0 |
| 124 |
|
| 125 |
syscall(SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &ts); |
| 126 |
//staptest// clock_gettime (CLOCK_PROCESS_CPUTIME_ID, XXXX) = |
| 127 |
|
| 128 |
syscall(SYS_clock_settime, CLOCK_PROCESS_CPUTIME_ID, &ts); |
| 129 |
//staptest// clock_settime (CLOCK_PROCESS_CPUTIME_ID, \[NNNN.NNNN\]) = |
| 130 |
|
| 131 |
syscall(SYS_clock_getres, CLOCK_PROCESS_CPUTIME_ID, &ts); |
| 132 |
//staptest// clock_getres (CLOCK_PROCESS_CPUTIME_ID, XXXX) = |
| 133 |
|
| 134 |
syscall(SYS_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &ts); |
| 135 |
//staptest// clock_gettime (CLOCK_THREAD_CPUTIME_ID, XXXX) = |
| 136 |
|
| 137 |
syscall(SYS_clock_settime, CLOCK_THREAD_CPUTIME_ID, &ts); |
| 138 |
//staptest// clock_settime (CLOCK_THREAD_CPUTIME_ID, \[NNNN.NNNN\]) = |
| 139 |
|
| 140 |
syscall(SYS_clock_getres, CLOCK_THREAD_CPUTIME_ID, &ts); |
| 141 |
//staptest// clock_getres (CLOCK_THREAD_CPUTIME_ID, XXXX) = |
| 142 |
|
| 143 |
syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); |
| 144 |
//staptest// clock_gettime (CLOCK_REALTIME, XXXX) = 0 |
| 145 |
|
| 146 |
ts.tv_sec++; |
| 147 |
syscall(SYS_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME, &ts); |
| 148 |
//staptest// clock_nanosleep (CLOCK_REALTIME, TIMER_ABSTIME, \[NNNN.NNNN\], XXXX) = 0 |
| 149 |
|
| 150 |
ts.tv_sec = 0; ts.tv_nsec = 10000; |
| 151 |
syscall(SYS_clock_nanosleep, CLOCK_REALTIME, 0x0, &ts); |
| 152 |
//staptest// clock_nanosleep (CLOCK_REALTIME, 0x0, \[NNNN.NNNN\], XXXX) = 0 |
| 153 |
|
| 154 |
syscall(SYS_clock_gettime, -1, &ts); |
| 155 |
//staptest// clock_gettime (0x[f]+, XXXX) = -NNNN (EINVAL) |
| 156 |
|
| 157 |
syscall(SYS_clock_gettime, CLOCK_REALTIME, -1); |
| 158 |
#ifdef __s390__ |
| 159 |
//staptest// clock_gettime (CLOCK_REALTIME, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 160 |
#else |
| 161 |
//staptest// clock_gettime (CLOCK_REALTIME, 0x[f]+) = -NNNN (EFAULT) |
| 162 |
#endif |
| 163 |
|
| 164 |
syscall(SYS_clock_settime, -1, &ts); |
| 165 |
//staptest// clock_settime (0x[f]+, \[NNNN.NNNN\]) = -NNNN (EINVAL) |
| 166 |
|
| 167 |
syscall(SYS_clock_settime, CLOCK_MONOTONIC, -1); |
| 168 |
#ifdef __s390__ |
| 169 |
//staptest// clock_settime (CLOCK_MONOTONIC, 0x[7]?[f]+) = -NNNN |
| 170 |
#else |
| 171 |
//staptest// clock_settime (CLOCK_MONOTONIC, 0x[f]+) = -NNNN |
| 172 |
#endif |
| 173 |
|
| 174 |
ts.tv_sec = 0; ts.tv_nsec = 10000; |
| 175 |
syscall(SYS_clock_nanosleep, -1, 0x0, &ts); |
| 176 |
//staptest// clock_nanosleep (0x[f]+, 0x0, \[NNNN.NNNN\], XXXX) = -NNNN |
| 177 |
ts.tv_sec = 0; ts.tv_nsec = 10000; |
| 178 |
|
| 179 |
syscall(SYS_clock_nanosleep, CLOCK_REALTIME, -1, &ts); |
| 180 |
//staptest// clock_nanosleep (CLOCK_REALTIME, 0x[f]+, \[NNNN.NNNN\], XXXX) = 0 |
| 181 |
ts.tv_sec = 0; ts.tv_nsec = 10000; |
| 182 |
|
| 183 |
syscall(SYS_clock_nanosleep, CLOCK_REALTIME, 0x0, -1); |
| 184 |
#ifdef __s390__ |
| 185 |
//staptest// clock_nanosleep (CLOCK_REALTIME, 0x0, 0x[7]?[f]+, XXXX) = -NNNN (EFAULT) |
| 186 |
#else |
| 187 |
//staptest// clock_nanosleep (CLOCK_REALTIME, 0x0, 0x[f]+, XXXX) = -NNNN (EFAULT) |
| 188 |
#endif |
| 189 |
|
| 190 |
// The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 in valid_timex_to_timex64() |
| 191 |
#if __WORDSIZE == 64 |
| 192 |
adjtimex((struct timex *)-1); |
| 193 |
#ifdef __s390__ |
| 194 |
//staptest// [[[[adjtimex (!!!!clock_adjtime (CLOCK_REALTIME, ]]]]0x[7]?[f]+) = NNNN |
| 195 |
#else |
| 196 |
//staptest// [[[[adjtimex (!!!!clock_adjtime (CLOCK_REALTIME, ]]]]0x[f]+) = NNNN |
| 197 |
#endif |
| 198 |
#endif |
| 199 |
|
| 200 |
#ifdef __NR_clock_adjtime |
| 201 |
memset(&tx, 0, sizeof(tx)); |
| 202 |
tx.modes = ADJ_STATUS; |
| 203 |
adjtimex(&tx); |
| 204 |
tx.modes = ADJ_FREQUENCY; |
| 205 |
|
| 206 |
syscall(__NR_clock_adjtime, CLOCK_REALTIME, &tx); |
| 207 |
//staptest// clock_adjtime (CLOCK_REALTIME, \{ADJ_FREQUENCY, constant=NNNN, esterror=NNNN, freq=NNNN, maxerror=NNNN, offset=NNNN, precision=NNNN, status=NNNN, tick=NNNN, tolerance=NNNN\}) = NNNN |
| 208 |
|
| 209 |
syscall(__NR_clock_adjtime, (int)-1, &tx); |
| 210 |
//staptest// clock_adjtime (0xffffffff, \{[^\}]*\}) = -NNNN |
| 211 |
|
| 212 |
syscall(__NR_clock_adjtime, CLOCK_REALTIME, (struct timex *)-1); |
| 213 |
#ifdef __s390__ |
| 214 |
//staptest// clock_adjtime (CLOCK_REALTIME, 0x[7]?[f]+) = -NNNN |
| 215 |
#else |
| 216 |
//staptest// clock_adjtime (CLOCK_REALTIME, 0x[f]+) = -NNNN |
| 217 |
#endif |
| 218 |
#endif |
| 219 |
|
| 220 |
return 0; |
| 221 |
} |