2018-04-06 16:46:49 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
2018-06-18 17:45:45 +00:00
|
|
|
"fmt"
|
2018-04-06 16:46:49 +00:00
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/syzkaller/prog"
|
|
|
|
_ "github.com/google/syzkaller/sys"
|
|
|
|
)
|
|
|
|
|
2018-06-12 12:05:02 +00:00
|
|
|
func TestDetectSupportedSyscalls(t *testing.T) {
|
2018-06-19 12:33:56 +00:00
|
|
|
// Note: this test is not parallel because it modifies global testFallback var.
|
2018-06-18 17:45:45 +00:00
|
|
|
for _, fallback := range []bool{false, true} {
|
|
|
|
t.Run(fmt.Sprintf("fallback=%v", fallback), func(t *testing.T) {
|
|
|
|
oldFallback := testFallback
|
|
|
|
testFallback = fallback
|
|
|
|
defer func() { testFallback = oldFallback }()
|
|
|
|
target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Dump for manual inspection.
|
|
|
|
supp, disabled, err := DetectSupportedSyscalls(target, "none")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for c, ok := range supp {
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("map contains false value for %v", c.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Logf("unsupported:")
|
|
|
|
for c, reason := range disabled {
|
|
|
|
t.Logf("%v: %v", c.Name, reason)
|
|
|
|
}
|
|
|
|
_, disabled = target.TransitivelyEnabledCalls(supp)
|
|
|
|
t.Logf("\n\ntransitively unsupported:")
|
|
|
|
for c, reason := range disabled {
|
|
|
|
t.Logf("%v: %v", c.Name, reason)
|
|
|
|
}
|
|
|
|
})
|
2018-04-06 16:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-12 12:05:02 +00:00
|
|
|
|
|
|
|
func TestCheck(t *testing.T) {
|
|
|
|
t.Parallel()
|
2018-07-06 18:18:05 +00:00
|
|
|
target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
features, err := Check(target)
|
2018-06-12 12:05:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-11-15 10:42:18 +00:00
|
|
|
for _, feat := range features.Supported() {
|
2018-06-12 12:05:02 +00:00
|
|
|
t.Logf("%-24v: %v", feat.Name, feat.Reason)
|
|
|
|
}
|
|
|
|
}
|