aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
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 /pkg
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.
Diffstat (limited to 'pkg')
-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
7 files changed, 44 insertions, 28 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 {