Skip to content

Commit 6507951

Browse files
committed
test-driver: Remove sudo fallbacks and improve reload robustness
The test driver was silently falling back to sudo for privileged commands, masking permission issues and producing inconsistent results depending on the caller's sudo configuration. Additionally, the module reload sequence used a fixed sleep that was too short for firmware initialisation, causing subsequent interface-dependent checks to fail or produce misleading output when run immediately after reload. Remove the sudo fallback from all dmesg and iw invocations so that permission failures are surfaced explicitly and handled via the existing skip mechanism. Extend the reload wait logic to poll for the WiFi interface and then wait for NetworkManager reconnection, replacing the fixed three-second delay with bounded polling loops. Add progress messages throughout the main check sequence so the operator can follow long-running stages without assuming the script has hung. Signed-off-by: Javier Tia <floss@jetm.me>
1 parent adad40c commit 6507951

1 file changed

Lines changed: 61 additions & 12 deletions

File tree

test-driver.sh

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ check_module_source() {
157157
# ---------------------------------------------------------------------------
158158
check_firmware() {
159159
local dmesg_out=""
160-
dmesg_out="$(dmesg 2>/dev/null || sudo dmesg 2>/dev/null || true)"
160+
dmesg_out="$(dmesg 2>/dev/null || true)"
161161

162162
if [[ -z "$dmesg_out" ]]; then
163163
skip "dmesg not accessible (try with sudo)"
@@ -192,7 +192,7 @@ check_firmware() {
192192
# ---------------------------------------------------------------------------
193193
check_aspm() {
194194
local dmesg_out=""
195-
dmesg_out="$(dmesg 2>/dev/null || sudo dmesg 2>/dev/null || true)"
195+
dmesg_out="$(dmesg 2>/dev/null || true)"
196196

197197
if [[ -z "$dmesg_out" ]]; then
198198
skip "dmesg not accessible"
@@ -250,7 +250,7 @@ check_bt_usb() {
250250
# ---------------------------------------------------------------------------
251251
check_bt_firmware() {
252252
local dmesg_out=""
253-
dmesg_out="$(dmesg 2>/dev/null || sudo dmesg 2>/dev/null || true)"
253+
dmesg_out="$(dmesg 2>/dev/null || true)"
254254

255255
if [[ -z "$dmesg_out" ]]; then
256256
skip "dmesg not accessible"
@@ -515,10 +515,10 @@ check_scan() {
515515
fi
516516

517517
local scan_out=""
518-
scan_out="$(iw dev "$iface" scan 2>/dev/null || sudo iw dev "$iface" scan 2>/dev/null || true)"
518+
scan_out="$(iw dev "$iface" scan 2>&1 || true)"
519519

520-
if [[ -z "$scan_out" ]]; then
521-
skip "scan failed (interface down or needs sudo)"
520+
if [[ -z "$scan_out" ]] || echo "$scan_out" | has_match "Operation not permitted\|command failed"; then
521+
skip "scan failed (interface down or driver busy)"
522522
return
523523
fi
524524

@@ -663,7 +663,7 @@ check_data_path() {
663663
# ---------------------------------------------------------------------------
664664
check_errors() {
665665
local dmesg_out=""
666-
dmesg_out="$(dmesg 2>/dev/null || sudo dmesg 2>/dev/null || true)"
666+
dmesg_out="$(dmesg 2>/dev/null || true)"
667667

668668
if [[ -z "$dmesg_out" ]]; then
669669
skip "dmesg not accessible"
@@ -717,20 +717,52 @@ check_errors() {
717717
# Module reload (ensures we test installed DKMS build, not boot-time modules)
718718
# ---------------------------------------------------------------------------
719719
reload_modules() {
720-
# WiFi modules (order matters: leaf drivers first)
721720
local wifi_mods=(mt7925e mt7921e mt7925_common mt7921_common mt792x_lib mt76_connac_lib mt76)
722721
local bt_mods=(btusb btmtk)
723722

723+
echo "Reloading modules..."
724724
modprobe -r "${wifi_mods[@]}" 2>/dev/null || true
725725
modprobe -r "${bt_mods[@]}" 2>/dev/null || true
726726

727-
# Reload - kernel resolves DKMS vs built-in automatically
728727
modprobe mt7925e 2>/dev/null || true
729728
modprobe mt7921e 2>/dev/null || true
730729
modprobe btusb 2>/dev/null || true
731730

732-
# Let firmware init complete
733-
sleep 3
731+
echo "Waiting for firmware init..."
732+
sleep 5
733+
734+
# Wait for WiFi interface to appear (up to 10s)
735+
local iface="" waited=0
736+
while ((waited < 10)); do
737+
for dev_path in /sys/bus/pci/drivers/mt7925e/*/net/*; do
738+
if [[ -d "$dev_path" ]]; then
739+
iface="$(basename "$dev_path")"
740+
break 2
741+
fi
742+
done
743+
sleep 1
744+
waited=$((waited + 1))
745+
done
746+
747+
if [[ -z "$iface" ]]; then
748+
echo " WiFi interface not detected after ${waited}s"
749+
return
750+
fi
751+
752+
echo " WiFi interface: $iface"
753+
754+
# Wait for NetworkManager to reconnect (up to 30s)
755+
echo "Waiting for network reconnection..."
756+
waited=0
757+
while ((waited < 30)); do
758+
if iw dev "$iface" link 2>/dev/null | grep -q "Connected"; then
759+
echo " Connected after ${waited}s"
760+
return
761+
fi
762+
sleep 1
763+
waited=$((waited + 1))
764+
done
765+
echo " Not reconnected after ${waited}s (scan/connection checks may skip)"
734766
}
735767

736768
# ---------------------------------------------------------------------------
@@ -753,32 +785,49 @@ main() {
753785
iface="$(detect_interface)"
754786
fi
755787

788+
echo ""
789+
echo "Running checks..."
790+
756791
local pkg_ver kernel_ver pci_id
757792
local modules dkms_status mod_source firmware aspm_status
758793
local bt_usb bt_firmware bt_rfkill
759794
local eht_caps device_ready regulatory
760795
local scan_result conn_result data_result errors_result
761796

762-
# Gather results
797+
echo " Package and kernel..."
763798
pkg_ver="$(get_package_version)"
764799
kernel_ver="$(get_kernel_version)"
765800
pci_id="$(get_pci_id)"
801+
802+
echo " Modules and DKMS..."
766803
modules="$(check_modules)"
767804
dkms_status="$(check_dkms)"
768805
mod_source="$(check_module_source)"
806+
807+
echo " WiFi firmware and ASPM..."
769808
firmware="$(check_firmware)"
770809
aspm_status="$(check_aspm)"
810+
811+
echo " Bluetooth..."
771812
bt_usb="$(check_bt_usb)"
772813
bt_firmware="$(check_bt_firmware)"
773814
bt_rfkill="$(check_bt_rfkill)"
815+
816+
echo " WiFi capabilities..."
774817
eht_caps="$(check_eht_caps "$iface")"
775818
device_ready="$(check_device_ready "$iface")"
776819
regulatory="$(check_regulatory "$iface")"
820+
821+
echo " Scan, connection, data path..."
777822
scan_result="$(check_scan "$iface")"
778823
conn_result="$(check_connection "$iface")"
779824
data_result="$(check_data_path "$iface")"
825+
826+
echo " Checking dmesg for errors..."
780827
errors_result="$(check_errors)"
781828

829+
echo ""
830+
782831
# Count failures from output (FAIL_COUNT doesn't propagate from subshells)
783832
local report
784833
report=$(

0 commit comments

Comments
 (0)