blob: 21dbc0fa6838f6201d506b8c98b6e0ed6caeca64 [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// Copyright 2018 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
15package apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jooyung Han39edb6c2019-11-06 16:53:07 +090020 "path"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070021 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090022 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090023 "strings"
24 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090025
26 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090030 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090031)
32
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070033var buildDir string
34
Jooyung Hand3639552019-08-09 12:57:43 +090035// names returns name list from white space separated string
36func names(s string) (ns []string) {
37 for _, n := range strings.Split(s, " ") {
38 if len(n) > 0 {
39 ns = append(ns, n)
40 }
41 }
42 return
43}
44
Jooyung Han344d5432019-08-23 11:17:39 +090045func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
46 t.Helper()
47 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090048 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
49 if len(errs) > 0 {
50 android.FailIfNoMatchingErrors(t, pattern, errs)
51 return
52 }
53 _, errs = ctx.PrepareBuildActions(config)
54 if len(errs) > 0 {
55 android.FailIfNoMatchingErrors(t, pattern, errs)
56 return
57 }
58
59 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
60}
61
Jooyung Han344d5432019-08-23 11:17:39 +090062func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
63 t.Helper()
64 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
66 android.FailIfErrored(t, errs)
67 _, errs = ctx.PrepareBuildActions(config)
68 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070069 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090070}
71
Jooyung Han344d5432019-08-23 11:17:39 +090072type testCustomizer func(fs map[string][]byte, config android.Config)
73
74func withFiles(files map[string][]byte) testCustomizer {
75 return func(fs map[string][]byte, config android.Config) {
76 for k, v := range files {
77 fs[k] = v
78 }
79 }
80}
81
82func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
83 return func(fs map[string][]byte, config android.Config) {
84 for k, v := range targets {
85 config.Targets[k] = v
86 }
87 }
88}
89
Jooyung Han31c470b2019-10-18 16:26:59 +090090func withBinder32bit(fs map[string][]byte, config android.Config) {
91 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
92}
93
Jiyong Park7cd10e32020-01-14 09:22:18 +090094func withUnbundledBuild(fs map[string][]byte, config android.Config) {
95 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
96}
97
Jooyung Han344d5432019-08-23 11:17:39 +090098func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jooyung Han671f1ce2019-12-17 12:47:13 +090099 android.ClearApexDependency()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900100
101 bp = bp + `
102 toolchain_library {
103 name: "libcompiler_rt-extras",
104 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900105 vendor_available: true,
106 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900107 }
108
109 toolchain_library {
110 name: "libatomic",
111 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900112 vendor_available: true,
113 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900114 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900115 }
116
117 toolchain_library {
118 name: "libgcc",
119 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900120 vendor_available: true,
121 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900122 }
123
124 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700125 name: "libgcc_stripped",
126 src: "",
127 vendor_available: true,
128 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900129 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700130 }
131
132 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 name: "libclang_rt.builtins-aarch64-android",
134 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900135 vendor_available: true,
136 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900137 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900138 }
139
140 toolchain_library {
141 name: "libclang_rt.builtins-arm-android",
142 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900143 vendor_available: true,
144 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900145 native_bridge_supported: true,
146 }
147
148 toolchain_library {
149 name: "libclang_rt.builtins-x86_64-android",
150 src: "",
151 vendor_available: true,
152 recovery_available: true,
153 native_bridge_supported: true,
154 }
155
156 toolchain_library {
157 name: "libclang_rt.builtins-i686-android",
158 src: "",
159 vendor_available: true,
160 recovery_available: true,
161 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900162 }
163
164 cc_object {
165 name: "crtbegin_so",
166 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900167 vendor_available: true,
168 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900169 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900170 }
171
172 cc_object {
173 name: "crtend_so",
174 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900175 vendor_available: true,
176 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900177 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900178 }
179
Alex Light3d673592019-01-18 14:37:31 -0800180 cc_object {
181 name: "crtbegin_static",
182 stl: "none",
183 }
184
185 cc_object {
186 name: "crtend_android",
187 stl: "none",
188 }
189
Jiyong Parkda6eb592018-12-19 17:12:36 +0900190 llndk_library {
191 name: "libc",
192 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900193 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900194 }
195
196 llndk_library {
197 name: "libm",
198 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900199 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900200 }
201
202 llndk_library {
203 name: "libdl",
204 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900205 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900206 }
Jooyung Han54aca7b2019-11-20 02:26:02 +0900207
208 filegroup {
209 name: "myapex-file_contexts",
210 srcs: [
211 "system/sepolicy/apex/myapex-file_contexts",
212 ],
213 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900214 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800215
Dario Frenicde2a032019-10-27 00:29:22 +0100216 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900217
Jooyung Han344d5432019-08-23 11:17:39 +0900218 fs := map[string][]byte{
Jooyung Han54aca7b2019-11-20 02:26:02 +0900219 "a.java": nil,
220 "PrebuiltAppFoo.apk": nil,
221 "PrebuiltAppFooPriv.apk": nil,
222 "build/make/target/product/security": nil,
223 "apex_manifest.json": nil,
224 "AndroidManifest.xml": nil,
225 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Park83dc74b2020-01-14 18:38:44 +0900226 "system/sepolicy/apex/myapex2-file_contexts": nil,
Jooyung Han54aca7b2019-11-20 02:26:02 +0900227 "system/sepolicy/apex/otherapex-file_contexts": nil,
228 "system/sepolicy/apex/commonapex-file_contexts": nil,
229 "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800230 "mylib.cpp": nil,
231 "mylib_common.cpp": nil,
232 "mytest.cpp": nil,
233 "mytest1.cpp": nil,
234 "mytest2.cpp": nil,
235 "mytest3.cpp": nil,
236 "myprebuilt": nil,
237 "my_include": nil,
238 "foo/bar/MyClass.java": nil,
239 "prebuilt.jar": nil,
240 "vendor/foo/devkeys/test.x509.pem": nil,
241 "vendor/foo/devkeys/test.pk8": nil,
242 "testkey.x509.pem": nil,
243 "testkey.pk8": nil,
244 "testkey.override.x509.pem": nil,
245 "testkey.override.pk8": nil,
246 "vendor/foo/devkeys/testkey.avbpubkey": nil,
247 "vendor/foo/devkeys/testkey.pem": nil,
248 "NOTICE": nil,
249 "custom_notice": nil,
250 "testkey2.avbpubkey": nil,
251 "testkey2.pem": nil,
252 "myapex-arm64.apex": nil,
253 "myapex-arm.apex": nil,
254 "frameworks/base/api/current.txt": nil,
255 "framework/aidl/a.aidl": nil,
256 "build/make/core/proguard.flags": nil,
257 "build/make/core/proguard_basic_keeps.flags": nil,
258 "dummy.txt": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900259 }
260
261 for _, handler := range handlers {
Colin Cross98be1bb2019-12-13 20:41:13 -0800262 // The fs now needs to be populated before creating the config, call handlers twice
263 // for now, once to get any fs changes, and later after the config was created to
264 // set product variables or targets.
265 tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
266 handler(fs, tempConfig)
Jooyung Han344d5432019-08-23 11:17:39 +0900267 }
268
Colin Cross98be1bb2019-12-13 20:41:13 -0800269 config := android.TestArchConfig(buildDir, nil, bp, fs)
270 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
271 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
272 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
273 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
274 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
275 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
276
277 for _, handler := range handlers {
278 // The fs now needs to be populated before creating the config, call handlers twice
279 // for now, earlier to get any fs changes, and now after the config was created to
280 // set product variables or targets.
281 tempFS := map[string][]byte{}
282 handler(tempFS, config)
283 }
284
285 ctx := android.NewTestArchContext()
286 ctx.RegisterModuleType("apex", BundleFactory)
287 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
288 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
289 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
290 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
291 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
292 ctx.RegisterModuleType("override_apex", overrideApexFactory)
293
Paul Duffin77980a82019-12-19 16:01:36 +0000294 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800295 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800296 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800297 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
298 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800299 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
300 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800301 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000302 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000303 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000304 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900305 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800306
307 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800308 ctx.PreDepsMutators(RegisterPreDepsMutators)
309 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
310 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800311
312 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900313
Jooyung Han5c998b92019-06-27 11:30:33 +0900314 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315}
316
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700317func setUp() {
318 var err error
319 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900320 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700321 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900323}
324
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700325func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900326 os.RemoveAll(buildDir)
327}
328
329// ensure that 'result' contains 'expected'
330func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900331 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900332 if !strings.Contains(result, expected) {
333 t.Errorf("%q is not found in %q", expected, result)
334 }
335}
336
337// ensures that 'result' does not contain 'notExpected'
338func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900339 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900340 if strings.Contains(result, notExpected) {
341 t.Errorf("%q is found in %q", notExpected, result)
342 }
343}
344
345func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900346 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900347 if !android.InList(expected, result) {
348 t.Errorf("%q is not found in %v", expected, result)
349 }
350}
351
352func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900353 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900354 if android.InList(notExpected, result) {
355 t.Errorf("%q is found in %v", notExpected, result)
356 }
357}
358
Jooyung Hane1633032019-08-01 17:41:43 +0900359func ensureListEmpty(t *testing.T, result []string) {
360 t.Helper()
361 if len(result) > 0 {
362 t.Errorf("%q is expected to be empty", result)
363 }
364}
365
Jiyong Park25fc6a92018-11-18 18:02:45 +0900366// Minimal test
367func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700368 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900369 apex_defaults {
370 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900371 manifest: ":myapex.manifest",
372 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900373 key: "myapex.key",
374 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800375 multilib: {
376 both: {
377 binaries: ["foo",],
378 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900379 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900380 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900381 }
382
Jiyong Park30ca9372019-02-07 16:27:23 +0900383 apex {
384 name: "myapex",
385 defaults: ["myapex-defaults"],
386 }
387
Jiyong Park25fc6a92018-11-18 18:02:45 +0900388 apex_key {
389 name: "myapex.key",
390 public_key: "testkey.avbpubkey",
391 private_key: "testkey.pem",
392 }
393
Jiyong Park809bb722019-02-13 21:33:49 +0900394 filegroup {
395 name: "myapex.manifest",
396 srcs: ["apex_manifest.json"],
397 }
398
399 filegroup {
400 name: "myapex.androidmanifest",
401 srcs: ["AndroidManifest.xml"],
402 }
403
Jiyong Park25fc6a92018-11-18 18:02:45 +0900404 cc_library {
405 name: "mylib",
406 srcs: ["mylib.cpp"],
407 shared_libs: ["mylib2"],
408 system_shared_libs: [],
409 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000410 // TODO: remove //apex_available:platform
411 apex_available: [
412 "//apex_available:platform",
413 "myapex",
414 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900415 }
416
Alex Light3d673592019-01-18 14:37:31 -0800417 cc_binary {
418 name: "foo",
419 srcs: ["mylib.cpp"],
420 compile_multilib: "both",
421 multilib: {
422 lib32: {
423 suffix: "32",
424 },
425 lib64: {
426 suffix: "64",
427 },
428 },
429 symlinks: ["foo_link_"],
430 symlink_preferred_arch: true,
431 system_shared_libs: [],
432 static_executable: true,
433 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000434 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800435 }
436
Jiyong Park25fc6a92018-11-18 18:02:45 +0900437 cc_library {
438 name: "mylib2",
439 srcs: ["mylib.cpp"],
440 system_shared_libs: [],
441 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900442 notice: "custom_notice",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000443 // TODO: remove //apex_available:platform
444 apex_available: [
445 "//apex_available:platform",
446 "myapex",
447 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900448 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900449
450 java_library {
451 name: "myjar",
452 srcs: ["foo/bar/MyClass.java"],
453 sdk_version: "none",
454 system_modules: "none",
455 compile_dex: true,
456 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900457 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000458 // TODO: remove //apex_available:platform
459 apex_available: [
460 "//apex_available:platform",
461 "myapex",
462 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900463 }
464
465 java_library {
466 name: "myotherjar",
467 srcs: ["foo/bar/MyClass.java"],
468 sdk_version: "none",
469 system_modules: "none",
470 compile_dex: true,
471 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900472
473 java_library {
474 name: "mysharedjar",
475 srcs: ["foo/bar/MyClass.java"],
476 sdk_version: "none",
477 system_modules: "none",
478 compile_dex: true,
479 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900480 `)
481
Sundong Ahnabb64432019-10-22 13:58:29 +0900482 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900483
484 optFlags := apexRule.Args["opt_flags"]
485 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700486 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900487 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900488
Jiyong Park25fc6a92018-11-18 18:02:45 +0900489 copyCmds := apexRule.Args["copy_commands"]
490
491 // Ensure that main rule creates an output
492 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
493
494 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800495 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900496 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900497
498 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800499 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900500 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900501
502 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800503 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
504 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900505 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
506 // .. but not for java libs
507 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900508 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800509
Colin Cross7113d202019-11-20 16:39:12 -0800510 // Ensure that the platform variant ends with _shared or _common
511 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
512 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900513 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
514 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900515 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
516
517 // Ensure that dynamic dependency to java libs are not included
518 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800519
520 // Ensure that all symlinks are present.
521 found_foo_link_64 := false
522 found_foo := false
523 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900524 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800525 if strings.HasSuffix(cmd, "bin/foo") {
526 found_foo = true
527 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
528 found_foo_link_64 = true
529 }
530 }
531 }
532 good := found_foo && found_foo_link_64
533 if !good {
534 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
535 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900536
Sundong Ahnabb64432019-10-22 13:58:29 +0900537 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700538 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700539 if len(noticeInputs) != 2 {
540 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900541 }
542 ensureListContains(t, noticeInputs, "NOTICE")
543 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900544
545 depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n")
546 ensureListContains(t, depsInfo, "internal myjar")
547 ensureListContains(t, depsInfo, "internal mylib")
548 ensureListContains(t, depsInfo, "internal mylib2")
549 ensureListContains(t, depsInfo, "internal myotherjar")
Alex Light5098a612018-11-29 17:12:15 -0800550}
551
Jooyung Hanf21c7972019-12-16 22:32:06 +0900552func TestDefaults(t *testing.T) {
553 ctx, _ := testApex(t, `
554 apex_defaults {
555 name: "myapex-defaults",
556 key: "myapex.key",
557 prebuilts: ["myetc"],
558 native_shared_libs: ["mylib"],
559 java_libs: ["myjar"],
560 apps: ["AppFoo"],
561 }
562
563 prebuilt_etc {
564 name: "myetc",
565 src: "myprebuilt",
566 }
567
568 apex {
569 name: "myapex",
570 defaults: ["myapex-defaults"],
571 }
572
573 apex_key {
574 name: "myapex.key",
575 public_key: "testkey.avbpubkey",
576 private_key: "testkey.pem",
577 }
578
579 cc_library {
580 name: "mylib",
581 system_shared_libs: [],
582 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000583 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900584 }
585
586 java_library {
587 name: "myjar",
588 srcs: ["foo/bar/MyClass.java"],
589 sdk_version: "none",
590 system_modules: "none",
591 compile_dex: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000592 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900593 }
594
595 android_app {
596 name: "AppFoo",
597 srcs: ["foo/bar/MyClass.java"],
598 sdk_version: "none",
599 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000600 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900601 }
602 `)
603 ensureExactContents(t, ctx, "myapex", []string{
604 "etc/myetc",
605 "javalib/myjar.jar",
606 "lib64/mylib.so",
607 "app/AppFoo/AppFoo.apk",
608 })
609}
610
Jooyung Han01a3ee22019-11-02 02:52:25 +0900611func TestApexManifest(t *testing.T) {
612 ctx, _ := testApex(t, `
613 apex {
614 name: "myapex",
615 key: "myapex.key",
616 }
617
618 apex_key {
619 name: "myapex.key",
620 public_key: "testkey.avbpubkey",
621 private_key: "testkey.pem",
622 }
623 `)
624
625 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900626 args := module.Rule("apexRule").Args
627 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
628 t.Error("manifest should be apex_manifest.pb, but " + manifest)
629 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900630}
631
Alex Light5098a612018-11-29 17:12:15 -0800632func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700633 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800634 apex {
635 name: "myapex",
636 key: "myapex.key",
637 payload_type: "zip",
638 native_shared_libs: ["mylib"],
639 }
640
641 apex_key {
642 name: "myapex.key",
643 public_key: "testkey.avbpubkey",
644 private_key: "testkey.pem",
645 }
646
647 cc_library {
648 name: "mylib",
649 srcs: ["mylib.cpp"],
650 shared_libs: ["mylib2"],
651 system_shared_libs: [],
652 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000653 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800654 }
655
656 cc_library {
657 name: "mylib2",
658 srcs: ["mylib.cpp"],
659 system_shared_libs: [],
660 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800662 }
663 `)
664
Sundong Ahnabb64432019-10-22 13:58:29 +0900665 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800666 copyCmds := zipApexRule.Args["copy_commands"]
667
668 // Ensure that main rule creates an output
669 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
670
671 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800672 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800673
674 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800675 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800676
677 // Ensure that both direct and indirect deps are copied into apex
678 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
679 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900680}
681
682func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700683 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900684 apex {
685 name: "myapex",
686 key: "myapex.key",
687 native_shared_libs: ["mylib", "mylib3"],
688 }
689
690 apex_key {
691 name: "myapex.key",
692 public_key: "testkey.avbpubkey",
693 private_key: "testkey.pem",
694 }
695
696 cc_library {
697 name: "mylib",
698 srcs: ["mylib.cpp"],
699 shared_libs: ["mylib2", "mylib3"],
700 system_shared_libs: [],
701 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000702 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900703 }
704
705 cc_library {
706 name: "mylib2",
707 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900708 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900709 system_shared_libs: [],
710 stl: "none",
711 stubs: {
712 versions: ["1", "2", "3"],
713 },
714 }
715
716 cc_library {
717 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900718 srcs: ["mylib.cpp"],
719 shared_libs: ["mylib4"],
720 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900721 stl: "none",
722 stubs: {
723 versions: ["10", "11", "12"],
724 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000725 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900726 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900727
728 cc_library {
729 name: "mylib4",
730 srcs: ["mylib.cpp"],
731 system_shared_libs: [],
732 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000733 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900734 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900735 `)
736
Sundong Ahnabb64432019-10-22 13:58:29 +0900737 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900738 copyCmds := apexRule.Args["copy_commands"]
739
740 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800741 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900742
743 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800744 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900745
746 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800747 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900748
Colin Cross7113d202019-11-20 16:39:12 -0800749 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900750
751 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900752 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900753 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900754 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900755
756 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Colin Cross7113d202019-11-20 16:39:12 -0800757 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900758 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800759 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900760
761 // Ensure that stubs libs are built without -include flags
Colin Cross7113d202019-11-20 16:39:12 -0800762 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900763 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900764
765 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900766 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900767
768 ensureExactContents(t, ctx, "myapex", []string{
769 "lib64/mylib.so",
770 "lib64/mylib3.so",
771 "lib64/mylib4.so",
772 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900773}
774
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900775func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700776 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900777 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900778 name: "myapex2",
779 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900780 native_shared_libs: ["mylib"],
781 }
782
783 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900784 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900785 public_key: "testkey.avbpubkey",
786 private_key: "testkey.pem",
787 }
788
789 cc_library {
790 name: "mylib",
791 srcs: ["mylib.cpp"],
792 shared_libs: ["libfoo#10"],
793 system_shared_libs: [],
794 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000795 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900796 }
797
798 cc_library {
799 name: "libfoo",
800 srcs: ["mylib.cpp"],
801 shared_libs: ["libbar"],
802 system_shared_libs: [],
803 stl: "none",
804 stubs: {
805 versions: ["10", "20", "30"],
806 },
807 }
808
809 cc_library {
810 name: "libbar",
811 srcs: ["mylib.cpp"],
812 system_shared_libs: [],
813 stl: "none",
814 }
815
816 `)
817
Jiyong Park83dc74b2020-01-14 18:38:44 +0900818 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900819 copyCmds := apexRule.Args["copy_commands"]
820
821 // Ensure that direct non-stubs dep is always included
822 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
823
824 // Ensure that indirect stubs dep is not included
825 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
826
827 // Ensure that dependency of stubs is not included
828 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
829
Jiyong Park83dc74b2020-01-14 18:38:44 +0900830 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900831
832 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900833 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900834 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900835 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900836
Jiyong Park3ff16992019-12-27 14:11:47 +0900837 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900838
839 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
840 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900841
842 depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n")
843 ensureListContains(t, depsInfo, "internal mylib")
844 ensureListContains(t, depsInfo, "external libfoo")
845 ensureListNotContains(t, depsInfo, "internal libfoo")
846 ensureListNotContains(t, depsInfo, "external mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900847}
848
Jooyung Hand3639552019-08-09 12:57:43 +0900849func TestApexWithRuntimeLibsDependency(t *testing.T) {
850 /*
851 myapex
852 |
853 v (runtime_libs)
854 mylib ------+------> libfoo [provides stub]
855 |
856 `------> libbar
857 */
858 ctx, _ := testApex(t, `
859 apex {
860 name: "myapex",
861 key: "myapex.key",
862 native_shared_libs: ["mylib"],
863 }
864
865 apex_key {
866 name: "myapex.key",
867 public_key: "testkey.avbpubkey",
868 private_key: "testkey.pem",
869 }
870
871 cc_library {
872 name: "mylib",
873 srcs: ["mylib.cpp"],
874 runtime_libs: ["libfoo", "libbar"],
875 system_shared_libs: [],
876 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000877 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900878 }
879
880 cc_library {
881 name: "libfoo",
882 srcs: ["mylib.cpp"],
883 system_shared_libs: [],
884 stl: "none",
885 stubs: {
886 versions: ["10", "20", "30"],
887 },
888 }
889
890 cc_library {
891 name: "libbar",
892 srcs: ["mylib.cpp"],
893 system_shared_libs: [],
894 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000895 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900896 }
897
898 `)
899
Sundong Ahnabb64432019-10-22 13:58:29 +0900900 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900901 copyCmds := apexRule.Args["copy_commands"]
902
903 // Ensure that direct non-stubs dep is always included
904 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
905
906 // Ensure that indirect stubs dep is not included
907 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
908
909 // Ensure that runtime_libs dep in included
910 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
911
Sundong Ahnabb64432019-10-22 13:58:29 +0900912 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900913 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
914 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900915
916}
917
Jooyung Han9c80bae2019-08-20 17:30:57 +0900918func TestApexDependencyToLLNDK(t *testing.T) {
919 ctx, _ := testApex(t, `
920 apex {
921 name: "myapex",
922 key: "myapex.key",
923 use_vendor: true,
924 native_shared_libs: ["mylib"],
925 }
926
927 apex_key {
928 name: "myapex.key",
929 public_key: "testkey.avbpubkey",
930 private_key: "testkey.pem",
931 }
932
933 cc_library {
934 name: "mylib",
935 srcs: ["mylib.cpp"],
936 vendor_available: true,
937 shared_libs: ["libbar"],
938 system_shared_libs: [],
939 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000940 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900941 }
942
943 cc_library {
944 name: "libbar",
945 srcs: ["mylib.cpp"],
946 system_shared_libs: [],
947 stl: "none",
948 }
949
950 llndk_library {
951 name: "libbar",
952 symbol_file: "",
953 }
Jooyung Handc782442019-11-01 03:14:38 +0900954 `, func(fs map[string][]byte, config android.Config) {
955 setUseVendorWhitelistForTest(config, []string{"myapex"})
956 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900957
Sundong Ahnabb64432019-10-22 13:58:29 +0900958 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900959 copyCmds := apexRule.Args["copy_commands"]
960
961 // Ensure that LLNDK dep is not included
962 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
963
Sundong Ahnabb64432019-10-22 13:58:29 +0900964 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900965 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900966
967 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900968 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900969
970}
971
Jiyong Park25fc6a92018-11-18 18:02:45 +0900972func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700973 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900974 apex {
975 name: "myapex",
976 key: "myapex.key",
977 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
978 }
979
980 apex_key {
981 name: "myapex.key",
982 public_key: "testkey.avbpubkey",
983 private_key: "testkey.pem",
984 }
985
986 cc_library {
987 name: "mylib",
988 srcs: ["mylib.cpp"],
989 shared_libs: ["libdl#27"],
990 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000991 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900992 }
993
994 cc_library_shared {
995 name: "mylib_shared",
996 srcs: ["mylib.cpp"],
997 shared_libs: ["libdl#27"],
998 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000999 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001000 }
1001
1002 cc_library {
1003 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -07001004 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001005 nocrt: true,
1006 system_shared_libs: [],
1007 stl: "none",
1008 stubs: {
1009 versions: ["27", "28", "29"],
1010 },
1011 }
1012
1013 cc_library {
1014 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -07001015 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001016 nocrt: true,
1017 system_shared_libs: [],
1018 stl: "none",
1019 stubs: {
1020 versions: ["27", "28", "29"],
1021 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001022 apex_available: [
1023 "//apex_available:platform",
1024 "myapex"
1025 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001026 }
1027
1028 cc_library {
1029 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -07001030 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001031 nocrt: true,
1032 system_shared_libs: [],
1033 stl: "none",
1034 stubs: {
1035 versions: ["27", "28", "29"],
1036 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001037 apex_available: [
1038 "//apex_available:platform",
1039 "myapex"
1040 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001041 }
Jiyong Parkb0788572018-12-20 22:10:17 +09001042
1043 cc_library {
1044 name: "libBootstrap",
1045 srcs: ["mylib.cpp"],
1046 stl: "none",
1047 bootstrap: true,
1048 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001049 `)
1050
Sundong Ahnabb64432019-10-22 13:58:29 +09001051 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001052 copyCmds := apexRule.Args["copy_commands"]
1053
1054 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -08001055 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +09001056 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
1057 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001058
1059 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001060 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001061
Colin Cross7113d202019-11-20 16:39:12 -08001062 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1063 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1064 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001065
1066 // For dependency to libc
1067 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001068 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001069 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001070 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001071 // ... Cflags from stub is correctly exported to mylib
1072 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
1073 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
1074
1075 // For dependency to libm
1076 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001077 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001078 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001079 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001080 // ... and is not compiling with the stub
1081 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
1082 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
1083
1084 // For dependency to libdl
1085 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001086 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001087 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001088 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
1089 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001090 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001091 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001092 // ... Cflags from stub is correctly exported to mylib
1093 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1094 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001095
1096 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001097 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
1098 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
1099 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
1100 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001101}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001102
1103func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001104 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001105 apex {
1106 name: "myapex",
1107 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001108 native_shared_libs: ["mylib"],
1109 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001110 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001111 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001112 }
1113
1114 apex_key {
1115 name: "myapex.key",
1116 public_key: "testkey.avbpubkey",
1117 private_key: "testkey.pem",
1118 }
1119
1120 prebuilt_etc {
1121 name: "myetc",
1122 src: "myprebuilt",
1123 sub_dir: "foo/bar",
1124 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001125
1126 cc_library {
1127 name: "mylib",
1128 srcs: ["mylib.cpp"],
1129 relative_install_path: "foo/bar",
1130 system_shared_libs: [],
1131 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001132 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001133 }
1134
1135 cc_binary {
1136 name: "mybin",
1137 srcs: ["mylib.cpp"],
1138 relative_install_path: "foo/bar",
1139 system_shared_libs: [],
1140 static_executable: true,
1141 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001142 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001143 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001144 `)
1145
Sundong Ahnabb64432019-10-22 13:58:29 +09001146 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001147 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1148
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001149 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001150 ensureListContains(t, dirs, "etc")
1151 ensureListContains(t, dirs, "etc/foo")
1152 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001153 ensureListContains(t, dirs, "lib64")
1154 ensureListContains(t, dirs, "lib64/foo")
1155 ensureListContains(t, dirs, "lib64/foo/bar")
1156 ensureListContains(t, dirs, "lib")
1157 ensureListContains(t, dirs, "lib/foo")
1158 ensureListContains(t, dirs, "lib/foo/bar")
1159
Jiyong Parkbd13e442019-03-15 18:10:35 +09001160 ensureListContains(t, dirs, "bin")
1161 ensureListContains(t, dirs, "bin/foo")
1162 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001163}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001164
1165func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001166 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001167 apex {
1168 name: "myapex",
1169 key: "myapex.key",
1170 native_shared_libs: ["mylib"],
1171 use_vendor: true,
1172 }
1173
1174 apex_key {
1175 name: "myapex.key",
1176 public_key: "testkey.avbpubkey",
1177 private_key: "testkey.pem",
1178 }
1179
1180 cc_library {
1181 name: "mylib",
1182 srcs: ["mylib.cpp"],
1183 shared_libs: ["mylib2"],
1184 system_shared_libs: [],
1185 vendor_available: true,
1186 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001187 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001188 }
1189
1190 cc_library {
1191 name: "mylib2",
1192 srcs: ["mylib.cpp"],
1193 system_shared_libs: [],
1194 vendor_available: true,
1195 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001196 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001197 }
Jooyung Handc782442019-11-01 03:14:38 +09001198 `, func(fs map[string][]byte, config android.Config) {
1199 setUseVendorWhitelistForTest(config, []string{"myapex"})
1200 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001201
1202 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001203 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001204 for _, implicit := range i.Implicits {
1205 inputsList = append(inputsList, implicit.String())
1206 }
1207 }
1208 inputsString := strings.Join(inputsList, " ")
1209
1210 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001211 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1212 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001213
1214 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001215 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1216 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001217}
Jiyong Park16e91a02018-12-20 18:18:08 +09001218
Jooyung Handc782442019-11-01 03:14:38 +09001219func TestUseVendorRestriction(t *testing.T) {
1220 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1221 apex {
1222 name: "myapex",
1223 key: "myapex.key",
1224 use_vendor: true,
1225 }
1226 apex_key {
1227 name: "myapex.key",
1228 public_key: "testkey.avbpubkey",
1229 private_key: "testkey.pem",
1230 }
1231 `, func(fs map[string][]byte, config android.Config) {
1232 setUseVendorWhitelistForTest(config, []string{""})
1233 })
1234 // no error with whitelist
1235 testApex(t, `
1236 apex {
1237 name: "myapex",
1238 key: "myapex.key",
1239 use_vendor: true,
1240 }
1241 apex_key {
1242 name: "myapex.key",
1243 public_key: "testkey.avbpubkey",
1244 private_key: "testkey.pem",
1245 }
1246 `, func(fs map[string][]byte, config android.Config) {
1247 setUseVendorWhitelistForTest(config, []string{"myapex"})
1248 })
1249}
1250
Jooyung Han5c998b92019-06-27 11:30:33 +09001251func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1252 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1253 apex {
1254 name: "myapex",
1255 key: "myapex.key",
1256 native_shared_libs: ["mylib"],
1257 use_vendor: true,
1258 }
1259
1260 apex_key {
1261 name: "myapex.key",
1262 public_key: "testkey.avbpubkey",
1263 private_key: "testkey.pem",
1264 }
1265
1266 cc_library {
1267 name: "mylib",
1268 srcs: ["mylib.cpp"],
1269 system_shared_libs: [],
1270 stl: "none",
1271 }
1272 `)
1273}
1274
Jiyong Park16e91a02018-12-20 18:18:08 +09001275func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001276 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001277 apex {
1278 name: "myapex",
1279 key: "myapex.key",
1280 native_shared_libs: ["mylib"],
1281 }
1282
1283 apex_key {
1284 name: "myapex.key",
1285 public_key: "testkey.avbpubkey",
1286 private_key: "testkey.pem",
1287 }
1288
1289 cc_library {
1290 name: "mylib",
1291 srcs: ["mylib.cpp"],
1292 system_shared_libs: [],
1293 stl: "none",
1294 stubs: {
1295 versions: ["1", "2", "3"],
1296 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001297 apex_available: [
1298 "//apex_available:platform",
1299 "myapex",
1300 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001301 }
1302
1303 cc_binary {
1304 name: "not_in_apex",
1305 srcs: ["mylib.cpp"],
1306 static_libs: ["mylib"],
1307 static_executable: true,
1308 system_shared_libs: [],
1309 stl: "none",
1310 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001311 `)
1312
Colin Cross7113d202019-11-20 16:39:12 -08001313 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001314
1315 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001316 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001317}
Jiyong Park9335a262018-12-24 11:31:58 +09001318
1319func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001320 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001321 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001322 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001323 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001324 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001325 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001326 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001327 }
1328
1329 cc_library {
1330 name: "mylib",
1331 srcs: ["mylib.cpp"],
1332 system_shared_libs: [],
1333 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001334 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001335 }
1336
1337 apex_key {
1338 name: "myapex.key",
1339 public_key: "testkey.avbpubkey",
1340 private_key: "testkey.pem",
1341 }
1342
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001343 android_app_certificate {
1344 name: "myapex.certificate",
1345 certificate: "testkey",
1346 }
1347
1348 android_app_certificate {
1349 name: "myapex.certificate.override",
1350 certificate: "testkey.override",
1351 }
1352
Jiyong Park9335a262018-12-24 11:31:58 +09001353 `)
1354
1355 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001356 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001357
1358 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1359 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1360 "vendor/foo/devkeys/testkey.avbpubkey")
1361 }
1362 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1363 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1364 "vendor/foo/devkeys/testkey.pem")
1365 }
1366
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001367 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001368 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001369 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001370 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001371 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001372 }
1373}
Jiyong Park58e364a2019-01-19 19:24:06 +09001374
Jooyung Hanf121a652019-12-17 14:30:11 +09001375func TestCertificate(t *testing.T) {
1376 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1377 ctx, _ := testApex(t, `
1378 apex {
1379 name: "myapex",
1380 key: "myapex.key",
1381 }
1382 apex_key {
1383 name: "myapex.key",
1384 public_key: "testkey.avbpubkey",
1385 private_key: "testkey.pem",
1386 }`)
1387 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1388 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1389 if actual := rule.Args["certificates"]; actual != expected {
1390 t.Errorf("certificates should be %q, not %q", expected, actual)
1391 }
1392 })
1393 t.Run("override when unspecified", func(t *testing.T) {
1394 ctx, _ := testApex(t, `
1395 apex {
1396 name: "myapex_keytest",
1397 key: "myapex.key",
1398 file_contexts: ":myapex-file_contexts",
1399 }
1400 apex_key {
1401 name: "myapex.key",
1402 public_key: "testkey.avbpubkey",
1403 private_key: "testkey.pem",
1404 }
1405 android_app_certificate {
1406 name: "myapex.certificate.override",
1407 certificate: "testkey.override",
1408 }`)
1409 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1410 expected := "testkey.override.x509.pem testkey.override.pk8"
1411 if actual := rule.Args["certificates"]; actual != expected {
1412 t.Errorf("certificates should be %q, not %q", expected, actual)
1413 }
1414 })
1415 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1416 ctx, _ := testApex(t, `
1417 apex {
1418 name: "myapex",
1419 key: "myapex.key",
1420 certificate: ":myapex.certificate",
1421 }
1422 apex_key {
1423 name: "myapex.key",
1424 public_key: "testkey.avbpubkey",
1425 private_key: "testkey.pem",
1426 }
1427 android_app_certificate {
1428 name: "myapex.certificate",
1429 certificate: "testkey",
1430 }`)
1431 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1432 expected := "testkey.x509.pem testkey.pk8"
1433 if actual := rule.Args["certificates"]; actual != expected {
1434 t.Errorf("certificates should be %q, not %q", expected, actual)
1435 }
1436 })
1437 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1438 ctx, _ := testApex(t, `
1439 apex {
1440 name: "myapex_keytest",
1441 key: "myapex.key",
1442 file_contexts: ":myapex-file_contexts",
1443 certificate: ":myapex.certificate",
1444 }
1445 apex_key {
1446 name: "myapex.key",
1447 public_key: "testkey.avbpubkey",
1448 private_key: "testkey.pem",
1449 }
1450 android_app_certificate {
1451 name: "myapex.certificate.override",
1452 certificate: "testkey.override",
1453 }`)
1454 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1455 expected := "testkey.override.x509.pem testkey.override.pk8"
1456 if actual := rule.Args["certificates"]; actual != expected {
1457 t.Errorf("certificates should be %q, not %q", expected, actual)
1458 }
1459 })
1460 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1461 ctx, _ := testApex(t, `
1462 apex {
1463 name: "myapex",
1464 key: "myapex.key",
1465 certificate: "testkey",
1466 }
1467 apex_key {
1468 name: "myapex.key",
1469 public_key: "testkey.avbpubkey",
1470 private_key: "testkey.pem",
1471 }`)
1472 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1473 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1474 if actual := rule.Args["certificates"]; actual != expected {
1475 t.Errorf("certificates should be %q, not %q", expected, actual)
1476 }
1477 })
1478 t.Run("override when specified as <name>", func(t *testing.T) {
1479 ctx, _ := testApex(t, `
1480 apex {
1481 name: "myapex_keytest",
1482 key: "myapex.key",
1483 file_contexts: ":myapex-file_contexts",
1484 certificate: "testkey",
1485 }
1486 apex_key {
1487 name: "myapex.key",
1488 public_key: "testkey.avbpubkey",
1489 private_key: "testkey.pem",
1490 }
1491 android_app_certificate {
1492 name: "myapex.certificate.override",
1493 certificate: "testkey.override",
1494 }`)
1495 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1496 expected := "testkey.override.x509.pem testkey.override.pk8"
1497 if actual := rule.Args["certificates"]; actual != expected {
1498 t.Errorf("certificates should be %q, not %q", expected, actual)
1499 }
1500 })
1501}
1502
Jiyong Park58e364a2019-01-19 19:24:06 +09001503func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001504 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001505 apex {
1506 name: "myapex",
1507 key: "myapex.key",
1508 native_shared_libs: ["mylib"],
1509 }
1510
1511 apex {
1512 name: "otherapex",
1513 key: "myapex.key",
1514 native_shared_libs: ["mylib"],
1515 }
1516
1517 apex_key {
1518 name: "myapex.key",
1519 public_key: "testkey.avbpubkey",
1520 private_key: "testkey.pem",
1521 }
1522
1523 cc_library {
1524 name: "mylib",
1525 srcs: ["mylib.cpp"],
1526 system_shared_libs: [],
1527 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001528 // TODO: remove //apex_available:platform
1529 apex_available: [
1530 "//apex_available:platform",
1531 "myapex",
1532 "otherapex",
1533 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001534 }
1535 `)
1536
Jooyung Han6b8459b2019-10-30 08:29:25 +09001537 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001538 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001539 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001540 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1541 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001542
Jooyung Han6b8459b2019-10-30 08:29:25 +09001543 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001544 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001545 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001546 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1547 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001548
Jooyung Han6b8459b2019-10-30 08:29:25 +09001549 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001550 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001551 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001552 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1553 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001554}
Jiyong Park7e636d02019-01-28 16:16:54 +09001555
1556func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001557 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001558 apex {
1559 name: "myapex",
1560 key: "myapex.key",
1561 native_shared_libs: ["mylib"],
1562 }
1563
1564 apex_key {
1565 name: "myapex.key",
1566 public_key: "testkey.avbpubkey",
1567 private_key: "testkey.pem",
1568 }
1569
1570 cc_library_headers {
1571 name: "mylib_headers",
1572 export_include_dirs: ["my_include"],
1573 system_shared_libs: [],
1574 stl: "none",
1575 }
1576
1577 cc_library {
1578 name: "mylib",
1579 srcs: ["mylib.cpp"],
1580 system_shared_libs: [],
1581 stl: "none",
1582 header_libs: ["mylib_headers"],
1583 export_header_lib_headers: ["mylib_headers"],
1584 stubs: {
1585 versions: ["1", "2", "3"],
1586 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001587 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001588 }
1589
1590 cc_library {
1591 name: "otherlib",
1592 srcs: ["mylib.cpp"],
1593 system_shared_libs: [],
1594 stl: "none",
1595 shared_libs: ["mylib"],
1596 }
1597 `)
1598
Colin Cross7113d202019-11-20 16:39:12 -08001599 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001600
1601 // Ensure that the include path of the header lib is exported to 'otherlib'
1602 ensureContains(t, cFlags, "-Imy_include")
1603}
Alex Light9670d332019-01-29 18:07:33 -08001604
Jiyong Park7cd10e32020-01-14 09:22:18 +09001605type fileInApex struct {
1606 path string // path in apex
1607 isLink bool
1608}
1609
1610func getFiles(t *testing.T, ctx *android.TestContext, moduleName string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001611 t.Helper()
Sundong Ahnabb64432019-10-22 13:58:29 +09001612 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001613 copyCmds := apexRule.Args["copy_commands"]
1614 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001615 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001616 for _, cmd := range strings.Split(copyCmds, "&&") {
1617 cmd = strings.TrimSpace(cmd)
1618 if cmd == "" {
1619 continue
1620 }
1621 terms := strings.Split(cmd, " ")
Jiyong Park7cd10e32020-01-14 09:22:18 +09001622 var dst string
1623 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001624 switch terms[0] {
1625 case "mkdir":
1626 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001627 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001628 t.Fatal("copyCmds contains invalid cp command", cmd)
1629 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001630 dst = terms[len(terms)-1]
1631 isLink = false
1632 case "ln":
1633 if len(terms) != 3 && len(terms) != 4 {
1634 // ln LINK TARGET or ln -s LINK TARGET
1635 t.Fatal("copyCmds contains invalid ln command", cmd)
1636 }
1637 dst = terms[len(terms)-1]
1638 isLink = true
1639 default:
1640 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1641 }
1642 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001643 index := strings.Index(dst, imageApexDir)
1644 if index == -1 {
1645 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1646 }
1647 dstFile := dst[index+len(imageApexDir):]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001648 ret = append(ret, fileInApex{path: dstFile, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001649 }
1650 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001651 return ret
1652}
1653
1654func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1655 var failed bool
1656 var surplus []string
1657 filesMatched := make(map[string]bool)
1658 for _, file := range getFiles(t, ctx, moduleName) {
1659 for _, expected := range files {
1660 if matched, _ := path.Match(expected, file.path); matched {
1661 filesMatched[expected] = true
1662 return
1663 }
1664 }
1665 surplus = append(surplus, file.path)
1666 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001667
Jooyung Han31c470b2019-10-18 16:26:59 +09001668 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001669 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001670 t.Log("surplus files", surplus)
1671 failed = true
1672 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001673
1674 if len(files) > len(filesMatched) {
1675 var missing []string
1676 for _, expected := range files {
1677 if !filesMatched[expected] {
1678 missing = append(missing, expected)
1679 }
1680 }
1681 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001682 t.Log("missing files", missing)
1683 failed = true
1684 }
1685 if failed {
1686 t.Fail()
1687 }
1688}
1689
Jooyung Han344d5432019-08-23 11:17:39 +09001690func TestVndkApexCurrent(t *testing.T) {
1691 ctx, _ := testApex(t, `
1692 apex_vndk {
1693 name: "myapex",
1694 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001695 }
1696
1697 apex_key {
1698 name: "myapex.key",
1699 public_key: "testkey.avbpubkey",
1700 private_key: "testkey.pem",
1701 }
1702
1703 cc_library {
1704 name: "libvndk",
1705 srcs: ["mylib.cpp"],
1706 vendor_available: true,
1707 vndk: {
1708 enabled: true,
1709 },
1710 system_shared_libs: [],
1711 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001712 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001713 }
1714
1715 cc_library {
1716 name: "libvndksp",
1717 srcs: ["mylib.cpp"],
1718 vendor_available: true,
1719 vndk: {
1720 enabled: true,
1721 support_system_process: true,
1722 },
1723 system_shared_libs: [],
1724 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001725 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001726 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001727 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001728
Jooyung Han31c470b2019-10-18 16:26:59 +09001729 ensureExactContents(t, ctx, "myapex", []string{
1730 "lib/libvndk.so",
1731 "lib/libvndksp.so",
1732 "lib64/libvndk.so",
1733 "lib64/libvndksp.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001734 "etc/llndk.libraries.VER.txt",
1735 "etc/vndkcore.libraries.VER.txt",
1736 "etc/vndksp.libraries.VER.txt",
1737 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001738 })
Jooyung Han344d5432019-08-23 11:17:39 +09001739}
1740
1741func TestVndkApexWithPrebuilt(t *testing.T) {
1742 ctx, _ := testApex(t, `
1743 apex_vndk {
1744 name: "myapex",
1745 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001746 }
1747
1748 apex_key {
1749 name: "myapex.key",
1750 public_key: "testkey.avbpubkey",
1751 private_key: "testkey.pem",
1752 }
1753
1754 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001755 name: "libvndk",
1756 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001757 vendor_available: true,
1758 vndk: {
1759 enabled: true,
1760 },
1761 system_shared_libs: [],
1762 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001763 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001764 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001765
1766 cc_prebuilt_library_shared {
1767 name: "libvndk.arm",
1768 srcs: ["libvndk.arm.so"],
1769 vendor_available: true,
1770 vndk: {
1771 enabled: true,
1772 },
1773 enabled: false,
1774 arch: {
1775 arm: {
1776 enabled: true,
1777 },
1778 },
1779 system_shared_libs: [],
1780 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001781 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001782 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001783 `+vndkLibrariesTxtFiles("current"),
1784 withFiles(map[string][]byte{
1785 "libvndk.so": nil,
1786 "libvndk.arm.so": nil,
1787 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001788
Jooyung Han31c470b2019-10-18 16:26:59 +09001789 ensureExactContents(t, ctx, "myapex", []string{
1790 "lib/libvndk.so",
1791 "lib/libvndk.arm.so",
1792 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001793 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001794 })
Jooyung Han344d5432019-08-23 11:17:39 +09001795}
1796
Jooyung Han39edb6c2019-11-06 16:53:07 +09001797func vndkLibrariesTxtFiles(vers ...string) (result string) {
1798 for _, v := range vers {
1799 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09001800 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001801 result += `
1802 vndk_libraries_txt {
1803 name: "` + txt + `.libraries.txt",
1804 }
1805 `
1806 }
1807 } else {
1808 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
1809 result += `
1810 prebuilt_etc {
1811 name: "` + txt + `.libraries.` + v + `.txt",
1812 src: "dummy.txt",
1813 }
1814 `
1815 }
1816 }
1817 }
1818 return
1819}
1820
Jooyung Han344d5432019-08-23 11:17:39 +09001821func TestVndkApexVersion(t *testing.T) {
1822 ctx, _ := testApex(t, `
1823 apex_vndk {
1824 name: "myapex_v27",
1825 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001826 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001827 vndk_version: "27",
1828 }
1829
1830 apex_key {
1831 name: "myapex.key",
1832 public_key: "testkey.avbpubkey",
1833 private_key: "testkey.pem",
1834 }
1835
Jooyung Han31c470b2019-10-18 16:26:59 +09001836 vndk_prebuilt_shared {
1837 name: "libvndk27",
1838 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001839 vendor_available: true,
1840 vndk: {
1841 enabled: true,
1842 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001843 target_arch: "arm64",
1844 arch: {
1845 arm: {
1846 srcs: ["libvndk27_arm.so"],
1847 },
1848 arm64: {
1849 srcs: ["libvndk27_arm64.so"],
1850 },
1851 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001852 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001853 }
1854
1855 vndk_prebuilt_shared {
1856 name: "libvndk27",
1857 version: "27",
1858 vendor_available: true,
1859 vndk: {
1860 enabled: true,
1861 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001862 target_arch: "x86_64",
1863 arch: {
1864 x86: {
1865 srcs: ["libvndk27_x86.so"],
1866 },
1867 x86_64: {
1868 srcs: ["libvndk27_x86_64.so"],
1869 },
1870 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09001871 }
1872 `+vndkLibrariesTxtFiles("27"),
1873 withFiles(map[string][]byte{
1874 "libvndk27_arm.so": nil,
1875 "libvndk27_arm64.so": nil,
1876 "libvndk27_x86.so": nil,
1877 "libvndk27_x86_64.so": nil,
1878 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001879
Jooyung Han31c470b2019-10-18 16:26:59 +09001880 ensureExactContents(t, ctx, "myapex_v27", []string{
1881 "lib/libvndk27_arm.so",
1882 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001883 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001884 })
Jooyung Han344d5432019-08-23 11:17:39 +09001885}
1886
1887func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1888 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1889 apex_vndk {
1890 name: "myapex_v27",
1891 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001892 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001893 vndk_version: "27",
1894 }
1895 apex_vndk {
1896 name: "myapex_v27_other",
1897 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001898 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001899 vndk_version: "27",
1900 }
1901
1902 apex_key {
1903 name: "myapex.key",
1904 public_key: "testkey.avbpubkey",
1905 private_key: "testkey.pem",
1906 }
1907
1908 cc_library {
1909 name: "libvndk",
1910 srcs: ["mylib.cpp"],
1911 vendor_available: true,
1912 vndk: {
1913 enabled: true,
1914 },
1915 system_shared_libs: [],
1916 stl: "none",
1917 }
1918
1919 vndk_prebuilt_shared {
1920 name: "libvndk",
1921 version: "27",
1922 vendor_available: true,
1923 vndk: {
1924 enabled: true,
1925 },
1926 srcs: ["libvndk.so"],
1927 }
1928 `, withFiles(map[string][]byte{
1929 "libvndk.so": nil,
1930 }))
1931}
1932
Jooyung Han90eee022019-10-01 20:02:42 +09001933func TestVndkApexNameRule(t *testing.T) {
1934 ctx, _ := testApex(t, `
1935 apex_vndk {
1936 name: "myapex",
1937 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001938 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09001939 }
1940 apex_vndk {
1941 name: "myapex_v28",
1942 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001943 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09001944 vndk_version: "28",
1945 }
1946 apex_key {
1947 name: "myapex.key",
1948 public_key: "testkey.avbpubkey",
1949 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001950 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09001951
1952 assertApexName := func(expected, moduleName string) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001953 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001954 actual := proptools.String(bundle.properties.Apex_name)
1955 if !reflect.DeepEqual(actual, expected) {
1956 t.Errorf("Got '%v', expected '%v'", actual, expected)
1957 }
1958 }
1959
1960 assertApexName("com.android.vndk.vVER", "myapex")
1961 assertApexName("com.android.vndk.v28", "myapex_v28")
1962}
1963
Jooyung Han344d5432019-08-23 11:17:39 +09001964func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1965 ctx, _ := testApex(t, `
1966 apex_vndk {
1967 name: "myapex",
1968 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001969 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001970 }
1971
1972 apex_key {
1973 name: "myapex.key",
1974 public_key: "testkey.avbpubkey",
1975 private_key: "testkey.pem",
1976 }
1977
1978 cc_library {
1979 name: "libvndk",
1980 srcs: ["mylib.cpp"],
1981 vendor_available: true,
1982 native_bridge_supported: true,
1983 host_supported: true,
1984 vndk: {
1985 enabled: true,
1986 },
1987 system_shared_libs: [],
1988 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001989 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001990 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001991 `+vndkLibrariesTxtFiles("current"),
1992 withTargets(map[android.OsType][]android.Target{
1993 android.Android: []android.Target{
1994 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1995 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1996 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1997 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
1998 },
1999 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002000
Jooyung Han31c470b2019-10-18 16:26:59 +09002001 ensureExactContents(t, ctx, "myapex", []string{
2002 "lib/libvndk.so",
2003 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002004 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002005 })
Jooyung Han344d5432019-08-23 11:17:39 +09002006}
2007
2008func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2009 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2010 apex_vndk {
2011 name: "myapex",
2012 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002013 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002014 native_bridge_supported: true,
2015 }
2016
2017 apex_key {
2018 name: "myapex.key",
2019 public_key: "testkey.avbpubkey",
2020 private_key: "testkey.pem",
2021 }
2022
2023 cc_library {
2024 name: "libvndk",
2025 srcs: ["mylib.cpp"],
2026 vendor_available: true,
2027 native_bridge_supported: true,
2028 host_supported: true,
2029 vndk: {
2030 enabled: true,
2031 },
2032 system_shared_libs: [],
2033 stl: "none",
2034 }
2035 `)
2036}
2037
Jooyung Han31c470b2019-10-18 16:26:59 +09002038func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002039 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002040 apex_vndk {
2041 name: "myapex_v27",
2042 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002043 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002044 vndk_version: "27",
2045 }
2046
2047 apex_key {
2048 name: "myapex.key",
2049 public_key: "testkey.avbpubkey",
2050 private_key: "testkey.pem",
2051 }
2052
2053 vndk_prebuilt_shared {
2054 name: "libvndk27",
2055 version: "27",
2056 target_arch: "arm",
2057 vendor_available: true,
2058 vndk: {
2059 enabled: true,
2060 },
2061 arch: {
2062 arm: {
2063 srcs: ["libvndk27.so"],
2064 }
2065 },
2066 }
2067
2068 vndk_prebuilt_shared {
2069 name: "libvndk27",
2070 version: "27",
2071 target_arch: "arm",
2072 binder32bit: true,
2073 vendor_available: true,
2074 vndk: {
2075 enabled: true,
2076 },
2077 arch: {
2078 arm: {
2079 srcs: ["libvndk27binder32.so"],
2080 }
2081 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002082 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002083 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002084 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002085 withFiles(map[string][]byte{
2086 "libvndk27.so": nil,
2087 "libvndk27binder32.so": nil,
2088 }),
2089 withBinder32bit,
2090 withTargets(map[android.OsType][]android.Target{
2091 android.Android: []android.Target{
2092 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2093 },
2094 }),
2095 )
2096
2097 ensureExactContents(t, ctx, "myapex_v27", []string{
2098 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002099 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002100 })
2101}
2102
Jooyung Hane1633032019-08-01 17:41:43 +09002103func TestDependenciesInApexManifest(t *testing.T) {
2104 ctx, _ := testApex(t, `
2105 apex {
2106 name: "myapex_nodep",
2107 key: "myapex.key",
2108 native_shared_libs: ["lib_nodep"],
2109 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002110 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002111 }
2112
2113 apex {
2114 name: "myapex_dep",
2115 key: "myapex.key",
2116 native_shared_libs: ["lib_dep"],
2117 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002118 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002119 }
2120
2121 apex {
2122 name: "myapex_provider",
2123 key: "myapex.key",
2124 native_shared_libs: ["libfoo"],
2125 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002126 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002127 }
2128
2129 apex {
2130 name: "myapex_selfcontained",
2131 key: "myapex.key",
2132 native_shared_libs: ["lib_dep", "libfoo"],
2133 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002134 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002135 }
2136
2137 apex_key {
2138 name: "myapex.key",
2139 public_key: "testkey.avbpubkey",
2140 private_key: "testkey.pem",
2141 }
2142
2143 cc_library {
2144 name: "lib_nodep",
2145 srcs: ["mylib.cpp"],
2146 system_shared_libs: [],
2147 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002148 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002149 }
2150
2151 cc_library {
2152 name: "lib_dep",
2153 srcs: ["mylib.cpp"],
2154 shared_libs: ["libfoo"],
2155 system_shared_libs: [],
2156 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002157 apex_available: [
2158 "myapex_dep",
2159 "myapex_provider",
2160 "myapex_selfcontained",
2161 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002162 }
2163
2164 cc_library {
2165 name: "libfoo",
2166 srcs: ["mytest.cpp"],
2167 stubs: {
2168 versions: ["1"],
2169 },
2170 system_shared_libs: [],
2171 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002172 apex_available: [
2173 "myapex_provider",
2174 "myapex_selfcontained",
2175 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002176 }
2177 `)
2178
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002179 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002180 var provideNativeLibs, requireNativeLibs []string
2181
Sundong Ahnabb64432019-10-22 13:58:29 +09002182 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002183 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2184 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002185 ensureListEmpty(t, provideNativeLibs)
2186 ensureListEmpty(t, requireNativeLibs)
2187
Sundong Ahnabb64432019-10-22 13:58:29 +09002188 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002189 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2190 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002191 ensureListEmpty(t, provideNativeLibs)
2192 ensureListContains(t, requireNativeLibs, "libfoo.so")
2193
Sundong Ahnabb64432019-10-22 13:58:29 +09002194 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002195 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2196 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002197 ensureListContains(t, provideNativeLibs, "libfoo.so")
2198 ensureListEmpty(t, requireNativeLibs)
2199
Sundong Ahnabb64432019-10-22 13:58:29 +09002200 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002201 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2202 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002203 ensureListContains(t, provideNativeLibs, "libfoo.so")
2204 ensureListEmpty(t, requireNativeLibs)
2205}
2206
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002207func TestApexName(t *testing.T) {
2208 ctx, _ := testApex(t, `
2209 apex {
2210 name: "myapex",
2211 key: "myapex.key",
2212 apex_name: "com.android.myapex",
2213 }
2214
2215 apex_key {
2216 name: "myapex.key",
2217 public_key: "testkey.avbpubkey",
2218 private_key: "testkey.pem",
2219 }
2220 `)
2221
Sundong Ahnabb64432019-10-22 13:58:29 +09002222 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002223 apexManifestRule := module.Rule("apexManifestRule")
2224 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2225 apexRule := module.Rule("apexRule")
2226 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
2227}
2228
Alex Light0851b882019-02-07 13:20:53 -08002229func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002230 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002231 apex {
2232 name: "myapex",
2233 key: "myapex.key",
2234 native_shared_libs: ["mylib_common"],
2235 }
2236
2237 apex_key {
2238 name: "myapex.key",
2239 public_key: "testkey.avbpubkey",
2240 private_key: "testkey.pem",
2241 }
2242
2243 cc_library {
2244 name: "mylib_common",
2245 srcs: ["mylib.cpp"],
2246 system_shared_libs: [],
2247 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002248 apex_available: [
2249 "//apex_available:platform",
2250 "myapex",
2251 ],
Alex Light0851b882019-02-07 13:20:53 -08002252 }
2253 `)
2254
Sundong Ahnabb64432019-10-22 13:58:29 +09002255 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002256 apexRule := module.Rule("apexRule")
2257 copyCmds := apexRule.Args["copy_commands"]
2258
2259 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2260 t.Log("Apex was a test apex!")
2261 t.Fail()
2262 }
2263 // Ensure that main rule creates an output
2264 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2265
2266 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002267 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002268
2269 // Ensure that both direct and indirect deps are copied into apex
2270 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2271
Colin Cross7113d202019-11-20 16:39:12 -08002272 // Ensure that the platform variant ends with _shared
2273 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002274
2275 if !android.InAnyApex("mylib_common") {
2276 t.Log("Found mylib_common not in any apex!")
2277 t.Fail()
2278 }
2279}
2280
2281func TestTestApex(t *testing.T) {
2282 if android.InAnyApex("mylib_common_test") {
2283 t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
2284 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002285 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002286 apex_test {
2287 name: "myapex",
2288 key: "myapex.key",
2289 native_shared_libs: ["mylib_common_test"],
2290 }
2291
2292 apex_key {
2293 name: "myapex.key",
2294 public_key: "testkey.avbpubkey",
2295 private_key: "testkey.pem",
2296 }
2297
2298 cc_library {
2299 name: "mylib_common_test",
2300 srcs: ["mylib.cpp"],
2301 system_shared_libs: [],
2302 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002303 // TODO: remove //apex_available:platform
2304 apex_available: [
2305 "//apex_available:platform",
2306 "myapex",
2307 ],
Alex Light0851b882019-02-07 13:20:53 -08002308 }
2309 `)
2310
Sundong Ahnabb64432019-10-22 13:58:29 +09002311 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002312 apexRule := module.Rule("apexRule")
2313 copyCmds := apexRule.Args["copy_commands"]
2314
2315 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2316 t.Log("Apex was not a test apex!")
2317 t.Fail()
2318 }
2319 // Ensure that main rule creates an output
2320 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2321
2322 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002323 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002324
2325 // Ensure that both direct and indirect deps are copied into apex
2326 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2327
Colin Cross7113d202019-11-20 16:39:12 -08002328 // Ensure that the platform variant ends with _shared
2329 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002330
2331 if android.InAnyApex("mylib_common_test") {
2332 t.Log("Found mylib_common_test in some apex!")
2333 t.Fail()
2334 }
2335}
2336
Alex Light9670d332019-01-29 18:07:33 -08002337func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002338 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002339 apex {
2340 name: "myapex",
2341 key: "myapex.key",
2342 multilib: {
2343 first: {
2344 native_shared_libs: ["mylib_common"],
2345 }
2346 },
2347 target: {
2348 android: {
2349 multilib: {
2350 first: {
2351 native_shared_libs: ["mylib"],
2352 }
2353 }
2354 },
2355 host: {
2356 multilib: {
2357 first: {
2358 native_shared_libs: ["mylib2"],
2359 }
2360 }
2361 }
2362 }
2363 }
2364
2365 apex_key {
2366 name: "myapex.key",
2367 public_key: "testkey.avbpubkey",
2368 private_key: "testkey.pem",
2369 }
2370
2371 cc_library {
2372 name: "mylib",
2373 srcs: ["mylib.cpp"],
2374 system_shared_libs: [],
2375 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002376 // TODO: remove //apex_available:platform
2377 apex_available: [
2378 "//apex_available:platform",
2379 "myapex",
2380 ],
Alex Light9670d332019-01-29 18:07:33 -08002381 }
2382
2383 cc_library {
2384 name: "mylib_common",
2385 srcs: ["mylib.cpp"],
2386 system_shared_libs: [],
2387 stl: "none",
2388 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002389 // TODO: remove //apex_available:platform
2390 apex_available: [
2391 "//apex_available:platform",
2392 "myapex",
2393 ],
Alex Light9670d332019-01-29 18:07:33 -08002394 }
2395
2396 cc_library {
2397 name: "mylib2",
2398 srcs: ["mylib.cpp"],
2399 system_shared_libs: [],
2400 stl: "none",
2401 compile_multilib: "first",
2402 }
2403 `)
2404
Sundong Ahnabb64432019-10-22 13:58:29 +09002405 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002406 copyCmds := apexRule.Args["copy_commands"]
2407
2408 // Ensure that main rule creates an output
2409 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2410
2411 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002412 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2413 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2414 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002415
2416 // Ensure that both direct and indirect deps are copied into apex
2417 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2418 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2419 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2420
Colin Cross7113d202019-11-20 16:39:12 -08002421 // Ensure that the platform variant ends with _shared
2422 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2423 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2424 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002425}
Jiyong Park04480cf2019-02-06 00:16:29 +09002426
2427func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002428 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002429 apex {
2430 name: "myapex",
2431 key: "myapex.key",
2432 binaries: ["myscript"],
2433 }
2434
2435 apex_key {
2436 name: "myapex.key",
2437 public_key: "testkey.avbpubkey",
2438 private_key: "testkey.pem",
2439 }
2440
2441 sh_binary {
2442 name: "myscript",
2443 src: "mylib.cpp",
2444 filename: "myscript.sh",
2445 sub_dir: "script",
2446 }
2447 `)
2448
Sundong Ahnabb64432019-10-22 13:58:29 +09002449 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002450 copyCmds := apexRule.Args["copy_commands"]
2451
2452 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2453}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002454
Jooyung Han91df2082019-11-20 01:49:42 +09002455func TestApexInVariousPartition(t *testing.T) {
2456 testcases := []struct {
2457 propName, parition, flattenedPartition string
2458 }{
2459 {"", "system", "system_ext"},
2460 {"product_specific: true", "product", "product"},
2461 {"soc_specific: true", "vendor", "vendor"},
2462 {"proprietary: true", "vendor", "vendor"},
2463 {"vendor: true", "vendor", "vendor"},
2464 {"system_ext_specific: true", "system_ext", "system_ext"},
2465 }
2466 for _, tc := range testcases {
2467 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2468 ctx, _ := testApex(t, `
2469 apex {
2470 name: "myapex",
2471 key: "myapex.key",
2472 `+tc.propName+`
2473 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002474
Jooyung Han91df2082019-11-20 01:49:42 +09002475 apex_key {
2476 name: "myapex.key",
2477 public_key: "testkey.avbpubkey",
2478 private_key: "testkey.pem",
2479 }
2480 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002481
Jooyung Han91df2082019-11-20 01:49:42 +09002482 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2483 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2484 actual := apex.installDir.String()
2485 if actual != expected {
2486 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2487 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002488
Jooyung Han91df2082019-11-20 01:49:42 +09002489 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2490 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2491 actual = flattened.installDir.String()
2492 if actual != expected {
2493 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2494 }
2495 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002496 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002497}
Jiyong Park67882562019-03-21 01:11:21 +09002498
Jooyung Han54aca7b2019-11-20 02:26:02 +09002499func TestFileContexts(t *testing.T) {
2500 ctx, _ := testApex(t, `
2501 apex {
2502 name: "myapex",
2503 key: "myapex.key",
2504 }
2505
2506 apex_key {
2507 name: "myapex.key",
2508 public_key: "testkey.avbpubkey",
2509 private_key: "testkey.pem",
2510 }
2511 `)
2512 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2513 apexRule := module.Rule("apexRule")
2514 actual := apexRule.Args["file_contexts"]
2515 expected := "system/sepolicy/apex/myapex-file_contexts"
2516 if actual != expected {
2517 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2518 }
2519
2520 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2521 apex {
2522 name: "myapex",
2523 key: "myapex.key",
2524 file_contexts: "my_own_file_contexts",
2525 }
2526
2527 apex_key {
2528 name: "myapex.key",
2529 public_key: "testkey.avbpubkey",
2530 private_key: "testkey.pem",
2531 }
2532 `, withFiles(map[string][]byte{
2533 "my_own_file_contexts": nil,
2534 }))
2535
2536 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2537 apex {
2538 name: "myapex",
2539 key: "myapex.key",
2540 product_specific: true,
2541 file_contexts: "product_specific_file_contexts",
2542 }
2543
2544 apex_key {
2545 name: "myapex.key",
2546 public_key: "testkey.avbpubkey",
2547 private_key: "testkey.pem",
2548 }
2549 `)
2550
2551 ctx, _ = testApex(t, `
2552 apex {
2553 name: "myapex",
2554 key: "myapex.key",
2555 product_specific: true,
2556 file_contexts: "product_specific_file_contexts",
2557 }
2558
2559 apex_key {
2560 name: "myapex.key",
2561 public_key: "testkey.avbpubkey",
2562 private_key: "testkey.pem",
2563 }
2564 `, withFiles(map[string][]byte{
2565 "product_specific_file_contexts": nil,
2566 }))
2567 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2568 apexRule = module.Rule("apexRule")
2569 actual = apexRule.Args["file_contexts"]
2570 expected = "product_specific_file_contexts"
2571 if actual != expected {
2572 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2573 }
2574
2575 ctx, _ = testApex(t, `
2576 apex {
2577 name: "myapex",
2578 key: "myapex.key",
2579 product_specific: true,
2580 file_contexts: ":my-file-contexts",
2581 }
2582
2583 apex_key {
2584 name: "myapex.key",
2585 public_key: "testkey.avbpubkey",
2586 private_key: "testkey.pem",
2587 }
2588
2589 filegroup {
2590 name: "my-file-contexts",
2591 srcs: ["product_specific_file_contexts"],
2592 }
2593 `, withFiles(map[string][]byte{
2594 "product_specific_file_contexts": nil,
2595 }))
2596 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2597 apexRule = module.Rule("apexRule")
2598 actual = apexRule.Args["file_contexts"]
2599 expected = "product_specific_file_contexts"
2600 if actual != expected {
2601 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2602 }
2603}
2604
Jiyong Park67882562019-03-21 01:11:21 +09002605func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002606 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002607 apex_key {
2608 name: "myapex.key",
2609 public_key: ":my.avbpubkey",
2610 private_key: ":my.pem",
2611 product_specific: true,
2612 }
2613
2614 filegroup {
2615 name: "my.avbpubkey",
2616 srcs: ["testkey2.avbpubkey"],
2617 }
2618
2619 filegroup {
2620 name: "my.pem",
2621 srcs: ["testkey2.pem"],
2622 }
2623 `)
2624
2625 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2626 expected_pubkey := "testkey2.avbpubkey"
2627 actual_pubkey := apex_key.public_key_file.String()
2628 if actual_pubkey != expected_pubkey {
2629 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2630 }
2631 expected_privkey := "testkey2.pem"
2632 actual_privkey := apex_key.private_key_file.String()
2633 if actual_privkey != expected_privkey {
2634 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2635 }
2636}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002637
2638func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002639 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002640 prebuilt_apex {
2641 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002642 arch: {
2643 arm64: {
2644 src: "myapex-arm64.apex",
2645 },
2646 arm: {
2647 src: "myapex-arm.apex",
2648 },
2649 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002650 }
2651 `)
2652
2653 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2654
Jiyong Parkc95714e2019-03-29 14:23:10 +09002655 expectedInput := "myapex-arm64.apex"
2656 if prebuilt.inputApex.String() != expectedInput {
2657 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2658 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002659}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002660
2661func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002662 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002663 prebuilt_apex {
2664 name: "myapex",
2665 src: "myapex-arm.apex",
2666 filename: "notmyapex.apex",
2667 }
2668 `)
2669
2670 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2671
2672 expected := "notmyapex.apex"
2673 if p.installFilename != expected {
2674 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2675 }
2676}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002677
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002678func TestPrebuiltOverrides(t *testing.T) {
2679 ctx, config := testApex(t, `
2680 prebuilt_apex {
2681 name: "myapex.prebuilt",
2682 src: "myapex-arm.apex",
2683 overrides: [
2684 "myapex",
2685 ],
2686 }
2687 `)
2688
2689 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2690
2691 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002692 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002693 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002694 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002695 }
2696}
2697
Roland Levillain630846d2019-06-26 12:48:34 +01002698func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002699 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002700 apex_test {
2701 name: "myapex",
2702 key: "myapex.key",
2703 tests: [
2704 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002705 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002706 ],
2707 }
2708
2709 apex_key {
2710 name: "myapex.key",
2711 public_key: "testkey.avbpubkey",
2712 private_key: "testkey.pem",
2713 }
2714
2715 cc_test {
2716 name: "mytest",
2717 gtest: false,
2718 srcs: ["mytest.cpp"],
2719 relative_install_path: "test",
2720 system_shared_libs: [],
2721 static_executable: true,
2722 stl: "none",
2723 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002724
2725 cc_test {
2726 name: "mytests",
2727 gtest: false,
2728 srcs: [
2729 "mytest1.cpp",
2730 "mytest2.cpp",
2731 "mytest3.cpp",
2732 ],
2733 test_per_src: true,
2734 relative_install_path: "test",
2735 system_shared_libs: [],
2736 static_executable: true,
2737 stl: "none",
2738 }
Roland Levillain630846d2019-06-26 12:48:34 +01002739 `)
2740
Sundong Ahnabb64432019-10-22 13:58:29 +09002741 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002742 copyCmds := apexRule.Args["copy_commands"]
2743
2744 // Ensure that test dep is copied into apex.
2745 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002746
2747 // Ensure that test deps built with `test_per_src` are copied into apex.
2748 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2749 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2750 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002751
2752 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002753 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002754 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2755 name := apexBundle.BaseModuleName()
2756 prefix := "TARGET_"
2757 var builder strings.Builder
2758 data.Custom(&builder, name, prefix, "", data)
2759 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002760 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2761 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2762 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2763 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002764 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09002765 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002766 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002767}
2768
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002769func TestInstallExtraFlattenedApexes(t *testing.T) {
2770 ctx, config := testApex(t, `
2771 apex {
2772 name: "myapex",
2773 key: "myapex.key",
2774 }
2775 apex_key {
2776 name: "myapex.key",
2777 public_key: "testkey.avbpubkey",
2778 private_key: "testkey.pem",
2779 }
2780 `, func(fs map[string][]byte, config android.Config) {
2781 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
2782 })
2783 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09002784 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002785 mk := android.AndroidMkDataForTest(t, config, "", ab)
2786 var builder strings.Builder
2787 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
2788 androidMk := builder.String()
2789 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
2790}
2791
Jooyung Han5c998b92019-06-27 11:30:33 +09002792func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002793 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002794 apex {
2795 name: "myapex",
2796 key: "myapex.key",
2797 native_shared_libs: ["mylib"],
2798 uses: ["commonapex"],
2799 }
2800
2801 apex {
2802 name: "commonapex",
2803 key: "myapex.key",
2804 native_shared_libs: ["libcommon"],
2805 provide_cpp_shared_libs: true,
2806 }
2807
2808 apex_key {
2809 name: "myapex.key",
2810 public_key: "testkey.avbpubkey",
2811 private_key: "testkey.pem",
2812 }
2813
2814 cc_library {
2815 name: "mylib",
2816 srcs: ["mylib.cpp"],
2817 shared_libs: ["libcommon"],
2818 system_shared_libs: [],
2819 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002820 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002821 }
2822
2823 cc_library {
2824 name: "libcommon",
2825 srcs: ["mylib_common.cpp"],
2826 system_shared_libs: [],
2827 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002828 // TODO: remove //apex_available:platform
2829 apex_available: [
2830 "//apex_available:platform",
2831 "commonapex",
2832 "myapex",
2833 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002834 }
2835 `)
2836
Sundong Ahnabb64432019-10-22 13:58:29 +09002837 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002838 apexRule1 := module1.Rule("apexRule")
2839 copyCmds1 := apexRule1.Args["copy_commands"]
2840
Sundong Ahnabb64432019-10-22 13:58:29 +09002841 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002842 apexRule2 := module2.Rule("apexRule")
2843 copyCmds2 := apexRule2.Args["copy_commands"]
2844
Colin Cross7113d202019-11-20 16:39:12 -08002845 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2846 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09002847 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2848 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2849 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2850}
2851
2852func TestApexUsesFailsIfNotProvided(t *testing.T) {
2853 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2854 apex {
2855 name: "myapex",
2856 key: "myapex.key",
2857 uses: ["commonapex"],
2858 }
2859
2860 apex {
2861 name: "commonapex",
2862 key: "myapex.key",
2863 }
2864
2865 apex_key {
2866 name: "myapex.key",
2867 public_key: "testkey.avbpubkey",
2868 private_key: "testkey.pem",
2869 }
2870 `)
2871 testApexError(t, `uses: "commonapex" is not a provider`, `
2872 apex {
2873 name: "myapex",
2874 key: "myapex.key",
2875 uses: ["commonapex"],
2876 }
2877
2878 cc_library {
2879 name: "commonapex",
2880 system_shared_libs: [],
2881 stl: "none",
2882 }
2883
2884 apex_key {
2885 name: "myapex.key",
2886 public_key: "testkey.avbpubkey",
2887 private_key: "testkey.pem",
2888 }
2889 `)
2890}
2891
2892func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2893 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2894 apex {
2895 name: "myapex",
2896 key: "myapex.key",
2897 use_vendor: true,
2898 uses: ["commonapex"],
2899 }
2900
2901 apex {
2902 name: "commonapex",
2903 key: "myapex.key",
2904 provide_cpp_shared_libs: true,
2905 }
2906
2907 apex_key {
2908 name: "myapex.key",
2909 public_key: "testkey.avbpubkey",
2910 private_key: "testkey.pem",
2911 }
Jooyung Handc782442019-11-01 03:14:38 +09002912 `, func(fs map[string][]byte, config android.Config) {
2913 setUseVendorWhitelistForTest(config, []string{"myapex"})
2914 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002915}
2916
Jooyung Hand48f3c32019-08-23 11:18:57 +09002917func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2918 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2919 apex {
2920 name: "myapex",
2921 key: "myapex.key",
2922 native_shared_libs: ["libfoo"],
2923 }
2924
2925 apex_key {
2926 name: "myapex.key",
2927 public_key: "testkey.avbpubkey",
2928 private_key: "testkey.pem",
2929 }
2930
2931 cc_library {
2932 name: "libfoo",
2933 stl: "none",
2934 system_shared_libs: [],
2935 enabled: false,
2936 }
2937 `)
2938 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2939 apex {
2940 name: "myapex",
2941 key: "myapex.key",
2942 java_libs: ["myjar"],
2943 }
2944
2945 apex_key {
2946 name: "myapex.key",
2947 public_key: "testkey.avbpubkey",
2948 private_key: "testkey.pem",
2949 }
2950
2951 java_library {
2952 name: "myjar",
2953 srcs: ["foo/bar/MyClass.java"],
2954 sdk_version: "none",
2955 system_modules: "none",
2956 compile_dex: true,
2957 enabled: false,
2958 }
2959 `)
2960}
2961
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002962func TestApexWithApps(t *testing.T) {
2963 ctx, _ := testApex(t, `
2964 apex {
2965 name: "myapex",
2966 key: "myapex.key",
2967 apps: [
2968 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002969 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002970 ],
2971 }
2972
2973 apex_key {
2974 name: "myapex.key",
2975 public_key: "testkey.avbpubkey",
2976 private_key: "testkey.pem",
2977 }
2978
2979 android_app {
2980 name: "AppFoo",
2981 srcs: ["foo/bar/MyClass.java"],
2982 sdk_version: "none",
2983 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09002984 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002985 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002986 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002987
2988 android_app {
2989 name: "AppFooPriv",
2990 srcs: ["foo/bar/MyClass.java"],
2991 sdk_version: "none",
2992 system_modules: "none",
2993 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002994 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09002995 }
Jiyong Park8be103b2019-11-08 15:53:48 +09002996
2997 cc_library_shared {
2998 name: "libjni",
2999 srcs: ["mylib.cpp"],
3000 stl: "none",
3001 system_shared_libs: [],
3002 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003003 `)
3004
Sundong Ahnabb64432019-10-22 13:58:29 +09003005 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003006 apexRule := module.Rule("apexRule")
3007 copyCmds := apexRule.Args["copy_commands"]
3008
3009 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003010 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003011
3012 // JNI libraries are embedded inside APK
3013 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Rule("zip")
Colin Cross7113d202019-11-20 16:39:12 -08003014 libjniOutput := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
Jiyong Park52cd06f2019-11-11 10:14:32 +09003015 ensureListContains(t, appZipRule.Implicits.Strings(), libjniOutput.String())
3016 // ... uncompressed
3017 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
3018 t.Errorf("jni lib is not uncompressed for AppFoo")
3019 }
3020 // ... and not directly inside the APEX
3021 ensureNotContains(t, copyCmds, "image.apex/lib64/libjni.so")
Dario Frenicde2a032019-10-27 00:29:22 +01003022}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003023
Dario Frenicde2a032019-10-27 00:29:22 +01003024func TestApexWithAppImports(t *testing.T) {
3025 ctx, _ := testApex(t, `
3026 apex {
3027 name: "myapex",
3028 key: "myapex.key",
3029 apps: [
3030 "AppFooPrebuilt",
3031 "AppFooPrivPrebuilt",
3032 ],
3033 }
3034
3035 apex_key {
3036 name: "myapex.key",
3037 public_key: "testkey.avbpubkey",
3038 private_key: "testkey.pem",
3039 }
3040
3041 android_app_import {
3042 name: "AppFooPrebuilt",
3043 apk: "PrebuiltAppFoo.apk",
3044 presigned: true,
3045 dex_preopt: {
3046 enabled: false,
3047 },
3048 }
3049
3050 android_app_import {
3051 name: "AppFooPrivPrebuilt",
3052 apk: "PrebuiltAppFooPriv.apk",
3053 privileged: true,
3054 presigned: true,
3055 dex_preopt: {
3056 enabled: false,
3057 },
3058 }
3059 `)
3060
Sundong Ahnabb64432019-10-22 13:58:29 +09003061 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003062 apexRule := module.Rule("apexRule")
3063 copyCmds := apexRule.Args["copy_commands"]
3064
3065 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3066 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003067}
3068
Dario Freni6f3937c2019-12-20 22:58:03 +00003069func TestApexWithTestHelperApp(t *testing.T) {
3070 ctx, _ := testApex(t, `
3071 apex {
3072 name: "myapex",
3073 key: "myapex.key",
3074 apps: [
3075 "TesterHelpAppFoo",
3076 ],
3077 }
3078
3079 apex_key {
3080 name: "myapex.key",
3081 public_key: "testkey.avbpubkey",
3082 private_key: "testkey.pem",
3083 }
3084
3085 android_test_helper_app {
3086 name: "TesterHelpAppFoo",
3087 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003088 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003089 }
3090
3091 `)
3092
3093 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3094 apexRule := module.Rule("apexRule")
3095 copyCmds := apexRule.Args["copy_commands"]
3096
3097 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3098}
3099
Jooyung Han18020ea2019-11-13 10:50:48 +09003100func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3101 // libfoo's apex_available comes from cc_defaults
3102 testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
3103 apex {
3104 name: "myapex",
3105 key: "myapex.key",
3106 native_shared_libs: ["libfoo"],
3107 }
3108
3109 apex_key {
3110 name: "myapex.key",
3111 public_key: "testkey.avbpubkey",
3112 private_key: "testkey.pem",
3113 }
3114
3115 apex {
3116 name: "otherapex",
3117 key: "myapex.key",
3118 native_shared_libs: ["libfoo"],
3119 }
3120
3121 cc_defaults {
3122 name: "libfoo-defaults",
3123 apex_available: ["otherapex"],
3124 }
3125
3126 cc_library {
3127 name: "libfoo",
3128 defaults: ["libfoo-defaults"],
3129 stl: "none",
3130 system_shared_libs: [],
3131 }`)
3132}
3133
Jiyong Park127b40b2019-09-30 16:04:35 +09003134func TestApexAvailable(t *testing.T) {
3135 // libfoo is not available to myapex, but only to otherapex
3136 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3137 apex {
3138 name: "myapex",
3139 key: "myapex.key",
3140 native_shared_libs: ["libfoo"],
3141 }
3142
3143 apex_key {
3144 name: "myapex.key",
3145 public_key: "testkey.avbpubkey",
3146 private_key: "testkey.pem",
3147 }
3148
3149 apex {
3150 name: "otherapex",
3151 key: "otherapex.key",
3152 native_shared_libs: ["libfoo"],
3153 }
3154
3155 apex_key {
3156 name: "otherapex.key",
3157 public_key: "testkey.avbpubkey",
3158 private_key: "testkey.pem",
3159 }
3160
3161 cc_library {
3162 name: "libfoo",
3163 stl: "none",
3164 system_shared_libs: [],
3165 apex_available: ["otherapex"],
3166 }`)
3167
3168 // libbar is an indirect dep
3169 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
3170 apex {
3171 name: "myapex",
3172 key: "myapex.key",
3173 native_shared_libs: ["libfoo"],
3174 }
3175
3176 apex_key {
3177 name: "myapex.key",
3178 public_key: "testkey.avbpubkey",
3179 private_key: "testkey.pem",
3180 }
3181
3182 apex {
3183 name: "otherapex",
3184 key: "otherapex.key",
3185 native_shared_libs: ["libfoo"],
3186 }
3187
3188 apex_key {
3189 name: "otherapex.key",
3190 public_key: "testkey.avbpubkey",
3191 private_key: "testkey.pem",
3192 }
3193
3194 cc_library {
3195 name: "libfoo",
3196 stl: "none",
3197 shared_libs: ["libbar"],
3198 system_shared_libs: [],
3199 apex_available: ["myapex", "otherapex"],
3200 }
3201
3202 cc_library {
3203 name: "libbar",
3204 stl: "none",
3205 system_shared_libs: [],
3206 apex_available: ["otherapex"],
3207 }`)
3208
3209 testApexError(t, "\"otherapex\" is not a valid module name", `
3210 apex {
3211 name: "myapex",
3212 key: "myapex.key",
3213 native_shared_libs: ["libfoo"],
3214 }
3215
3216 apex_key {
3217 name: "myapex.key",
3218 public_key: "testkey.avbpubkey",
3219 private_key: "testkey.pem",
3220 }
3221
3222 cc_library {
3223 name: "libfoo",
3224 stl: "none",
3225 system_shared_libs: [],
3226 apex_available: ["otherapex"],
3227 }`)
3228
3229 ctx, _ := testApex(t, `
3230 apex {
3231 name: "myapex",
3232 key: "myapex.key",
3233 native_shared_libs: ["libfoo", "libbar"],
3234 }
3235
3236 apex_key {
3237 name: "myapex.key",
3238 public_key: "testkey.avbpubkey",
3239 private_key: "testkey.pem",
3240 }
3241
3242 cc_library {
3243 name: "libfoo",
3244 stl: "none",
3245 system_shared_libs: [],
3246 apex_available: ["myapex"],
3247 }
3248
3249 cc_library {
3250 name: "libbar",
3251 stl: "none",
3252 system_shared_libs: [],
3253 apex_available: ["//apex_available:anyapex"],
3254 }`)
3255
3256 // check that libfoo and libbar are created only for myapex, but not for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003257 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3258 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3259 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3260 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003261
3262 ctx, _ = testApex(t, `
3263 apex {
3264 name: "myapex",
3265 key: "myapex.key",
3266 }
3267
3268 apex_key {
3269 name: "myapex.key",
3270 public_key: "testkey.avbpubkey",
3271 private_key: "testkey.pem",
3272 }
3273
3274 cc_library {
3275 name: "libfoo",
3276 stl: "none",
3277 system_shared_libs: [],
3278 apex_available: ["//apex_available:platform"],
3279 }`)
3280
3281 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003282 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3283 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003284
3285 ctx, _ = testApex(t, `
3286 apex {
3287 name: "myapex",
3288 key: "myapex.key",
3289 native_shared_libs: ["libfoo"],
3290 }
3291
3292 apex_key {
3293 name: "myapex.key",
3294 public_key: "testkey.avbpubkey",
3295 private_key: "testkey.pem",
3296 }
3297
3298 cc_library {
3299 name: "libfoo",
3300 stl: "none",
3301 system_shared_libs: [],
3302 apex_available: ["myapex"],
3303 static: {
3304 apex_available: ["//apex_available:platform"],
3305 },
3306 }`)
3307
3308 // shared variant of libfoo is only available to myapex
Colin Cross7113d202019-11-20 16:39:12 -08003309 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3310 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003311 // but the static variant is available to both myapex and the platform
Colin Cross7113d202019-11-20 16:39:12 -08003312 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3313 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003314}
3315
Jiyong Park5d790c32019-11-15 18:40:32 +09003316func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003317 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003318 apex {
3319 name: "myapex",
3320 key: "myapex.key",
3321 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003322 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003323 }
3324
3325 override_apex {
3326 name: "override_myapex",
3327 base: "myapex",
3328 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003329 overrides: ["unknownapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003330 }
3331
3332 apex_key {
3333 name: "myapex.key",
3334 public_key: "testkey.avbpubkey",
3335 private_key: "testkey.pem",
3336 }
3337
3338 android_app {
3339 name: "app",
3340 srcs: ["foo/bar/MyClass.java"],
3341 package_name: "foo",
3342 sdk_version: "none",
3343 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003344 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003345 }
3346
3347 override_android_app {
3348 name: "override_app",
3349 base: "app",
3350 package_name: "bar",
3351 }
3352 `)
3353
Jiyong Park317645e2019-12-05 13:20:58 +09003354 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3355 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3356 if originalVariant.GetOverriddenBy() != "" {
3357 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3358 }
3359 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3360 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3361 }
3362
Jiyong Park5d790c32019-11-15 18:40:32 +09003363 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3364 apexRule := module.Rule("apexRule")
3365 copyCmds := apexRule.Args["copy_commands"]
3366
3367 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3368 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003369
3370 apexBundle := module.Module().(*apexBundle)
3371 name := apexBundle.Name()
3372 if name != "override_myapex" {
3373 t.Errorf("name should be \"override_myapex\", but was %q", name)
3374 }
3375
3376 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3377 var builder strings.Builder
3378 data.Custom(&builder, name, "TARGET_", "", data)
3379 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003380 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003381 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3382 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003383 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003384 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003385 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003386 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3387 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003388}
3389
Jooyung Han214bf372019-11-12 13:03:50 +09003390func TestLegacyAndroid10Support(t *testing.T) {
3391 ctx, _ := testApex(t, `
3392 apex {
3393 name: "myapex",
3394 key: "myapex.key",
3395 legacy_android10_support: true,
3396 }
3397
3398 apex_key {
3399 name: "myapex.key",
3400 public_key: "testkey.avbpubkey",
3401 private_key: "testkey.pem",
3402 }
3403 `)
3404
3405 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3406 args := module.Rule("apexRule").Args
3407 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003408 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Jooyung Han214bf372019-11-12 13:03:50 +09003409}
3410
Jooyung Han58f26ab2019-12-18 15:34:32 +09003411func TestJavaSDKLibrary(t *testing.T) {
3412 ctx, _ := testApex(t, `
3413 apex {
3414 name: "myapex",
3415 key: "myapex.key",
3416 java_libs: ["foo"],
3417 }
3418
3419 apex_key {
3420 name: "myapex.key",
3421 public_key: "testkey.avbpubkey",
3422 private_key: "testkey.pem",
3423 }
3424
3425 java_sdk_library {
3426 name: "foo",
3427 srcs: ["a.java"],
3428 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003429 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003430 }
3431 `, withFiles(map[string][]byte{
3432 "api/current.txt": nil,
3433 "api/removed.txt": nil,
3434 "api/system-current.txt": nil,
3435 "api/system-removed.txt": nil,
3436 "api/test-current.txt": nil,
3437 "api/test-removed.txt": nil,
3438 }))
3439
3440 // java_sdk_library installs both impl jar and permission XML
3441 ensureExactContents(t, ctx, "myapex", []string{
3442 "javalib/foo.jar",
3443 "etc/permissions/foo.xml",
3444 })
3445 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jooyung Han624058e2019-12-24 18:38:06 +09003446 xml := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml")
3447 ensureContains(t, xml.Args["content"], `<library name="foo" file="/apex/myapex/javalib/foo.jar"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003448}
3449
Jiyong Park479321d2019-12-16 11:47:12 +09003450func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3451 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3452 apex {
3453 name: "myapex",
3454 key: "myapex.key",
3455 java_libs: ["myjar"],
3456 }
3457
3458 apex_key {
3459 name: "myapex.key",
3460 public_key: "testkey.avbpubkey",
3461 private_key: "testkey.pem",
3462 }
3463
3464 java_library {
3465 name: "myjar",
3466 srcs: ["foo/bar/MyClass.java"],
3467 sdk_version: "none",
3468 system_modules: "none",
3469 }
3470 `)
3471}
3472
Jiyong Park7afd1072019-12-30 16:56:33 +09003473func TestCarryRequiredModuleNames(t *testing.T) {
3474 ctx, config := testApex(t, `
3475 apex {
3476 name: "myapex",
3477 key: "myapex.key",
3478 native_shared_libs: ["mylib"],
3479 }
3480
3481 apex_key {
3482 name: "myapex.key",
3483 public_key: "testkey.avbpubkey",
3484 private_key: "testkey.pem",
3485 }
3486
3487 cc_library {
3488 name: "mylib",
3489 srcs: ["mylib.cpp"],
3490 system_shared_libs: [],
3491 stl: "none",
3492 required: ["a", "b"],
3493 host_required: ["c", "d"],
3494 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003495 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003496 }
3497 `)
3498
3499 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3500 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3501 name := apexBundle.BaseModuleName()
3502 prefix := "TARGET_"
3503 var builder strings.Builder
3504 data.Custom(&builder, name, prefix, "", data)
3505 androidMk := builder.String()
3506 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3507 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3508 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3509}
3510
Jiyong Park7cd10e32020-01-14 09:22:18 +09003511func TestSymlinksFromApexToSystem(t *testing.T) {
3512 bp := `
3513 apex {
3514 name: "myapex",
3515 key: "myapex.key",
3516 native_shared_libs: ["mylib"],
3517 java_libs: ["myjar"],
3518 }
3519
3520 apex_key {
3521 name: "myapex.key",
3522 public_key: "testkey.avbpubkey",
3523 private_key: "testkey.pem",
3524 }
3525
3526 cc_library {
3527 name: "mylib",
3528 srcs: ["mylib.cpp"],
3529 shared_libs: ["myotherlib"],
3530 system_shared_libs: [],
3531 stl: "none",
3532 apex_available: [
3533 "myapex",
3534 "//apex_available:platform",
3535 ],
3536 }
3537
3538 cc_library {
3539 name: "myotherlib",
3540 srcs: ["mylib.cpp"],
3541 system_shared_libs: [],
3542 stl: "none",
3543 apex_available: [
3544 "myapex",
3545 "//apex_available:platform",
3546 ],
3547 }
3548
3549 java_library {
3550 name: "myjar",
3551 srcs: ["foo/bar/MyClass.java"],
3552 sdk_version: "none",
3553 system_modules: "none",
3554 libs: ["myotherjar"],
3555 compile_dex: true,
3556 apex_available: [
3557 "myapex",
3558 "//apex_available:platform",
3559 ],
3560 }
3561
3562 java_library {
3563 name: "myotherjar",
3564 srcs: ["foo/bar/MyClass.java"],
3565 sdk_version: "none",
3566 system_modules: "none",
3567 apex_available: [
3568 "myapex",
3569 "//apex_available:platform",
3570 ],
3571 }
3572 `
3573
3574 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3575 for _, f := range files {
3576 if f.path == file {
3577 if f.isLink {
3578 t.Errorf("%q is not a real file", file)
3579 }
3580 return
3581 }
3582 }
3583 t.Errorf("%q is not found", file)
3584 }
3585
3586 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3587 for _, f := range files {
3588 if f.path == file {
3589 if !f.isLink {
3590 t.Errorf("%q is not a symlink", file)
3591 }
3592 return
3593 }
3594 }
3595 t.Errorf("%q is not found", file)
3596 }
3597
3598 ctx, _ := testApex(t, bp, withUnbundledBuild)
3599 files := getFiles(t, ctx, "myapex")
3600 ensureRealfileExists(t, files, "javalib/myjar.jar")
3601 ensureRealfileExists(t, files, "lib64/mylib.so")
3602 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3603
3604 ctx, _ = testApex(t, bp)
3605 files = getFiles(t, ctx, "myapex")
3606 ensureRealfileExists(t, files, "javalib/myjar.jar")
3607 ensureRealfileExists(t, files, "lib64/mylib.so")
3608 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
3609}
3610
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07003611func TestMain(m *testing.M) {
3612 run := func() int {
3613 setUp()
3614 defer tearDown()
3615
3616 return m.Run()
3617 }
3618
3619 os.Exit(run())
3620}