Skip to content

Commit

Permalink
scripts/run-mocks.sh: major refactor
Browse files Browse the repository at this point in the history
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
thesofproject/sof-test#740

Fix all quoting issues and other shellcheck warnings.

Add comments.

Signed-off-by: Marc Herbert <[email protected]>
  • Loading branch information
marc-hb committed Jul 25, 2021
1 parent 49b2631 commit 4256dac
Showing 1 changed file with 70 additions and 27 deletions.
97 changes: 70 additions & 27 deletions scripts/run-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
Usage: [ -v ] [ -c platform_defconfig ]
Re-compiles unit tests with the host toolchain and runs them one by
one, optionally with valgrind. If you don't need valgrind it's faster
and better looking to run "make -j test". See
https://thesofproject.github.io/latest/developer_guides/unit_tests.html
EOF
exit 1
}

parse_opts()
{
# default config if none supplied
CONFIG="tgph_defconfig"
VALGRIND_CMD=""

while getopts "vc:" flag; do
case "${flag}" in
c) CONFIG=${OPTARG}
;;
v) VALGRIND_CMD="valgrind --tool=memcheck --track-origins=yes \
--leak-check=full --show-leak-kinds=all --error-exitcode=1"
;;
?) usage
;;
esac
done

while getopts "vc:" flag; do
case "${flag}" in
c) CONFIG=${OPTARG};;
v) VALGRIND_CMD="valgrind --tool=memcheck --track-origins=yes --leak-check=full --show-leak-kinds=all";;
?) echo "Usage: -v -c defconfig"
exit 1;;
esac
done
shift $((OPTIND -1 ))
# anything left?
test -z "$1" || usage
}

rebuild_ut()
{
# -DINIT_CONFIG is ignored after the first time. Invoke make (or
# -ninja) after this for faster, incremental builds.
rm -rf build_ut/

cmake -S "$SOFTOP" -B build_ut -DBUILD_UNIT_TESTS=ON -DBUILD_UNIT_TESTS_HOST=ON \
-DINIT_CONFIG="${CONFIG}"

# clean build area
rm -rf build_ut
mkdir build_ut
cmake --build build_ut -- -j"$(nproc --all)"
}

# copy initial defconfig
cp src/arch/xtensa/configs/${CONFIG} initial.config
cd build_ut
run_ut()
{
local TESTS; TESTS=$(find build_ut/test -type f -executable -print)
echo test are "${TESTS}"
for test in ${TESTS}
do
if [ x"$test" = x'build_ut/test/cmocka/src/lib/alloc/alloc' ]; then
printf 'SKIP alloc test until it is fixed on HOST (passes with xt-run)'
continue
fi

cmake -DBUILD_UNIT_TESTS=ON -DBUILD_UNIT_TESTS_HOST=ON ..
printf 'Running %s\n' "${test}"
( set -x
${VALGRIND_CMD} ./"${test}"
)
done
}

make -j$(nproc --all)
main()
{
parse_opts "$@"
rebuild_ut
run_ut
}

TESTS=`find test -type f -executable -print`
echo test are ${TESTS}
for test in ${TESTS}
do
echo got ${test}
${VALGRIND_CMD} ./${test}
done
main "$@"

0 comments on commit 4256dac

Please sign in to comment.