aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-14 19:25:01 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-15 16:02:37 +0200
commit52a33fd516102a98d3753bf69417235b655a68dc (patch)
tree351ab73db934d3b4e4babbe27e8801c659f2631b /pkg/host
parent25f4fe0662f7f3b390d16b2e786f2ba0aa0293f1 (diff)
prog: remove default target and all global state
Now each prog function accepts the desired target explicitly. No global, implicit state involved. This is much cleaner and allows cross-OS/arch testing, etc.
Diffstat (limited to 'pkg/host')
-rw-r--r--pkg/host/host.go4
-rw-r--r--pkg/host/host_test.go24
2 files changed, 16 insertions, 12 deletions
diff --git a/pkg/host/host.go b/pkg/host/host.go
index 0fa66dfa4..993db175b 100644
--- a/pkg/host/host.go
+++ b/pkg/host/host.go
@@ -16,7 +16,7 @@ import (
)
// DetectSupportedSyscalls returns list on supported syscalls on host.
-func DetectSupportedSyscalls() (map[*prog.Syscall]bool, error) {
+func DetectSupportedSyscalls(target *prog.Target) (map[*prog.Syscall]bool, error) {
// There are 3 possible strategies:
// 1. Executes all syscalls with presumably invalid arguments and check for ENOprog.
// But not all syscalls are safe to execute. For example, pause will hang,
@@ -29,7 +29,7 @@ func DetectSupportedSyscalls() (map[*prog.Syscall]bool, error) {
kallsyms, _ := ioutil.ReadFile("/proc/kallsyms")
supported := make(map[*prog.Syscall]bool)
- for _, c := range prog.Syscalls {
+ for _, c := range target.Syscalls {
if isSupported(kallsyms, c) {
supported[c] = true
}
diff --git a/pkg/host/host_test.go b/pkg/host/host_test.go
index a9130c094..1c40335d7 100644
--- a/pkg/host/host_test.go
+++ b/pkg/host/host_test.go
@@ -12,19 +12,19 @@ import (
_ "github.com/google/syzkaller/sys"
)
-func init() {
- prog.SetDefaultTarget("linux", runtime.GOARCH)
-}
-
func TestLog(t *testing.T) {
t.Parallel()
+ target, err := prog.GetTarget("linux", runtime.GOARCH)
+ if err != nil {
+ t.Fatal(err)
+ }
// Dump for manual inspection.
- supp, err := DetectSupportedSyscalls()
+ supp, err := DetectSupportedSyscalls(target)
if err != nil {
t.Skipf("skipping: %v", err)
}
t.Logf("unsupported:")
- for _, c := range prog.Syscalls {
+ for _, c := range target.Syscalls {
s, ok := supp[c]
if ok && !s {
t.Fatalf("map contains false value")
@@ -33,9 +33,9 @@ func TestLog(t *testing.T) {
t.Logf("\t%v", c.Name)
}
}
- trans := prog.TransitivelyEnabledCalls(supp)
+ trans := target.TransitivelyEnabledCalls(supp)
t.Logf("transitively unsupported:")
- for _, c := range prog.Syscalls {
+ for _, c := range target.Syscalls {
s, ok := trans[c]
if ok && !s {
t.Fatalf("map contains false value")
@@ -48,7 +48,11 @@ func TestLog(t *testing.T) {
func TestSupportedSyscalls(t *testing.T) {
t.Parallel()
- supp, err := DetectSupportedSyscalls()
+ target, err := prog.GetTarget("linux", runtime.GOARCH)
+ if err != nil {
+ t.Fatal(err)
+ }
+ supp, err := DetectSupportedSyscalls(target)
if err != nil {
t.Skipf("skipping: %v", err)
}
@@ -64,7 +68,7 @@ func TestSupportedSyscalls(t *testing.T) {
"stat",
}
for _, name := range safe {
- c := prog.SyscallMap[name]
+ c := target.SyscallMap[name]
if c == nil {
t.Fatalf("can't find syscall '%v'", name)
}