1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) International Business Machines Corp., 2001,2005 4 * Ported to LTP: Wayne Boyer 5 * 06/2005 Test for alarm cleanup by Amos Waterland 6 * 7 * Copyright (c) 2018 Cyril Hrubis <[email protected]> 8 * Copyright (c) Linux Test Project, 2006-2022 9 */ 10 11 /*\ 12 * [Description] 13 * 14 * The return value of the alarm system call should be equal to the 15 * amount previously remaining in the alarm clock. 16 * A SIGALRM signal should be received after the specified amount of 17 * time has elapsed. 18 */ 19 20 #include "tst_test.h" 21 22 static volatile int alarms_fired; 23 run(void)24static void run(void) 25 { 26 alarms_fired = 0; 27 28 TST_EXP_PASS(alarm(10)); 29 sleep(1); 30 TST_EXP_VAL(alarm(1), 9); 31 sleep(2); 32 TST_EXP_EQ_LU(alarms_fired, 1); 33 } 34 sighandler(int sig)35static void sighandler(int sig) 36 { 37 if (sig == SIGALRM) 38 alarms_fired++; 39 } 40 setup(void)41static void setup(void) 42 { 43 SAFE_SIGNAL(SIGALRM, sighandler); 44 } 45 46 static struct tst_test test = { 47 .test_all = run, 48 .setup = setup, 49 }; 50