diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-05-03 13:12:00 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-05-16 15:38:27 +0000 |
| commit | 03820adaef911ce08278d95f034f134c3c0c852e (patch) | |
| tree | 57f87ce0f3dedda459fb1771d3b79ff96e0853bb /pkg/fuzzer/queue/prio_queue_test.go | |
| parent | ef5d53ed7e3c7d30481a88301f680e37a5cc4775 (diff) | |
pkg/fuzzer: use queue layers
Instead of relying on a fuzzer-internal priority queue, utilize
stackable layers of request-generating steps.
Move the functionality to a separate pkg/fuzzer/queue package.
The pkg/fuzzer/queue package can be reused to add extra processing
layers on top of the fuzzing and to combine machine checking and fuzzing
execution pipelines.
Diffstat (limited to 'pkg/fuzzer/queue/prio_queue_test.go')
| -rw-r--r-- | pkg/fuzzer/queue/prio_queue_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/fuzzer/queue/prio_queue_test.go b/pkg/fuzzer/queue/prio_queue_test.go new file mode 100644 index 000000000..a82886bdd --- /dev/null +++ b/pkg/fuzzer/queue/prio_queue_test.go @@ -0,0 +1,40 @@ +// 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 queue + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNextPriority(t *testing.T) { + first := priority{0} + second := first.next() + third := second.next() + assert.True(t, first.greaterThan(second)) + assert.True(t, second.greaterThan(third)) +} + +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})) + assert.True(t, priority{1}.greaterThan(priority{1, -1})) + assert.False(t, priority{1}.greaterThan(priority{1, 1})) + assert.True(t, priority{1, 0}.greaterThan(priority{1})) +} + +func TestPrioQueueOrder(t *testing.T) { + pq := priorityQueueOps[int]{} + pq.Push(1, priority{1}) + pq.Push(3, priority{3}) + pq.Push(2, priority{2}) + + assert.Equal(t, 3, pq.Pop()) + assert.Equal(t, 2, pq.Pop()) + assert.Equal(t, 1, pq.Pop()) + assert.Zero(t, pq.Pop()) + assert.Zero(t, pq.Len()) +} |
