Add support for SDK tests with LinuxBionic OS type.
Break apart test helpers a bit to make it possible to enable
LinuxBionic in a single test, and add LinuxBionic support to
cc.GatherRequiredDepsForTest.
Test: m nothing
Bug: 160349757
Change-Id: Iace1024c964cee2308c130c945daef9e46c18c66
diff --git a/cc/testing.go b/cc/testing.go
index a106d46..4d0b28b 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -30,6 +30,7 @@
ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)
ctx.RegisterModuleType("cc_object", ObjectFactory)
+ ctx.RegisterModuleType("cc_genrule", genRuleFactory)
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory)
ctx.RegisterModuleType("ndk_library", NdkLibraryFactory)
@@ -39,6 +40,7 @@
ret := `
toolchain_library {
name: "libatomic",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
native_bridge_supported: true,
@@ -92,6 +94,7 @@
toolchain_library {
name: "libclang_rt.builtins-x86_64-android",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
native_bridge_supported: true,
@@ -121,6 +124,7 @@
toolchain_library {
name: "libclang_rt.fuzzer-x86_64-android",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
src: "",
@@ -144,6 +148,7 @@
toolchain_library {
name: "libgcc",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
src: "",
@@ -151,6 +156,7 @@
toolchain_library {
name: "libgcc_stripped",
+ defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
sdk_version: "current",
@@ -159,6 +165,7 @@
cc_library {
name: "libc",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -175,6 +182,7 @@
}
cc_library {
name: "libm",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -234,6 +242,7 @@
cc_library {
name: "libdl",
+ defaults: ["linux_bionic_supported"],
no_libcrt: true,
nocrt: true,
stl: "none",
@@ -326,6 +335,7 @@
cc_defaults {
name: "crt_defaults",
+ defaults: ["linux_bionic_supported"],
recovery_available: true,
vendor_available: true,
native_bridge_supported: true,
@@ -437,6 +447,7 @@
}
`
+ supportLinuxBionic := false
for _, os := range oses {
if os == android.Fuchsia {
ret += `
@@ -465,7 +476,59 @@
}
`
}
+ if os == android.LinuxBionic {
+ supportLinuxBionic = true
+ ret += `
+ cc_binary {
+ name: "linker",
+ defaults: ["linux_bionic_supported"],
+ recovery_available: true,
+ stl: "none",
+ nocrt: true,
+ static_executable: true,
+ native_coverage: false,
+ system_shared_libs: [],
+ }
+
+ cc_genrule {
+ name: "host_bionic_linker_flags",
+ host_supported: true,
+ device_supported: false,
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+ out: ["linker.flags"],
+ }
+
+ cc_defaults {
+ name: "linux_bionic_supported",
+ host_supported: true,
+ target: {
+ host: {
+ enabled: false,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+ }
+ `
+ }
}
+
+ if !supportLinuxBionic {
+ ret += `
+ cc_defaults {
+ name: "linux_bionic_supported",
+ }
+ `
+ }
+
return ret
}
diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go
index 2dd23c7..935d348 100644
--- a/sdk/cc_sdk_test.go
+++ b/sdk/cc_sdk_test.go
@@ -21,20 +21,20 @@
"android/soong/cc"
)
+var ccTestFs = map[string][]byte{
+ "Test.cpp": nil,
+ "include/Test.h": nil,
+ "include-android/AndroidTest.h": nil,
+ "include-host/HostTest.h": nil,
+ "arm64/include/Arm64Test.h": nil,
+ "libfoo.so": nil,
+ "aidl/foo/bar/Test.aidl": nil,
+ "some/where/stubslib.map.txt": nil,
+}
+
func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
t.Helper()
-
- fs := map[string][]byte{
- "Test.cpp": nil,
- "include/Test.h": nil,
- "include-android/AndroidTest.h": nil,
- "include-host/HostTest.h": nil,
- "arm64/include/Arm64Test.h": nil,
- "libfoo.so": nil,
- "aidl/foo/bar/Test.aidl": nil,
- "some/where/stubslib.map.txt": nil,
- }
- return testSdkWithFs(t, bp, fs)
+ return testSdkWithFs(t, bp, ccTestFs)
}
// Contains tests for SDK members provided by the cc package.
diff --git a/sdk/testing.go b/sdk/testing.go
index 378ce1f..34ea8f0 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -29,7 +29,9 @@
"android/soong/java"
)
-func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
+func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
+ extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
+
bp = bp + `
apex_key {
name: "myapex.key",
@@ -41,7 +43,7 @@
name: "myapex.cert",
certificate: "myapex",
}
- ` + cc.GatherRequiredDepsForTest(android.Android, android.Windows)
+ ` + cc.GatherRequiredDepsForTest(extraOsTypes...)
mockFS := map[string][]byte{
"build/make/target/product/security": nil,
@@ -69,6 +71,15 @@
{android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", ""},
}
+ for _, extraOsType := range extraOsTypes {
+ switch extraOsType {
+ case android.LinuxBionic:
+ config.Targets[android.LinuxBionic] = []android.Target{
+ {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", ""},
+ }
+ }
+ }
+
ctx := android.NewTestArchContext()
// Enable androidmk support.
@@ -117,9 +128,8 @@
return ctx, config
}
-func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
+func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
t.Helper()
- ctx, config := testSdkContext(bp, fs)
_, errs := ctx.ParseBlueprintsFiles(".")
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -131,9 +141,15 @@
}
}
+func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
+ t.Helper()
+ ctx, config := testSdkContext(bp, fs, nil)
+ return runTests(t, ctx, config)
+}
+
func testSdkError(t *testing.T, pattern, bp string) {
t.Helper()
- ctx, config := testSdkContext(bp, nil)
+ ctx, config := testSdkContext(bp, nil, nil)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)