10 #include "cmsis_os2.h"
24 #ifdef TEST_FRAMEWORK_S
26 "tfm_secure_client_service_api.h"
29 #define TRY_SFN(fn, ...) \
31 enum tfm_status_e res = (enum tfm_status_e) fn(__VA_ARGS__); \
34 TEST_LOG("Secure call to " #fn "(" #__VA_ARGS__") successful!");\
36 case TFM_ERROR_SECURE_DOMAIN_LOCKED: \
37 TEST_LOG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \
41 TEST_LOG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \
50 static struct test_t core_tests[] = {
51 {&tfm_core_test_2001,
"TFM_CORE_TEST_2001",
59 list_size = (
sizeof(core_tests) /
sizeof(core_tests[0]));
61 set_testsuite(
"Core non-secure interactive tests (TFM_CORE_TEST_2XXX)",
62 core_tests, list_size, p_test_suite);
65 static void execute_ns_interactive_tests(
void);
72 execute_ns_interactive_tests();
78 static psa_status_t psa_test_common(uint32_t sid, uint32_t version,
108 psa_invec in_vec = {&testcase_id,
sizeof(testcase_id)};
110 TRY_SFN(tfm_spm_core_test_sfn_veneer, &in_vec, 1, NULL, 0);
118 TEST_LOG(
"Secure call to sfn block failed, generic!");
131 psa_invec in_vec = {&testcase_id,
sizeof(testcase_id)};
133 TRY_SFN(tfm_spm_core_test_sfn_veneer, &in_vec, 1, NULL, 0);
141 TEST_LOG(
"Secure call to sfn block failed, generic!");
169 static const osThreadAttr_t tattr_seq = {
172 .attr_bits = osThreadJoinable,
175 static const osThreadAttr_t tattr_mid = {
178 .attr_bits = osThreadJoinable,
180 .priority = osPriorityAboveNormal
182 static const osThreadAttr_t tattr_pri = {
185 .attr_bits = osThreadJoinable,
187 .priority = osPriorityHigh
193 static osMutexId_t mutex_id;
198 static const osMutexAttr_t mattr_ns_lock = {
221 static void tfm_service_request(
void(*fn)(
void),
228 #define LOG_MSG_THREAD(MSG_THREAD) \
230 sprintf(buffer,"%s [%s]", MSG_THREAD, osThreadGetName(osThreadGetId())); \
238 result = osMutexAcquire(mutex_id,0);
239 if (result == osOK) {
244 if (!strcmp(osThreadGetName(osThreadGetId()),
"seq_task")) {
249 osMutexRelease(mutex_id);
252 if (ns_lock_options_p->
timeout == osWaitForever) {
258 result = osMutexAcquire(mutex_id,ns_lock_options_p->
timeout);
259 if (result == osOK) {
263 osMutexRelease(mutex_id);
264 }
else if (result == osErrorTimeout) {
275 if (!strcmp(osThreadGetName(osThreadGetId()),
"pri_task")) {
286 __attribute__((noreturn))
287 static
void mid_task(
void *argument)
289 osThreadId_t thread_id_pri;
290 osThreadState_t thread_pri_state;
293 #ifdef TFM_NS_CLIENT_IDENTIFICATION
297 thread_id_pri = *((osThreadId_t *)argument);
302 thread_pri_state = osThreadGetState(thread_id_pri);
304 if (thread_pri_state == osThreadBlocked) {
305 TEST_LOG(
"Running [mid_task] while [pri_task] is blocked");
306 }
else if (thread_pri_state == osThreadTerminated) {
307 TEST_LOG(
"Running [mid_task] while [pri_task] is terminated");
313 for (idx=0; idx<0x3ffffff; idx++) {
325 __attribute__((noreturn))
326 static
void pri_task(
void *argument)
328 #ifdef TFM_NS_CLIENT_IDENTIFICATION
346 __attribute__((noreturn))
347 static
void seq_task(
void *argument)
349 osThreadId_t thread_id, thread_id_mid;
358 #ifdef TFM_NS_CLIENT_IDENTIFICATION
362 test_type = *((
enum test_type *)argument);
365 TEST_LOG(
"Scenario 1 - Sequential");
368 thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri);
370 TEST_LOG(
"Scenario 3 - Priority inversion");
371 thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri);
372 thread_id_mid = osThreadNew(mid_task, &thread_id, &tattr_mid);
374 TEST_LOG(
"Scenario 4 - non-NS lock");
377 TEST_LOG(
"Scenario 5 - non-NS lock, core locked");
379 thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri);
381 TEST_LOG(
"Scenario 6 - Core prioritization effects on NS world");
382 ns_lock_opt_pri.
timeout = 0x10000;
383 thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri);
393 TEST_LOG(
"Scenario 1 - test finished\n");
395 osThreadJoin(thread_id);
396 TEST_LOG(
"Scenario 2 - test finished\n");
398 osThreadJoin(thread_id);
399 osThreadJoin(thread_id_mid);
400 TEST_LOG(
"Scenario 3 - test finished\n");
402 TEST_LOG(
"Scenario 4 - test finished\n");
404 osThreadJoin(thread_id);
405 TEST_LOG(
"Scenario 5 - test finished\n");
407 osThreadJoin(thread_id);
408 TEST_LOG(
"Scenario 6 - test finished\n");
418 static void execute_ns_interactive_tests(
void)
422 osThreadId_t thread_id;
429 mutex_id = osMutexNew(&mattr_ns_lock);
432 for (idx=0; idx<
sizeof(
test_type); idx++) {
434 thread_id = osThreadNew(seq_task, &test_type[idx], &tattr_seq);
437 osThreadJoin(thread_id);
uint32_t tfm_nspm_register_client_id(void)
Reports the client ID of this task to TF-M.
#define SPM_CORE_TEST_BLOCK_SID
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
#define CORE_TEST_ID_BLOCK
void psa_close(psa_handle_t handle)
Close a connection to an RoT Service.
psa_handle_t psa_connect(uint32_t sid, uint32_t version)
Connect to an RoT Service by its SID.
test_type
Test definition for the RTX - TFM integration tests scenarios.
#define SPM_CORE_TEST_BLOCK_VERSION
void secure_decrement_ns_lock_1(void)
secure_decrement_ns_lock_1
void register_testsuite_ns_core_interactive(struct test_suite_t *p_test_suite)
Register testsuite for the core interactive tests.
void secure_decrement_ns_lock_2(void)
secure_decrement_ns_lock_2
int32_t psa_status_t
Function return status.
psa_status_t psa_call(psa_handle_t handle, int32_t type, const psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len)
Call an RoT Service on an established connection.
#define LOG_MSG_THREAD(MSG_THREAD)