|
3 | 3 | #Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
|
4 | 4 | #SPDX-License-Identifier: BSD-3-Clause-Clear
|
5 | 5 |
|
6 |
| -# Source init_env and functestlib.sh |
| 6 | +# Robustly find and source init_env |
7 | 7 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
8 | 8 | INIT_ENV=""
|
9 | 9 | SEARCH="$SCRIPT_DIR"
|
10 |
| - |
11 | 10 | while [ "$SEARCH" != "/" ]; do
|
12 | 11 | if [ -f "$SEARCH/init_env" ]; then
|
13 | 12 | INIT_ENV="$SEARCH/init_env"
|
14 | 13 | break
|
15 | 14 | fi
|
16 | 15 | SEARCH=$(dirname "$SEARCH")
|
17 | 16 | done
|
18 |
| - |
| 17 | + |
19 | 18 | if [ -z "$INIT_ENV" ]; then
|
20 | 19 | echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
|
21 | 20 | exit 1
|
22 | 21 | fi
|
23 |
| - |
24 |
| -# shellcheck disable=SC1090 |
25 |
| -. "$INIT_ENV" |
| 22 | + |
| 23 | +if [ -z "$__INIT_ENV_LOADED" ]; then |
| 24 | + # shellcheck disable=SC1090 |
| 25 | + . "$INIT_ENV" |
| 26 | +fi |
26 | 27 | # shellcheck disable=SC1090,SC1091
|
27 | 28 | . "$TOOLS/functestlib.sh"
|
28 |
| - |
| 29 | + |
29 | 30 | TESTNAME="Ethernet"
|
30 |
| -test_path=$(find_test_case_by_name "$TESTNAME") || { |
31 |
| - log_fail "$TESTNAME : Test directory not found." |
32 |
| - echo "FAIL $TESTNAME" > "./$TESTNAME.res" |
33 |
| - exit 1 |
34 |
| -} |
35 |
| - |
| 31 | +test_path=$(find_test_case_by_name "$TESTNAME") |
36 | 32 | cd "$test_path" || exit 1
|
37 | 33 | res_file="./$TESTNAME.res"
|
38 |
| -rm -f "$res_file" |
| 34 | +summary_file="./$TESTNAME.summary" |
| 35 | +rm -f "$res_file" "$summary_file" |
39 | 36 |
|
40 | 37 | log_info "--------------------------------------------------------------------------"
|
41 | 38 | log_info "-------------------Starting $TESTNAME Testcase----------------------------"
|
42 |
| - |
| 39 | + |
| 40 | +# Check for dependencies |
43 | 41 | check_dependencies ip ping
|
44 |
| - |
45 |
| -IFACE="eth0" |
46 |
| -RETRIES=3 |
47 |
| -SLEEP_SEC=3 |
48 |
| - |
49 |
| -# Check interface existence |
50 |
| -if ! ip link show "$IFACE" >/dev/null 2>&1; then |
51 |
| - log_fail "Ethernet interface $IFACE not found" |
52 |
| - echo "FAIL $TESTNAME" > "$res_file" |
53 |
| - exit 1 |
| 42 | + |
| 43 | +# User-specified interface (argument) or all detected |
| 44 | +# Accept user-preferred interface as argument |
| 45 | +user_iface="$1" |
| 46 | +if [ -n "$user_iface" ]; then |
| 47 | + IFACES="$user_iface" |
| 48 | + log_info "User specified interface: $user_iface" |
| 49 | +else |
| 50 | + IFACES=$(get_ethernet_interfaces) |
| 51 | + log_info "Auto-detected Ethernet interfaces: $IFACES" |
54 | 52 | fi
|
55 |
| - |
56 |
| -# Bring up interface with retries |
57 |
| -log_info "Ensuring $IFACE is UP..." |
58 |
| -i=0 |
59 |
| -while [ $i -lt $RETRIES ]; do |
60 |
| - ip link set "$IFACE" up |
61 |
| - sleep "$SLEEP_SEC" |
62 |
| - if ip link show "$IFACE" | grep -q "state UP"; then |
63 |
| - log_info "$IFACE is UP" |
64 |
| - break |
| 53 | + |
| 54 | +iface_passed=0 |
| 55 | +iface_failed=0 |
| 56 | +iface_skipped=0 |
| 57 | + |
| 58 | +for iface in $IFACES; do |
| 59 | + log_info "---- Testing interface: $iface ----" |
| 60 | + |
| 61 | + # Check if interface is up |
| 62 | + if ! is_interface_up "$iface"; then |
| 63 | + log_warn "$iface is DOWN, skipping" |
| 64 | + echo "$iface: SKIP (down/no cable)" >> "$summary_file" |
| 65 | + iface_skipped=$((iface_skipped+1)) |
| 66 | + continue |
| 67 | + fi |
| 68 | + |
| 69 | + ip_addr="$(get_ip_address "$iface")" |
| 70 | + |
| 71 | + if [ -z "$ip_addr" ]; then |
| 72 | + log_info "$iface has no IP, attempting DHCP" |
| 73 | + run_dhcp_client "$iface" 10 |
| 74 | + sleep 2 |
| 75 | + ip_addr="$(get_ip_address "$iface")" |
| 76 | + fi |
| 77 | + |
| 78 | + if [ -z "$ip_addr" ]; then |
| 79 | + log_warn "$iface has no IP assigned, skipping" |
| 80 | + echo "$iface: SKIP (no IP assigned)" >> "$summary_file" |
| 81 | + iface_skipped=$((iface_skipped+1)) |
| 82 | + continue |
| 83 | + elif echo "$ip_addr" | grep -q '^169\.254'; then |
| 84 | + log_warn "$iface got only link-local IP ($ip_addr), skipping" |
| 85 | + echo "$iface: SKIP (link-local IP: $ip_addr)" >> "$summary_file" |
| 86 | + iface_skipped=$((iface_skipped+1)) |
| 87 | + continue |
| 88 | + else |
| 89 | + log_info "$iface got IP: $ip_addr" |
| 90 | + fi |
| 91 | + |
| 92 | + # Ping test |
| 93 | + if ping -I "$iface" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then |
| 94 | + log_pass "$iface connectivity verified via ping" |
| 95 | + echo "$iface: PASS" >> "$summary_file" |
| 96 | + iface_passed=$((iface_passed+1)) |
| 97 | + else |
| 98 | + log_fail "Ping test failed for $iface" |
| 99 | + echo "$iface: FAIL (ping failed)" >> "$summary_file" |
| 100 | + iface_failed=$((iface_failed+1)) |
65 | 101 | fi
|
66 |
| - log_warn "$IFACE is still DOWN (attempt $((i + 1))/$RETRIES)..." |
67 |
| - i=$((i + 1)) |
68 | 102 | done
|
69 |
| - |
70 |
| -if [ $i -eq $RETRIES ]; then |
71 |
| - log_fail "Failed to bring up $IFACE after $RETRIES attempts" |
72 |
| - echo "FAIL $TESTNAME" > "$res_file" |
| 103 | + |
| 104 | +log_info "---- Ethernet Interface Test Summary ----" |
| 105 | +cat "$summary_file" |
| 106 | + |
| 107 | +if [ "$iface_passed" -gt 0 ]; then |
| 108 | + echo "$TESTNAME PASS" > "$res_file" |
| 109 | + exit 0 |
| 110 | +elif [ "$iface_failed" -gt 0 ]; then |
| 111 | + echo "$TESTNAME FAIL" > "$res_file" |
73 | 112 | exit 1
|
| 113 | +else |
| 114 | + echo "$TESTNAME SKIP" > "$res_file" |
| 115 | + exit 2 |
74 | 116 | fi
|
75 |
| - |
76 |
| -# Ping test with retries |
77 |
| -log_info "Running ping test to 8.8.8.8 via $IFACE..." |
78 |
| -i=0 |
79 |
| -while [ $i -lt $RETRIES ]; do |
80 |
| - if ping -I "$IFACE" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then |
81 |
| - log_pass "Ethernet connectivity verified via ping" |
82 |
| - echo "PASS $TESTNAME" > "$res_file" |
83 |
| - exit 0 |
84 |
| - fi |
85 |
| - log_warn "Ping failed (attempt $((i + 1))/$RETRIES)... retrying" |
86 |
| - sleep "$SLEEP_SEC" |
87 |
| - i=$((i + 1)) |
88 |
| -done |
89 |
| - |
90 |
| -log_fail "Ping test failed after $RETRIES attempts" |
91 |
| -echo "FAIL $TESTNAME" > "$res_file" |
92 |
| -exit 1 |
|
0 commit comments