Skip to content

Commit 11763ff

Browse files
committed
Ethernet test: Make interface detection dynamic, robustify bring-up and ping validation
- Add logic to auto-detect active Ethernet interface using ip/ipconfig - Enhance bring-up sequence with retries and logging - Improve ping test error handling and reporting - Refactor for better CI diagnostics Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent edfad16 commit 11763ff

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

Runner/suites/Connectivity/Ethernet/run.sh

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,54 +39,44 @@ rm -f "$res_file"
3939

4040
log_info "--------------------------------------------------------------------------"
4141
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
42-
42+
4343
check_dependencies ip ping
44-
45-
IFACE="eth0"
44+
45+
# Dynamically detect Ethernet interface
46+
IFACE=$(get_ethernet_interface)
47+
if [ -z "$IFACE" ]; then
48+
log_fail "No Ethernet interface found!"
49+
echo "$TESTNAME SKIP" > "$res_file"
50+
exit 0
51+
fi
52+
log_info "Detected Ethernet interface: $IFACE"
53+
4654
RETRIES=3
4755
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
54-
fi
55-
56-
# Bring up interface with retries
56+
57+
# Bring up the interface with retries
5758
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
65-
fi
66-
log_warn "$IFACE is still DOWN (attempt $((i + 1))/$RETRIES)..."
67-
i=$((i + 1))
68-
done
69-
70-
if [ $i -eq $RETRIES ]; then
59+
if ! bringup_interface "$IFACE" $RETRIES $SLEEP_SEC; then
7160
log_fail "Failed to bring up $IFACE after $RETRIES attempts"
72-
echo "FAIL $TESTNAME" > "$res_file"
61+
echo "$TESTNAME FAIL" > "$res_file"
7362
exit 1
7463
fi
75-
64+
log_pass "$IFACE is UP"
65+
7666
# Ping test with retries
7767
log_info "Running ping test to 8.8.8.8 via $IFACE..."
7868
i=0
7969
while [ $i -lt $RETRIES ]; do
8070
if ping -I "$IFACE" -c 4 -W 2 8.8.8.8 >/dev/null 2>&1; then
8171
log_pass "Ethernet connectivity verified via ping"
82-
echo "PASS $TESTNAME" > "$res_file"
72+
echo "$TESTNAME PASS" > "$res_file"
8373
exit 0
8474
fi
8575
log_warn "Ping failed (attempt $((i + 1))/$RETRIES)... retrying"
8676
sleep "$SLEEP_SEC"
8777
i=$((i + 1))
8878
done
89-
79+
9080
log_fail "Ping test failed after $RETRIES attempts"
91-
echo "FAIL $TESTNAME" > "$res_file"
81+
echo "$TESTNAME FAIL" > "$res_file"
9282
exit 1

Runner/utils/functestlib.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,45 @@ weston_start() {
391391
fi
392392
}
393393

394+
# Returns the name of a detected Ethernet interface, else empty
395+
get_ethernet_interface() {
396+
# Prefer 'ip', fallback to 'ifconfig'
397+
if command -v ip >/dev/null 2>&1; then
398+
# List interfaces, exclude loopback and wireless (wl* or wlan*)
399+
ip -o link show | awk -F': ' '{print $2}' | grep -E -v '^(lo|wl|wlan)' | head -n1
400+
elif command -v ifconfig >/dev/null 2>&1; then
401+
ifconfig -a | grep -E '^[a-zA-Z0-9]+' | grep -v -E '^(lo|wl|wlan)' | awk '{print $1}' | head -n1
402+
else
403+
echo ""
404+
return 1
405+
fi
406+
}
407+
408+
# Bring up interface with retries: always down before up
409+
bringup_interface() {
410+
iface="$1"
411+
retries="$2"
412+
sleep_sec="$3"
413+
i=0
414+
while [ $i -lt "$retries" ]; do
415+
if command -v ip >/dev/null 2>&1; then
416+
ip link set "$iface" down
417+
sleep 1
418+
ip link set "$iface" up
419+
sleep "$sleep_sec"
420+
if ip link show "$iface" | grep -q "state UP"; then
421+
return 0
422+
fi
423+
elif command -v ifconfig >/dev/null 2>&1; then
424+
ifconfig "$iface" down
425+
sleep 1
426+
ifconfig "$iface" up
427+
sleep "$sleep_sec"
428+
if ifconfig "$iface" | grep -q "UP"; then
429+
return 0
430+
fi
431+
fi
432+
i=$((i + 1))
433+
done
434+
return 1
435+
}

0 commit comments

Comments
 (0)