1// Copyright 2015 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4package host
5
6import (
7	"fmt"
8	"runtime"
9	"testing"
10
11	"github.com/google/syzkaller/prog"
12	_ "github.com/google/syzkaller/sys"
13)
14
15func TestDetectSupportedSyscalls(t *testing.T) {
16	// Note: this test is not parallel because it modifies global testFallback var.
17	for _, fallback := range []bool{false, true} {
18		t.Run(fmt.Sprintf("fallback=%v", fallback), func(t *testing.T) {
19			oldFallback := testFallback
20			testFallback = fallback
21			defer func() { testFallback = oldFallback }()
22			target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)
23			if err != nil {
24				t.Fatal(err)
25			}
26			// Dump for manual inspection.
27			supp, disabled, err := DetectSupportedSyscalls(target, "none")
28			if err != nil {
29				t.Fatal(err)
30			}
31			for c, ok := range supp {
32				if !ok {
33					t.Fatalf("map contains false value for %v", c.Name)
34				}
35			}
36			t.Logf("unsupported:")
37			for c, reason := range disabled {
38				t.Logf("%v: %v", c.Name, reason)
39			}
40			_, disabled = target.TransitivelyEnabledCalls(supp)
41			t.Logf("\n\ntransitively unsupported:")
42			for c, reason := range disabled {
43				t.Logf("%v: %v", c.Name, reason)
44			}
45		})
46	}
47}
48
49func TestCheck(t *testing.T) {
50	t.Parallel()
51	target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)
52	if err != nil {
53		t.Fatal(err)
54	}
55	features, err := Check(target)
56	if err != nil {
57		t.Fatal(err)
58	}
59	for _, feat := range features {
60		t.Logf("%-24v: %v", feat.Name, feat.Reason)
61	}
62}
63