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