@@ -36,57 +36,87 @@ test_path=$(find_test_case_by_name "$TESTNAME") || {
3636cd " $test_path " || exit 1
3737res_file=" ./$TESTNAME .res"
3838rm -f " $res_file "
39+ summary_file=" ./$TESTNAME .summary"
40+ rm -f " $res_file " " $summary_file "
3941
4042log_info " --------------------------------------------------------------------------"
4143log_info " -------------------Starting $TESTNAME Testcase----------------------------"
42-
44+
45+ # Check for dependencies
4346check_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
47+
48+ # User-specified interface (argument) or all detected
49+ # Accept user-preferred interface as argument
50+ user_iface=" $1 "
51+
52+ iface_passed=0
53+ iface_failed=0
54+ iface_skipped=0
55+ any_tested=0
56+
57+ # Get interfaces to test
58+ if [ -n " $user_iface " ]; then
59+ if is_ethernet_interface " $user_iface " ; then
60+ eth_ifaces=" $user_iface "
61+ log_info " User specified interface: $user_iface "
62+ else
63+ log_fail " User-specified interface '$user_iface ' is not a valid Ethernet interface"
64+ echo " $TESTNAME SKIP" > " $res_file "
65+ exit 0
66+ fi
67+ else
68+ eth_ifaces=" $( get_ethernet_interfaces) "
69+ log_info " Auto-detected Ethernet interfaces: $eth_ifaces "
5470fi
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
71+
72+ for iface in $eth_ifaces ; do
73+ log_info " ---- Testing interface: $iface ----"
74+ if ! is_interface_up " $iface " ; then
75+ log_warn " $iface is DOWN, skipping"
76+ echo " $iface : SKIP (down/no cable)" >> " $summary_file "
77+ iface_skipped=$(( iface_skipped+ 1 ))
78+ continue
79+ fi
80+
81+ # Get IP (avoid link-local)
82+ ip_addr=$( wait_for_ip_address " $iface " 10)
83+ if [ -z " $ip_addr " ]; then
84+ log_warn " $iface did not get a valid IP, skipping"
85+ echo " $iface : SKIP (no valid IP)" >> " $summary_file "
86+ iface_skipped=$(( iface_skipped+ 1 ))
87+ continue
88+ fi
89+ if echo " $ip_addr " | grep -q ' ^169\.254' ; then
90+ log_warn " $iface got only link-local IP ($ip_addr ), skipping"
91+ echo " $iface : SKIP (link-local only)" >> " $summary_file "
92+ iface_skipped=$(( iface_skipped+ 1 ))
93+ continue
94+ fi
95+ log_info " $iface got IP: $ip_addr "
96+ any_tested=1
97+
98+ # Ping test
99+ if ping -I " $iface " -c 4 -W 2 8.8.8.8 > /dev/null 2>&1 ; then
100+ log_pass " $iface connectivity verified via ping"
101+ echo " $iface : PASS" >> " $summary_file "
102+ iface_passed=$(( iface_passed+ 1 ))
103+ else
104+ log_fail " $iface ping test failed"
105+ echo " $iface : FAIL (ping failed)" >> " $summary_file "
106+ iface_failed=$(( iface_failed+ 1 ))
65107 fi
66- log_warn " $IFACE is still DOWN (attempt $(( i + 1 )) /$RETRIES )..."
67- i=$(( i + 1 ))
68108done
69-
70- if [ $i -eq $RETRIES ]; then
71- log_fail " Failed to bring up $IFACE after $RETRIES attempts"
72- echo " FAIL $TESTNAME " > " $res_file "
109+
110+ log_info " ---- Ethernet Interface Test Summary ----"
111+ cat " $summary_file "
112+
113+ if [ " $iface_passed " -gt 0 ]; then
114+ echo " $TESTNAME PASS" > " $res_file "
115+ exit 0
116+ elif [ " $any_tested " -eq 1 ]; then
117+ echo " $TESTNAME FAIL" > " $res_file "
73118 exit 1
119+ else
120+ echo " $TESTNAME SKIP" > " $res_file "
121+ exit 0
74122fi
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