Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

104 lignes
2.4KB

  1. package runtime
  2. import (
  3. "testing"
  4. "sdr-visual-suite/internal/config"
  5. )
  6. func TestApplyConfigUpdate(t *testing.T) {
  7. cfg := config.Default()
  8. mgr := New(cfg)
  9. center := 7.2e6
  10. sampleRate := 1_024_000
  11. fftSize := 4096
  12. threshold := -35.0
  13. bw := 1536
  14. cfarEnabled := true
  15. cfarGuard := 2
  16. cfarTrain := 12
  17. cfarRank := 18
  18. cfarScale := 5.5
  19. updated, err := mgr.ApplyConfig(ConfigUpdate{
  20. CenterHz: &center,
  21. SampleRate: &sampleRate,
  22. FFTSize: &fftSize,
  23. TunerBwKHz: &bw,
  24. Detector: &DetectorUpdate{
  25. ThresholdDb: &threshold,
  26. CFAREnabled: &cfarEnabled,
  27. CFARGuardCells: &cfarGuard,
  28. CFARTrainCells: &cfarTrain,
  29. CFARRank: &cfarRank,
  30. CFARScaleDb: &cfarScale,
  31. },
  32. })
  33. if err != nil {
  34. t.Fatalf("apply: %v", err)
  35. }
  36. if updated.CenterHz != center {
  37. t.Fatalf("center hz: %v", updated.CenterHz)
  38. }
  39. if updated.SampleRate != sampleRate {
  40. t.Fatalf("sample rate: %v", updated.SampleRate)
  41. }
  42. if updated.FFTSize != fftSize {
  43. t.Fatalf("fft size: %v", updated.FFTSize)
  44. }
  45. if updated.Detector.ThresholdDb != threshold {
  46. t.Fatalf("threshold: %v", updated.Detector.ThresholdDb)
  47. }
  48. if updated.Detector.CFAREnabled != cfarEnabled {
  49. t.Fatalf("cfar enabled: %v", updated.Detector.CFAREnabled)
  50. }
  51. if updated.Detector.CFARGuardCells != cfarGuard {
  52. t.Fatalf("cfar guard: %v", updated.Detector.CFARGuardCells)
  53. }
  54. if updated.Detector.CFARTrainCells != cfarTrain {
  55. t.Fatalf("cfar train: %v", updated.Detector.CFARTrainCells)
  56. }
  57. if updated.Detector.CFARRank != cfarRank {
  58. t.Fatalf("cfar rank: %v", updated.Detector.CFARRank)
  59. }
  60. if updated.Detector.CFARScaleDb != cfarScale {
  61. t.Fatalf("cfar scale: %v", updated.Detector.CFARScaleDb)
  62. }
  63. if updated.TunerBwKHz != bw {
  64. t.Fatalf("tuner bw: %v", updated.TunerBwKHz)
  65. }
  66. }
  67. func TestApplyConfigRejectsInvalid(t *testing.T) {
  68. cfg := config.Default()
  69. mgr := New(cfg)
  70. bad := 0
  71. if _, err := mgr.ApplyConfig(ConfigUpdate{SampleRate: &bad}); err == nil {
  72. t.Fatalf("expected error")
  73. }
  74. snap := mgr.Snapshot()
  75. if snap.SampleRate != cfg.SampleRate {
  76. t.Fatalf("sample rate changed on error")
  77. }
  78. }
  79. func TestApplySettings(t *testing.T) {
  80. cfg := config.Default()
  81. mgr := New(cfg)
  82. agc := true
  83. dc := true
  84. iq := true
  85. updated, err := mgr.ApplySettings(SettingsUpdate{
  86. AGC: &agc,
  87. DCBlock: &dc,
  88. IQBalance: &iq,
  89. })
  90. if err != nil {
  91. t.Fatalf("apply settings: %v", err)
  92. }
  93. if !updated.AGC || !updated.DCBlock || !updated.IQBalance {
  94. t.Fatalf("settings not applied: %+v", updated)
  95. }
  96. }