Home | History | Annotate | Download | only in alarm
      1 // SPDX-License-Identifier: GPL-2.0-or-later
      2 /*
      3  * Copyright (c) International Business Machines  Corp., 2001
      4  * Author: Wayne Boyer
      5  *
      6  * Test Description:
      7  *  By the SIGALRM signal, check whether the previously specified alarm request
      8  *  was cleared in the child process or not.
      9  */
     10 
     11 #include <unistd.h>
     12 #include <stdlib.h>
     13 #include <errno.h>
     14 #include <signal.h>
     15 
     16 #include "tst_test.h"
     17 
     18 static volatile int alarm_cnt = 0;
     19 
     20 static void verify_alarm(void)
     21 {
     22 	pid_t pid;
     23 	alarm_cnt = 0;
     24 
     25 	TEST(alarm(1));
     26 	pid = SAFE_FORK();
     27 
     28 	sleep(3);
     29 
     30 	if (pid == 0) {
     31 		if (alarm_cnt == 0) {
     32 			tst_res(TPASS, "alarm() request cleared in child");
     33 		} else {
     34 			tst_res(TFAIL, "alarm() request not cleared in "
     35 				"child; alarms received:%d", alarm_cnt);
     36 		}
     37 		exit(0);
     38 	}
     39 
     40 	if (alarm_cnt != 1)
     41 		tst_res(TFAIL, "Sigalarms in parent %i, expected 1", alarm_cnt);
     42 	else
     43 		tst_res(TPASS, "Got 1 sigalarm in parent");
     44 }
     45 
     46 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
     47 {
     48 	alarm_cnt++;
     49 }
     50 
     51 static void setup(void)
     52 {
     53 	SAFE_SIGNAL(SIGALRM, sighandler);
     54 }
     55 
     56 static struct tst_test test = {
     57 	.test_all = verify_alarm,
     58 	.setup = setup,
     59 	.forks_child = 1,
     60 };
     61