Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 line
1.5KB

  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. updated, err := mgr.ApplyConfig(ConfigUpdate{
  14. CenterHz: &center,
  15. SampleRate: &sampleRate,
  16. FFTSize: &fftSize,
  17. Detector: &DetectorUpdate{
  18. ThresholdDb: &threshold,
  19. },
  20. })
  21. if err != nil {
  22. t.Fatalf("apply: %v", err)
  23. }
  24. if updated.CenterHz != center {
  25. t.Fatalf("center hz: %v", updated.CenterHz)
  26. }
  27. if updated.SampleRate != sampleRate {
  28. t.Fatalf("sample rate: %v", updated.SampleRate)
  29. }
  30. if updated.FFTSize != fftSize {
  31. t.Fatalf("fft size: %v", updated.FFTSize)
  32. }
  33. if updated.Detector.ThresholdDb != threshold {
  34. t.Fatalf("threshold: %v", updated.Detector.ThresholdDb)
  35. }
  36. }
  37. func TestApplyConfigRejectsInvalid(t *testing.T) {
  38. cfg := config.Default()
  39. mgr := New(cfg)
  40. bad := 0
  41. if _, err := mgr.ApplyConfig(ConfigUpdate{SampleRate: &bad}); err == nil {
  42. t.Fatalf("expected error")
  43. }
  44. snap := mgr.Snapshot()
  45. if snap.SampleRate != cfg.SampleRate {
  46. t.Fatalf("sample rate changed on error")
  47. }
  48. }
  49. func TestApplySettings(t *testing.T) {
  50. cfg := config.Default()
  51. mgr := New(cfg)
  52. agc := true
  53. dc := true
  54. iq := true
  55. updated, err := mgr.ApplySettings(SettingsUpdate{
  56. AGC: &agc,
  57. DCBlock: &dc,
  58. IQBalance: &iq,
  59. })
  60. if err != nil {
  61. t.Fatalf("apply settings: %v", err)
  62. }
  63. if !updated.AGC || !updated.DCBlock || !updated.IQBalance {
  64. t.Fatalf("settings not applied: %+v", updated)
  65. }
  66. }