xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/tkill/tkill02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Crackerjack Project., 2007
4  * Ported from Crackerjack to LTP by Manas Kumar Nayak [email protected]>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Basic tests for the tkill() errors.
11  *
12  * [Algorithm]
13  *
14  * - EINVAL on an invalid thread ID
15  * - ESRCH when no process with the specified thread ID exists
16  */
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <signal.h>
23 
24 #include "tst_test.h"
25 #include "lapi/syscalls.h"
26 
27 static pid_t unused_tid;
28 static pid_t inval_tid = -1;
29 
30 struct test_case_t {
31 	int *tid;
32 	int exp_errno;
33 } tc[] = {
34 	{&inval_tid, EINVAL},
35 	{&unused_tid, ESRCH}
36 };
37 
setup(void)38 static void setup(void)
39 {
40 	unused_tid = tst_get_unused_pid();
41 }
42 
run(unsigned int i)43 static void run(unsigned int i)
44 {
45 	TST_EXP_FAIL(tst_syscall(__NR_tkill, *(tc[i].tid), SIGUSR1),
46 		     tc[i].exp_errno, "tst_syscall(__NR_tkill) expecting %s",
47 			 tst_strerrno(tc[i].exp_errno));
48 }
49 
50 static struct tst_test test = {
51 	.tcnt = ARRAY_SIZE(tc),
52 	.needs_tmpdir = 1,
53 	.setup = setup,
54 	.test = run,
55 };
56