diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-04-09 09:49:39 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-09 08:33:12 +0000 |
| commit | 56086b24bdfd822d3b227edb3064db443cd8c971 (patch) | |
| tree | fc307b5a2332cb85d0b8804e9d2645450da10853 /pkg | |
| parent | da07505f2b87b144347aa19597979d340b134b06 (diff) | |
pkg/cover: don't duplicate broken kcov logic in the test
dwarf.go already detects if kcov is broken and need to provide this bit
for the check in report.go, so just use this bit in the test as well.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/cover/backend/dwarf.go | 6 | ||||
| -rw-r--r-- | pkg/cover/backend/dwarf_test.go | 10 | ||||
| -rw-r--r-- | pkg/cover/report_test.go | 21 |
3 files changed, 11 insertions, 26 deletions
diff --git a/pkg/cover/backend/dwarf.go b/pkg/cover/backend/dwarf.go index b13ba2ca8..331cab9e3 100644 --- a/pkg/cover/backend/dwarf.go +++ b/pkg/cover/backend/dwarf.go @@ -189,7 +189,7 @@ func makeDWARFUnsafe(params *dwarfParams) (*Impl, error) { } allRanges = append(allRanges, ranges...) allUnits = append(allUnits, units...) - if IsKcovBrokenInCompiler(params.getCompilerVersion(module.Path)) { + if isKcovBrokenInCompiler(params.getCompilerVersion(module.Path)) { preciseCoverage = false } } @@ -304,7 +304,7 @@ func buildSymbols(symbols []*Symbol, ranges []pcRange, coverPoints [2][]uint64) return symbols } -// Regexps to parse compiler version string in IsKcovBrokenInCompiler. +// Regexps to parse compiler version string in isKcovBrokenInCompiler. // Some targets (e.g. NetBSD) use g++ instead of gcc. var gccRE = regexp.MustCompile(`gcc|GCC|g\+\+`) var gccVersionRE = regexp.MustCompile(`(gcc|GCC|g\+\+).* ([0-9]{1,2})\.[0-9]+\.[0-9]+`) @@ -312,7 +312,7 @@ var gccVersionRE = regexp.MustCompile(`(gcc|GCC|g\+\+).* ([0-9]{1,2})\.[0-9]+\.[ // GCC < 14 incorrectly tail-calls kcov callbacks, which does not let syzkaller // verify that collected coverage points have matching callbacks. // See https://github.com/google/syzkaller/issues/4447 for more information. -func IsKcovBrokenInCompiler(versionStr string) bool { +func isKcovBrokenInCompiler(versionStr string) bool { if !gccRE.MatchString(versionStr) { return false } diff --git a/pkg/cover/backend/dwarf_test.go b/pkg/cover/backend/dwarf_test.go index bc2ebf12e..9d4da8e90 100644 --- a/pkg/cover/backend/dwarf_test.go +++ b/pkg/cover/backend/dwarf_test.go @@ -26,15 +26,13 @@ func TestIsKcovBrokenInCompiler(t *testing.T) { "g++ (Compiler-Explorer-Build-gcc-2a9637b229f64775d82fb5917f83f71e8ad1911d-binutils-2.40) 14.0.1 20240125 (experimental)", // nolint:lll } for _, ver := range inputDataTrue { - result := IsKcovBrokenInCompiler(ver) - if !result { - t.Fatalf("IsKcovBrokenInCompiler(`%s`) unexpectedly returned %v\n", ver, result) + if !isKcovBrokenInCompiler(ver) { + t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned false\n", ver) } } for _, ver := range inputDataFalse { - result := IsKcovBrokenInCompiler(ver) - if result { - t.Fatalf("IsKcovBrokenInCompiler(`%s`) unexpectedly returned %v\n", ver, result) + if isKcovBrokenInCompiler(ver) { + t.Fatalf("isKcovBrokenInCompiler(%q) unexpectedly returned true\n", ver) } } } diff --git a/pkg/cover/report_test.go b/pkg/cover/report_test.go index 729caba41..ab0be490b 100644 --- a/pkg/cover/report_test.go +++ b/pkg/cover/report_test.go @@ -40,9 +40,6 @@ type Test struct { DebugInfo bool AddCover bool AddBadPc bool - // Set by the testing environment depending on the target compiler. - // See https://github.com/google/syzkaller/issues/4447. - KcovIsBroken bool // Set to true if the test should be skipped under broken kcov. SkipIfKcovIsBroken bool // Inexact coverage generated by AddCover=true may override empty Result. @@ -135,17 +132,12 @@ func TestReportGenerator(t *testing.T) { if target.BrokenCompiler != "" { t.Skip("skipping the test due to broken cross-compiler:\n" + target.BrokenCompiler) } - kcovIsBroken := targetKcovIsBroken(t, target) for _, test := range tests { test := test - test.KcovIsBroken = kcovIsBroken t.Run(test.Name, func(t *testing.T) { if test.Supports != nil && !test.Supports(target) { t.Skip("unsupported target") } - if test.SkipIfKcovIsBroken && test.KcovIsBroken { - t.Skip("coverage testing requested, but kcov is broken") - } t.Parallel() testReportGenerator(t, target, test) }) @@ -281,14 +273,6 @@ func buildTestBinary(t *testing.T, target *targets.Target, test *Test, dir strin return bin } -// Work around https://github.com/google/syzkaller/issues/4447. Do not use for anything else. -func targetKcovIsBroken(t *testing.T, target *targets.Target) bool { - if out, err := osutil.RunCmd(time.Hour, "", target.CCompiler, "--version"); err == nil { - return backend.IsKcovBrokenInCompiler(string(out)) - } - return true -} - type reports struct { html []byte csv []byte @@ -328,6 +312,9 @@ func generateReport(t *testing.T, target *targets.Target, test *Test) (*reports, if err != nil { return nil, err } + if !rg.PreciseCoverage && test.SkipIfKcovIsBroken { + t.Skip("coverage testing requested, but kcov is broken") + } if test.AddCover { var pcs []uint64 Inexact := false @@ -363,7 +350,7 @@ func generateReport(t *testing.T, target *targets.Target, test *Test) (*reports, t.Logf("using inexact coverage range 0x%x-0x%x", main.Addr, main.Addr+uint64(main.Size)) Inexact = true } - if Inexact && test.Result == "" && !test.KcovIsBroken { + if Inexact && test.Result == "" && rg.PreciseCoverage { test.Result = fmt.Sprintf("%d out of %d PCs returned by kcov do not have matching coverage callbacks", len(pcs)-1, len(pcs)) } |
