Enforce that tests in MTS specify a min_sdk_version
Specifying min_sdk_version ensures backwards compatibility. There are some existing violations, and those have been baseline'd using an allowlist. Bug: 156476221 Test: m nothing Change-Id: I55098206da8ec5cfa0a9f5e7b41c9b8dedbdcbd2
This commit is contained in:
@@ -71,12 +71,15 @@ func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionLev
|
|||||||
return targetSdkVersionLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module()))
|
return targetSdkVersionLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function that casts android.Module to java.androidTestApp
|
// Helper function that returns true if android_test, android_test_helper_app, java_test are in an MTS suite.
|
||||||
// If this type conversion is possible, it queries whether the test app is included in an MTS suite
|
|
||||||
func includedInMts(module android.Module) bool {
|
func includedInMts(module android.Module) bool {
|
||||||
if test, ok := module.(androidTestApp); ok {
|
if test, ok := module.(androidTestApp); ok {
|
||||||
return test.includedInTestSuite("mts")
|
return test.includedInTestSuite("mts")
|
||||||
}
|
}
|
||||||
|
// java_test
|
||||||
|
if test, ok := module.(*Test); ok {
|
||||||
|
return android.PrefixInList(test.testProperties.Test_suites, "mts")
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
java/app.go
29
java/app.go
@@ -345,7 +345,35 @@ func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutato
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(b/156476221): Remove this allowlist
|
||||||
|
var (
|
||||||
|
missingMinSdkVersionMtsAllowlist = []string{
|
||||||
|
"CellBroadcastReceiverGoogleUnitTests",
|
||||||
|
"CellBroadcastReceiverUnitTests",
|
||||||
|
"CtsBatterySavingTestCases",
|
||||||
|
"CtsDeviceAndProfileOwnerApp23",
|
||||||
|
"CtsDeviceAndProfileOwnerApp30",
|
||||||
|
"CtsIntentSenderApp",
|
||||||
|
"CtsJobSchedulerTestCases",
|
||||||
|
"CtsMimeMapTestCases",
|
||||||
|
"CtsTareTestCases",
|
||||||
|
"LibStatsPullTests",
|
||||||
|
"MediaProviderClientTests",
|
||||||
|
"TeleServiceTests",
|
||||||
|
"TestExternalImsServiceApp",
|
||||||
|
"TestSmsRetrieverApp",
|
||||||
|
"TetheringPrivilegedTests",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkMinSdkVersionMts(ctx android.ModuleContext, minSdkVersion android.ApiLevel) {
|
||||||
|
if includedInMts(ctx.Module()) && !minSdkVersion.Specified() && !android.InList(ctx.ModuleName(), missingMinSdkVersionMtsAllowlist) {
|
||||||
|
ctx.PropertyErrorf("min_sdk_version", "min_sdk_version is a required property for tests included in MTS")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
checkMinSdkVersionMts(ctx, a.MinSdkVersion(ctx))
|
||||||
applicationId := a.appTestHelperAppProperties.Manifest_values.ApplicationId
|
applicationId := a.appTestHelperAppProperties.Manifest_values.ApplicationId
|
||||||
if applicationId != nil {
|
if applicationId != nil {
|
||||||
if a.overridableAppProperties.Package_name != nil {
|
if a.overridableAppProperties.Package_name != nil {
|
||||||
@@ -1366,6 +1394,7 @@ func (a *AndroidTestHelperApp) includedInTestSuite(searchPrefix string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
checkMinSdkVersionMts(ctx, a.MinSdkVersion(ctx))
|
||||||
var configs []tradefed.Config
|
var configs []tradefed.Config
|
||||||
if a.appTestProperties.Instrumentation_target_package != nil {
|
if a.appTestProperties.Instrumentation_target_package != nil {
|
||||||
a.additionalAaptFlags = append(a.additionalAaptFlags,
|
a.additionalAaptFlags = append(a.additionalAaptFlags,
|
||||||
|
@@ -4146,6 +4146,7 @@ func TestTargetSdkVersionMtsTests(t *testing.T) {
|
|||||||
bpTemplate := `
|
bpTemplate := `
|
||||||
%v {
|
%v {
|
||||||
name: "mytest",
|
name: "mytest",
|
||||||
|
min_sdk_version: "34",
|
||||||
target_sdk_version: "%v",
|
target_sdk_version: "%v",
|
||||||
test_suites: ["othersuite", "%v"],
|
test_suites: ["othersuite", "%v"],
|
||||||
}
|
}
|
||||||
|
@@ -1510,6 +1510,7 @@ func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
checkMinSdkVersionMts(ctx, j.MinSdkVersion(ctx))
|
||||||
j.generateAndroidBuildActionsWithConfig(ctx, nil)
|
j.generateAndroidBuildActionsWithConfig(ctx, nil)
|
||||||
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
|
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user