This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit b95c9980b5ab7babbe086827c943271f5e164083 Author: buxiasen <[email protected]> AuthorDate: Wed Sep 3 17:37:08 2025 +0800 apps/ostest/roundrobin: add fail detect and print Before patch we never detect the roundrobin fail. After patch use a array to detect if the calculation swapped when processing. Signed-off-by: buxiasen <[email protected]> --- testing/ostest/Kconfig | 4 ++-- testing/ostest/roundrobin.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/testing/ostest/Kconfig b/testing/ostest/Kconfig index 98b54f101..83054fa68 100644 --- a/testing/ostest/Kconfig +++ b/testing/ostest/Kconfig @@ -53,7 +53,7 @@ endif config TESTING_OSTEST_RR_RANGE int "Round-robin test - end of search range" - default 10000 + default 30000 range 1 32767 ---help--- During round-robin scheduling test two threads are created. Each of the threads @@ -62,7 +62,7 @@ config TESTING_OSTEST_RR_RANGE This value specifies the end of search range and together with number of runs allows to configure the length of this test - it should last at least a few - tens of seconds. Allowed values [1; 32767], default 10000 + tens of seconds. Allowed values [1; 32767], default 30000 config TESTING_OSTEST_RR_RUNS int "Round-robin test - number of runs" diff --git a/testing/ostest/roundrobin.c b/testing/ostest/roundrobin.c index c74bbc1f0..2735ba028 100644 --- a/testing/ostest/roundrobin.c +++ b/testing/ostest/roundrobin.c @@ -66,6 +66,8 @@ * Private Data ****************************************************************************/ +static uint8_t g_rr_values[CONFIG_TESTING_OSTEST_RR_RUNS * 2]; +static atomic_t g_rr_value_index; static sem_t g_rrsem; /**************************************************************************** @@ -132,6 +134,7 @@ static FAR void *get_primes_thread(FAR void *parameter) for (i = 0; i < CONFIG_TESTING_OSTEST_RR_RUNS; i++) { get_primes(&count, &last); + g_rr_values[atomic_fetch_add(&g_rr_value_index, 1)] = id; } printf("get_primes_thread id=%d finished, found %d primes, " @@ -154,11 +157,13 @@ void rr_test(void) pthread_t get_primes1_thread; pthread_t get_primes2_thread; struct sched_param sparam; + bool test_passed = false; pthread_attr_t attr; pthread_addr_t result; int status; + int i; - /* Setup common thread attrributes */ + /* Setup common thread attributes */ status = pthread_attr_init(&attr); if (status != OK) @@ -197,6 +202,8 @@ void rr_test(void) /* This semaphore will prevent anything from running until we are ready */ sched_lock(); + atomic_set(&g_rr_value_index, 0); + memset(g_rr_values, 0, sizeof(g_rr_values)); sem_init(&g_rrsem, 0, 0); /* Start the threads */ @@ -235,7 +242,26 @@ void rr_test(void) pthread_join(get_primes2_thread, &result); pthread_join(get_primes1_thread, &result); - printf("rr_test: Done\n"); + + for (i = 1; i < CONFIG_TESTING_OSTEST_RR_RUNS; i++) + { + if (g_rr_values[i - 1] != g_rr_values[i]) + { + test_passed = true; + break; + } + } + + if (test_passed) + { + printf("rr_test: Done\n"); + } + else + { + printf("rr_test: Roundrobin Failed\n"); + ASSERT(false); + } + sem_destroy(&g_rrsem); }
