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) { |
Sam Delmerico | c759372 | 2022-08-31 15:57:52 -0400 | [diff] [blame^] | 99 | prepareForTestWithFrameworkCoverage := android.GroupFixturePreparers( |
| 100 | android.FixtureMergeEnv(map[string]string{ |
| 101 | "EMMA_INSTRUMENT": "true", |
| 102 | "EMMA_INSTRUMENT_FRAMEWORK": "true", |
| 103 | }), |
| 104 | // need to mock jacocoagent here to satisfy dependency added for |
| 105 | // instrumented libraries at build time |
| 106 | android.FixtureAddFile("jacocoagent/Android.bp", []byte(` |
| 107 | java_library { |
| 108 | name: "jacocoagent", |
| 109 | srcs: ["Test.java"], |
| 110 | system_modules: "none", |
| 111 | sdk_version: "none", |
| 112 | } |
| 113 | `)), |
| 114 | ) |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 115 | |
| 116 | prepareWithBp := android.FixtureWithRootAndroidBp(` |
| 117 | bootclasspath_fragment { |
| 118 | name: "myfragment", |
| 119 | contents: [ |
| 120 | "mybootlib", |
| 121 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 122 | api: { |
| 123 | stub_libs: [ |
| 124 | "mysdklibrary", |
| 125 | ], |
| 126 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 127 | coverage: { |
| 128 | contents: [ |
| 129 | "coveragelib", |
| 130 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 131 | api: { |
| 132 | stub_libs: [ |
| 133 | "mycoveragestubs", |
| 134 | ], |
| 135 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 136 | }, |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 137 | hidden_api: { |
| 138 | split_packages: ["*"], |
| 139 | }, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | java_library { |
| 143 | name: "mybootlib", |
| 144 | srcs: ["Test.java"], |
| 145 | system_modules: "none", |
| 146 | sdk_version: "none", |
| 147 | compile_dex: true, |
| 148 | } |
| 149 | |
| 150 | java_library { |
| 151 | name: "coveragelib", |
| 152 | srcs: ["Test.java"], |
| 153 | system_modules: "none", |
| 154 | sdk_version: "none", |
| 155 | compile_dex: true, |
| 156 | } |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 157 | |
| 158 | java_sdk_library { |
| 159 | name: "mysdklibrary", |
| 160 | srcs: ["Test.java"], |
| 161 | compile_dex: true, |
| 162 | public: {enabled: true}, |
| 163 | system: {enabled: true}, |
| 164 | } |
| 165 | |
| 166 | java_sdk_library { |
| 167 | name: "mycoveragestubs", |
| 168 | srcs: ["Test.java"], |
| 169 | compile_dex: true, |
| 170 | public: {enabled: true}, |
| 171 | } |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 172 | `) |
| 173 | |
| 174 | checkContents := func(t *testing.T, result *android.TestResult, expected ...string) { |
| 175 | module := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) |
| 176 | android.AssertArrayString(t, "contents property", expected, module.properties.Contents) |
| 177 | } |
| 178 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 179 | preparer := android.GroupFixturePreparers( |
| 180 | prepareForTestWithBootclasspathFragment, |
| 181 | PrepareForTestWithJavaSdkLibraryFiles, |
| 182 | FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 183 | FixtureConfigureApexBootJars("someapex:mybootlib"), |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 184 | prepareWithBp, |
| 185 | ) |
| 186 | |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 187 | t.Run("without coverage", func(t *testing.T) { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 188 | result := preparer.RunTest(t) |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 189 | checkContents(t, result, "mybootlib") |
| 190 | }) |
| 191 | |
| 192 | t.Run("with coverage", func(t *testing.T) { |
| 193 | result := android.GroupFixturePreparers( |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 194 | prepareForTestWithFrameworkCoverage, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 195 | preparer, |
Paul Duffin | c7d1644 | 2021-04-23 13:55:49 +0100 | [diff] [blame] | 196 | ).RunTest(t) |
| 197 | checkContents(t, result, "mybootlib", "coveragelib") |
| 198 | }) |
| 199 | } |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 200 | |
| 201 | func TestBootclasspathFragment_StubLibs(t *testing.T) { |
| 202 | result := android.GroupFixturePreparers( |
| 203 | prepareForTestWithBootclasspathFragment, |
| 204 | PrepareForTestWithJavaSdkLibraryFiles, |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 205 | FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 206 | FixtureConfigureApexBootJars("someapex:mysdklibrary"), |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 207 | ).RunTestWithBp(t, ` |
| 208 | bootclasspath_fragment { |
| 209 | name: "myfragment", |
| 210 | contents: ["mysdklibrary"], |
| 211 | api: { |
| 212 | stub_libs: [ |
| 213 | "mystublib", |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 214 | "myothersdklibrary", |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 215 | ], |
| 216 | }, |
| 217 | core_platform_api: { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 218 | stub_libs: ["mycoreplatform.stubs"], |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 219 | }, |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 220 | hidden_api: { |
| 221 | split_packages: ["*"], |
| 222 | }, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | java_library { |
| 226 | name: "mystublib", |
| 227 | srcs: ["Test.java"], |
| 228 | system_modules: "none", |
| 229 | sdk_version: "none", |
| 230 | compile_dex: true, |
| 231 | } |
| 232 | |
| 233 | java_sdk_library { |
| 234 | name: "mysdklibrary", |
| 235 | srcs: ["a.java"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 236 | shared_library: false, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 237 | public: {enabled: true}, |
| 238 | system: {enabled: true}, |
| 239 | } |
| 240 | |
| 241 | java_sdk_library { |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 242 | name: "myothersdklibrary", |
| 243 | srcs: ["a.java"], |
| 244 | shared_library: false, |
| 245 | public: {enabled: true}, |
| 246 | } |
| 247 | |
| 248 | java_sdk_library { |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 249 | name: "mycoreplatform", |
| 250 | srcs: ["a.java"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 251 | shared_library: false, |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 252 | public: {enabled: true}, |
| 253 | } |
| 254 | `) |
| 255 | |
| 256 | fragment := result.Module("myfragment", "android_common") |
Paul Duffin | 18cf197 | 2021-05-21 22:46:59 +0100 | [diff] [blame] | 257 | info := result.ModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 258 | |
| 259 | stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar" |
| 260 | |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 261 | // Stubs jars for mysdklibrary |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 262 | publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar" |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 263 | 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] | 264 | |
Paul Duffin | 34827d4 | 2021-05-13 21:25:05 +0100 | [diff] [blame] | 265 | // Stubs jars for myothersdklibrary |
| 266 | otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar" |
| 267 | |
| 268 | // Check that SdkPublic uses public stubs for all sdk libraries. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 269 | 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] | 270 | |
| 271 | // Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary |
| 272 | // as it does not provide system stubs. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 273 | 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] | 274 | |
| 275 | // Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs |
| 276 | // 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] | 277 | 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] | 278 | |
| 279 | // Check that SdkCorePlatform uses public stubs from the mycoreplatform library. |
| 280 | corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar" |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 281 | 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] | 282 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 283 | // Check the widest stubs.. The list contains the widest stub dex jar provided by each module. |
| 284 | expectedWidestPaths := []string{ |
| 285 | // mycoreplatform's widest API is core platform. |
| 286 | corePlatformStubsJar, |
| 287 | |
| 288 | // myothersdklibrary's widest API is public. |
| 289 | otherPublicStubsJar, |
| 290 | |
| 291 | // sdklibrary's widest API is system. |
| 292 | systemStubsJar, |
| 293 | |
| 294 | // mystublib's only provides one API and so it must be the widest. |
| 295 | stubsJar, |
| 296 | } |
| 297 | |
| 298 | android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope()) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 299 | } |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 300 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 301 | func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { |
| 302 | result := android.GroupFixturePreparers( |
| 303 | prepareForTestWithBootclasspathFragment, |
| 304 | PrepareForTestWithJavaSdkLibraryFiles, |
| 305 | FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"), |
| 306 | FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"), |
| 307 | android.MockFS{ |
| 308 | "my-blocked.txt": nil, |
| 309 | "my-max-target-o-low-priority.txt": nil, |
| 310 | "my-max-target-p.txt": nil, |
| 311 | "my-max-target-q.txt": nil, |
| 312 | "my-max-target-r-low-priority.txt": nil, |
| 313 | "my-removed.txt": nil, |
| 314 | "my-unsupported-packages.txt": nil, |
| 315 | "my-unsupported.txt": nil, |
| 316 | "my-new-max-target-q.txt": nil, |
| 317 | }.AddToFixture(), |
| 318 | android.FixtureWithRootAndroidBp(` |
| 319 | bootclasspath_fragment { |
| 320 | name: "mybootclasspathfragment", |
| 321 | apex_available: ["myapex"], |
| 322 | contents: ["mybootlib", "mynewlibrary"], |
| 323 | hidden_api: { |
| 324 | unsupported: [ |
| 325 | "my-unsupported.txt", |
| 326 | ], |
| 327 | removed: [ |
| 328 | "my-removed.txt", |
| 329 | ], |
| 330 | max_target_r_low_priority: [ |
| 331 | "my-max-target-r-low-priority.txt", |
| 332 | ], |
| 333 | max_target_q: [ |
| 334 | "my-max-target-q.txt", |
| 335 | ], |
| 336 | max_target_p: [ |
| 337 | "my-max-target-p.txt", |
| 338 | ], |
| 339 | max_target_o_low_priority: [ |
| 340 | "my-max-target-o-low-priority.txt", |
| 341 | ], |
| 342 | blocked: [ |
| 343 | "my-blocked.txt", |
| 344 | ], |
| 345 | unsupported_packages: [ |
| 346 | "my-unsupported-packages.txt", |
| 347 | ], |
| 348 | split_packages: ["sdklibrary"], |
| 349 | package_prefixes: ["sdklibrary.all.mine"], |
| 350 | single_packages: ["sdklibrary.mine"], |
| 351 | }, |
| 352 | } |
| 353 | |
| 354 | java_library { |
| 355 | name: "mybootlib", |
| 356 | apex_available: ["myapex"], |
| 357 | srcs: ["Test.java"], |
| 358 | system_modules: "none", |
| 359 | sdk_version: "none", |
| 360 | min_sdk_version: "1", |
| 361 | compile_dex: true, |
| 362 | permitted_packages: ["mybootlib"], |
| 363 | } |
| 364 | |
| 365 | java_sdk_library { |
| 366 | name: "mynewlibrary", |
| 367 | apex_available: ["myapex"], |
| 368 | srcs: ["Test.java"], |
| 369 | min_sdk_version: "10", |
| 370 | compile_dex: true, |
| 371 | public: {enabled: true}, |
| 372 | permitted_packages: ["mysdklibrary"], |
| 373 | hidden_api: { |
| 374 | max_target_q: [ |
| 375 | "my-new-max-target-q.txt", |
| 376 | ], |
| 377 | split_packages: ["sdklibrary", "newlibrary"], |
| 378 | package_prefixes: ["newlibrary.all.mine"], |
| 379 | single_packages: ["newlibrary.mine"], |
| 380 | }, |
| 381 | } |
| 382 | `), |
| 383 | ).RunTest(t) |
| 384 | |
| 385 | // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment. |
| 386 | library := result.Module("mynewlibrary", "android_common") |
| 387 | info := result.ModuleProvider(library, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) |
| 388 | android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages) |
| 389 | android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes) |
| 390 | android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) |
| 391 | for _, c := range HiddenAPIFlagFileCategories { |
| 392 | expectedMaxTargetQPaths := []string(nil) |
| 393 | if c.PropertyName == "max_target_q" { |
| 394 | expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"} |
| 395 | } |
| 396 | android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) |
| 397 | } |
| 398 | |
| 399 | // Make sure that the signature-patterns.csv is passed all the appropriate package properties |
| 400 | // from the bootclasspath_fragment and its contents. |
| 401 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common") |
| 402 | rule := fragment.Output("modular-hiddenapi/signature-patterns.csv") |
| 403 | expectedCommand := strings.Join([]string{ |
| 404 | "--split-package newlibrary", |
| 405 | "--split-package sdklibrary", |
| 406 | "--package-prefix newlibrary.all.mine", |
| 407 | "--package-prefix sdklibrary.all.mine", |
| 408 | "--single-package newlibrary.mine", |
| 409 | "--single-package sdklibrary", |
| 410 | }, " ") |
| 411 | android.AssertStringDoesContain(t, "signature patterns command", rule.RuleParams.Command, expectedCommand) |
| 412 | } |
| 413 | |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 414 | func TestBootclasspathFragment_Test(t *testing.T) { |
| 415 | result := android.GroupFixturePreparers( |
| 416 | prepareForTestWithBootclasspathFragment, |
| 417 | PrepareForTestWithJavaSdkLibraryFiles, |
| 418 | FixtureWithLastReleaseApis("mysdklibrary"), |
| 419 | ).RunTestWithBp(t, ` |
| 420 | bootclasspath_fragment { |
| 421 | name: "myfragment", |
| 422 | contents: ["mysdklibrary"], |
| 423 | hidden_api: { |
| 424 | split_packages: [], |
| 425 | }, |
| 426 | } |
| 427 | |
Paul Duffin | ff9b6fa | 2022-04-12 18:20:14 +0100 | [diff] [blame] | 428 | bootclasspath_fragment { |
| 429 | name: "test_fragment", |
| 430 | contents: ["mysdklibrary"], |
| 431 | hidden_api: { |
| 432 | split_packages: [], |
| 433 | }, |
| 434 | } |
| 435 | |
| 436 | bootclasspath_fragment { |
| 437 | name: "apex.apexd_test_bootclasspath-fragment", |
| 438 | contents: ["mysdklibrary"], |
| 439 | hidden_api: { |
| 440 | split_packages: [], |
| 441 | }, |
| 442 | } |
| 443 | |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 444 | bootclasspath_fragment_test { |
| 445 | name: "a_test_fragment", |
| 446 | contents: ["mysdklibrary"], |
| 447 | hidden_api: { |
| 448 | split_packages: [], |
| 449 | }, |
| 450 | } |
| 451 | |
| 452 | |
| 453 | java_sdk_library { |
| 454 | name: "mysdklibrary", |
| 455 | srcs: ["a.java"], |
| 456 | shared_library: false, |
| 457 | public: {enabled: true}, |
| 458 | system: {enabled: true}, |
| 459 | } |
| 460 | `) |
| 461 | |
| 462 | fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule) |
| 463 | android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment()) |
| 464 | |
Paul Duffin | ff9b6fa | 2022-04-12 18:20:14 +0100 | [diff] [blame] | 465 | fragment = result.Module("test_fragment", "android_common").(*BootclasspathFragmentModule) |
| 466 | android.AssertBoolEquals(t, "is a test fragment by prefix", true, fragment.isTestFragment()) |
| 467 | |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 468 | fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule) |
| 469 | android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment()) |
Paul Duffin | ff9b6fa | 2022-04-12 18:20:14 +0100 | [diff] [blame] | 470 | |
| 471 | fragment = result.Module("apex.apexd_test_bootclasspath-fragment", "android_common").(*BootclasspathFragmentModule) |
| 472 | android.AssertBoolEquals(t, "is a test fragment by name", true, fragment.isTestFragment()) |
Paul Duffin | c15b9e9 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 473 | } |