platform_build_soong/java/dexpreopt_bootjars_test.go
Ulya Trafimovich 9ab4933a1c Remove host boot image from boot.zip.
Host boot image is not needed in boot.zip, which is used for the ART
APK scanner and runs on target. This commit also changes the paths in
the boot.zip by removing OS subdirectory.

Test: lunch aosp_cf_x86_phone-userdebug && m
Test: m out/soong/vsoc_x86/dex_bootjars/boot.zip \
    && zipinfo -1 out/soong/vsoc_x86/dex_bootjars/boot.zip
    system/framework/x86/boot-framework.art
    system/framework/x86/boot-framework.oat
    system/framework/x86/boot-ext.art
    system/framework/x86/boot-ext.oat
    system/framework/x86/boot-core-icu4j.art
    system/framework/x86/boot-core-icu4j.oat
    system/framework/x86/boot-telephony-common.art
    system/framework/x86/boot-telephony-common.oat
    system/framework/x86/boot-voip-common.art
    system/framework/x86/boot-voip-common.oat
    system/framework/x86/boot-ims-common.art
    system/framework/x86/boot-ims-common.oat
    system/framework/x86/boot-framework-atb-backward-compatibility.art
    system/framework/x86/boot-framework-atb-backward-compatibility.oat
    system/framework/x86/boot-framework.vdex
    system/framework/x86/boot-ext.vdex
    system/framework/x86/boot-core-icu4j.vdex
    system/framework/x86/boot-telephony-common.vdex
    system/framework/x86/boot-voip-common.vdex
    system/framework/x86/boot-ims-common.vdex
    system/framework/x86/boot-framework-atb-backward-compatibility.vdex

Change-Id: Idf0541908059c454348181d90b0b3e5d6d350057
2020-06-10 15:54:23 +01:00

135 lines
4.1 KiB
Go

// 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.
package java
import (
"path/filepath"
"reflect"
"sort"
"testing"
"android/soong/android"
"android/soong/dexpreopt"
)
func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) {
bp := `
java_sdk_library {
name: "foo",
srcs: ["a.java"],
api_packages: ["foo"],
}
java_library {
name: "bar",
srcs: ["b.java"],
installable: true,
}
dex_import {
name: "baz",
jars: ["a.jar"],
}
`
config := testConfig(nil, bp, nil)
pathCtx := android.PathContextForTesting(config)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
dexpreoptConfig.BootJars = []string{"platform:foo", "platform:bar", "platform:baz"}
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext()
RegisterDexpreoptBootJarsComponents(ctx)
run(t, ctx, config)
dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
rule := dexpreoptBootJars.Output(ruleFile)
for i := range expectedInputs {
expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i])
}
for i := range expectedOutputs {
expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i])
}
inputs := rule.Implicits.Strings()
sort.Strings(inputs)
sort.Strings(expectedInputs)
outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings()
sort.Strings(outputs)
sort.Strings(expectedOutputs)
if !reflect.DeepEqual(inputs, expectedInputs) {
t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
}
if !reflect.DeepEqual(outputs, expectedOutputs) {
t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
}
}
func TestDexpreoptBootJars(t *testing.T) {
ruleFile := "boot-foo.art"
expectedInputs := []string{
"dex_artjars/android/apex/com.android.art/javalib/arm64/boot.art",
"dex_bootjars_input/foo.jar",
"dex_bootjars_input/bar.jar",
"dex_bootjars_input/baz.jar",
}
expectedOutputs := []string{
"dex_bootjars/android/system/framework/arm64/boot.invocation",
"dex_bootjars/android/system/framework/arm64/boot-foo.art",
"dex_bootjars/android/system/framework/arm64/boot-bar.art",
"dex_bootjars/android/system/framework/arm64/boot-baz.art",
"dex_bootjars/android/system/framework/arm64/boot-foo.oat",
"dex_bootjars/android/system/framework/arm64/boot-bar.oat",
"dex_bootjars/android/system/framework/arm64/boot-baz.oat",
"dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
"dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
"dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
"dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
"dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
"dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
}
testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
}
// Changes to the boot.zip structure may break the ART APK scanner.
func TestDexpreoptBootZip(t *testing.T) {
ruleFile := "boot.zip"
ctx := android.PathContextForTesting(testConfig(nil, "", nil))
expectedInputs := []string{}
for _, target := range ctx.Config().Targets[android.Android] {
for _, ext := range []string{".art", ".oat", ".vdex"} {
for _, jar := range []string{"foo", "bar", "baz"} {
expectedInputs = append(expectedInputs,
filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext))
}
}
}
expectedOutputs := []string{
"dex_bootjars/boot.zip",
}
testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
}