1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "bs_tracing.h" 8 #include "bs_types.h" 9 #include "bstests.h" 10 11 #define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC) 12 13 extern enum bst_result_t bst_result; 14 15 #define DECLARE_FLAG(flag) extern atomic_t flag 16 #define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false 17 #define TEST_FLAG(flag) (bool)atomic_get(&flag) 18 #define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) 19 #define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) 20 21 #define WAIT_FOR_VAL(var, val) \ 22 while (atomic_get(&var) != val) { \ 23 (void)k_sleep(K_MSEC(1)); \ 24 } 25 #define WAIT_FOR_FLAG(flag) \ 26 while (!(bool)atomic_get(&flag)) { \ 27 (void)k_sleep(K_MSEC(1)); \ 28 } 29 #define WAIT_FOR_FLAG_UNSET(flag) \ 30 while ((bool)atomic_get(&flag)) { \ 31 (void)k_sleep(K_MSEC(1)); \ 32 } 33 #define TAKE_FLAG(flag) \ 34 while (!(bool)atomic_cas(&flag, true, false)) { \ 35 (void)k_sleep(K_MSEC(1)); \ 36 } 37 38 #define ASSERT(expr, ...) \ 39 do { \ 40 if (!(expr)) { \ 41 FAIL(__VA_ARGS__); \ 42 } \ 43 } while (0) 44 45 #define FAIL(...) \ 46 do { \ 47 bst_result = Failed; \ 48 bs_trace_error_time_line(__VA_ARGS__); \ 49 } while (0) 50 51 #define PASS(...) \ 52 do { \ 53 bst_result = Passed; \ 54 bs_trace_info_time(1, __VA_ARGS__); \ 55 } while (0) 56 57 #define TEST_TIMEOUT_SIMULATED BS_SECONDS(100) 58 #define HVX_HANDLE 0x0012 59 #define DUT_DEVICE_NBR 0 60 61 /* Run for more than ATT_TIMEOUT */ 62 #define PROCEDURE_1_TIMEOUT_MS (1000 * 70) 63