tests: cmsis_rtos_v2: Dynamic thread stack tests

Added a set of tests that use the default thread stacks to ensure they
work the same as the passed in stacks. Abstracted the common
functionality into functions.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
This commit is contained in:
Carlos Stuart 2019-02-06 08:39:43 +00:00 committed by Anas Nashif
parent d4eb2c9014
commit c6375729ff
3 changed files with 62 additions and 15 deletions

View File

@ -9,4 +9,7 @@ CONFIG_THREAD_MONITOR=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_INIT_STACKS=y
CONFIG_SCHED_SCALABLE=y
CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE=128
CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE=128
CONFIG_CMSIS_V2_THREAD_MAX_COUNT=16
CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT=3
CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE=512

View File

@ -11,7 +11,9 @@
extern void test_kernel_apis(void);
extern void test_delay(void);
extern void test_thread_apis(void);
extern void test_thread_apis_dynamic(void);
extern void test_thread_prio(void);
extern void test_thread_prio_dynamic(void);
extern void test_timer(void);
extern void test_mutex(void);
extern void test_mutex_lock_timeout(void);
@ -32,7 +34,9 @@ void test_main(void)
ztest_unit_test(test_kernel_apis),
ztest_unit_test(test_delay),
ztest_unit_test(test_thread_apis),
ztest_unit_test(test_thread_apis_dynamic),
ztest_unit_test(test_thread_prio),
ztest_unit_test(test_thread_prio_dynamic),
ztest_unit_test(test_timer),
ztest_unit_test(test_mutex),
ztest_unit_test(test_mutex_lock_timeout),

View File

@ -12,6 +12,7 @@
/* This is used to check the thread yield functionality between 2 threads */
static int thread_yield_check;
static int thread_yield_check_dynamic;
static K_THREAD_STACK_DEFINE(test_stack1, STACKSZ);
static osThreadAttr_t thread1_attr = {
@ -29,22 +30,28 @@ static osThreadAttr_t thread2_attr = {
.priority = osPriorityHigh,
};
struct thread1_args {
int *yield_check;
const char *name;
};
static void thread1(void *argument)
{
osStatus_t status;
osThreadId_t thread_id;
const char *name;
struct thread1_args *args = (struct thread1_args *)argument;
thread_id = osThreadGetId();
zassert_true(thread_id != NULL, "Failed getting Thread ID");
name = osThreadGetName(thread_id);
zassert_true(strcmp(thread1_attr.name, name) == 0,
zassert_true(strcmp(args->name, name) == 0,
"Failed getting Thread name");
/* This thread starts off at a high priority (same as thread2) */
thread_yield_check++;
zassert_equal(thread_yield_check, 1, NULL);
(*args->yield_check)++;
zassert_equal(*args->yield_check, 1, NULL);
/* Yield to thread2 which is of same priority */
status = osThreadYield();
@ -53,7 +60,7 @@ static void thread1(void *argument)
/* thread_yield_check should now be 2 as it was incremented
* in thread2.
*/
zassert_equal(thread_yield_check, 2, NULL);
zassert_equal(*args->yield_check, 2, NULL);
osThreadExit();
}
@ -62,12 +69,13 @@ static void thread2(void *argument)
{
u32_t i, num_threads, max_num_threads = 5;
osThreadId_t *thread_array;
int *yield_check = (int *)argument;
/* By now thread1 would have set thread_yield_check to 1 and would
* have yielded the CPU. Incrementing it over here would essentially
* confirm that the yield was indeed executed.
*/
thread_yield_check++;
(*yield_check)++;
thread_array = k_calloc(max_num_threads, sizeof(osThreadId_t));
num_threads = osThreadEnumerate(thread_array, max_num_threads);
@ -103,15 +111,23 @@ static void thread2(void *argument)
osThreadYield();
}
void test_thread_apis(void)
static void thread_apis_common(int *yield_check,
const char *thread1_name,
osThreadAttr_t *thread1_attr,
osThreadAttr_t *thread2_attr)
{
osThreadId_t id1;
osThreadId_t id2;
id1 = osThreadNew(thread1, NULL, &thread1_attr);
struct thread1_args args = {
.yield_check = yield_check,
.name = thread1_name
};
id1 = osThreadNew(thread1, &args, thread1_attr);
zassert_true(id1 != NULL, "Failed creating thread1");
id2 = osThreadNew(thread2, NULL, &thread2_attr);
id2 = osThreadNew(thread2, yield_check, thread2_attr);
zassert_true(id2 != NULL, "Failed creating thread2");
zassert_equal(osThreadGetCount(), 2,
@ -119,13 +135,26 @@ void test_thread_apis(void)
do {
osDelay(100);
} while (thread_yield_check != 2);
} while (*yield_check != 2);
}
void test_thread_apis_dynamic(void)
{
thread_apis_common(&thread_yield_check_dynamic, "ZephyrThread",
NULL, NULL);
}
void test_thread_apis(void)
{
thread_apis_common(&thread_yield_check, thread1_attr.name,
&thread1_attr, &thread2_attr);
}
static osPriority_t OsPriorityInvalid = 60;
/* This is used to indicate the completion of processing for thread3 */
static int thread3_state;
static int thread3_state_dynamic;
static K_THREAD_STACK_DEFINE(test_stack3, STACKSZ);
static osThreadAttr_t thread3_attr = {
@ -141,6 +170,7 @@ static void thread3(void *argument)
osPriority_t rv;
osThreadId_t id = osThreadGetId();
osPriority_t prio = osThreadGetPriority(id);
int *state = (int *)argument;
/* Lower the priority of the current thread */
osThreadSetPriority(id, osPriorityBelowNormal);
@ -169,7 +199,7 @@ static void thread3(void *argument)
"Something's wrong with osThreadSetPriority!");
/* Indication that thread3 is done with its processing */
thread3_state = 1;
*state = 1;
/* Keep looping till it gets killed */
do {
@ -177,12 +207,12 @@ static void thread3(void *argument)
} while (1);
}
void test_thread_prio(void)
static void thread_prior_common(int *state, osThreadAttr_t *attr)
{
osStatus_t status;
osThreadId_t id3;
id3 = osThreadNew(thread3, NULL, &thread3_attr);
id3 = osThreadNew(thread3, state, attr);
zassert_true(id3 != NULL, "Failed creating thread3");
/* Keep delaying 10 milliseconds to ensure thread3 is done with
@ -190,7 +220,7 @@ void test_thread_prio(void)
*/
do {
osDelay(10);
} while (thread3_state == 0);
} while (*state == 0);
status = osThreadTerminate(id3);
zassert_true(status == osOK, "Error terminating thread3");
@ -205,5 +235,15 @@ void test_thread_prio(void)
zassert_true(status == osErrorResource,
"Something's wrong with osThreadTerminate!");
thread3_state = 0;
*state = 0;
}
void test_thread_prio_dynamic(void)
{
thread_prior_common(&thread3_state_dynamic, NULL);
}
void test_thread_prio(void)
{
thread_prior_common(&thread3_state, &thread3_attr);
}