aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/instance
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/instance.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index cc1b147f1..b3e24aace 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -27,11 +27,17 @@ import (
"github.com/google/syzkaller/vm"
)
-type Env struct {
+type BuilderTester interface {
+ BuildSyzkaller(string, string) error
+ BuildKernel(string, string, string, string, []byte) (string, error)
+ Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error)
+}
+
+type env struct {
cfg *mgrconfig.Config
}
-func NewEnv(cfg *mgrconfig.Config) (*Env, error) {
+func NewEnv(cfg *mgrconfig.Config) (BuilderTester, error) {
if !vm.AllowsOvercommit(cfg.Type) {
return nil, fmt.Errorf("test instances are not supported for %v VMs", cfg.Type)
}
@@ -47,13 +53,13 @@ func NewEnv(cfg *mgrconfig.Config) (*Env, error) {
if err := osutil.MkdirAll(cfg.Workdir); err != nil {
return nil, fmt.Errorf("failed to create tmp dir: %v", err)
}
- env := &Env{
+ env := &env{
cfg: cfg,
}
return env, nil
}
-func (env *Env) BuildSyzkaller(repo, commit string) error {
+func (env *env) BuildSyzkaller(repo, commit string) error {
cfg := env.cfg
srcIndex := strings.LastIndex(cfg.Syzkaller, "/src/")
if srcIndex == -1 {
@@ -82,7 +88,7 @@ func (env *Env) BuildSyzkaller(repo, commit string) error {
return nil
}
-func (env *Env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile string,
+func (env *env) BuildKernel(compilerBin, userspaceDir, cmdlineFile, sysctlFile string,
kernelConfig []byte) (string, error) {
cfg := env.cfg
imageDir := filepath.Join(cfg.Workdir, "image")
@@ -170,7 +176,7 @@ func (err *CrashError) Error() string {
// Test boots numVMs VMs, tests basic kernel operation, and optionally tests the provided reproducer.
// TestError is returned if there is a problem with kernel/image (crash, reboot loop, etc).
// CrashError is returned if the reproducer crashes kernel.
-func (env *Env) Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error) {
+func (env *env) Test(numVMs int, reproSyz, reproOpts, reproC []byte) ([]error, error) {
if err := mgrconfig.Complete(env.cfg); err != nil {
return nil, err
}