xiaoxiang781216 commented on code in PR #3393: URL: https://github.com/apache/nuttx-apps/pull/3393#discussion_r2754667722
########## testing/ostest/sched_params.c: ########## @@ -0,0 +1,346 @@ +/**************************************************************************** + * apps/testing/ostest/sched_params.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> +#include <errno.h> +#include <sched.h> +#include <pthread.h> +#include <unistd.h> +#include <assert.h> +#include <time.h> + +#include <nuttx/sched.h> + +#include "ostest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Test parameters */ + +#define SCHEDULER_TEST_PRIORITY_LOW 100 +#define SCHEDULER_TEST_PRIORITY_MED 150 +#define SCHEDULER_TEST_PRIORITY_HIGH 200 + +#ifdef CONFIG_SCHED_SPORADIC +#define SPORADIC_INIT_PRIORITY 150 +#define SPORADIC_MAX_REPL 200 /* Max priority */ +#define SPORADIC_REPL_PERIOD 1000 /* milliseconds */ +#define SPORADIC_BUDGET 300 /* milliseconds */ +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static pthread_t g_test_thread; +static volatile bool g_thread_ready = false; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_test_thread + * + * Description: + * Test thread that can have its scheduler parameters modified. + * + ****************************************************************************/ + +static FAR void *sched_test_thread(FAR void *parameter) +{ + g_thread_ready = true; + + /* Just keep the thread running for testing */ + + while (1) + { + usleep(100000); /* Sleep 100ms */ + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sched_params_test + * + * Description: + * Test nxsched_set_param, nxsched_get_param, nxsched_set_scheduler, + * and nxsched_get_scheduler functions. Also test CONFIG_SCHED_SPORADIC + * if enabled. + * + ****************************************************************************/ + +void sched_params_test(void) +{ + struct sched_param param; + struct sched_param get_param; + int policy; + int ret; + int current_priority; + pid_t main_pid; + int test_priorities[4]; + int i; + + test_priorities[0] = 120; + test_priorities[1] = 140; + test_priorities[2] = 160; + test_priorities[3] = 130; + + printf("\nsched_params_test: Starting scheduler parameters test\n"); + + /* Test 1: Get main task's current scheduler and parameters */ + + printf("\nTest 1: Get main task scheduler and priority\n"); + + main_pid = getpid(); + printf("sched_params_test: Main task PID = %d\n", main_pid); + + /* Get scheduler policy for main task */ + + ret = nxsched_get_scheduler(main_pid); Review Comment: why not call sched_get_xxx, so protect/kernel build can run this test case? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
