aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host/host_linux_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-20 15:38:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-20 21:19:29 +0200
commitc7ff68231e6c9a054fc3df9348262f376c7b91b4 (patch)
tree93ba24b964b6fbb62b6ea6cf0c81119047455c01 /pkg/host/host_linux_test.go
parentdc1c172fee85054f10955fc4975d0cea921f999f (diff)
pkg/host: add fuchsia support
Diffstat (limited to 'pkg/host/host_linux_test.go')
-rw-r--r--pkg/host/host_linux_test.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/pkg/host/host_linux_test.go b/pkg/host/host_linux_test.go
new file mode 100644
index 000000000..e32fe09cc
--- /dev/null
+++ b/pkg/host/host_linux_test.go
@@ -0,0 +1,86 @@
+// Copyright 2015 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// +build linux
+
+package host
+
+import (
+ "runtime"
+ "syscall"
+ "testing"
+
+ "github.com/google/syzkaller/prog"
+ _ "github.com/google/syzkaller/sys"
+)
+
+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(target)
+ if err != nil {
+ t.Skipf("skipping: %v", err)
+ }
+ t.Logf("unsupported:")
+ for _, c := range target.Syscalls {
+ s, ok := supp[c]
+ if ok && !s {
+ t.Fatalf("map contains false value")
+ }
+ if !s {
+ t.Logf("\t%v", c.Name)
+ }
+ }
+ trans := target.TransitivelyEnabledCalls(supp)
+ t.Logf("transitively unsupported:")
+ for _, c := range target.Syscalls {
+ s, ok := trans[c]
+ if ok && !s {
+ t.Fatalf("map contains false value")
+ }
+ if !s && supp[c] {
+ t.Logf("\t%v", c.Name)
+ }
+ }
+}
+
+func TestSupportedSyscalls(t *testing.T) {
+ t.Parallel()
+ 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)
+ }
+ // These are safe to execute with invalid arguments.
+ safe := []string{
+ "memfd_create",
+ "sendfile",
+ "bpf$MAP_CREATE",
+ "open",
+ "openat",
+ "read",
+ "write",
+ "stat",
+ }
+ for _, name := range safe {
+ c := target.SyscallMap[name]
+ if c == nil {
+ t.Fatalf("can't find syscall '%v'", name)
+ }
+ a := ^uintptr(0) - 4097 // hopefully invalid
+ _, _, err := syscall.Syscall6(uintptr(c.NR), a, a, a, a, a, a)
+ if err == 0 {
+ t.Fatalf("%v did not fail", name)
+ }
+ if ok := err != syscall.ENOSYS; ok != supp[c] {
+ t.Fatalf("syscall %v: perse=%v kallsyms=%v", name, ok, supp[c])
+ }
+ }
+}