blob: 00bd80cb348ae63b7a1c2e2eae706c7324614ba0 [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"
19 "reflect"
20 "sort"
21 "testing"
22
23 "android/soong/android"
24 "android/soong/dexpreopt"
25)
26
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010027func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) {
Colin Cross76228672019-02-25 16:40:34 -080028 bp := `
29 java_sdk_library {
30 name: "foo",
31 srcs: ["a.java"],
32 api_packages: ["foo"],
33 }
34
35 java_library {
36 name: "bar",
37 srcs: ["b.java"],
38 installable: true,
39 }
Colin Cross42be7612019-02-21 18:12:14 -080040
41 dex_import {
42 name: "baz",
43 jars: ["a.jar"],
44 }
Colin Cross76228672019-02-25 16:40:34 -080045 `
46
Colin Cross98be1bb2019-12-13 20:41:13 -080047 config := testConfig(nil, bp, nil)
Colin Cross76228672019-02-25 16:40:34 -080048
Colin Cross98be1bb2019-12-13 20:41:13 -080049 pathCtx := android.PathContextForTesting(config)
Colin Cross76228672019-02-25 16:40:34 -080050 dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
Ulya Trafimovich249386a2020-07-01 14:31:13 +010051 dexpreoptConfig.BootJars = android.CreateConfiguredJarList(pathCtx, []string{"platform:foo", "platform:bar", "platform:baz"})
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +000052 dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
Colin Cross76228672019-02-25 16:40:34 -080053
Colin Cross98be1bb2019-12-13 20:41:13 -080054 ctx := testContext()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +000055 RegisterDexpreoptBootJarsComponents(ctx)
Colin Cross76228672019-02-25 16:40:34 -080056 run(t, ctx, config)
57
58 dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010059 rule := dexpreoptBootJars.Output(ruleFile)
Colin Cross76228672019-02-25 16:40:34 -080060
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010061 for i := range expectedInputs {
62 expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i])
63 }
64
65 for i := range expectedOutputs {
66 expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i])
67 }
68
69 inputs := rule.Implicits.Strings()
70 sort.Strings(inputs)
71 sort.Strings(expectedInputs)
72
73 outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings()
74 sort.Strings(outputs)
75 sort.Strings(expectedOutputs)
76
77 if !reflect.DeepEqual(inputs, expectedInputs) {
78 t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
79 }
80
81 if !reflect.DeepEqual(outputs, expectedOutputs) {
82 t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
83 }
84}
85
86func TestDexpreoptBootJars(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -070087 t.Parallel()
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +010088 ruleFile := "boot-foo.art"
Colin Cross76228672019-02-25 16:40:34 -080089
90 expectedInputs := []string{
David Srbecky7f8dac12020-02-13 16:00:45 +000091 "dex_artjars/android/apex/com.android.art/javalib/arm64/boot.art",
Colin Cross76228672019-02-25 16:40:34 -080092 "dex_bootjars_input/foo.jar",
93 "dex_bootjars_input/bar.jar",
Colin Cross42be7612019-02-21 18:12:14 -080094 "dex_bootjars_input/baz.jar",
Colin Cross76228672019-02-25 16:40:34 -080095 }
96
Colin Cross76228672019-02-25 16:40:34 -080097 expectedOutputs := []string{
David Srbecky7f8dac12020-02-13 16:00:45 +000098 "dex_bootjars/android/system/framework/arm64/boot.invocation",
David Srbecky7f8dac12020-02-13 16:00:45 +000099 "dex_bootjars/android/system/framework/arm64/boot-foo.art",
100 "dex_bootjars/android/system/framework/arm64/boot-bar.art",
101 "dex_bootjars/android/system/framework/arm64/boot-baz.art",
David Srbecky7f8dac12020-02-13 16:00:45 +0000102 "dex_bootjars/android/system/framework/arm64/boot-foo.oat",
103 "dex_bootjars/android/system/framework/arm64/boot-bar.oat",
104 "dex_bootjars/android/system/framework/arm64/boot-baz.oat",
David Srbecky7f8dac12020-02-13 16:00:45 +0000105 "dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
106 "dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
107 "dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
David Srbecky7f8dac12020-02-13 16:00:45 +0000108 "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
109 "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
110 "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
Colin Cross76228672019-02-25 16:40:34 -0800111 }
112
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100113 testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
114}
115
116// Changes to the boot.zip structure may break the ART APK scanner.
117func TestDexpreoptBootZip(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -0700118 t.Parallel()
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100119 ruleFile := "boot.zip"
120
Ulya Trafimovich5006d8d2020-05-20 13:47:13 +0100121 ctx := android.PathContextForTesting(testConfig(nil, "", nil))
122 expectedInputs := []string{}
Ulya Trafimovich9ab49332020-06-10 15:44:25 +0100123 for _, target := range ctx.Config().Targets[android.Android] {
Ulya Trafimovich5006d8d2020-05-20 13:47:13 +0100124 for _, ext := range []string{".art", ".oat", ".vdex"} {
125 for _, jar := range []string{"foo", "bar", "baz"} {
126 expectedInputs = append(expectedInputs,
127 filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext))
128 }
129 }
Colin Cross76228672019-02-25 16:40:34 -0800130 }
131
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100132 expectedOutputs := []string{
133 "dex_bootjars/boot.zip",
Colin Cross76228672019-02-25 16:40:34 -0800134 }
Ulya Trafimovich86d9e3a2020-05-19 11:15:44 +0100135
136 testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
Colin Cross76228672019-02-25 16:40:34 -0800137}