mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 08:01:10 +00:00
SIM swap can leave qmi_wwan/qmi-proxy holding a dead cdc-wdm session while AT still works. Recovery then kept allocating CTL clients on that wedged port. Prefer AT IMEI during rescan, skip startup UIM reset when the card is already ready, and if CTL allocate times out twice with AT alive, USB-reset only that modem.
103 lines
3.2 KiB
Go
103 lines
3.2 KiB
Go
package device
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yibaiba/hideck/internal/backend"
|
|
"github.com/yibaiba/hideck/internal/config"
|
|
)
|
|
|
|
func TestSuppressQMIUnhealthyEvictionDuringLifecycleRecovery(t *testing.T) {
|
|
pool := NewPool(&config.Config{})
|
|
worker := &Worker{
|
|
ID: "dev1",
|
|
Config: config.DeviceConfig{
|
|
ID: "dev1",
|
|
DeviceBackend: backend.BackendQMI,
|
|
ControlDevice: "/dev/cdc-wdm0",
|
|
},
|
|
Backend: &workerStatusBackendStub{mode: backend.BackendQMI, opModeErr: errBackendUnavailable{}},
|
|
}
|
|
pool.workers["dev1"] = worker
|
|
pool.lifecycle.BeginRecovery("dev1", LifecyclePhaseQMIStarting, "modem_reboot", qmiLifecycleRecoveryTTL)
|
|
|
|
suppressed, reason := pool.suppressQMIUnhealthyEviction(worker)
|
|
if !suppressed {
|
|
t.Fatal("expected lifecycle recovery to suppress eviction")
|
|
}
|
|
if !strings.Contains(reason, "lifecycle_qmi_starting") {
|
|
t.Fatalf("reason=%q want contains lifecycle_qmi_starting", reason)
|
|
}
|
|
}
|
|
|
|
func TestSuppressQMIUnhealthyEvictionAfterLifecycleDeadline(t *testing.T) {
|
|
pool := NewPool(&config.Config{})
|
|
worker := &Worker{
|
|
ID: "dev1",
|
|
Config: config.DeviceConfig{
|
|
ID: "dev1",
|
|
DeviceBackend: backend.BackendQMI,
|
|
ControlDevice: "/dev/cdc-wdm0",
|
|
},
|
|
Backend: &workerStatusBackendStub{mode: backend.BackendQMI, opModeErr: errBackendUnavailable{}},
|
|
}
|
|
now := time.Now().Add(-2 * qmiLifecycleRecoveryTTL)
|
|
pool.lifecycle.BeginRecoveryAt("dev1", LifecyclePhaseRecovering, "modem_reboot", now, time.Second)
|
|
|
|
suppressed, reason := pool.suppressQMIUnhealthyEviction(worker)
|
|
if suppressed {
|
|
t.Fatalf("suppressed=true want false reason=%q", reason)
|
|
}
|
|
}
|
|
|
|
func TestSuppressQMIUnhealthyEvictionWhileUSBUnstick(t *testing.T) {
|
|
pool := NewPool(&config.Config{})
|
|
worker := &Worker{
|
|
ID: "dev1",
|
|
Config: config.DeviceConfig{
|
|
ID: "dev1",
|
|
DeviceBackend: backend.BackendQMI,
|
|
ControlDevice: "/dev/cdc-wdm0",
|
|
},
|
|
Backend: &workerStatusBackendStub{mode: backend.BackendQMI, opModeErr: errBackendUnavailable{}},
|
|
}
|
|
worker.markQMIUSBUnsticking(time.Minute)
|
|
suppressed, reason := pool.suppressQMIUnhealthyEviction(worker)
|
|
if !suppressed {
|
|
t.Fatal("expected USB unstick to suppress eviction")
|
|
}
|
|
if reason != "qmi_usb_unstick" {
|
|
t.Fatalf("reason=%q want qmi_usb_unstick", reason)
|
|
}
|
|
}
|
|
|
|
func TestSuppressQMIUnhealthyEvictionWhileQMICoreStarting(t *testing.T) {
|
|
pool := NewPool(&config.Config{})
|
|
worker := &Worker{
|
|
ID: "dev1",
|
|
Config: config.DeviceConfig{
|
|
ID: "dev1",
|
|
DeviceBackend: backend.BackendQMI,
|
|
ControlDevice: "/dev/cdc-wdm0",
|
|
},
|
|
Backend: &workerStatusBackendStub{mode: backend.BackendQMI, opModeErr: errBackendUnavailable{}},
|
|
}
|
|
worker.markQMICoreStarting()
|
|
now := time.Now().Add(-2 * qmiLifecycleRecoveryTTL)
|
|
pool.lifecycle.BeginRecoveryAt("dev1", LifecyclePhaseQMIStarting, "qmi_start_core", now, time.Second)
|
|
|
|
suppressed, reason := pool.suppressQMIUnhealthyEviction(worker)
|
|
if !suppressed {
|
|
t.Fatal("expected qmi core starting to suppress eviction after lifecycle deadline")
|
|
}
|
|
if reason != "qmi_core_starting" {
|
|
t.Fatalf("reason=%q want qmi_core_starting", reason)
|
|
}
|
|
}
|
|
|
|
type errBackendUnavailable struct{}
|
|
|
|
func (errBackendUnavailable) Error() string { return "backend unavailable" }
|