From d59ba98314e02be939938f682fd67cd68bbb3b68 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Mon, 26 Sep 2022 09:23:11 +0200 Subject: vm: add the proxyapp support (#3269) * vm: add pool.Close() support * vm: add proxyapp client implementation * vm/proxyapp: autogenerate mocks * vm/proxyapp: add proxyapp tests * pkg/mgrconfig: add proxyapp type tests --- vm/vm.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'vm/vm.go') diff --git a/vm/vm.go b/vm/vm.go index 61020b6ed..c56211081 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -11,8 +11,10 @@ package vm import ( "bytes" "fmt" + "io" "os" "path/filepath" + "sync/atomic" "time" "github.com/google/syzkaller/pkg/mgrconfig" @@ -30,16 +32,18 @@ import ( _ "github.com/google/syzkaller/vm/isolated" _ "github.com/google/syzkaller/vm/kvm" _ "github.com/google/syzkaller/vm/odroid" + _ "github.com/google/syzkaller/vm/proxyapp" _ "github.com/google/syzkaller/vm/qemu" _ "github.com/google/syzkaller/vm/vmm" _ "github.com/google/syzkaller/vm/vmware" ) type Pool struct { - impl vmimpl.Pool - workdir string - template string - timeouts targets.Timeouts + impl vmimpl.Pool + workdir string + template string + timeouts targets.Timeouts + activeCount int32 } type Instance struct { @@ -47,6 +51,7 @@ type Instance struct { workdir string timeouts targets.Timeouts index int + onClose func() } var ( @@ -123,14 +128,28 @@ func (pool *Pool) Create(index int) (*Instance, error) { os.RemoveAll(workdir) return nil, err } + atomic.AddInt32(&pool.activeCount, 1) return &Instance{ impl: impl, workdir: workdir, timeouts: pool.timeouts, index: index, + onClose: func() { atomic.AddInt32(&pool.activeCount, -1) }, }, nil } +// TODO: Integration or end-to-end testing is needed. +// https://github.com/google/syzkaller/pull/3269#discussion_r967650801 +func (pool *Pool) Close() error { + if pool.activeCount != 0 { + panic("all the instances should be closed before pool.Close()") + } + if closer, ok := pool.impl.(io.Closer); ok { + return closer.Close() + } + return nil +} + func (inst *Instance) Copy(hostSrc string) (string, error) { return inst.impl.Copy(hostSrc) } @@ -161,6 +180,7 @@ func (inst *Instance) diagnose(rep *report.Report) ([]byte, bool) { func (inst *Instance) Close() { inst.impl.Close() os.RemoveAll(inst.workdir) + inst.onClose() } type ExitCondition int -- cgit mrf-deployment