2020-03-04 17:35:06 +08:00
|
|
|
#!/usr/bin/env bash
|
2021-10-01 19:04:32 +08:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2020-03-04 17:35:06 +08:00
|
|
|
set -e
|
2017-11-29 02:42:15 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
is_valid_target() {
|
|
|
|
local target="${1:?}"
|
|
|
|
local t
|
|
|
|
|
|
|
|
for t in all setup run clean clean-again; do
|
|
|
|
[[ "$target" == "$t" ]] && return 0
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
pass_deny_list() {
|
|
|
|
local test="${1:?}"
|
|
|
|
local marker
|
|
|
|
|
|
|
|
for marker in $DENY_LIST_MARKERS $BLACKLIST_MARKERS; do
|
|
|
|
if [[ -f "$test/$marker" ]]; then
|
|
|
|
echo "========== DENY-LISTED: $test ($marker) =========="
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-03-12 20:11:16 +08:00
|
|
|
test_run() {
|
|
|
|
local test_name="${1:?}"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
echo >&2 "test_run: missing arguments"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Note: let's be very explicit in reporting the return code of the test command here, i.e don't rely on
|
|
|
|
# `set -e` or the return code of the last statement in the function, since reporting false positive
|
|
|
|
# would be very bad in this case.
|
|
|
|
if [[ "${SPLIT_TEST_LOGS:-0}" -ne 0 && -n "${ARTIFACT_DIRECTORY:-}" ]]; then
|
|
|
|
(set -x; "$@") &>>"$ARTIFACT_DIRECTORY/$test_name.log" || return $?
|
|
|
|
else
|
|
|
|
(set -x; "$@") || return $?
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
ARGS=(setup run clean-again)
|
|
|
|
CLEAN=0
|
|
|
|
CLEAN_AGAIN=0
|
|
|
|
COUNT=0
|
|
|
|
FAILURES=0
|
|
|
|
declare -A RESULTS
|
|
|
|
declare -A TIMES
|
|
|
|
|
|
|
|
if [[ "${NO_BUILD:-0}" =~ ^(1|yes|true)$ ]]; then
|
2020-11-18 04:55:47 +08:00
|
|
|
BUILD_DIR=""
|
2021-09-30 02:30:08 +08:00
|
|
|
elif BUILD_DIR="$("$(dirname "$0")/../tools/find-build-dir.sh")"; then
|
2020-11-18 04:55:47 +08:00
|
|
|
ninja -C "$BUILD_DIR"
|
|
|
|
else
|
2024-03-12 19:52:45 +08:00
|
|
|
echo >&2 "No build found, please set BUILD_DIR or NO_BUILD"
|
2020-11-18 04:55:47 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ $# -gt 0 ]]; then
|
|
|
|
ARGS=("$@")
|
2017-12-06 22:13:02 +08:00
|
|
|
fi
|
2020-11-18 20:30:11 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
# Reject invalid make targets
|
|
|
|
for arg in "${ARGS[@]}"; do
|
2020-11-18 20:30:11 +08:00
|
|
|
if ! is_valid_target "$arg"; then
|
2024-03-12 19:52:45 +08:00
|
|
|
echo >&2 "Invalid target: $arg"
|
2020-11-18 20:30:11 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
# Separate 'clean' and 'clean-again' operations
|
|
|
|
args_filtered=()
|
|
|
|
for arg in "${ARGS[@]}"; do
|
|
|
|
if [[ "$arg" == "clean-again" ]]; then
|
|
|
|
CLEAN_AGAIN=1
|
|
|
|
elif [[ "$arg" == "clean" ]]; then
|
|
|
|
CLEAN=1
|
|
|
|
else
|
|
|
|
args_filtered+=("$arg")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
ARGS=("${args_filtered[@]}")
|
2017-11-29 02:42:15 +08:00
|
|
|
|
2017-12-06 22:09:54 +08:00
|
|
|
cd "$(dirname "$0")"
|
2019-12-12 16:37:19 +08:00
|
|
|
|
2021-05-11 02:46:37 +08:00
|
|
|
SELECTED_TESTS="${SELECTED_TESTS:-TEST-??-*}"
|
|
|
|
|
2020-11-18 20:30:11 +08:00
|
|
|
# Let's always do the cleaning operation first, because it destroys the image
|
|
|
|
# cache.
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ $CLEAN -eq 1 ]]; then
|
|
|
|
for test in $SELECTED_TESTS; do
|
2024-03-12 20:11:16 +08:00
|
|
|
test_run "$test" make -C "$test" clean
|
2020-11-18 20:30:11 +08:00
|
|
|
done
|
|
|
|
fi
|
2018-03-23 17:02:22 +08:00
|
|
|
|
2020-11-18 20:30:11 +08:00
|
|
|
# Run actual tests (if requested)
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ ${#ARGS[@]} -ne 0 ]]; then
|
|
|
|
for test in $SELECTED_TESTS; do
|
|
|
|
COUNT=$((COUNT + 1))
|
2020-03-25 20:46:44 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
pass_deny_list "$test" || continue
|
|
|
|
SECONDS=0
|
2017-11-29 02:42:15 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
echo -e "\n[$(date +%R:%S)] --x-- Running $test --x--"
|
2020-11-18 20:30:11 +08:00
|
|
|
set +e
|
2024-03-12 20:11:16 +08:00
|
|
|
test_run "$test" make -C "$test" "${ARGS[@]}"
|
2024-03-12 19:52:45 +08:00
|
|
|
result=$?
|
2020-11-18 20:30:11 +08:00
|
|
|
set -e
|
2024-03-12 19:52:45 +08:00
|
|
|
echo "[$(date +%R:%S)] --x-- Result of $test: $result --x--"
|
2017-11-29 02:42:15 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
RESULTS["$test"]="$result"
|
|
|
|
TIMES["$test"]="$SECONDS"
|
2020-11-18 20:30:11 +08:00
|
|
|
|
2024-03-21 19:11:01 +08:00
|
|
|
# Run clean-again here to free up space, if requested, and if the test succeeded
|
|
|
|
if [[ "$result" -ne 0 ]]; then
|
|
|
|
FAILURES=$((FAILURES + 1))
|
|
|
|
elif [[ $CLEAN_AGAIN -eq 1 ]]; then
|
|
|
|
test_run "$test" make -C "$test" clean-again
|
|
|
|
fi
|
2019-12-12 16:37:19 +08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2017-11-29 02:42:15 +08:00
|
|
|
echo ""
|
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
for test in "${!RESULTS[@]}"; do
|
|
|
|
result="${RESULTS[$test]}"
|
|
|
|
time="${TIMES[$test]}"
|
|
|
|
[[ "$result" -eq 0 ]] && string="SUCCESS" || string="FAIL"
|
|
|
|
printf "%-35s %-8s (%3s s)\n" "$test:" "$string" "$time"
|
2017-11-29 02:42:15 +08:00
|
|
|
done | sort
|
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ "$FAILURES" -eq 0 ]]; then
|
scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)
Also remove the few vim config lines that were left. We should either have them
on all files, or none.
Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-04 20:10:42 +08:00
|
|
|
echo -e "\nALL $COUNT TESTS PASSED"
|
2017-11-29 02:42:15 +08:00
|
|
|
else
|
scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)
Also remove the few vim config lines that were left. We should either have them
on all files, or none.
Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-04 20:10:42 +08:00
|
|
|
echo -e "\nTOTAL FAILURES: $FAILURES OF $COUNT"
|
2017-11-29 02:42:15 +08:00
|
|
|
fi
|
|
|
|
|
2021-10-03 23:50:38 +08:00
|
|
|
# If we have coverage files, merge them into a single report for upload
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ -n "$ARTIFACT_DIRECTORY" ]]; then
|
2021-10-03 23:50:38 +08:00
|
|
|
lcov_args=()
|
|
|
|
|
|
|
|
while read -r info_file; do
|
2024-03-12 19:52:45 +08:00
|
|
|
lcov_args+=(--add-tracefile "$info_file")
|
|
|
|
done < <(find "$ARTIFACT_DIRECTORY" -maxdepth 1 -name "*.coverage-info")
|
2021-10-03 23:50:38 +08:00
|
|
|
|
2024-03-12 19:52:45 +08:00
|
|
|
if [[ ${#lcov_args[@]} -gt 1 ]]; then
|
|
|
|
lcov "${lcov_args[@]}" --output-file "$ARTIFACT_DIRECTORY/merged.coverage-info"
|
2021-10-03 23:50:38 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-11-29 02:42:15 +08:00
|
|
|
exit "$FAILURES"
|