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