aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/fuzzer/queue/queue_test.go
blob: a89ec0d3d37e2138e1ed699d3a44b4e022a43bda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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/google/syzkaller/pkg/stats"
	"github.com/stretchr/testify/assert"
)

func TestPlainQueue(t *testing.T) {
	val := stats.Create("v0", "desc0")
	pq := PlainWithStat(val)

	req1, req2, req3 := &Request{}, &Request{}, &Request{}

	pq.Submit(req1)
	assert.Equal(t, 1, val.Val())
	pq.Submit(req2)
	assert.Equal(t, 2, val.Val())

	assert.Equal(t, req1, pq.Next())
	assert.Equal(t, 1, val.Val())

	assert.Equal(t, req2, pq.Next())
	assert.Equal(t, 0, val.Val())

	pq.Submit(req3)
	assert.Equal(t, 1, val.Val())
	assert.Equal(t, req3, pq.Next())
	assert.Nil(t, pq.Next())
}

func TestPrioQueue(t *testing.T) {
	req1, req2, req3, req4 :=
		&Request{}, &Request{}, &Request{}, &Request{}
	pq := DynamicOrder()

	pq1 := pq.Append()
	pq2 := pq.Append()
	pq3 := pq.Append()

	pq2.Submit(req2)
	pq3.Submit(req3)
	assert.Equal(t, req2, pq.Next())

	pq1.Submit(req1)
	assert.Equal(t, req1, pq.Next())

	pq2.Submit(req4)
	assert.Equal(t, req4, pq.Next())
	assert.Equal(t, req3, pq.Next())
}