blob: c99540da8c4ce56af8f908ad11196b8fb54375c1 [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
27func TestDexpreoptBootJars(t *testing.T) {
28 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 }
40 `
41
42 config := testConfig(nil)
43
44 pathCtx := android.PathContextForTesting(config, nil)
45 dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
46 dexpreoptConfig.RuntimeApexJars = []string{"foo", "bar"}
47 setDexpreoptTestGlobalConfig(config, dexpreoptConfig)
48
49 ctx := testContext(config, bp, nil)
50
51 ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory))
52
53 run(t, ctx, config)
54
55 dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars")
56
57 bootArt := dexpreoptBootJars.Output("boot.art")
58
59 expectedInputs := []string{
60 "dex_bootjars_input/foo.jar",
61 "dex_bootjars_input/bar.jar",
62 }
63
64 for i := range expectedInputs {
65 expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i])
66 }
67
68 inputs := bootArt.Implicits.Strings()
69 sort.Strings(inputs)
70 sort.Strings(expectedInputs)
71
72 if !reflect.DeepEqual(inputs, expectedInputs) {
73 t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs)
74 }
75
76 expectedOutputs := []string{
77 "dex_bootjars/system/framework/arm64/boot.invocation",
78
79 "dex_bootjars/system/framework/arm64/boot.art",
80 "dex_bootjars/system/framework/arm64/boot-bar.art",
81
82 "dex_bootjars/system/framework/arm64/boot.oat",
83 "dex_bootjars/system/framework/arm64/boot-bar.oat",
84
85 "dex_bootjars/system/framework/arm64/boot.vdex",
86 "dex_bootjars/system/framework/arm64/boot-bar.vdex",
87
88 "dex_bootjars_unstripped/system/framework/arm64/boot.oat",
89 "dex_bootjars_unstripped/system/framework/arm64/boot-bar.oat",
90 }
91
92 for i := range expectedOutputs {
93 expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i])
94 }
95
96 outputs := bootArt.Outputs.Strings()
97 sort.Strings(outputs)
98 sort.Strings(expectedOutputs)
99
100 if !reflect.DeepEqual(outputs, expectedOutputs) {
101 t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs)
102 }
103}