platform_build_soong/java/dexpreopt_bootjars_test.go
Ulya Trafimovich b28cc3758c Forbid generating boot image files for jars in updatable modules.
This is to guard against the potential situation when someone adds
updatable modules to the list of boot jars by mistake.

Test: aosp_walleye-userdebug builds.

Test: Manually break the checks and observe the errors:
  - move updatable module 'conscrypt' from
    PRODUCT_UPDATABLE_BOOT_JARS to ART_APEX_JARS:
      internal error: module 'conscrypt' from updatable apex 'com.android.conscrypt' is not allowed in the ART boot image

  - add updatable module 'conscrypt' to ART_APEX_JARS
    (but do not remove it from PRODUCT_UPDATABLE_BOOT_JARS):
      error: A jar in PRODUCT_UPDATABLE_BOOT_JARS must not be in PRODUCT_BOOT_JARS, but conscrypt is.

  - move updatable module 'framework-tethering' from
    PRODUCT_UPDATABLE_BOOT_JARS to PRODUCT_BOOT_JARS:
      internal error: module 'framework-tethering' from updatable apex 'com.android.tethering' is not allowed in the framework boot image

  - add non-updatable (in AOSP) module 'android.net.ipsec.ike'
    to PRODUCT_BOOT_JARS:
      internal error: failed to find a dex jar path for module 'com.android.ipsec.ike', note that some jars may be filtered out by module constraints

Bug: 147579140

Change-Id: I25ca2f52530fcfa1f9823b2cfa3485db9c0d0db1
2020-04-07 17:09:59 +01:00

114 lines
3.2 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 TestDexpreoptBootJars(t *testing.T) {
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{"foo", "bar", "baz"}
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext()
RegisterDexpreoptBootJarsComponents(ctx)
run(t, ctx, config)
dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
bootArt := dexpreoptBootJars.Output("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",
}
for i := range expectedInputs {
expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i])
}
inputs := bootArt.Implicits.Strings()
sort.Strings(inputs)
sort.Strings(expectedInputs)
if !reflect.DeepEqual(inputs, expectedInputs) {
t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
}
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",
}
for i := range expectedOutputs {
expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i])
}
outputs := append(android.WritablePaths{bootArt.Output}, bootArt.ImplicitOutputs...).Strings()
sort.Strings(outputs)
sort.Strings(expectedOutputs)
if !reflect.DeepEqual(outputs, expectedOutputs) {
t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
}
}