export common bp2build testing functions
bp2buildTestCase attrNameToString runBp2BuildTestCase makeBazelTargetNoRestrictions The testing framework defined in the bp2build package can only be used from within the package because many common testing functions are private to the package. This prevents modules defined in Soong plugins (e.g. system/tools/aidl/build) from testing bp2build conversions. Test: go test ./bp2build Change-Id: Ia867081327c5181d04687b13c4550e68e6a11f86
This commit is contained in:
committed by
Liz Kammer
parent
88e7512572
commit
3177a6e1e0
@@ -26,23 +26,23 @@ func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
|
||||
}
|
||||
|
||||
func runCcObjectTestCase(t *testing.T, tc bp2buildTestCase) {
|
||||
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).moduleTypeUnderTest = "cc_object"
|
||||
(&tc).moduleTypeUnderTestFactory = cc.ObjectFactory
|
||||
runBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
|
||||
(&tc).ModuleTypeUnderTest = "cc_object"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory
|
||||
RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
|
||||
}
|
||||
|
||||
func TestCcObjectSimple(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "simple cc_object generates cc_object with include header dep",
|
||||
filesystem: map[string]string{
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "simple cc_object generates cc_object with include header dep",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/foo.h": "",
|
||||
"a/b/bar.h": "",
|
||||
"a/b/exclude.c": "",
|
||||
"a/b/c.c": "",
|
||||
},
|
||||
blueprint: `cc_object {
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
local_include_dirs: ["include"],
|
||||
system_shared_libs: [],
|
||||
@@ -59,8 +59,8 @@ func TestCcObjectSimple(t *testing.T) {
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `[
|
||||
"-fno-addrsig",
|
||||
"-Wno-gcc-compat",
|
||||
@@ -73,16 +73,16 @@ func TestCcObjectSimple(t *testing.T) {
|
||||
]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectDefaults(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: [
|
||||
@@ -105,8 +105,8 @@ cc_defaults {
|
||||
],
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `[
|
||||
"-Werror",
|
||||
"-fno-addrsig",
|
||||
@@ -119,13 +119,13 @@ cc_defaults {
|
||||
}
|
||||
|
||||
func TestCcObjectCcObjetDepsInObjs(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object with cc_object deps in objs props",
|
||||
filesystem: map[string]string{
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with cc_object deps in objs props",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/c.c": "",
|
||||
"x/y/z.c": "",
|
||||
},
|
||||
blueprint: `cc_object {
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a/b/c.c"],
|
||||
@@ -140,12 +140,12 @@ cc_object {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "bar", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "bar", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["x/y/z.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}), makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
}), makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"deps": `[":bar"]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
@@ -156,21 +156,21 @@ cc_object {
|
||||
}
|
||||
|
||||
func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object with include_build_dir: false",
|
||||
filesystem: map[string]string{
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with include_build_dir: false",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/c.c": "",
|
||||
"x/y/z.c": "",
|
||||
},
|
||||
blueprint: `cc_object {
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a/b/c.c"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
@@ -180,9 +180,9 @@ func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCcObjectProductVariable(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object with product variable",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with product variable",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
include_build_directory: false,
|
||||
@@ -194,8 +194,8 @@ func TestCcObjectProductVariable(t *testing.T) {
|
||||
srcs: ["src.S"],
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"asflags": `select({
|
||||
"//build/bazel/product_variables:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
|
||||
"//conditions:default": [],
|
||||
@@ -209,9 +209,9 @@ func TestCcObjectProductVariable(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCcObjectCflagsOneArch(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object setting cflags for one arch",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting cflags for one arch",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a.cpp"],
|
||||
@@ -226,8 +226,8 @@ func TestCcObjectCflagsOneArch(t *testing.T) {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"] + select({
|
||||
"//build/bazel/platforms/arch:x86": ["-fPIC"],
|
||||
"//conditions:default": [],
|
||||
@@ -243,9 +243,9 @@ func TestCcObjectCflagsOneArch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCcObjectCflagsFourArch(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object setting cflags for 4 architectures",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting cflags for 4 architectures",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["base.cpp"],
|
||||
@@ -270,8 +270,8 @@ func TestCcObjectCflagsFourArch(t *testing.T) {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"] + select({
|
||||
"//build/bazel/platforms/arch:arm": ["-Wall"],
|
||||
"//build/bazel/platforms/arch:arm64": ["-Wall"],
|
||||
@@ -293,17 +293,17 @@ func TestCcObjectCflagsFourArch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCcObjectLinkerScript(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object setting linker_script",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting linker_script",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
linker_script: "bunny.lds",
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"linker_script": `"bunny.lds"`,
|
||||
"srcs": `["base.cpp"]`,
|
||||
@@ -313,9 +313,9 @@ func TestCcObjectLinkerScript(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object setting deps and linker_script across archs",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting deps and linker_script across archs",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
arch: {
|
||||
@@ -359,8 +359,8 @@ cc_object {
|
||||
bazel_module: { bp2build_available: false },
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"deps": `select({
|
||||
"//build/bazel/platforms/arch:arm": [":arm_obj"],
|
||||
@@ -381,9 +381,9 @@ cc_object {
|
||||
}
|
||||
|
||||
func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
||||
runCcObjectTestCase(t, bp2buildTestCase{
|
||||
description: "cc_object setting srcs based on linux and bionic archs",
|
||||
blueprint: `cc_object {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting srcs based on linux and bionic archs",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
target: {
|
||||
@@ -400,8 +400,8 @@ func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
expectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", attrNameToString{
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["base.cpp"] + select({
|
||||
"//build/bazel/platforms/os_arch:android_arm64": [
|
||||
|
Reference in New Issue
Block a user