github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/mgrconfig/mgrconfig_test.go (about) 1 // Copyright 2017 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 4 package mgrconfig_test 5 6 import ( 7 "path/filepath" 8 "testing" 9 10 "github.com/google/syzkaller/pkg/config" 11 . "github.com/google/syzkaller/pkg/mgrconfig" 12 "github.com/google/syzkaller/vm/gce" 13 "github.com/google/syzkaller/vm/proxyapp" 14 "github.com/google/syzkaller/vm/qemu" 15 ) 16 17 func TestCanned(t *testing.T) { 18 files, err := filepath.Glob(filepath.Join("testdata", "*.cfg")) 19 if err != nil || len(files) == 0 { 20 t.Fatalf("failed to read input files: %v", err) 21 } 22 for _, file := range files { 23 t.Run(file, func(t *testing.T) { 24 cfg, err := LoadFile(file) 25 if err != nil { 26 t.Fatal(err) 27 } 28 var vmCfg interface{} 29 switch cfg.Type { 30 case "qemu": 31 vmCfg = new(qemu.Config) 32 case "gce": 33 vmCfg = new(gce.Config) 34 case "proxyapp": 35 vmCfg = new(proxyapp.Config) 36 default: 37 t.Fatalf("unknown VM type: %v", cfg.Type) 38 } 39 if err := config.LoadData(cfg.VM, vmCfg); err != nil { 40 t.Fatalf("failed to load %v config: %v", cfg.Type, err) 41 } 42 }) 43 } 44 } 45 46 func TestMatchSyscall(t *testing.T) { 47 tests := []struct { 48 pattern string 49 call string 50 result bool 51 }{ 52 {"foo", "foo", true}, 53 {"foo", "bar", false}, 54 {"foo", "foo$BAR", true}, 55 {"foo*", "foo", true}, 56 {"foo*", "foobar", true}, 57 {"foo*", "foo$BAR", true}, 58 {"foo$*", "foo", false}, 59 {"foo$*", "foo$BAR", true}, 60 } 61 for i, test := range tests { 62 res := MatchSyscall(test.call, test.pattern) 63 if res != test.result { 64 t.Errorf("#%v: pattern=%q call=%q want=%v got=%v", 65 i, test.pattern, test.call, test.result, res) 66 } 67 } 68 }