From ca9137d5a85595b0ee77ecbfabc4a686fc816bc8 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sun, 25 Jul 2021 04:45:56 +0000 Subject: [PATCH 1/7] common_mocks.c: fix !CONFIG_TRACE build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes 'no previous prototype for trace_log_filtered' -Werr and redefinition of ‘trace_flush_dma_to_mbox’ error. Signed-off-by: Marc Herbert --- test/cmocka/src/common_mocks.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index 59ed9fce496c..e362f4b953bd 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -100,6 +100,7 @@ void WEAK __panic(uint32_t p, char *filename, uint32_t linenum) exit(EXIT_FAILURE); } +#if CONFIG_TRACE void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const struct tr_ctx *ctx, uint32_t lvl, uint32_t id_1, uint32_t id_2, int arg_count, ...) { @@ -115,6 +116,7 @@ void WEAK trace_log_filtered(bool send_atomic, const void *log_entry, const stru void WEAK trace_flush_dma_to_mbox(void) { } +#endif #if CONFIG_LIBRARY volatile void *task_context_get(void); @@ -330,6 +332,8 @@ int WEAK arch_cpu_is_core_enabled(int id) int WEAK test_bench_trace = 1; int WEAK debug; +/* ... but not always in unit tests */ +#if CONFIG_TRACE /* look up subsystem class name from table */ char * WEAK get_trace_class(uint32_t trace_class) { @@ -339,6 +343,7 @@ char * WEAK get_trace_class(uint32_t trace_class) */ return "unknown"; } +#endif uint8_t * WEAK get_library_mailbox(void) { From f0b2b0e6fddfa51144e931dc24ce9cd1110f8d06 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Wed, 30 Jun 2021 06:41:30 +0000 Subject: [PATCH 2/7] suecreek_gcc_defconfig: CONFIG_TRACE=n This has been finding several pre-processing bugs already. Short of randconfig some variety is the best we have. Signed-off-by: Marc Herbert --- src/arch/xtensa/configs/suecreek_gcc_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arch/xtensa/configs/suecreek_gcc_defconfig b/src/arch/xtensa/configs/suecreek_gcc_defconfig index ede3ac642b8b..3e223d2c02ea 100644 --- a/src/arch/xtensa/configs/suecreek_gcc_defconfig +++ b/src/arch/xtensa/configs/suecreek_gcc_defconfig @@ -3,3 +3,4 @@ CONFIG_INTEL_DMIC=y CONFIG_INTEL_SSP=y CONFIG_LP_MEMORY_BANKS=1 CONFIG_HP_MEMORY_BANKS=47 +CONFIG_TRACE=n From 3f3696d028aa48a1224bbf0b775b85eb05d6fd37 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 23 Jul 2021 19:04:58 +0000 Subject: [PATCH 3/7] xtensa-build-all.sh: link to cmake docs on sof-docs Link to the CMake section in sof-docs which documents a lot of what this script does and is probably out of date now. It would be less out of date if this link had been there and more people had been aware that this documentation even existed. Signed-off-by: Marc Herbert --- scripts/xtensa-build-all.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/xtensa-build-all.sh b/scripts/xtensa-build-all.sh index 9716033371c4..21cb24231b7b 100755 --- a/scripts/xtensa-build-all.sh +++ b/scripts/xtensa-build-all.sh @@ -43,8 +43,10 @@ die() print_usage() { cat <_defconfig file. +Re-configures and re-builds SOF using the corresponding compiler and the +_defconfig file. Implements and saves the manual configuration +described in +https://thesofproject.github.io/latest/developer_guides/firmware/cmake.html usage: $0 [options] platform(s) From e80e361aea023a1871e446631dd8c7e5054b38b7 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sat, 24 Jul 2021 01:18:11 +0000 Subject: [PATCH 4/7] cmocka/cmake: add $SIMULATOR to fix "make test" on host Before this it was required to find and run the executables one by one Signed-off-by: Marc Herbert --- test/cmocka/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/cmocka/CMakeLists.txt b/test/cmocka/CMakeLists.txt index 1116128ac7c6..8eb8afe7595e 100644 --- a/test/cmocka/CMakeLists.txt +++ b/test/cmocka/CMakeLists.txt @@ -8,14 +8,19 @@ add_library(cmocka STATIC IMPORTED) if(BUILD_UNIT_TESTS_HOST) set(UT_CC_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cmocka-host-gcc-toolchain.cmake) set(UT_TOOLCHAIN "") + # TODO: add an option to support valgrind. + # In the mean time use scripts/run-mocks.sh for valgrind. + set(SIMULATOR "") elseif(BUILD_UNIT_TESTS_XTENSA_GCC) # GCC xtensa build for future Qemu. set(UT_CC_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cmocka-xtensa-gcc-toolchain.cmake) set(UT_TOOLCHAIN "-DTOOLCHAIN=${TOOLCHAIN}") + set(SIMULATOR xt-run --exit_with_target_code) else() # xtensa XCC build for xt-run. set(UT_CC_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cmocka-xtensa-xt-toolchain.cmake) set(UT_TOOLCHAIN "") + set(SIMULATOR xt-run --exit_with_target_code) endif() if(DEFINED CMOCKA_DIRECTORY) @@ -102,7 +107,7 @@ function(cmocka_test test_name) # Cmocka requires this define for stdint.h that defines uintptr target_compile_definitions(${test_name} PRIVATE -D_UINTPTR_T_DEFINED) - add_test(NAME ${test_name} COMMAND xt-run --exit_with_target_code ${test_name}) + add_test(NAME ${test_name} COMMAND ${SIMULATOR} ${test_name}) sof_append_relative_path_definitions(${test_name}) endfunction() From c1b9b4d0fdd71b3b24584e9a4f8355e137bc5696 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sat, 24 Jul 2021 19:51:42 +0000 Subject: [PATCH 5/7] scripts/run-mocks.sh: major refactor Adds --error-exitcode=1 to valgrind options (otherwise what's the point of using valgrind?) Skip alloc test that does not pass on HOST (passes with xt-run) Add help message. Runnable from anywhere. Use shell functions https://github.com/thesofproject/sof-test/issues/740 Fix all quoting issues and other shellcheck warnings. Add comments. Signed-off-by: Marc Herbert --- scripts/run-mocks.sh | 97 ++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/scripts/run-mocks.sh b/scripts/run-mocks.sh index be10de7aed1e..61cb9a7d32f3 100755 --- a/scripts/run-mocks.sh +++ b/scripts/run-mocks.sh @@ -2,40 +2,83 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2021 Intel Corporation. All rights reserved. -# fail on any errors + +# Stop on most errors set -e -# default config of none supplied -CONFIG="tgph_defconfig" -VALGRIND_CMD="" +SOFTOP=$(cd "$(dirname "$0")"/.. && pwd) + +usage() +{ + cat < Date: Sat, 24 Jul 2021 21:41:55 +0000 Subject: [PATCH 6/7] unit tests: skip 'alloc' test when compiled on host It is failing and skipped only when compiled on the host, runs fine with xt-run. This is temporarily needed to add host-based unit tests to CI now and catch any regression in any other test now. Signed-off-by: Marc Herbert --- test/cmocka/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/cmocka/CMakeLists.txt b/test/cmocka/CMakeLists.txt index 8eb8afe7595e..509d8a046df5 100644 --- a/test/cmocka/CMakeLists.txt +++ b/test/cmocka/CMakeLists.txt @@ -107,7 +107,13 @@ function(cmocka_test test_name) # Cmocka requires this define for stdint.h that defines uintptr target_compile_definitions(${test_name} PRIVATE -D_UINTPTR_T_DEFINED) - add_test(NAME ${test_name} COMMAND ${SIMULATOR} ${test_name}) + # Skip running alloc test on HOST until it's fixed (it passes and is run + # with xt-run) + if( "alloc" STREQUAL "${test_name}" AND BUILD_UNIT_TESTS_HOST) + message(WARNING "SKIP alloc test on HOST, built but not run") + else() + add_test(NAME ${test_name} COMMAND ${SIMULATOR} ${test_name}) + endif() sof_append_relative_path_definitions(${test_name}) endfunction() From 0cbac3ae3b04ee571f12bf1798d949b829be390a Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sun, 25 Jul 2021 00:51:38 +0000 Subject: [PATCH 7/7] .github: run unit tests with -DBUILD_UNIT_TESTS_HOST=ON Because we can. Signed-off-by: Marc Herbert --- .github/workflows/unit-tests.yml | 21 +++++++++++++++++ test/test-all-defconfigs.sh | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/unit-tests.yml create mode 100755 test/test-all-defconfigs.sh diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 000000000000..9bbe004092ea --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,21 @@ +--- + +# https://thesofproject.github.io/latest/developer_guides/unit_tests.html + +name: Unit tests + +# 'workflow_dispatch' allows running this workflow manually from the +# 'Actions' tab + +# yamllint disable-line rule:truthy +on: [pull_request, workflow_dispatch] + +jobs: + cmocka_utests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: {fetch-depth: 2} + + - name: build and run all defconfigs + run: ./test/test-all-defconfigs.sh diff --git a/test/test-all-defconfigs.sh b/test/test-all-defconfigs.sh new file mode 100755 index 000000000000..44ac254bede7 --- /dev/null +++ b/test/test-all-defconfigs.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +set -e + +SOFTOP=$(cd "$(dirname "$0")"/.. && pwd) + +BUILDTOP=build_ut_defs + +rebuild_config() +{ + local conf="$1" + mkdir -p "$BUILDTOP" + ( set -x + cmake -DINIT_CONFIG="$conf" -B "$BUILDTOP"/"$conf" -DBUILD_UNIT_TESTS=ON \ + -DBUILD_UNIT_TESTS_HOST=ON + + cmake --build "$BUILDTOP"/"$conf" -- -j"$(nproc)" + ) +} + +main() +{ + local defconfig + + # First make sure all configurations build + for d in "$SOFTOP"/src/arch/xtensa/configs/*_defconfig; do + defconfig=$(basename "$d") + rebuild_config "$defconfig" + done + + # Now run all the tests + for d in "$BUILDTOP"/*_defconfig; do + ( set -x + cmake --build "$d" -- test + ) + done +} + +main "$@"