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