From a2bdbd8c37841cc507a2ad59f25d90d6467e5858 Mon Sep 17 00:00:00 2001 From: Zubin Mithra Date: Tue, 8 Oct 2019 15:57:52 -0700 Subject: pkg/bisect: add initial testing support for cause bisection (note: incomplete change) Refactor existing code as follows: * Move reusable test utility functions from git_repo_test.go to pkg/vcs/test_util.go and make them exported. * Split Run() into Run()+runImpl(). * Change type of bisect.go:env.inst to `instance.BuilderTester`. Change usage inside syz-testbuild/testbuild.go accordingly. * Move most of linux.PreviousReleaseTags() into vcs/git.go as git.previousReleaseTags(). * Allow build.CompilerIdentity to be mocked. Introduce the following changes: * instance.BuilderTester is an interface with methods BuildSyzkaller() BuildKernel() Test() NewEnv() now returns this interface. * type testEnv implements instance.BuilderTester. * type testBuilder implements builder interface. Add a entry into table inside pkg/build/build.go:getBuilder() to return testBuilder object. --- pkg/instance/instance.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'pkg/instance') 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 } -- cgit mrf-deployment