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