blob: bc7a55eb9c7d8fc35946a5aab78aedfcebcf2f59 [file] [log] [blame]
Colin Cross76228672019-02-25 16:40:34 -08001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "path/filepath"
Colin Cross76228672019-02-25 16:40:34 -080019 "sort"
20 "testing"
21
22 "android/soong/android"
Colin Cross76228672019-02-25 16:40:34 -080023)
24
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010025func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) {
Colin Cross76228672019-02-25 16:40:34 -080026 bp := `
27 java_sdk_library {
28 name: "foo",
29 srcs: ["a.java"],
30 api_packages: ["foo"],
31 }
32
33 java_library {
34 name: "bar",
35 srcs: ["b.java"],
36 installable: true,
Ulya Trafimoviche736e132021-04-09 17:41:24 +010037 system_ext_specific: true,
Colin Cross76228672019-02-25 16:40:34 -080038 }
Colin Cross42be7612019-02-21 18:12:14 -080039
40 dex_import {
41 name: "baz",
42 jars: ["a.jar"],
43 }
Paul Duffin2fc82ad2021-04-29 23:36:12 +010044
45 platform_bootclasspath {
46 name: "platform-bootclasspath",
47 }
Colin Cross76228672019-02-25 16:40:34 -080048 `
49
Paul Duffin71ae5942021-03-22 15:36:52 +000050 result := android.GroupFixturePreparers(
51 prepareForJavaTest,
52 PrepareForTestWithJavaSdkLibraryFiles,
53 FixtureWithLastReleaseApis("foo"),
Paul Duffin2fc82ad2021-04-29 23:36:12 +010054 FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"),
Paul Duffin71ae5942021-03-22 15:36:52 +000055 ).RunTestWithBp(t, bp)
Colin Cross76228672019-02-25 16:40:34 -080056
Paul Duffin2fc82ad2021-04-29 23:36:12 +010057 platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common")
58 rule := platformBootclasspath.Output(ruleFile)
Colin Cross76228672019-02-25 16:40:34 -080059
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010060 for i := range expectedInputs {
Paul Duffin67d485e2021-03-22 16:24:19 +000061 expectedInputs[i] = filepath.Join("out/soong/test_device", expectedInputs[i])
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010062 }
63
64 for i := range expectedOutputs {
Paul Duffin67d485e2021-03-22 16:24:19 +000065 expectedOutputs[i] = filepath.Join("out/soong/test_device", expectedOutputs[i])
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010066 }
67
68 inputs := rule.Implicits.Strings()
69 sort.Strings(inputs)
70 sort.Strings(expectedInputs)
71
72 outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings()
73 sort.Strings(outputs)
74 sort.Strings(expectedOutputs)
75
Paul Duffin67d485e2021-03-22 16:24:19 +000076 android.AssertStringPathsRelativeToTopEquals(t, "inputs", result.Config, expectedInputs, inputs)
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010077
Paul Duffin67d485e2021-03-22 16:24:19 +000078 android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs)
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010079}
80
81func TestDexpreoptBootJars(t *testing.T) {
82 ruleFile := "boot-foo.art"
Colin Cross76228672019-02-25 16:40:34 -080083
84 expectedInputs := []string{
Martin Stjernholmea581fc2020-10-14 23:29:49 +010085 "dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art",
Colin Cross76228672019-02-25 16:40:34 -080086 "dex_bootjars_input/foo.jar",
87 "dex_bootjars_input/bar.jar",
Colin Cross42be7612019-02-21 18:12:14 -080088 "dex_bootjars_input/baz.jar",
Colin Cross76228672019-02-25 16:40:34 -080089 }
90
Colin Cross76228672019-02-25 16:40:34 -080091 expectedOutputs := []string{
David Srbecky7f8dac12020-02-13 16:00:45 +000092 "dex_bootjars/android/system/framework/arm64/boot.invocation",
David Srbecky7f8dac12020-02-13 16:00:45 +000093 "dex_bootjars/android/system/framework/arm64/boot-foo.art",
94 "dex_bootjars/android/system/framework/arm64/boot-bar.art",
95 "dex_bootjars/android/system/framework/arm64/boot-baz.art",
David Srbecky7f8dac12020-02-13 16:00:45 +000096 "dex_bootjars/android/system/framework/arm64/boot-foo.oat",
97 "dex_bootjars/android/system/framework/arm64/boot-bar.oat",
98 "dex_bootjars/android/system/framework/arm64/boot-baz.oat",
David Srbecky7f8dac12020-02-13 16:00:45 +000099 "dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
100 "dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
101 "dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
David Srbecky7f8dac12020-02-13 16:00:45 +0000102 "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
103 "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
104 "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
Colin Cross76228672019-02-25 16:40:34 -0800105 }
106
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100107 testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
108}
109
110// Changes to the boot.zip structure may break the ART APK scanner.
111func TestDexpreoptBootZip(t *testing.T) {
112 ruleFile := "boot.zip"
113
Paul Duffin67d485e2021-03-22 16:24:19 +0000114 ctx := android.PathContextForTesting(android.TestArchConfig("", nil, "", nil))
Ulya Trafimovich5006d8d2020-05-20 13:47:13 +0100115 expectedInputs := []string{}
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100116 for _, target := range ctx.Config().Targets[android.Android] {
Ulya Trafimovich5006d8d2020-05-20 13:47:13 +0100117 for _, ext := range []string{".art", ".oat", ".vdex"} {
118 for _, jar := range []string{"foo", "bar", "baz"} {
119 expectedInputs = append(expectedInputs,
120 filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext))
121 }
122 }
Colin Cross76228672019-02-25 16:40:34 -0800123 }
124
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100125 expectedOutputs := []string{
126 "dex_bootjars/boot.zip",
Colin Cross76228672019-02-25 16:40:34 -0800127 }
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100128
129 testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
Colin Cross76228672019-02-25 16:40:34 -0800130}