1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later 2*49cdfc7eSAndroid Build Coastguard Worker /* 3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001 4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2017 Cyril Hrubis <[email protected]> 5*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Linux Test Project, 2002-2022 6*49cdfc7eSAndroid Build Coastguard Worker * Ported to LTP: Wayne Boyer 7*49cdfc7eSAndroid Build Coastguard Worker */ 8*49cdfc7eSAndroid Build Coastguard Worker 9*49cdfc7eSAndroid Build Coastguard Worker /*\ 10*49cdfc7eSAndroid Build Coastguard Worker * [Description] 11*49cdfc7eSAndroid Build Coastguard Worker * 12*49cdfc7eSAndroid Build Coastguard Worker * Verify that any pending alarm() is canceled when seconds is zero. 13*49cdfc7eSAndroid Build Coastguard Worker */ 14*49cdfc7eSAndroid Build Coastguard Worker 15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h" 16*49cdfc7eSAndroid Build Coastguard Worker 17*49cdfc7eSAndroid Build Coastguard Worker static volatile int alarms_received; 18*49cdfc7eSAndroid Build Coastguard Worker sigproc(int sig)19*49cdfc7eSAndroid Build Coastguard Workerstatic void sigproc(int sig) 20*49cdfc7eSAndroid Build Coastguard Worker { 21*49cdfc7eSAndroid Build Coastguard Worker if (sig == SIGALRM) 22*49cdfc7eSAndroid Build Coastguard Worker alarms_received++; 23*49cdfc7eSAndroid Build Coastguard Worker } 24*49cdfc7eSAndroid Build Coastguard Worker setup(void)25*49cdfc7eSAndroid Build Coastguard Workerstatic void setup(void) 26*49cdfc7eSAndroid Build Coastguard Worker { 27*49cdfc7eSAndroid Build Coastguard Worker SAFE_SIGNAL(SIGALRM, sigproc); 28*49cdfc7eSAndroid Build Coastguard Worker } 29*49cdfc7eSAndroid Build Coastguard Worker verify_alarm(void)30*49cdfc7eSAndroid Build Coastguard Workerstatic void verify_alarm(void) 31*49cdfc7eSAndroid Build Coastguard Worker { 32*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS_SILENT(alarm(2)); 33*49cdfc7eSAndroid Build Coastguard Worker sleep(1); 34*49cdfc7eSAndroid Build Coastguard Worker 35*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_VAL(alarm(0), 1); 36*49cdfc7eSAndroid Build Coastguard Worker 37*49cdfc7eSAndroid Build Coastguard Worker /* Wait for signal SIGALRM */ 38*49cdfc7eSAndroid Build Coastguard Worker sleep(2); 39*49cdfc7eSAndroid Build Coastguard Worker 40*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LU(alarms_received, 0); 41*49cdfc7eSAndroid Build Coastguard Worker } 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = { 44*49cdfc7eSAndroid Build Coastguard Worker .setup = setup, 45*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_alarm, 46*49cdfc7eSAndroid Build Coastguard Worker }; 47