Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1 | // Copyright 2017 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 ( |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 18 | "fmt" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 20 | "reflect" |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 21 | "sort" |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 22 | "strings" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 23 | "testing" |
Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint/proptools" |
| 26 | |
| 27 | "android/soong/android" |
| 28 | "android/soong/cc" |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 29 | "android/soong/dexpreopt" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 30 | ) |
| 31 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 32 | // testApp runs tests using the prepareForJavaTest |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 33 | // |
| 34 | // See testJava for an explanation as to how to stop using this deprecated method. |
| 35 | // |
| 36 | // deprecated |
| 37 | func testApp(t *testing.T, bp string) *android.TestContext { |
| 38 | t.Helper() |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 39 | result := prepareForJavaTest.RunTestWithBp(t, bp) |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 40 | return result.TestContext |
| 41 | } |
| 42 | |
| 43 | func TestApp(t *testing.T) { |
| 44 | resourceFiles := []string{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 45 | "res/layout/layout.xml", |
| 46 | "res/values/strings.xml", |
| 47 | "res/values-en-rUS/strings.xml", |
| 48 | } |
| 49 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 50 | compiledResourceFiles := []string{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 51 | "aapt2/res/layout_layout.xml.flat", |
| 52 | "aapt2/res/values_strings.arsc.flat", |
| 53 | "aapt2/res/values-en-rUS_strings.arsc.flat", |
| 54 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 55 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 56 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 57 | t.Run(moduleType, func(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 58 | result := android.GroupFixturePreparers( |
| 59 | prepareForJavaTest, |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 60 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 61 | for _, file := range resourceFiles { |
| 62 | fs[file] = nil |
| 63 | } |
| 64 | }), |
| 65 | ).RunTestWithBp(t, moduleType+` { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 66 | name: "foo", |
| 67 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 68 | sdk_version: "current" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 69 | } |
| 70 | `) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 71 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 72 | foo := result.ModuleForTests("foo", "android_common") |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 73 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 74 | var expectedLinkImplicits []string |
| 75 | |
| 76 | manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml") |
| 77 | expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 78 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 79 | frameworkRes := result.ModuleForTests("framework-res", "android_common") |
Rashed Abdel-Tawab | 8782f15 | 2018-08-09 14:08:53 -0700 | [diff] [blame] | 80 | lineageRes := result.ModuleForTests("org.lineageos.platform-res", "android_common") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 81 | expectedLinkImplicits = append(expectedLinkImplicits, |
| 82 | frameworkRes.Output("package-res.apk").Output.String()) |
Rashed Abdel-Tawab | 8782f15 | 2018-08-09 14:08:53 -0700 | [diff] [blame] | 83 | expectedLinkImplicits = append(expectedLinkImplicits, |
| 84 | lineageRes.Output("package-res.apk").Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 85 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 86 | // Test the mapping from input files to compiled output file names |
| 87 | compile := foo.Output(compiledResourceFiles[0]) |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 88 | android.AssertDeepEquals(t, "aapt2 compile inputs", resourceFiles, compile.Inputs.Strings()) |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 89 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 90 | compiledResourceOutputs := compile.Outputs.Strings() |
| 91 | sort.Strings(compiledResourceOutputs) |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 92 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 93 | expectedLinkImplicits = append(expectedLinkImplicits, compiledResourceOutputs...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 94 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 95 | list := foo.Output("aapt2/res.list") |
| 96 | expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 97 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 98 | // Check that the link rule uses |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 99 | res := result.ModuleForTests("foo", "android_common").Output("package-res.apk") |
| 100 | android.AssertDeepEquals(t, "aapt2 link implicits", expectedLinkImplicits, res.Implicits.Strings()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 101 | }) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 104 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 105 | func TestAppSplits(t *testing.T) { |
| 106 | ctx := testApp(t, ` |
| 107 | android_app { |
| 108 | name: "foo", |
| 109 | srcs: ["a.java"], |
| 110 | package_splits: ["v4", "v7,hdpi"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 111 | sdk_version: "current" |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 112 | }`) |
| 113 | |
| 114 | foo := ctx.ModuleForTests("foo", "android_common") |
| 115 | |
| 116 | expectedOutputs := []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 117 | "out/soong/.intermediates/foo/android_common/foo.apk", |
| 118 | "out/soong/.intermediates/foo/android_common/foo_v4.apk", |
| 119 | "out/soong/.intermediates/foo/android_common/foo_v7_hdpi.apk", |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 120 | } |
| 121 | for _, expectedOutput := range expectedOutputs { |
| 122 | foo.Output(expectedOutput) |
| 123 | } |
| 124 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 125 | outputFiles, err := foo.Module().(*AndroidApp).OutputFiles("") |
| 126 | if err != nil { |
| 127 | t.Fatal(err) |
| 128 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 129 | android.AssertPathsRelativeToTopEquals(t, `OutputFiles("")`, expectedOutputs, outputFiles) |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 132 | func TestPlatformAPIs(t *testing.T) { |
| 133 | testJava(t, ` |
| 134 | android_app { |
| 135 | name: "foo", |
| 136 | srcs: ["a.java"], |
| 137 | platform_apis: true, |
| 138 | } |
| 139 | `) |
| 140 | |
| 141 | testJava(t, ` |
| 142 | android_app { |
| 143 | name: "foo", |
| 144 | srcs: ["a.java"], |
| 145 | sdk_version: "current", |
| 146 | } |
| 147 | `) |
| 148 | |
Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 149 | testJavaError(t, "This module has conflicting settings. sdk_version is empty, which means that this module is build against platform APIs. However platform_apis is not set to true", ` |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 150 | android_app { |
| 151 | name: "bar", |
| 152 | srcs: ["b.java"], |
| 153 | } |
| 154 | `) |
| 155 | |
Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 156 | testJavaError(t, "This module has conflicting settings. sdk_version is not empty, which means this module cannot use platform APIs. However platform_apis is set to true.", ` |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 157 | android_app { |
| 158 | name: "bar", |
| 159 | srcs: ["b.java"], |
| 160 | sdk_version: "system_current", |
| 161 | platform_apis: true, |
| 162 | } |
| 163 | `) |
| 164 | } |
| 165 | |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 166 | func TestAndroidAppLinkType(t *testing.T) { |
| 167 | testJava(t, ` |
| 168 | android_app { |
| 169 | name: "foo", |
| 170 | srcs: ["a.java"], |
| 171 | libs: ["bar"], |
| 172 | static_libs: ["baz"], |
| 173 | platform_apis: true, |
| 174 | } |
| 175 | |
| 176 | java_library { |
| 177 | name: "bar", |
| 178 | sdk_version: "current", |
| 179 | srcs: ["b.java"], |
| 180 | } |
| 181 | |
| 182 | android_library { |
| 183 | name: "baz", |
| 184 | sdk_version: "system_current", |
| 185 | srcs: ["c.java"], |
| 186 | } |
| 187 | `) |
| 188 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 189 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 190 | android_app { |
| 191 | name: "foo", |
| 192 | srcs: ["a.java"], |
| 193 | libs: ["bar"], |
| 194 | sdk_version: "current", |
| 195 | static_libs: ["baz"], |
| 196 | } |
| 197 | |
| 198 | java_library { |
| 199 | name: "bar", |
| 200 | sdk_version: "current", |
| 201 | srcs: ["b.java"], |
| 202 | } |
| 203 | |
| 204 | android_library { |
| 205 | name: "baz", |
| 206 | sdk_version: "system_current", |
| 207 | srcs: ["c.java"], |
| 208 | } |
| 209 | `) |
| 210 | |
| 211 | testJava(t, ` |
| 212 | android_app { |
| 213 | name: "foo", |
| 214 | srcs: ["a.java"], |
| 215 | libs: ["bar"], |
| 216 | sdk_version: "system_current", |
| 217 | static_libs: ["baz"], |
| 218 | } |
| 219 | |
| 220 | java_library { |
| 221 | name: "bar", |
| 222 | sdk_version: "current", |
| 223 | srcs: ["b.java"], |
| 224 | } |
| 225 | |
| 226 | android_library { |
| 227 | name: "baz", |
| 228 | sdk_version: "system_current", |
| 229 | srcs: ["c.java"], |
| 230 | } |
| 231 | `) |
| 232 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 233 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 234 | android_app { |
| 235 | name: "foo", |
| 236 | srcs: ["a.java"], |
| 237 | libs: ["bar"], |
| 238 | sdk_version: "system_current", |
| 239 | static_libs: ["baz"], |
| 240 | } |
| 241 | |
| 242 | java_library { |
| 243 | name: "bar", |
| 244 | sdk_version: "current", |
| 245 | srcs: ["b.java"], |
| 246 | } |
| 247 | |
| 248 | android_library { |
| 249 | name: "baz", |
| 250 | srcs: ["c.java"], |
| 251 | } |
| 252 | `) |
| 253 | } |
| 254 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 255 | func TestUpdatableApps(t *testing.T) { |
| 256 | testCases := []struct { |
| 257 | name string |
| 258 | bp string |
| 259 | expectedError string |
| 260 | }{ |
| 261 | { |
| 262 | name: "Stable public SDK", |
| 263 | bp: `android_app { |
| 264 | name: "foo", |
| 265 | srcs: ["a.java"], |
| 266 | sdk_version: "29", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 267 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 268 | updatable: true, |
| 269 | }`, |
| 270 | }, |
| 271 | { |
| 272 | name: "Stable system SDK", |
| 273 | bp: `android_app { |
| 274 | name: "foo", |
| 275 | srcs: ["a.java"], |
| 276 | sdk_version: "system_29", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 277 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 278 | updatable: true, |
| 279 | }`, |
| 280 | }, |
| 281 | { |
| 282 | name: "Current public SDK", |
| 283 | bp: `android_app { |
| 284 | name: "foo", |
| 285 | srcs: ["a.java"], |
| 286 | sdk_version: "current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 287 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 288 | updatable: true, |
| 289 | }`, |
| 290 | }, |
| 291 | { |
| 292 | name: "Current system SDK", |
| 293 | bp: `android_app { |
| 294 | name: "foo", |
| 295 | srcs: ["a.java"], |
| 296 | sdk_version: "system_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 297 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 298 | updatable: true, |
| 299 | }`, |
| 300 | }, |
| 301 | { |
| 302 | name: "Current module SDK", |
| 303 | bp: `android_app { |
| 304 | name: "foo", |
| 305 | srcs: ["a.java"], |
| 306 | sdk_version: "module_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 307 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 308 | updatable: true, |
| 309 | }`, |
| 310 | }, |
| 311 | { |
| 312 | name: "Current core SDK", |
| 313 | bp: `android_app { |
| 314 | name: "foo", |
| 315 | srcs: ["a.java"], |
| 316 | sdk_version: "core_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 317 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 318 | updatable: true, |
| 319 | }`, |
| 320 | }, |
| 321 | { |
| 322 | name: "No Platform APIs", |
| 323 | bp: `android_app { |
| 324 | name: "foo", |
| 325 | srcs: ["a.java"], |
| 326 | platform_apis: true, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 327 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 328 | updatable: true, |
| 329 | }`, |
| 330 | expectedError: "Updatable apps must use stable SDKs", |
| 331 | }, |
| 332 | { |
| 333 | name: "No Core Platform APIs", |
| 334 | bp: `android_app { |
| 335 | name: "foo", |
| 336 | srcs: ["a.java"], |
| 337 | sdk_version: "core_platform", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 338 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 339 | updatable: true, |
| 340 | }`, |
| 341 | expectedError: "Updatable apps must use stable SDKs", |
| 342 | }, |
| 343 | { |
| 344 | name: "No unspecified APIs", |
| 345 | bp: `android_app { |
| 346 | name: "foo", |
| 347 | srcs: ["a.java"], |
| 348 | updatable: true, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 349 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 350 | }`, |
| 351 | expectedError: "Updatable apps must use stable SDK", |
| 352 | }, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 353 | { |
| 354 | name: "Must specify min_sdk_version", |
| 355 | bp: `android_app { |
| 356 | name: "app_without_min_sdk_version", |
| 357 | srcs: ["a.java"], |
| 358 | sdk_version: "29", |
| 359 | updatable: true, |
| 360 | }`, |
| 361 | expectedError: "updatable apps must set min_sdk_version.", |
| 362 | }, |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | for _, test := range testCases { |
| 366 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 367 | errorHandler := android.FixtureExpectsNoErrors |
| 368 | if test.expectedError != "" { |
| 369 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 370 | } |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 371 | android.GroupFixturePreparers( |
| 372 | prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{ |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 373 | "29": {"foo"}, |
| 374 | })). |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 375 | ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, test.bp) |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 376 | }) |
| 377 | } |
| 378 | } |
| 379 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 380 | func TestUpdatableApps_TransitiveDepsShouldSetMinSdkVersion(t *testing.T) { |
| 381 | testJavaError(t, `module "bar".*: should support min_sdk_version\(29\)`, cc.GatherRequiredDepsForTest(android.Android)+` |
| 382 | android_app { |
| 383 | name: "foo", |
| 384 | srcs: ["a.java"], |
| 385 | updatable: true, |
| 386 | sdk_version: "current", |
| 387 | min_sdk_version: "29", |
| 388 | static_libs: ["bar"], |
| 389 | } |
| 390 | |
| 391 | java_library { |
| 392 | name: "bar", |
| 393 | sdk_version: "current", |
| 394 | } |
| 395 | `) |
| 396 | } |
| 397 | |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 398 | func TestUpdatableApps_JniLibsShouldShouldSupportMinSdkVersion(t *testing.T) { |
| 399 | testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
| 400 | android_app { |
| 401 | name: "foo", |
| 402 | srcs: ["a.java"], |
| 403 | updatable: true, |
| 404 | sdk_version: "current", |
| 405 | min_sdk_version: "current", |
| 406 | jni_libs: ["libjni"], |
| 407 | } |
| 408 | |
| 409 | cc_library { |
| 410 | name: "libjni", |
| 411 | stl: "none", |
| 412 | system_shared_libs: [], |
| 413 | sdk_version: "current", |
| 414 | } |
| 415 | `) |
| 416 | } |
| 417 | |
| 418 | func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) { |
| 419 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 420 | android_app { |
| 421 | name: "foo", |
| 422 | srcs: ["a.java"], |
| 423 | updatable: true, |
| 424 | sdk_version: "current", |
| 425 | min_sdk_version: "29", |
| 426 | jni_libs: ["libjni"], |
| 427 | } |
| 428 | |
| 429 | cc_library { |
| 430 | name: "libjni", |
| 431 | stl: "none", |
| 432 | system_shared_libs: [], |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 433 | sdk_version: "current", |
| 434 | min_sdk_version: "29", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 435 | } |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 436 | ` |
| 437 | fs := map[string][]byte{ |
| 438 | "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtbegin_so.o": nil, |
| 439 | "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtend_so.o": nil, |
| 440 | "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtbegin_so.o": nil, |
| 441 | "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil, |
| 442 | } |
| 443 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 444 | ctx, _ := testJavaWithFS(t, bp, fs) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 445 | |
| 446 | inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits |
| 447 | var crtbeginFound, crtendFound bool |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 448 | expectedCrtBegin := ctx.ModuleForTests("crtbegin_so", |
| 449 | "android_arm64_armv8-a_sdk_29").Rule("partialLd").Output |
| 450 | expectedCrtEnd := ctx.ModuleForTests("crtend_so", |
| 451 | "android_arm64_armv8-a_sdk_29").Rule("partialLd").Output |
| 452 | implicits := []string{} |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 453 | for _, input := range inputs { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 454 | implicits = append(implicits, input.String()) |
| 455 | if strings.HasSuffix(input.String(), expectedCrtBegin.String()) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 456 | crtbeginFound = true |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 457 | } else if strings.HasSuffix(input.String(), expectedCrtEnd.String()) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 458 | crtendFound = true |
| 459 | } |
| 460 | } |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 461 | if !crtbeginFound { |
| 462 | t.Error(fmt.Sprintf( |
| 463 | "expected implicit with suffix %q, have the following implicits:\n%s", |
| 464 | expectedCrtBegin, strings.Join(implicits, "\n"))) |
| 465 | } |
| 466 | if !crtendFound { |
| 467 | t.Error(fmt.Sprintf( |
| 468 | "expected implicit with suffix %q, have the following implicits:\n%s", |
| 469 | expectedCrtEnd, strings.Join(implicits, "\n"))) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | func TestUpdatableApps_ErrorIfJniLibDoesntSupportMinSdkVersion(t *testing.T) { |
| 474 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 475 | android_app { |
| 476 | name: "foo", |
| 477 | srcs: ["a.java"], |
| 478 | updatable: true, |
| 479 | sdk_version: "current", |
| 480 | min_sdk_version: "29", // this APK should support 29 |
| 481 | jni_libs: ["libjni"], |
| 482 | } |
| 483 | |
| 484 | cc_library { |
| 485 | name: "libjni", |
| 486 | stl: "none", |
| 487 | sdk_version: "current", |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 488 | min_sdk_version: "current", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 489 | } |
| 490 | ` |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 491 | testJavaError(t, `"libjni" .*: min_sdk_version\(current\) is higher than min_sdk_version\(29\)`, bp) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 492 | } |
| 493 | |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 494 | func TestUpdatableApps_ErrorIfDepMinSdkVersionIsHigher(t *testing.T) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 495 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 496 | android_app { |
| 497 | name: "foo", |
| 498 | srcs: ["a.java"], |
| 499 | updatable: true, |
| 500 | sdk_version: "current", |
| 501 | min_sdk_version: "29", // this APK should support 29 |
| 502 | jni_libs: ["libjni"], |
| 503 | } |
| 504 | |
| 505 | cc_library { |
| 506 | name: "libjni", |
| 507 | stl: "none", |
| 508 | shared_libs: ["libbar"], |
| 509 | system_shared_libs: [], |
| 510 | sdk_version: "27", |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 511 | min_sdk_version: "27", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | cc_library { |
| 515 | name: "libbar", |
| 516 | stl: "none", |
| 517 | system_shared_libs: [], |
| 518 | sdk_version: "current", |
Spandan Das | 456a77e | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 519 | min_sdk_version: "current", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 520 | } |
| 521 | ` |
| 522 | testJavaError(t, `"libjni" .*: links "libbar" built against newer API version "current"`, bp) |
| 523 | } |
| 524 | |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 525 | func TestResourceDirs(t *testing.T) { |
| 526 | testCases := []struct { |
| 527 | name string |
| 528 | prop string |
| 529 | resources []string |
| 530 | }{ |
| 531 | { |
| 532 | name: "no resource_dirs", |
| 533 | prop: "", |
| 534 | resources: []string{"res/res/values/strings.xml"}, |
| 535 | }, |
| 536 | { |
| 537 | name: "resource_dirs", |
| 538 | prop: `resource_dirs: ["res"]`, |
| 539 | resources: []string{"res/res/values/strings.xml"}, |
| 540 | }, |
| 541 | { |
| 542 | name: "empty resource_dirs", |
| 543 | prop: `resource_dirs: []`, |
| 544 | resources: nil, |
| 545 | }, |
| 546 | } |
| 547 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 548 | fs := android.MockFS{ |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 549 | "res/res/values/strings.xml": nil, |
| 550 | } |
| 551 | |
| 552 | bp := ` |
| 553 | android_app { |
| 554 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 555 | sdk_version: "current", |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 556 | %s |
| 557 | } |
| 558 | ` |
| 559 | |
| 560 | for _, testCase := range testCases { |
| 561 | t.Run(testCase.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 562 | result := android.GroupFixturePreparers( |
| 563 | PrepareForTestWithJavaDefaultModules, |
| 564 | PrepareForTestWithOverlayBuildComponents, |
| 565 | fs.AddToFixture(), |
| 566 | ).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop)) |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 567 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 568 | module := result.ModuleForTests("foo", "android_common") |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 569 | resourceList := module.MaybeOutput("aapt2/res.list") |
| 570 | |
| 571 | var resources []string |
| 572 | if resourceList.Rule != nil { |
| 573 | for _, compiledResource := range resourceList.Inputs.Strings() { |
| 574 | resources = append(resources, module.Output(compiledResource).Inputs.Strings()...) |
| 575 | } |
| 576 | } |
| 577 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 578 | android.AssertDeepEquals(t, "resource files", testCase.resources, resources) |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 579 | }) |
| 580 | } |
| 581 | } |
| 582 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 583 | func TestLibraryAssets(t *testing.T) { |
| 584 | bp := ` |
| 585 | android_app { |
| 586 | name: "foo", |
| 587 | sdk_version: "current", |
| 588 | static_libs: ["lib1", "lib2", "lib3"], |
| 589 | } |
| 590 | |
| 591 | android_library { |
| 592 | name: "lib1", |
| 593 | sdk_version: "current", |
| 594 | asset_dirs: ["assets_a"], |
| 595 | } |
| 596 | |
| 597 | android_library { |
| 598 | name: "lib2", |
| 599 | sdk_version: "current", |
| 600 | } |
| 601 | |
| 602 | android_library { |
| 603 | name: "lib3", |
| 604 | sdk_version: "current", |
| 605 | static_libs: ["lib4"], |
| 606 | } |
| 607 | |
| 608 | android_library { |
| 609 | name: "lib4", |
| 610 | sdk_version: "current", |
| 611 | asset_dirs: ["assets_b"], |
| 612 | } |
| 613 | ` |
| 614 | |
| 615 | testCases := []struct { |
| 616 | name string |
| 617 | assetFlag string |
| 618 | assetPackages []string |
| 619 | }{ |
| 620 | { |
| 621 | name: "foo", |
| 622 | // lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively. |
| 623 | assetPackages: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 624 | "out/soong/.intermediates/foo/android_common/aapt2/package-res.apk", |
| 625 | "out/soong/.intermediates/lib1/android_common/assets.zip", |
| 626 | "out/soong/.intermediates/lib3/android_common/assets.zip", |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 627 | }, |
| 628 | }, |
| 629 | { |
| 630 | name: "lib1", |
| 631 | assetFlag: "-A assets_a", |
| 632 | }, |
| 633 | { |
| 634 | name: "lib2", |
| 635 | }, |
| 636 | { |
| 637 | name: "lib3", |
| 638 | assetPackages: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 639 | "out/soong/.intermediates/lib3/android_common/aapt2/package-res.apk", |
| 640 | "out/soong/.intermediates/lib4/android_common/assets.zip", |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 641 | }, |
| 642 | }, |
| 643 | { |
| 644 | name: "lib4", |
| 645 | assetFlag: "-A assets_b", |
| 646 | }, |
| 647 | } |
| 648 | ctx := testApp(t, bp) |
| 649 | |
| 650 | for _, test := range testCases { |
| 651 | t.Run(test.name, func(t *testing.T) { |
| 652 | m := ctx.ModuleForTests(test.name, "android_common") |
| 653 | |
| 654 | // Check asset flag in aapt2 link flags |
| 655 | var aapt2link android.TestingBuildParams |
| 656 | if len(test.assetPackages) > 0 { |
| 657 | aapt2link = m.Output("aapt2/package-res.apk") |
| 658 | } else { |
| 659 | aapt2link = m.Output("package-res.apk") |
| 660 | } |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 661 | aapt2link = aapt2link |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 662 | aapt2Flags := aapt2link.Args["flags"] |
| 663 | if test.assetFlag != "" { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 664 | android.AssertStringDoesContain(t, "asset flag", aapt2Flags, test.assetFlag) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 665 | } else { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 666 | android.AssertStringDoesNotContain(t, "aapt2 link flags", aapt2Flags, " -A ") |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | // Check asset merge rule. |
| 670 | if len(test.assetPackages) > 0 { |
| 671 | mergeAssets := m.Output("package-res.apk") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 672 | android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 673 | } |
| 674 | }) |
| 675 | } |
| 676 | } |
| 677 | |
Colin Cross | b014f07 | 2021-02-26 14:54:36 -0800 | [diff] [blame] | 678 | func TestAppJavaResources(t *testing.T) { |
| 679 | bp := ` |
| 680 | android_app { |
| 681 | name: "foo", |
| 682 | sdk_version: "current", |
| 683 | java_resources: ["resources/a"], |
| 684 | srcs: ["a.java"], |
| 685 | } |
| 686 | |
| 687 | android_app { |
| 688 | name: "bar", |
| 689 | sdk_version: "current", |
| 690 | java_resources: ["resources/a"], |
| 691 | } |
| 692 | ` |
| 693 | |
| 694 | ctx := testApp(t, bp) |
| 695 | |
| 696 | foo := ctx.ModuleForTests("foo", "android_common") |
| 697 | fooResources := foo.Output("res/foo.jar") |
| 698 | fooDexJar := foo.Output("dex-withres/foo.jar") |
| 699 | fooDexJarAligned := foo.Output("dex-withres-aligned/foo.jar") |
| 700 | fooApk := foo.Rule("combineApk") |
| 701 | |
| 702 | if g, w := fooDexJar.Inputs.Strings(), fooResources.Output.String(); !android.InList(w, g) { |
| 703 | t.Errorf("expected resource jar %q in foo dex jar inputs %q", w, g) |
| 704 | } |
| 705 | |
| 706 | if g, w := fooDexJarAligned.Input.String(), fooDexJar.Output.String(); g != w { |
| 707 | t.Errorf("expected dex jar %q in foo aligned dex jar inputs %q", w, g) |
| 708 | } |
| 709 | |
| 710 | if g, w := fooApk.Inputs.Strings(), fooDexJarAligned.Output.String(); !android.InList(w, g) { |
| 711 | t.Errorf("expected aligned dex jar %q in foo apk inputs %q", w, g) |
| 712 | } |
| 713 | |
| 714 | bar := ctx.ModuleForTests("bar", "android_common") |
| 715 | barResources := bar.Output("res/bar.jar") |
| 716 | barApk := bar.Rule("combineApk") |
| 717 | |
| 718 | if g, w := barApk.Inputs.Strings(), barResources.Output.String(); !android.InList(w, g) { |
| 719 | t.Errorf("expected resources jar %q in bar apk inputs %q", w, g) |
| 720 | } |
| 721 | } |
| 722 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 723 | func TestAndroidResources(t *testing.T) { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 724 | testCases := []struct { |
| 725 | name string |
| 726 | enforceRROTargets []string |
| 727 | enforceRROExcludedOverlays []string |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 728 | resourceFiles map[string][]string |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 729 | overlayFiles map[string][]string |
| 730 | rroDirs map[string][]string |
| 731 | }{ |
| 732 | { |
| 733 | name: "no RRO", |
| 734 | enforceRROTargets: nil, |
| 735 | enforceRROExcludedOverlays: nil, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 736 | resourceFiles: map[string][]string{ |
| 737 | "foo": nil, |
| 738 | "bar": {"bar/res/res/values/strings.xml"}, |
| 739 | "lib": nil, |
| 740 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 741 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 742 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 743 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 744 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 745 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 746 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 747 | "foo/res/res/values/strings.xml", |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 748 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 749 | "device/vendor/blah/overlay/foo/res/values/strings.xml", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 750 | "product/vendor/blah/overlay/foo/res/values/strings.xml", |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 751 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 752 | "bar": { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 753 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", |
| 754 | "device/vendor/blah/overlay/bar/res/values/strings.xml", |
| 755 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 756 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 757 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 758 | "lib/res/res/values/strings.xml", |
| 759 | "device/vendor/blah/overlay/lib/res/values/strings.xml", |
| 760 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 761 | }, |
| 762 | rroDirs: map[string][]string{ |
| 763 | "foo": nil, |
| 764 | "bar": nil, |
| 765 | }, |
| 766 | }, |
| 767 | { |
| 768 | name: "enforce RRO on foo", |
| 769 | enforceRROTargets: []string{"foo"}, |
| 770 | enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"}, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 771 | resourceFiles: map[string][]string{ |
| 772 | "foo": nil, |
| 773 | "bar": {"bar/res/res/values/strings.xml"}, |
| 774 | "lib": nil, |
| 775 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 776 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 777 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 778 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 779 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 780 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 781 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 782 | "foo/res/res/values/strings.xml", |
| 783 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 784 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 785 | "bar": { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 786 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", |
| 787 | "device/vendor/blah/overlay/bar/res/values/strings.xml", |
| 788 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 789 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 790 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 791 | "lib/res/res/values/strings.xml", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 792 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 793 | }, |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 794 | |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 795 | rroDirs: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 796 | "foo": { |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 797 | "device:device/vendor/blah/overlay/foo/res", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 798 | "product:product/vendor/blah/overlay/foo/res", |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 799 | "device:device/vendor/blah/overlay/lib/res", |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 800 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 801 | "bar": nil, |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 802 | "lib": {"device:device/vendor/blah/overlay/lib/res"}, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 803 | }, |
| 804 | }, |
| 805 | { |
| 806 | name: "enforce RRO on all", |
| 807 | enforceRROTargets: []string{"*"}, |
| 808 | enforceRROExcludedOverlays: []string{ |
| 809 | // Excluding specific apps/res directories also allowed. |
| 810 | "device/vendor/blah/static_overlay/foo", |
| 811 | "device/vendor/blah/static_overlay/bar/res", |
| 812 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 813 | resourceFiles: map[string][]string{ |
| 814 | "foo": nil, |
| 815 | "bar": {"bar/res/res/values/strings.xml"}, |
| 816 | "lib": nil, |
| 817 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 818 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 819 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 820 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 821 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 822 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 823 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 824 | "foo/res/res/values/strings.xml", |
| 825 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 826 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 827 | "bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"}, |
| 828 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 829 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 830 | "lib/res/res/values/strings.xml", |
| 831 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 832 | }, |
| 833 | rroDirs: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 834 | "foo": { |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 835 | "device:device/vendor/blah/overlay/foo/res", |
| 836 | "product:product/vendor/blah/overlay/foo/res", |
| 837 | // Lib dep comes after the direct deps |
| 838 | "device:device/vendor/blah/overlay/lib/res", |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 839 | }, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 840 | "bar": {"device:device/vendor/blah/overlay/bar/res"}, |
| 841 | "lib": {"device:device/vendor/blah/overlay/lib/res"}, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 842 | }, |
| 843 | }, |
| 844 | } |
| 845 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 846 | deviceResourceOverlays := []string{ |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 847 | "device/vendor/blah/overlay", |
| 848 | "device/vendor/blah/overlay2", |
| 849 | "device/vendor/blah/static_overlay", |
| 850 | } |
| 851 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 852 | productResourceOverlays := []string{ |
| 853 | "product/vendor/blah/overlay", |
| 854 | } |
| 855 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 856 | fs := android.MockFS{ |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 857 | "foo/res/res/values/strings.xml": nil, |
| 858 | "bar/res/res/values/strings.xml": nil, |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 859 | "lib/res/res/values/strings.xml": nil, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 860 | "lib2/res/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 861 | "device/vendor/blah/overlay/foo/res/values/strings.xml": nil, |
| 862 | "device/vendor/blah/overlay/bar/res/values/strings.xml": nil, |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 863 | "device/vendor/blah/overlay/lib/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 864 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil, |
| 865 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil, |
| 866 | "device/vendor/blah/overlay2/res/values/strings.xml": nil, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 867 | "product/vendor/blah/overlay/foo/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | bp := ` |
| 871 | android_app { |
| 872 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 873 | sdk_version: "current", |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 874 | resource_dirs: ["foo/res"], |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 875 | static_libs: ["lib", "lib3"], |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | android_app { |
| 879 | name: "bar", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 880 | sdk_version: "current", |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 881 | resource_dirs: ["bar/res"], |
| 882 | } |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 883 | |
| 884 | android_library { |
| 885 | name: "lib", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 886 | sdk_version: "current", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 887 | resource_dirs: ["lib/res"], |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 888 | static_libs: ["lib2"], |
| 889 | } |
| 890 | |
| 891 | android_library { |
| 892 | name: "lib2", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 893 | sdk_version: "current", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 894 | resource_dirs: ["lib2/res"], |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 895 | } |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 896 | |
| 897 | // This library has the same resources as lib (should not lead to dupe RROs) |
| 898 | android_library { |
| 899 | name: "lib3", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 900 | sdk_version: "current", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 901 | resource_dirs: ["lib/res"] |
| 902 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 903 | ` |
| 904 | |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 905 | for _, testCase := range testCases { |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 906 | t.Run(testCase.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 907 | result := android.GroupFixturePreparers( |
| 908 | PrepareForTestWithJavaDefaultModules, |
| 909 | PrepareForTestWithOverlayBuildComponents, |
| 910 | fs.AddToFixture(), |
| 911 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 912 | variables.DeviceResourceOverlays = deviceResourceOverlays |
| 913 | variables.ProductResourceOverlays = productResourceOverlays |
| 914 | if testCase.enforceRROTargets != nil { |
| 915 | variables.EnforceRROTargets = testCase.enforceRROTargets |
| 916 | } |
| 917 | if testCase.enforceRROExcludedOverlays != nil { |
| 918 | variables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays |
| 919 | } |
| 920 | }), |
| 921 | ).RunTestWithBp(t, bp) |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 922 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 923 | resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { |
| 924 | for _, o := range list { |
| 925 | res := module.MaybeOutput(o) |
| 926 | if res.Rule != nil { |
| 927 | // If the overlay is compiled as part of this module (i.e. a .arsc.flat file), |
| 928 | // verify the inputs to the .arsc.flat rule. |
| 929 | files = append(files, res.Inputs.Strings()...) |
| 930 | } else { |
| 931 | // Otherwise, verify the full path to the output of the other module |
| 932 | files = append(files, o) |
Anton Hansson | 94c93f3 | 2019-01-30 16:03:37 +0000 | [diff] [blame] | 933 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 934 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 935 | return files |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 938 | getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 939 | module := result.ModuleForTests(moduleName, "android_common") |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 940 | resourceList := module.MaybeOutput("aapt2/res.list") |
| 941 | if resourceList.Rule != nil { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 942 | resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs)) |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 943 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 944 | overlayList := module.MaybeOutput("aapt2/overlay.list") |
| 945 | if overlayList.Rule != nil { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 946 | overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs)) |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 947 | } |
| 948 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 949 | for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() { |
| 950 | var prefix string |
| 951 | if d.overlayType == device { |
| 952 | prefix = "device:" |
| 953 | } else if d.overlayType == product { |
| 954 | prefix = "product:" |
| 955 | } else { |
| 956 | t.Fatalf("Unexpected overlayType %d", d.overlayType) |
| 957 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 958 | rroDirs = append(rroDirs, prefix+android.PathRelativeToTop(d.path)) |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 959 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 960 | |
| 961 | return resourceFiles, overlayFiles, rroDirs |
| 962 | } |
| 963 | |
| 964 | modules := []string{"foo", "bar", "lib", "lib2"} |
| 965 | for _, module := range modules { |
| 966 | resourceFiles, overlayFiles, rroDirs := getResources(module) |
| 967 | |
| 968 | if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) { |
| 969 | t.Errorf("expected %s resource files:\n %#v\n got:\n %#v", |
| 970 | module, testCase.resourceFiles[module], resourceFiles) |
| 971 | } |
| 972 | if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) { |
| 973 | t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v", |
| 974 | module, testCase.overlayFiles[module], overlayFiles) |
| 975 | } |
| 976 | if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) { |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 977 | t.Errorf("expected %s rroDirs: %#v\n got:\n %#v", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 978 | module, testCase.rroDirs[module], rroDirs) |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 979 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 980 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 981 | }) |
| 982 | } |
| 983 | } |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 984 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 985 | func checkSdkVersion(t *testing.T, result *android.TestResult, expectedSdkVersion string) { |
| 986 | foo := result.ModuleForTests("foo", "android_common") |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 987 | link := foo.Output("package-res.apk") |
| 988 | linkFlags := strings.Split(link.Args["flags"], " ") |
| 989 | min := android.IndexList("--min-sdk-version", linkFlags) |
| 990 | target := android.IndexList("--target-sdk-version", linkFlags) |
| 991 | |
| 992 | if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 { |
| 993 | t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags) |
| 994 | } |
| 995 | |
| 996 | gotMinSdkVersion := linkFlags[min+1] |
| 997 | gotTargetSdkVersion := linkFlags[target+1] |
| 998 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 999 | android.AssertStringEquals(t, "incorrect --min-sdk-version", expectedSdkVersion, gotMinSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1000 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1001 | android.AssertStringEquals(t, "incorrect --target-sdk-version", expectedSdkVersion, gotTargetSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1002 | } |
| 1003 | |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1004 | func TestAppSdkVersion(t *testing.T) { |
| 1005 | testCases := []struct { |
| 1006 | name string |
| 1007 | sdkVersion string |
| 1008 | platformSdkInt int |
| 1009 | platformSdkCodename string |
| 1010 | platformSdkFinal bool |
| 1011 | expectedMinSdkVersion string |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1012 | platformApis bool |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1013 | activeCodenames []string |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1014 | }{ |
| 1015 | { |
| 1016 | name: "current final SDK", |
| 1017 | sdkVersion: "current", |
| 1018 | platformSdkInt: 27, |
| 1019 | platformSdkCodename: "REL", |
| 1020 | platformSdkFinal: true, |
| 1021 | expectedMinSdkVersion: "27", |
| 1022 | }, |
| 1023 | { |
| 1024 | name: "current non-final SDK", |
| 1025 | sdkVersion: "current", |
| 1026 | platformSdkInt: 27, |
| 1027 | platformSdkCodename: "OMR1", |
| 1028 | platformSdkFinal: false, |
| 1029 | expectedMinSdkVersion: "OMR1", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1030 | activeCodenames: []string{"OMR1"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1031 | }, |
| 1032 | { |
| 1033 | name: "default final SDK", |
| 1034 | sdkVersion: "", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1035 | platformApis: true, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1036 | platformSdkInt: 27, |
| 1037 | platformSdkCodename: "REL", |
| 1038 | platformSdkFinal: true, |
| 1039 | expectedMinSdkVersion: "27", |
| 1040 | }, |
| 1041 | { |
| 1042 | name: "default non-final SDK", |
| 1043 | sdkVersion: "", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1044 | platformApis: true, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1045 | platformSdkInt: 27, |
| 1046 | platformSdkCodename: "OMR1", |
| 1047 | platformSdkFinal: false, |
| 1048 | expectedMinSdkVersion: "OMR1", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1049 | activeCodenames: []string{"OMR1"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1050 | }, |
| 1051 | { |
| 1052 | name: "14", |
| 1053 | sdkVersion: "14", |
| 1054 | expectedMinSdkVersion: "14", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1055 | platformSdkCodename: "S", |
| 1056 | activeCodenames: []string{"S"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1057 | }, |
| 1058 | } |
| 1059 | |
| 1060 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 1061 | for _, test := range testCases { |
| 1062 | t.Run(moduleType+" "+test.name, func(t *testing.T) { |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1063 | platformApiProp := "" |
| 1064 | if test.platformApis { |
| 1065 | platformApiProp = "platform_apis: true," |
| 1066 | } |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1067 | bp := fmt.Sprintf(`%s { |
| 1068 | name: "foo", |
| 1069 | srcs: ["a.java"], |
| 1070 | sdk_version: "%s", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1071 | %s |
| 1072 | }`, moduleType, test.sdkVersion, platformApiProp) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1073 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 1074 | result := android.GroupFixturePreparers( |
| 1075 | prepareForJavaTest, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1076 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1077 | variables.Platform_sdk_version = &test.platformSdkInt |
| 1078 | variables.Platform_sdk_codename = &test.platformSdkCodename |
| 1079 | variables.Platform_version_active_codenames = test.activeCodenames |
| 1080 | variables.Platform_sdk_final = &test.platformSdkFinal |
| 1081 | }), |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 1082 | FixtureWithPrebuiltApis(map[string][]string{ |
| 1083 | "14": {"foo"}, |
| 1084 | }), |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1085 | ).RunTestWithBp(t, bp) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1086 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1087 | checkSdkVersion(t, result, test.expectedMinSdkVersion) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1088 | }) |
| 1089 | } |
| 1090 | } |
| 1091 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1092 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1093 | func TestVendorAppSdkVersion(t *testing.T) { |
| 1094 | testCases := []struct { |
| 1095 | name string |
| 1096 | sdkVersion string |
| 1097 | platformSdkInt int |
| 1098 | platformSdkCodename string |
| 1099 | platformSdkFinal bool |
| 1100 | deviceCurrentApiLevelForVendorModules string |
| 1101 | expectedMinSdkVersion string |
| 1102 | }{ |
| 1103 | { |
| 1104 | name: "current final SDK", |
| 1105 | sdkVersion: "current", |
| 1106 | platformSdkInt: 29, |
| 1107 | platformSdkCodename: "REL", |
| 1108 | platformSdkFinal: true, |
| 1109 | deviceCurrentApiLevelForVendorModules: "29", |
| 1110 | expectedMinSdkVersion: "29", |
| 1111 | }, |
| 1112 | { |
| 1113 | name: "current final SDK", |
| 1114 | sdkVersion: "current", |
| 1115 | platformSdkInt: 29, |
| 1116 | platformSdkCodename: "REL", |
| 1117 | platformSdkFinal: true, |
| 1118 | deviceCurrentApiLevelForVendorModules: "28", |
| 1119 | expectedMinSdkVersion: "28", |
| 1120 | }, |
| 1121 | { |
| 1122 | name: "current final SDK", |
| 1123 | sdkVersion: "current", |
| 1124 | platformSdkInt: 29, |
| 1125 | platformSdkCodename: "Q", |
| 1126 | platformSdkFinal: false, |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1127 | deviceCurrentApiLevelForVendorModules: "28", |
| 1128 | expectedMinSdkVersion: "28", |
| 1129 | }, |
| 1130 | } |
| 1131 | |
| 1132 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 1133 | for _, sdkKind := range []string{"", "system_"} { |
| 1134 | for _, test := range testCases { |
| 1135 | t.Run(moduleType+" "+test.name, func(t *testing.T) { |
| 1136 | bp := fmt.Sprintf(`%s { |
| 1137 | name: "foo", |
| 1138 | srcs: ["a.java"], |
| 1139 | sdk_version: "%s%s", |
| 1140 | vendor: true, |
| 1141 | }`, moduleType, sdkKind, test.sdkVersion) |
| 1142 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 1143 | result := android.GroupFixturePreparers( |
| 1144 | prepareForJavaTest, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1145 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1146 | variables.Platform_sdk_version = &test.platformSdkInt |
| 1147 | variables.Platform_sdk_codename = &test.platformSdkCodename |
| 1148 | variables.Platform_sdk_final = &test.platformSdkFinal |
| 1149 | variables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules |
| 1150 | variables.DeviceSystemSdkVersions = []string{"28", "29"} |
| 1151 | }), |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 1152 | FixtureWithPrebuiltApis(map[string][]string{ |
| 1153 | "28": {"foo"}, |
| 1154 | "29": {"foo"}, |
| 1155 | "current": {"foo"}, |
| 1156 | }), |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1157 | ).RunTestWithBp(t, bp) |
| 1158 | |
| 1159 | checkSdkVersion(t, result, test.expectedMinSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1160 | }) |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1166 | func TestJNIABI(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1167 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1168 | cc_library { |
| 1169 | name: "libjni", |
| 1170 | system_shared_libs: [], |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1171 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1172 | stl: "none", |
| 1173 | } |
| 1174 | |
| 1175 | android_test { |
| 1176 | name: "test", |
| 1177 | sdk_version: "core_platform", |
| 1178 | jni_libs: ["libjni"], |
| 1179 | } |
| 1180 | |
| 1181 | android_test { |
| 1182 | name: "test_first", |
| 1183 | sdk_version: "core_platform", |
| 1184 | compile_multilib: "first", |
| 1185 | jni_libs: ["libjni"], |
| 1186 | } |
| 1187 | |
| 1188 | android_test { |
| 1189 | name: "test_both", |
| 1190 | sdk_version: "core_platform", |
| 1191 | compile_multilib: "both", |
| 1192 | jni_libs: ["libjni"], |
| 1193 | } |
| 1194 | |
| 1195 | android_test { |
| 1196 | name: "test_32", |
| 1197 | sdk_version: "core_platform", |
| 1198 | compile_multilib: "32", |
| 1199 | jni_libs: ["libjni"], |
| 1200 | } |
| 1201 | |
| 1202 | android_test { |
| 1203 | name: "test_64", |
| 1204 | sdk_version: "core_platform", |
| 1205 | compile_multilib: "64", |
| 1206 | jni_libs: ["libjni"], |
| 1207 | } |
| 1208 | `) |
| 1209 | |
| 1210 | testCases := []struct { |
| 1211 | name string |
| 1212 | abis []string |
| 1213 | }{ |
| 1214 | {"test", []string{"arm64-v8a"}}, |
| 1215 | {"test_first", []string{"arm64-v8a"}}, |
| 1216 | {"test_both", []string{"arm64-v8a", "armeabi-v7a"}}, |
| 1217 | {"test_32", []string{"armeabi-v7a"}}, |
| 1218 | {"test_64", []string{"arm64-v8a"}}, |
| 1219 | } |
| 1220 | |
| 1221 | for _, test := range testCases { |
| 1222 | t.Run(test.name, func(t *testing.T) { |
| 1223 | app := ctx.ModuleForTests(test.name, "android_common") |
| 1224 | jniLibZip := app.Output("jnilibs.zip") |
| 1225 | var abis []string |
| 1226 | args := strings.Fields(jniLibZip.Args["jarArgs"]) |
| 1227 | for i := 0; i < len(args); i++ { |
| 1228 | if args[i] == "-P" { |
| 1229 | abis = append(abis, filepath.Base(args[i+1])) |
| 1230 | i++ |
| 1231 | } |
| 1232 | } |
| 1233 | if !reflect.DeepEqual(abis, test.abis) { |
| 1234 | t.Errorf("want abis %v, got %v", test.abis, abis) |
| 1235 | } |
| 1236 | }) |
| 1237 | } |
| 1238 | } |
| 1239 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1240 | func TestAppSdkVersionByPartition(t *testing.T) { |
| 1241 | testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", ` |
| 1242 | android_app { |
| 1243 | name: "foo", |
| 1244 | srcs: ["a.java"], |
| 1245 | vendor: true, |
| 1246 | platform_apis: true, |
| 1247 | } |
| 1248 | `) |
| 1249 | |
| 1250 | testJava(t, ` |
| 1251 | android_app { |
| 1252 | name: "bar", |
| 1253 | srcs: ["b.java"], |
| 1254 | platform_apis: true, |
| 1255 | } |
| 1256 | `) |
| 1257 | |
| 1258 | for _, enforce := range []bool{true, false} { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1259 | bp := ` |
| 1260 | android_app { |
| 1261 | name: "foo", |
| 1262 | srcs: ["a.java"], |
| 1263 | product_specific: true, |
| 1264 | platform_apis: true, |
| 1265 | } |
| 1266 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1267 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1268 | errorHandler := android.FixtureExpectsNoErrors |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1269 | if enforce { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1270 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product") |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1271 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1272 | |
| 1273 | android.GroupFixturePreparers( |
| 1274 | PrepareForTestWithJavaDefaultModules, |
| 1275 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1276 | variables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) |
| 1277 | }), |
| 1278 | ). |
| 1279 | ExtendWithErrorHandler(errorHandler). |
| 1280 | RunTestWithBp(t, bp) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1284 | func TestJNIPackaging(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1285 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1286 | cc_library { |
| 1287 | name: "libjni", |
| 1288 | system_shared_libs: [], |
| 1289 | stl: "none", |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 1290 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | android_app { |
| 1294 | name: "app", |
| 1295 | jni_libs: ["libjni"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1296 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | android_app { |
| 1300 | name: "app_noembed", |
| 1301 | jni_libs: ["libjni"], |
| 1302 | use_embedded_native_libs: false, |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1303 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | android_app { |
| 1307 | name: "app_embed", |
| 1308 | jni_libs: ["libjni"], |
| 1309 | use_embedded_native_libs: true, |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1310 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | android_test { |
| 1314 | name: "test", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1315 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1316 | jni_libs: ["libjni"], |
| 1317 | } |
| 1318 | |
| 1319 | android_test { |
| 1320 | name: "test_noembed", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1321 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1322 | jni_libs: ["libjni"], |
| 1323 | use_embedded_native_libs: false, |
| 1324 | } |
| 1325 | |
| 1326 | android_test_helper_app { |
| 1327 | name: "test_helper", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1328 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1329 | jni_libs: ["libjni"], |
| 1330 | } |
| 1331 | |
| 1332 | android_test_helper_app { |
| 1333 | name: "test_helper_noembed", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1334 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1335 | jni_libs: ["libjni"], |
| 1336 | use_embedded_native_libs: false, |
| 1337 | } |
| 1338 | `) |
| 1339 | |
| 1340 | testCases := []struct { |
| 1341 | name string |
| 1342 | packaged bool |
| 1343 | compressed bool |
| 1344 | }{ |
| 1345 | {"app", false, false}, |
| 1346 | {"app_noembed", false, false}, |
| 1347 | {"app_embed", true, false}, |
| 1348 | {"test", true, false}, |
| 1349 | {"test_noembed", true, true}, |
| 1350 | {"test_helper", true, false}, |
| 1351 | {"test_helper_noembed", true, true}, |
| 1352 | } |
| 1353 | |
| 1354 | for _, test := range testCases { |
| 1355 | t.Run(test.name, func(t *testing.T) { |
| 1356 | app := ctx.ModuleForTests(test.name, "android_common") |
| 1357 | jniLibZip := app.MaybeOutput("jnilibs.zip") |
| 1358 | if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { |
| 1359 | t.Errorf("expected jni packaged %v, got %v", w, g) |
| 1360 | } |
| 1361 | |
| 1362 | if jniLibZip.Rule != nil { |
| 1363 | if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w { |
| 1364 | t.Errorf("expected jni compressed %v, got %v", w, g) |
| 1365 | } |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1366 | |
| 1367 | if !strings.Contains(jniLibZip.Implicits[0].String(), "_sdk_") { |
| 1368 | t.Errorf("expected input %q to use sdk variant", jniLibZip.Implicits[0].String()) |
| 1369 | } |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1370 | } |
| 1371 | }) |
| 1372 | } |
Colin Cross | 47fa9d3 | 2019-03-26 10:51:39 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1375 | func TestJNISDK(t *testing.T) { |
| 1376 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
| 1377 | cc_library { |
| 1378 | name: "libjni", |
| 1379 | system_shared_libs: [], |
| 1380 | stl: "none", |
| 1381 | sdk_version: "current", |
| 1382 | } |
| 1383 | |
| 1384 | android_test { |
| 1385 | name: "app_platform", |
| 1386 | jni_libs: ["libjni"], |
| 1387 | platform_apis: true, |
| 1388 | } |
| 1389 | |
| 1390 | android_test { |
| 1391 | name: "app_sdk", |
| 1392 | jni_libs: ["libjni"], |
| 1393 | sdk_version: "current", |
| 1394 | } |
| 1395 | |
| 1396 | android_test { |
| 1397 | name: "app_force_platform", |
| 1398 | jni_libs: ["libjni"], |
| 1399 | sdk_version: "current", |
| 1400 | jni_uses_platform_apis: true, |
| 1401 | } |
| 1402 | |
| 1403 | android_test { |
| 1404 | name: "app_force_sdk", |
| 1405 | jni_libs: ["libjni"], |
| 1406 | platform_apis: true, |
| 1407 | jni_uses_sdk_apis: true, |
| 1408 | } |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1409 | |
| 1410 | cc_library { |
| 1411 | name: "libvendorjni", |
| 1412 | system_shared_libs: [], |
| 1413 | stl: "none", |
| 1414 | vendor: true, |
| 1415 | } |
| 1416 | |
| 1417 | android_test { |
| 1418 | name: "app_vendor", |
| 1419 | jni_libs: ["libvendorjni"], |
| 1420 | sdk_version: "current", |
| 1421 | vendor: true, |
| 1422 | } |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1423 | `) |
| 1424 | |
| 1425 | testCases := []struct { |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1426 | name string |
| 1427 | sdkJNI bool |
| 1428 | vendorJNI bool |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1429 | }{ |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1430 | {name: "app_platform"}, |
| 1431 | {name: "app_sdk", sdkJNI: true}, |
| 1432 | {name: "app_force_platform"}, |
| 1433 | {name: "app_force_sdk", sdkJNI: true}, |
| 1434 | {name: "app_vendor", vendorJNI: true}, |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1437 | platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared"). |
| 1438 | Output("libjni.so").Output.String() |
| 1439 | sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared"). |
| 1440 | Output("libjni.so").Output.String() |
| 1441 | vendorJNI := ctx.ModuleForTests("libvendorjni", "android_arm64_armv8-a_shared"). |
| 1442 | Output("libvendorjni.so").Output.String() |
| 1443 | |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1444 | for _, test := range testCases { |
| 1445 | t.Run(test.name, func(t *testing.T) { |
| 1446 | app := ctx.ModuleForTests(test.name, "android_common") |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1447 | |
| 1448 | jniLibZip := app.MaybeOutput("jnilibs.zip") |
| 1449 | if len(jniLibZip.Implicits) != 1 { |
| 1450 | t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings()) |
| 1451 | } |
| 1452 | gotJNI := jniLibZip.Implicits[0].String() |
| 1453 | |
| 1454 | if test.sdkJNI { |
| 1455 | if gotJNI != sdkJNI { |
| 1456 | t.Errorf("expected SDK JNI library %q, got %q", sdkJNI, gotJNI) |
| 1457 | } |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 1458 | } else if test.vendorJNI { |
| 1459 | if gotJNI != vendorJNI { |
| 1460 | t.Errorf("expected platform JNI library %q, got %q", vendorJNI, gotJNI) |
| 1461 | } |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1462 | } else { |
| 1463 | if gotJNI != platformJNI { |
| 1464 | t.Errorf("expected platform JNI library %q, got %q", platformJNI, gotJNI) |
| 1465 | } |
| 1466 | } |
| 1467 | }) |
| 1468 | } |
| 1469 | |
| 1470 | t.Run("jni_uses_platform_apis_error", func(t *testing.T) { |
| 1471 | testJavaError(t, `jni_uses_platform_apis: can only be set for modules that set sdk_version`, ` |
| 1472 | android_test { |
| 1473 | name: "app_platform", |
| 1474 | platform_apis: true, |
| 1475 | jni_uses_platform_apis: true, |
| 1476 | } |
| 1477 | `) |
| 1478 | }) |
| 1479 | |
| 1480 | t.Run("jni_uses_sdk_apis_error", func(t *testing.T) { |
| 1481 | testJavaError(t, `jni_uses_sdk_apis: can only be set for modules that do not set sdk_version`, ` |
| 1482 | android_test { |
| 1483 | name: "app_sdk", |
| 1484 | sdk_version: "current", |
| 1485 | jni_uses_sdk_apis: true, |
| 1486 | } |
| 1487 | `) |
| 1488 | }) |
| 1489 | |
| 1490 | } |
| 1491 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1492 | func TestCertificates(t *testing.T) { |
| 1493 | testCases := []struct { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1494 | name string |
| 1495 | bp string |
| 1496 | certificateOverride string |
| 1497 | expectedCertSigningFlags string |
| 1498 | expectedCertificate string |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1499 | }{ |
| 1500 | { |
| 1501 | name: "default", |
| 1502 | bp: ` |
| 1503 | android_app { |
| 1504 | name: "foo", |
| 1505 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1506 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1507 | } |
| 1508 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1509 | certificateOverride: "", |
| 1510 | expectedCertSigningFlags: "", |
| 1511 | expectedCertificate: "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1512 | }, |
| 1513 | { |
| 1514 | name: "module certificate property", |
| 1515 | bp: ` |
| 1516 | android_app { |
| 1517 | name: "foo", |
| 1518 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1519 | certificate: ":new_certificate", |
| 1520 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | android_app_certificate { |
| 1524 | name: "new_certificate", |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1525 | certificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1526 | } |
| 1527 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1528 | certificateOverride: "", |
| 1529 | expectedCertSigningFlags: "", |
| 1530 | expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1531 | }, |
| 1532 | { |
| 1533 | name: "path certificate property", |
| 1534 | bp: ` |
| 1535 | android_app { |
| 1536 | name: "foo", |
| 1537 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1538 | certificate: "expiredkey", |
| 1539 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1540 | } |
| 1541 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1542 | certificateOverride: "", |
| 1543 | expectedCertSigningFlags: "", |
| 1544 | expectedCertificate: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1545 | }, |
| 1546 | { |
| 1547 | name: "certificate overrides", |
| 1548 | bp: ` |
| 1549 | android_app { |
| 1550 | name: "foo", |
| 1551 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1552 | certificate: "expiredkey", |
| 1553 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | android_app_certificate { |
| 1557 | name: "new_certificate", |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 1558 | certificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1559 | } |
| 1560 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1561 | certificateOverride: "foo:new_certificate", |
| 1562 | expectedCertSigningFlags: "", |
| 1563 | expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1564 | }, |
| 1565 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1566 | name: "certificate signing flags", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1567 | bp: ` |
| 1568 | android_app { |
| 1569 | name: "foo", |
| 1570 | srcs: ["a.java"], |
| 1571 | certificate: ":new_certificate", |
| 1572 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1573 | rotationMinSdkVersion: "32", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1574 | sdk_version: "current", |
| 1575 | } |
| 1576 | |
| 1577 | android_app_certificate { |
| 1578 | name: "new_certificate", |
| 1579 | certificate: "cert/new_cert", |
| 1580 | } |
| 1581 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1582 | certificateOverride: "", |
| 1583 | expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
| 1584 | expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1585 | }, |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 1586 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1587 | name: "cert signing flags from filegroup", |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 1588 | bp: ` |
| 1589 | android_app { |
| 1590 | name: "foo", |
| 1591 | srcs: ["a.java"], |
| 1592 | certificate: ":new_certificate", |
| 1593 | lineage: ":lineage_bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1594 | rotationMinSdkVersion: "32", |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 1595 | sdk_version: "current", |
| 1596 | } |
| 1597 | |
| 1598 | android_app_certificate { |
| 1599 | name: "new_certificate", |
| 1600 | certificate: "cert/new_cert", |
| 1601 | } |
| 1602 | |
| 1603 | filegroup { |
| 1604 | name: "lineage_bin", |
| 1605 | srcs: ["lineage.bin"], |
| 1606 | } |
| 1607 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1608 | certificateOverride: "", |
| 1609 | expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
| 1610 | expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8", |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 1611 | }, |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | for _, test := range testCases { |
| 1615 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1616 | result := android.GroupFixturePreparers( |
| 1617 | PrepareForTestWithJavaDefaultModules, |
| 1618 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1619 | if test.certificateOverride != "" { |
| 1620 | variables.CertificateOverrides = []string{test.certificateOverride} |
| 1621 | } |
| 1622 | }), |
| 1623 | ).RunTestWithBp(t, test.bp) |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1624 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1625 | foo := result.ModuleForTests("foo", "android_common") |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1626 | |
| 1627 | signapk := foo.Output("foo.apk") |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1628 | signCertificateFlags := signapk.Args["certificates"] |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1629 | android.AssertStringEquals(t, "certificates flags", test.expectedCertificate, signCertificateFlags) |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1630 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1631 | certSigningFlags := signapk.Args["flags"] |
| 1632 | android.AssertStringEquals(t, "cert signing flags", test.expectedCertSigningFlags, certSigningFlags) |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 1633 | }) |
| 1634 | } |
| 1635 | } |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1636 | |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1637 | func TestRequestV4SigningFlag(t *testing.T) { |
| 1638 | testCases := []struct { |
| 1639 | name string |
| 1640 | bp string |
| 1641 | expected string |
| 1642 | }{ |
| 1643 | { |
| 1644 | name: "default", |
| 1645 | bp: ` |
| 1646 | android_app { |
| 1647 | name: "foo", |
| 1648 | srcs: ["a.java"], |
| 1649 | sdk_version: "current", |
| 1650 | } |
| 1651 | `, |
| 1652 | expected: "", |
| 1653 | }, |
| 1654 | { |
| 1655 | name: "default", |
| 1656 | bp: ` |
| 1657 | android_app { |
| 1658 | name: "foo", |
| 1659 | srcs: ["a.java"], |
| 1660 | sdk_version: "current", |
| 1661 | v4_signature: false, |
| 1662 | } |
| 1663 | `, |
| 1664 | expected: "", |
| 1665 | }, |
| 1666 | { |
| 1667 | name: "module certificate property", |
| 1668 | bp: ` |
| 1669 | android_app { |
| 1670 | name: "foo", |
| 1671 | srcs: ["a.java"], |
| 1672 | sdk_version: "current", |
| 1673 | v4_signature: true, |
| 1674 | } |
| 1675 | `, |
| 1676 | expected: "--enable-v4", |
| 1677 | }, |
| 1678 | } |
| 1679 | |
| 1680 | for _, test := range testCases { |
| 1681 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1682 | result := android.GroupFixturePreparers( |
| 1683 | PrepareForTestWithJavaDefaultModules, |
| 1684 | ).RunTestWithBp(t, test.bp) |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1685 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1686 | foo := result.ModuleForTests("foo", "android_common") |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1687 | |
| 1688 | signapk := foo.Output("foo.apk") |
| 1689 | signFlags := signapk.Args["flags"] |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1690 | android.AssertStringEquals(t, "signing flags", test.expected, signFlags) |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 1691 | }) |
| 1692 | } |
| 1693 | } |
| 1694 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1695 | func TestPackageNameOverride(t *testing.T) { |
| 1696 | testCases := []struct { |
| 1697 | name string |
| 1698 | bp string |
| 1699 | packageNameOverride string |
| 1700 | expected []string |
| 1701 | }{ |
| 1702 | { |
| 1703 | name: "default", |
| 1704 | bp: ` |
| 1705 | android_app { |
| 1706 | name: "foo", |
| 1707 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1708 | sdk_version: "current", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1709 | } |
| 1710 | `, |
| 1711 | packageNameOverride: "", |
| 1712 | expected: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1713 | "out/soong/.intermediates/foo/android_common/foo.apk", |
| 1714 | "out/soong/target/product/test_device/system/app/foo/foo.apk", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1715 | }, |
| 1716 | }, |
| 1717 | { |
Jooyung Han | 29e2f6d | 2022-01-08 12:13:59 +0900 | [diff] [blame] | 1718 | name: "overridden via PRODUCT_PACKAGE_NAME_OVERRIDES", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1719 | bp: ` |
| 1720 | android_app { |
| 1721 | name: "foo", |
| 1722 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1723 | sdk_version: "current", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1724 | } |
| 1725 | `, |
| 1726 | packageNameOverride: "foo:bar", |
| 1727 | expected: []string{ |
| 1728 | // The package apk should be still be the original name for test dependencies. |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1729 | "out/soong/.intermediates/foo/android_common/bar.apk", |
| 1730 | "out/soong/target/product/test_device/system/app/bar/bar.apk", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1731 | }, |
| 1732 | }, |
Jooyung Han | 29e2f6d | 2022-01-08 12:13:59 +0900 | [diff] [blame] | 1733 | { |
| 1734 | name: "overridden via stem", |
| 1735 | bp: ` |
| 1736 | android_app { |
| 1737 | name: "foo", |
| 1738 | srcs: ["a.java"], |
| 1739 | sdk_version: "current", |
| 1740 | stem: "bar", |
| 1741 | } |
| 1742 | `, |
| 1743 | packageNameOverride: "", |
| 1744 | expected: []string{ |
| 1745 | "out/soong/.intermediates/foo/android_common/bar.apk", |
| 1746 | "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 1747 | }, |
| 1748 | }, |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | for _, test := range testCases { |
| 1752 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1753 | result := android.GroupFixturePreparers( |
| 1754 | PrepareForTestWithJavaDefaultModules, |
| 1755 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1756 | if test.packageNameOverride != "" { |
| 1757 | variables.PackageNameOverrides = []string{test.packageNameOverride} |
| 1758 | } |
| 1759 | }), |
| 1760 | ).RunTestWithBp(t, test.bp) |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1761 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1762 | foo := result.ModuleForTests("foo", "android_common") |
| 1763 | |
Lukacs T. Berki | fbaf725 | 2021-08-19 09:36:42 +0200 | [diff] [blame] | 1764 | outSoongDir := result.Config.SoongOutDir() |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1765 | |
| 1766 | outputs := foo.AllOutputs() |
| 1767 | outputMap := make(map[string]bool) |
| 1768 | for _, o := range outputs { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1769 | outputMap[android.StringPathRelativeToTop(outSoongDir, o)] = true |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 1770 | } |
| 1771 | for _, e := range test.expected { |
| 1772 | if _, exist := outputMap[e]; !exist { |
| 1773 | t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs) |
| 1774 | } |
| 1775 | } |
| 1776 | }) |
| 1777 | } |
| 1778 | } |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1779 | |
| 1780 | func TestInstrumentationTargetOverridden(t *testing.T) { |
| 1781 | bp := ` |
| 1782 | android_app { |
| 1783 | name: "foo", |
| 1784 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1785 | sdk_version: "current", |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | android_test { |
| 1789 | name: "bar", |
| 1790 | instrumentation_for: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1791 | sdk_version: "current", |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1792 | } |
| 1793 | ` |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1794 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1795 | result := android.GroupFixturePreparers( |
| 1796 | PrepareForTestWithJavaDefaultModules, |
| 1797 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1798 | variables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} |
| 1799 | }), |
| 1800 | ).RunTestWithBp(t, bp) |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1801 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1802 | bar := result.ModuleForTests("bar", "android_common") |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 1803 | res := bar.Output("package-res.apk") |
| 1804 | aapt2Flags := res.Args["flags"] |
| 1805 | e := "--rename-instrumentation-target-package org.dandroid.bp" |
| 1806 | if !strings.Contains(aapt2Flags, e) { |
| 1807 | t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags) |
| 1808 | } |
| 1809 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1810 | |
| 1811 | func TestOverrideAndroidApp(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1812 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp( |
| 1813 | t, ` |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1814 | android_app { |
| 1815 | name: "foo", |
| 1816 | srcs: ["a.java"], |
Jaewoong Jung | a641ee9 | 2019-03-27 11:17:14 -0700 | [diff] [blame] | 1817 | certificate: "expiredkey", |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 1818 | overrides: ["qux"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1819 | sdk_version: "current", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | override_android_app { |
| 1823 | name: "bar", |
| 1824 | base: "foo", |
| 1825 | certificate: ":new_certificate", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1826 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1827 | rotationMinSdkVersion: "32", |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 1828 | logging_parent: "bah", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | android_app_certificate { |
| 1832 | name: "new_certificate", |
| 1833 | certificate: "cert/new_cert", |
| 1834 | } |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1835 | |
| 1836 | override_android_app { |
| 1837 | name: "baz", |
| 1838 | base: "foo", |
| 1839 | package_name: "org.dandroid.bp", |
| 1840 | } |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1841 | |
| 1842 | override_android_app { |
| 1843 | name: "baz_no_rename_resources", |
| 1844 | base: "foo", |
| 1845 | package_name: "org.dandroid.bp", |
| 1846 | rename_resources_package: false, |
| 1847 | } |
| 1848 | |
| 1849 | android_app { |
| 1850 | name: "foo_no_rename_resources", |
| 1851 | srcs: ["a.java"], |
| 1852 | certificate: "expiredkey", |
| 1853 | overrides: ["qux"], |
| 1854 | rename_resources_package: false, |
| 1855 | sdk_version: "current", |
| 1856 | } |
| 1857 | |
| 1858 | override_android_app { |
| 1859 | name: "baz_base_no_rename_resources", |
| 1860 | base: "foo_no_rename_resources", |
| 1861 | package_name: "org.dandroid.bp", |
| 1862 | } |
| 1863 | |
| 1864 | override_android_app { |
| 1865 | name: "baz_override_base_rename_resources", |
| 1866 | base: "foo_no_rename_resources", |
| 1867 | package_name: "org.dandroid.bp", |
| 1868 | rename_resources_package: true, |
| 1869 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1870 | `) |
| 1871 | |
| 1872 | expectedVariants := []struct { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1873 | name string |
| 1874 | moduleName string |
| 1875 | variantName string |
| 1876 | apkName string |
| 1877 | apkPath string |
| 1878 | certFlag string |
| 1879 | certSigningFlags string |
| 1880 | overrides []string |
| 1881 | packageFlag string |
| 1882 | renameResources bool |
| 1883 | logging_parent string |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1884 | }{ |
| 1885 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1886 | name: "foo", |
| 1887 | moduleName: "foo", |
| 1888 | variantName: "android_common", |
| 1889 | apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk", |
| 1890 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 1891 | certSigningFlags: "", |
| 1892 | overrides: []string{"qux"}, |
| 1893 | packageFlag: "", |
| 1894 | renameResources: false, |
| 1895 | logging_parent: "", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1896 | }, |
| 1897 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1898 | name: "foo", |
| 1899 | moduleName: "bar", |
| 1900 | variantName: "android_common_bar", |
| 1901 | apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 1902 | certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", |
| 1903 | certSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
| 1904 | overrides: []string{"qux", "foo"}, |
| 1905 | packageFlag: "", |
| 1906 | renameResources: false, |
| 1907 | logging_parent: "bah", |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1908 | }, |
| 1909 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1910 | name: "foo", |
| 1911 | moduleName: "baz", |
| 1912 | variantName: "android_common_baz", |
| 1913 | apkPath: "out/soong/target/product/test_device/system/app/baz/baz.apk", |
| 1914 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 1915 | certSigningFlags: "", |
| 1916 | overrides: []string{"qux", "foo"}, |
| 1917 | packageFlag: "org.dandroid.bp", |
| 1918 | renameResources: true, |
| 1919 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1920 | }, |
| 1921 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1922 | name: "foo", |
| 1923 | moduleName: "baz_no_rename_resources", |
| 1924 | variantName: "android_common_baz_no_rename_resources", |
| 1925 | apkPath: "out/soong/target/product/test_device/system/app/baz_no_rename_resources/baz_no_rename_resources.apk", |
| 1926 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 1927 | certSigningFlags: "", |
| 1928 | overrides: []string{"qux", "foo"}, |
| 1929 | packageFlag: "org.dandroid.bp", |
| 1930 | renameResources: false, |
| 1931 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1932 | }, |
| 1933 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1934 | name: "foo_no_rename_resources", |
| 1935 | moduleName: "baz_base_no_rename_resources", |
| 1936 | variantName: "android_common_baz_base_no_rename_resources", |
| 1937 | apkPath: "out/soong/target/product/test_device/system/app/baz_base_no_rename_resources/baz_base_no_rename_resources.apk", |
| 1938 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 1939 | certSigningFlags: "", |
| 1940 | overrides: []string{"qux", "foo_no_rename_resources"}, |
| 1941 | packageFlag: "org.dandroid.bp", |
| 1942 | renameResources: false, |
| 1943 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1944 | }, |
| 1945 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1946 | name: "foo_no_rename_resources", |
| 1947 | moduleName: "baz_override_base_rename_resources", |
| 1948 | variantName: "android_common_baz_override_base_rename_resources", |
| 1949 | apkPath: "out/soong/target/product/test_device/system/app/baz_override_base_rename_resources/baz_override_base_rename_resources.apk", |
| 1950 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 1951 | certSigningFlags: "", |
| 1952 | overrides: []string{"qux", "foo_no_rename_resources"}, |
| 1953 | packageFlag: "org.dandroid.bp", |
| 1954 | renameResources: true, |
| 1955 | logging_parent: "", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1956 | }, |
| 1957 | } |
| 1958 | for _, expected := range expectedVariants { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1959 | variant := result.ModuleForTests(expected.name, expected.variantName) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1960 | |
| 1961 | // Check the final apk name |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1962 | variant.Output(expected.apkPath) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1963 | |
| 1964 | // Check the certificate paths |
Jaewoong Jung | 5a49881 | 2019-11-07 14:14:38 -0800 | [diff] [blame] | 1965 | signapk := variant.Output(expected.moduleName + ".apk") |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1966 | certFlag := signapk.Args["certificates"] |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1967 | android.AssertStringEquals(t, "certificates flags", expected.certFlag, certFlag) |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 1968 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 1969 | // Check the cert signing flags |
| 1970 | certSigningFlags := signapk.Args["flags"] |
| 1971 | android.AssertStringEquals(t, "cert signing flags", expected.certSigningFlags, certSigningFlags) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1972 | |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1973 | // Check if the overrides field values are correctly aggregated. |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1974 | mod := variant.Module().(*AndroidApp) |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 1975 | android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides) |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1976 | |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 1977 | // Test Overridable property: Logging_parent |
| 1978 | logging_parent := mod.aapt.LoggingParent |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1979 | android.AssertStringEquals(t, "overrides property value for logging parent", expected.logging_parent, logging_parent) |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 1980 | |
Liz Kammer | 1d5983b | 2020-05-19 19:15:37 +0000 | [diff] [blame] | 1981 | // Check the package renaming flag, if exists. |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 1982 | res := variant.Output("package-res.apk") |
| 1983 | aapt2Flags := res.Args["flags"] |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1984 | checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) |
| 1985 | expectedPackage := expected.packageFlag |
| 1986 | if !expected.renameResources { |
| 1987 | expectedPackage = "" |
Liz Kammer | 1d5983b | 2020-05-19 19:15:37 +0000 | [diff] [blame] | 1988 | } |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 1989 | checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expectedPackage) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1990 | } |
| 1991 | } |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 1992 | |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 1993 | func TestOverrideAndroidAppOverrides(t *testing.T) { |
| 1994 | ctx, _ := testJava( |
| 1995 | t, ` |
| 1996 | android_app { |
| 1997 | name: "foo", |
| 1998 | srcs: ["a.java"], |
| 1999 | sdk_version: "current", |
| 2000 | overrides: ["qux"] |
| 2001 | } |
| 2002 | |
| 2003 | android_app { |
| 2004 | name: "bar", |
| 2005 | srcs: ["b.java"], |
| 2006 | sdk_version: "current", |
| 2007 | overrides: ["foo"] |
| 2008 | } |
| 2009 | |
| 2010 | override_android_app { |
| 2011 | name: "foo_override", |
| 2012 | base: "foo", |
| 2013 | overrides: ["bar"] |
| 2014 | } |
| 2015 | `) |
| 2016 | |
| 2017 | expectedVariants := []struct { |
| 2018 | name string |
| 2019 | moduleName string |
| 2020 | variantName string |
| 2021 | overrides []string |
| 2022 | }{ |
| 2023 | { |
| 2024 | name: "foo", |
| 2025 | moduleName: "foo", |
| 2026 | variantName: "android_common", |
| 2027 | overrides: []string{"qux"}, |
| 2028 | }, |
| 2029 | { |
| 2030 | name: "bar", |
| 2031 | moduleName: "bar", |
| 2032 | variantName: "android_common", |
| 2033 | overrides: []string{"foo"}, |
| 2034 | }, |
| 2035 | { |
| 2036 | name: "foo", |
| 2037 | moduleName: "foo_override", |
| 2038 | variantName: "android_common_foo_override", |
| 2039 | overrides: []string{"bar", "foo"}, |
| 2040 | }, |
| 2041 | } |
| 2042 | for _, expected := range expectedVariants { |
| 2043 | variant := ctx.ModuleForTests(expected.name, expected.variantName) |
| 2044 | |
| 2045 | // Check if the overrides field values are correctly aggregated. |
| 2046 | mod := variant.Module().(*AndroidApp) |
| 2047 | android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides) |
| 2048 | } |
| 2049 | } |
| 2050 | |
Colin Cross | 5088544 | 2022-05-16 16:19:54 -0700 | [diff] [blame] | 2051 | func TestOverrideAndroidAppWithPrebuilt(t *testing.T) { |
| 2052 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp( |
| 2053 | t, ` |
| 2054 | android_app { |
| 2055 | name: "foo", |
| 2056 | srcs: ["a.java"], |
| 2057 | sdk_version: "current", |
| 2058 | } |
| 2059 | |
| 2060 | override_android_app { |
| 2061 | name: "bar", |
| 2062 | base: "foo", |
| 2063 | } |
| 2064 | |
| 2065 | android_app_import { |
| 2066 | name: "bar", |
| 2067 | prefer: true, |
| 2068 | apk: "bar.apk", |
| 2069 | presigned: true, |
| 2070 | } |
| 2071 | `) |
| 2072 | |
| 2073 | // An app that has an override that also has a prebuilt should not be hidden. |
| 2074 | foo := result.ModuleForTests("foo", "android_common") |
| 2075 | if foo.Module().IsHideFromMake() { |
| 2076 | t.Errorf("expected foo to have HideFromMake false") |
| 2077 | } |
| 2078 | |
| 2079 | // An override that also has a prebuilt should be hidden. |
| 2080 | barOverride := result.ModuleForTests("foo", "android_common_bar") |
| 2081 | if !barOverride.Module().IsHideFromMake() { |
| 2082 | t.Errorf("expected bar override variant of foo to have HideFromMake true") |
| 2083 | } |
| 2084 | } |
| 2085 | |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 2086 | func TestOverrideAndroidAppStem(t *testing.T) { |
| 2087 | ctx, _ := testJava(t, ` |
| 2088 | android_app { |
| 2089 | name: "foo", |
| 2090 | srcs: ["a.java"], |
| 2091 | sdk_version: "current", |
| 2092 | } |
| 2093 | override_android_app { |
| 2094 | name: "bar", |
| 2095 | base: "foo", |
| 2096 | } |
| 2097 | override_android_app { |
| 2098 | name: "baz", |
| 2099 | base: "foo", |
| 2100 | stem: "baz_stem", |
| 2101 | } |
| 2102 | android_app { |
| 2103 | name: "foo2", |
| 2104 | srcs: ["a.java"], |
| 2105 | sdk_version: "current", |
| 2106 | stem: "foo2_stem", |
| 2107 | } |
| 2108 | override_android_app { |
| 2109 | name: "bar2", |
| 2110 | base: "foo2", |
| 2111 | } |
| 2112 | override_android_app { |
| 2113 | name: "baz2", |
| 2114 | base: "foo2", |
| 2115 | stem: "baz2_stem", |
| 2116 | } |
| 2117 | `) |
| 2118 | for _, expected := range []struct { |
| 2119 | moduleName string |
| 2120 | variantName string |
| 2121 | apkPath string |
| 2122 | }{ |
| 2123 | { |
| 2124 | moduleName: "foo", |
| 2125 | variantName: "android_common", |
| 2126 | apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk", |
| 2127 | }, |
| 2128 | { |
| 2129 | moduleName: "foo", |
| 2130 | variantName: "android_common_bar", |
| 2131 | apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 2132 | }, |
| 2133 | { |
| 2134 | moduleName: "foo", |
| 2135 | variantName: "android_common_baz", |
| 2136 | apkPath: "out/soong/target/product/test_device/system/app/baz_stem/baz_stem.apk", |
| 2137 | }, |
| 2138 | { |
| 2139 | moduleName: "foo2", |
| 2140 | variantName: "android_common", |
| 2141 | apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk", |
| 2142 | }, |
| 2143 | { |
| 2144 | moduleName: "foo2", |
| 2145 | variantName: "android_common_bar2", |
| 2146 | // Note that this may cause the duplicate output error. |
| 2147 | apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk", |
| 2148 | }, |
| 2149 | { |
| 2150 | moduleName: "foo2", |
| 2151 | variantName: "android_common_baz2", |
| 2152 | apkPath: "out/soong/target/product/test_device/system/app/baz2_stem/baz2_stem.apk", |
| 2153 | }, |
| 2154 | } { |
| 2155 | variant := ctx.ModuleForTests(expected.moduleName, expected.variantName) |
| 2156 | variant.Output(expected.apkPath) |
| 2157 | } |
| 2158 | } |
| 2159 | |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2160 | func TestOverrideAndroidAppDependency(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 2161 | ctx, _ := testJava(t, ` |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2162 | android_app { |
| 2163 | name: "foo", |
| 2164 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2165 | sdk_version: "current", |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | override_android_app { |
| 2169 | name: "bar", |
| 2170 | base: "foo", |
| 2171 | package_name: "org.dandroid.bp", |
| 2172 | } |
| 2173 | |
| 2174 | android_test { |
| 2175 | name: "baz", |
| 2176 | srcs: ["b.java"], |
| 2177 | instrumentation_for: "foo", |
| 2178 | } |
| 2179 | |
| 2180 | android_test { |
| 2181 | name: "qux", |
| 2182 | srcs: ["b.java"], |
| 2183 | instrumentation_for: "bar", |
| 2184 | } |
| 2185 | `) |
| 2186 | |
| 2187 | // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2188 | javac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2189 | fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar" |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2190 | if !strings.Contains(javac.Args["classpath"], fooTurbine) { |
| 2191 | t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) |
| 2192 | } |
| 2193 | |
| 2194 | // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2195 | javac = ctx.ModuleForTests("qux", "android_common").Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2196 | barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar" |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2197 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 2198 | t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) |
| 2199 | } |
| 2200 | } |
| 2201 | |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2202 | func TestOverrideAndroidTest(t *testing.T) { |
| 2203 | ctx, _ := testJava(t, ` |
| 2204 | android_app { |
| 2205 | name: "foo", |
| 2206 | srcs: ["a.java"], |
| 2207 | package_name: "com.android.foo", |
| 2208 | sdk_version: "current", |
| 2209 | } |
| 2210 | |
| 2211 | override_android_app { |
| 2212 | name: "bar", |
| 2213 | base: "foo", |
| 2214 | package_name: "com.android.bar", |
| 2215 | } |
| 2216 | |
| 2217 | android_test { |
| 2218 | name: "foo_test", |
| 2219 | srcs: ["b.java"], |
| 2220 | instrumentation_for: "foo", |
| 2221 | } |
| 2222 | |
| 2223 | override_android_test { |
| 2224 | name: "bar_test", |
| 2225 | base: "foo_test", |
| 2226 | package_name: "com.android.bar.test", |
| 2227 | instrumentation_for: "bar", |
| 2228 | instrumentation_target_package: "com.android.bar", |
| 2229 | } |
| 2230 | `) |
| 2231 | |
| 2232 | expectedVariants := []struct { |
| 2233 | moduleName string |
| 2234 | variantName string |
| 2235 | apkPath string |
| 2236 | overrides []string |
| 2237 | targetVariant string |
| 2238 | packageFlag string |
| 2239 | targetPackageFlag string |
| 2240 | }{ |
| 2241 | { |
| 2242 | variantName: "android_common", |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 2243 | apkPath: "/target/product/test_device/testcases/foo_test/arm64/foo_test.apk", |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2244 | overrides: nil, |
| 2245 | targetVariant: "android_common", |
| 2246 | packageFlag: "", |
| 2247 | targetPackageFlag: "", |
| 2248 | }, |
| 2249 | { |
| 2250 | variantName: "android_common_bar_test", |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 2251 | apkPath: "/target/product/test_device/testcases/bar_test/arm64/bar_test.apk", |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2252 | overrides: []string{"foo_test"}, |
| 2253 | targetVariant: "android_common_bar", |
| 2254 | packageFlag: "com.android.bar.test", |
| 2255 | targetPackageFlag: "com.android.bar", |
| 2256 | }, |
| 2257 | } |
| 2258 | for _, expected := range expectedVariants { |
| 2259 | variant := ctx.ModuleForTests("foo_test", expected.variantName) |
| 2260 | |
| 2261 | // Check the final apk name |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2262 | variant.Output("out/soong" + expected.apkPath) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2263 | |
| 2264 | // Check if the overrides field values are correctly aggregated. |
| 2265 | mod := variant.Module().(*AndroidTest) |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2266 | if !reflect.DeepEqual(expected.overrides, mod.overridableAppProperties.Overrides) { |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2267 | t.Errorf("Incorrect overrides property value, expected: %q, got: %q", |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2268 | expected.overrides, mod.overridableAppProperties.Overrides) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | // Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2272 | javac := variant.Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2273 | turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar") |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2274 | if !strings.Contains(javac.Args["classpath"], turbine) { |
| 2275 | t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine) |
| 2276 | } |
| 2277 | |
| 2278 | // Check aapt2 flags. |
| 2279 | res := variant.Output("package-res.apk") |
| 2280 | aapt2Flags := res.Args["flags"] |
| 2281 | checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2282 | checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expected.packageFlag) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2283 | checkAapt2LinkFlag(t, aapt2Flags, "rename-instrumentation-target-package", expected.targetPackageFlag) |
| 2284 | } |
| 2285 | } |
| 2286 | |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2287 | func TestAndroidTest_FixTestConfig(t *testing.T) { |
| 2288 | ctx, _ := testJava(t, ` |
| 2289 | android_app { |
| 2290 | name: "foo", |
| 2291 | srcs: ["a.java"], |
| 2292 | package_name: "com.android.foo", |
| 2293 | sdk_version: "current", |
| 2294 | } |
| 2295 | |
| 2296 | android_test { |
| 2297 | name: "foo_test", |
| 2298 | srcs: ["b.java"], |
| 2299 | instrumentation_for: "foo", |
| 2300 | } |
| 2301 | |
| 2302 | android_test { |
| 2303 | name: "bar_test", |
| 2304 | srcs: ["b.java"], |
| 2305 | package_name: "com.android.bar.test", |
| 2306 | instrumentation_for: "foo", |
| 2307 | } |
| 2308 | |
| 2309 | override_android_test { |
| 2310 | name: "baz_test", |
| 2311 | base: "foo_test", |
| 2312 | package_name: "com.android.baz.test", |
| 2313 | } |
| 2314 | `) |
| 2315 | |
| 2316 | testCases := []struct { |
| 2317 | moduleName string |
| 2318 | variantName string |
| 2319 | expectedFlags []string |
| 2320 | }{ |
| 2321 | { |
| 2322 | moduleName: "foo_test", |
| 2323 | variantName: "android_common", |
| 2324 | }, |
| 2325 | { |
| 2326 | moduleName: "bar_test", |
| 2327 | variantName: "android_common", |
| 2328 | expectedFlags: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2329 | "--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2330 | "--package-name com.android.bar.test", |
| 2331 | }, |
| 2332 | }, |
| 2333 | { |
| 2334 | moduleName: "foo_test", |
| 2335 | variantName: "android_common_baz_test", |
| 2336 | expectedFlags: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2337 | "--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2338 | "--package-name com.android.baz.test", |
| 2339 | "--test-file-name baz_test.apk", |
| 2340 | }, |
| 2341 | }, |
| 2342 | } |
| 2343 | |
| 2344 | for _, test := range testCases { |
| 2345 | variant := ctx.ModuleForTests(test.moduleName, test.variantName) |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2346 | params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml") |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2347 | |
| 2348 | if len(test.expectedFlags) > 0 { |
| 2349 | if params.Rule == nil { |
| 2350 | t.Errorf("test_config_fixer was expected to run, but didn't") |
| 2351 | } else { |
| 2352 | for _, flag := range test.expectedFlags { |
| 2353 | if !strings.Contains(params.RuleParams.Command, flag) { |
| 2354 | t.Errorf("Flag %q was not found in command: %q", flag, params.RuleParams.Command) |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | } else { |
| 2359 | if params.Rule != nil { |
| 2360 | t.Errorf("test_config_fixer was not expected to run, but did: %q", params.RuleParams.Command) |
| 2361 | } |
| 2362 | } |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
Paul Duffin | 53a70a4 | 2022-01-11 14:35:55 +0000 | [diff] [blame] | 2366 | func TestInstrumentationTargetPrebuilt(t *testing.T) { |
| 2367 | bp := ` |
| 2368 | android_app_import { |
| 2369 | name: "foo", |
| 2370 | apk: "foo.apk", |
| 2371 | presigned: true, |
| 2372 | } |
| 2373 | |
| 2374 | android_test { |
| 2375 | name: "bar", |
| 2376 | srcs: ["a.java"], |
| 2377 | instrumentation_for: "foo", |
| 2378 | sdk_version: "current", |
| 2379 | } |
| 2380 | ` |
| 2381 | |
| 2382 | android.GroupFixturePreparers( |
| 2383 | PrepareForTestWithJavaDefaultModules, |
| 2384 | ).ExtendWithErrorHandler( |
| 2385 | android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 2386 | "instrumentation_for: dependency \"foo\" of type \"android_app_import\" does not provide JavaInfo so is unsuitable for use with this property")). |
| 2387 | RunTestWithBp(t, bp) |
| 2388 | } |
| 2389 | |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 2390 | func TestStl(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 2391 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 2392 | cc_library { |
| 2393 | name: "libjni", |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 2394 | sdk_version: "current", |
| 2395 | stl: "c++_shared", |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | android_test { |
| 2399 | name: "stl", |
| 2400 | jni_libs: ["libjni"], |
| 2401 | compile_multilib: "both", |
| 2402 | sdk_version: "current", |
| 2403 | stl: "c++_shared", |
| 2404 | } |
| 2405 | |
| 2406 | android_test { |
| 2407 | name: "system", |
| 2408 | jni_libs: ["libjni"], |
| 2409 | compile_multilib: "both", |
| 2410 | sdk_version: "current", |
| 2411 | } |
| 2412 | `) |
| 2413 | |
| 2414 | testCases := []struct { |
| 2415 | name string |
| 2416 | jnis []string |
| 2417 | }{ |
| 2418 | {"stl", |
| 2419 | []string{ |
| 2420 | "libjni.so", |
Jaewoong Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 2421 | "libc++_shared.so", |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 2422 | }, |
| 2423 | }, |
| 2424 | {"system", |
| 2425 | []string{ |
| 2426 | "libjni.so", |
| 2427 | }, |
| 2428 | }, |
| 2429 | } |
| 2430 | |
| 2431 | for _, test := range testCases { |
| 2432 | t.Run(test.name, func(t *testing.T) { |
| 2433 | app := ctx.ModuleForTests(test.name, "android_common") |
| 2434 | jniLibZip := app.Output("jnilibs.zip") |
| 2435 | var jnis []string |
| 2436 | args := strings.Fields(jniLibZip.Args["jarArgs"]) |
| 2437 | for i := 0; i < len(args); i++ { |
| 2438 | if args[i] == "-f" { |
| 2439 | jnis = append(jnis, args[i+1]) |
| 2440 | i += 1 |
| 2441 | } |
| 2442 | } |
| 2443 | jnisJoined := strings.Join(jnis, " ") |
| 2444 | for _, jni := range test.jnis { |
| 2445 | if !strings.Contains(jnisJoined, jni) { |
| 2446 | t.Errorf("missing jni %q in %q", jni, jnis) |
| 2447 | } |
| 2448 | } |
| 2449 | }) |
| 2450 | } |
| 2451 | } |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2452 | |
| 2453 | func TestUsesLibraries(t *testing.T) { |
| 2454 | bp := ` |
| 2455 | java_sdk_library { |
| 2456 | name: "foo", |
| 2457 | srcs: ["a.java"], |
| 2458 | api_packages: ["foo"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2459 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | java_sdk_library { |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2463 | name: "qux", |
| 2464 | srcs: ["a.java"], |
| 2465 | api_packages: ["qux"], |
| 2466 | sdk_version: "current", |
| 2467 | } |
| 2468 | |
| 2469 | java_sdk_library { |
| 2470 | name: "quuz", |
| 2471 | srcs: ["a.java"], |
| 2472 | api_packages: ["quuz"], |
| 2473 | sdk_version: "current", |
| 2474 | } |
| 2475 | |
| 2476 | java_sdk_library { |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2477 | name: "fred", |
| 2478 | srcs: ["a.java"], |
| 2479 | api_packages: ["fred"], |
| 2480 | sdk_version: "current", |
| 2481 | } |
| 2482 | |
| 2483 | java_sdk_library { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2484 | name: "bar", |
| 2485 | srcs: ["a.java"], |
| 2486 | api_packages: ["bar"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2487 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
Ulya Trafimovich | 4b6d4c1 | 2020-08-19 14:58:01 +0100 | [diff] [blame] | 2490 | java_sdk_library { |
| 2491 | name: "runtime-library", |
| 2492 | srcs: ["a.java"], |
| 2493 | sdk_version: "current", |
| 2494 | } |
| 2495 | |
| 2496 | java_library { |
| 2497 | name: "static-runtime-helper", |
| 2498 | srcs: ["a.java"], |
| 2499 | libs: ["runtime-library"], |
| 2500 | sdk_version: "current", |
| 2501 | } |
| 2502 | |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 2503 | java_library { |
| 2504 | name: "runtime-required-x", |
| 2505 | srcs: ["a.java"], |
| 2506 | installable: true, |
| 2507 | sdk_version: "current", |
| 2508 | } |
| 2509 | |
| 2510 | java_library { |
| 2511 | name: "runtime-optional-x", |
| 2512 | srcs: ["a.java"], |
| 2513 | installable: true, |
| 2514 | sdk_version: "current", |
| 2515 | } |
| 2516 | |
| 2517 | android_library { |
| 2518 | name: "static-x", |
| 2519 | uses_libs: ["runtime-required-x"], |
| 2520 | optional_uses_libs: ["runtime-optional-x"], |
| 2521 | sdk_version: "current", |
| 2522 | } |
| 2523 | |
| 2524 | java_library { |
| 2525 | name: "runtime-required-y", |
| 2526 | srcs: ["a.java"], |
| 2527 | installable: true, |
| 2528 | sdk_version: "current", |
| 2529 | } |
| 2530 | |
| 2531 | java_library { |
| 2532 | name: "runtime-optional-y", |
| 2533 | srcs: ["a.java"], |
| 2534 | installable: true, |
| 2535 | sdk_version: "current", |
| 2536 | } |
| 2537 | |
| 2538 | java_library { |
| 2539 | name: "static-y", |
| 2540 | srcs: ["a.java"], |
| 2541 | uses_libs: ["runtime-required-y"], |
| 2542 | optional_uses_libs: ["runtime-optional-y"], |
| 2543 | sdk_version: "current", |
| 2544 | } |
| 2545 | |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 2546 | // A library that has to use "provides_uses_lib", because: |
| 2547 | // - it is not an SDK library |
| 2548 | // - its library name is different from its module name |
| 2549 | java_library { |
| 2550 | name: "non-sdk-lib", |
| 2551 | provides_uses_lib: "com.non.sdk.lib", |
| 2552 | installable: true, |
| 2553 | srcs: ["a.java"], |
| 2554 | } |
| 2555 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2556 | android_app { |
| 2557 | name: "app", |
| 2558 | srcs: ["a.java"], |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 2559 | libs: [ |
| 2560 | "qux", |
| 2561 | "quuz.stubs" |
| 2562 | ], |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2563 | static_libs: [ |
| 2564 | "static-runtime-helper", |
| 2565 | // statically linked component libraries should not pull their SDK libraries, |
| 2566 | // so "fred" should not be added to class loader context |
| 2567 | "fred.stubs", |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 2568 | "static-x", |
| 2569 | "static-y", |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2570 | ], |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 2571 | uses_libs: [ |
| 2572 | "foo", |
| 2573 | "non-sdk-lib" |
| 2574 | ], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2575 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2576 | optional_uses_libs: [ |
| 2577 | "bar", |
| 2578 | "baz", |
| 2579 | ], |
| 2580 | } |
| 2581 | |
| 2582 | android_app_import { |
| 2583 | name: "prebuilt", |
| 2584 | apk: "prebuilts/apk/app.apk", |
| 2585 | certificate: "platform", |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 2586 | uses_libs: [ |
| 2587 | "foo", |
| 2588 | "non-sdk-lib", |
| 2589 | "android.test.runner" |
| 2590 | ], |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2591 | optional_uses_libs: [ |
| 2592 | "bar", |
| 2593 | "baz", |
| 2594 | ], |
| 2595 | } |
| 2596 | ` |
| 2597 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 2598 | result := android.GroupFixturePreparers( |
| 2599 | prepareForJavaTest, |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 2600 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2601 | FixtureWithLastReleaseApis("runtime-library", "foo", "quuz", "qux", "bar", "fred"), |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2602 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2603 | variables.MissingUsesLibraries = []string{"baz"} |
| 2604 | }), |
| 2605 | ).RunTestWithBp(t, bp) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2606 | |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2607 | app := result.ModuleForTests("app", "android_common") |
| 2608 | prebuilt := result.ModuleForTests("prebuilt", "android_common") |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2609 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2610 | // Test that implicit dependencies on java_sdk_library instances are passed to the manifest. |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2611 | // This should not include explicit `uses_libs`/`optional_uses_libs` entries. |
| 2612 | actualManifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 2613 | expectManifestFixerArgs := `--extract-native-libs=true ` + |
| 2614 | `--uses-library qux ` + |
| 2615 | `--uses-library quuz ` + |
Ulya Trafimovich | 0b1c70e | 2021-08-20 15:39:12 +0100 | [diff] [blame] | 2616 | `--uses-library runtime-library` |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 2617 | android.AssertStringDoesContain(t, "manifest_fixer args", actualManifestFixerArgs, expectManifestFixerArgs) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2618 | |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2619 | // Test that all libraries are verified (library order matters). |
| 2620 | verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command |
| 2621 | verifyArgs := `--uses-library foo ` + |
Ulya Trafimovich | eea486a | 2021-02-26 11:38:21 +0000 | [diff] [blame] | 2622 | `--uses-library com.non.sdk.lib ` + |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2623 | `--uses-library qux ` + |
| 2624 | `--uses-library quuz ` + |
| 2625 | `--uses-library runtime-library ` + |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 2626 | `--uses-library runtime-required-x ` + |
| 2627 | `--uses-library runtime-required-y ` + |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2628 | `--optional-uses-library bar ` + |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 2629 | `--optional-uses-library baz ` + |
| 2630 | `--optional-uses-library runtime-optional-x ` + |
| 2631 | `--optional-uses-library runtime-optional-y ` |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2632 | android.AssertStringDoesContain(t, "verify cmd args", verifyCmd, verifyArgs) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2633 | |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2634 | // Test that all libraries are verified for an APK (library order matters). |
| 2635 | verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 2636 | verifyApkArgs := `--uses-library foo ` + |
| 2637 | `--uses-library com.non.sdk.lib ` + |
| 2638 | `--uses-library android.test.runner ` + |
| 2639 | `--optional-uses-library bar ` + |
| 2640 | `--optional-uses-library baz ` |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2641 | android.AssertStringDoesContain(t, "verify apk cmd args", verifyApkCmd, verifyApkArgs) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2642 | |
Ulya Trafimovich | 8130c48 | 2020-10-07 15:17:13 +0100 | [diff] [blame] | 2643 | // Test that all present libraries are preopted, including implicit SDK dependencies, possibly stubs |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 2644 | cmd := app.Rule("dexpreopt").RuleParams.Command |
Ulya Trafimovich | 8130c48 | 2020-10-07 15:17:13 +0100 | [diff] [blame] | 2645 | w := `--target-context-for-sdk any ` + |
Ulya Trafimovich | 8130c48 | 2020-10-07 15:17:13 +0100 | [diff] [blame] | 2646 | `PCL[/system/framework/qux.jar]#` + |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 2647 | `PCL[/system/framework/quuz.jar]#` + |
| 2648 | `PCL[/system/framework/foo.jar]#` + |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 2649 | `PCL[/system/framework/non-sdk-lib.jar]#` + |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 2650 | `PCL[/system/framework/bar.jar]#` + |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 2651 | `PCL[/system/framework/runtime-library.jar]#` + |
| 2652 | `PCL[/system/framework/runtime-required-x.jar]#` + |
| 2653 | `PCL[/system/framework/runtime-optional-x.jar]#` + |
| 2654 | `PCL[/system/framework/runtime-required-y.jar]#` + |
| 2655 | `PCL[/system/framework/runtime-optional-y.jar] ` |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2656 | android.AssertStringDoesContain(t, "dexpreopt app cmd args", cmd, w) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2657 | |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame] | 2658 | // Test conditional context for target SDK version 28. |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2659 | android.AssertStringDoesContain(t, "dexpreopt app cmd 28", cmd, |
| 2660 | `--target-context-for-sdk 28`+ |
| 2661 | ` PCL[/system/framework/org.apache.http.legacy.jar] `) |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame] | 2662 | |
| 2663 | // Test conditional context for target SDK version 29. |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2664 | android.AssertStringDoesContain(t, "dexpreopt app cmd 29", cmd, |
| 2665 | `--target-context-for-sdk 29`+ |
| 2666 | ` PCL[/system/framework/android.hidl.manager-V1.0-java.jar]`+ |
| 2667 | `#PCL[/system/framework/android.hidl.base-V1.0-java.jar] `) |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame] | 2668 | |
| 2669 | // Test conditional context for target SDK version 30. |
Ulya Trafimovich | 46b3d5b | 2020-10-21 13:20:55 +0100 | [diff] [blame] | 2670 | // "android.test.mock" is absent because "android.test.runner" is not used. |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2671 | android.AssertStringDoesContain(t, "dexpreopt app cmd 30", cmd, |
| 2672 | `--target-context-for-sdk 30`+ |
| 2673 | ` PCL[/system/framework/android.test.base.jar] `) |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame] | 2674 | |
Ulya Trafimovich | fc24ad3 | 2020-08-19 16:32:54 +0100 | [diff] [blame] | 2675 | cmd = prebuilt.Rule("dexpreopt").RuleParams.Command |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2676 | android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd", cmd, |
| 2677 | `--target-context-for-sdk any`+ |
| 2678 | ` PCL[/system/framework/foo.jar]`+ |
| 2679 | `#PCL[/system/framework/non-sdk-lib.jar]`+ |
| 2680 | `#PCL[/system/framework/android.test.runner.jar]`+ |
| 2681 | `#PCL[/system/framework/bar.jar] `) |
Ulya Trafimovich | 24813e1 | 2020-10-07 15:05:21 +0100 | [diff] [blame] | 2682 | |
| 2683 | // Test conditional context for target SDK version 30. |
Ulya Trafimovich | 46b3d5b | 2020-10-21 13:20:55 +0100 | [diff] [blame] | 2684 | // "android.test.mock" is present because "android.test.runner" is used. |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 2685 | android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd 30", cmd, |
| 2686 | `--target-context-for-sdk 30`+ |
| 2687 | ` PCL[/system/framework/android.test.base.jar]`+ |
| 2688 | `#PCL[/system/framework/android.test.mock.jar] `) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 2689 | } |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2690 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 2691 | func TestDexpreoptBcp(t *testing.T) { |
| 2692 | bp := ` |
| 2693 | java_sdk_library { |
| 2694 | name: "foo", |
| 2695 | srcs: ["a.java"], |
| 2696 | api_packages: ["foo"], |
| 2697 | sdk_version: "current", |
| 2698 | } |
| 2699 | |
| 2700 | java_sdk_library { |
| 2701 | name: "bar", |
| 2702 | srcs: ["a.java"], |
| 2703 | api_packages: ["bar"], |
| 2704 | permitted_packages: ["bar"], |
| 2705 | sdk_version: "current", |
| 2706 | } |
| 2707 | |
| 2708 | android_app { |
| 2709 | name: "app", |
| 2710 | srcs: ["a.java"], |
| 2711 | sdk_version: "current", |
| 2712 | } |
| 2713 | ` |
| 2714 | |
| 2715 | testCases := []struct { |
| 2716 | name string |
| 2717 | with bool |
| 2718 | expect string |
| 2719 | }{ |
| 2720 | { |
| 2721 | name: "with updatable bcp", |
| 2722 | with: true, |
| 2723 | expect: "/system/framework/foo.jar:/system/framework/bar.jar", |
| 2724 | }, |
| 2725 | { |
| 2726 | name: "without updatable bcp", |
| 2727 | with: false, |
| 2728 | expect: "/system/framework/foo.jar", |
| 2729 | }, |
| 2730 | } |
| 2731 | |
| 2732 | for _, test := range testCases { |
| 2733 | t.Run(test.name, func(t *testing.T) { |
| 2734 | result := android.GroupFixturePreparers( |
| 2735 | prepareForJavaTest, |
| 2736 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2737 | FixtureWithLastReleaseApis("runtime-library", "foo", "bar"), |
| 2738 | dexpreopt.FixtureSetBootJars("platform:foo"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 2739 | dexpreopt.FixtureSetApexBootJars("platform:bar"), |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 2740 | dexpreopt.FixtureSetPreoptWithUpdatableBcp(test.with), |
| 2741 | ).RunTestWithBp(t, bp) |
| 2742 | |
| 2743 | app := result.ModuleForTests("app", "android_common") |
| 2744 | cmd := app.Rule("dexpreopt").RuleParams.Command |
| 2745 | bcp := " -Xbootclasspath-locations:" + test.expect + " " // space at the end matters |
| 2746 | android.AssertStringDoesContain(t, "dexpreopt app bcp", cmd, bcp) |
| 2747 | }) |
| 2748 | } |
| 2749 | } |
| 2750 | |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2751 | func TestCodelessApp(t *testing.T) { |
| 2752 | testCases := []struct { |
| 2753 | name string |
| 2754 | bp string |
| 2755 | noCode bool |
| 2756 | }{ |
| 2757 | { |
| 2758 | name: "normal", |
| 2759 | bp: ` |
| 2760 | android_app { |
| 2761 | name: "foo", |
| 2762 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2763 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2764 | } |
| 2765 | `, |
| 2766 | noCode: false, |
| 2767 | }, |
| 2768 | { |
| 2769 | name: "app without sources", |
| 2770 | bp: ` |
| 2771 | android_app { |
| 2772 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2773 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2774 | } |
| 2775 | `, |
| 2776 | noCode: true, |
| 2777 | }, |
| 2778 | { |
| 2779 | name: "app with libraries", |
| 2780 | bp: ` |
| 2781 | android_app { |
| 2782 | name: "foo", |
| 2783 | static_libs: ["lib"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2784 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | java_library { |
| 2788 | name: "lib", |
| 2789 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2790 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2791 | } |
| 2792 | `, |
| 2793 | noCode: false, |
| 2794 | }, |
| 2795 | { |
| 2796 | name: "app with sourceless libraries", |
| 2797 | bp: ` |
| 2798 | android_app { |
| 2799 | name: "foo", |
| 2800 | static_libs: ["lib"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2801 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | java_library { |
| 2805 | name: "lib", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2806 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 2807 | } |
| 2808 | `, |
| 2809 | // TODO(jungjw): this should probably be true |
| 2810 | noCode: false, |
| 2811 | }, |
| 2812 | } |
| 2813 | |
| 2814 | for _, test := range testCases { |
| 2815 | t.Run(test.name, func(t *testing.T) { |
| 2816 | ctx := testApp(t, test.bp) |
| 2817 | |
| 2818 | foo := ctx.ModuleForTests("foo", "android_common") |
| 2819 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 2820 | if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode { |
| 2821 | t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs) |
| 2822 | } |
| 2823 | }) |
| 2824 | } |
| 2825 | } |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 2826 | |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2827 | func TestUncompressDex(t *testing.T) { |
| 2828 | testCases := []struct { |
| 2829 | name string |
| 2830 | bp string |
| 2831 | |
| 2832 | uncompressedPlatform bool |
| 2833 | uncompressedUnbundled bool |
| 2834 | }{ |
| 2835 | { |
| 2836 | name: "normal", |
| 2837 | bp: ` |
| 2838 | android_app { |
| 2839 | name: "foo", |
| 2840 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2841 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2842 | } |
| 2843 | `, |
| 2844 | uncompressedPlatform: true, |
| 2845 | uncompressedUnbundled: false, |
| 2846 | }, |
| 2847 | { |
| 2848 | name: "use_embedded_dex", |
| 2849 | bp: ` |
| 2850 | android_app { |
| 2851 | name: "foo", |
| 2852 | use_embedded_dex: true, |
| 2853 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2854 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2855 | } |
| 2856 | `, |
| 2857 | uncompressedPlatform: true, |
| 2858 | uncompressedUnbundled: true, |
| 2859 | }, |
| 2860 | { |
| 2861 | name: "privileged", |
| 2862 | bp: ` |
| 2863 | android_app { |
| 2864 | name: "foo", |
| 2865 | privileged: true, |
| 2866 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2867 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2868 | } |
| 2869 | `, |
| 2870 | uncompressedPlatform: true, |
| 2871 | uncompressedUnbundled: true, |
| 2872 | }, |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 2873 | { |
| 2874 | name: "normal_uncompress_dex_true", |
| 2875 | bp: ` |
| 2876 | android_app { |
| 2877 | name: "foo", |
| 2878 | srcs: ["a.java"], |
| 2879 | sdk_version: "current", |
| 2880 | uncompress_dex: true, |
| 2881 | } |
| 2882 | `, |
| 2883 | uncompressedPlatform: true, |
| 2884 | uncompressedUnbundled: true, |
| 2885 | }, |
| 2886 | { |
| 2887 | name: "normal_uncompress_dex_false", |
| 2888 | bp: ` |
| 2889 | android_app { |
| 2890 | name: "foo", |
| 2891 | srcs: ["a.java"], |
| 2892 | sdk_version: "current", |
| 2893 | uncompress_dex: false, |
| 2894 | } |
| 2895 | `, |
| 2896 | uncompressedPlatform: false, |
| 2897 | uncompressedUnbundled: false, |
| 2898 | }, |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | test := func(t *testing.T, bp string, want bool, unbundled bool) { |
| 2902 | t.Helper() |
| 2903 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 2904 | result := android.GroupFixturePreparers( |
| 2905 | prepareForJavaTest, |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 2906 | PrepareForTestWithPrebuiltsOfCurrentApi, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 2907 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2908 | if unbundled { |
| 2909 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 2910 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 2911 | } |
| 2912 | }), |
| 2913 | ).RunTestWithBp(t, bp) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2914 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 2915 | foo := result.ModuleForTests("foo", "android_common") |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2916 | dex := foo.Rule("r8") |
| 2917 | uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0") |
| 2918 | aligned := foo.MaybeRule("zipalign").Rule != nil |
| 2919 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 2920 | android.AssertBoolEquals(t, "uncompressed in dex", want, uncompressedInDexJar) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2921 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 2922 | android.AssertBoolEquals(t, "aligne", want, aligned) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | for _, tt := range testCases { |
| 2926 | t.Run(tt.name, func(t *testing.T) { |
| 2927 | t.Run("platform", func(t *testing.T) { |
| 2928 | test(t, tt.bp, tt.uncompressedPlatform, false) |
| 2929 | }) |
| 2930 | t.Run("unbundled", func(t *testing.T) { |
| 2931 | test(t, tt.bp, tt.uncompressedUnbundled, true) |
| 2932 | }) |
| 2933 | }) |
| 2934 | } |
| 2935 | } |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2936 | |
| 2937 | func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string) { |
| 2938 | if expectedValue != "" { |
| 2939 | expectedFlag := "--" + flagName + " " + expectedValue |
| 2940 | if !strings.Contains(aapt2Flags, expectedFlag) { |
| 2941 | t.Errorf("%q is missing in aapt2 link flags, %q", expectedFlag, aapt2Flags) |
| 2942 | } |
| 2943 | } else { |
| 2944 | unexpectedFlag := "--" + flagName |
| 2945 | if strings.Contains(aapt2Flags, unexpectedFlag) { |
| 2946 | t.Errorf("unexpected flag, %q is found in aapt2 link flags, %q", unexpectedFlag, aapt2Flags) |
| 2947 | } |
| 2948 | } |
| 2949 | } |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 2950 | |
Cole Faust | 9a63131 | 2020-10-22 21:05:24 +0000 | [diff] [blame] | 2951 | func TestExportedProguardFlagFiles(t *testing.T) { |
| 2952 | ctx, _ := testJava(t, ` |
| 2953 | android_app { |
| 2954 | name: "foo", |
| 2955 | sdk_version: "current", |
| 2956 | static_libs: ["lib1"], |
| 2957 | } |
| 2958 | |
| 2959 | android_library { |
| 2960 | name: "lib1", |
| 2961 | sdk_version: "current", |
| 2962 | optimize: { |
| 2963 | proguard_flags_files: ["lib1proguard.cfg"], |
| 2964 | } |
| 2965 | } |
| 2966 | `) |
| 2967 | |
| 2968 | m := ctx.ModuleForTests("foo", "android_common") |
| 2969 | hasLib1Proguard := false |
| 2970 | for _, s := range m.Rule("java.r8").Implicits.Strings() { |
| 2971 | if s == "lib1proguard.cfg" { |
| 2972 | hasLib1Proguard = true |
| 2973 | break |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | if !hasLib1Proguard { |
| 2978 | t.Errorf("App does not use library proguard config") |
| 2979 | } |
| 2980 | } |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 2981 | |
| 2982 | func TestTargetSdkVersionManifestFixer(t *testing.T) { |
| 2983 | platform_sdk_codename := "Tiramisu" |
| 2984 | testCases := []struct { |
| 2985 | name string |
| 2986 | targetSdkVersionInBp string |
| 2987 | targetSdkVersionExpected string |
| 2988 | unbundledBuild bool |
| 2989 | }{ |
| 2990 | { |
| 2991 | name: "Non-Unbundled build: Android.bp has targetSdkVersion", |
| 2992 | targetSdkVersionInBp: "30", |
| 2993 | targetSdkVersionExpected: "30", |
| 2994 | unbundledBuild: false, |
| 2995 | }, |
| 2996 | { |
| 2997 | name: "Unbundled build: Android.bp has targetSdkVersion", |
| 2998 | targetSdkVersionInBp: "30", |
| 2999 | targetSdkVersionExpected: "30", |
| 3000 | unbundledBuild: true, |
| 3001 | }, |
| 3002 | { |
| 3003 | name: "Non-Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename", |
| 3004 | targetSdkVersionInBp: platform_sdk_codename, |
| 3005 | targetSdkVersionExpected: platform_sdk_codename, |
| 3006 | unbundledBuild: false, |
| 3007 | }, |
| 3008 | { |
| 3009 | name: "Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename", |
| 3010 | targetSdkVersionInBp: platform_sdk_codename, |
| 3011 | targetSdkVersionExpected: "10000", |
| 3012 | unbundledBuild: true, |
| 3013 | }, |
| 3014 | |
| 3015 | { |
| 3016 | name: "Non-Unbundled build: Android.bp has no targetSdkVersion", |
| 3017 | targetSdkVersionExpected: platform_sdk_codename, |
| 3018 | unbundledBuild: false, |
| 3019 | }, |
| 3020 | { |
| 3021 | name: "Unbundled build: Android.bp has no targetSdkVersion", |
| 3022 | targetSdkVersionExpected: "10000", |
| 3023 | unbundledBuild: true, |
| 3024 | }, |
| 3025 | } |
| 3026 | for _, testCase := range testCases { |
| 3027 | bp := fmt.Sprintf(` |
| 3028 | android_app { |
| 3029 | name: "foo", |
| 3030 | sdk_version: "current", |
| 3031 | target_sdk_version: "%v", |
| 3032 | } |
| 3033 | `, testCase.targetSdkVersionInBp) |
| 3034 | fixture := android.GroupFixturePreparers( |
| 3035 | prepareForJavaTest, |
| 3036 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3037 | // explicitly set platform_sdk_codename to make the test deterministic |
| 3038 | variables.Platform_sdk_codename = &platform_sdk_codename |
| 3039 | variables.Platform_version_active_codenames = []string{platform_sdk_codename} |
| 3040 | // create a non-empty list if unbundledBuild==true |
| 3041 | if testCase.unbundledBuild { |
| 3042 | variables.Unbundled_build_apps = []string{"apex_a", "apex_b"} |
| 3043 | } |
| 3044 | }), |
| 3045 | ) |
| 3046 | |
| 3047 | result := fixture.RunTestWithBp(t, bp) |
| 3048 | foo := result.ModuleForTests("foo", "android_common") |
| 3049 | |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 3050 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3051 | android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } |
Colin Cross | 412436f | 2022-04-07 17:40:07 -0700 | [diff] [blame] | 3054 | |
| 3055 | func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { |
| 3056 | result := android.GroupFixturePreparers( |
| 3057 | PrepareForTestWithJavaDefaultModules, |
| 3058 | android.PrepareForTestWithAllowMissingDependencies, |
| 3059 | android.PrepareForTestWithAndroidMk, |
| 3060 | ).RunTestWithBp(t, ` |
| 3061 | android_app { |
| 3062 | name: "foo", |
| 3063 | srcs: ["a.java"], |
| 3064 | certificate: ":missing_certificate", |
| 3065 | sdk_version: "current", |
| 3066 | }`) |
| 3067 | |
| 3068 | foo := result.ModuleForTests("foo", "android_common") |
| 3069 | fooApk := foo.Output("foo.apk") |
| 3070 | if fooApk.Rule != android.ErrorRule { |
| 3071 | t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String()) |
| 3072 | } |
| 3073 | android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n") |
| 3074 | } |