Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 581341d4 authored by Dan Willemsen's avatar Dan Willemsen
Browse files

Native Coverage support in Soong (gcov)

This is configured the same as make -- a global NATIVE_COVERAGE=true
flag to allow native coverage, then COVERAGE_PATHS=path1,path2,... to
turn it on for certain paths.

There are .gcnodir files exported to Make and saved in $OUT/coverage/...
files which are `ar` archives containing all of the compiler-produced
.gcno files for a particular executable / shared library.

Unlike the Make implementation, this only passes links the helper
library (automatically through --coverage) when one of the object files
or static libraries being used actually has coverage enabled.

Host support is currently disabled, since we set -nodefaultlibs, which
prevents libclang_rt.profile-*.a from being picked up automatically.

Bug: 32749731
Test: NATIVE_COVERAGE=true COVERAGE_PATHS=system/core/libcutils m -j libbacktrace libutils tombstoned
      $OUT/coverage/system/lib*/libcutils.gcnodir looks correct (self)
      $OUT/coverage/system/lib*/libbacktrace.gcnodir looks correct (static)
      $OUT/coverage/system/lib*/libutils.gcnodir doesn't exist (shared)
      $OUT/coverage/system/bin/tombstoned.gcnodir looks correct (executable)
Test: NATIVE_COVERAGE=true COVERAGE_PATHS=external/libcxxabi m -j libc++
      Confirm that $OUT/coverage/system/lib*/libc++.gcnodir looks correct (whole_static_libs)
Change-Id: I48aaa0ba8d76e50e9c2d1151421c0c6dc8ed79a9
parent e13374d3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ bootstrap_go_package {
        "cc/builder.go",
        "cc/cc.go",
        "cc/check.go",
        "cc/coverage.go",
        "cc/gen.go",
        "cc/makevars.go",
        "cc/prebuilt.go",
+15 −0
Original line number Diff line number Diff line
@@ -471,3 +471,18 @@ func (c *deviceConfig) VndkVersion() string {
func (c *deviceConfig) BtConfigIncludeDir() string {
	return String(c.config.ProductVariables.BtConfigIncludeDir)
}

func (c *deviceConfig) NativeCoverageEnabled() bool {
	return Bool(c.config.ProductVariables.NativeCoverage)
}

func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
	if c.config.ProductVariables.CoveragePaths != nil {
		for _, prefix := range *c.config.ProductVariables.CoveragePaths {
			if strings.HasPrefix(path, prefix) {
				return true
			}
		}
	}
	return false
}
+3 −0
Original line number Diff line number Diff line
@@ -131,6 +131,9 @@ type productVariables struct {
	ClangTidy  *bool   `json:",omitempty"`
	TidyChecks *string `json:",omitempty"`

	NativeCoverage *bool     `json:",omitempty"`
	CoveragePaths  *[]string `json:",omitempty"`

	DevicePrefer32BitExecutables *bool `json:",omitempty"`
	HostPrefer32BitExecutables   *bool `json:",omitempty"`

+7 −0
Original line number Diff line number Diff line
@@ -111,6 +111,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An

		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")

		if library.coverageOutputFile.Valid() {
			fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
		}

		return nil
	})

@@ -145,6 +149,9 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
			fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
		}

		if binary.coverageOutputFile.Valid() {
			fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String())
		}
		return nil
	})
}
+7 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ type binaryDecorator struct {

	// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
	symlinks []string

	// Output archive of gcno coverage information
	coverageOutputFile android.OptionalPath
}

var _ linker = (*binaryDecorator)(nil)
@@ -299,6 +302,10 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
		deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
		builderFlags, outputFile)

	objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
	objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
	binary.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, binary.getStem(ctx))

	return ret
}

Loading