aboutsummaryrefslogtreecommitdiffstats
path: root/sys/openbsd/init_test.go
blob: 780fe3efb1928c1d1adaedb0abe7120fb5cbf3c6 (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
package openbsd_test

import (
	"fmt"
	"strings"
	"testing"

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

func TestSanitizeMknodCall(t *testing.T) {
	target, err := prog.GetTarget("openbsd", "amd64")
	if err != nil {
		t.Fatal(err)
	}
	tests := []struct {
		input  string
		output string
	}{
		{
			// major=22, minor=232
			`mknodat(0x0, 0x0, 0x0, 0x16e8)`,
			`mknodat(0x0, 0x0, 0x0, 0x202)`,
		},
		{
			// major=22, minor=232
			`mknod(0x0, 0x0, 0x16e8)`,
			`mknod(0x0, 0x0, 0x202)`,
		},
		{
			// major=22, minor=0
			`mknod(0x0, 0x0, 0x1600)`,
			`mknod(0x0, 0x0, 0x1600)`,
		},
	}
	for i, test := range tests {
		t.Run(fmt.Sprint(i), func(t *testing.T) {
			p, err := target.Deserialize([]byte(test.input), prog.Strict)
			if err != nil {
				t.Fatal(err)
			}
			got := strings.TrimSpace(string(p.Serialize()))
			want := strings.TrimSpace(test.output)
			if got != want {
				t.Fatalf("input:\n%v\ngot:\n%v\nwant:\n%s", test.input, got, want)
			}
		})
	}
}