Skip to content

Commit 615409b

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: Audio: Remove dependency on host mocks
Removes the dependency on the host mocks for LE Audio tests. This is done by copying the missing mocks for assert into the audio mocks, and then always including ztest.h. The inclusion of ztest.h is due to the fact that arch/cpu.h does not have an appropriate header file for ztest, and some header files depend on ARCH_STACK_PTR_ALIGN which is usually defined by those headers in cpu.h. However ztest.h does define this value as well, and thus needs to be included always. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 55e8966 commit 615409b

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

tests/bluetooth/audio/mocks/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#
1010

1111
add_library(mocks STATIC
12+
src/assert.c
1213
src/bap_stream.c
1314
src/conn.c
1415
src/crypto.c
@@ -39,8 +40,7 @@ target_sources(testbinary PRIVATE
3940
${ZEPHYR_BASE}/include/zephyr/kernel.h
4041
)
4142

42-
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks)
43-
44-
target_link_libraries(mocks PRIVATE test_interface host_mocks)
43+
target_link_libraries(mocks PRIVATE test_interface)
44+
target_compile_options(test_interface INTERFACE -include ztest.h)
4545
target_link_options(mocks PUBLIC
4646
"SHELL:-T ${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/mock-sections.ld")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/fff.h>
8+
#include <zephyr/kernel.h>
9+
10+
/* List of fakes used by this unit tester */
11+
#define ASSERT_FFF_FAKES_LIST(FAKE) \
12+
FAKE(mock_check_if_assert_expected) \
13+
14+
DECLARE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected);
15+
16+
#define expect_assert() (mock_check_if_assert_expected_fake.return_val = 1)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include "assert.h"
9+
10+
DEFINE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected);
11+
12+
void assert_print(const char *fmt, ...)
13+
{
14+
va_list ap;
15+
16+
va_start(ap, fmt);
17+
vprintk(fmt, ap);
18+
va_end(ap);
19+
}
20+
21+
void assert_post_action(const char *file, unsigned int line)
22+
{
23+
/* ztest_test_pass()/ztest_test_fail() are used to stop the execution
24+
* If this is an unexpected assert (i.e. not following expect_assert())
25+
* calling mock_check_if_assert_expected() will return 'false' as
26+
* a default return value
27+
*/
28+
if (mock_check_if_assert_expected() == true) {
29+
printk("Assertion expected as part of a test case.\n");
30+
/* Mark the test as passed and stop execution:
31+
* Needed in the passing scenario to prevent undefined behavior after hitting the
32+
* assert. In real builds (non-UT), the system will be halted by the assert.
33+
*/
34+
ztest_test_pass();
35+
} else {
36+
/* Mark the test as failed and stop execution */
37+
ztest_test_fail();
38+
}
39+
}

0 commit comments

Comments
 (0)