1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * Author: Richard Logan
5 *
6 * Test Description:
7 * The process does a fork:
8 * 1) By the value returned by child's alarm(0), check whether child
9 * process cleared the previously specified alarm request or not.
10 * 2) By the value returned by parent's alarm(0), check whether parent
11 * process cleared the previously specified alarm request or not.
12 */
13
14 #include <errno.h>
15 #include <signal.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18
19 #include "tst_test.h"
20
verify_alarm(void)21 static void verify_alarm(void)
22 {
23 pid_t pid;
24
25 TEST(alarm(100));
26
27 pid = SAFE_FORK();
28 if (pid == 0) {
29 TEST(alarm(0));
30 if (TST_RET != 0) {
31 tst_res(TFAIL,
32 "alarm(100), fork, alarm(0) child's "
33 "alarm returned %ld", TST_RET);
34 } else {
35 tst_res(TPASS,
36 "alarm(100), fork, alarm(0) child's "
37 "alarm returned %ld", TST_RET);
38 }
39 exit(0);
40 }
41
42 TEST(alarm(0));
43 if (TST_RET != 100) {
44 tst_res(TFAIL,
45 "alarm(100), fork, alarm(0) parent's "
46 "alarm returned %ld", TST_RET);
47 } else {
48 tst_res(TPASS,
49 "alarm(100), fork, alarm(0) parent's "
50 "alarm returned %ld", TST_RET);
51 }
52 }
53
54 static struct tst_test test = {
55 .test_all = verify_alarm,
56 .forks_child = 1,
57 };
58