|
3 | 3 | # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
4 | 4 | # SPDX-License-Identifier: BSD-3-Clause-Clear |
5 | 5 |
|
6 | | -# Import test suite definitions |
7 | | -. "${PWD}"/init_env |
| 6 | +SCRIPT_DIR="$(dirname "$(realpath "$0")")" |
| 7 | +TOOLS="$SCRIPT_DIR/utils" |
8 | 8 |
|
9 | | -#import test functions library |
10 | | -. "${TOOLS}"/functestlib.sh |
11 | | - |
12 | | - |
13 | | -# Find test case path by name |
14 | | -find_test_case_by_name() { |
15 | | - # Check if the file is a directory |
16 | | - if [ -d "$1" ]; then |
17 | | - # Get the directory name |
18 | | - dir_name_in_dir=${1##*/} |
| 9 | +# Source init_env |
| 10 | +if [ -f "$SCRIPT_DIR/init_env" ]; then |
| 11 | + # shellcheck source=/dev/null |
| 12 | + . "$SCRIPT_DIR/init_env" |
| 13 | +else |
| 14 | + echo "[INFO] init_env not found at $SCRIPT_DIR/init_env — skipping." |
| 15 | +fi |
19 | 16 |
|
20 | | - # Check if the directory name matches the user input |
21 | | - if [ "${dir_name_in_dir}" = "$test_name" ]; then |
22 | | - # Get the absolute path of the directory |
23 | | - abs_path=$(readlink -f "$1") |
24 | | - echo "$abs_path" |
25 | | - fi |
26 | | - fi |
| 17 | +# Source functestlib |
| 18 | +if [ -f "$TOOLS/functestlib.sh" ]; then |
| 19 | + # shellcheck source=/dev/null |
| 20 | + . "$TOOLS/functestlib.sh" |
| 21 | + export ROOT_DIR TOOLS __RUNNER_SUITES_DIR __RUNNER_UTILS_BIN_DIR |
| 22 | +else |
| 23 | + echo "[ERROR] functestlib.sh not found at $TOOLS/functestlib.sh" |
| 24 | + exit 1 |
| 25 | +fi |
27 | 26 |
|
28 | | - # Recursively search for the directory in the subdirectory |
29 | | - for file in "$1"/*; do |
30 | | - # Check if the file is a directory |
31 | | - if [ -d "$file" ]; then |
32 | | - # Recursively search for the directory in the subdirectory |
33 | | - find_test_case_by_name "$file" |
34 | | - fi |
35 | | - done |
36 | | -} |
| 27 | +RESULTS_PASS="" |
| 28 | +RESULTS_FAIL="" |
37 | 29 |
|
38 | | -# Execute a test case |
39 | 30 | execute_test_case() { |
40 | | - local test_path="$1" |
| 31 | + test_path="$1" |
| 32 | + test_name=$(basename "$test_path") |
| 33 | + |
41 | 34 | if [ -d "$test_path" ]; then |
42 | 35 | run_script="$test_path/run.sh" |
43 | 36 | if [ -f "$run_script" ]; then |
44 | | - log "Executing test case: $test_path" |
45 | | - sh "$run_script" 2>&1 |
| 37 | + log "Executing test case: $test_name" |
| 38 | + if (cd "$test_path" && NO_INIT_LOG=1 sh "./run.sh"); then |
| 39 | + log_pass "$test_name passed" |
| 40 | + if [ -z "$RESULTS_PASS" ]; then |
| 41 | + RESULTS_PASS="$test_name" |
| 42 | + else |
| 43 | + RESULTS_PASS=$(printf "%s\n%s" "$RESULTS_PASS" "$test_name") |
| 44 | + fi |
| 45 | + else |
| 46 | + log_fail "$test_name failed" |
| 47 | + if [ -z "$RESULTS_FAIL" ]; then |
| 48 | + RESULTS_FAIL="$test_name" |
| 49 | + else |
| 50 | + RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name") |
| 51 | + fi |
| 52 | + fi |
46 | 53 | else |
47 | | - log "No run.sh found in $test_path" |
| 54 | + log_error "No run.sh found in $test_path" |
| 55 | + RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (missing run.sh)") |
48 | 56 | fi |
49 | 57 | else |
50 | | - log "Test case directory not found: $test_path" |
| 58 | + log_error "Test case directory not found: $test_path" |
| 59 | + RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (directory not found)") |
51 | 60 | fi |
52 | 61 | } |
53 | 62 |
|
54 | | -# Function to run a specific test case by name |
55 | 63 | run_specific_test_by_name() { |
56 | 64 | test_name="$1" |
57 | | - test_path=$(find_test_case_by_name ".") |
| 65 | + test_path=$(find_test_case_by_name "$test_name") |
58 | 66 | if [ -z "$test_path" ]; then |
59 | | - log "Test case with name $test_name not found." |
| 67 | + log_error "Test case with name $test_name not found." |
| 68 | + RESULTS_FAIL=$(printf "%s\n%s" "$RESULTS_FAIL" "$test_name (not found)") |
60 | 69 | else |
61 | 70 | execute_test_case "$test_path" |
62 | 71 | fi |
63 | 72 | } |
64 | 73 |
|
65 | | -# Main script logic |
| 74 | +run_all_tests() { |
| 75 | + find "${__RUNNER_SUITES_DIR}" -type d -name '[A-Za-z]*' -maxdepth 3 | while IFS= read -r test_dir; do |
| 76 | + [ -f "$test_dir/run.sh" ] && execute_test_case "$test_dir" |
| 77 | + done |
| 78 | +} |
| 79 | + |
| 80 | +print_summary() { |
| 81 | + echo |
| 82 | + log_info "========== Test Summary ==========" |
| 83 | + echo "PASSED:" |
| 84 | + [ -n "$RESULTS_PASS" ] && printf "%s\n" "$RESULTS_PASS" || echo " None" |
| 85 | + echo |
| 86 | + echo "FAILED:" |
| 87 | + [ -n "$RESULTS_FAIL" ] && printf "%s\n" "$RESULTS_FAIL" || echo " None" |
| 88 | + log_info "==================================" |
| 89 | +} |
| 90 | + |
| 91 | +# Main |
66 | 92 | if [ "$#" -eq 0 ]; then |
67 | 93 | log "Usage: $0 [all | <testcase_name>]" |
68 | 94 | exit 1 |
69 | 95 | fi |
70 | 96 |
|
| 97 | +if [ "$1" = "all" ]; then |
| 98 | + run_all_tests |
| 99 | +else |
| 100 | + run_specific_test_by_name "$1" |
| 101 | +fi |
71 | 102 |
|
72 | | -run_specific_test_by_name "$1" |
| 103 | +print_summary |
0 commit comments