|
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 |
8 | | -#import platform |
9 | | -. "${TOOLS}"/platform.sh |
10 | | - |
11 | | -__RUNNER_SUITES_DIR="/var/Runner/suites" |
12 | | -__RUNNER_UTILS_BIN_DIR="/var/common" |
13 | | - |
14 | | -#This function used for test logging |
| 6 | +# --- Logging helpers --- |
15 | 7 | log() { |
16 | | - local level="$1" |
| 8 | + level=$1 |
17 | 9 | shift |
18 | | - # echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a /var/test_framework.log |
19 | | - echo "[$level] $(date '+%Y-%m-%d %H:%M:%S') - $*" | tee -a /var/test_output.log |
| 10 | + echo "[$level] $(date '+%Y-%m-%d %H:%M:%S') - $*" |
20 | 11 | } |
21 | | -# Find test case path by name |
| 12 | +log_info() { log "INFO" "$@"; } |
| 13 | +log_pass() { log "PASS" "$@"; } |
| 14 | +log_fail() { log "FAIL" "$@"; } |
| 15 | +log_error() { log "ERROR" "$@"; } |
| 16 | +log_skip() { log "SKIP" "$@"; } |
| 17 | + |
| 18 | +# --- Dependency check --- |
| 19 | +check_dependencies() { |
| 20 | + missing=0 |
| 21 | + for cmd in "$@"; do |
| 22 | + if ! command -v "$cmd" >/dev/null 2>&1; then |
| 23 | + log_error "Required command '$cmd' not found in PATH." |
| 24 | + missing=1 |
| 25 | + fi |
| 26 | + done |
| 27 | + [ "$missing" -ne 0 ] && exit 1 |
| 28 | +} |
| 29 | + |
| 30 | +# --- Test case directory lookup --- |
22 | 31 | find_test_case_by_name() { |
23 | | - local test_name="$1" |
24 | | - if [ -d "$__RUNNER_SUITES_DIR" ]; then |
25 | | - find $__RUNNER_SUITES_DIR -type d -iname "$test_name" 2>/dev/null |
26 | | - else |
27 | | - find "${PWD}" -type d -iname "$test_name" 2>/dev/null |
28 | | - fi |
| 32 | + test_name=$1 |
| 33 | + base_dir="${__RUNNER_SUITES_DIR:-$ROOT_DIR/suites}" |
| 34 | + # Only search under the SUITES directory! |
| 35 | + testpath=$(find "$base_dir" -type d -iname "$test_name" -print -quit 2>/dev/null) |
| 36 | + echo "$testpath" |
29 | 37 | } |
30 | 38 |
|
31 | | -# Find test case path by name |
32 | 39 | find_test_case_bin_by_name() { |
33 | | - local test_name="$1" |
34 | | - find $__RUNNER_UTILS_BIN_DIR -type f -iname "$test_name" 2>/dev/null |
| 40 | + test_name=$1 |
| 41 | + base_dir="${__RUNNER_UTILS_BIN_DIR:-$ROOT_DIR/common}" |
| 42 | + find "$base_dir" -type f -iname "$test_name" -print -quit 2>/dev/null |
35 | 43 | } |
36 | 44 |
|
37 | | -# Find test case path by name |
38 | 45 | find_test_case_script_by_name() { |
39 | | - local test_name="$1" |
40 | | - if [ -d "$__RUNNER_UTILS_BIN_DIR" ]; then |
41 | | - find $__RUNNER_UTILS_BIN_DIR -type d -iname "$test_name" 2>/dev/null |
42 | | - else |
43 | | - find "${PWD}" -type d -iname "$test_name" 2>/dev/null |
44 | | - fi |
| 46 | + test_name=$1 |
| 47 | + base_dir="${__RUNNER_UTILS_BIN_DIR:-$ROOT_DIR/common}" |
| 48 | + find "$base_dir" -type d -iname "$test_name" -print -quit 2>/dev/null |
45 | 49 | } |
46 | 50 |
|
47 | | -check_dependencies() { |
48 | | - local missing=0 |
49 | | - for cmd in "$@"; do |
50 | | - if ! command -v "$cmd" > /dev/null 2>&1; then |
51 | | - log_error "ERROR: Required command '$cmd' not found in PATH." |
52 | | - missing=1 |
| 51 | +# --- Optional: POSIX-safe repo root detector --- |
| 52 | +detect_runner_root() { |
| 53 | + path=$1 |
| 54 | + while [ "$path" != "/" ]; do |
| 55 | + if [ -d "$path/suites" ]; then |
| 56 | + echo "$path" |
| 57 | + return |
53 | 58 | fi |
| 59 | + path=$(dirname "$path") |
54 | 60 | done |
55 | | - if [ "$missing" -ne 0 ]; then |
56 | | - log_error "Exiting due to missing dependencies." |
57 | | - exit 1 |
| 61 | + echo "" |
| 62 | +} |
| 63 | + |
| 64 | +# ---------------------------- |
| 65 | +# Additional Utility Functions |
| 66 | +# ---------------------------- |
| 67 | + |
| 68 | +check_network_status() { |
| 69 | + ip_addr=$(ip -4 addr show scope global up 2>/dev/null | awk '/inet /{print $2}' | cut -d/ -f1 | head -n 1) |
| 70 | + if [ -n "$ip_addr" ]; then |
| 71 | + log_pass "Network is active. IP address: $ip_addr" |
| 72 | +if ping -c 1 -W 2 8.8.8.8 >/dev/null 2>&1; then |
| 73 | + log_pass "Internet is reachable." |
| 74 | + return 0 |
| 75 | + else |
| 76 | + log_error "Network active but no internet access." |
| 77 | + return 2 |
| 78 | + fi |
58 | 79 | else |
59 | | - log_pass "Test related dependencies are present." |
| 80 | + log_fail "No active network interface found." |
| 81 | + return 1 |
60 | 82 | fi |
61 | 83 | } |
62 | 84 |
|
63 | | -# Logging levels |
64 | | -log_info() { log "INFO" "$@"; } |
65 | | -log_pass() { log "PASS" "$@"; } |
66 | | -log_fail() { log "FAIL" "$@"; } |
67 | | -log_error() { log "ERROR" "$@"; } |
| 85 | +check_tar_file() { |
| 86 | + url=$1 |
| 87 | + filename=$(basename "$url") |
| 88 | + foldername="${filename%.tar*}" |
68 | 89 |
|
| 90 | + if [ ! -f "$filename" ]; then |
| 91 | + log_error "File $filename does not exist." |
| 92 | + return 1 |
| 93 | + fi |
| 94 | + if [ ! -s "$filename" ]; then |
| 95 | + log_error "File $filename exists but is empty." |
| 96 | + return 1 |
| 97 | + fi |
| 98 | + if ! tar -tf "$filename" >/dev/null 2>&1; then |
| 99 | + log_error "File $filename is not a valid tar archive." |
| 100 | + return 1 |
| 101 | + fi |
| 102 | + if [ -d "$foldername" ]; then |
| 103 | + log_pass "$filename has already been extracted to $foldername/" |
| 104 | + return 0 |
| 105 | + fi |
| 106 | + log_info "$filename exists and is valid, but not yet extracted." |
| 107 | + return 2 |
| 108 | +} |
69 | 109 |
|
70 | | -## this doc fn comes last |
71 | | -FUNCTIONS="\ |
72 | | -log_info \ |
73 | | -log_pass \ |
74 | | -log_fail \ |
75 | | -log_error \ |
76 | | -find_test_case_by_name \ |
77 | | -find_test_case_bin_by_name \ |
78 | | -find_test_case_script_by_name \ |
79 | | -log \ |
80 | | -" |
81 | | - |
82 | | -functestlibdoc() |
83 | | -{ |
84 | | - echo "functestlib.sh" |
85 | | - echo "" |
86 | | - echo "Functions:" |
87 | | - for fn in $FUNCTIONS; do |
88 | | - echo $fn |
89 | | - eval $fn"_doc" |
90 | | - echo "" |
91 | | - done |
92 | | - echo "Note, these functions will probably not work with >=32 CPUs" |
| 110 | +extract_tar_from_url() { |
| 111 | + url=$1 |
| 112 | + filename=$(basename "$url") |
| 113 | + |
| 114 | + check_tar_file "$url" |
| 115 | + status=$? |
| 116 | + if [ "$status" -eq 0 ]; then |
| 117 | + log_info "Already extracted. Skipping download." |
| 118 | + return 0 |
| 119 | + elif [ "$status" -eq 1 ]; then |
| 120 | + log_info "File missing or invalid. Will download and extract." |
| 121 | + fi |
| 122 | + |
| 123 | + check_network_status || return 1 |
| 124 | + |
| 125 | + log_info "Downloading $url..." |
| 126 | + wget -O "$filename" "$url" || { |
| 127 | + log_fail "Failed to download $filename" |
| 128 | + return 1 |
| 129 | + } |
| 130 | + |
| 131 | + log_info "Extracting $filename..." |
| 132 | + tar -xvf "$filename" || { |
| 133 | + log_fail "Failed to extract $filename" |
| 134 | + return 1 |
| 135 | + } |
| 136 | + |
| 137 | + extracted_files=$(tar -tf "$filename") |
| 138 | + if [ -z "$extracted_files" ]; then |
| 139 | + log_fail "No files were extracted from $filename." |
| 140 | + return 1 |
| 141 | + else |
| 142 | + log_pass "Files extracted successfully:" |
| 143 | + echo "$extracted_files" |
| 144 | + return 0 |
| 145 | + fi |
93 | 146 | } |
94 | 147 |
|
95 | 148 | # Function is to check for network connectivity status |
|
0 commit comments