2022-01-13 14:48:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function usage()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
${SCRIPT_NAME}: Generate coverage using grcov.
|
|
|
|
|
|
|
|
Usage:
|
2022-02-17 17:56:33 +00:00
|
|
|
coverage [opts] [suites...] : Run the provided test suites.
|
2022-01-13 14:48:25 +00:00
|
|
|
|
|
|
|
Options:
|
|
|
|
-h: Print this message.
|
|
|
|
-c: Continue using data from previous runs. (By default, data is deleted.)
|
|
|
|
|
|
|
|
Suites:
|
|
|
|
"unit": equivalent to cargo test --all-features
|
|
|
|
"integration": a simple integration test with a chutney network.
|
|
|
|
"all": enables all suites.
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
You need to have grcov, rust-nightly, and llvm-tools-preview installed.
|
|
|
|
For integration tests, you'll need chutney and tor.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
TOPDIR=$(dirname "$0")/..
|
|
|
|
cd "$TOPDIR"
|
|
|
|
|
|
|
|
CLEAR=yes
|
|
|
|
UNIT=no
|
|
|
|
INTEGRATION=no
|
|
|
|
|
|
|
|
while getopts "ch" opt ; do
|
|
|
|
case "$opt" in
|
|
|
|
c) CLEAR=no
|
|
|
|
;;
|
|
|
|
h) usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*) echo "Unknown option. (Run '$0 -h' for help.)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove the parsed flags.
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
for suite in "$@"; do
|
|
|
|
case "$suite" in
|
|
|
|
unit) UNIT=yes
|
|
|
|
;;
|
|
|
|
integration) INTEGRATION=yes
|
|
|
|
;;
|
|
|
|
all) UNIT=yes
|
|
|
|
INTEGRATION=yes
|
|
|
|
;;
|
|
|
|
*) echo "Unrecognized test suite '$suite'. (Run '$0 -h' for help.)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$UNIT" = no ] && [ "$INTEGRATION" = no ]; then
|
2022-01-19 13:04:46 +00:00
|
|
|
echo "No test suites listed; nothing will be done. (Run '$0 -h' for help.)"
|
|
|
|
exit 1
|
2022-01-13 14:48:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$CLEAR" = yes ] ; then
|
|
|
|
# Clear the old coverage report. We do this by default unless
|
|
|
|
# we are given the -c option.
|
2022-02-17 17:56:33 +00:00
|
|
|
./maint/with_coverage -s /bin/true
|
2022-01-13 14:48:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$UNIT" = yes ] ; then
|
|
|
|
# Run the unit tests, with coverage.
|
2022-02-17 17:56:33 +00:00
|
|
|
./maint/with_coverage -c -s cargo test --all-features
|
2022-01-13 14:48:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$INTEGRATION" = yes ] ; then
|
|
|
|
# Run the integration tests, with coverage.
|
|
|
|
#
|
|
|
|
# (This is just a basic test that uses curl over Arti over a
|
|
|
|
# chutney network. It's taken from the gitlab-ci tests.)
|
|
|
|
|
|
|
|
# TODO: we might want, at some point, to have a the following stuff
|
|
|
|
# go into a basic extensible integration-testing script that gets
|
|
|
|
# run both from here and from the .gitlab-ci.yml file.
|
2022-02-17 17:56:33 +00:00
|
|
|
trap ./tests/chutney/teardown 0
|
2022-03-10 14:56:11 +00:00
|
|
|
./maint/with_coverage -c -s ./tests/chutney/setup proxy
|
2022-01-13 14:48:25 +00:00
|
|
|
curl http://example.com -vs --socks5-hostname 127.0.0.1:9150 -o /dev/null
|
|
|
|
trap - 0
|
2022-02-17 17:56:33 +00:00
|
|
|
./tests/chutney/teardown
|
2022-01-13 14:48:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate the coverage report.
|
2022-02-17 17:56:33 +00:00
|
|
|
./maint/with_coverage -c /bin/true
|
2021-05-25 22:11:45 +01:00
|
|
|
|