From a02cae345bb3d082972eddd51482181c447b35e8 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 9 Mar 2021 01:44:06 +0000 Subject: [PATCH] Convert ...InstallHwasan.. tests to use fixtures These tests rely on changing the definition of the "libc" module which is a default module provided by the cc.GatherRequiredDepsForTest() function. That function is called from within testApexContext() and so added by default. Previously, the tests relied on a number of factors to work: 1. All the default cc modules were added to the bp contents that were passed to testApexContext(). 2. testApexContext() passed the augmented bp contents to TestArchConfig(). 3. TestArchConfig() only stored the supplied bp contents in the root Android.bp file if it did not exist. So, in order to override the default modules it simply made sure to add its own Android.bp file into the file system first. Unfortunately, that does not work with the test fixtures as the default modules are defined in their own specific paths to avoid conflicting with each other. To achieve the same effect as previously, i.e. no default modules, this test uses an emptyFixtureFactory and only adds preparers for cc and apex build components and ignores the default module definitions altogether. Bug: 181070625 Test: m nothing Change-Id: Ic6b961dd2bd78c32cb326b2c7905426ee971c2d8 --- apex/apex_test.go | 52 +++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 3fde14458..5dbec58ae 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -127,6 +127,8 @@ func withUnbundledBuild(_ map[string][]byte, config android.Config) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } +var emptyFixtureFactory = android.NewFixtureFactory(&buildDir) + var apexFixtureFactory = android.NewFixtureFactory( &buildDir, // General preparers in alphabetical order as test infrastructure will enforce correct @@ -1316,9 +1318,10 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) { } -func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { - ctx := testApex(t, "", func(fs map[string][]byte, config android.Config) { - bp := ` +var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( + cc.PrepareForTestWithCcBuildComponents, + PrepareForTestWithApexBuildComponents, + android.FixtureAddTextFile("bionic/apex/Android.bp", ` apex { name: "com.android.runtime", key: "com.android.runtime.key", @@ -1331,7 +1334,12 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { public_key: "testkey.avbpubkey", private_key: "testkey.pem", } + `), + android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), +) +func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { + result := emptyFixtureFactory.Extend(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` cc_library { name: "libc", no_libcrt: true, @@ -1358,12 +1366,8 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { sanitize: { never: true, }, - } - ` - // override bp to use hard-coded names: com.android.runtime and libc - fs["Android.bp"] = []byte(bp) - fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil - }) + } `) + ctx := result.TestContext ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ "lib64/bionic/libc.so", @@ -1381,21 +1385,12 @@ func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { } func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { - ctx := testApex(t, "", func(fs map[string][]byte, config android.Config) { - bp := ` - apex { - name: "com.android.runtime", - key: "com.android.runtime.key", - native_shared_libs: ["libc"], - updatable: false, - } - - apex_key { - name: "com.android.runtime.key", - public_key: "testkey.avbpubkey", - private_key: "testkey.pem", - } - + result := emptyFixtureFactory.Extend( + prepareForTestOfRuntimeApexWithHwasan, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.SanitizeDevice = []string{"hwaddress"} + }), + ).RunTestWithBp(t, ` cc_library { name: "libc", no_libcrt: true, @@ -1419,13 +1414,8 @@ func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { never: true, }, } - ` - // override bp to use hard-coded names: com.android.runtime and libc - fs["Android.bp"] = []byte(bp) - fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil - - config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} - }) + `) + ctx := result.TestContext ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ "lib64/bionic/libc.so",