Skip to content

Commit 6aebbc1

Browse files
committed
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]>
1 parent b90440f commit 6aebbc1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

testing/ostest/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ endif
5353

5454
config TESTING_OSTEST_RR_RANGE
5555
int "Round-robin test - end of search range"
56-
default 10000
56+
default 30000
5757
range 1 32767
5858
---help---
5959
During round-robin scheduling test two threads are created. Each of the threads
@@ -62,7 +62,7 @@ config TESTING_OSTEST_RR_RANGE
6262

6363
This value specifies the end of search range and together with number of runs
6464
allows to configure the length of this test - it should last at least a few
65-
tens of seconds. Allowed values [1; 32767], default 10000
65+
tens of seconds. Allowed values [1; 32767], default 30000
6666

6767
config TESTING_OSTEST_RR_RUNS
6868
int "Round-robin test - number of runs"

testing/ostest/roundrobin.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
* Private Data
6767
****************************************************************************/
6868

69+
static uint8_t g_rr_values[CONFIG_TESTING_OSTEST_RR_RUNS * 2];
70+
static atomic_t g_rr_value_index;
6971
static sem_t g_rrsem;
7072

7173
/****************************************************************************
@@ -132,6 +134,7 @@ static FAR void *get_primes_thread(FAR void *parameter)
132134
for (i = 0; i < CONFIG_TESTING_OSTEST_RR_RUNS; i++)
133135
{
134136
get_primes(&count, &last);
137+
g_rr_values[atomic_fetch_add(&g_rr_value_index, 1)] = id;
135138
}
136139

137140
printf("get_primes_thread id=%d finished, found %d primes, "
@@ -154,11 +157,13 @@ void rr_test(void)
154157
pthread_t get_primes1_thread;
155158
pthread_t get_primes2_thread;
156159
struct sched_param sparam;
160+
bool test_passed = false;
157161
pthread_attr_t attr;
158162
pthread_addr_t result;
159163
int status;
164+
int i;
160165

161-
/* Setup common thread attrributes */
166+
/* Setup common thread attributes */
162167

163168
status = pthread_attr_init(&attr);
164169
if (status != OK)
@@ -197,6 +202,8 @@ void rr_test(void)
197202
/* This semaphore will prevent anything from running until we are ready */
198203

199204
sched_lock();
205+
atomic_set(&g_rr_value_index, 0);
206+
memset(g_rr_values, 0, sizeof(g_rr_values));
200207
sem_init(&g_rrsem, 0, 0);
201208

202209
/* Start the threads */
@@ -235,7 +242,26 @@ void rr_test(void)
235242

236243
pthread_join(get_primes2_thread, &result);
237244
pthread_join(get_primes1_thread, &result);
238-
printf("rr_test: Done\n");
245+
246+
for (i = 1; i < CONFIG_TESTING_OSTEST_RR_RUNS; i++)
247+
{
248+
if (g_rr_values[i - 1] != g_rr_values[i])
249+
{
250+
test_passed = true;
251+
break;
252+
}
253+
}
254+
255+
if (test_passed)
256+
{
257+
printf("rr_test: Done\n");
258+
}
259+
else
260+
{
261+
printf("rr_test: Roundrobin Failed\n");
262+
ASSERT(false);
263+
}
264+
239265
sem_destroy(&g_rrsem);
240266
}
241267

0 commit comments

Comments
 (0)