wl_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // wl_test.go — ParseWlWireless con la salida real capturada de un RT-AX92U
  2. // con Merlin (dhd: nl80211 ciego, wl lo sabe todo).
  3. package probe
  4. import "testing"
  5. const wlFixture = `==IF== wl1.1
  6. 04:d9:f5:27:76:04
  7. a
  8. target channel 48
  9. CHSPEC 48/80 (0xe32a)
  10. STA 48:B0:2D:03:B6:78 -73
  11. STA 00:41:0E:80:51:25 -52
  12. STA 38:B8:00:0A:24:37 -75
  13. ==IF== wl0.1
  14. 04:d9:f5:27:76:01
  15. b
  16. target channel 3
  17. CHSPEC 11 (0x100b)
  18. `
  19. func TestParseWlWireless(t *testing.T) {
  20. clients, radios := ParseWlWireless(wlFixture)
  21. if len(clients) != 3 {
  22. t.Fatalf("clientes: %d, want 3", len(clients))
  23. }
  24. tv, ok := clients["38:B8:00:0A:24:37"]
  25. if !ok || tv.Band != "5 GHz" || tv.SignalDbm != -75 {
  26. t.Fatalf("TV: %+v", tv)
  27. }
  28. if len(radios) != 2 {
  29. t.Fatalf("radios: %d, want 2", len(radios))
  30. }
  31. if radios[0].Name != "5 GHz" || radios[0].Channel != 48 || radios[0].WidthMhz != 80 || radios[0].BSSID != "04:D9:F5:27:76:04" || radios[0].Clients != 3 {
  32. t.Fatalf("radio 5G: %+v", radios[0])
  33. }
  34. if radios[1].Name != "2.4 GHz" || radios[1].Channel != 3 || radios[1].WidthMhz != 20 || radios[1].BSSID != "04:D9:F5:27:76:01" {
  35. t.Fatalf("radio 2.4G: %+v", radios[1])
  36. }
  37. }
  38. func TestParseWlWirelessGarbage(t *testing.T) {
  39. // rssi no numérico (estación yendo en este mismo instante): el cliente
  40. // se omite en vez de inventar señal; la radio igualmente se emite.
  41. out := `==IF== wl0.1
  42. 04:d9:f5:27:76:01
  43. b
  44. target channel 3
  45. STA AA:BB:CC:DD:EE:FF
  46. `
  47. clients, radios := ParseWlWireless(out)
  48. if len(clients) != 0 {
  49. t.Fatalf("clientes: %+v, want ninguno", clients)
  50. }
  51. if len(radios) != 1 || radios[0].Name != "2.4 GHz" || radios[0].Clients != 0 {
  52. t.Fatalf("radios: %+v", radios)
  53. }
  54. }
  55. func TestWlWidthMhz(t *testing.T) {
  56. cases := []struct {
  57. in string
  58. want int
  59. }{
  60. {"48/80 (0xe32a)", 80},
  61. {"11/40", 40},
  62. {"36/160 (0x1a2b)", 160},
  63. {"11 (0x100b)", 20},
  64. {"", 0},
  65. {"foo", 0},
  66. }
  67. for _, c := range cases {
  68. if got := wlWidthMhz(c.in); got != c.want {
  69. t.Fatalf("wlWidthMhz(%q)=%d, want %d", c.in, got, c.want)
  70. }
  71. }
  72. }
  73. func TestWlBandFromChannelFallback(t *testing.T) {
  74. if b := wlBand("ax", 3); b != "2.4 GHz" {
  75. t.Fatalf("canal 3: %q", b)
  76. }
  77. if b := wlBand("ax", 149); b != "5 GHz" {
  78. t.Fatalf("canal 149: %q", b)
  79. }
  80. if b := wlBand("", 0); b != "" {
  81. t.Fatalf("sin datos: %q, want vacío", b)
  82. }
  83. }