Wideband autonomous SDR analysis engine forked from sdr-visual-suite
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

191 行
5.3KB

  1. package runtime
  2. import (
  3. "testing"
  4. "sdr-wideband-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. cfarMode := "OS"
  15. cfarWrap := true
  16. cfarGuard := 2
  17. cfarTrain := 12
  18. cfarRank := 18
  19. cfarScale := 5.5
  20. mode := "wideband-balanced"
  21. profile := "wideband-balanced"
  22. survFPS := 12
  23. displayBins := 1024
  24. displayFPS := 8
  25. maxRefJobs := 24
  26. updated, err := mgr.ApplyConfig(ConfigUpdate{
  27. CenterHz: &center,
  28. SampleRate: &sampleRate,
  29. FFTSize: &fftSize,
  30. TunerBwKHz: &bw,
  31. Pipeline: &PipelineUpdate{Mode: &mode, Profile: &profile},
  32. Surveillance: &SurveillanceUpdate{FrameRate: &survFPS, DisplayBins: &displayBins, DisplayFPS: &displayFPS},
  33. Resources: &ResourcesUpdate{MaxRefinementJobs: &maxRefJobs},
  34. Detector: &DetectorUpdate{
  35. ThresholdDb: &threshold,
  36. CFARMode: &cfarMode,
  37. CFARWrapAround: &cfarWrap,
  38. CFARGuardCells: &cfarGuard,
  39. CFARTrainCells: &cfarTrain,
  40. CFARRank: &cfarRank,
  41. CFARScaleDb: &cfarScale,
  42. },
  43. })
  44. if err != nil {
  45. t.Fatalf("apply: %v", err)
  46. }
  47. if updated.CenterHz != center {
  48. t.Fatalf("center hz: %v", updated.CenterHz)
  49. }
  50. if updated.SampleRate != sampleRate {
  51. t.Fatalf("sample rate: %v", updated.SampleRate)
  52. }
  53. if updated.FFTSize != fftSize {
  54. t.Fatalf("fft size: %v", updated.FFTSize)
  55. }
  56. if updated.Surveillance.AnalysisFFTSize != fftSize {
  57. t.Fatalf("analysis fft size: %v", updated.Surveillance.AnalysisFFTSize)
  58. }
  59. if updated.Detector.ThresholdDb != threshold {
  60. t.Fatalf("threshold: %v", updated.Detector.ThresholdDb)
  61. }
  62. if updated.Detector.CFARMode != cfarMode {
  63. t.Fatalf("cfar mode: %v", updated.Detector.CFARMode)
  64. }
  65. if updated.Detector.CFARWrapAround != cfarWrap {
  66. t.Fatalf("cfar wrap: %v", updated.Detector.CFARWrapAround)
  67. }
  68. if updated.Detector.CFARGuardCells != cfarGuard {
  69. t.Fatalf("cfar guard: %v", updated.Detector.CFARGuardCells)
  70. }
  71. if updated.Detector.CFARTrainCells != cfarTrain {
  72. t.Fatalf("cfar train: %v", updated.Detector.CFARTrainCells)
  73. }
  74. if updated.Detector.CFARRank != cfarRank {
  75. t.Fatalf("cfar rank: %v", updated.Detector.CFARRank)
  76. }
  77. if updated.Detector.CFARScaleDb != cfarScale {
  78. t.Fatalf("cfar scale: %v", updated.Detector.CFARScaleDb)
  79. }
  80. if updated.TunerBwKHz != bw {
  81. t.Fatalf("tuner bw: %v", updated.TunerBwKHz)
  82. }
  83. if updated.Pipeline.Mode != mode {
  84. t.Fatalf("pipeline mode: %v", updated.Pipeline.Mode)
  85. }
  86. if updated.Surveillance.FrameRate != survFPS || updated.FrameRate != survFPS {
  87. t.Fatalf("surveillance frame rate: %v / %v", updated.Surveillance.FrameRate, updated.FrameRate)
  88. }
  89. if updated.Resources.MaxRefinementJobs != maxRefJobs {
  90. t.Fatalf("max refinement jobs: %v", updated.Resources.MaxRefinementJobs)
  91. }
  92. if updated.Surveillance.DisplayBins != displayBins || updated.Surveillance.DisplayFPS != displayFPS {
  93. t.Fatalf("display settings not applied: bins=%d fps=%d", updated.Surveillance.DisplayBins, updated.Surveillance.DisplayFPS)
  94. }
  95. }
  96. func TestApplyConfigRejectsInvalid(t *testing.T) {
  97. cfg := config.Default()
  98. {
  99. mgr := New(cfg)
  100. bad := 0
  101. if _, err := mgr.ApplyConfig(ConfigUpdate{SampleRate: &bad}); err == nil {
  102. t.Fatalf("expected error")
  103. }
  104. snap := mgr.Snapshot()
  105. if snap.SampleRate != cfg.SampleRate {
  106. t.Fatalf("sample rate changed on error")
  107. }
  108. }
  109. {
  110. mgr := New(cfg)
  111. badAlpha := -0.5
  112. if _, err := mgr.ApplyConfig(ConfigUpdate{Detector: &DetectorUpdate{EmaAlpha: &badAlpha}}); err == nil {
  113. t.Fatalf("expected ema_alpha error")
  114. }
  115. if mgr.Snapshot().Detector.EmaAlpha != cfg.Detector.EmaAlpha {
  116. t.Fatalf("ema_alpha changed on error")
  117. }
  118. }
  119. {
  120. mgr := New(cfg)
  121. badAlpha := 1.5
  122. if _, err := mgr.ApplyConfig(ConfigUpdate{Detector: &DetectorUpdate{EmaAlpha: &badAlpha}}); err == nil {
  123. t.Fatalf("expected ema_alpha upper bound error")
  124. }
  125. if mgr.Snapshot().Detector.EmaAlpha != cfg.Detector.EmaAlpha {
  126. t.Fatalf("ema_alpha changed on error")
  127. }
  128. }
  129. {
  130. mgr := New(cfg)
  131. badHyst := -1.0
  132. if _, err := mgr.ApplyConfig(ConfigUpdate{Detector: &DetectorUpdate{HysteresisDb: &badHyst}}); err == nil {
  133. t.Fatalf("expected hysteresis_db error")
  134. }
  135. if mgr.Snapshot().Detector.HysteresisDb != cfg.Detector.HysteresisDb {
  136. t.Fatalf("hysteresis_db changed on error")
  137. }
  138. }
  139. {
  140. mgr := New(cfg)
  141. badStable := 0
  142. if _, err := mgr.ApplyConfig(ConfigUpdate{Detector: &DetectorUpdate{MinStableFrames: &badStable}}); err == nil {
  143. t.Fatalf("expected min_stable_frames error")
  144. }
  145. if mgr.Snapshot().Detector.MinStableFrames != cfg.Detector.MinStableFrames {
  146. t.Fatalf("min_stable_frames changed on error")
  147. }
  148. }
  149. {
  150. mgr := New(cfg)
  151. badGap := -10
  152. if _, err := mgr.ApplyConfig(ConfigUpdate{Detector: &DetectorUpdate{GapToleranceMs: &badGap}}); err == nil {
  153. t.Fatalf("expected gap_tolerance_ms error")
  154. }
  155. if mgr.Snapshot().Detector.GapToleranceMs != cfg.Detector.GapToleranceMs {
  156. t.Fatalf("gap_tolerance_ms changed on error")
  157. }
  158. }
  159. }
  160. func TestApplySettings(t *testing.T) {
  161. cfg := config.Default()
  162. mgr := New(cfg)
  163. agc := true
  164. dc := true
  165. iq := true
  166. updated, err := mgr.ApplySettings(SettingsUpdate{
  167. AGC: &agc,
  168. DCBlock: &dc,
  169. IQBalance: &iq,
  170. })
  171. if err != nil {
  172. t.Fatalf("apply settings: %v", err)
  173. }
  174. if !updated.AGC || !updated.DCBlock || !updated.IQBalance {
  175. t.Fatalf("settings not applied: %+v", updated)
  176. }
  177. }