• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Linux Test Project, 2009-2021
4  * Copyright (c) Crackerjack Project, 2007
5  * Ported from Crackerjack to LTP by Manas Kumar Nayak maknayak@in.ibm.com>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Basic tests for the tkill syscall.
12  *
13  * [Algorithm]
14  *
15  * Calls tkill and capture signal to verify success.
16  */
17 
18 #include <signal.h>
19 
20 #include "lapi/syscalls.h"
21 #include "tst_test.h"
22 
23 static volatile sig_atomic_t sig_flag;
24 
sighandler(int sig)25 static void sighandler(int sig)
26 {
27 	if (sig == SIGUSR1)
28 		sig_flag = 1;
29 }
30 
setup(void)31 static void setup(void)
32 {
33 	SAFE_SIGNAL(SIGUSR1, sighandler);
34 }
35 
run(void)36 static void run(void)
37 {
38 	int tid;
39 	int timeout_ms = 1000;
40 	sig_flag = 0;
41 
42 	tid = tst_syscall(__NR_gettid);
43 	TST_EXP_PASS(tst_syscall(__NR_tkill, tid, SIGUSR1));
44 
45 	while (timeout_ms--) {
46 		if (sig_flag)
47 			break;
48 
49 		usleep(1000);
50 	}
51 
52 	if (sig_flag)
53 		tst_res(TPASS, "signal captured");
54 	else
55 		tst_res(TFAIL, "signal not captured");
56 }
57 
58 static struct tst_test test = {
59 	.needs_tmpdir = 1,
60 	.setup = setup,
61 	.test_all = run,
62 };
63