aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host/host_test.go
blob: 6e977074466e77cd28f32c6b6c60dadd65d076c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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 (
	"fmt"
	"runtime"
	"testing"

	"github.com/google/syzkaller/prog"
	_ "github.com/google/syzkaller/sys"
)

func TestDetectSupportedSyscalls(t *testing.T) {
	// Note: this test is not parallel because it modifies global testFallback var.
	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)
			}
			enabled := make(map[*prog.Syscall]bool)
			for _, c := range target.Syscalls {
				enabled[c] = true
			}
			// Dump for manual inspection.
			supp, disabled, err := DetectSupportedSyscalls(target, "none", enabled)
			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)
			}
		})
	}
}

func TestCheck(t *testing.T) {
	t.Parallel()
	target, err := prog.GetTarget(runtime.GOOS, runtime.GOARCH)
	if err != nil {
		t.Fatal(err)
	}
	features, err := Check(target)
	if err != nil {
		t.Fatal(err)
	}
	for _, feat := range features.Supported() {
		t.Logf("%-24v: %v", feat.Name, feat.Reason)
	}
}