github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/workflow/service.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 workflow 5 6 import ( 7 "sync" 8 "time" 9 ) 10 11 // Service is the interface for starting and managing the workflows that process individual patch series. 12 // The workflow includes steps like building base/patched kernel, dong boot tests, running fuzzing, etc. 13 // It's assumed that the workflow will query the necessary data and report its detailed progress itself, 14 // so we only need to be able to start it and to check its current overall state. 15 type Service interface { 16 Start(sessionID string) error 17 Status(id string) (Status, []byte, error) 18 // The recommended value. May depend on the implementation (test/prod). 19 PollPeriod() time.Duration 20 } 21 22 type Status string 23 24 const ( 25 StatusNotFound Status = "not_found" 26 StatusRunning Status = "running" 27 StatusFinished Status = "finished" 28 StatusFailed Status = "failed" 29 ) 30 31 // MockService serializes callback invocations to simplify test implementations. 32 type MockService struct { 33 mu sync.Mutex 34 PollDelayValue time.Duration 35 OnStart func(string) error 36 OnStatus func(string) (Status, []byte, error) 37 } 38 39 func (ms *MockService) Start(id string) error { 40 ms.mu.Lock() 41 defer ms.mu.Unlock() 42 if ms.OnStart != nil { 43 return ms.OnStart(id) 44 } 45 return nil 46 } 47 48 func (ms *MockService) Status(id string) (Status, []byte, error) { 49 ms.mu.Lock() 50 defer ms.mu.Unlock() 51 if ms.OnStatus != nil { 52 return ms.OnStatus(id) 53 } 54 return StatusNotFound, nil, nil 55 } 56 57 func (ms *MockService) PollPeriod() time.Duration { 58 return ms.PollDelayValue 59 }