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