diff options
| author | Taras Madan <tarasmadan@google.com> | 2022-09-26 09:23:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 09:23:11 +0200 |
| commit | d59ba98314e02be939938f682fd67cd68bbb3b68 (patch) | |
| tree | 27a44d1d8315577110c0c9e09fb825a386b6255b /vm/vm.go | |
| parent | 0042f2b4c00ce1ceeaa44a0147909fe3a6f86c5c (diff) | |
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
Diffstat (limited to 'vm/vm.go')
| -rw-r--r-- | vm/vm.go | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -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 |
