Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 1 | // Copyright 2020 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 ( |
Ulya Trafimovich | 55f72d7 | 2021-09-01 14:13:57 +0100 | [diff] [blame] | 18 | "fmt" |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 19 | "reflect" |
| 20 | "regexp" |
| 21 | "strings" |
| 22 | "testing" |
| 23 | |
| 24 | "github.com/google/blueprint/proptools" |
| 25 | |
| 26 | "android/soong/android" |
| 27 | ) |
| 28 | |
| 29 | func TestAndroidAppImport(t *testing.T) { |
| 30 | ctx, _ := testJava(t, ` |
| 31 | android_app_import { |
| 32 | name: "foo", |
| 33 | apk: "prebuilts/apk/app.apk", |
| 34 | certificate: "platform", |
| 35 | dex_preopt: { |
| 36 | enabled: true, |
| 37 | }, |
| 38 | } |
| 39 | `) |
| 40 | |
| 41 | variant := ctx.ModuleForTests("foo", "android_common") |
| 42 | |
| 43 | // Check dexpreopt outputs. |
| 44 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || |
| 45 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { |
| 46 | t.Errorf("can't find dexpreopt outputs") |
| 47 | } |
| 48 | |
| 49 | // Check cert signing flag. |
| 50 | signedApk := variant.Output("signed/foo.apk") |
| 51 | signingFlag := signedApk.Args["certificates"] |
| 52 | expected := "build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8" |
| 53 | if expected != signingFlag { |
| 54 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) |
| 55 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 56 | rule := variant.Rule("genProvenanceMetaData") |
| 57 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 58 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 59 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 60 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | func TestAndroidAppImport_NoDexPreopt(t *testing.T) { |
| 64 | ctx, _ := testJava(t, ` |
| 65 | android_app_import { |
| 66 | name: "foo", |
| 67 | apk: "prebuilts/apk/app.apk", |
| 68 | certificate: "platform", |
| 69 | dex_preopt: { |
| 70 | enabled: false, |
| 71 | }, |
| 72 | } |
| 73 | `) |
| 74 | |
| 75 | variant := ctx.ModuleForTests("foo", "android_common") |
| 76 | |
| 77 | // Check dexpreopt outputs. They shouldn't exist. |
| 78 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule != nil || |
| 79 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule != nil { |
| 80 | t.Errorf("dexpreopt shouldn't have run.") |
| 81 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 82 | |
| 83 | rule := variant.Rule("genProvenanceMetaData") |
| 84 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 85 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 86 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 87 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func TestAndroidAppImport_Presigned(t *testing.T) { |
| 91 | ctx, _ := testJava(t, ` |
| 92 | android_app_import { |
| 93 | name: "foo", |
| 94 | apk: "prebuilts/apk/app.apk", |
| 95 | presigned: true, |
| 96 | dex_preopt: { |
| 97 | enabled: true, |
| 98 | }, |
| 99 | } |
| 100 | `) |
| 101 | |
| 102 | variant := ctx.ModuleForTests("foo", "android_common") |
| 103 | |
| 104 | // Check dexpreopt outputs. |
| 105 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || |
| 106 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { |
| 107 | t.Errorf("can't find dexpreopt outputs") |
| 108 | } |
| 109 | // Make sure signing was skipped and aligning was done. |
| 110 | if variant.MaybeOutput("signed/foo.apk").Rule != nil { |
| 111 | t.Errorf("signing rule shouldn't be included.") |
| 112 | } |
| 113 | if variant.MaybeOutput("zip-aligned/foo.apk").Rule == nil { |
| 114 | t.Errorf("can't find aligning rule") |
| 115 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 116 | |
| 117 | rule := variant.Rule("genProvenanceMetaData") |
| 118 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 119 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 120 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 121 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | func TestAndroidAppImport_SigningLineage(t *testing.T) { |
| 125 | ctx, _ := testJava(t, ` |
| 126 | android_app_import { |
| 127 | name: "foo", |
| 128 | apk: "prebuilts/apk/app.apk", |
| 129 | certificate: "platform", |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 130 | additional_certificates: [":additional_certificate"], |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 131 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 132 | rotationMinSdkVersion: "32", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 133 | } |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 134 | |
| 135 | android_app_certificate { |
| 136 | name: "additional_certificate", |
| 137 | certificate: "cert/additional_cert", |
| 138 | } |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 139 | `) |
| 140 | |
| 141 | variant := ctx.ModuleForTests("foo", "android_common") |
| 142 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 143 | signedApk := variant.Output("signed/foo.apk") |
Jaewoong Jung | 25ae8de | 2021-03-08 17:37:46 -0800 | [diff] [blame] | 144 | // Check certificates |
| 145 | certificatesFlag := signedApk.Args["certificates"] |
| 146 | expected := "build/make/target/product/security/platform.x509.pem " + |
| 147 | "build/make/target/product/security/platform.pk8 " + |
| 148 | "cert/additional_cert.x509.pem cert/additional_cert.pk8" |
| 149 | if expected != certificatesFlag { |
| 150 | t.Errorf("Incorrect certificates flags, expected: %q, got: %q", expected, certificatesFlag) |
| 151 | } |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 152 | |
| 153 | // Check cert signing flags. |
| 154 | actualCertSigningFlags := signedApk.Args["flags"] |
| 155 | expectedCertSigningFlags := "--lineage lineage.bin --rotation-min-sdk-version 32" |
| 156 | if expectedCertSigningFlags != actualCertSigningFlags { |
| 157 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expectedCertSigningFlags, actualCertSigningFlags) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 158 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 159 | |
| 160 | rule := variant.Rule("genProvenanceMetaData") |
| 161 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 162 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 163 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 164 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 167 | func TestAndroidAppImport_SigningLineageFilegroup(t *testing.T) { |
| 168 | ctx, _ := testJava(t, ` |
| 169 | android_app_import { |
| 170 | name: "foo", |
| 171 | apk: "prebuilts/apk/app.apk", |
| 172 | certificate: "platform", |
| 173 | lineage: ":lineage_bin", |
| 174 | } |
| 175 | |
| 176 | filegroup { |
| 177 | name: "lineage_bin", |
| 178 | srcs: ["lineage.bin"], |
| 179 | } |
| 180 | `) |
| 181 | |
| 182 | variant := ctx.ModuleForTests("foo", "android_common") |
| 183 | |
| 184 | signedApk := variant.Output("signed/foo.apk") |
| 185 | // Check cert signing lineage flag. |
| 186 | signingFlag := signedApk.Args["flags"] |
| 187 | expected := "--lineage lineage.bin" |
| 188 | if expected != signingFlag { |
| 189 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) |
| 190 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 191 | |
| 192 | rule := variant.Rule("genProvenanceMetaData") |
| 193 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 194 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 195 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 196 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 199 | func TestAndroidAppImport_DefaultDevCert(t *testing.T) { |
| 200 | ctx, _ := testJava(t, ` |
| 201 | android_app_import { |
| 202 | name: "foo", |
| 203 | apk: "prebuilts/apk/app.apk", |
| 204 | default_dev_cert: true, |
| 205 | dex_preopt: { |
| 206 | enabled: true, |
| 207 | }, |
| 208 | } |
| 209 | `) |
| 210 | |
| 211 | variant := ctx.ModuleForTests("foo", "android_common") |
| 212 | |
| 213 | // Check dexpreopt outputs. |
| 214 | if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil || |
| 215 | variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil { |
| 216 | t.Errorf("can't find dexpreopt outputs") |
| 217 | } |
| 218 | |
| 219 | // Check cert signing flag. |
| 220 | signedApk := variant.Output("signed/foo.apk") |
| 221 | signingFlag := signedApk.Args["certificates"] |
| 222 | expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8" |
| 223 | if expected != signingFlag { |
| 224 | t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag) |
| 225 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 226 | |
| 227 | rule := variant.Rule("genProvenanceMetaData") |
| 228 | android.AssertStringEquals(t, "Invalid input", "prebuilts/apk/app.apk", rule.Inputs[0].String()) |
| 229 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 230 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 231 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | func TestAndroidAppImport_DpiVariants(t *testing.T) { |
| 235 | bp := ` |
| 236 | android_app_import { |
| 237 | name: "foo", |
| 238 | apk: "prebuilts/apk/app.apk", |
| 239 | dpi_variants: { |
| 240 | xhdpi: { |
| 241 | apk: "prebuilts/apk/app_xhdpi.apk", |
| 242 | }, |
| 243 | xxhdpi: { |
| 244 | apk: "prebuilts/apk/app_xxhdpi.apk", |
| 245 | }, |
| 246 | }, |
| 247 | presigned: true, |
| 248 | dex_preopt: { |
| 249 | enabled: true, |
| 250 | }, |
| 251 | } |
| 252 | ` |
| 253 | testCases := []struct { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 254 | name string |
| 255 | aaptPreferredConfig *string |
| 256 | aaptPrebuiltDPI []string |
| 257 | expected string |
| 258 | expectedProvenanceMetaDataArtifactPath string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 259 | }{ |
| 260 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 261 | name: "no preferred", |
| 262 | aaptPreferredConfig: nil, |
| 263 | aaptPrebuiltDPI: []string{}, |
| 264 | expected: "verify_uses_libraries/apk/app.apk", |
| 265 | expectedProvenanceMetaDataArtifactPath: "prebuilts/apk/app.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 266 | }, |
| 267 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 268 | name: "AAPTPreferredConfig matches", |
| 269 | aaptPreferredConfig: proptools.StringPtr("xhdpi"), |
| 270 | aaptPrebuiltDPI: []string{"xxhdpi", "ldpi"}, |
| 271 | expected: "verify_uses_libraries/apk/app_xhdpi.apk", |
| 272 | expectedProvenanceMetaDataArtifactPath: "prebuilts/apk/app_xhdpi.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 273 | }, |
| 274 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 275 | name: "AAPTPrebuiltDPI matches", |
| 276 | aaptPreferredConfig: proptools.StringPtr("mdpi"), |
| 277 | aaptPrebuiltDPI: []string{"xxhdpi", "xhdpi"}, |
| 278 | expected: "verify_uses_libraries/apk/app_xxhdpi.apk", |
| 279 | expectedProvenanceMetaDataArtifactPath: "prebuilts/apk/app_xxhdpi.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 280 | }, |
| 281 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 282 | name: "non-first AAPTPrebuiltDPI matches", |
| 283 | aaptPreferredConfig: proptools.StringPtr("mdpi"), |
| 284 | aaptPrebuiltDPI: []string{"ldpi", "xhdpi"}, |
| 285 | expected: "verify_uses_libraries/apk/app_xhdpi.apk", |
| 286 | expectedProvenanceMetaDataArtifactPath: "prebuilts/apk/app_xhdpi.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 287 | }, |
| 288 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 289 | name: "no matches", |
| 290 | aaptPreferredConfig: proptools.StringPtr("mdpi"), |
| 291 | aaptPrebuiltDPI: []string{"ldpi", "xxxhdpi"}, |
| 292 | expected: "verify_uses_libraries/apk/app.apk", |
| 293 | expectedProvenanceMetaDataArtifactPath: "prebuilts/apk/app.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 294 | }, |
| 295 | } |
| 296 | |
| 297 | jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") |
| 298 | for _, test := range testCases { |
Paul Duffin | fb8bc95 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 299 | result := android.GroupFixturePreparers( |
| 300 | PrepareForTestWithJavaDefaultModules, |
| 301 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 302 | variables.AAPTPreferredConfig = test.aaptPreferredConfig |
| 303 | variables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI |
| 304 | }), |
| 305 | ).RunTestWithBp(t, bp) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 306 | |
Paul Duffin | fb8bc95 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 307 | variant := result.ModuleForTests("foo", "android_common") |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 308 | jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command |
| 309 | matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) |
| 310 | if len(matches) != 2 { |
| 311 | t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) |
| 312 | } |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 313 | if strings.HasSuffix(matches[1], test.expected) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 314 | t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) |
| 315 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 316 | |
| 317 | provenanceMetaDataRule := variant.Rule("genProvenanceMetaData") |
| 318 | android.AssertStringEquals(t, "Invalid input", test.expectedProvenanceMetaDataArtifactPath, provenanceMetaDataRule.Inputs[0].String()) |
| 319 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", provenanceMetaDataRule.Output.String()) |
| 320 | android.AssertStringEquals(t, "Invalid args", "foo", provenanceMetaDataRule.Args["module_name"]) |
| 321 | android.AssertStringEquals(t, "Invalid args", "/system/app/foo/foo.apk", provenanceMetaDataRule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | func TestAndroidAppImport_Filename(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 326 | ctx, _ := testJava(t, ` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 327 | android_app_import { |
| 328 | name: "foo", |
| 329 | apk: "prebuilts/apk/app.apk", |
| 330 | presigned: true, |
| 331 | } |
| 332 | |
| 333 | android_app_import { |
| 334 | name: "bar", |
| 335 | apk: "prebuilts/apk/app.apk", |
| 336 | presigned: true, |
| 337 | filename: "bar_sample.apk" |
| 338 | } |
| 339 | `) |
| 340 | |
| 341 | testCases := []struct { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 342 | name string |
| 343 | expected string |
| 344 | onDevice string |
| 345 | expectedArtifactPath string |
| 346 | expectedMetaDataPath string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 347 | }{ |
| 348 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 349 | name: "foo", |
| 350 | expected: "foo.apk", |
| 351 | onDevice: "/system/app/foo/foo.apk", |
| 352 | expectedArtifactPath: "prebuilts/apk/app.apk", |
| 353 | expectedMetaDataPath: "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 354 | }, |
| 355 | { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 356 | name: "bar", |
| 357 | expected: "bar_sample.apk", |
| 358 | onDevice: "/system/app/bar/bar_sample.apk", |
| 359 | expectedArtifactPath: "prebuilts/apk/app.apk", |
| 360 | expectedMetaDataPath: "out/soong/.intermediates/provenance_metadata/bar/provenance_metadata.textproto", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 361 | }, |
| 362 | } |
| 363 | |
| 364 | for _, test := range testCases { |
| 365 | variant := ctx.ModuleForTests(test.name, "android_common") |
| 366 | if variant.MaybeOutput(test.expected).Rule == nil { |
| 367 | t.Errorf("can't find output named %q - all outputs: %v", test.expected, variant.AllOutputs()) |
| 368 | } |
| 369 | |
| 370 | a := variant.Module().(*AndroidAppImport) |
| 371 | expectedValues := []string{test.expected} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 372 | actualValues := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_INSTALLED_MODULE_STEM"] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 373 | if !reflect.DeepEqual(actualValues, expectedValues) { |
| 374 | t.Errorf("Incorrect LOCAL_INSTALLED_MODULE_STEM value '%s', expected '%s'", |
| 375 | actualValues, expectedValues) |
| 376 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 377 | rule := variant.Rule("genProvenanceMetaData") |
| 378 | android.AssertStringEquals(t, "Invalid input", test.expectedArtifactPath, rule.Inputs[0].String()) |
| 379 | android.AssertStringEquals(t, "Invalid output", test.expectedMetaDataPath, rule.Output.String()) |
| 380 | android.AssertStringEquals(t, "Invalid args", test.name, rule.Args["module_name"]) |
| 381 | android.AssertStringEquals(t, "Invalid args", test.onDevice, rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
| 385 | func TestAndroidAppImport_ArchVariants(t *testing.T) { |
| 386 | // The test config's target arch is ARM64. |
| 387 | testCases := []struct { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 388 | name string |
| 389 | bp string |
| 390 | expected string |
| 391 | artifactPath string |
| 392 | metaDataPath string |
| 393 | installPath string |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 394 | }{ |
| 395 | { |
| 396 | name: "matching arch", |
| 397 | bp: ` |
| 398 | android_app_import { |
| 399 | name: "foo", |
| 400 | apk: "prebuilts/apk/app.apk", |
| 401 | arch: { |
| 402 | arm64: { |
| 403 | apk: "prebuilts/apk/app_arm64.apk", |
| 404 | }, |
| 405 | }, |
| 406 | presigned: true, |
| 407 | dex_preopt: { |
| 408 | enabled: true, |
| 409 | }, |
| 410 | } |
| 411 | `, |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 412 | expected: "verify_uses_libraries/apk/app_arm64.apk", |
| 413 | artifactPath: "prebuilts/apk/app_arm64.apk", |
| 414 | installPath: "/system/app/foo/foo.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 415 | }, |
| 416 | { |
| 417 | name: "no matching arch", |
| 418 | bp: ` |
| 419 | android_app_import { |
| 420 | name: "foo", |
| 421 | apk: "prebuilts/apk/app.apk", |
| 422 | arch: { |
| 423 | arm: { |
| 424 | apk: "prebuilts/apk/app_arm.apk", |
| 425 | }, |
| 426 | }, |
| 427 | presigned: true, |
| 428 | dex_preopt: { |
| 429 | enabled: true, |
| 430 | }, |
| 431 | } |
| 432 | `, |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 433 | expected: "verify_uses_libraries/apk/app.apk", |
| 434 | artifactPath: "prebuilts/apk/app.apk", |
| 435 | installPath: "/system/app/foo/foo.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 436 | }, |
| 437 | { |
| 438 | name: "no matching arch without default", |
| 439 | bp: ` |
| 440 | android_app_import { |
| 441 | name: "foo", |
| 442 | arch: { |
| 443 | arm: { |
| 444 | apk: "prebuilts/apk/app_arm.apk", |
| 445 | }, |
| 446 | }, |
| 447 | presigned: true, |
| 448 | dex_preopt: { |
| 449 | enabled: true, |
| 450 | }, |
| 451 | } |
| 452 | `, |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 453 | expected: "", |
| 454 | artifactPath: "prebuilts/apk/app_arm.apk", |
| 455 | installPath: "/system/app/foo/foo.apk", |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 456 | }, |
| 457 | } |
| 458 | |
| 459 | jniRuleRe := regexp.MustCompile("^if \\(zipinfo (\\S+)") |
| 460 | for _, test := range testCases { |
| 461 | ctx, _ := testJava(t, test.bp) |
| 462 | |
| 463 | variant := ctx.ModuleForTests("foo", "android_common") |
| 464 | if test.expected == "" { |
| 465 | if variant.Module().Enabled() { |
| 466 | t.Error("module should have been disabled, but wasn't") |
| 467 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 468 | rule := variant.MaybeRule("genProvenanceMetaData") |
| 469 | android.AssertDeepEquals(t, "Provenance metadata is not empty", android.TestingBuildParams{}, rule) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 470 | continue |
| 471 | } |
| 472 | jniRuleCommand := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command |
| 473 | matches := jniRuleRe.FindStringSubmatch(jniRuleCommand) |
| 474 | if len(matches) != 2 { |
| 475 | t.Errorf("failed to extract the src apk path from %q", jniRuleCommand) |
| 476 | } |
Ulya Trafimovich | 22890c4 | 2021-01-05 12:04:17 +0000 | [diff] [blame] | 477 | if strings.HasSuffix(matches[1], test.expected) { |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 478 | t.Errorf("wrong src apk, expected: %q got: %q", test.expected, matches[1]) |
| 479 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 480 | rule := variant.Rule("genProvenanceMetaData") |
| 481 | android.AssertStringEquals(t, "Invalid input", test.artifactPath, rule.Inputs[0].String()) |
| 482 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/foo/provenance_metadata.textproto", rule.Output.String()) |
| 483 | android.AssertStringEquals(t, "Invalid args", "foo", rule.Args["module_name"]) |
| 484 | android.AssertStringEquals(t, "Invalid args", test.installPath, rule.Args["install_path"]) |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | func TestAndroidAppImport_overridesDisabledAndroidApp(t *testing.T) { |
| 489 | ctx, _ := testJava(t, ` |
| 490 | android_app { |
| 491 | name: "foo", |
| 492 | srcs: ["a.java"], |
| 493 | enabled: false, |
| 494 | } |
| 495 | |
| 496 | android_app_import { |
| 497 | name: "foo", |
| 498 | apk: "prebuilts/apk/app.apk", |
| 499 | certificate: "platform", |
| 500 | prefer: true, |
| 501 | } |
| 502 | `) |
| 503 | |
| 504 | variant := ctx.ModuleForTests("prebuilt_foo", "android_common") |
| 505 | a := variant.Module().(*AndroidAppImport) |
| 506 | // The prebuilt module should still be enabled and active even if the source-based counterpart |
| 507 | // is disabled. |
| 508 | if !a.prebuilt.UsePrebuilt() { |
| 509 | t.Errorf("prebuilt foo module is not active") |
| 510 | } |
| 511 | if !a.Enabled() { |
| 512 | t.Errorf("prebuilt foo module is disabled") |
| 513 | } |
| 514 | } |
| 515 | |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 516 | func TestAndroidAppImport_frameworkRes(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 517 | ctx, _ := testJava(t, ` |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 518 | android_app_import { |
| 519 | name: "framework-res", |
| 520 | certificate: "platform", |
| 521 | apk: "package-res.apk", |
| 522 | prefer: true, |
| 523 | export_package_resources: true, |
| 524 | // Disable dexpreopt and verify_uses_libraries check as the app |
| 525 | // contains no Java code to be dexpreopted. |
| 526 | enforce_uses_libs: false, |
| 527 | dex_preopt: { |
| 528 | enabled: false, |
| 529 | }, |
| 530 | } |
| 531 | `) |
| 532 | |
| 533 | mod := ctx.ModuleForTests("prebuilt_framework-res", "android_common").Module() |
| 534 | a := mod.(*AndroidAppImport) |
| 535 | |
| 536 | if !a.preprocessed { |
| 537 | t.Errorf("prebuilt framework-res is not preprocessed") |
| 538 | } |
| 539 | |
Paul Duffin | fb8bc95 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 540 | expectedInstallPath := "out/soong/target/product/test_device/system/framework/framework-res.apk" |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 541 | |
Paul Duffin | fb8bc95 | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 542 | android.AssertPathRelativeToTopEquals(t, "prebuilt framework-res install location", expectedInstallPath, a.dexpreopter.installPath) |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 543 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 544 | entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] |
Bill Peckham | a036da9 | 2021-01-08 16:09:09 -0800 | [diff] [blame] | 545 | |
| 546 | expectedPath := "." |
| 547 | // From apk property above, in the root of the source tree. |
| 548 | expectedPrebuiltModuleFile := "package-res.apk" |
| 549 | // Verify that the apk is preprocessed: The export package is the same |
| 550 | // as the prebuilt. |
| 551 | expectedSoongResourceExportPackage := expectedPrebuiltModuleFile |
| 552 | |
| 553 | actualPath := entries.EntryMap["LOCAL_PATH"] |
| 554 | actualPrebuiltModuleFile := entries.EntryMap["LOCAL_PREBUILT_MODULE_FILE"] |
| 555 | actualSoongResourceExportPackage := entries.EntryMap["LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE"] |
| 556 | |
| 557 | if len(actualPath) != 1 { |
| 558 | t.Errorf("LOCAL_PATH incorrect len %d", len(actualPath)) |
| 559 | } else if actualPath[0] != expectedPath { |
| 560 | t.Errorf("LOCAL_PATH mismatch, actual: %s, expected: %s", actualPath[0], expectedPath) |
| 561 | } |
| 562 | |
| 563 | if len(actualPrebuiltModuleFile) != 1 { |
| 564 | t.Errorf("LOCAL_PREBUILT_MODULE_FILE incorrect len %d", len(actualPrebuiltModuleFile)) |
| 565 | } else if actualPrebuiltModuleFile[0] != expectedPrebuiltModuleFile { |
| 566 | t.Errorf("LOCAL_PREBUILT_MODULE_FILE mismatch, actual: %s, expected: %s", actualPrebuiltModuleFile[0], expectedPrebuiltModuleFile) |
| 567 | } |
| 568 | |
| 569 | if len(actualSoongResourceExportPackage) != 1 { |
| 570 | t.Errorf("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE incorrect len %d", len(actualSoongResourceExportPackage)) |
| 571 | } else if actualSoongResourceExportPackage[0] != expectedSoongResourceExportPackage { |
| 572 | t.Errorf("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE mismatch, actual: %s, expected: %s", actualSoongResourceExportPackage[0], expectedSoongResourceExportPackage) |
| 573 | } |
| 574 | } |
| 575 | |
Spandan Das | d1fac64 | 2021-05-18 17:01:41 +0000 | [diff] [blame] | 576 | func TestAndroidAppImport_relativeInstallPath(t *testing.T) { |
| 577 | bp := ` |
| 578 | android_app_import { |
| 579 | name: "no_relative_install_path", |
| 580 | apk: "prebuilts/apk/app.apk", |
| 581 | presigned: true, |
| 582 | } |
| 583 | |
| 584 | android_app_import { |
| 585 | name: "relative_install_path", |
| 586 | apk: "prebuilts/apk/app.apk", |
| 587 | presigned: true, |
| 588 | relative_install_path: "my/path", |
| 589 | } |
| 590 | |
| 591 | android_app_import { |
| 592 | name: "framework-res", |
| 593 | apk: "prebuilts/apk/app.apk", |
| 594 | presigned: true, |
| 595 | prefer: true, |
| 596 | } |
| 597 | |
| 598 | android_app_import { |
| 599 | name: "privileged_relative_install_path", |
| 600 | apk: "prebuilts/apk/app.apk", |
| 601 | presigned: true, |
| 602 | privileged: true, |
| 603 | relative_install_path: "my/path" |
| 604 | } |
| 605 | ` |
| 606 | testCases := []struct { |
| 607 | name string |
| 608 | expectedInstallPath string |
| 609 | errorMessage string |
| 610 | }{ |
| 611 | { |
| 612 | name: "no_relative_install_path", |
| 613 | expectedInstallPath: "out/soong/target/product/test_device/system/app/no_relative_install_path/no_relative_install_path.apk", |
| 614 | errorMessage: "Install path is not correct when relative_install_path is missing", |
| 615 | }, |
| 616 | { |
| 617 | name: "relative_install_path", |
| 618 | expectedInstallPath: "out/soong/target/product/test_device/system/app/my/path/relative_install_path/relative_install_path.apk", |
| 619 | errorMessage: "Install path is not correct for app when relative_install_path is present", |
| 620 | }, |
| 621 | { |
| 622 | name: "prebuilt_framework-res", |
| 623 | expectedInstallPath: "out/soong/target/product/test_device/system/framework/framework-res.apk", |
| 624 | errorMessage: "Install path is not correct for framework-res", |
| 625 | }, |
| 626 | { |
| 627 | name: "privileged_relative_install_path", |
| 628 | expectedInstallPath: "out/soong/target/product/test_device/system/priv-app/my/path/privileged_relative_install_path/privileged_relative_install_path.apk", |
| 629 | errorMessage: "Install path is not correct for privileged app when relative_install_path is present", |
| 630 | }, |
| 631 | } |
| 632 | for _, testCase := range testCases { |
| 633 | ctx, _ := testJava(t, bp) |
| 634 | mod := ctx.ModuleForTests(testCase.name, "android_common").Module().(*AndroidAppImport) |
| 635 | android.AssertPathRelativeToTopEquals(t, testCase.errorMessage, testCase.expectedInstallPath, mod.installPath) |
| 636 | } |
| 637 | } |
| 638 | |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 639 | func TestAndroidTestImport(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 640 | ctx, _ := testJava(t, ` |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 641 | android_test_import { |
| 642 | name: "foo", |
| 643 | apk: "prebuilts/apk/app.apk", |
| 644 | presigned: true, |
| 645 | data: [ |
| 646 | "testdata/data", |
| 647 | ], |
| 648 | } |
| 649 | `) |
| 650 | |
| 651 | test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport) |
| 652 | |
| 653 | // Check android mks. |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 654 | entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] |
Jaewoong Jung | f9b4465 | 2020-12-21 12:29:12 -0800 | [diff] [blame] | 655 | expected := []string{"tests"} |
| 656 | actual := entries.EntryMap["LOCAL_MODULE_TAGS"] |
| 657 | if !reflect.DeepEqual(expected, actual) { |
| 658 | t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual) |
| 659 | } |
| 660 | expected = []string{"testdata/data:testdata/data"} |
| 661 | actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] |
| 662 | if !reflect.DeepEqual(expected, actual) { |
| 663 | t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual) |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) { |
| 668 | ctx, _ := testJava(t, ` |
| 669 | android_test_import { |
| 670 | name: "foo", |
| 671 | apk: "prebuilts/apk/app.apk", |
| 672 | certificate: "cert/new_cert", |
| 673 | data: [ |
| 674 | "testdata/data", |
| 675 | ], |
| 676 | } |
| 677 | |
| 678 | android_test_import { |
| 679 | name: "foo_presigned", |
| 680 | apk: "prebuilts/apk/app.apk", |
| 681 | presigned: true, |
| 682 | data: [ |
| 683 | "testdata/data", |
| 684 | ], |
| 685 | } |
| 686 | `) |
| 687 | |
| 688 | variant := ctx.ModuleForTests("foo", "android_common") |
| 689 | jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command |
| 690 | if !strings.HasPrefix(jniRule, "if (zipinfo") { |
| 691 | t.Errorf("Unexpected JNI uncompress rule command: " + jniRule) |
| 692 | } |
| 693 | |
| 694 | variant = ctx.ModuleForTests("foo_presigned", "android_common") |
| 695 | jniRule = variant.Output("jnis-uncompressed/foo_presigned.apk").BuildParams.Rule.String() |
| 696 | if jniRule != android.Cp.String() { |
| 697 | t.Errorf("Unexpected JNI uncompress rule: " + jniRule) |
| 698 | } |
| 699 | if variant.MaybeOutput("zip-aligned/foo_presigned.apk").Rule == nil { |
| 700 | t.Errorf("Presigned test apk should be aligned") |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | func TestAndroidTestImport_Preprocessed(t *testing.T) { |
| 705 | ctx, _ := testJava(t, ` |
| 706 | android_test_import { |
| 707 | name: "foo", |
| 708 | apk: "prebuilts/apk/app.apk", |
| 709 | presigned: true, |
| 710 | preprocessed: true, |
| 711 | } |
| 712 | |
| 713 | android_test_import { |
| 714 | name: "foo_cert", |
| 715 | apk: "prebuilts/apk/app.apk", |
| 716 | certificate: "cert/new_cert", |
| 717 | preprocessed: true, |
| 718 | } |
| 719 | `) |
| 720 | |
| 721 | testModules := []string{"foo", "foo_cert"} |
| 722 | for _, m := range testModules { |
| 723 | apkName := m + ".apk" |
| 724 | variant := ctx.ModuleForTests(m, "android_common") |
| 725 | jniRule := variant.Output("jnis-uncompressed/" + apkName).BuildParams.Rule.String() |
| 726 | if jniRule != android.Cp.String() { |
| 727 | t.Errorf("Unexpected JNI uncompress rule: " + jniRule) |
| 728 | } |
| 729 | |
| 730 | // Make sure signing and aligning were skipped. |
| 731 | if variant.MaybeOutput("signed/"+apkName).Rule != nil { |
| 732 | t.Errorf("signing rule shouldn't be included for preprocessed.") |
| 733 | } |
| 734 | if variant.MaybeOutput("zip-aligned/"+apkName).Rule != nil { |
| 735 | t.Errorf("aligning rule shouldn't be for preprocessed") |
| 736 | } |
| 737 | } |
| 738 | } |
Ulya Trafimovich | 55f72d7 | 2021-09-01 14:13:57 +0100 | [diff] [blame] | 739 | |
| 740 | func TestAndroidTestImport_UncompressDex(t *testing.T) { |
| 741 | testCases := []struct { |
| 742 | name string |
| 743 | bp string |
| 744 | }{ |
| 745 | { |
| 746 | name: "normal", |
| 747 | bp: ` |
| 748 | android_app_import { |
| 749 | name: "foo", |
| 750 | presigned: true, |
| 751 | apk: "prebuilts/apk/app.apk", |
| 752 | } |
| 753 | `, |
| 754 | }, |
| 755 | { |
| 756 | name: "privileged", |
| 757 | bp: ` |
| 758 | android_app_import { |
| 759 | name: "foo", |
| 760 | presigned: true, |
| 761 | privileged: true, |
| 762 | apk: "prebuilts/apk/app.apk", |
| 763 | } |
| 764 | `, |
| 765 | }, |
| 766 | } |
| 767 | |
| 768 | test := func(t *testing.T, bp string, unbundled bool, dontUncompressPrivAppDexs bool) { |
| 769 | t.Helper() |
| 770 | |
| 771 | result := android.GroupFixturePreparers( |
| 772 | prepareForJavaTest, |
| 773 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 774 | if unbundled { |
| 775 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 776 | } |
| 777 | variables.UncompressPrivAppDex = proptools.BoolPtr(!dontUncompressPrivAppDexs) |
| 778 | }), |
| 779 | ).RunTestWithBp(t, bp) |
| 780 | |
| 781 | foo := result.ModuleForTests("foo", "android_common") |
| 782 | actual := foo.MaybeRule("uncompress-dex").Rule != nil |
| 783 | |
| 784 | expect := !unbundled |
| 785 | if strings.Contains(bp, "privileged: true") { |
| 786 | if dontUncompressPrivAppDexs { |
Ulya Trafimovich | 0061c0d | 2021-09-01 15:40:38 +0100 | [diff] [blame] | 787 | expect = false |
Ulya Trafimovich | 55f72d7 | 2021-09-01 14:13:57 +0100 | [diff] [blame] | 788 | } else { |
Ulya Trafimovich | 0061c0d | 2021-09-01 15:40:38 +0100 | [diff] [blame] | 789 | // TODO(b/194504107): shouldn't priv-apps be always uncompressed unless |
| 790 | // DONT_UNCOMPRESS_PRIV_APPS_DEXS is true (regardless of unbundling)? |
Ulya Trafimovich | 55f72d7 | 2021-09-01 14:13:57 +0100 | [diff] [blame] | 791 | // expect = true |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | android.AssertBoolEquals(t, "uncompress dex", expect, actual) |
| 796 | } |
| 797 | |
| 798 | for _, unbundled := range []bool{false, true} { |
| 799 | for _, dontUncompressPrivAppDexs := range []bool{false, true} { |
| 800 | for _, tt := range testCases { |
| 801 | name := fmt.Sprintf("%s,unbundled:%t,dontUncompressPrivAppDexs:%t", |
| 802 | tt.name, unbundled, dontUncompressPrivAppDexs) |
| 803 | t.Run(name, func(t *testing.T) { |
| 804 | test(t, tt.bp, unbundled, dontUncompressPrivAppDexs) |
| 805 | }) |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame^] | 810 | |
| 811 | func TestAppImportMissingCertificateAllowMissingDependencies(t *testing.T) { |
| 812 | result := android.GroupFixturePreparers( |
| 813 | PrepareForTestWithJavaDefaultModules, |
| 814 | android.PrepareForTestWithAllowMissingDependencies, |
| 815 | android.PrepareForTestWithAndroidMk, |
| 816 | ).RunTestWithBp(t, ` |
| 817 | android_app_import { |
| 818 | name: "foo", |
| 819 | apk: "a.apk", |
| 820 | certificate: ":missing_certificate", |
| 821 | }`) |
| 822 | |
| 823 | foo := result.ModuleForTests("foo", "android_common") |
| 824 | fooApk := foo.Output("signed/foo.apk") |
| 825 | if fooApk.Rule != android.ErrorRule { |
| 826 | t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String()) |
| 827 | } |
| 828 | android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n") |
| 829 | } |