Skip to content
Permalink
Browse files

tests: kernel: fp_sharing: increase robustness of float_disable test

This commit make the float_disable test suite more robust
for fast CPUs, by replacing k_sleep(1) with k_yield(), as
the mechanism to trigger thread swap-out during the test
execution. In the wake of using k_yield(), the test, now,
fixes the priorities of all testing threads to 0, making
the test behavior more deterministic with respect to
thread scheduling. The patch doesn't change the functional
behavior of the test.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and carlescufi committed Jul 18, 2019
1 parent fece690 commit 6c4fdc61ef5b91dc4c7f5c7a5ac25ed694a23e4b
Showing with 42 additions and 13 deletions.
  1. +42 −13 tests/kernel/fp_sharing/float_disable/src/k_float_disable.c
@@ -7,7 +7,12 @@
#include <ztest.h>

#define STACKSIZE 1024
#define PRIORITY 5

/* Priority level of the threads used in this test.
* The priority level, itself, is arbitrary; we only
* want to ensure they are cooperative threads.
*/
#define PRIORITY K_PRIO_COOP(0)

#if defined(CONFIG_ARM)
#define K_FP_OPTS K_FP_REGS
@@ -24,7 +29,7 @@ ZTEST_BMEM static volatile int ret = TC_PASS;

static void usr_fp_thread_entry_1(void)
{
k_sleep(1);
k_yield();
}

#if defined(CONFIG_ARM) || \
@@ -36,7 +41,7 @@ static void usr_fp_thread_entry_1(void)

static void usr_fp_thread_entry_2(void)
{
k_sleep(1);
k_yield();

/* System call to disable FP mode */
if (k_float_disable(k_current_get()) != K_FLOAT_DISABLE_SYSCALL_RETVAL) {
@@ -49,13 +54,23 @@ static void usr_fp_thread_entry_2(void)

void test_k_float_disable_common(void)
{
/* Create an FP-capable User thread */
ret = TC_PASS;

/* Set thread priority level to the one used
* in this test suite for cooperative threads.
*/
k_thread_priority_set(k_current_get(), PRIORITY);

/* Create an FP-capable User thread with the same cooperative
* priority as the current thread.
*/
k_thread_create(&usr_fp_thread, usr_fp_thread_stack, STACKSIZE,
(k_thread_entry_t)usr_fp_thread_entry_1, NULL, NULL, NULL,
K_PRIO_COOP(PRIORITY), K_USER | K_FP_OPTS,
PRIORITY, K_USER | K_FP_OPTS,
K_NO_WAIT);

k_sleep(1);
/* Yield will swap-in usr_fp_thread */
k_yield();

/* Verify K_FP_OPTS are set properly */
zassert_true(
@@ -92,21 +107,28 @@ void test_k_float_disable_syscall(void)
{
ret = TC_PASS;

/* Create an FP-capable User thread that will disable its FP mode */
k_thread_priority_set(k_current_get(), PRIORITY);

/* Create an FP-capable User thread with the same cooperative
* priority as the current thread. The thread will disable its
* FP mode.
*/
k_thread_create(&usr_fp_thread, usr_fp_thread_stack, STACKSIZE,
(k_thread_entry_t)usr_fp_thread_entry_2, NULL, NULL, NULL,
K_PRIO_COOP(PRIORITY), K_INHERIT_PERMS | K_USER | K_FP_OPTS,
PRIORITY, K_INHERIT_PERMS | K_USER | K_FP_OPTS,
K_NO_WAIT);

k_sleep(1);
/* Yield will swap-in usr_fp_thread */
k_yield();

/* Verify K_FP_OPTS are set properly */
zassert_true(
(usr_fp_thread.base.user_options & K_FP_OPTS) != 0,
"usr_fp_thread FP options not set (0x%0x)",
usr_fp_thread.base.user_options);

k_sleep(1);
/* Yield will swap-in usr_fp_thread */
k_yield();

#if defined(CONFIG_ARM) || \
(defined(CONFIG_X86) && defined(CONFIG_LAZY_FP_SHARING))
@@ -201,20 +223,27 @@ void test_k_float_disable_irq(void)
{
ret = TC_PASS;

/* Create an FP-capable User thread */
k_thread_priority_set(k_current_get(), PRIORITY);


/* Create an FP-capable Supervisor thread with the same cooperative
* priority as the current thread.
*/
k_thread_create(&sup_fp_thread, sup_fp_thread_stack, STACKSIZE,
(k_thread_entry_t)sup_fp_thread_entry, NULL, NULL, NULL,
K_PRIO_COOP(PRIORITY), K_FP_REGS,
PRIORITY, K_FP_REGS,
K_NO_WAIT);

k_sleep(1);
/* Yield will swap-in sup_fp_thread */
k_yield();

zassert_true(ret == TC_PASS, "");
}
#else
void test_k_float_disable_irq(void)
{
TC_PRINT("Skipped for x86 or ARM without support for dynamic IRQs\n");
ztest_test_skip();
}
#endif /* CONFIG_ARM && CONFIG_DYNAMIC_INTERRUPTS */
/**

0 comments on commit 6c4fdc6

Please sign in to comment.
You can’t perform that action at this time.