Skip to content

Commit 75ef136

Browse files
committed
qemu: maths: build the math ztests when CONFIG_ZTEST is enabled
Wire up the math basic-arithmetic ztests under zephyr/test/CMakeLists.txt so they are built whenever CONFIG_SOF_BOOT_TEST_STANDALONE and CONFIG_ZTEST are enabled, and expose the corresponding APIs in src/math (find/norm helpers) when CONFIG_ZTEST is set so the tests link. In the current tree CONFIG_ZTEST is only enabled by the native_sim board configuration, so in practice these tests run on native_sim today, but the gating itself is generic and any board enabling CONFIG_ZTEST will pick them up. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 18c88b7 commit 75ef136

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

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

zephyr/test/CMakeLists.txt

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

0 commit comments

Comments
 (0)