| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "path/filepath" | 
|  | 19 | "reflect" | 
|  | 20 | "sort" | 
|  | 21 | "testing" | 
|  | 22 |  | 
|  | 23 | "android/soong/android" | 
|  | 24 | "android/soong/dexpreopt" | 
|  | 25 | ) | 
|  | 26 |  | 
|  | 27 | func 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 | } | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 40 |  | 
|  | 41 | dex_import { | 
|  | 42 | name: "baz", | 
|  | 43 | jars: ["a.jar"], | 
|  | 44 | } | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 45 | ` | 
|  | 46 |  | 
|  | 47 | config := testConfig(nil) | 
|  | 48 |  | 
|  | 49 | pathCtx := android.PathContextForTesting(config, nil) | 
|  | 50 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 51 | dexpreoptConfig.RuntimeApexJars = []string{"foo", "bar", "baz"} | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 52 | setDexpreoptTestGlobalConfig(config, dexpreoptConfig) | 
|  | 53 |  | 
|  | 54 | ctx := testContext(config, bp, nil) | 
|  | 55 |  | 
|  | 56 | ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory)) | 
|  | 57 |  | 
|  | 58 | run(t, ctx, config) | 
|  | 59 |  | 
|  | 60 | dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars") | 
|  | 61 |  | 
|  | 62 | bootArt := dexpreoptBootJars.Output("boot.art") | 
|  | 63 |  | 
|  | 64 | expectedInputs := []string{ | 
|  | 65 | "dex_bootjars_input/foo.jar", | 
|  | 66 | "dex_bootjars_input/bar.jar", | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 67 | "dex_bootjars_input/baz.jar", | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 68 | } | 
|  | 69 |  | 
|  | 70 | for i := range expectedInputs { | 
|  | 71 | expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i]) | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | inputs := bootArt.Implicits.Strings() | 
|  | 75 | sort.Strings(inputs) | 
|  | 76 | sort.Strings(expectedInputs) | 
|  | 77 |  | 
|  | 78 | if !reflect.DeepEqual(inputs, expectedInputs) { | 
|  | 79 | t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs) | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | expectedOutputs := []string{ | 
|  | 83 | "dex_bootjars/system/framework/arm64/boot.invocation", | 
|  | 84 |  | 
|  | 85 | "dex_bootjars/system/framework/arm64/boot.art", | 
|  | 86 | "dex_bootjars/system/framework/arm64/boot-bar.art", | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 87 | "dex_bootjars/system/framework/arm64/boot-baz.art", | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 88 |  | 
|  | 89 | "dex_bootjars/system/framework/arm64/boot.oat", | 
|  | 90 | "dex_bootjars/system/framework/arm64/boot-bar.oat", | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 91 | "dex_bootjars/system/framework/arm64/boot-baz.oat", | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 92 |  | 
|  | 93 | "dex_bootjars/system/framework/arm64/boot.vdex", | 
|  | 94 | "dex_bootjars/system/framework/arm64/boot-bar.vdex", | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 95 | "dex_bootjars/system/framework/arm64/boot-baz.vdex", | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 96 |  | 
|  | 97 | "dex_bootjars_unstripped/system/framework/arm64/boot.oat", | 
|  | 98 | "dex_bootjars_unstripped/system/framework/arm64/boot-bar.oat", | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 99 | "dex_bootjars_unstripped/system/framework/arm64/boot-baz.oat", | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 100 | } | 
|  | 101 |  | 
|  | 102 | for i := range expectedOutputs { | 
|  | 103 | expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i]) | 
|  | 104 | } | 
|  | 105 |  | 
| Colin Cross | 1d2cf04 | 2019-03-29 15:33:06 -0700 | [diff] [blame] | 106 | outputs := append(android.WritablePaths{bootArt.Output}, bootArt.ImplicitOutputs...).Strings() | 
| Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 107 | sort.Strings(outputs) | 
|  | 108 | sort.Strings(expectedOutputs) | 
|  | 109 |  | 
|  | 110 | if !reflect.DeepEqual(outputs, expectedOutputs) { | 
|  | 111 | t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs) | 
|  | 112 | } | 
|  | 113 | } |