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" |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 25 | func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) { |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 26 | 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 Trafimovich | e736e13 | 2021-04-09 17:41:24 +0100 | [diff] [blame] | 37 | system_ext_specific: true, |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 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 | } |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 44 | |
| 45 | platform_bootclasspath { |
| 46 | name: "platform-bootclasspath", |
| 47 | } |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 48 | ` |
| 49 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 50 | result := android.GroupFixturePreparers( |
| 51 | prepareForJavaTest, |
| 52 | PrepareForTestWithJavaSdkLibraryFiles, |
| 53 | FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 54 | FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"), |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 55 | ).RunTestWithBp(t, bp) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 56 | |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 57 | platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common") |
| 58 | rule := platformBootclasspath.Output(ruleFile) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 59 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 60 | for i := range expectedInputs { |
Paul Duffin | 67d485e | 2021-03-22 16:24:19 +0000 | [diff] [blame] | 61 | expectedInputs[i] = filepath.Join("out/soong/test_device", expectedInputs[i]) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | for i := range expectedOutputs { |
Paul Duffin | 67d485e | 2021-03-22 16:24:19 +0000 | [diff] [blame] | 65 | expectedOutputs[i] = filepath.Join("out/soong/test_device", expectedOutputs[i]) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 66 | } |
| 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 Duffin | 67d485e | 2021-03-22 16:24:19 +0000 | [diff] [blame] | 76 | android.AssertStringPathsRelativeToTopEquals(t, "inputs", result.Config, expectedInputs, inputs) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 77 | |
Paul Duffin | 67d485e | 2021-03-22 16:24:19 +0000 | [diff] [blame] | 78 | android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs) |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | func TestDexpreoptBootJars(t *testing.T) { |
| 82 | ruleFile := "boot-foo.art" |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 83 | |
| 84 | expectedInputs := []string{ |
Martin Stjernholm | ea581fc | 2020-10-14 23:29:49 +0100 | [diff] [blame] | 85 | "dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 86 | "dex_bootjars_input/foo.jar", |
| 87 | "dex_bootjars_input/bar.jar", |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 88 | "dex_bootjars_input/baz.jar", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 91 | expectedOutputs := []string{ |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 92 | "dex_bootjars/android/system/framework/arm64/boot.invocation", |
David Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 93 | "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 Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 96 | "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 Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 99 | "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 Srbecky | 7f8dac1 | 2020-02-13 16:00:45 +0000 | [diff] [blame] | 102 | "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 Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 107 | testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) |
| 108 | } |
| 109 | |
| 110 | // Changes to the boot.zip structure may break the ART APK scanner. |
| 111 | func TestDexpreoptBootZip(t *testing.T) { |
| 112 | ruleFile := "boot.zip" |
| 113 | |
Paul Duffin | 67d485e | 2021-03-22 16:24:19 +0000 | [diff] [blame] | 114 | ctx := android.PathContextForTesting(android.TestArchConfig("", nil, "", nil)) |
Ulya Trafimovich | 5006d8d | 2020-05-20 13:47:13 +0100 | [diff] [blame] | 115 | expectedInputs := []string{} |
Ulya Trafimovich | 9ab4933 | 2020-06-10 15:44:25 +0100 | [diff] [blame] | 116 | for _, target := range ctx.Config().Targets[android.Android] { |
Ulya Trafimovich | 5006d8d | 2020-05-20 13:47:13 +0100 | [diff] [blame] | 117 | 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 Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 125 | expectedOutputs := []string{ |
| 126 | "dex_bootjars/boot.zip", |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 127 | } |
Ulya Trafimovich | 86d9e3a | 2020-05-19 11:15:44 +0100 | [diff] [blame] | 128 | |
| 129 | testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs) |
Colin Cross | 7622867 | 2019-02-25 16:40:34 -0800 | [diff] [blame] | 130 | } |