aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-29 09:57:18 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-30 13:33:18 +0100
commita142e60d5cf11dc798e4909c97803d75add83a11 (patch)
tree498344a05a38e63fee99f7d2a7485c6823129a24
parent229f64ce5eb21cc7b95a5642fbb6b12acf1f4cfc (diff)
pkg/mgrconfig: move derived fields into separate struct
Users should not be concerned with the internal derived fields. Move all derived fields into a separate struct before adding more. This leaves config.go as a better documentation for end users.
-rw-r--r--pkg/bisect/bisect_test.go10
-rw-r--r--pkg/build/netbsd.go20
-rw-r--r--pkg/mgrconfig/config.go11
-rw-r--r--pkg/mgrconfig/load.go13
-rw-r--r--pkg/report/fuzz.go6
-rw-r--r--pkg/report/linux_test.go6
-rw-r--r--pkg/report/report_test.go6
-rw-r--r--tools/syz-symbolize/symbolize.go12
-rw-r--r--tools/syz-testbuild/testbuild.go32
-rw-r--r--vm/vm_test.go12
10 files changed, 75 insertions, 53 deletions
diff --git a/pkg/bisect/bisect_test.go b/pkg/bisect/bisect_test.go
index 7d0c89c75..26e157aaa 100644
--- a/pkg/bisect/bisect_test.go
+++ b/pkg/bisect/bisect_test.go
@@ -127,10 +127,12 @@ func runBisection(t *testing.T, baseDir string, test BisectionTest) (*Result, er
Fix: test.fix,
Trace: trace,
Manager: mgrconfig.Config{
- TargetOS: targets.TestOS,
- TargetVMArch: targets.TestArch64,
- Type: "qemu",
- KernelSrc: baseDir,
+ Derived: mgrconfig.Derived{
+ TargetOS: targets.TestOS,
+ TargetVMArch: targets.TestArch64,
+ },
+ Type: "qemu",
+ KernelSrc: baseDir,
},
Kernel: KernelConfig{
Repo: baseDir,
diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go
index e0f4bcea0..e3019f2e3 100644
--- a/pkg/build/netbsd.go
+++ b/pkg/build/netbsd.go
@@ -101,15 +101,17 @@ func (ctx netbsd) copyKernelToDisk(targetArch, vmType, outputDir, kernel string)
}`
// Create config for booting the disk image.
cfg := &mgrconfig.Config{
- Workdir: outputDir,
- Image: filepath.Join(outputDir, "image"),
- SSHKey: filepath.Join(outputDir, "key"),
- SSHUser: "root",
- TargetOS: targets.NetBSD,
- TargetArch: targetArch,
- TargetVMArch: targetArch,
- Type: "qemu",
- VM: json.RawMessage([]byte(vmConfig)),
+ Workdir: outputDir,
+ Image: filepath.Join(outputDir, "image"),
+ SSHKey: filepath.Join(outputDir, "key"),
+ SSHUser: "root",
+ Type: "qemu",
+ VM: json.RawMessage([]byte(vmConfig)),
+ Derived: mgrconfig.Derived{
+ TargetOS: targets.NetBSD,
+ TargetArch: targetArch,
+ TargetVMArch: targetArch,
+ },
}
// Create a VM pool.
pool, err := vm.Create(cfg, false)
diff --git a/pkg/mgrconfig/config.go b/pkg/mgrconfig/config.go
index fc63bb20d..0fc7316e4 100644
--- a/pkg/mgrconfig/config.go
+++ b/pkg/mgrconfig/config.go
@@ -107,13 +107,6 @@ type Config struct {
// Parameters for concrete types are in Config type in vm/TYPE/TYPE.go, e.g. vm/qemu/qemu.go.
VM json.RawMessage `json:"vm"`
- // Implementation details beyond this point.
- // Parsed Target:
- TargetOS string `json:"-"`
- TargetArch string `json:"-"`
- TargetVMArch string `json:"-"`
- // Syzkaller binaries that we are going to use:
- SyzFuzzerBin string `json:"-"`
- SyzExecprogBin string `json:"-"`
- SyzExecutorBin string `json:"-"`
+ // Implementation details beyond this point. Filled after parsing.
+ Derived `json:"-"`
}
diff --git a/pkg/mgrconfig/load.go b/pkg/mgrconfig/load.go
index 7e2efe82d..a1bde9efa 100644
--- a/pkg/mgrconfig/load.go
+++ b/pkg/mgrconfig/load.go
@@ -17,6 +17,19 @@ import (
"github.com/google/syzkaller/sys/targets"
)
+// Derived config values that are handy to keep with the config, filled after reading user config.
+type Derived struct {
+ // Parsed Target:
+ TargetOS string
+ TargetArch string
+ TargetVMArch string
+
+ // Syzkaller binaries that we are going to use:
+ SyzFuzzerBin string
+ SyzExecprogBin string
+ SyzExecutorBin string
+}
+
func LoadData(data []byte) (*Config, error) {
cfg, err := LoadPartialData(data)
if err != nil {
diff --git a/pkg/report/fuzz.go b/pkg/report/fuzz.go
index f812f78eb..8952baf76 100644
--- a/pkg/report/fuzz.go
+++ b/pkg/report/fuzz.go
@@ -71,8 +71,10 @@ var fuzzReporters = func() map[string]Reporter {
continue
}
cfg := &mgrconfig.Config{
- TargetOS: os,
- TargetArch: targets.AMD64,
+ Derived: mgrconfig.Derived{
+ TargetOS: os,
+ TargetArch: targets.AMD64,
+ },
}
reporter, err := NewReporter(cfg)
if err != nil {
diff --git a/pkg/report/linux_test.go b/pkg/report/linux_test.go
index d1b343efe..7d1d20daa 100644
--- a/pkg/report/linux_test.go
+++ b/pkg/report/linux_test.go
@@ -14,8 +14,10 @@ import (
func TestLinuxIgnores(t *testing.T) {
cfg := &mgrconfig.Config{
- TargetOS: targets.Linux,
- TargetArch: targets.AMD64,
+ Derived: mgrconfig.Derived{
+ TargetOS: targets.Linux,
+ TargetArch: targets.AMD64,
+ },
}
reporter, err := NewReporter(cfg)
if err != nil {
diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go
index eebbb4c22..05883a21f 100644
--- a/pkg/report/report_test.go
+++ b/pkg/report/report_test.go
@@ -308,8 +308,10 @@ func forEachFile(t *testing.T, dir string, fn func(t *testing.T, reporter Report
continue // not implemented
}
cfg := &mgrconfig.Config{
- TargetOS: os,
- TargetArch: targets.AMD64,
+ Derived: mgrconfig.Derived{
+ TargetOS: os,
+ TargetArch: targets.AMD64,
+ },
}
reporter, err := NewReporter(cfg)
if err != nil {
diff --git a/tools/syz-symbolize/symbolize.go b/tools/syz-symbolize/symbolize.go
index 587a095bb..39973664d 100644
--- a/tools/syz-symbolize/symbolize.go
+++ b/tools/syz-symbolize/symbolize.go
@@ -34,11 +34,13 @@ func main() {
os.Exit(1)
}
cfg := &mgrconfig.Config{
- TargetOS: *flagOS,
- TargetArch: *flagArch,
- TargetVMArch: *flagArch,
- KernelObj: *flagKernelObj,
- KernelSrc: *flagKernelSrc,
+ Derived: mgrconfig.Derived{
+ TargetOS: *flagOS,
+ TargetArch: *flagArch,
+ TargetVMArch: *flagArch,
+ },
+ KernelObj: *flagKernelObj,
+ KernelSrc: *flagKernelSrc,
}
cfg.CompleteKernelDirs()
reporter, err := report.NewReporter(cfg)
diff --git a/tools/syz-testbuild/testbuild.go b/tools/syz-testbuild/testbuild.go
index f4c108a52..eae70e2ae 100644
--- a/tools/syz-testbuild/testbuild.go
+++ b/tools/syz-testbuild/testbuild.go
@@ -67,21 +67,23 @@ func main() {
}
defer os.RemoveAll(dir)
cfg := &mgrconfig.Config{
- Target: *flagOS + "/" + *flagArch,
- TargetOS: *flagOS,
- TargetArch: *flagArch,
- TargetVMArch: *flagArch,
- HTTP: ":0",
- Workdir: dir,
- KernelSrc: *flagKernelSrc,
- KernelObj: *flagKernelSrc,
- Syzkaller: *flagSyzkaller,
- Sandbox: *flagSandbox,
- SSHUser: "root",
- Procs: 1,
- Cover: false,
- Type: vmType,
- VM: json.RawMessage([]byte(fmt.Sprintf(`{ "count": %v, "cpu": 2, "mem": 2048 }`, numTests))),
+ Target: *flagOS + "/" + *flagArch,
+ HTTP: ":0",
+ Workdir: dir,
+ KernelSrc: *flagKernelSrc,
+ KernelObj: *flagKernelSrc,
+ Syzkaller: *flagSyzkaller,
+ Sandbox: *flagSandbox,
+ SSHUser: "root",
+ Procs: 1,
+ Cover: false,
+ Type: vmType,
+ VM: json.RawMessage([]byte(fmt.Sprintf(`{ "count": %v, "cpu": 2, "mem": 2048 }`, numTests))),
+ Derived: mgrconfig.Derived{
+ TargetOS: *flagOS,
+ TargetArch: *flagArch,
+ TargetVMArch: *flagArch,
+ },
}
if err := mgrconfig.Complete(cfg); err != nil {
fail(err)
diff --git a/vm/vm_test.go b/vm/vm_test.go
index 3c3a14aa3..c9a0fcf60 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -340,11 +340,13 @@ func testMonitorExecution(t *testing.T, test *Test) {
}
defer os.RemoveAll(dir)
cfg := &mgrconfig.Config{
- Workdir: dir,
- TargetOS: targets.Linux,
- TargetArch: targets.AMD64,
- TargetVMArch: targets.AMD64,
- Type: "test",
+ Derived: mgrconfig.Derived{
+ TargetOS: targets.Linux,
+ TargetArch: targets.AMD64,
+ TargetVMArch: targets.AMD64,
+ },
+ Workdir: dir,
+ Type: "test",
}
pool, err := Create(cfg, false)
if err != nil {