github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/fuzzer/queue/distributor_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/stretchr/testify/assert"
    10  )
    11  
    12  func TestDistributor(t *testing.T) {
    13  	q := Plain()
    14  	dist := Distribute(q)
    15  
    16  	req := &Request{}
    17  	q.Submit(req)
    18  	assert.Equal(t, req, dist.Next(0))
    19  
    20  	q.Submit(req)
    21  	assert.Equal(t, req, dist.Next(1))
    22  
    23  	// Avoid VM 0.
    24  	req.Avoid = []ExecutorID{{VM: 0}}
    25  	q.Submit(req)
    26  	var noReq *Request
    27  	assert.Equal(t, noReq, dist.Next(0))
    28  	assert.Equal(t, noReq, dist.Next(0))
    29  	assert.Equal(t, req, dist.Next(1))
    30  
    31  	// If only VM 0 queries requests, it should eventually got it.
    32  	q.Submit(req)
    33  	assert.Equal(t, noReq, dist.Next(0))
    34  	for {
    35  		got := dist.Next(0)
    36  		if got == req {
    37  			break
    38  		}
    39  		assert.Equal(t, noReq, got)
    40  	}
    41  
    42  	// If all active VMs are in the avoid set, then they should get
    43  	// the request immidiatly.
    44  	assert.Equal(t, noReq, dist.Next(1))
    45  	req.Avoid = []ExecutorID{{VM: 0}, {VM: 1}}
    46  	q.Submit(req)
    47  	assert.Equal(t, req, dist.Next(1))
    48  }