@@ -36,57 +36,101 @@ test_path=$(find_test_case_by_name "$TESTNAME") || {
36
36
cd " $test_path " || exit 1
37
37
res_file=" ./$TESTNAME .res"
38
38
rm -f " $res_file "
39
+ summary_file=" ./$TESTNAME .summary"
40
+ rm -f " $res_file " " $summary_file "
39
41
40
42
log_info " --------------------------------------------------------------------------"
41
43
log_info " -------------------Starting $TESTNAME Testcase----------------------------"
42
-
44
+
45
+ # Check for dependencies
43
46
check_dependencies ip ping
44
-
45
- IFACE=" eth0"
47
+
46
48
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
49
+ SLEEP_SEC=2
50
+
51
+ user_iface=" $1 "
52
+ iface_list=" "
53
+ if [ -n " $user_iface " ]; then
54
+ iface_list=" $user_iface "
55
+ log_info " User specified interface: $user_iface "
56
+ else
57
+ iface_list=$( get_ethernet_interfaces)
58
+ log_info " Enumerating all detected Ethernet interfaces: $iface_list "
54
59
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
60
+
61
+ pass_count=0
62
+ fail_count=0
63
+ skip_count=0
64
+
65
+ for iface in $iface_list ; do
66
+ log_info " ---- Testing interface: $iface ----"
67
+ if ! is_link_up " $iface " ; then
68
+ log_warn " No cable detected or carrier not present on $iface . Skipping."
69
+ echo " $iface : SKIP (no cable)" >> " $summary_file "
70
+ skip_count=$(( skip_count + 1 ))
71
+ continue
72
+ fi
73
+
74
+ if ! bringup_interface " $iface " " $RETRIES " " $SLEEP_SEC " ; then
75
+ log_fail " Failed to bring up $iface after $RETRIES attempts"
76
+ echo " $iface : FAIL (up failed)" >> " $summary_file "
77
+ fail_count=$(( fail_count + 1 ))
78
+ continue
79
+ fi
80
+ log_pass " $iface is UP"
81
+
82
+ # Try DHCP client if present (optional)
83
+ if ! wait_for_ip_address " $iface " 10 > /dev/null; then
84
+ if command -v dhclient > /dev/null 2>&1 ; then
85
+ log_info " Trying dhclient for $iface "
86
+ dhclient " $iface "
87
+ sleep 2
88
+ elif command -v udhcpc > /dev/null 2>&1 ; then
89
+ log_info " Trying udhcpc for $iface "
90
+ udhcpc -i " $iface "
91
+ sleep 2
92
+ fi
93
+ fi
94
+
95
+ ip_addr=$( wait_for_ip_address " $iface " 10)
96
+ if [ -z " $ip_addr " ]; then
97
+ log_fail " $iface did not get IP address"
98
+ echo " $iface : FAIL (no IP)" >> " $summary_file "
99
+ fail_count=$(( fail_count + 1 ))
100
+ continue
101
+ fi
102
+ log_pass " $iface got IP address: $ip_addr "
103
+
104
+ i=0
105
+ ping_success=0
106
+ while [ $i -lt $RETRIES ]; do
107
+ if ping -I " $iface " -c 3 -W 2 8.8.8.8 > /dev/null 2>&1 ; then
108
+ log_pass " $iface : Ethernet connectivity verified via ping"
109
+ echo " $iface : PASS" >> " $summary_file "
110
+ pass_count=$(( pass_count + 1 ))
111
+ ping_success=1
112
+ break
113
+ fi
114
+ log_warn " $iface : Ping failed (attempt $(( i + 1 )) /$RETRIES )... retrying"
115
+ sleep " $SLEEP_SEC "
116
+ i=$(( i + 1 ))
117
+ done
118
+ if [ $ping_success -eq 0 ]; then
119
+ log_fail " $iface : Ping test failed after $RETRIES attempts"
120
+ echo " $iface : FAIL (ping)" >> " $summary_file "
121
+ fail_count=$(( fail_count + 1 ))
65
122
fi
66
- log_warn " $IFACE is still DOWN (attempt $(( i + 1 )) /$RETRIES )..."
67
- i=$(( i + 1 ))
68
123
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 "
124
+
125
+ log_info " ---- Ethernet Interface Test Summary ----"
126
+ cat " $summary_file "
127
+
128
+ if [ $pass_count -gt 0 ]; then
129
+ log_pass " At least one interface PASS; overall PASS"
130
+ echo " $TESTNAME PASS" > " $res_file "
131
+ exit 0
132
+ else
133
+ log_fail " No interfaces passed connectivity test"
134
+ echo " $TESTNAME FAIL" > " $res_file "
73
135
exit 1
74
136
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