• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 maknayak@in.ibm.com>
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 #include <sys/syscall.h>
24 
25 #include "lapi/syscalls.h"
26 #include "tst_test.h"
27 
28 static pid_t unused_tid;
29 static pid_t inval_tid = -1;
30 
31 struct test_case_t {
32 	int *tid;
33 	int exp_errno;
34 } tc[] = {
35 	{&inval_tid, EINVAL},
36 	{&unused_tid, ESRCH}
37 };
38 
setup(void)39 static void setup(void)
40 {
41 	unused_tid = tst_get_unused_pid();
42 }
43 
run(unsigned int i)44 static void run(unsigned int i)
45 {
46 	TST_EXP_FAIL(tst_syscall(__NR_tkill, *(tc[i].tid), SIGUSR1),
47 		     tc[i].exp_errno, "tst_syscall(__NR_tkill) expecting %s",
48 			 tst_strerrno(tc[i].exp_errno));
49 }
50 
51 static struct tst_test test = {
52 	.tcnt = ARRAY_SIZE(tc),
53 	.needs_tmpdir = 1,
54 	.setup = setup,
55 	.test = run,
56 };
57