Skip to content

Instantly share code, notes, and snippets.

@perillo
Created April 4, 2024 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perillo/cebd9f82094471b241b961a4f869b0ed to your computer and use it in GitHub Desktop.
Save perillo/cebd9f82094471b241b961a4f869b0ed to your computer and use it in GitHub Desktop.
#!/bin/sh
set -euo pipefail
# Build kcov
scripts/make.sh
printf "\n\n"
# Build tests
mkdir -p build-tests
cd build-tests
cmake ../tests
make
# Run tests
run_tests() {
# Don't pollute the /tmp directory.
tmpdir=$(mktemp -d --tmpdir kcov-test-XXXXXXXXXX)
export TMPDIR="$tmpdir"
# Print the name of the temporary work directory.
printf "WORK=%s\n" "$TMPDIR"
export PYTHONPATH=tests/tools
python -m libkcov build/src/kcov "$tmpdir" build-tests "." -v "$@" || exit 64
}
# Remove all artifacts generated by a previous run_tests
cleanup() {
# Used by system mode
rm -rdf /tmp/kcov-data
# /tmp/kcov-system.pid
# /tmp/kcov-system.pipe
# Total coverage
rm -rdf /tmp/kcov-kcov
# Other
rm -rdf /tmp/test-kcov # bash.bash_accumulate_changed_data
rm -f /tmp/setpgid.pid # compiled.setpgid_kill
rm -f main.log # compiled.attach_process_with_threads
rm -f thread.log # compiled.attach_process_with_threads
rm -rdf "echo" # basic.outdir_is_executable
# rm -rdf build-tests/.debug # debuglink
}
cd ..
# Clean generated files and directories
trap 'cleanup' EXIT INT QUIT TERM
# TODO: "rm -rf /tmp/kcov-system.*", better done by each test case.
# TODO: Reap all childrens?
run_tests "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment