Give cc_test rule information to determine the test types
There are three types of tests, deviceless tests, device-driven tests and host-driven device tests. But currently we don't have information to get the type of a test and can't generate test targets on desired types. Test: b test //platform_testing/tests/example/native:hello_world_test Test: b test //packages/modules/adb:adbd_test Bug: 296312548 Change-Id: I3f022ef769636d508e055477623a4d1a6a1d9044
This commit is contained in:
@@ -689,3 +689,21 @@ func AttachValidationActions(ctx ModuleContext, outputFilePath Path, validations
|
|||||||
})
|
})
|
||||||
return validatedOutputFilePath
|
return validatedOutputFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RunsOn(hostSupported bool, deviceSupported bool, unitTest bool) []string {
|
||||||
|
var runsOn []string
|
||||||
|
|
||||||
|
if hostSupported && deviceSupported {
|
||||||
|
runsOn = []string{"host_without_device", "device"}
|
||||||
|
} else if hostSupported {
|
||||||
|
if unitTest {
|
||||||
|
runsOn = []string{"host_without_device"}
|
||||||
|
} else {
|
||||||
|
runsOn = []string{"host_with_device"}
|
||||||
|
}
|
||||||
|
} else if deviceSupported {
|
||||||
|
runsOn = []string{"device"}
|
||||||
|
}
|
||||||
|
|
||||||
|
return runsOn
|
||||||
|
}
|
||||||
|
@@ -135,6 +135,10 @@ cc_test_library {
|
|||||||
"//build/bazel/platforms/os:linux_musl": ["linux.cpp"],
|
"//build/bazel/platforms/os:linux_musl": ["linux.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
})`,
|
})`,
|
||||||
|
"runs_on": `[
|
||||||
|
"host_without_device",
|
||||||
|
"device",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -158,6 +162,10 @@ cc_test {
|
|||||||
"gtest": "False",
|
"gtest": "False",
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
|
"runs_on": `[
|
||||||
|
"host_without_device",
|
||||||
|
"device",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -184,6 +192,10 @@ cc_test {
|
|||||||
"deps": `[
|
"deps": `[
|
||||||
":libgtest_main",
|
":libgtest_main",
|
||||||
":libgtest",
|
":libgtest",
|
||||||
|
]`,
|
||||||
|
"runs_on": `[
|
||||||
|
"host_without_device",
|
||||||
|
"device",
|
||||||
]`,
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -215,6 +227,7 @@ cc_test {
|
|||||||
":libgtest_main",
|
":libgtest_main",
|
||||||
":libgtest",
|
":libgtest",
|
||||||
]`,
|
]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -244,6 +257,7 @@ cc_test {
|
|||||||
":libgtest_main",
|
":libgtest_main",
|
||||||
":libgtest",
|
":libgtest",
|
||||||
]`,
|
]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -280,6 +294,7 @@ cc_test {
|
|||||||
"template_test_config": `"test_config_template.xml"`,
|
"template_test_config": `"test_config_template.xml"`,
|
||||||
"deps": `[":libgtest_isolated_main"]`,
|
"deps": `[":libgtest_isolated_main"]`,
|
||||||
"dynamic_deps": `[":liblog"]`,
|
"dynamic_deps": `[":liblog"]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -306,6 +321,7 @@ cc_test {
|
|||||||
":libgtest",
|
":libgtest",
|
||||||
":libgtest_main",
|
":libgtest_main",
|
||||||
]`,
|
]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -331,6 +347,7 @@ cc_test {
|
|||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
"deps": `[":libgtest_isolated_main"]`,
|
"deps": `[":libgtest_isolated_main"]`,
|
||||||
"dynamic_deps": `[":liblog"]`,
|
"dynamic_deps": `[":liblog"]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -361,12 +378,14 @@ cc_test {
|
|||||||
]`,
|
]`,
|
||||||
"gtest": "True",
|
"gtest": "True",
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
|
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"gtest": "False",
|
"gtest": "False",
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
"runs_on": `["device"]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
10
cc/test.go
10
cc/test.go
@@ -686,6 +686,8 @@ type testBinaryAttributes struct {
|
|||||||
|
|
||||||
tidyAttributes
|
tidyAttributes
|
||||||
tradefed.TestConfigAttributes
|
tradefed.TestConfigAttributes
|
||||||
|
|
||||||
|
Runs_on bazel.StringListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
// testBinaryBp2build is the bp2build converter for cc_test modules. A cc_test's
|
// testBinaryBp2build is the bp2build converter for cc_test modules. A cc_test's
|
||||||
@@ -730,6 +732,8 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
|
|
||||||
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
|
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
|
||||||
|
|
||||||
|
var unitTest *bool
|
||||||
|
|
||||||
for _, testProps := range m.GetProperties() {
|
for _, testProps := range m.GetProperties() {
|
||||||
if p, ok := testProps.(*TestBinaryProperties); ok {
|
if p, ok := testProps.(*TestBinaryProperties); ok {
|
||||||
useVendor := false // TODO Bug: 262914724
|
useVendor := false // TODO Bug: 262914724
|
||||||
@@ -745,9 +749,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
&testInstallBase,
|
&testInstallBase,
|
||||||
)
|
)
|
||||||
testBinaryAttrs.TestConfigAttributes = testConfigAttributes
|
testBinaryAttrs.TestConfigAttributes = testConfigAttributes
|
||||||
|
unitTest = p.Test_options.Unit_test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBinaryAttrs.Runs_on = bazel.MakeStringListAttribute(android.RunsOn(
|
||||||
|
m.ModuleBase.HostSupported(),
|
||||||
|
m.ModuleBase.DeviceSupported(),
|
||||||
|
gtest || (unitTest != nil && *unitTest)))
|
||||||
|
|
||||||
// TODO (b/262914724): convert to tradefed_cc_test and tradefed_cc_test_host
|
// TODO (b/262914724): convert to tradefed_cc_test and tradefed_cc_test_host
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{
|
bazel.BazelTargetModuleProperties{
|
||||||
|
Reference in New Issue
Block a user