Merge "Set targetSdkVersion to 10000 for MTS tests targeting current"
This commit is contained in:
commit
0264058aea
3 changed files with 88 additions and 1 deletions
|
@ -45,7 +45,11 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
|||
// This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK
|
||||
func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext android.SdkContext) string {
|
||||
targetSdkVersionSpec := sdkContext.TargetSdkVersion(ctx)
|
||||
if ctx.Config().UnbundledBuildApps() && targetSdkVersionSpec.ApiLevel.IsPreview() {
|
||||
// Return 10000 for modules targeting "current" if either
|
||||
// 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty)
|
||||
// 2. The module is run as part of MTS, and should be testable on stable branches
|
||||
// TODO(b/240294501): Determine the rules for handling test apexes
|
||||
if targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module())) {
|
||||
return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt())
|
||||
}
|
||||
targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx)
|
||||
|
@ -55,6 +59,15 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, sdkContext andr
|
|||
return targetSdkVersion
|
||||
}
|
||||
|
||||
// Helper function that casts android.Module to java.androidTestApp
|
||||
// If this type conversion is possible, it queries whether the test app is included in an MTS suite
|
||||
func includedInMts(module android.Module) bool {
|
||||
if test, ok := module.(androidTestApp); ok {
|
||||
return test.includedInTestSuite("mts")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type ManifestFixerParams struct {
|
||||
SdkContext android.SdkContext
|
||||
ClassLoaderContexts dexpreopt.ClassLoaderContextMap
|
||||
|
|
12
java/app.go
12
java/app.go
|
@ -962,6 +962,18 @@ func (a *AndroidTest) InstallInTestcases() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
type androidTestApp interface {
|
||||
includedInTestSuite(searchPrefix string) bool
|
||||
}
|
||||
|
||||
func (a *AndroidTest) includedInTestSuite(searchPrefix string) bool {
|
||||
return android.PrefixInList(a.testProperties.Test_suites, searchPrefix)
|
||||
}
|
||||
|
||||
func (a *AndroidTestHelperApp) includedInTestSuite(searchPrefix string) bool {
|
||||
return android.PrefixInList(a.appTestHelperAppProperties.Test_suites, searchPrefix)
|
||||
}
|
||||
|
||||
func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
var configs []tradefed.Config
|
||||
if a.appTestProperties.Instrumentation_target_package != nil {
|
||||
|
|
|
@ -3160,3 +3160,65 @@ func TestAppIncludesJniPackages(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetSdkVersionMtsTests(t *testing.T) {
|
||||
platformSdkCodename := "Tiramisu"
|
||||
android_test := "android_test"
|
||||
android_test_helper_app := "android_test_helper_app"
|
||||
bpTemplate := `
|
||||
%v {
|
||||
name: "mytest",
|
||||
target_sdk_version: "%v",
|
||||
test_suites: ["othersuite", "%v"],
|
||||
}
|
||||
`
|
||||
testCases := []struct {
|
||||
desc string
|
||||
moduleType string
|
||||
targetSdkVersionInBp string
|
||||
targetSdkVersionExpected string
|
||||
testSuites string
|
||||
}{
|
||||
{
|
||||
desc: "Non-MTS android_test_apps targeting current should not be upgraded to 10000",
|
||||
moduleType: android_test,
|
||||
targetSdkVersionInBp: "current",
|
||||
targetSdkVersionExpected: platformSdkCodename,
|
||||
testSuites: "non-mts-suite",
|
||||
},
|
||||
{
|
||||
desc: "MTS android_test_apps targeting released sdks should not be upgraded to 10000",
|
||||
moduleType: android_test,
|
||||
targetSdkVersionInBp: "29",
|
||||
targetSdkVersionExpected: "29",
|
||||
testSuites: "mts-suite",
|
||||
},
|
||||
{
|
||||
desc: "MTS android_test_apps targeting current should be upgraded to 10000",
|
||||
moduleType: android_test,
|
||||
targetSdkVersionInBp: "current",
|
||||
targetSdkVersionExpected: "10000",
|
||||
testSuites: "mts-suite",
|
||||
},
|
||||
{
|
||||
desc: "MTS android_test_helper_apps targeting current should be upgraded to 10000",
|
||||
moduleType: android_test_helper_app,
|
||||
targetSdkVersionInBp: "current",
|
||||
targetSdkVersionExpected: "10000",
|
||||
testSuites: "mts-suite",
|
||||
},
|
||||
}
|
||||
fixture := android.GroupFixturePreparers(
|
||||
prepareForJavaTest,
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
variables.Platform_sdk_codename = &platformSdkCodename
|
||||
variables.Platform_version_active_codenames = []string{platformSdkCodename}
|
||||
}),
|
||||
)
|
||||
for _, testCase := range testCases {
|
||||
result := fixture.RunTestWithBp(t, fmt.Sprintf(bpTemplate, testCase.moduleType, testCase.targetSdkVersionInBp, testCase.testSuites))
|
||||
mytest := result.ModuleForTests("mytest", "android_common")
|
||||
manifestFixerArgs := mytest.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
|
||||
android.AssertStringDoesContain(t, testCase.desc, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue