1:255.13-alt1
[systemd_ALT.git] / test / run-integration-tests.sh
blob2a2b075aa3a457ad067ee5fa6faab5249d8ce816
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
5 if [ "$NO_BUILD" ]; then
6 BUILD_DIR=""
7 elif BUILD_DIR="$("$(dirname "$0")/../tools/find-build-dir.sh")"; then
8 ninja -C "$BUILD_DIR"
9 else
10 echo "No build found, please set BUILD_DIR or NO_BUILD" >&2
11 exit 1
14 if [ $# -gt 0 ]; then
15 args="$*"
16 else
17 args="setup run clean-again"
20 VALID_TARGETS="all setup run clean clean-again"
22 is_valid_target() {
23 for target in $VALID_TARGETS; do
24 [ "$1" = "$target" ] && return 0
25 done
26 return 1
29 # reject invalid make targets in $args
30 for arg in $args; do
31 if ! is_valid_target "$arg"; then
32 echo "Invalid target: $arg" >&2
33 exit 1
35 done
37 CLEAN=0
38 CLEANAGAIN=0
40 # separate 'clean' and 'clean-again' operations
41 [[ "$args" =~ "clean-again" ]] && CLEANAGAIN=1
42 args=${args/clean-again}
43 [[ "$args" =~ "clean" ]] && CLEAN=1
44 args=${args/clean}
46 declare -A results
47 declare -A times
49 COUNT=0
50 FAILURES=0
52 cd "$(dirname "$0")"
54 pass_deny_list() {
55 for marker in $DENY_LIST_MARKERS $BLACKLIST_MARKERS; do
56 if [ -f "$1/$marker" ]; then
57 echo "========== DENY-LISTED: $1 ($marker) =========="
58 return 1
60 done
61 return 0
64 SELECTED_TESTS="${SELECTED_TESTS:-TEST-??-*}"
66 # Let's always do the cleaning operation first, because it destroys the image
67 # cache.
68 if [ $CLEAN = 1 ]; then
69 for TEST in $SELECTED_TESTS; do
70 ( set -x ; make -C "$TEST" clean )
71 done
74 # Run actual tests (if requested)
75 if [[ $args =~ [a-z] ]]; then
76 for TEST in $SELECTED_TESTS; do
77 COUNT=$((COUNT+1))
79 pass_deny_list "$TEST" || continue
80 start=$(date +%s)
82 echo -e "\n[$(date +%R:%S)] --x-- Running $TEST --x--"
83 set +e
84 # shellcheck disable=SC2086
85 ( set -x ; make -C "$TEST" $args )
86 RESULT=$?
87 set -e
88 echo "[$(date +%R:%S)] --x-- Result of $TEST: $RESULT --x--"
90 results["$TEST"]="$RESULT"
91 times["$TEST"]=$(( $(date +%s) - start ))
93 [ "$RESULT" -ne "0" ] && FAILURES=$((FAILURES+1))
94 done
97 # Run clean-again, if requested, and if no tests failed
98 if [[ $FAILURES -eq 0 && $CLEANAGAIN -eq 1 ]]; then
99 for TEST in "${!results[@]}"; do
100 ( set -x ; make -C "$TEST" clean-again )
101 done
104 echo ""
106 for TEST in "${!results[@]}"; do
107 RESULT="${results[$TEST]}"
108 time="${times[$TEST]}"
109 string=$([ "$RESULT" = "0" ] && echo "SUCCESS" || echo "FAIL")
110 printf "%-35s %-8s (%3s s)\n" "${TEST}:" "${string}" "$time"
111 done | sort
113 if [ "$FAILURES" -eq 0 ] ; then
114 echo -e "\nALL $COUNT TESTS PASSED"
115 else
116 echo -e "\nTOTAL FAILURES: $FAILURES OF $COUNT"
119 # If we have coverage files, merge them into a single report for upload
120 if [ -n "${ARTIFACT_DIRECTORY}" ]; then
121 lcov_args=()
123 while read -r info_file; do
124 lcov_args+=(--add-tracefile "${info_file}")
125 done < <(find "${ARTIFACT_DIRECTORY}" -maxdepth 1 -name "*.coverage-info")
127 if [ ${#lcov_args[@]} -gt 1 ]; then
128 lcov "${lcov_args[@]}" --output-file "${ARTIFACT_DIRECTORY}/merged.coverage-info"
132 exit "$FAILURES"