1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2021, BELLSOFT. All rights reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Testcase to check sched_getscheduler() returns correct return value. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * [Algorithm] 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * Call sched_setcheduler() to set the scheduling policy of the current 15f08c3bdfSopenharmony_ci * process. Then call sched_getscheduler() to ensure that this is same 16f08c3bdfSopenharmony_ci * as what set by the previous call to sched_setscheduler(). 17f08c3bdfSopenharmony_ci * 18f08c3bdfSopenharmony_ci * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for 19f08c3bdfSopenharmony_ci * sched_setscheduler(). 20f08c3bdfSopenharmony_ci * 21f08c3bdfSopenharmony_ci */ 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ci#include <errno.h> 24f08c3bdfSopenharmony_ci#include <stdio.h> 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci#include "tst_test.h" 27f08c3bdfSopenharmony_ci#include "tst_sched.h" 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_cistruct test_cases_t { 30f08c3bdfSopenharmony_ci int priority; 31f08c3bdfSopenharmony_ci int policy; 32f08c3bdfSopenharmony_ci} tcases[] = { 33f08c3bdfSopenharmony_ci {1, SCHED_RR}, 34f08c3bdfSopenharmony_ci {0, SCHED_OTHER}, 35f08c3bdfSopenharmony_ci {1, SCHED_FIFO} 36f08c3bdfSopenharmony_ci}; 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_cistatic void run(unsigned int n) 39f08c3bdfSopenharmony_ci{ 40f08c3bdfSopenharmony_ci struct sched_variant *tv = &sched_variants[tst_variant]; 41f08c3bdfSopenharmony_ci struct test_cases_t *tc = &tcases[n]; 42f08c3bdfSopenharmony_ci struct sched_param p = { .sched_priority = tc->priority }; 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p)); 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci if (!TST_PASS) 47f08c3bdfSopenharmony_ci return; 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci TEST(tv->sched_getscheduler(0)); 50f08c3bdfSopenharmony_ci if (TST_RET == tc->policy) 51f08c3bdfSopenharmony_ci tst_res(TPASS, "got expected policy %d", tc->policy); 52f08c3bdfSopenharmony_ci else 53f08c3bdfSopenharmony_ci tst_res(TFAIL | TERRNO, "got policy %ld, expected %d", TST_RET, tc->policy); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic void setup(void) 57f08c3bdfSopenharmony_ci{ 58f08c3bdfSopenharmony_ci tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc); 59f08c3bdfSopenharmony_ci} 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_cistatic struct tst_test test = { 62f08c3bdfSopenharmony_ci .needs_root = 1, 63f08c3bdfSopenharmony_ci .setup = setup, 64f08c3bdfSopenharmony_ci .test_variants = ARRAY_SIZE(sched_variants), 65f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 66f08c3bdfSopenharmony_ci .test = run, 67f08c3bdfSopenharmony_ci}; 68