From 32edd1a60868cb8d6238a517cbb3e4d3ed6494ea Mon Sep 17 00:00:00 2001 From: Kevin Dagostino Date: Sun, 4 Dec 2022 11:16:42 +0000 Subject: [PATCH] Add tradefed attributes to cc_test bazel macro The BUILD file will now have the needed attributes to run the tradefed test rules. Test: b test //packages/modules/adb:adbd_test --platforms=//build/bazel/platforms:android_target Change-Id: I5cb84ccdde27a7fadbef479269df594344a29187 --- bp2build/cc_test_conversion_test.go | 90 ++++++++++++++++++- cc/test.go | 130 +++++++++++++++++----------- tradefed/Android.bp | 1 + tradefed/autogen_bazel.go | 105 ++++++++++++++++++++++ 4 files changed, 275 insertions(+), 51 deletions(-) create mode 100644 tradefed/autogen_bazel.go diff --git a/bp2build/cc_test_conversion_test.go b/bp2build/cc_test_conversion_test.go index 8c2d30d24..b20f6ffbc 100644 --- a/bp2build/cc_test_conversion_test.go +++ b/bp2build/cc_test_conversion_test.go @@ -26,6 +26,7 @@ import ( type ccTestBp2buildTestCase struct { description string blueprint string + filesystem map[string]string targets []testBazelTarget } @@ -41,12 +42,12 @@ func registerCcTestModuleTypes(ctx android.RegistrationContext) { func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) { t.Helper() moduleTypeUnderTest := "cc_test" - description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) t.Run(description, func(t *testing.T) { t.Helper() RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{ ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported), + Filesystem: testCase.filesystem, ModuleTypeUnderTest: moduleTypeUnderTest, ModuleTypeUnderTestFactory: cc.TestFactory, Description: description, @@ -172,3 +173,90 @@ cc_test { }, }) } + +func TestCcTest_TestConfig(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that sets a test_config", + filesystem: map[string]string{ + "test_config.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], + test_config: "test_config.xml", +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "test_config": `"test_config.xml"`, + }, + }, + }, + }) +} + +func TestCcTest_TestConfigAndroidTestXML(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that defaults to test config AndroidTest.xml", + filesystem: map[string]string{ + "AndroidTest.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "test_config": `"AndroidTest.xml"`, + }, + }, + }, + }) +} + +func TestCcTest_TestConfigTemplateOptions(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that sets test config template attributes", + filesystem: map[string]string{ + "test_config_template.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], + test_config_template: "test_config_template.xml", + auto_gen_config: true, +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "auto_generate_test_config": "True", + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "template_configs": `[ + "'\\n '", + "'