From c35c26ec6312219507c518bae2e56c1ea46a5f36 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 16 Feb 2024 22:47:59 +0100 Subject: 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. --- pkg/fuzzer/prio_queue_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pkg/fuzzer/prio_queue_test.go (limited to 'pkg/fuzzer/prio_queue_test.go') 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() +} -- cgit mrf-deployment