github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/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/flatrpc" 10 "github.com/google/syzkaller/prog" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestPlainQueue(t *testing.T) { 15 pq := Plain() 16 17 req1, req2, req3 := &Request{}, &Request{}, &Request{} 18 19 pq.Submit(req1) 20 pq.Submit(req2) 21 assert.Equal(t, req1, pq.Next()) 22 assert.Equal(t, req2, pq.Next()) 23 pq.Submit(req3) 24 assert.Equal(t, req3, pq.Next()) 25 assert.Nil(t, pq.Next()) 26 } 27 28 func TestPrioQueue(t *testing.T) { 29 req1, req2, req3, req4 := 30 &Request{}, &Request{}, &Request{}, &Request{} 31 pq := DynamicOrder() 32 33 pq1 := pq.Append() 34 pq2 := pq.Append() 35 pq3 := pq.Append() 36 37 pq2.Submit(req2) 38 pq3.Submit(req3) 39 assert.Equal(t, req2, pq.Next()) 40 41 pq1.Submit(req1) 42 assert.Equal(t, req1, pq.Next()) 43 44 pq2.Submit(req4) 45 assert.Equal(t, req4, pq.Next()) 46 assert.Equal(t, req3, pq.Next()) 47 } 48 49 func TestGlobFiles(t *testing.T) { 50 r := &Result{} 51 assert.Equal(t, r.GlobFiles(), []string(nil)) 52 r.Output = []byte{'a', 'b', 0, 'c', 0} 53 assert.Equal(t, r.GlobFiles(), []string{"ab", "c"}) 54 } 55 56 func TestTee(t *testing.T) { 57 base, dup := Plain(), Plain() 58 59 tee := Tee(base, dup) 60 req := &Request{ 61 Prog: &prog.Prog{}, 62 Type: flatrpc.RequestTypeProgram, 63 ExecOpts: flatrpc.ExecOpts{SandboxArg: 10}, 64 BinaryFile: "file", 65 GlobPattern: "pattern", 66 // These must be ignored. 67 ReturnOutput: true, 68 Important: true, 69 } 70 base.Submit(req) 71 72 origReq := tee.Next() 73 assert.Equal(t, req, origReq) 74 copy := dup.Next() 75 assert.Equal(t, req.Type, copy.Type) 76 assert.Equal(t, req.ExecOpts, copy.ExecOpts) 77 assert.Equal(t, req.BinaryFile, copy.BinaryFile) 78 assert.Equal(t, req.GlobPattern, copy.GlobPattern) 79 assert.Empty(t, copy.ReturnOutput) 80 assert.Empty(t, copy.Important) 81 }