github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-verifier/exectask_test.go (about) 1 // Copyright 2022 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 main 5 6 import ( 7 "testing" 8 ) 9 10 func TestExecTask_MakeDelete(t *testing.T) { 11 program := getTestProgram(t) 12 taskFactory := MakeExecTaskFactory() 13 if l := taskFactory.ExecTasksQueued(); l != 0 { 14 t.Errorf("expected to see empty map, current size is %v", l) 15 } 16 task := taskFactory.MakeExecTask(program) 17 if l := taskFactory.ExecTasksQueued(); l != 1 { 18 t.Errorf("expected map len is 1, current size is %v", l) 19 } 20 taskFactory.DeleteExecTask(task) 21 if l := taskFactory.ExecTasksQueued(); l != 0 { 22 t.Errorf("expected map len is 0, current size is %v", l) 23 } 24 } 25 26 func TestExecTask_ToRPC(t *testing.T) { 27 program := getTestProgram(t) 28 taskFactory := MakeExecTaskFactory() 29 task := taskFactory.MakeExecTask(program) 30 if task.ToRPC() == nil { 31 t.Errorf("rpcView generation failed") 32 } 33 } 34 35 func TestGetExecResultChan(t *testing.T) { 36 taskFactory := MakeExecTaskFactory() 37 if l := taskFactory.ExecTasksQueued(); l != 0 { 38 t.Errorf("expected to see empty map, current size is %v", l) 39 } 40 ch := taskFactory.GetExecResultChan(100) 41 if l := taskFactory.ExecTasksQueued(); l != 0 { 42 t.Errorf("expected to see empty map, current size is %v", l) 43 } 44 if ch != nil { 45 t.Errorf("expected to see nil channel") 46 } 47 } 48 49 func TestExecTaskQueue_PushTask(t *testing.T) { 50 q := MakeExecTaskQueue() 51 if l := q.Len(); l != 0 { 52 t.Errorf("expected to see zero len, current is %v", l) 53 } 54 55 taskFactory := MakeExecTaskFactory() 56 q.PushTask(taskFactory.MakeExecTask(getTestProgram(t))) 57 if l := q.Len(); l != 1 { 58 t.Errorf("expected to see single element, current size is %v", l) 59 } 60 } 61 62 func TestExecTaskQueue_PopTask(t *testing.T) { 63 q := MakeExecTaskQueue() 64 task, gotResult := q.PopTask() 65 if task != nil || gotResult != false { 66 t.Errorf("empty queue operation error") 67 } 68 program := getTestProgram(t) 69 taskFactory := MakeExecTaskFactory() 70 q.PushTask(taskFactory.MakeExecTask(program)) 71 q.PushTask(taskFactory.MakeExecTask(program)) 72 q.PushTask(taskFactory.MakeExecTask(program)) 73 task, gotResult = q.PopTask() 74 if task == nil || gotResult == false { 75 t.Errorf("non-empty task or error was expected") 76 } 77 }