github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/cover/backend/gvisor_test.go (about) 1 // Copyright 2022 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 backend 5 6 import ( 7 "bufio" 8 "os" 9 "testing" 10 ) 11 12 func TestGvisorParseLine(t *testing.T) { 13 inputDataFiles := []string{ 14 "test_data/symbolize_all_gvisor_be6ffa78e4df78df13d004a17f2a8833305285c4.txt", 15 "test_data/symbolize_all_gvisor_release-20211026.0.txt", 16 } 17 18 for _, inputDataFile := range inputDataFiles { 19 file, err := os.Open(inputDataFile) 20 if err != nil { 21 t.Fatal(err) 22 } 23 defer file.Close() 24 25 lineNum := 0 26 s := bufio.NewScanner(file) 27 for s.Scan() { 28 lineNum++ 29 _, err := gvisorParseLine(s) 30 if err != nil { 31 t.Fatal(err) 32 } 33 } 34 } 35 } 36 37 func TestGvisorLineRe(t *testing.T) { 38 type Test struct { 39 line string 40 want string 41 } 42 43 tests := []Test{ 44 { 45 "gvisor.dev/gvisor/pkg/abi/abi.go:38.10,39.34", 46 "pkg/abi/abi.go", 47 }, 48 { 49 "bazel-out/k8-fastbuild-ST-246649c541f7/bin/pkg/abi/linux/linux_abi_autogen_unsafe.go:165.38,167.2", 50 "pkg/abi/linux/linux_abi_autogen_unsafe.go", 51 }, 52 { 53 "pkg/waiter/waiter.go:301.47,302.2", 54 "pkg/waiter/waiter.go", 55 }, 56 } 57 58 for _, test := range tests { 59 match := gvisorLineRe.FindStringSubmatch(test.line) 60 if match == nil { 61 t.Fatalf("FindStringSubmatch error on %v", test.line) 62 } 63 got := match[2] 64 if got != test.want { 65 t.Fatalf("wanted %v, got %v", test.want, got) 66 } 67 } 68 }