2019-02-26 01:40:34 +01:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2023-05-11 17:39:27 +02:00
|
|
|
package apex
|
2019-02-26 01:40:34 +01:00
|
|
|
|
|
|
|
import (
|
2023-05-10 19:38:34 +02:00
|
|
|
"fmt"
|
2019-02-26 01:40:34 +01:00
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2023-05-11 17:39:27 +02:00
|
|
|
"android/soong/java"
|
2019-02-26 01:40:34 +01:00
|
|
|
)
|
|
|
|
|
2023-05-10 19:38:34 +02:00
|
|
|
func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string, preferPrebuilt bool) {
|
2019-02-26 01:40:34 +01:00
|
|
|
bp := `
|
2023-05-10 19:38:34 +02:00
|
|
|
// Platform.
|
|
|
|
|
2019-02-26 01:40:34 +01:00
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
2021-04-09 18:41:24 +02:00
|
|
|
system_ext_specific: true,
|
2019-02-26 01:40:34 +01:00
|
|
|
}
|
2019-02-22 03:12:14 +01:00
|
|
|
|
|
|
|
dex_import {
|
|
|
|
name: "baz",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
}
|
2021-04-30 00:36:12 +02:00
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "platform-bootclasspath",
|
2023-05-10 19:38:34 +02:00
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
apex: "com.android.art",
|
|
|
|
module: "art-bootclasspath-fragment",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
// Source ART APEX.
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "core-oj",
|
|
|
|
srcs: ["core-oj.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "art-bootclasspath-fragment",
|
|
|
|
image_name: "art",
|
|
|
|
contents: ["core-oj"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.art.key",
|
|
|
|
public_key: "com.android.art.avbpubkey",
|
|
|
|
private_key: "com.android.art.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "com.android.art",
|
|
|
|
key: "com.android.art.key",
|
|
|
|
bootclasspath_fragments: ["art-bootclasspath-fragment"],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prebuilt ART APEX.
|
|
|
|
|
|
|
|
java_import {
|
|
|
|
name: "core-oj",
|
|
|
|
prefer: %[1]t,
|
|
|
|
jars: ["core-oj.jar"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt_bootclasspath_fragment {
|
|
|
|
name: "art-bootclasspath-fragment",
|
|
|
|
prefer: %[1]t,
|
|
|
|
image_name: "art",
|
|
|
|
contents: ["core-oj"],
|
|
|
|
hidden_api: {
|
|
|
|
annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv",
|
|
|
|
metadata: "my-bootclasspath-fragment/metadata.csv",
|
|
|
|
index: "my-bootclasspath-fragment/index.csv",
|
|
|
|
stub_flags: "my-bootclasspath-fragment/stub-flags.csv",
|
|
|
|
all_flags: "my-bootclasspath-fragment/all-flags.csv",
|
|
|
|
},
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt_apex {
|
|
|
|
name: "com.android.art",
|
|
|
|
prefer: %[1]t,
|
|
|
|
apex_name: "com.android.art",
|
|
|
|
src: "com.android.art-arm.apex",
|
|
|
|
exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
|
2021-04-30 00:36:12 +02:00
|
|
|
}
|
2019-02-26 01:40:34 +01:00
|
|
|
`
|
|
|
|
|
2021-03-22 16:36:52 +01:00
|
|
|
result := android.GroupFixturePreparers(
|
2023-05-11 17:39:27 +02:00
|
|
|
java.PrepareForTestWithDexpreopt,
|
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
java.FixtureWithLastReleaseApis("foo"),
|
2023-05-10 19:38:34 +02:00
|
|
|
java.FixtureConfigureBootJars("com.android.art:core-oj", "platform:foo", "system_ext:bar", "platform:baz"),
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
prepareForTestWithArtApex,
|
|
|
|
).RunTestWithBp(t, fmt.Sprintf(bp, preferPrebuilt))
|
2019-02-26 01:40:34 +01:00
|
|
|
|
2023-07-13 12:03:38 +02:00
|
|
|
dexBootJars := result.ModuleForTests("dex_bootjars", "android_common")
|
|
|
|
rule := dexBootJars.Output(ruleFile)
|
2019-02-26 01:40:34 +01:00
|
|
|
|
2020-05-19 12:15:44 +02:00
|
|
|
inputs := rule.Implicits.Strings()
|
2019-02-26 01:40:34 +01:00
|
|
|
sort.Strings(inputs)
|
|
|
|
sort.Strings(expectedInputs)
|
|
|
|
|
2020-05-19 12:15:44 +02:00
|
|
|
outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings()
|
|
|
|
sort.Strings(outputs)
|
|
|
|
sort.Strings(expectedOutputs)
|
|
|
|
|
2021-03-22 17:24:19 +01:00
|
|
|
android.AssertStringPathsRelativeToTopEquals(t, "inputs", result.Config, expectedInputs, inputs)
|
2019-02-26 01:40:34 +01:00
|
|
|
|
2021-03-22 17:24:19 +01:00
|
|
|
android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs)
|
2020-05-19 12:15:44 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 19:38:34 +02:00
|
|
|
func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) {
|
2023-07-11 15:31:22 +02:00
|
|
|
ruleFile := "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art"
|
2023-05-10 19:38:34 +02:00
|
|
|
|
|
|
|
expectedInputs := []string{
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar",
|
2023-07-13 12:03:38 +02:00
|
|
|
"out/soong/.intermediates/art-bootclasspath-fragment/android_common_apex10000/art-bootclasspath-fragment/boot.prof",
|
|
|
|
"out/soong/.intermediates/default/java/dex_bootjars/android_common/boot/boot.prof",
|
2023-05-10 19:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedOutputs := []string{
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
|
|
|
|
}
|
|
|
|
|
|
|
|
testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only difference is that the ART profile should be deapexed from the prebuilt APEX. Other
|
|
|
|
// inputs and outputs should be the same as above.
|
|
|
|
func TestDexpreoptBootJarsWithPrebuiltArtApex(t *testing.T) {
|
2023-07-11 15:31:22 +02:00
|
|
|
ruleFile := "out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art"
|
2020-05-19 12:15:44 +02:00
|
|
|
|
|
|
|
expectedInputs := []string{
|
2023-05-10 19:38:34 +02:00
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar",
|
|
|
|
"out/soong/.intermediates/com.android.art.deapexer/android_common/deapexer/etc/boot-image.prof",
|
2023-07-13 12:03:38 +02:00
|
|
|
"out/soong/.intermediates/default/java/dex_bootjars/android_common/boot/boot.prof",
|
2020-05-19 12:15:44 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:40:34 +01:00
|
|
|
expectedOutputs := []string{
|
2023-05-10 19:38:34 +02:00
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
|
2019-02-26 01:40:34 +01:00
|
|
|
}
|
|
|
|
|
2023-05-10 19:38:34 +02:00
|
|
|
testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, true)
|
2020-05-19 12:15:44 +02:00
|
|
|
}
|
2019-02-26 01:40:34 +01:00
|
|
|
|
2020-05-19 12:15:44 +02:00
|
|
|
// Changes to the boot.zip structure may break the ART APK scanner.
|
|
|
|
func TestDexpreoptBootZip(t *testing.T) {
|
|
|
|
ruleFile := "boot.zip"
|
2019-02-26 01:40:34 +01:00
|
|
|
|
2021-03-22 17:24:19 +01:00
|
|
|
ctx := android.PathContextForTesting(android.TestArchConfig("", nil, "", nil))
|
2020-05-20 14:47:13 +02:00
|
|
|
expectedInputs := []string{}
|
2020-06-10 16:44:25 +02:00
|
|
|
for _, target := range ctx.Config().Targets[android.Android] {
|
2020-05-20 14:47:13 +02:00
|
|
|
for _, ext := range []string{".art", ".oat", ".vdex"} {
|
2023-05-10 19:38:34 +02:00
|
|
|
for _, suffix := range []string{"", "-foo", "-bar", "-baz"} {
|
2020-05-20 14:47:13 +02:00
|
|
|
expectedInputs = append(expectedInputs,
|
2023-05-10 19:38:34 +02:00
|
|
|
filepath.Join(
|
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars",
|
|
|
|
target.Os.String(),
|
|
|
|
"system/framework",
|
|
|
|
target.Arch.ArchType.String(),
|
|
|
|
"boot"+suffix+ext))
|
2020-05-20 14:47:13 +02:00
|
|
|
}
|
|
|
|
}
|
2019-02-26 01:40:34 +01:00
|
|
|
}
|
2020-05-19 12:15:44 +02:00
|
|
|
|
|
|
|
expectedOutputs := []string{
|
2023-05-10 19:38:34 +02:00
|
|
|
"out/soong/dexpreopt_arm64/dex_bootjars/boot.zip",
|
2020-05-19 12:15:44 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 19:38:34 +02:00
|
|
|
testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false)
|
2019-02-26 01:40:34 +01:00
|
|
|
}
|