github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/fuzzer/queue/queue_test.go (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package queue 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/pkg/stats" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestPlainQueue(t *testing.T) { 14 val := stats.Create("v0", "desc0") 15 pq := PlainWithStat(val) 16 17 req1, req2, req3 := &Request{}, &Request{}, &Request{} 18 19 pq.Submit(req1) 20 assert.Equal(t, 1, val.Val()) 21 pq.Submit(req2) 22 assert.Equal(t, 2, val.Val()) 23 24 assert.Equal(t, req1, pq.Next()) 25 assert.Equal(t, 1, val.Val()) 26 27 assert.Equal(t, req2, pq.Next()) 28 assert.Equal(t, 0, val.Val()) 29 30 pq.Submit(req3) 31 assert.Equal(t, 1, val.Val()) 32 assert.Equal(t, req3, pq.Next()) 33 assert.Nil(t, pq.Next()) 34 } 35 36 func TestPrioQueue(t *testing.T) { 37 req1, req2, req3, req4 := 38 &Request{}, &Request{}, &Request{}, &Request{} 39 pq := DynamicOrder() 40 41 pq1 := pq.Append() 42 pq2 := pq.Append() 43 pq3 := pq.Append() 44 45 pq2.Submit(req2) 46 pq3.Submit(req3) 47 assert.Equal(t, req2, pq.Next()) 48 49 pq1.Submit(req1) 50 assert.Equal(t, req1, pq.Next()) 51 52 pq2.Submit(req4) 53 assert.Equal(t, req4, pq.Next()) 54 assert.Equal(t, req3, pq.Next()) 55 }