aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/fuzzer/prio_queue_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-02-16 22:47:59 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-03-12 11:14:34 +0000
commitc35c26ec6312219507c518bae2e56c1ea46a5f36 (patch)
treece5b570187b5720857d7d1d38c4c399354f394bc /pkg/fuzzer/prio_queue_test.go
parent5d97b658d9c2ec0cd68e5632ce7f11bfe5d6c282 (diff)
pkg/fuzzer: factor out the fuzzing engine
This is the first step for #1541. Move the fuzzing engine that used to be interleaved with other syz-fuzzer code into a separate package. For now, the algorithm is more or less the same as it was, the only difference is that a pkg/fuzzer instance scales to the available computing power. Add an executor-based test that performs real fuzzing.
Diffstat (limited to 'pkg/fuzzer/prio_queue_test.go')
-rw-r--r--pkg/fuzzer/prio_queue_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/fuzzer/prio_queue_test.go b/pkg/fuzzer/prio_queue_test.go
new file mode 100644
index 000000000..b2abdb01b
--- /dev/null
+++ b/pkg/fuzzer/prio_queue_test.go
@@ -0,0 +1,44 @@
+// Copyright 2024 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package fuzzer
+
+import (
+ "sync"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPriority(t *testing.T) {
+ assert.True(t, priority{1, 2}.greaterThan(priority{1, 1}))
+ assert.True(t, priority{3, 2}.greaterThan(priority{2, 3}))
+ assert.True(t, priority{1, -5}.greaterThan(priority{1, -10}))
+}
+
+func TestPrioQueueOrder(t *testing.T) {
+ pq := makePriorityQueue[int]()
+ pq.push(&priorityQueueItem[int]{value: 1, prio: priority{1}})
+ pq.push(&priorityQueueItem[int]{value: 3, prio: priority{3}})
+ pq.push(&priorityQueueItem[int]{value: 2, prio: priority{2}})
+
+ assert.Equal(t, 3, pq.pop().value)
+ assert.Equal(t, 2, pq.pop().value)
+ assert.Equal(t, 1, pq.pop().value)
+ assert.Nil(t, pq.tryPop())
+}
+
+func TestPrioQueueWait(t *testing.T) {
+ var wg sync.WaitGroup
+ pq := makePriorityQueue[int]()
+ assert.Nil(t, pq.tryPop())
+
+ wg.Add(1)
+ go func() {
+ assert.Equal(t, 10, pq.pop().value)
+ wg.Done()
+ }()
+
+ pq.push(&priorityQueueItem[int]{value: 10, prio: priority{1}})
+ wg.Wait()
+}