Skip to content

Commit 182c351

Browse files
committed
tests: ztest: execute unit tests on native_sim boot
Currently, native_sim standalone boot tests were skipped because the main application overrode test_main() without invoking the test suite runner for non-QEMU targets. Also, the math arithmetic unit tests were not compiled into the main image structure natively, reducing test coverage for native execution. This patch: - Injects standalone basic arithmetic math unit tests into the zephyr test library when building in standalone boot test mode. - Modifies CMake definitions and math configuration macros to ensure the underlying vector algorithms are compiled globally when Ztest is enabled. - Updates the main test loop invocation to explicitly execute Ztests on all boards including native_sim. - Enables standalone boot tests in the native_sim Kconfig. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent f3f8bf0 commit 182c351

6 files changed

Lines changed: 34 additions & 6 deletions

File tree

app/boards/native_sim.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ CONFIG_ZEPHYR_POSIX=y
22
CONFIG_SYS_HEAP_BIG_ONLY=y
33
CONFIG_ZEPHYR_NATIVE_DRIVERS=y
44
CONFIG_ZEPHYR_LOG=y
5+
CONFIG_ZTEST=y
6+
CONFIG_SOF_BOOT_TEST_STANDALONE=y

app/src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ static inline void qemu_xtensa_exit(int status)
7777
void test_main(void)
7878
{
7979
sof_app_main();
80-
#if CONFIG_SOF_BOOT_TEST && defined(QEMU_BOOT_TESTS)
80+
#if CONFIG_SOF_BOOT_TEST
8181
sof_run_boot_tests();
82+
#if defined(QEMU_BOOT_TESTS)
8283
qemu_xtensa_exit(0);
8384
#endif
85+
#endif
8486
}
8587
#else
8688
int main(void)

src/math/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ if(zephyr) ### Zephyr ###
106106
${base_files}
107107
)
108108

109+
if(CONFIG_ZTEST)
110+
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/numbers.c
111+
PROPERTIES COMPILE_DEFINITIONS "CONFIG_NUMBERS_VECTOR_FIND=1;CONFIG_NUMBERS_NORM=1"
112+
)
113+
endif()
114+
109115
else() ### library, e.g. testbench or plugin ###
110116

111117
add_local_sources(sof ${base_files})

src/math/numbers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int gcd(int a, int b)
7979
EXPORT_SYMBOL(gcd);
8080
#endif /* USE_SOF_GCD */
8181

82-
#if CONFIG_NUMBERS_VECTOR_FIND
82+
#if CONFIG_NUMBERS_VECTOR_FIND || CONFIG_ZTEST
8383

8484
/* This function searches from vec[] (of length vec_length) integer values
8585
* of n. The indexes to equal values is returned in idx[]. The function
@@ -133,9 +133,9 @@ int32_t find_max_abs_int32(int32_t vec[], int vec_length)
133133
return SATP_INT32(amax); /* Amax is always a positive value */
134134
}
135135

136-
#endif /* CONFIG_VECTOR_FIND */
136+
#endif /* CONFIG_VECTOR_FIND || CONFIG_ZTEST */
137137

138-
#if CONFIG_NUMBERS_NORM
138+
#if CONFIG_NUMBERS_NORM || CONFIG_ZTEST
139139

140140
/* Count the left shift amount to normalize a 32 bit signed integer value
141141
* without causing overflow. Input value 0 will result to 31.
@@ -155,7 +155,7 @@ int norm_int32(int32_t val)
155155
}
156156
EXPORT_SYMBOL(norm_int32);
157157

158-
#endif /* CONFIG_NORM */
158+
#endif /* CONFIG_NORM || CONFIG_ZTEST */
159159

160160
/**
161161
* Basic CRC-32 implementation, based on pseudo-code from

src/platform/posix/ipc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static void posix_ipc_isr(void *arg)
2424
}
2525

2626
// External symbols set up by the fuzzing layer
27-
extern uint8_t *posix_fuzz_buf, posix_fuzz_sz;
27+
extern const uint8_t *posix_fuzz_buf;
28+
extern size_t posix_fuzz_sz;
2829

2930
// Lots of space. Should really synchronize with the -max_len
3031
// parameter to libFuzzer (defaults to 4096), but that requires

zephyr/test/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,20 @@ endif()
2323
if(CONFIG_SOF_BOOT_TEST_STANDALONE AND CONFIG_SOF_USERSPACE_LL)
2424
zephyr_library_sources(userspace/test_ll_task.c)
2525
endif()
26+
27+
if(CONFIG_SOF_BOOT_TEST_STANDALONE AND CONFIG_ZTEST)
28+
set(MATH_ZTEST_SOURCES
29+
../../test/ztest/unit/math/basic/arithmetic/test_crc32_ztest.c
30+
../../test/ztest/unit/math/basic/arithmetic/test_find_equal_int16_ztest.c
31+
../../test/ztest/unit/math/basic/arithmetic/test_find_max_abs_int32_ztest.c
32+
../../test/ztest/unit/math/basic/arithmetic/test_find_min_int16_ztest.c
33+
../../test/ztest/unit/math/basic/arithmetic/test_gcd_ztest.c
34+
../../test/ztest/unit/math/basic/arithmetic/test_norm_int32_ztest.c
35+
)
36+
37+
zephyr_library_sources(${MATH_ZTEST_SOURCES})
38+
39+
set_source_files_properties(${MATH_ZTEST_SOURCES}
40+
PROPERTIES COMPILE_DEFINITIONS "CONFIG_NUMBERS_VECTOR_FIND=1;CONFIG_NUMBERS_NORM=1;UNIT_TEST=1"
41+
)
42+
endif()

0 commit comments

Comments
 (0)