1 /* 2 * Common functions and helpers for L2CAP tests 3 * 4 * Copyright (c) 2023 Nordic Semiconductor ASA 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #include <stddef.h> 10 11 #include <zephyr/types.h> 12 #include <zephyr/sys/util.h> 13 #include <zephyr/sys/byteorder.h> 14 15 #include <zephyr/bluetooth/bluetooth.h> 16 #include <zephyr/bluetooth/hci.h> 17 #include <zephyr/bluetooth/l2cap.h> 18 #include "bs_types.h" 19 #include "bs_tracing.h" 20 #include "bstests.h" 21 #include "bs_pc_backchannel.h" 22 23 extern enum bst_result_t bst_result; 24 25 #define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false 26 #define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) 27 #define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) 28 #define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) 29 #define WAIT_FOR_FLAG_SET(flag) \ 30 while (!(bool)atomic_get(&flag)) { \ 31 (void)k_sleep(K_MSEC(1)); \ 32 } 33 #define WAIT_FOR_FLAG_UNSET(flag) \ 34 while ((bool)atomic_get(&flag)) { \ 35 (void)k_sleep(K_MSEC(1)); \ 36 } 37 38 39 #define WAIT_SECONDS 30 /* seconds */ 40 #define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ 41 42 #define FAIL(...) \ 43 do { \ 44 bst_result = Failed; \ 45 bs_trace_error_time_line(__VA_ARGS__); \ 46 } while (0) 47 48 #define PASS(...) \ 49 do { \ 50 bst_result = Passed; \ 51 bs_trace_info_time(1, __VA_ARGS__); \ 52 } while (0) 53 54 #define ASSERT(expr, ...) if (!(expr)) {FAIL(__VA_ARGS__); } 55 56 void test_init(void); 57 void test_tick(bs_time_t HW_device_time); 58