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
67
68
|
// Copyright 2017 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 mgrconfig_test
import (
"path/filepath"
"testing"
"github.com/google/syzkaller/pkg/config"
. "github.com/google/syzkaller/pkg/mgrconfig"
"github.com/google/syzkaller/vm/gce"
"github.com/google/syzkaller/vm/proxyapp"
"github.com/google/syzkaller/vm/qemu"
)
func TestCanned(t *testing.T) {
files, err := filepath.Glob(filepath.Join("testdata", "*.cfg"))
if err != nil || len(files) == 0 {
t.Fatalf("failed to read input files: %v", err)
}
for _, file := range files {
t.Run(file, func(t *testing.T) {
cfg, err := LoadFile(file)
if err != nil {
t.Fatal(err)
}
var vmCfg any
switch cfg.Type {
case "qemu":
vmCfg = new(qemu.Config)
case "gce":
vmCfg = new(gce.Config)
case "proxyapp":
vmCfg = new(proxyapp.Config)
default:
t.Fatalf("unknown VM type: %v", cfg.Type)
}
if err := config.LoadData(cfg.VM, vmCfg); err != nil {
t.Fatalf("failed to load %v config: %v", cfg.Type, err)
}
})
}
}
func TestMatchSyscall(t *testing.T) {
tests := []struct {
pattern string
call string
result bool
}{
{"foo", "foo", true},
{"foo", "bar", false},
{"foo", "foo$BAR", true},
{"foo*", "foo", true},
{"foo*", "foobar", true},
{"foo*", "foo$BAR", true},
{"foo$*", "foo", false},
{"foo$*", "foo$BAR", true},
}
for i, test := range tests {
res := MatchSyscall(test.call, test.pattern)
if res != test.result {
t.Errorf("#%v: pattern=%q call=%q want=%v got=%v",
i, test.pattern, test.call, test.result, res)
}
}
}
|