From 0ef84591d219e3142621dc31dcec970300f7ec0c Mon Sep 17 00:00:00 2001 From: Dean Deng Date: Fri, 4 Dec 2020 15:59:12 -0800 Subject: pkg/build: skip coverage instrumentation on gVisor norace files These cannot be instrumented with regular atomic operations (e.g., sync/atomic.AddInt32), which will happen if -race is enabled. We may be able to re-enable coverage on them when https://golang.org/issue/43007 is resolved. --- pkg/build/gvisor.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/build/gvisor.go b/pkg/build/gvisor.go index d0711ee70..b540d0144 100644 --- a/pkg/build/gvisor.go +++ b/pkg/build/gvisor.go @@ -24,14 +24,32 @@ func (gvisor gvisor) build(params *Params) error { config := strings.Fields(string(params.Config)) args := []string{"build", "--verbose_failures"} target := "//runsc:runsc" + race := raceEnabled(config) + if race { + args = append(args, "--features=race") + target = "//runsc:runsc-race" + } if coverageEnabled(config) { + coverageFiles := "//pkg/..." + exclusions := []string{ + "//pkg/sentry/platform/...", // Breaks kvm. + } + if race { + // These files use go:norace, which is not respected by + // coverage instrumentation. Race builds will be + // instrumented with atomic coverage (using + // sync/atomic.AddInt32), which will not work. + exclusions = append(exclusions, []string{ + "//pkg/sleep/sleep_unsafe.go", + "//pkg/syncevent/waiter_unsafe.go", + }...) + } + for _, f := range exclusions { + coverageFiles += ",-" + f + } args = append(args, []string{ "--collect_code_coverage", - "--instrumentation_filter=//pkg/...,-//pkg/sentry/platform/..."}...) - } - if raceEnabled(config) { - args = append(args, "--features=race") - target = "//runsc:runsc-race" + "--instrumentation_filter=" + coverageFiles}...) } args = append(args, target) // The 1 hour timeout is quite high. But we've seen false positives with 20 mins -- cgit mrf-deployment