From 6ca1eb5a578bb1421ad0f3dbde675eb34647e6d7 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 5 Jul 2024 15:41:55 +0200 Subject: all: transition to instance.Pool Rely on instance.Pool to perform fuzzing and do bug reproductions. Extract the reproduction queue logic to separate testable class. --- vm/vm.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'vm') diff --git a/vm/vm.go b/vm/vm.go index 40e2972f6..cc7c656cd 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -10,6 +10,7 @@ package vm import ( "bytes" + "context" "fmt" "io" "os" @@ -65,6 +66,15 @@ var ( _ InfraErrorer = vmimpl.InfraError{} ) +func ShutdownCtx() context.Context { + ctx, done := context.WithCancel(context.Background()) + go func() { + <-Shutdown + done() + }() + return ctx +} + type BootErrorer interface { BootError() (string, []byte) } @@ -191,7 +201,7 @@ const ( ExitError ) -type StopChan <-chan bool +type StopContext context.Context type InjectExecuting <-chan bool type OutputSize int @@ -202,7 +212,7 @@ type EarlyFinishCb func() // and the kernel console output. It detects kernel oopses in output, lost connections, hangs, etc. // Returns command+kernel output and a non-symbolized crash report (nil if no error happens). // Accepted options: -// - StopChan: stop channel can be used to prematurely stop the command +// - StopContext: the context to be used to prematurely stop the command // - ExitCondition: says which exit modes should be considered as errors/OK // - OutputSize: how much output to keep/return func (inst *Instance) Run(timeout time.Duration, reporter *report.Reporter, command string, opts ...any) ( @@ -216,8 +226,13 @@ func (inst *Instance) Run(timeout time.Duration, reporter *report.Reporter, comm switch opt := o.(type) { case ExitCondition: exit = opt - case StopChan: - stop = opt + case StopContext: + stopCh := make(chan bool) + go func() { + <-opt.Done() + close(stopCh) + }() + stop = stopCh case OutputSize: outputSize = int(opt) case InjectExecuting: -- cgit mrf-deployment