Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testing/ostest/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
47 changes: 45 additions & 2 deletions testing/ostest/roundrobin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/****************************************************************************
Expand Down Expand Up @@ -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, "
Expand All @@ -154,11 +157,16 @@ 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;
#ifdef CONFIG_SMP
cpu_set_t cpuset;
#endif
int status;
int i;

/* Setup common thread attrributes */
/* Setup common thread attributes */

status = pthread_attr_init(&attr);
if (status != OK)
Expand Down Expand Up @@ -194,9 +202,25 @@ void rr_test(void)
printf("rr_test: Set thread policy to SCHED_RR\n");
}

#ifdef CONFIG_SMP
/* RR case on SMP only run on core0 */

CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset);
status = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
if (status != OK)
{
printf("rr_test: ERROR: pthread_attr_setaffinity_np failed,"
" status=%d\n", status);
ASSERT(false);
}
#endif

/* 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 */
Expand Down Expand Up @@ -235,7 +259,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);
}

Expand Down
Loading