Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: vDSO: vdso_test_correctness: Add a test for time()

Extend the test to also cover the time() function.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260227-vdso-selftest-cleanups-v2-6-d84830fa8beb@linutronix.de

authored by

Thomas Weißschuh and committed by
Borislav Petkov (AMD)
bed0053a a8b22a15

+66
+66
tools/testing/selftests/vDSO/vdso_test_correctness.c
··· 55 55 56 56 vgtod_t vdso_gettimeofday; 57 57 58 + typedef time_t (*vtime_t)(__kernel_time_t *tloc); 59 + 60 + vtime_t vdso_time; 61 + 58 62 typedef long (*getcpu_t)(unsigned *, unsigned *, void *); 59 63 60 64 getcpu_t vgetcpu; ··· 137 133 if (!vdso_gettimeofday) 138 134 printf("Warning: failed to find gettimeofday in vDSO\n"); 139 135 136 + vdso_time = (vtime_t)vdso_sym(version, name[2]); 137 + if (!vdso_time) 138 + printf("Warning: failed to find time in vDSO\n"); 139 + 140 140 } 141 141 142 142 static long sys_getcpu(unsigned * cpu, unsigned * node, ··· 162 154 static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz) 163 155 { 164 156 return syscall(__NR_gettimeofday, tv, tz); 157 + } 158 + 159 + static inline __kernel_old_time_t sys_time(__kernel_old_time_t *tloc) 160 + { 161 + #ifdef __NR_time 162 + return syscall(__NR_time, tloc); 163 + #else 164 + errno = ENOSYS; 165 + return -1; 166 + #endif 165 167 } 166 168 167 169 static void test_getcpu(void) ··· 440 422 VDSO_CALL(vdso_gettimeofday, 2, &vdso, NULL); 441 423 } 442 424 425 + static void test_time(void) 426 + { 427 + __kernel_old_time_t start, end, vdso_ret, vdso_param; 428 + 429 + if (!vdso_time) 430 + return; 431 + 432 + printf("[RUN]\tTesting time...\n"); 433 + 434 + if (sys_time(&start) < 0) { 435 + if (errno == -ENOSYS) { 436 + printf("[SKIP]\tNo time() support\n"); 437 + } else { 438 + printf("[FAIL]\tsys_time failed (%d)\n", errno); 439 + nerrs++; 440 + } 441 + return; 442 + } 443 + 444 + vdso_ret = VDSO_CALL(vdso_time, 1, &vdso_param); 445 + end = sys_time(NULL); 446 + 447 + if (vdso_ret < 0 || end < 0) { 448 + printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n", 449 + (int)vdso_ret, errno); 450 + nerrs++; 451 + return; 452 + } 453 + 454 + printf("\t%lld %lld %lld\n", 455 + (long long)start, 456 + (long long)vdso_ret, 457 + (long long)end); 458 + 459 + if (vdso_ret != vdso_param) { 460 + printf("[FAIL]\tinconsistent return values: %lld %lld\n", 461 + (long long)vdso_ret, (long long)vdso_param); 462 + nerrs++; 463 + return; 464 + } 465 + 466 + if (!(start <= vdso_ret) || !(vdso_ret <= end)) { 467 + printf("[FAIL]\tTimes are out of sequence\n"); 468 + nerrs++; 469 + } 470 + } 471 + 443 472 int main(int argc, char **argv) 444 473 { 445 474 version = versions[VDSO_VERSION]; ··· 497 432 test_clock_gettime(); 498 433 test_clock_gettime64(); 499 434 test_gettimeofday(); 435 + test_time(); 500 436 501 437 /* 502 438 * Test getcpu() last so that, if something goes wrong setting affinity,