Merge changes Ifc96992e,Ic76523ba
* changes:
Support test fixtures in sdk package
Add apexFixtureFactory to apex package
diff --git a/android/androidmk.go b/android/androidmk.go
index 32d7712..9317567 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -44,6 +44,14 @@
ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
}
+// Enable androidmk support.
+// * Register the singleton
+// * Configure that we are inside make
+var PrepareForTestWithAndroidMk = GroupFixturePreparers(
+ FixtureRegisterWithContext(RegisterAndroidMkBuildComponents),
+ FixtureModifyConfig(SetKatiEnabledForTests),
+)
+
// Deprecated: Use AndroidMkEntriesProvider instead, especially if you're not going to use the
// Custom function. It's easier to use and test.
type AndroidMkDataProvider interface {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index cc1f7d0..7d9fa47 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -55,7 +55,6 @@
var ccFixtureFactory = android.NewFixtureFactory(
&buildDir,
PrepareForTestWithCcIncludeVndk,
-
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceVndkVersion = StringPtr("current")
variables.ProductVndkVersion = StringPtr("current")
@@ -3421,24 +3420,16 @@
}
`
- config := TestConfig(buildDir, android.Android, nil, bp, nil)
- config.TestProductVariables.Debuggable = BoolPtr(true)
+ result := ccFixtureFactory.Extend(
+ android.PrepareForTestWithVariables,
- ctx := CreateTestContext(config)
- ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("variable", android.VariableMutator).Parallel()
- })
- ctx.Register()
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.Debuggable = BoolPtr(true)
+ }),
+ ).RunTestWithBp(t, bp)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
-
- libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
- if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
- t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
- }
+ libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
+ result.AssertStringListContains("cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
}
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
@@ -3456,32 +3447,17 @@
}
`
- config := TestConfig(buildDir, android.Android, nil, bp, nil)
- config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
+ result := ccFixtureFactory.Extend(
+ android.PrepareForTestWithAllowMissingDependencies,
+ ).RunTestWithBp(t, bp)
- ctx := CreateTestContext(config)
- ctx.SetAllowMissingDependencies(true)
- ctx.Register()
+ libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
+ result.AssertDeepEquals("libbar rule", android.ErrorRule, libbar.Rule)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
+ result.AssertStringDoesContain("libbar error", libbar.Args["error"], "missing dependencies: libmissing")
- libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
- if g, w := libbar.Rule, android.ErrorRule; g != w {
- t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
- }
-
- if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
- t.Errorf("Expected libbar error to contain %q, was %q", w, g)
- }
-
- libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
- if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
- t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
- }
-
+ libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
+ result.AssertStringListContains("libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
}
func TestInstallSharedLibs(t *testing.T) {
@@ -3671,8 +3647,9 @@
}
}
-func makeMemtagTestConfig(t *testing.T) android.Config {
- templateBp := `
+var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
+ android.FixtureModifyMockFS(func(fs android.MockFS) {
+ templateBp := `
cc_test {
name: "%[1]s_test",
gtest: false,
@@ -3726,35 +3703,30 @@
sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
}
`
- subdirDefaultBp := fmt.Sprintf(templateBp, "default")
- subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
- subdirSyncBp := fmt.Sprintf(templateBp, "sync")
- subdirAsyncBp := fmt.Sprintf(templateBp, "async")
+ subdirDefaultBp := fmt.Sprintf(templateBp, "default")
+ subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
+ subdirSyncBp := fmt.Sprintf(templateBp, "sync")
+ subdirAsyncBp := fmt.Sprintf(templateBp, "async")
- mockFS := map[string][]byte{
- "subdir_default/Android.bp": []byte(subdirDefaultBp),
- "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
- "subdir_sync/Android.bp": []byte(subdirSyncBp),
- "subdir_async/Android.bp": []byte(subdirAsyncBp),
- }
-
- return TestConfig(buildDir, android.Android, nil, "", mockFS)
-}
+ fs.Merge(android.MockFS{
+ "subdir_default/Android.bp": []byte(subdirDefaultBp),
+ "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
+ "subdir_sync/Android.bp": []byte(subdirSyncBp),
+ "subdir_async/Android.bp": []byte(subdirAsyncBp),
+ })
+ }),
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
+ variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
+ variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
+ }),
+)
func TestSanitizeMemtagHeap(t *testing.T) {
variant := "android_arm64_armv8-a"
- config := makeMemtagTestConfig(t)
- config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
- config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
- config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
- ctx := CreateTestContext(config)
- ctx.Register()
-
- _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
+ result := ccFixtureFactory.Extend(prepareForTestWithMemtagHeap).RunTest(t)
+ ctx := result.TestContext
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
@@ -3808,18 +3780,13 @@
func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
variant := "android_arm64_armv8-a"
- config := makeMemtagTestConfig(t)
- config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
- config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
- config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
- config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
- ctx := CreateTestContext(config)
- ctx.Register()
-
- _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
+ result := ccFixtureFactory.Extend(
+ prepareForTestWithMemtagHeap,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.SanitizeDevice = []string{"memtag_heap"}
+ }),
+ ).RunTest(t)
+ ctx := result.TestContext
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
@@ -3873,19 +3840,14 @@
func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
variant := "android_arm64_armv8-a"
- config := makeMemtagTestConfig(t)
- config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
- config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
- config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
- config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
- config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
- ctx := CreateTestContext(config)
- ctx.Register()
-
- _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
+ result := ccFixtureFactory.Extend(
+ prepareForTestWithMemtagHeap,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.SanitizeDevice = []string{"memtag_heap"}
+ variables.SanitizeDeviceDiag = []string{"memtag_heap"}
+ }),
+ ).RunTest(t)
+ ctx := result.TestContext
checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index ee4de6e..20274b2 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -23,27 +23,16 @@
"github.com/google/blueprint"
)
-func testPrebuilt(t *testing.T, bp string, fs map[string][]byte, handlers ...configCustomizer) *android.TestContext {
- config := TestConfig(buildDir, android.Android, nil, bp, fs)
- ctx := CreateTestContext(config)
+var prebuiltFixtureFactory = ccFixtureFactory.Extend(
+ android.PrepareForTestWithAndroidMk,
+)
- // Enable androidmk support.
- // * Register the singleton
- // * Configure that we are inside make
- // * Add CommonOS to ensure that androidmk processing works.
- android.RegisterAndroidMkBuildComponents(ctx)
- android.SetKatiEnabledForTests(config)
+func testPrebuilt(t *testing.T, bp string, fs android.MockFS, handlers ...android.FixturePreparer) *android.TestContext {
+ result := prebuiltFixtureFactory.Extend(
+ fs.AddToFixture(),
+ ).Extend(handlers...).RunTestWithBp(t, bp)
- for _, handler := range handlers {
- handler(config)
- }
-
- ctx.Register()
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
- return ctx
+ return result.TestContext
}
type configCustomizer func(config android.Config)
@@ -370,9 +359,11 @@
assertString(t, static2.OutputFile().Path().Base(), "libf.a")
// With SANITIZE_TARGET=hwaddress
- ctx = testPrebuilt(t, bp, fs, func(config android.Config) {
- config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
- })
+ ctx = testPrebuilt(t, bp, fs,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.SanitizeDevice = []string{"hwaddress"}
+ }),
+ )
shared_rule = ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared_hwasan").Rule("android/soong/cc.strip")
assertString(t, shared_rule.Input.String(), "hwasan/libf.so")
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index 764f045..8e2c554 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -237,3 +237,13 @@
func (b *bootimg) OutputPath() android.Path {
return b.output
}
+
+var _ android.OutputFileProducer = (*bootimg)(nil)
+
+// Implements android.OutputFileProducer
+func (b *bootimg) OutputFiles(tag string) (android.Paths, error) {
+ if tag == "" {
+ return []android.Path{b.output}, nil
+ }
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+}
diff --git a/filesystem/logical_partition.go b/filesystem/logical_partition.go
index e547203..16b6037 100644
--- a/filesystem/logical_partition.go
+++ b/filesystem/logical_partition.go
@@ -208,3 +208,13 @@
func (l *logicalPartition) OutputPath() android.Path {
return l.output
}
+
+var _ android.OutputFileProducer = (*logicalPartition)(nil)
+
+// Implements android.OutputFileProducer
+func (l *logicalPartition) OutputFiles(tag string) (android.Paths, error) {
+ if tag == "" {
+ return []android.Path{l.output}, nil
+ }
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+}
diff --git a/java/lint.go b/java/lint.go
index 5940eac..9f677db 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -189,6 +189,10 @@
remoteRSPInputs android.Paths
}
+func lintRBEExecStrategy(ctx android.ModuleContext) string {
+ return ctx.Config().GetenvWithDefault("RBE_LINT_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
+}
+
func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.RuleBuilder) lintPaths {
var deps android.Paths
var remoteInputs android.Paths
@@ -280,7 +284,8 @@
cmd.FlagForEachArg("--extra_checks_jar ", l.extraLintCheckJars.Strings())
trackInputDependency(l.extraLintCheckJars...)
- if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_LINT") {
+ if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_LINT") &&
+ lintRBEExecStrategy(ctx) != remoteexec.LocalExecStrategy {
// TODO(b/181912787): remove these and use "." instead.
cmd.FlagWithArg("--root_dir ", "/b/f/w")
} else {
@@ -391,7 +396,7 @@
pool := ctx.Config().GetenvWithDefault("RBE_LINT_POOL", "java16")
// TODO(b/181912787): this should be local fallback once the hack that passes /b/f/w in project.xml
// is removed.
- execStrategy := ctx.Config().GetenvWithDefault("RBE_LINT_EXEC_STRATEGY", remoteexec.RemoteExecStrategy)
+ execStrategy := lintRBEExecStrategy(ctx)
labels := map[string]string{"type": "tool", "name": "lint"}
rule.Remoteable(android.RemoteRuleSupports{RBE: true})
remoteInputs := lintPaths.remoteInputs
@@ -417,6 +422,7 @@
"ANDROID_SDK_HOME",
"SDK_ANNOTATIONS",
"LINT_OPTS",
+ "LANG",
},
Platform: map[string]string{remoteexec.PoolKey: pool},
}).NoVarTemplate(ctx.Config()))
diff --git a/java/system_modules_test.go b/java/system_modules_test.go
index 44049ee..abcd186 100644
--- a/java/system_modules_test.go
+++ b/java/system_modules_test.go
@@ -20,7 +20,7 @@
"android/soong/android"
)
-func normalizedPathsToHeaderJars(result *android.TestResult, moduleNames ...string) []string {
+func getModuleHeaderJarsAsNormalizedPaths(result *android.TestResult, moduleNames ...string) []string {
paths := []string{}
for _, moduleName := range moduleNames {
module := result.Module(moduleName, "android_common")
@@ -57,7 +57,7 @@
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the source input modules.
- expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
}
@@ -84,7 +84,7 @@
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the renamed prebuilt input modules.
- expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
result.AssertArrayString("renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
}
@@ -99,7 +99,7 @@
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the source input modules.
- expectedSourcePaths := normalizedPathsToHeaderJars(result, "system-module1", "system-module2")
+ expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
// check the existence of the renamed prebuilt module
@@ -107,6 +107,6 @@
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
// The expected paths are the header jars from the renamed prebuilt input modules.
- expectedPrebuiltPaths := normalizedPathsToHeaderJars(result, "prebuilt_system-module1", "prebuilt_system-module2")
+ expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "prebuilt_system-module1", "prebuilt_system-module2")
result.AssertArrayString("prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
}
diff --git a/sdk/testing.go b/sdk/testing.go
index 1fb571f..41280fc 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -105,7 +105,7 @@
}
// Analyse the sdk build rules to extract information about what it is doing.
-
+//
// e.g. find the src/dest pairs from each cp command, the various zip files
// generated, etc.
func getSdkSnapshotBuildInfo(result *android.TestResult, sdk *sdk) *snapshotBuildInfo {