From e6e35dba937599d098fc034eff2686e5ddc409e9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 26 Oct 2020 10:51:06 +0100 Subject: 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. --- pkg/report/fuzz.go | 7 ++++--- pkg/report/linux_test.go | 5 +++-- pkg/report/report.go | 16 ++++++++-------- pkg/report/report_test.go | 5 +++-- 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'pkg/report') diff --git a/pkg/report/fuzz.go b/pkg/report/fuzz.go index 0db602491..f812f78eb 100644 --- a/pkg/report/fuzz.go +++ b/pkg/report/fuzz.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/google/syzkaller/pkg/mgrconfig" + "github.com/google/syzkaller/sys/targets" ) func Fuzz(data []byte) int { @@ -32,7 +33,7 @@ func Fuzz(data []byte) int { if len(rep.Output) == 0 { panic(fmt.Sprintf("%v: len(Output) == 0", typ)) } - if os == "fuchsia" { + if os == targets.Fuchsia { // Fuchsia has Start/End/SkipPos set incorrectly because it symbolizes before parsing. continue } @@ -66,12 +67,12 @@ func Fuzz(data []byte) int { var fuzzReporters = func() map[string]Reporter { reporters := make(map[string]Reporter) for os := range ctors { - if os == "windows" { + if os == targets.Windows { continue } cfg := &mgrconfig.Config{ TargetOS: os, - TargetArch: "amd64", + 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 2e31ee755..d1b343efe 100644 --- a/pkg/report/linux_test.go +++ b/pkg/report/linux_test.go @@ -9,12 +9,13 @@ import ( "github.com/google/syzkaller/pkg/mgrconfig" "github.com/google/syzkaller/pkg/symbolizer" + "github.com/google/syzkaller/sys/targets" ) func TestLinuxIgnores(t *testing.T) { cfg := &mgrconfig.Config{ - TargetOS: "linux", - TargetArch: "amd64", + TargetOS: targets.Linux, + TargetArch: targets.AMD64, } reporter, err := NewReporter(cfg) if err != nil { diff --git a/pkg/report/report.go b/pkg/report/report.go index ae618d6e6..13f76e67d 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -132,14 +132,14 @@ const ( ) var ctors = map[string]fn{ - "akaros": ctorAkaros, - "linux": ctorLinux, - "gvisor": ctorGvisor, - "freebsd": ctorFreebsd, - "netbsd": ctorNetbsd, - "openbsd": ctorOpenbsd, - "fuchsia": ctorFuchsia, - "windows": ctorStub, + targets.Akaros: ctorAkaros, + targets.Linux: ctorLinux, + "gvisor": ctorGvisor, + targets.FreeBSD: ctorFreebsd, + targets.NetBSD: ctorNetbsd, + targets.OpenBSD: ctorOpenbsd, + targets.Fuchsia: ctorFuchsia, + targets.Windows: ctorStub, } type config struct { diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index 1545a44e9..eebbb4c22 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -16,6 +16,7 @@ import ( "github.com/google/syzkaller/pkg/mgrconfig" "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/sys/targets" ) var flagUpdate = flag.Bool("update", false, "update test files accordingly to current results") @@ -303,12 +304,12 @@ func testGuiltyFile(t *testing.T, reporter Reporter, fn string) { func forEachFile(t *testing.T, dir string, fn func(t *testing.T, reporter Reporter, fn string)) { for os := range ctors { - if os == "windows" { + if os == targets.Windows { continue // not implemented } cfg := &mgrconfig.Config{ TargetOS: os, - TargetArch: "amd64", + TargetArch: targets.AMD64, } reporter, err := NewReporter(cfg) if err != nil { -- cgit mrf-deployment