aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/instance
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-10-26 10:51:06 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-10-26 15:44:28 +0100
commite6e35dba937599d098fc034eff2686e5ddc409e9 (patch)
tree802be708d0bc84dee01b9285639690a53f1f6f94 /pkg/instance
parentd46bc75207fea1d7671c1277dd660cf1a4d7847b (diff)
sys/targets: add OS/Arch name consts
We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere.
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/instance.go4
-rw-r--r--pkg/instance/instance_test.go15
2 files changed, 11 insertions, 8 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index b5cbd3bd2..467998a60 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -318,7 +318,7 @@ func (inst *inst) testInstance() error {
}
}
- cmd := OldFuzzerCmd(fuzzerBin, executorCmd, "test", inst.cfg.TargetOS, inst.cfg.TargetArch, fwdAddr,
+ cmd := OldFuzzerCmd(fuzzerBin, executorCmd, targets.TestOS, inst.cfg.TargetOS, inst.cfg.TargetArch, fwdAddr,
inst.cfg.Sandbox, 0, inst.cfg.Cover, true)
outc, errc, err := inst.vm.Run(10*time.Minute, nil, cmd)
if err != nil {
@@ -470,7 +470,7 @@ func ExecprogCmd(execprog, executor, OS, arch, sandbox string, repeat, threaded,
}
var MakeBin = func() string {
- if runtime.GOOS == "freebsd" || runtime.GOOS == "openbsd" {
+ if runtime.GOOS == targets.FreeBSD || runtime.GOOS == targets.OpenBSD {
return "gmake"
}
return "make"
diff --git a/pkg/instance/instance_test.go b/pkg/instance/instance_test.go
index 5b9a28404..e19f91faf 100644
--- a/pkg/instance/instance_test.go
+++ b/pkg/instance/instance_test.go
@@ -9,6 +9,8 @@ import (
"runtime"
"strings"
"testing"
+
+ "github.com/google/syzkaller/sys/targets"
)
func TestFuzzerCmd(t *testing.T) {
@@ -29,7 +31,7 @@ func TestFuzzerCmd(t *testing.T) {
flagSandbox := flags.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace)")
flagDebug := flags.Bool("debug", false, "debug output from executor")
flagV := flags.Int("v", 0, "verbosity")
- cmdLine := OldFuzzerCmd(os.Args[0], "/myexecutor", "myname", "linux", "386", "localhost:1234",
+ cmdLine := OldFuzzerCmd(os.Args[0], "/myexecutor", "myname", targets.Linux, targets.I386, "localhost:1234",
"namespace", 3, true, true)
args := strings.Split(cmdLine, " ")[1:]
if err := flags.Parse(args); err != nil {
@@ -38,8 +40,8 @@ func TestFuzzerCmd(t *testing.T) {
if *flagName != "myname" {
t.Errorf("bad name: %q, want: %q", *flagName, "myname")
}
- if *flagArch != "386" {
- t.Errorf("bad arch: %q, want: %q", *flagArch, "386")
+ if *flagArch != targets.I386 {
+ t.Errorf("bad arch: %q, want: %q", *flagArch, targets.I386)
}
if *flagManager != "localhost:1234" {
t.Errorf("bad manager: %q, want: %q", *flagManager, "localhost:1234")
@@ -91,7 +93,8 @@ func TestExecprogCmd(t *testing.T) {
flagCollide := flags.Bool("collide", true, "collide syscalls to provoke data races")
flagSignal := flags.Bool("cover", false, "collect feedback signals (coverage)")
flagSandbox := flags.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace)")
- cmdLine := ExecprogCmd(os.Args[0], "/myexecutor", "freebsd", "386", "namespace", true, false, false, 7, 2, 3, "myprog")
+ cmdLine := ExecprogCmd(os.Args[0], "/myexecutor", targets.FreeBSD, targets.I386,
+ "namespace", true, false, false, 7, 2, 3, "myprog")
args := strings.Split(cmdLine, " ")[1:]
if err := flags.Parse(args); err != nil {
t.Fatal(err)
@@ -102,8 +105,8 @@ func TestExecprogCmd(t *testing.T) {
if *flagOS != runtime.GOOS {
t.Errorf("bad os: %q, want: %q", *flagOS, runtime.GOOS)
}
- if *flagArch != "386" {
- t.Errorf("bad arch: %q, want: %q", *flagArch, "386")
+ if *flagArch != targets.I386 {
+ t.Errorf("bad arch: %q, want: %q", *flagArch, targets.I386)
}
if *flagRepeat != 0 {
t.Errorf("bad repeat: %v, want: %v", *flagRepeat, 0)