Home | History | Annotate | Download | only in alarm
      1 /*
      2  * Copyright (c) International Business Machines  Corp., 2001
      3  * Copyright (C) 2017 Cyril Hrubis <chrubis (at) suse.cz>
      4  *
      5  * This program is free software;  you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 2 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  * the GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program;  if not, write to the Free Software Foundation,
     17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * Test Description:
     22  *  Check the functionality of the Alarm system call when the time input
     23  *  parameter is zero.
     24  *
     25  * Expected Result:
     26  *  The previously specified alarm request should be cancelled and the
     27  *  SIGALRM should not be received.
     28  *
     29  * HISTORY
     30  *	07/2001 Ported by Wayne Boyer
     31  */
     32 
     33 #include <stdio.h>
     34 #include <unistd.h>
     35 #include <sys/types.h>
     36 #include <errno.h>
     37 #include <string.h>
     38 #include <signal.h>
     39 
     40 #include "tst_test.h"
     41 
     42 static volatile int alarms_received = 0;
     43 
     44 static void sigproc(int sig)
     45 {
     46 	if (sig == SIGALRM)
     47 		alarms_received++;
     48 }
     49 
     50 static void setup(void)
     51 {
     52 	SAFE_SIGNAL(SIGALRM, sigproc);
     53 }
     54 
     55 static void verify_alarm(void)
     56 {
     57 	int ret;
     58 
     59 	alarm(2);
     60 	sleep(1);
     61 
     62 	ret = alarm(0);
     63 
     64 	/* Wait for signal SIGALRM */
     65 	sleep(2);
     66 
     67 	if (alarms_received)
     68 		tst_res(TFAIL, "Received %i alarms", alarms_received);
     69 	else
     70 		tst_res(TPASS, "Received 0 alarms");
     71 
     72 	if (ret == 1)
     73 		tst_res(TPASS, "alarm(0) returned 1");
     74 	else
     75 		tst_res(TFAIL, "alarm(0) returned %i, expected 1", ret);
     76 }
     77 
     78 static struct tst_test test = {
     79 	.setup = setup,
     80 	.test_all = verify_alarm,
     81 };
     82