diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-03-04 22:00:57 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-03-04 22:00:57 +0000 |
commit | 78c753a2bc1062c1fdb4c7b2e618554896827b45 (patch) | |
tree | bed7e68b13373f89a7ffd8feb37b0cc557e9da5b /testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c | |
parent | 215bb8bdef76ef57566913dc4e9fc0bc20b0d92d (diff) | |
parent | 90164cf586a337bcb89a75f9dd92b9803e278dc1 (diff) | |
download | ltp-simpleperf-release.tar.gz |
Snap for 11526323 from 90164cf586a337bcb89a75f9dd92b9803e278dc1 to simpleperf-releasesimpleperf-release
Change-Id: I288786e8fccc3a1f3a579fa5d8791b22977dd569
Diffstat (limited to 'testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c')
-rw-r--r-- | testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file mode 100644 index 000000000..828d1ec09 --- /dev/null +++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Federico Bonfiglio <federico.bonfiglio@protonmail.ch> + */ + +/* + * [Description] + * + * Testcases that test if sched_setscheduler with flag + * SCHED_RESET_ON_FORK restores children policy to + * SCHED_NORMAL. + * + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <linux/sched.h> + +#include "tst_test.h" +#include "tst_sched.h" + +struct test_case_t { + int policy; + char *desc; +}; + +static struct test_case_t cases[] = { + { + .policy = SCHED_FIFO, + .desc = "SCHED_FIFO" + }, + { + .policy = SCHED_RR, + .desc = "SCHED_RR" + } +}; + +static void test_reset_on_fork(unsigned int i) +{ + struct sched_variant *tv = &sched_variants[tst_variant]; + struct test_case_t *tc = &cases[i]; + + tst_res(TINFO, "Testing %s variant %s policy", tv->desc, tc->desc); + + struct sched_param param = { .sched_priority = 10 }; + + tv->sched_setscheduler(getpid(), tc->policy | SCHED_RESET_ON_FORK, ¶m); + + pid_t pid = SAFE_FORK(); + + if (pid) { + if (sched_getscheduler(pid) == SCHED_NORMAL) + tst_res(TPASS, "Policy reset to SCHED_NORMAL"); + else + tst_res(TFAIL, "Policy NOT reset to SCHED_NORMAL"); + + sched_getparam(pid, ¶m); + + /* kernel will return sched_priority 0 if task is not RT Policy */ + if (param.sched_priority == 0) + tst_res(TPASS, "Priority set to 0"); + else + tst_res(TFAIL, "Priority not set to 0"); + } +} + +static struct tst_test test = { + .forks_child = 1, + .caps = (struct tst_cap[]) { + TST_CAP(TST_CAP_REQ, CAP_SYS_NICE), + {} + }, + .test_variants = ARRAY_SIZE(sched_variants), + .tcnt = ARRAY_SIZE(cases), + .test = test_reset_on_fork, +}; |