mirror of https://github.com/thesofproject/sof.git
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 <marc.herbert@intel.com>
This commit is contained in:
parent
c8b226b86f
commit
a7c1c52420
|
@ -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)
|
||||
|
||||
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
|
||||
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=""
|
||||
|
||||
# clean build area
|
||||
rm -rf build_ut
|
||||
mkdir build_ut
|
||||
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
|
||||
|
||||
# copy initial defconfig
|
||||
cp src/arch/xtensa/configs/${CONFIG} initial.config
|
||||
cd build_ut
|
||||
shift $((OPTIND -1 ))
|
||||
# anything left?
|
||||
test -z "$1" || usage
|
||||
}
|
||||
|
||||
cmake -DBUILD_UNIT_TESTS=ON -DBUILD_UNIT_TESTS_HOST=ON ..
|
||||
rebuild_ut()
|
||||
{
|
||||
# -DINIT_CONFIG is ignored after the first time. Invoke make (or
|
||||
# -ninja) after this for faster, incremental builds.
|
||||
rm -rf build_ut/
|
||||
|
||||
make -j$(nproc --all)
|
||||
cmake -S "$SOFTOP" -B build_ut -DBUILD_UNIT_TESTS=ON -DBUILD_UNIT_TESTS_HOST=ON \
|
||||
-DINIT_CONFIG="${CONFIG}"
|
||||
|
||||
TESTS=`find test -type f -executable -print`
|
||||
echo test are ${TESTS}
|
||||
for test in ${TESTS}
|
||||
do
|
||||
echo got ${test}
|
||||
${VALGRIND_CMD} ./${test}
|
||||
done
|
||||
cmake --build build_ut -- -j"$(nproc --all)"
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
printf 'Running %s\n' "${test}"
|
||||
( set -x
|
||||
${VALGRIND_CMD} ./"${test}"
|
||||
)
|
||||
done
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
parse_opts "$@"
|
||||
rebuild_ut
|
||||
run_ut
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in New Issue