1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) Crackerjack Project., 2007 4 * Porting from Crackerjack to LTP is done by: 5 * Manas Kumar Nayak <maknayak@in.ibm.com> 6 * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> 7 */ 8 9#include <time.h> 10#include <signal.h> 11#include <sys/syscall.h> 12#include <stdio.h> 13#include <errno.h> 14 15#include "time64_variants.h" 16#include "tst_timer.h" 17 18static struct time64_variants variants[] = { 19#if (__NR_timer_gettime != __LTP__NR_INVALID_SYSCALL) 20 { .timer_gettime = sys_timer_gettime, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, 21#endif 22 23#if (__NR_timer_gettime64 != __LTP__NR_INVALID_SYSCALL) 24 { .timer_gettime = sys_timer_gettime64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, 25#endif 26}; 27 28static kernel_timer_t timer; 29 30static void setup(void) 31{ 32 struct sigevent ev; 33 34 tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); 35 36 ev.sigev_value = (union sigval) 0; 37 ev.sigev_signo = SIGALRM; 38 ev.sigev_notify = SIGEV_SIGNAL; 39 40 TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer)); 41 42 if (TST_RET) { 43 tst_res(TFAIL | TTERRNO, "timer_create() failed"); 44 return; 45 } 46} 47 48static void verify(void) 49{ 50 struct time64_variants *tv = &variants[tst_variant]; 51 struct tst_its spec = {.type = tv->ts_type, }; 52 53 TEST(tv->timer_gettime(timer, tst_its_get(&spec))); 54 if (TST_RET == 0) { 55 if (tst_its_get_interval_sec(spec) || 56 tst_its_get_interval_nsec(spec) || 57 tst_its_get_value_sec(spec) || 58 tst_its_get_value_nsec(spec)) 59 tst_res(TFAIL, "timespec should have been zeroed"); 60 else 61 tst_res(TPASS, "timer_gettime() Passed"); 62 } else { 63 tst_res(TFAIL | TTERRNO, "timer_gettime() Failed"); 64 } 65 66 TEST(tv->timer_gettime((kernel_timer_t)-1, tst_its_get(&spec))); 67 if (TST_RET == -1 && TST_ERR == EINVAL) 68 tst_res(TPASS, "timer_gettime(-1) Failed: EINVAL"); 69 else 70 tst_res(TFAIL | TTERRNO, "timer_gettime(-1) = %li", TST_RET); 71 72 TEST(tv->timer_gettime(timer, NULL)); 73 if (TST_RET == -1 && TST_ERR == EFAULT) 74 tst_res(TPASS, "timer_gettime(NULL) Failed: EFAULT"); 75 else 76 tst_res(TFAIL | TTERRNO, "timer_gettime(-1) = %li", TST_RET); 77} 78 79static struct tst_test test = { 80 .test_all = verify, 81 .test_variants = ARRAY_SIZE(variants), 82 .setup = setup, 83 .needs_tmpdir = 1, 84}; 85