• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Huawei Technologies Co., Ltd., 2015
4  * Copyright (c) Linux Test Project, 2015-2024
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Verify that, sched_getattr(2) returns -1 and sets errno to:
11  *
12  * 1. ESRCH if pid is unused.
13  * 2. EINVAL if address is NULL.
14  * 3. EINVAL if size is invalid.
15  * 4. EINVAL if flag is not zero.
16  */
17 
18 #define _GNU_SOURCE
19 
20 #include <errno.h>
21 #include "tst_test.h"
22 #include "lapi/sched.h"
23 
24 static pid_t pid;
25 static pid_t unused_pid;
26 static struct sched_attr attr_copy;
27 
28 static struct test_case {
29 	pid_t *pid;
30 	struct sched_attr *attr;
31 	unsigned int size;
32 	unsigned int flags;
33 	int exp_errno;
34 } tcase[] = {
35 	{&unused_pid, &attr_copy, sizeof(struct sched_attr), 0, ESRCH},
36 	{&pid, NULL, sizeof(struct sched_attr), 0, EINVAL},
37 	{&pid, &attr_copy, SCHED_ATTR_SIZE_VER0 - 1, 0, EINVAL},
38 	{&pid, &attr_copy, sizeof(struct sched_attr), 1000, EINVAL}
39 };
40 
verify_sched_getattr(unsigned int n)41 static void verify_sched_getattr(unsigned int n)
42 {
43 	struct test_case *tc = &tcase[n];
44 
45 	TST_EXP_FAIL(sched_getattr(*(tc->pid), tc->attr, tc->size, tc->flags),
46 				 tc->exp_errno, "sched_getattr(%d, ..., %d, %d)", *tc->pid,
47 				 tc->size, tc->flags);
48 }
49 
setup(void)50 static void setup(void)
51 {
52 	unused_pid = tst_get_unused_pid();
53 }
54 
55 static struct tst_test test = {
56 	.needs_tmpdir = 1,
57 	.test = verify_sched_getattr,
58 	.tcnt = ARRAY_SIZE(tcase),
59 	.setup = setup,
60 };
61