Skip to content

Commit 3ef90fb

Browse files
authored
Merge pull request qualcomm-linux#80 from smuppand/eth-dynamic-fix
Ethernet Test: Dynamic Interface Detection and Robust CI Validation
2 parents 8e078f4 + 15ce842 commit 3ef90fb

File tree

4 files changed

+284
-62
lines changed

4 files changed

+284
-62
lines changed

Runner/plans/meta-qcom_PreMerge.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ metadata:
1414
run:
1515
steps:
1616
- cd Runner
17+
- $PWD/suites/Connectivity/Ethernet/run.sh || true
18+
- $PWD/utils/send-to-lava.sh $PWD/suites/Connectivity/Ethernet/Ethernet.res || true
1719
- $PWD/suites/Kernel/FunctionalArea/baseport/adsp_remoteproc/run.sh || true
1820
- $PWD/utils/send-to-lava.sh $PWD/suites/Kernel/FunctionalArea/baseport/adsp_remoteproc/adsp_remoteproc.res || true
1921
- $PWD/suites/Kernel/FunctionalArea/baseport/cdsp_remoteproc/run.sh || true
@@ -36,6 +38,4 @@ run:
3638
- $PWD/utils/send-to-lava.sh $PWD/suites/Multimedia/Audio/AudioRecord/AudioRecord.res || true
3739
- $PWD/suites/Connectivity/Bluetooth/run.sh || true
3840
- $PWD/utils/send-to-lava.sh $PWD/suites/Connectivity/Bluetooth/Bluetooth.res || true
39-
- $PWD/suites/Connectivity/Ethernet/run.sh || true
40-
- $PWD/utils/send-to-lava.sh $PWD/suites/Connectivity/Ethernet/Ethernet.res || true
4141
- $PWD/utils/result_parse.sh

Runner/suites/Connectivity/Ethernet/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ cd <this-repo>
2828
scp -r common Runner user@target_device_ip:<Path in device>
2929
ssh user@target_device_ip
3030
cd <Path in device>/Runner && ./run-test.sh Ethernet
31+
# Optional: specify preferred interface (e.g., eth1)
32+
./run.sh [preferred-interface]
3133
```
3234

3335
## Prerequisites
@@ -53,5 +55,14 @@ Test result will be saved in `Ethernet.res` as:
5355
## Output
5456
A .res file is generated in the same directory:
5557

56-
`PASS Ethernet` OR `FAIL Ethernet`
58+
`Ethernet PASS` OR `Ethernet FAIL`
5759

60+
## Sample Log
61+
```
62+
Output
63+
64+
[INFO] 2025-06-11 10:12:23 - Detected Ethernet interface: enP1p4s0u1u1
65+
[PASS] 2025-06-11 10:12:30 - enP1p4s0u1u1 is UP
66+
[INFO] 2025-06-11 10:12:31 - Assigned IP: 10.0.0.55
67+
[PASS] 2025-06-11 10:12:35 - Ping successful on enP1p4s0u1u1
68+
```

Runner/suites/Connectivity/Ethernet/run.sh

Lines changed: 102 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,133 @@
33
#Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
#SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
# Source init_env and functestlib.sh
6+
# Robustly find and source init_env
77
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
INIT_ENV=""
99
SEARCH="$SCRIPT_DIR"
10-
1110
while [ "$SEARCH" != "/" ]; do
1211
if [ -f "$SEARCH/init_env" ]; then
1312
INIT_ENV="$SEARCH/init_env"
1413
break
1514
fi
1615
SEARCH=$(dirname "$SEARCH")
1716
done
18-
17+
1918
if [ -z "$INIT_ENV" ]; then
2019
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
2120
exit 1
2221
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
2627
# shellcheck disable=SC1090,SC1091
2728
. "$TOOLS/functestlib.sh"
28-
29+
2930
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")
3632
cd "$test_path" || exit 1
3733
res_file="./$TESTNAME.res"
38-
rm -f "$res_file"
34+
summary_file="./$TESTNAME.summary"
35+
rm -f "$res_file" "$summary_file"
3936

4037
log_info "--------------------------------------------------------------------------"
4138
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
42-
39+
40+
# Check for dependencies
4341
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+
user_iface="$1"
45+
if [ -n "$user_iface" ]; then
46+
ETH_IFACES="$user_iface"
47+
log_info "User specified interface: $user_iface"
48+
else
49+
ETH_IFACES="$(get_ethernet_interfaces)"
50+
log_info "Auto-detected Ethernet interfaces: $ETH_IFACES"
5451
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
52+
53+
if [ -z "$ETH_IFACES" ]; then
54+
log_warn "No Ethernet interfaces detected."
55+
echo "No Ethernet interfaces detected." >> "$summary_file"
56+
echo "$TESTNAME SKIP" > "$res_file"
57+
exit 0
58+
fi
59+
60+
any_passed=0
61+
any_tested=0
62+
63+
for iface in $ETH_IFACES; do
64+
log_info "---- Testing interface: $iface ----"
65+
66+
if ! is_interface_up "$iface"; then
67+
log_warn "$iface is DOWN, skipping"
68+
echo "$iface: SKIP (down/no cable)" >> "$summary_file"
69+
continue
70+
fi
71+
72+
ip_addr=$(get_ip_address "$iface")
73+
if [ -z "$ip_addr" ]; then
74+
if try_dhcp_client_safe "$iface" 10; then
75+
ip_addr=$(get_ip_address "$iface")
76+
log_info "$iface obtained IP after DHCP: $ip_addr"
77+
fi
78+
fi
79+
80+
if [ -z "$ip_addr" ]; then
81+
log_warn "$iface did not obtain an IP address after DHCP attempt, skipping"
82+
echo "$iface: SKIP (no IP, DHCP failed)" >> "$summary_file"
83+
continue
84+
fi
85+
86+
if echo "$ip_addr" | grep -q '^169\.254'; then
87+
log_warn "$iface got only link-local IP ($ip_addr), skipping"
88+
echo "$iface: SKIP (link-local only: $ip_addr)" >> "$summary_file"
89+
continue
90+
fi
91+
92+
log_pass "$iface is UP"
93+
log_info "$iface got IP: $ip_addr"
94+
95+
any_tested=1
96+
retries=3
97+
pass=0
98+
for i in $(seq 1 $retries); do
99+
if ping -I "$iface" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then
100+
log_pass "Ethernet connectivity verified via ping"
101+
echo "$iface: PASS (IP: $ip_addr, ping OK)" >> "$summary_file"
102+
pass=1
103+
any_passed=1
104+
break
105+
else
106+
log_warn "Ping failed for $iface (attempt $i/$retries)"
107+
sleep 2
108+
fi
109+
done
110+
111+
if [ "$pass" -eq 0 ]; then
112+
log_fail "Ping test failed for $iface"
113+
echo "$iface: FAIL (IP: $ip_addr, ping failed)" >> "$summary_file"
65114
fi
66-
log_warn "$IFACE is still DOWN (attempt $((i + 1))/$RETRIES)..."
67-
i=$((i + 1))
68115
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"
116+
117+
log_info "---- Ethernet Interface Test Summary ----"
118+
if [ -f "$summary_file" ]; then
119+
cat "$summary_file"
120+
else
121+
log_info "No summary information recorded."
122+
fi
123+
124+
if [ "$any_passed" -gt 0 ]; then
125+
echo "$TESTNAME PASS" > "$res_file"
126+
exit 0
127+
elif [ "$any_tested" -gt 0 ]; then
128+
echo "$TESTNAME FAIL" > "$res_file"
73129
exit 1
130+
else
131+
log_warn "No interfaces were tested (all were skipped)."
132+
echo "No suitable Ethernet interfaces found. All were down, link-local, or failed to get IP." >> "$summary_file"
133+
echo "$TESTNAME SKIP" > "$res_file"
134+
exit 0
74135
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

Comments
 (0)