1#!/bin/sh
2
3set -e
4
5# Absolute
6SOFTOP=$(cd "$(dirname "$0")"/.. && pwd)
7
8# Relative
9BUILDTOP=build_ut_defs
10
11rebuild_config()
12{
13    local conf="$1"
14    mkdir -p "$BUILDTOP"
15    printf '\n    =========  Building native cmocka tests for %s ======\n\n' "$conf"
16
17    ( set -x
18     cmake  -DINIT_CONFIG="$conf" -S "$SOFTOP" -B "$BUILDTOP"/"$conf" \
19            -DBUILD_UNIT_TESTS=ON           \
20            -DBUILD_UNIT_TESTS_HOST=ON
21
22     cmake --build "$BUILDTOP"/"$conf" -- -j"$(nproc)"
23    )
24}
25
26main()
27{
28    local defconfig
29
30    # First make sure all configurations build
31    for d in "$SOFTOP"/src/arch/xtensa/configs/*_defconfig; do
32        defconfig=$(basename "$d")
33        rebuild_config "$defconfig"
34    done
35
36    # Now run all the tests
37    for d in "$BUILDTOP"/*_defconfig; do
38        printf '\n\n    =========  Running native cmocka tests in %s ======\n\n' "$d"
39        ( set -x
40         cmake --build "$d" -- test
41        )
42    done
43}
44
45main "$@"
46