2021-01-20 16:16:56 +01:00
|
|
|
// Copyright (C) 2021 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package apex
|
|
|
|
|
|
|
|
import (
|
2021-01-21 19:13:43 +01:00
|
|
|
"strings"
|
2021-01-20 16:16:56 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/java"
|
|
|
|
)
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
|
|
|
|
// bootclasspath_fragment requires modules from the ART apex.
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
|
2021-03-24 00:40:12 +01:00
|
|
|
java.PrepareForTestWithDexpreopt,
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Some additional files needed for the art apex.
|
|
|
|
var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{
|
|
|
|
"com.android.art.avbpubkey": nil,
|
|
|
|
"com.android.art.pem": nil,
|
|
|
|
"system/sepolicy/apex/com.android.art-file_contexts": nil,
|
|
|
|
})
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
func TestBootclasspathFragments(t *testing.T) {
|
2021-03-24 00:40:12 +01:00
|
|
|
result := android.GroupFixturePreparers(
|
2021-04-20 13:40:07 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-04-23 15:25:28 +02:00
|
|
|
// Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
|
2021-04-12 21:02:36 +02:00
|
|
|
java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
|
2021-03-24 00:40:12 +01:00
|
|
|
prepareForTestWithArtApex,
|
|
|
|
|
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
java.FixtureWithLastReleaseApis("foo"),
|
2021-03-09 15:13:25 +01:00
|
|
|
).RunTestWithBp(t, `
|
2021-01-20 16:16:56 +01:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "com.android.art",
|
|
|
|
key: "com.android.art.key",
|
|
|
|
java_libs: [
|
|
|
|
"baz",
|
|
|
|
"quuz",
|
|
|
|
],
|
2021-02-16 12:40:16 +01:00
|
|
|
updatable: false,
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.art.key",
|
|
|
|
public_key: "com.android.art.avbpubkey",
|
|
|
|
private_key: "com.android.art.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "quuz",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
2021-01-30 13:57:26 +01:00
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "art-bootclasspath-fragment",
|
2021-01-30 13:57:26 +01:00
|
|
|
image_name: "art",
|
2021-03-24 00:21:59 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
2021-01-30 13:57:26 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "framework-bootclasspath-fragment",
|
2021-01-30 13:57:26 +01:00
|
|
|
image_name: "boot",
|
|
|
|
}
|
2021-01-20 16:16:56 +01:00
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
// Make sure that the framework-bootclasspath-fragment is using the correct configuration.
|
|
|
|
checkBootclasspathFragment(t, result, "framework-bootclasspath-fragment", "platform:foo,platform:bar", `
|
2021-01-21 19:13:43 +01:00
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-bar.art
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat
|
|
|
|
test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
|
|
|
|
`)
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
// Make sure that the art-bootclasspath-fragment is using the correct configuration.
|
|
|
|
checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "com.android.art:baz,com.android.art:quuz", `
|
2021-01-21 19:13:43 +01:00
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
|
|
|
|
test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
|
|
|
|
`)
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
|
2021-01-20 16:16:56 +01:00
|
|
|
t.Helper()
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspathFragment := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootclasspathFragmentModule)
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
bootImageInfo := result.ModuleProvider(bootclasspathFragment, java.BootImageInfoProvider).(java.BootImageInfo)
|
2021-01-20 16:16:56 +01:00
|
|
|
modules := bootImageInfo.Modules()
|
2021-03-09 15:13:25 +01:00
|
|
|
android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
|
2021-01-21 19:13:43 +01:00
|
|
|
|
|
|
|
// Get a list of all the paths in the boot image sorted by arch type.
|
|
|
|
allPaths := []string{}
|
|
|
|
bootImageFilesByArchType := bootImageInfo.AndroidBootImageFilesByArchType()
|
|
|
|
for _, archType := range android.ArchTypeList() {
|
|
|
|
if paths, ok := bootImageFilesByArchType[archType]; ok {
|
|
|
|
for _, path := range paths {
|
|
|
|
allPaths = append(allPaths, android.NormalizePathForTesting(path))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
2021-01-21 19:13:43 +01:00
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
func TestBootclasspathFragmentInArtApex(t *testing.T) {
|
2021-03-24 00:40:12 +01:00
|
|
|
result := android.GroupFixturePreparers(
|
2021-04-20 13:40:07 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-03-23 23:53:07 +01:00
|
|
|
prepareForTestWithArtApex,
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Configure some libraries in the art bootclasspath_fragment.
|
2021-04-12 21:02:36 +02:00
|
|
|
java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
|
2021-03-09 15:13:25 +01:00
|
|
|
).RunTestWithBp(t, `
|
2021-01-21 19:13:43 +01:00
|
|
|
apex {
|
2021-03-23 23:53:07 +01:00
|
|
|
name: "com.android.art",
|
|
|
|
key: "com.android.art.key",
|
2021-04-20 13:40:07 +02:00
|
|
|
bootclasspath_fragments: [
|
|
|
|
"mybootclasspathfragment",
|
2021-01-21 19:13:43 +01:00
|
|
|
],
|
2021-03-24 16:42:20 +01:00
|
|
|
// bar (like foo) should be transitively included in this apex because it is part of the
|
2021-04-23 15:25:28 +02:00
|
|
|
// mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
|
|
|
|
// apex dedups the files correctly.
|
2021-03-23 23:53:07 +01:00
|
|
|
java_libs: [
|
|
|
|
"bar",
|
|
|
|
],
|
2021-02-16 12:40:16 +01:00
|
|
|
updatable: false,
|
2021-01-21 19:13:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
2021-03-23 23:53:07 +01:00
|
|
|
name: "com.android.art.key",
|
2021-01-21 19:13:43 +01:00
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
2021-03-23 23:53:07 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
2021-01-21 19:13:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
2021-03-23 23:53:07 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
2021-01-21 19:13:43 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspath_fragment {
|
2021-04-20 13:40:07 +02:00
|
|
|
name: "mybootclasspathfragment",
|
2021-03-23 23:53:07 +01:00
|
|
|
image_name: "art",
|
2021-01-21 19:13:43 +01:00
|
|
|
apex_available: [
|
2021-03-23 23:53:07 +01:00
|
|
|
"com.android.art",
|
2021-01-21 19:13:43 +01:00
|
|
|
],
|
|
|
|
}
|
2021-03-18 19:30:31 +01:00
|
|
|
|
2021-04-20 23:47:03 +02:00
|
|
|
java_import {
|
|
|
|
name: "foo",
|
|
|
|
jars: ["foo.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "bar",
|
|
|
|
jars: ["bar.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:30:31 +01:00
|
|
|
// Make sure that a preferred prebuilt doesn't affect the apex.
|
2021-04-23 15:25:28 +02:00
|
|
|
prebuilt_bootclasspath_fragment {
|
2021-04-20 13:40:07 +02:00
|
|
|
name: "mybootclasspathfragment",
|
2021-03-23 23:53:07 +01:00
|
|
|
image_name: "art",
|
2021-03-18 19:30:31 +01:00
|
|
|
prefer: true,
|
|
|
|
apex_available: [
|
2021-03-23 23:53:07 +01:00
|
|
|
"com.android.art",
|
2021-03-18 19:30:31 +01:00
|
|
|
],
|
|
|
|
}
|
2021-03-09 15:13:25 +01:00
|
|
|
`)
|
2021-01-21 19:13:43 +01:00
|
|
|
|
2021-03-23 23:53:07 +01:00
|
|
|
ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
|
|
|
|
"javalib/arm/boot.art",
|
|
|
|
"javalib/arm/boot.oat",
|
|
|
|
"javalib/arm/boot.vdex",
|
2021-01-21 19:13:43 +01:00
|
|
|
"javalib/arm/boot-bar.art",
|
|
|
|
"javalib/arm/boot-bar.oat",
|
|
|
|
"javalib/arm/boot-bar.vdex",
|
2021-03-23 23:53:07 +01:00
|
|
|
"javalib/arm64/boot.art",
|
|
|
|
"javalib/arm64/boot.oat",
|
|
|
|
"javalib/arm64/boot.vdex",
|
2021-01-21 19:13:43 +01:00
|
|
|
"javalib/arm64/boot-bar.art",
|
|
|
|
"javalib/arm64/boot-bar.oat",
|
|
|
|
"javalib/arm64/boot-bar.vdex",
|
2021-03-23 23:53:07 +01:00
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/foo.jar",
|
2021-01-21 19:13:43 +01:00
|
|
|
})
|
2021-03-18 19:30:31 +01:00
|
|
|
|
2021-03-23 23:53:07 +01:00
|
|
|
java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
|
|
|
|
`bar`,
|
|
|
|
`com.android.art.key`,
|
2021-04-20 13:40:07 +02:00
|
|
|
`mybootclasspathfragment`,
|
2021-03-18 19:30:31 +01:00
|
|
|
})
|
2021-01-21 19:13:43 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
|
2021-03-23 23:53:07 +01:00
|
|
|
result := android.GroupFixturePreparers(
|
2021-04-20 13:40:07 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-03-23 23:53:07 +01:00
|
|
|
prepareForTestWithArtApex,
|
|
|
|
|
|
|
|
android.FixtureMergeMockFs(android.MockFS{
|
|
|
|
"com.android.art-arm64.apex": nil,
|
|
|
|
"com.android.art-arm.apex": nil,
|
|
|
|
}),
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Configure some libraries in the art bootclasspath_fragment.
|
2021-04-12 21:02:36 +02:00
|
|
|
java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
|
2021-03-23 23:53:07 +01:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
prebuilt_apex {
|
|
|
|
name: "com.android.art",
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
src: "com.android.art-arm64.apex",
|
|
|
|
},
|
|
|
|
arm: {
|
|
|
|
src: "com.android.art-arm.apex",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
exported_java_libs: ["foo", "bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "foo",
|
|
|
|
jars: ["foo.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "bar",
|
|
|
|
jars: ["bar.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
prebuilt_bootclasspath_fragment {
|
2021-04-20 13:40:07 +02:00
|
|
|
name: "mybootclasspathfragment",
|
2021-03-23 23:53:07 +01:00
|
|
|
image_name: "art",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{
|
2021-03-01 15:14:52 +01:00
|
|
|
`com.android.art.apex.selector`,
|
2021-03-23 23:53:07 +01:00
|
|
|
`prebuilt_bar`,
|
|
|
|
`prebuilt_foo`,
|
|
|
|
})
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{
|
2021-03-23 23:53:07 +01:00
|
|
|
`dex2oatd`,
|
2021-03-24 00:21:59 +01:00
|
|
|
`prebuilt_bar`,
|
|
|
|
`prebuilt_foo`,
|
2021-03-23 23:53:07 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:40:07 +02:00
|
|
|
func TestBootclasspathFragmentContentsNoName(t *testing.T) {
|
2021-03-24 02:34:57 +01:00
|
|
|
result := android.GroupFixturePreparers(
|
2021-04-20 13:40:07 +02:00
|
|
|
prepareForTestWithBootclasspathFragment,
|
2021-03-24 02:34:57 +01:00
|
|
|
prepareForTestWithMyapex,
|
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2021-04-20 13:40:07 +02:00
|
|
|
bootclasspath_fragments: [
|
|
|
|
"mybootclasspathfragment",
|
2021-03-24 02:34:57 +01:00
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspath_fragment {
|
2021-04-20 13:40:07 +02:00
|
|
|
name: "mybootclasspathfragment",
|
2021-03-24 02:34:57 +01:00
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
"bar",
|
|
|
|
],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2021-03-24 16:42:20 +01:00
|
|
|
ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
|
|
|
|
// This does not include art, oat or vdex files as they are only included for the art boot
|
|
|
|
// image.
|
|
|
|
"javalib/bar.jar",
|
|
|
|
"javalib/foo.jar",
|
|
|
|
})
|
2021-03-24 02:34:57 +01:00
|
|
|
|
|
|
|
java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
|
|
|
|
`myapex.key`,
|
2021-04-20 13:40:07 +02:00
|
|
|
`mybootclasspathfragment`,
|
2021-03-24 02:34:57 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-21 19:13:43 +01:00
|
|
|
// TODO(b/177892522) - add test for host apex.
|