Wideband autonomous SDR analysis engine forked from sdr-visual-suite
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

98 líneas
3.8KB

  1. package pipeline
  2. import (
  3. "strings"
  4. "testing"
  5. "time"
  6. )
  7. func TestDecisionQueueDropsByBudget(t *testing.T) {
  8. arbiter := NewArbiter()
  9. decisions := []SignalDecision{
  10. {Candidate: Candidate{ID: 1, SNRDb: 12}, ShouldRecord: true, ShouldAutoDecode: true},
  11. {Candidate: Candidate{ID: 2, SNRDb: 10}, ShouldRecord: true, ShouldAutoDecode: true},
  12. }
  13. budget := BudgetModel{
  14. Record: BudgetQueue{Max: 1},
  15. Decode: BudgetQueue{Max: 1},
  16. }
  17. stats := arbiter.ApplyDecisions(decisions, budget, time.Now(), Policy{DecisionHoldMs: 250})
  18. if stats.RecordDropped == 0 || stats.DecodeDropped == 0 {
  19. t.Fatalf("expected drops by budget, got %+v", stats)
  20. }
  21. allowed := 0
  22. for _, d := range decisions {
  23. if d.ShouldRecord || d.ShouldAutoDecode {
  24. allowed++
  25. continue
  26. }
  27. if !strings.HasPrefix(d.Reason, DecisionReasonQueueRecord) && !strings.HasPrefix(d.Reason, DecisionReasonQueueDecode) {
  28. t.Fatalf("unexpected decision reason: %s", d.Reason)
  29. }
  30. }
  31. if allowed != 1 {
  32. t.Fatalf("expected 1 decision allowed, got %d", allowed)
  33. }
  34. }
  35. func TestDecisionQueueEnforcesBudgets(t *testing.T) {
  36. decisions := []SignalDecision{
  37. {Candidate: Candidate{ID: 1, SNRDb: 5}, ShouldRecord: true, ShouldAutoDecode: true},
  38. {Candidate: Candidate{ID: 2, SNRDb: 15}, ShouldRecord: true, ShouldAutoDecode: true},
  39. {Candidate: Candidate{ID: 3, SNRDb: 10}, ShouldRecord: true, ShouldAutoDecode: false},
  40. }
  41. arbiter := NewArbiter()
  42. policy := Policy{SignalPriorities: []string{"digital"}, MaxRecordingStreams: 1, MaxDecodeJobs: 1}
  43. budget := BudgetModelFromPolicy(policy)
  44. stats := arbiter.ApplyDecisions(decisions, budget, time.Now(), policy)
  45. if stats.RecordSelected != 1 || stats.DecodeSelected != 1 {
  46. t.Fatalf("unexpected counts: record=%d decode=%d", stats.RecordSelected, stats.DecodeSelected)
  47. }
  48. if !decisions[1].ShouldRecord || !decisions[1].ShouldAutoDecode {
  49. t.Fatalf("expected highest SNR decision to remain allowed")
  50. }
  51. if decisions[0].ShouldRecord || decisions[0].ShouldAutoDecode {
  52. t.Fatalf("expected lowest SNR decision to be budgeted off")
  53. }
  54. if decisions[2].ShouldRecord {
  55. t.Fatalf("expected mid SNR decision to be budgeted off by record budget")
  56. }
  57. if decisions[1].RecordAdmission == nil || decisions[1].RecordAdmission.Class != AdmissionClassAdmit {
  58. t.Fatalf("expected admitted record admission, got %+v", decisions[1].RecordAdmission)
  59. }
  60. if decisions[0].RecordAdmission == nil || decisions[0].RecordAdmission.Class != AdmissionClassDefer {
  61. t.Fatalf("expected deferred record admission, got %+v", decisions[0].RecordAdmission)
  62. }
  63. }
  64. func TestDecisionQueueHoldKeepsSelection(t *testing.T) {
  65. arbiter := NewArbiter()
  66. policy := Policy{DecisionHoldMs: 500}
  67. budget := BudgetModel{Record: BudgetQueue{Max: 1}, Decode: BudgetQueue{Max: 1}}
  68. now := time.Now()
  69. decisions := []SignalDecision{
  70. {Candidate: Candidate{ID: 1, SNRDb: 5}, ShouldRecord: true, ShouldAutoDecode: true},
  71. {Candidate: Candidate{ID: 2, SNRDb: 15}, ShouldRecord: true, ShouldAutoDecode: true},
  72. }
  73. arbiter.ApplyDecisions(decisions, budget, now, policy)
  74. if !decisions[1].ShouldRecord || !decisions[1].ShouldAutoDecode {
  75. t.Fatalf("expected candidate 2 to be selected initially")
  76. }
  77. decisions = []SignalDecision{
  78. {Candidate: Candidate{ID: 1, SNRDb: 25}, ShouldRecord: true, ShouldAutoDecode: true},
  79. {Candidate: Candidate{ID: 2, SNRDb: 2}, ShouldRecord: true, ShouldAutoDecode: true},
  80. }
  81. arbiter.ApplyDecisions(decisions, budget, now.Add(100*time.Millisecond), policy)
  82. if !decisions[1].ShouldRecord || !decisions[1].ShouldAutoDecode {
  83. t.Fatalf("expected held candidate 2 to remain selected")
  84. }
  85. if decisions[0].ShouldRecord || decisions[0].ShouldAutoDecode {
  86. t.Fatalf("expected candidate 1 to remain queued behind hold")
  87. }
  88. if decisions[1].RecordAdmission == nil || decisions[1].RecordAdmission.Class != AdmissionClassHold {
  89. t.Fatalf("expected record admission hold class, got %+v", decisions[1].RecordAdmission)
  90. }
  91. }