1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4 */
5
6/*\
7 * [Description]
8 *
9 * Verify that:
10 *
11 * - sched_getparam(2) returns -1 and sets errno to ESRCH if the
12 * process with specified pid could not be found
13 * - sched_getparam(2) returns -1 and sets errno to EINVAL if
14 * the parameter pid is an invalid value (-1)
15 * - sched_getparam(2) returns -1 and sets errno to EINVAL if the
16 * parameter p is an invalid address
17 */
18
19#include <errno.h>
20#include "tst_test.h"
21#include "tst_sched.h"
22
23static struct sched_param param;
24static pid_t unused_pid;
25static pid_t zero_pid;
26static pid_t inval_pid = -1;
27
28static struct test_case_t {
29	char *desc;
30	pid_t *pid;
31	struct sched_param *p;
32	int exp_errno;
33} test_cases[] = {
34	{"sched_getparam() with non-existing pid",
35	 &unused_pid, &param, ESRCH},
36	{"sched_getparam() with invalid pid",
37	 &inval_pid, &param, EINVAL},
38	{"sched_getparam() with invalid address for param",
39	 &zero_pid, NULL, EINVAL},
40};
41
42static void verify_sched_getparam(unsigned int n)
43{
44	struct test_case_t *tc = &test_cases[n];
45	struct sched_variant *tv = &sched_variants[tst_variant];
46
47	TST_EXP_FAIL(tv->sched_getparam(*(tc->pid), tc->p), tc->exp_errno,
48		     "%s", tc->desc);
49}
50
51static void setup(void)
52{
53	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
54	unused_pid = tst_get_unused_pid();
55}
56
57static struct tst_test test = {
58	.setup = setup,
59	.test_variants = ARRAY_SIZE(sched_variants),
60	.tcnt = ARRAY_SIZE(test_cases),
61	.test = verify_sched_getparam,
62};
63