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