Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 ( |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 18 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 19 | "testing" |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
| 22 | "android/soong/dexpreopt" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 23 | ) |
| 24 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 25 | // Contains some simple tests for bootclasspath_fragment logic, additional tests can be found in |
| 26 | // apex/bootclasspath_fragment_test.go as the ART boot image requires modules from the ART apex. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 27 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 28 | var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers( |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 29 | PrepareForTestWithJavaDefaultModules, |
| 30 | dexpreopt.PrepareForTestByEnablingDexpreopt, |
| 31 | ) |
| 32 | |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 33 | func TestBootclasspathFragment_UnknownImageName(t *testing.T) { |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 34 | prepareForTestWithBootclasspathFragment. |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 35 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 36 | `\Qimage_name: unknown image name "unknown", expected "art"\E`)). |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 37 | RunTestWithBp(t, ` |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 38 | bootclasspath_fragment { |
| 39 | name: "unknown-bootclasspath-fragment", |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 40 | image_name: "unknown", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 41 | contents: ["foo"], |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 42 | } |
| 43 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 44 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 45 | |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 46 | func TestPrebuiltBootclasspathFragment_UnknownImageName(t *testing.T) { |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 47 | prepareForTestWithBootclasspathFragment. |
Paul Duffin | 4b64ba0 | 2021-03-29 11:02:53 +0100 | [diff] [blame] | 48 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 49 | `\Qimage_name: unknown image name "unknown", expected "art"\E`)). |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 50 | RunTestWithBp(t, ` |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 51 | prebuilt_bootclasspath_fragment { |
| 52 | name: "unknown-bootclasspath-fragment", |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 53 | image_name: "unknown", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 54 | contents: ["foo"], |
Paul Duffin | 837486d | 2021-03-23 23:13:53 +0000 | [diff] [blame] | 55 | } |
| 56 | `) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 57 | } |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 58 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 59 | func TestBootclasspathFragmentInconsistentArtConfiguration_Platform(t *testing.T) { |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 60 | android.GroupFixturePreparers( |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 61 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 62 | dexpreopt.FixtureSetArtBootJars("platform:foo", "apex:bar"), |
| 63 | ). |
| 64 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 65 | `\QArtApexJars is invalid as it requests a platform variant of "foo"\E`)). |
| 66 | RunTestWithBp(t, ` |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 67 | bootclasspath_fragment { |
| 68 | name: "bootclasspath-fragment", |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 69 | image_name: "art", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 70 | contents: ["foo", "bar"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 71 | apex_available: [ |
| 72 | "apex", |
| 73 | ], |
| 74 | } |
| 75 | `) |
| 76 | } |
| 77 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 78 | func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testing.T) { |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 79 | android.GroupFixturePreparers( |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 80 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 81 | dexpreopt.FixtureSetArtBootJars("apex1:foo", "apex2:bar"), |
| 82 | ). |
| 83 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 84 | `\QArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex "apex1" and "apex2"\E`)). |
| 85 | RunTestWithBp(t, ` |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 86 | bootclasspath_fragment { |
| 87 | name: "bootclasspath-fragment", |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 88 | image_name: "art", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 89 | contents: ["foo", "bar"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 90 | apex_available: [ |
| 91 | "apex1", |
| 92 | "apex2", |
| 93 | ], |
| 94 | } |
| 95 | `) |
| 96 | } |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 97 | |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 98 | func TestBootclasspathFragment_Coverage(t *testing.T) { |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 99 | prepareWithBp := android.FixtureWithRootAndroidBp(` |
| 100 | bootclasspath_fragment { |
| 101 | name: "myfragment", |
| 102 | contents: [ |
| 103 | "mybootlib", |
| 104 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 105 | api: { |
| 106 | stub_libs: [ |
| 107 | "mysdklibrary", |
| 108 | ], |
| 109 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 110 | coverage: { |
| 111 | contents: [ |
| 112 | "coveragelib", |
| 113 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 114 | api: { |
| 115 | stub_libs: [ |
| 116 | "mycoveragestubs", |
| 117 | ], |
| 118 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 119 | }, |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 120 | hidden_api: { |
| 121 | split_packages: ["*"], |
| 122 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | java_library { |
| 126 | name: "mybootlib", |
| 127 | srcs: ["Test.java"], |
| 128 | system_modules: "none", |
| 129 | sdk_version: "none", |
| 130 | compile_dex: true, |
| 131 | } |
| 132 | |
| 133 | java_library { |
| 134 | name: "coveragelib", |
| 135 | srcs: ["Test.java"], |
| 136 | system_modules: "none", |
| 137 | sdk_version: "none", |
| 138 | compile_dex: true, |
| 139 | } |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 140 | |
| 141 | java_sdk_library { |
| 142 | name: "mysdklibrary", |
| 143 | srcs: ["Test.java"], |
| 144 | compile_dex: true, |
| 145 | public: {enabled: true}, |
| 146 | system: {enabled: true}, |
| 147 | } |
| 148 | |
| 149 | java_sdk_library { |
| 150 | name: "mycoveragestubs", |
| 151 | srcs: ["Test.java"], |
| 152 | compile_dex: true, |
| 153 | public: {enabled: true}, |
| 154 | } |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 155 | `) |
| 156 | |
| 157 | checkContents := func(t *testing.T, result *android.TestResult, expected ...string) { |
| 158 | module := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) |
| 159 | android.AssertArrayString(t, "contents property", expected, module.properties.Contents) |
| 160 | } |
| 161 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 162 | preparer := android.GroupFixturePreparers( |
| 163 | prepareForTestWithBootclasspathFragment, |
| 164 | PrepareForTestWithJavaSdkLibraryFiles, |
| 165 | FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 166 | FixtureConfigureApexBootJars("someapex:mybootlib"), |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 167 | prepareWithBp, |
| 168 | ) |
| 169 | |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 170 | t.Run("without coverage", func(t *testing.T) { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 171 | result := preparer.RunTest(t) |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 172 | checkContents(t, result, "mybootlib") |
| 173 | }) |
| 174 | |
| 175 | t.Run("with coverage", func(t *testing.T) { |
| 176 | result := android.GroupFixturePreparers( |
Sam Delmerico | 1e3f78f | 2022-09-07 12:07:07 -0400 | [diff] [blame] | 177 | prepareForTestWithFrameworkJacocoInstrumentation, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 178 | preparer, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 179 | ).RunTest(t) |
| 180 | checkContents(t, result, "mybootlib", "coveragelib") |
| 181 | }) |
| 182 | } |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 183 | |
| 184 | func TestBootclasspathFragment_StubLibs(t *testing.T) { |
| 185 | result := android.GroupFixturePreparers( |
| 186 | prepareForTestWithBootclasspathFragment, |
| 187 | PrepareForTestWithJavaSdkLibraryFiles, |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 188 | FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 189 | FixtureConfigureApexBootJars("someapex:mysdklibrary"), |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 190 | ).RunTestWithBp(t, ` |
| 191 | bootclasspath_fragment { |
| 192 | name: "myfragment", |
| 193 | contents: ["mysdklibrary"], |
| 194 | api: { |
| 195 | stub_libs: [ |
| 196 | "mystublib", |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 197 | "myothersdklibrary", |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 198 | ], |
| 199 | }, |
| 200 | core_platform_api: { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 201 | stub_libs: ["mycoreplatform.stubs"], |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 202 | }, |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 203 | hidden_api: { |
| 204 | split_packages: ["*"], |
| 205 | }, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | java_library { |
| 209 | name: "mystublib", |
| 210 | srcs: ["Test.java"], |
| 211 | system_modules: "none", |
| 212 | sdk_version: "none", |
| 213 | compile_dex: true, |
| 214 | } |
| 215 | |
| 216 | java_sdk_library { |
| 217 | name: "mysdklibrary", |
| 218 | srcs: ["a.java"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 219 | shared_library: false, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 220 | public: {enabled: true}, |
| 221 | system: {enabled: true}, |
| 222 | } |
| 223 | |
| 224 | java_sdk_library { |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 225 | name: "myothersdklibrary", |
| 226 | srcs: ["a.java"], |
| 227 | shared_library: false, |
| 228 | public: {enabled: true}, |
| 229 | } |
| 230 | |
| 231 | java_sdk_library { |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 232 | name: "mycoreplatform", |
| 233 | srcs: ["a.java"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 234 | shared_library: false, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 235 | public: {enabled: true}, |
| 236 | } |
| 237 | `) |
| 238 | |
| 239 | fragment := result.Module("myfragment", "android_common") |
Paul Duffin | 18cf197 | 2021-05-21 22:46:59 +0100 | [diff] [blame] | 240 | info := result.ModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 241 | |
| 242 | stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar" |
| 243 | |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 244 | // Stubs jars for mysdklibrary |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 245 | publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar" |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 246 | systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.system/android_common/dex/mysdklibrary.stubs.system.jar" |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 247 | |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 248 | // Stubs jars for myothersdklibrary |
| 249 | otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar" |
| 250 | |
| 251 | // Check that SdkPublic uses public stubs for all sdk libraries. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 252 | android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(PublicHiddenAPIScope)) |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 253 | |
| 254 | // Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary |
| 255 | // as it does not provide system stubs. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 256 | android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(SystemHiddenAPIScope)) |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 257 | |
| 258 | // Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs |
| 259 | // and public stubs for myothersdklibrary as it does not provide test stubs either. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 260 | android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(TestHiddenAPIScope)) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 261 | |
| 262 | // Check that SdkCorePlatform uses public stubs from the mycoreplatform library. |
| 263 | corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar" |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 264 | android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(CorePlatformHiddenAPIScope)) |
Paul Duffin | d2b1e0c | 2021-06-27 20:53:39 +0100 | [diff] [blame] | 265 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 266 | // Check the widest stubs.. The list contains the widest stub dex jar provided by each module. |
| 267 | expectedWidestPaths := []string{ |
| 268 | // mycoreplatform's widest API is core platform. |
| 269 | corePlatformStubsJar, |
| 270 | |
| 271 | // myothersdklibrary's widest API is public. |
| 272 | otherPublicStubsJar, |
| 273 | |
| 274 | // sdklibrary's widest API is system. |
| 275 | systemStubsJar, |
| 276 | |
| 277 | // mystublib's only provides one API and so it must be the widest. |
| 278 | stubsJar, |
| 279 | } |
| 280 | |
| 281 | android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope()) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 282 | } |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 283 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 284 | func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { |
| 285 | result := android.GroupFixturePreparers( |
| 286 | prepareForTestWithBootclasspathFragment, |
| 287 | PrepareForTestWithJavaSdkLibraryFiles, |
| 288 | FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"), |
| 289 | FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"), |
| 290 | android.MockFS{ |
| 291 | "my-blocked.txt": nil, |
| 292 | "my-max-target-o-low-priority.txt": nil, |
| 293 | "my-max-target-p.txt": nil, |
| 294 | "my-max-target-q.txt": nil, |
| 295 | "my-max-target-r-low-priority.txt": nil, |
| 296 | "my-removed.txt": nil, |
| 297 | "my-unsupported-packages.txt": nil, |
| 298 | "my-unsupported.txt": nil, |
| 299 | "my-new-max-target-q.txt": nil, |
| 300 | }.AddToFixture(), |
| 301 | android.FixtureWithRootAndroidBp(` |
| 302 | bootclasspath_fragment { |
| 303 | name: "mybootclasspathfragment", |
| 304 | apex_available: ["myapex"], |
| 305 | contents: ["mybootlib", "mynewlibrary"], |
| 306 | hidden_api: { |
| 307 | unsupported: [ |
| 308 | "my-unsupported.txt", |
| 309 | ], |
| 310 | removed: [ |
| 311 | "my-removed.txt", |
| 312 | ], |
| 313 | max_target_r_low_priority: [ |
| 314 | "my-max-target-r-low-priority.txt", |
| 315 | ], |
| 316 | max_target_q: [ |
| 317 | "my-max-target-q.txt", |
| 318 | ], |
| 319 | max_target_p: [ |
| 320 | "my-max-target-p.txt", |
| 321 | ], |
| 322 | max_target_o_low_priority: [ |
| 323 | "my-max-target-o-low-priority.txt", |
| 324 | ], |
| 325 | blocked: [ |
| 326 | "my-blocked.txt", |
| 327 | ], |
| 328 | unsupported_packages: [ |
| 329 | "my-unsupported-packages.txt", |
| 330 | ], |
| 331 | split_packages: ["sdklibrary"], |
| 332 | package_prefixes: ["sdklibrary.all.mine"], |
| 333 | single_packages: ["sdklibrary.mine"], |
| 334 | }, |
| 335 | } |
| 336 | |
| 337 | java_library { |
| 338 | name: "mybootlib", |
| 339 | apex_available: ["myapex"], |
| 340 | srcs: ["Test.java"], |
| 341 | system_modules: "none", |
| 342 | sdk_version: "none", |
| 343 | min_sdk_version: "1", |
| 344 | compile_dex: true, |
| 345 | permitted_packages: ["mybootlib"], |
| 346 | } |
| 347 | |
| 348 | java_sdk_library { |
| 349 | name: "mynewlibrary", |
| 350 | apex_available: ["myapex"], |
| 351 | srcs: ["Test.java"], |
| 352 | min_sdk_version: "10", |
| 353 | compile_dex: true, |
| 354 | public: {enabled: true}, |
| 355 | permitted_packages: ["mysdklibrary"], |
| 356 | hidden_api: { |
| 357 | max_target_q: [ |
| 358 | "my-new-max-target-q.txt", |
| 359 | ], |
| 360 | split_packages: ["sdklibrary", "newlibrary"], |
| 361 | package_prefixes: ["newlibrary.all.mine"], |
| 362 | single_packages: ["newlibrary.mine"], |
| 363 | }, |
| 364 | } |
| 365 | `), |
| 366 | ).RunTest(t) |
| 367 | |
| 368 | // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment. |
| 369 | library := result.Module("mynewlibrary", "android_common") |
| 370 | info := result.ModuleProvider(library, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) |
| 371 | android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages) |
| 372 | android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes) |
| 373 | android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) |
| 374 | for _, c := range HiddenAPIFlagFileCategories { |
| 375 | expectedMaxTargetQPaths := []string(nil) |
| 376 | if c.PropertyName == "max_target_q" { |
| 377 | expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"} |
| 378 | } |
| 379 | android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) |
| 380 | } |
| 381 | |
| 382 | // Make sure that the signature-patterns.csv is passed all the appropriate package properties |
| 383 | // from the bootclasspath_fragment and its contents. |
| 384 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common") |
| 385 | rule := fragment.Output("modular-hiddenapi/signature-patterns.csv") |
| 386 | expectedCommand := strings.Join([]string{ |
| 387 | "--split-package newlibrary", |
| 388 | "--split-package sdklibrary", |
| 389 | "--package-prefix newlibrary.all.mine", |
| 390 | "--package-prefix sdklibrary.all.mine", |
| 391 | "--single-package newlibrary.mine", |
| 392 | "--single-package sdklibrary", |
| 393 | }, " ") |
| 394 | android.AssertStringDoesContain(t, "signature patterns command", rule.RuleParams.Command, expectedCommand) |
| 395 | } |
| 396 | |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 397 | func TestBootclasspathFragment_Test(t *testing.T) { |
| 398 | result := android.GroupFixturePreparers( |
| 399 | prepareForTestWithBootclasspathFragment, |
| 400 | PrepareForTestWithJavaSdkLibraryFiles, |
| 401 | FixtureWithLastReleaseApis("mysdklibrary"), |
| 402 | ).RunTestWithBp(t, ` |
| 403 | bootclasspath_fragment { |
| 404 | name: "myfragment", |
| 405 | contents: ["mysdklibrary"], |
| 406 | hidden_api: { |
| 407 | split_packages: [], |
| 408 | }, |
| 409 | } |
| 410 | |
| 411 | bootclasspath_fragment_test { |
| 412 | name: "a_test_fragment", |
| 413 | contents: ["mysdklibrary"], |
| 414 | hidden_api: { |
| 415 | split_packages: [], |
| 416 | }, |
| 417 | } |
| 418 | |
| 419 | |
| 420 | java_sdk_library { |
| 421 | name: "mysdklibrary", |
| 422 | srcs: ["a.java"], |
| 423 | shared_library: false, |
| 424 | public: {enabled: true}, |
| 425 | system: {enabled: true}, |
| 426 | } |
| 427 | `) |
| 428 | |
| 429 | fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) |
| 430 | android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) |
| 431 | |
| 432 | fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) |
| 433 | android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) |
| 434 | } |