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

Commit a0cd8f9a authored by Ivan Lozano's avatar Ivan Lozano
Browse files

Add gcov coverage support to Rust modules.

This adds gcov coverage support for Rust device library and binary
modules (including test modules). Support is provided to pass Rust
static library gcno files to CC modules and visa versa.

Additional changes:
 * Begin mutator added for Rust modules.
 * SuffixInList added to android package.
 * CoverageEnabled added to Coverage interface.
 * CoverageFiles added to LinkableLibrary interface.
 * Fix in coverage mutator for non-CC modules which marked the wrong
   variant as the coverage variant.
 * Added coverage libraries to the cc.GatherRequiredDepsForTest.

Bug: 146448203
Test: NATIVE_COVERAGE=true COVERAGE_PATHS='*' m -j <rust_module>
Change-Id: If20728bdde42a1dd544a35a40f0d981b80a5835f
parent b8bb5d05
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -391,6 +391,7 @@ bootstrap_go_package {
    srcs: [
        "rust/androidmk.go",
        "rust/compiler.go",
        "rust/coverage.go",
        "rust/binary.go",
        "rust/builder.go",
        "rust/library.go",
@@ -403,6 +404,7 @@ bootstrap_go_package {
    testSrcs: [
        "rust/binary_test.go",
        "rust/compiler_test.go",
        "rust/coverage_test.go",
        "rust/library_test.go",
        "rust/rust_test.go",
        "rust/test_test.go",
+10 −0
Original line number Diff line number Diff line
@@ -141,6 +141,16 @@ func PrefixInList(list []string, prefix string) bool {
	return false
}

// Returns true if any string in the given list has the given suffix.
func SuffixInList(list []string, suffix string) bool {
	for _, s := range list {
		if strings.HasSuffix(s, suffix) {
			return true
		}
	}
	return false
}

// IndexListPred returns the index of the element which in the given `list` satisfying the predicate, or -1 if there is no such element.
func IndexListPred(pred func(s string) bool, list []string) int {
	for i, l := range list {
+4 −0
Original line number Diff line number Diff line
@@ -1611,6 +1611,8 @@ func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizer
	return android.InList(sanitizerName, globalSanitizerNames)
}

var _ cc.Coverage = (*apexBundle)(nil)

func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
	return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
}
@@ -1627,6 +1629,8 @@ func (a *apexBundle) MarkAsCoverageVariant(coverage bool) {
	a.properties.IsCoverageVariant = coverage
}

func (a *apexBundle) EnableCoverageIfNeeded() {}

// TODO(jiyong) move apexFileFor* close to the apexFile type definition
func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
	// Decide the APEX-local directory by the multilib of the library
+1 −38
Original line number Diff line number Diff line
@@ -117,44 +117,7 @@ func TestVndkApexUsesVendorVariant(t *testing.T) {
	})

	t.Run("VNDK APEX supports coverage variants", func(t *testing.T) {
		ctx, _ := testApex(t, bp+`
			cc_library {
				name: "libprofile-extras",
				vendor_available: true,
				recovery_available: true,
				native_coverage: false,
				system_shared_libs: [],
				stl: "none",
				notice: "custom_notice",
			}
			cc_library {
				name: "libprofile-clang-extras",
				vendor_available: true,
				recovery_available: true,
				native_coverage: false,
				system_shared_libs: [],
				stl: "none",
				notice: "custom_notice",
			}
			cc_library {
				name: "libprofile-extras_ndk",
				vendor_available: true,
				native_coverage: false,
				system_shared_libs: [],
				stl: "none",
				notice: "custom_notice",
				sdk_version: "current",
			}
			cc_library {
				name: "libprofile-clang-extras_ndk",
				vendor_available: true,
				native_coverage: false,
				system_shared_libs: [],
				stl: "none",
				notice: "custom_notice",
				sdk_version: "current",
			}
		`, func(fs map[string][]byte, config android.Config) {
		ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) {
			config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
		})

+13 −2
Original line number Diff line number Diff line
@@ -437,7 +437,6 @@ var (
	ndkLateStubDepTag     = DependencyTag{Name: "ndk late stub", Library: true}
	vndkExtDepTag         = DependencyTag{Name: "vndk extends", Library: true}
	runtimeDepTag         = DependencyTag{Name: "runtime lib"}
	coverageDepTag        = DependencyTag{Name: "coverage"}
	testPerSrcDepTag      = DependencyTag{Name: "test_per_src"}
)

@@ -741,6 +740,15 @@ func (c *Module) OutputFile() android.OptionalPath {
	return c.outputFile
}

func (c *Module) CoverageFiles() android.Paths {
	if c.linker != nil {
		if library, ok := c.linker.(libraryInterface); ok {
			return library.objs().coverageFiles
		}
	}
	panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
}

var _ LinkableInterface = (*Module)(nil)

func (c *Module) UnstrippedOutputFile() android.Path {
@@ -2489,13 +2497,16 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
			// When combining coverage files for shared libraries and executables, coverage files
			// in static libraries act as if they were whole static libraries. The same goes for
			// source based Abi dump files.
			// This should only be done for cc.Modules
			if c, ok := ccDep.(*Module); ok {
				staticLib := c.linker.(libraryInterface)
				depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
					staticLib.objs().coverageFiles...)
				depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
					staticLib.objs().sAbiDumpFiles...)
			} else if c, ok := ccDep.(LinkableInterface); ok {
				// Handle non-CC modules here
				depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
					c.CoverageFiles()...)
			}
		}

Loading