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" |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 19 | "sort" |
| 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | "android/soong/dexpreopt" |
| 24 | ) |
| 25 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 26 | func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) { |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 27 | bp := ` |
| 28 | java_sdk_library { |
| 29 | name: "foo", |
| 30 | srcs: ["a.java"], |
| 31 | api_packages: ["foo"], |
| 32 | } |
| 33 | |
| 34 | java_library { |
| 35 | name: "bar", |
| 36 | srcs: ["b.java"], |
| 37 | installable: true, |
| 38 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 39 | |
| 40 | dex_import { |
| 41 | name: "baz", |
| 42 | jars: ["a.jar"], |
| 43 | } |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 44 | ` |
| 45 | |
Paul Duffin | 451aeef | 2021-03-09 16:31:34 +0000 | [diff] [blame^] | 46 | result := javaFixtureFactory. |
| 47 | Extend(dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar", "platform:baz")). |
| 48 | RunTestWithBp(t, bp) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 49 | |
Paul Duffin | 451aeef | 2021-03-09 16:31:34 +0000 | [diff] [blame^] | 50 | dexpreoptBootJars := result.SingletonForTests("dex_bootjars") |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 51 | rule := dexpreoptBootJars.Output(ruleFile) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 52 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 53 | for i := range expectedInputs { |
| 54 | expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i]) |
| 55 | } |
| 56 | |
| 57 | for i := range expectedOutputs { |
| 58 | expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i]) |
| 59 | } |
| 60 | |
| 61 | inputs := rule.Implicits.Strings() |
| 62 | sort.Strings(inputs) |
| 63 | sort.Strings(expectedInputs) |
| 64 | |
| 65 | outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Strings() |
| 66 | sort.Strings(outputs) |
| 67 | sort.Strings(expectedOutputs) |
| 68 | |
Paul Duffin | 451aeef | 2021-03-09 16:31:34 +0000 | [diff] [blame^] | 69 | result.AssertDeepEquals("inputs", expectedInputs, inputs) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 70 | |
Paul Duffin | 451aeef | 2021-03-09 16:31:34 +0000 | [diff] [blame^] | 71 | result.AssertDeepEquals("outputs", expectedOutputs, outputs) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | func TestDexpreoptBootJars(t *testing.T) { |
| 75 | ruleFile := "boot-foo.art" |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 76 | |
| 77 | expectedInputs := []string{ |
Martin Stjernholm | ea581fc | 2020-10-14 23:29:49 +0100 | [diff] [blame] | 78 | "dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 79 | "dex_bootjars_input/foo.jar", |
| 80 | "dex_bootjars_input/bar.jar", |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 81 | "dex_bootjars_input/baz.jar", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 84 | expectedOutputs := []string{ |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 85 | "dex_bootjars/android/system/framework/arm64/boot.invocation", |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 86 | "dex_bootjars/android/system/framework/arm64/boot-foo.art", |
| 87 | "dex_bootjars/android/system/framework/arm64/boot-bar.art", |
| 88 | "dex_bootjars/android/system/framework/arm64/boot-baz.art", |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 89 | "dex_bootjars/android/system/framework/arm64/boot-foo.oat", |
| 90 | "dex_bootjars/android/system/framework/arm64/boot-bar.oat", |
| 91 | "dex_bootjars/android/system/framework/arm64/boot-baz.oat", |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 92 | "dex_bootjars/android/system/framework/arm64/boot-foo.vdex", |
| 93 | "dex_bootjars/android/system/framework/arm64/boot-bar.vdex", |
| 94 | "dex_bootjars/android/system/framework/arm64/boot-baz.vdex", |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 95 | "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat", |
| 96 | "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat", |
| 97 | "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 100 | testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) |
| 101 | } |
| 102 | |
| 103 | // Changes to the boot.zip structure may break the ART APK scanner. |
| 104 | func TestDexpreoptBootZip(t *testing.T) { |
| 105 | ruleFile := "boot.zip" |
| 106 | |
Ulya Trafimovich | 5006d8d | 2020-05-20 13:47:13 +0100 | [diff] [blame] | 107 | ctx := android.PathContextForTesting(testConfig(nil, "", nil)) |
| 108 | expectedInputs := []string{} |
Ulya Trafimovich | 9ab4933 | 2020-06-10 15:44:25 +0100 | [diff] [blame] | 109 | for _, target := range ctx.Config().Targets[android.Android] { |
Ulya Trafimovich | 5006d8d | 2020-05-20 13:47:13 +0100 | [diff] [blame] | 110 | for _, ext := range []string{".art", ".oat", ".vdex"} { |
| 111 | for _, jar := range []string{"foo", "bar", "baz"} { |
| 112 | expectedInputs = append(expectedInputs, |
| 113 | filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext)) |
| 114 | } |
| 115 | } |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 118 | expectedOutputs := []string{ |
| 119 | "dex_bootjars/boot.zip", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 120 | } |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 121 | |
| 122 | testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 123 | } |