Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 1 | /* |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017 - 2018, Arm Limited. All rights reserved. |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdint.h> |
| 10 | #include <string.h> |
| 11 | #include <stdbool.h> |
| 12 | |
| 13 | #include "cmsis.h" |
| 14 | #include "tfm_api.h" |
| 15 | #include "cmsis_os2.h" |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame^] | 16 | #include "tfm_nspm_api.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 17 | |
| 18 | #include "tfm_integ_test.h" |
Tamas Ban | c2074a7 | 2018-08-14 10:23:12 +0100 | [diff] [blame] | 19 | #include "test/framework/test_framework_integ_test.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 20 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 21 | #ifdef TEST_FRAMEWORK_S |
| 22 | #include \ |
| 23 | "test/test_services/tfm_secure_client_service/tfm_secure_client_service_api.h" |
| 24 | #endif |
| 25 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 26 | #ifdef CORE_TEST_INTERACTIVE |
| 27 | #include "test/test_services/tfm_core_test/core_test_defs.h" |
| 28 | #include "test/test_services/tfm_core_test/tfm_ss_core_test_veneers.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 29 | |
| 30 | #define TRY_SFN(fn, ...) \ |
| 31 | do { \ |
| 32 | enum tfm_status_e res = (enum tfm_status_e) fn(__VA_ARGS__); \ |
| 33 | switch(res) { \ |
| 34 | case TFM_SUCCESS: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 35 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") successful!");\ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 36 | break; \ |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 37 | case TFM_PARTITION_PENDED: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 38 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") pended!"); \ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 39 | break; \ |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 40 | case TFM_ERROR_PARTITION_ALREADY_PENDED: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 41 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \ |
| 42 | "already pended!");\ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 43 | break; \ |
| 44 | case TFM_ERROR_SECURE_DOMAIN_LOCKED: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 45 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \ |
| 46 | "S domain locked!");\ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 47 | break; \ |
| 48 | case TFM_ERROR_NS_THREAD_MODE_CALL: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 49 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \ |
| 50 | "NS thread mode!");\ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 51 | break; \ |
| 52 | default: \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 53 | LOG_MSG("Secure call to " #fn "(" #__VA_ARGS__") failed, " \ |
| 54 | "generic!");\ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 55 | } \ |
| 56 | } while(0) |
| 57 | /** |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 58 | * \brief secure_decrement_ns_lock_1 |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 59 | * |
| 60 | */ |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 61 | void secure_decrement_ns_lock_1(void) |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 62 | { |
| 63 | TRY_SFN(tfm_core_test_sfn, CORE_TEST_ID_BLOCK, 0x1, 0x1, 0x1); |
| 64 | } |
| 65 | |
| 66 | /** |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 67 | * \brief secure_decrement_ns_lock_2 |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 68 | * |
| 69 | */ |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 70 | void secure_decrement_ns_lock_2(void) |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 71 | { |
| 72 | TRY_SFN(tfm_core_test_sfn, CORE_TEST_ID_BLOCK, 0x2, 0x2, 0x2); |
| 73 | } |
| 74 | /** |
| 75 | * \brief Test definition for the RTX - TFM integration tests |
| 76 | * scenarios |
| 77 | */ |
| 78 | enum test_type { |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 79 | TEST_TYPE_1 = 1, /*!< Sequential test: single task using the NS lock to |
| 80 | access TFM */ |
| 81 | TEST_TYPE_2, /*!< Priority test: high priority tries to preempt TFM, |
| 82 | gets delayed */ |
| 83 | TEST_TYPE_3, /*!< Priority inversion: classical scenario with high |
| 84 | priority task waiting on lower priority task |
| 85 | undefinitely if NS lock is configured without priority |
| 86 | inheritance */ |
| 87 | TEST_TYPE_4, /*!< non-NS lock: like sequential, but doesn't use any NS |
| 88 | lock mechanism */ |
| 89 | TEST_TYPE_5, /*!< non-NS lock, core locked: high priority tries to |
| 90 | overcome the NS lock but finds TFM core locked by |
| 91 | lower priority task and fails */ |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 92 | TEST_TYPE_6 /*!< Like TEST_TYPE_2, but the high priority task has now a |
| 93 | timeout to acquire the NS lock. The timeout will |
| 94 | expire only if TFM Core is built with the |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 95 | de-prioritization disabled */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static const osThreadAttr_t tattr_seq = { |
| 99 | .name = "seq_task", |
| 100 | .stack_size = 1024U, |
| 101 | .attr_bits = osThreadJoinable, |
| 102 | .tz_module = 1, |
| 103 | }; |
| 104 | static const osThreadAttr_t tattr_mid = { |
| 105 | .name = "mid_task", |
| 106 | .stack_size = 512U, |
| 107 | .attr_bits = osThreadJoinable, |
| 108 | .tz_module = 0, |
| 109 | .priority = osPriorityAboveNormal |
| 110 | }; |
| 111 | static const osThreadAttr_t tattr_pri = { |
| 112 | .name = "pri_task", |
| 113 | .stack_size = 1024U, |
| 114 | .attr_bits = osThreadJoinable, |
| 115 | .tz_module = 1, |
| 116 | .priority = osPriorityHigh |
| 117 | }; |
| 118 | |
| 119 | /** |
| 120 | * \brief Mutex id, NS lock |
| 121 | */ |
| 122 | static osMutexId_t mutex_id; |
| 123 | |
| 124 | /** |
| 125 | * \brief Mutex properties, NS lock |
| 126 | */ |
| 127 | static const osMutexAttr_t mattr_ns_lock = { |
| 128 | .name = "ns_lock", |
| 129 | //.attr_bits = osMutexPrioInherit |
| 130 | }; |
| 131 | |
| 132 | /** |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 133 | * \brief TFM NS lock options |
| 134 | * |
| 135 | * \details Options used while acquiring the NS lock |
| 136 | */ |
| 137 | struct tfm_ns_lock_options |
| 138 | { |
| 139 | bool use_ns_lock; |
| 140 | uint32_t timeout; |
| 141 | }; |
| 142 | |
| 143 | /** |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 144 | * \brief tfm_service_request |
| 145 | * |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 146 | * \details This function is used to request a TFM service in thread mode. |
| 147 | * Optionally uses the NS lock and specifies a timeout for obtaining |
| 148 | * the NS lock. |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 149 | */ |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 150 | static void tfm_service_request(void(*fn)(void), |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 151 | struct tfm_ns_lock_options *ns_lock_options_p) |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 152 | { |
| 153 | osStatus_t result; |
| 154 | |
| 155 | char buffer[80]; |
| 156 | |
| 157 | #define LOG_MSG_THREAD(MSG_THREAD) \ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 158 | do { \ |
| 159 | sprintf(buffer,"%s [%s]", MSG_THREAD, osThreadGetName(osThreadGetId())); \ |
| 160 | LOG_MSG(buffer); \ |
| 161 | } \ |
| 162 | while(0) |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 163 | |
| 164 | LOG_MSG_THREAD("Trying to acquire the TFM core from NS"); |
| 165 | |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 166 | if (ns_lock_options_p->use_ns_lock) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 167 | result = osMutexAcquire(mutex_id,0); |
| 168 | if (result == osOK) { |
| 169 | LOG_MSG_THREAD("NS Lock: acquired"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 170 | /* Add a delay here just to let the pri_task try to |
| 171 | * acquire the NS lock before seq_task enters secure world |
| 172 | */ |
| 173 | if (!strcmp(osThreadGetName(osThreadGetId()),"seq_task")) { |
| 174 | osDelay(100U); |
| 175 | } |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 176 | fn(); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 177 | LOG_MSG_THREAD("NS Lock: releasing..."); |
| 178 | osMutexRelease(mutex_id); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 179 | } else { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 180 | |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 181 | if (ns_lock_options_p->timeout == osWaitForever) { |
| 182 | LOG_MSG_THREAD("Failed to acquire NS lock, keep waiting"); |
| 183 | } else { |
| 184 | LOG_MSG_THREAD("Failed to acquire NS lock, wait with timeout"); |
| 185 | } |
| 186 | |
| 187 | result = osMutexAcquire(mutex_id,ns_lock_options_p->timeout); |
| 188 | if (result == osOK) { |
| 189 | LOG_MSG_THREAD("NS Lock: acquired"); |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 190 | fn(); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 191 | LOG_MSG_THREAD("NS Lock: releasing..."); |
| 192 | osMutexRelease(mutex_id); |
| 193 | } else if (result == osErrorTimeout) { |
| 194 | LOG_MSG_THREAD("NS Lock: failed to acquire, timeout expired"); |
| 195 | } else { |
| 196 | LOG_MSG_THREAD("NS Lock: unexpected failure trying to acquire"); |
| 197 | } |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 198 | } |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 199 | } else { |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 200 | /* Add a delay here to let the seq_task (which always uses the NS lock) |
| 201 | * enter secure world before the pri_task (which can try to overcome the |
| 202 | * NS lock in test scenario 5) |
| 203 | */ |
| 204 | if (!strcmp(osThreadGetName(osThreadGetId()),"pri_task")) { |
| 205 | osDelay(100U); |
| 206 | } |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 207 | fn(); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * \brief Non-blocking test thread |
| 213 | * |
| 214 | */ |
| 215 | __attribute__((noreturn)) |
| 216 | static void mid_task(void *argument) |
| 217 | { |
| 218 | osThreadId_t thread_id_pri; |
| 219 | osThreadState_t thread_pri_state; |
| 220 | uint32_t idx; |
| 221 | |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame^] | 222 | tfm_nspm_register_client_id(); |
| 223 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 224 | thread_id_pri = *((osThreadId_t *)argument); |
| 225 | |
| 226 | /* go to sleep */ |
| 227 | osDelay(100U); |
| 228 | |
| 229 | thread_pri_state = osThreadGetState(thread_id_pri); |
| 230 | |
| 231 | if (thread_pri_state == osThreadBlocked) { |
| 232 | LOG_MSG("Running [mid_task] while [pri_task] is blocked"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 233 | } else if (thread_pri_state == osThreadTerminated) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 234 | LOG_MSG("Running [mid_task] while [pri_task] is terminated"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 235 | } else { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 236 | LOG_MSG("Running [mid_task]"); |
| 237 | } |
| 238 | |
| 239 | /* Do non TFM related, non blocking, operations */ |
| 240 | for (idx=0; idx<0x3ffffff; idx++) { |
| 241 | } |
| 242 | |
| 243 | LOG_MSG("Exiting [mid_task]"); |
| 244 | |
| 245 | osThreadExit(); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * \brief Priority test thread |
| 250 | * |
| 251 | */ |
| 252 | __attribute__((noreturn)) |
| 253 | static void pri_task(void *argument) |
| 254 | { |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame^] | 255 | tfm_nspm_register_client_id(); |
| 256 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 257 | /* go to sleep */ |
| 258 | osDelay(100U); |
| 259 | |
| 260 | /* After wake up, try to get hold of the NS lock */ |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 261 | tfm_service_request(secure_decrement_ns_lock_2, |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 262 | (struct tfm_ns_lock_options *)argument); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 263 | |
| 264 | osThreadExit(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * \brief Sequential test thread |
| 269 | * |
| 270 | */ |
| 271 | __attribute__((noreturn)) |
| 272 | static void seq_task(void *argument) |
| 273 | { |
| 274 | osThreadId_t thread_id, thread_id_mid; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 275 | enum test_type test_type; |
| 276 | |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 277 | /* By default, use NS lock and wait forever if busy, i.e. until unblocked */ |
| 278 | struct tfm_ns_lock_options ns_lock_opt = |
| 279 | {.use_ns_lock=true, .timeout=osWaitForever}; |
| 280 | struct tfm_ns_lock_options ns_lock_opt_pri = |
| 281 | {.use_ns_lock=true, .timeout=osWaitForever}; |
| 282 | |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame^] | 283 | tfm_nspm_register_client_id(); |
| 284 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 285 | test_type = *((enum test_type *)argument); |
| 286 | |
| 287 | if (test_type == TEST_TYPE_1) { |
| 288 | LOG_MSG("Scenario 1 - Sequential"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 289 | } else if (test_type == TEST_TYPE_2) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 290 | LOG_MSG("Scenario 2 - Priority"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 291 | thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 292 | } else if (test_type == TEST_TYPE_3) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 293 | LOG_MSG("Scenario 3 - Priority inversion"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 294 | thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 295 | thread_id_mid = osThreadNew(mid_task, &thread_id, &tattr_mid); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 296 | } else if (test_type == TEST_TYPE_4) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 297 | LOG_MSG("Scenario 4 - non-NS lock"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 298 | ns_lock_opt.use_ns_lock = false; |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 299 | } else if (test_type == TEST_TYPE_5) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 300 | LOG_MSG("Scenario 5 - non-NS lock, core locked"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 301 | ns_lock_opt_pri.use_ns_lock = false; |
| 302 | thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri); |
| 303 | } else if (test_type == TEST_TYPE_6) { |
| 304 | LOG_MSG("Scenario 6 - Core prioritization effects on NS world"); |
| 305 | ns_lock_opt_pri.timeout = 0x10000; /* timed_wait for NS lock */ |
| 306 | thread_id = osThreadNew(pri_task, &ns_lock_opt_pri, &tattr_pri); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 307 | } else { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 308 | LOG_MSG("Scenario not supported"); |
| 309 | osThreadExit(); |
| 310 | } |
| 311 | |
| 312 | /* Try to acquire the NS lock */ |
Mate Toth-Pal | 1379e15 | 2018-07-30 17:38:29 +0200 | [diff] [blame] | 313 | tfm_service_request(secure_decrement_ns_lock_1, &ns_lock_opt); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 314 | |
| 315 | if (test_type == TEST_TYPE_1) { |
| 316 | LOG_MSG("Scenario 1 - test finished\n"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 317 | } else if (test_type == TEST_TYPE_2) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 318 | osThreadJoin(thread_id); |
| 319 | LOG_MSG("Scenario 2 - test finished\n"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 320 | } else if (test_type == TEST_TYPE_3) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 321 | osThreadJoin(thread_id); |
| 322 | osThreadJoin(thread_id_mid); |
| 323 | LOG_MSG("Scenario 3 - test finished\n"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 324 | } else if (test_type == TEST_TYPE_4) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 325 | LOG_MSG("Scenario 4 - test finished\n"); |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 326 | } else if (test_type == TEST_TYPE_5) { |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 327 | osThreadJoin(thread_id); |
| 328 | LOG_MSG("Scenario 5 - test finished\n"); |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 329 | } else if (test_type == TEST_TYPE_6) { |
| 330 | osThreadJoin(thread_id); |
| 331 | LOG_MSG("Scenario 6 - test finished\n"); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | osThreadExit(); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * \brief Execute the interactive tets cases |
| 339 | * |
| 340 | */ |
| 341 | void execute_ns_interactive_tests(void) |
| 342 | { |
| 343 | uint8_t idx; |
| 344 | |
| 345 | osThreadId_t thread_id; |
| 346 | |
| 347 | /* Test type list */ |
Antonio de Angelis | 04bf659 | 2018-02-26 11:57:36 +0000 | [diff] [blame] | 348 | enum test_type test_type[] = {TEST_TYPE_1, TEST_TYPE_2, TEST_TYPE_3, |
Antonio de Angelis | 1ea2a13 | 2017-12-06 14:36:05 +0000 | [diff] [blame] | 349 | TEST_TYPE_4, TEST_TYPE_5, TEST_TYPE_6}; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 350 | |
| 351 | /* Create the NS lock -- shared among testing scenarios */ |
| 352 | mutex_id = osMutexNew(&mattr_ns_lock); |
| 353 | |
| 354 | /* Loop in the test list */ |
| 355 | for (idx=0; idx<sizeof(test_type); idx++) { |
| 356 | /* Spawn the main thread */ |
| 357 | thread_id = osThreadNew(seq_task, &test_type[idx], &tattr_seq); |
| 358 | |
| 359 | /* Wait for it to finish before moving to the next scenario */ |
| 360 | osThreadJoin(thread_id); |
| 361 | } |
| 362 | } |
| 363 | #endif /* CORE_TEST_INTERACTIVE */ |
| 364 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 365 | #if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S) |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 366 | /** |
| 367 | * \brief Services test thread |
| 368 | * |
| 369 | */ |
| 370 | __attribute__((noreturn)) |
| 371 | void test_app(void *argument) |
| 372 | { |
| 373 | UNUSED_VARIABLE(argument); |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 374 | |
| 375 | #ifdef TEST_FRAMEWORK_S |
| 376 | /* FIXME: The non-secure audit log test currently relies on the fact that |
| 377 | * the audit log secure test is run first. However the Non-secure tests |
| 378 | * represent simpler and more common test cases which would make more sense |
| 379 | * to be run first. Therefore if this dependency is removed the execution |
| 380 | * order of these test classes should be reversed. */ |
| 381 | tfm_secure_client_run_tests(); |
| 382 | #endif |
| 383 | #ifdef TEST_FRAMEWORK_NS |
| 384 | tfm_non_secure_client_run_tests(); |
| 385 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 386 | /* End of test */ |
| 387 | for (;;) { |
| 388 | } |
| 389 | } |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 390 | #endif /* TEST_FRAMEWORK_NS OR TEST_FRAMEWORK_S */ |