-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathrun-test.sh
More file actions
executable file
·164 lines (147 loc) · 5.06 KB
/
run-test.sh
File metadata and controls
executable file
·164 lines (147 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
# Resolve the real path of this script
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Set TOOLS path to utils under the script directory
TOOLS="$SCRIPT_DIR/utils"
# Disable wrapper-level capture; each test will capture in its own folder
export RUN_STDOUT_ENABLE=0
unset RUN_STDOUT_TAG RUN_STDOUT_FILE
# Safely source init_env from the same directory as this script
if [ -f "$SCRIPT_DIR/init_env" ]; then
# shellcheck source=/dev/null
. "$SCRIPT_DIR/init_env"
else
echo "[INFO] init_env not found at $SCRIPT_DIR/init_env — skipping."
fi
# Source functestlib.sh from utils/
if [ -f "$TOOLS/functestlib.sh" ]; then
# shellcheck source=/dev/null
. "$TOOLS/functestlib.sh"
# Export key vars so they are visible to child scripts like ./run.sh
export ROOT_DIR
export TOOLS
export __RUNNER_SUITES_DIR
export __RUNNER_UTILS_BIN_DIR
else
echo "[ERROR] functestlib.sh not found at $TOOLS/functestlib.sh"
exit 1
fi
# Store results
RESULTS_PASS=""
RESULTS_FAIL=""
RESULTS_SKIP=""
execute_test_case() {
test_path=$1
shift
test_name=$(basename "$test_path")
if [ -d "$test_path" ]; then
run_script="$test_path/run.sh"
if [ -f "$run_script" ]; then
log "Executing test case: $test_name"
(
cd "$test_path" || exit 2
# Enable per-test capture in the test folder with a clear tag
RUN_STDOUT_ENABLE=1 RUN_STDOUT_TAG="$test_name" sh "./run.sh" "$@"
)
res_file="$test_path/$test_name.res"
if [ -f "$res_file" ]; then
if grep -q "SKIP" "$res_file"; then
log_skip "$test_name skipped"
if [ -z "$RESULTS_SKIP" ]; then
RESULTS_SKIP="$test_name"
else
RESULTS_SKIP=$(printf "%s\n%s" "$RESULTS_SKIP" "$test_name")
fi
elif grep -q "PASS" "$res_file"; then
log_pass "$test_name passed"
if [ -z "$RESULTS_PASS" ]; then
RESULTS_PASS="$test_name"
else
RESULTS_PASS=$(printf "%s\n%s" "$RESULTS_PASS" "$test_name")
fi
elif grep -q "FAIL" "$res_file"; then
log_fail "$test_name failed"
if [ -z "$RESULTS_FAIL" ]; then
RESULTS_FAIL="$test_name"
else
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name")
fi
else
log_fail "$test_name: unknown result in .res file"
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (unknown result)")
fi
else
log_fail "$test_name: .res file not found"
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (.res not found)")
fi
else
log_error "No run.sh found in $test_path"
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (missing run.sh)")
fi
else
log_error "Test case directory not found: $test_path"
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (directory not found)")
fi
}
run_specific_test_by_name() {
test_name=$1
shift
test_path=$(find_test_case_by_name "$test_name")
if [ -z "$test_path" ]; then
log_error "Test case with name $test_name not found."
RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (not found)")
else
execute_test_case "$test_path" "$@"
fi
}
run_all_tests() {
find "${__RUNNER_SUITES_DIR}" -maxdepth 3 -type d -name '[A-Za-z]*' | while IFS= read -r test_dir; do
if [ -f "$test_dir/run.sh" ]; then
execute_test_case "$test_dir"
fi
done
}
print_summary() {
echo
log_info "========== Test Summary =========="
echo "PASSED:"
[ -n "$RESULTS_PASS" ] && printf "%s\n" "$RESULTS_PASS" || echo " None"
echo
echo "FAILED:"
[ -n "$RESULTS_FAIL" ] && printf "%s\n" "$RESULTS_FAIL" || echo " None"
echo
echo "SKIPPED:"
[ -n "$RESULTS_SKIP" ] && printf "%s\n" "$RESULTS_SKIP" || echo " None"
log_info "=================================="
}
print_usage() {
cat >&2 <<EOF
Usage:
"${0##*/}" all
"${0##*/}" <testcase_name> [arg1 arg2 ...]
Notes:
- Extra args are forwarded only when a single <testcase_name> is specified.
- 'all' runs every test and does not accept additional args.
- Each test captures stdout/stderr next to its .res file as:
<testname>_stdout_<timestamp>.log
EOF
}
if [ "$#" -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
print_usage
if [ "$#" -eq 0 ]; then
log_error "No arguments provided"
exit 1
else
exit 0
fi
fi
if [ "$1" = "all" ]; then
run_all_tests
else
test_case_name="$1"
shift
run_specific_test_by_name "$test_case_name" "$@"
fi
print_summary