1 /* 2 * Copyright (c) International Business Machines Corp., 2001,2005 3 * 07/2001 Ported by Wayne Boyer 4 * 06/2005 Test for alarm cleanup by Amos Waterland 5 * 6 * Copyright (c) 2018 Cyril Hrubis <chrubis (at) suse.cz> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 16 * the GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 23 /* 24 * Test Description: 25 * The return value of the alarm system call should be equal to the 26 * amount previously remaining in the alarm clock. 27 * A SIGALRM signal should be received after the specified amount of 28 * time has elapsed. 29 */ 30 31 #include "tst_test.h" 32 33 static volatile int alarms_fired = 0; 34 35 static void run(void) 36 { 37 unsigned int ret; 38 39 alarms_fired = 0; 40 41 ret = alarm(10); 42 if (ret) 43 tst_res(TFAIL, "alarm() returned non-zero"); 44 else 45 tst_res(TPASS, "alarm() returned zero"); 46 47 sleep(1); 48 49 ret = alarm(1); 50 if (ret == 9) 51 tst_res(TPASS, "alarm() returned remainder correctly"); 52 else 53 tst_res(TFAIL, "alarm() returned wrong remained %u", ret); 54 55 sleep(2); 56 57 if (alarms_fired == 1) 58 tst_res(TPASS, "alarm handler fired once"); 59 else 60 tst_res(TFAIL, "alarm handler filred %u times", alarms_fired); 61 } 62 63 static void sighandler(int sig) 64 { 65 if (sig == SIGALRM) 66 alarms_fired++; 67 } 68 69 static void setup(void) 70 { 71 SAFE_SIGNAL(SIGALRM, sighandler); 72 } 73 74 static struct tst_test test = { 75 .test_all = run, 76 .setup = setup, 77 }; 78