1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 *
5 * 1) prctl() fails with EINVAL when an invalid value is given for option
6 * 2) prctl() fails with EINVAL when option is PR_SET_PDEATHSIG & arg2 is
7 * not zero or a valid signal number
8 */
9
10 #include <errno.h>
11 #include <signal.h>
12 #include <sys/prctl.h>
13
14 #include "tst_test.h"
15
16 #define OPTION_INVALID 999
17 #define INVALID_ARG 999
18
19 static struct tcase {
20 int option;
21 unsigned long arg2;
22 int exp_errno;
23 } tcases[] = {
24 {OPTION_INVALID, 0, EINVAL},
25 {PR_SET_PDEATHSIG, INVALID_ARG, EINVAL},
26 };
27
verify_prctl(unsigned int n)28 static void verify_prctl(unsigned int n)
29 {
30 struct tcase *tc = &tcases[n];
31
32 TEST(prctl(tc->option, tc->arg2));
33 if (TST_RET == 0) {
34 tst_res(TFAIL, "prctl() succeeded unexpectedly");
35 return;
36 }
37
38 if (tc->exp_errno == TST_ERR) {
39 tst_res(TPASS | TTERRNO, "prctl() failed as expected");
40 } else {
41 tst_res(TPASS | TTERRNO, "prctl() failed unexpectedly, expected %s",
42 tst_strerrno(tc->exp_errno));
43 }
44 }
45
46 static struct tst_test test = {
47 .tcnt = ARRAY_SIZE(tcases),
48 .test = verify_prctl,
49 };
50