blob: b6904c62e6861ad34fab27adbb7dc0124b23e0fb [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"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070020 "reflect"
Jiyong Park25fc6a92018-11-18 18:02:45 +090021 "strings"
22 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090023
24 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090028 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090029)
30
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070031var buildDir string
32
Jooyung Hand3639552019-08-09 12:57:43 +090033// names returns name list from white space separated string
34func names(s string) (ns []string) {
35 for _, n := range strings.Split(s, " ") {
36 if len(n) > 0 {
37 ns = append(ns, n)
38 }
39 }
40 return
41}
42
Jooyung Han344d5432019-08-23 11:17:39 +090043func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
44 t.Helper()
45 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090046 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
47 if len(errs) > 0 {
48 android.FailIfNoMatchingErrors(t, pattern, errs)
49 return
50 }
51 _, errs = ctx.PrepareBuildActions(config)
52 if len(errs) > 0 {
53 android.FailIfNoMatchingErrors(t, pattern, errs)
54 return
55 }
56
57 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
58}
59
Jooyung Han344d5432019-08-23 11:17:39 +090060func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
61 t.Helper()
62 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090063 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
64 android.FailIfErrored(t, errs)
65 _, errs = ctx.PrepareBuildActions(config)
66 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070067 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090068}
69
Jooyung Han344d5432019-08-23 11:17:39 +090070type testCustomizer func(fs map[string][]byte, config android.Config)
71
72func withFiles(files map[string][]byte) testCustomizer {
73 return func(fs map[string][]byte, config android.Config) {
74 for k, v := range files {
75 fs[k] = v
76 }
77 }
78}
79
80func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
81 return func(fs map[string][]byte, config android.Config) {
82 for k, v := range targets {
83 config.Targets[k] = v
84 }
85 }
86}
87
88func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070089 config := android.TestArchConfig(buildDir, nil)
90 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
91 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
92 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
93 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
94 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jooyung Han344d5432019-08-23 11:17:39 +090095 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Jiyong Park25fc6a92018-11-18 18:02:45 +090096
97 ctx := android.NewTestArchContext()
Jiyong Parkd1063c12019-07-17 20:08:41 +090098 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(BundleFactory))
Alex Light0851b882019-02-07 13:20:53 -080099 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900100 ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory))
Jiyong Parkd1063c12019-07-17 20:08:41 +0900101 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(ApexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +0900102 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700103 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900104
Jooyung Hancc372c52019-09-25 15:18:44 +0900105 ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(func() android.Module {
106 return cc.DefaultsFactory()
107 }))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900108 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
109 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900110 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900111 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
112 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900113 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900114 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100115 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900116 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900117 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900118 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900119 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900120 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900121 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900122 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900123 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900124 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900125 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900126
Jooyung Han344d5432019-08-23 11:17:39 +0900127 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700128 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
129 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
130 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900131 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900132 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900134 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100135 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900136 ctx.BottomUp("version", cc.VersionMutator).Parallel()
137 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900138 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator)
139 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator)
140 })
141 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
142 ctx.TopDown("apex_deps", apexDepsMutator)
143 ctx.BottomUp("apex", apexMutator)
144 ctx.BottomUp("apex_uses", apexUsesMutator)
145 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
146 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900147 })
148
149 ctx.Register()
150
151 bp = bp + `
152 toolchain_library {
153 name: "libcompiler_rt-extras",
154 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900155 vendor_available: true,
156 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900157 }
158
159 toolchain_library {
160 name: "libatomic",
161 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900162 vendor_available: true,
163 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900164 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900165 }
166
167 toolchain_library {
168 name: "libgcc",
169 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900170 vendor_available: true,
171 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900172 }
173
174 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700175 name: "libgcc_stripped",
176 src: "",
177 vendor_available: true,
178 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900179 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700180 }
181
182 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900183 name: "libclang_rt.builtins-aarch64-android",
184 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900185 vendor_available: true,
186 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900187 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900188 }
189
190 toolchain_library {
191 name: "libclang_rt.builtins-arm-android",
192 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900193 vendor_available: true,
194 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900195 native_bridge_supported: true,
196 }
197
198 toolchain_library {
199 name: "libclang_rt.builtins-x86_64-android",
200 src: "",
201 vendor_available: true,
202 recovery_available: true,
203 native_bridge_supported: true,
204 }
205
206 toolchain_library {
207 name: "libclang_rt.builtins-i686-android",
208 src: "",
209 vendor_available: true,
210 recovery_available: true,
211 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900212 }
213
214 cc_object {
215 name: "crtbegin_so",
216 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900217 vendor_available: true,
218 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900219 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900220 }
221
222 cc_object {
223 name: "crtend_so",
224 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900225 vendor_available: true,
226 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900227 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900228 }
229
Alex Light3d673592019-01-18 14:37:31 -0800230 cc_object {
231 name: "crtbegin_static",
232 stl: "none",
233 }
234
235 cc_object {
236 name: "crtend_android",
237 stl: "none",
238 }
239
Jiyong Parkda6eb592018-12-19 17:12:36 +0900240 llndk_library {
241 name: "libc",
242 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900243 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900244 }
245
246 llndk_library {
247 name: "libm",
248 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900249 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900250 }
251
252 llndk_library {
253 name: "libdl",
254 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900255 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900256 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900257 `
258
Jooyung Han344d5432019-08-23 11:17:39 +0900259 fs := map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900260 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700261 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900262 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900263 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900264 "system/sepolicy/apex/myapex-file_contexts": nil,
265 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
266 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900267 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900268 "mylib.cpp": nil,
269 "mylib_common.cpp": nil,
270 "mytest.cpp": nil,
271 "mytest1.cpp": nil,
272 "mytest2.cpp": nil,
273 "mytest3.cpp": nil,
274 "myprebuilt": nil,
275 "my_include": nil,
276 "foo/bar/MyClass.java": nil,
277 "prebuilt.jar": nil,
278 "vendor/foo/devkeys/test.x509.pem": nil,
279 "vendor/foo/devkeys/test.pk8": nil,
280 "testkey.x509.pem": nil,
281 "testkey.pk8": nil,
282 "testkey.override.x509.pem": nil,
283 "testkey.override.pk8": nil,
284 "vendor/foo/devkeys/testkey.avbpubkey": nil,
285 "vendor/foo/devkeys/testkey.pem": nil,
286 "NOTICE": nil,
287 "custom_notice": nil,
288 "testkey2.avbpubkey": nil,
289 "testkey2.pem": nil,
290 "myapex-arm64.apex": nil,
291 "myapex-arm.apex": nil,
292 "frameworks/base/api/current.txt": nil,
293 "build/make/core/proguard.flags": nil,
294 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900295 }
296
297 for _, handler := range handlers {
298 handler(fs, config)
299 }
300
301 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900302
Jooyung Han5c998b92019-06-27 11:30:33 +0900303 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900304}
305
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700306func setUp() {
307 var err error
308 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900309 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700310 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900311 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900312}
313
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700314func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315 os.RemoveAll(buildDir)
316}
317
318// ensure that 'result' contains 'expected'
319func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900320 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900321 if !strings.Contains(result, expected) {
322 t.Errorf("%q is not found in %q", expected, result)
323 }
324}
325
326// ensures that 'result' does not contain 'notExpected'
327func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900328 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900329 if strings.Contains(result, notExpected) {
330 t.Errorf("%q is found in %q", notExpected, result)
331 }
332}
333
334func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900335 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900336 if !android.InList(expected, result) {
337 t.Errorf("%q is not found in %v", expected, result)
338 }
339}
340
341func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900342 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900343 if android.InList(notExpected, result) {
344 t.Errorf("%q is found in %v", notExpected, result)
345 }
346}
347
Jooyung Hane1633032019-08-01 17:41:43 +0900348func ensureListEmpty(t *testing.T, result []string) {
349 t.Helper()
350 if len(result) > 0 {
351 t.Errorf("%q is expected to be empty", result)
352 }
353}
354
Jiyong Park25fc6a92018-11-18 18:02:45 +0900355// Minimal test
356func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700357 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900358 apex_defaults {
359 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900360 manifest: ":myapex.manifest",
361 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900362 key: "myapex.key",
363 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800364 multilib: {
365 both: {
366 binaries: ["foo",],
367 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900368 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900369 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900370 }
371
Jiyong Park30ca9372019-02-07 16:27:23 +0900372 apex {
373 name: "myapex",
374 defaults: ["myapex-defaults"],
375 }
376
Jiyong Park25fc6a92018-11-18 18:02:45 +0900377 apex_key {
378 name: "myapex.key",
379 public_key: "testkey.avbpubkey",
380 private_key: "testkey.pem",
381 }
382
Jiyong Park809bb722019-02-13 21:33:49 +0900383 filegroup {
384 name: "myapex.manifest",
385 srcs: ["apex_manifest.json"],
386 }
387
388 filegroup {
389 name: "myapex.androidmanifest",
390 srcs: ["AndroidManifest.xml"],
391 }
392
Jiyong Park25fc6a92018-11-18 18:02:45 +0900393 cc_library {
394 name: "mylib",
395 srcs: ["mylib.cpp"],
396 shared_libs: ["mylib2"],
397 system_shared_libs: [],
398 stl: "none",
399 }
400
Alex Light3d673592019-01-18 14:37:31 -0800401 cc_binary {
402 name: "foo",
403 srcs: ["mylib.cpp"],
404 compile_multilib: "both",
405 multilib: {
406 lib32: {
407 suffix: "32",
408 },
409 lib64: {
410 suffix: "64",
411 },
412 },
413 symlinks: ["foo_link_"],
414 symlink_preferred_arch: true,
415 system_shared_libs: [],
416 static_executable: true,
417 stl: "none",
418 }
419
Jiyong Park25fc6a92018-11-18 18:02:45 +0900420 cc_library {
421 name: "mylib2",
422 srcs: ["mylib.cpp"],
423 system_shared_libs: [],
424 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900425 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900426 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900427
428 java_library {
429 name: "myjar",
430 srcs: ["foo/bar/MyClass.java"],
431 sdk_version: "none",
432 system_modules: "none",
433 compile_dex: true,
434 static_libs: ["myotherjar"],
435 }
436
437 java_library {
438 name: "myotherjar",
439 srcs: ["foo/bar/MyClass.java"],
440 sdk_version: "none",
441 system_modules: "none",
442 compile_dex: true,
443 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900444
445 java_import {
446 name: "myprebuiltjar",
447 jars: ["prebuilt.jar"],
448 installable: true,
449 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900450 `)
451
452 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900453
454 optFlags := apexRule.Args["opt_flags"]
455 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700456 // Ensure that the NOTICE output is being packaged as an asset.
457 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900458
Jiyong Park25fc6a92018-11-18 18:02:45 +0900459 copyCmds := apexRule.Args["copy_commands"]
460
461 // Ensure that main rule creates an output
462 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
463
464 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900465 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900466 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900467 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900468
469 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900470 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900471 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900472
473 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800474 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
475 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900476 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900477 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900478 // .. but not for java libs
479 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800480
Jiyong Park7f7766d2019-07-25 22:02:35 +0900481 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800482 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
483 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900484 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
485 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900486 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800487
488 // Ensure that all symlinks are present.
489 found_foo_link_64 := false
490 found_foo := false
491 for _, cmd := range strings.Split(copyCmds, " && ") {
492 if strings.HasPrefix(cmd, "ln -s foo64") {
493 if strings.HasSuffix(cmd, "bin/foo") {
494 found_foo = true
495 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
496 found_foo_link_64 = true
497 }
498 }
499 }
500 good := found_foo && found_foo_link_64
501 if !good {
502 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
503 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900504
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700505 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
506 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700507 if len(noticeInputs) != 2 {
508 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900509 }
510 ensureListContains(t, noticeInputs, "NOTICE")
511 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800512}
513
514func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700515 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800516 apex {
517 name: "myapex",
518 key: "myapex.key",
519 payload_type: "zip",
520 native_shared_libs: ["mylib"],
521 }
522
523 apex_key {
524 name: "myapex.key",
525 public_key: "testkey.avbpubkey",
526 private_key: "testkey.pem",
527 }
528
529 cc_library {
530 name: "mylib",
531 srcs: ["mylib.cpp"],
532 shared_libs: ["mylib2"],
533 system_shared_libs: [],
534 stl: "none",
535 }
536
537 cc_library {
538 name: "mylib2",
539 srcs: ["mylib.cpp"],
540 system_shared_libs: [],
541 stl: "none",
542 }
543 `)
544
545 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
546 copyCmds := zipApexRule.Args["copy_commands"]
547
548 // Ensure that main rule creates an output
549 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
550
551 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900552 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800553
554 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900555 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800556
557 // Ensure that both direct and indirect deps are copied into apex
558 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
559 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900560}
561
562func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700563 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900564 apex {
565 name: "myapex",
566 key: "myapex.key",
567 native_shared_libs: ["mylib", "mylib3"],
568 }
569
570 apex_key {
571 name: "myapex.key",
572 public_key: "testkey.avbpubkey",
573 private_key: "testkey.pem",
574 }
575
576 cc_library {
577 name: "mylib",
578 srcs: ["mylib.cpp"],
579 shared_libs: ["mylib2", "mylib3"],
580 system_shared_libs: [],
581 stl: "none",
582 }
583
584 cc_library {
585 name: "mylib2",
586 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900587 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900588 system_shared_libs: [],
589 stl: "none",
590 stubs: {
591 versions: ["1", "2", "3"],
592 },
593 }
594
595 cc_library {
596 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900597 srcs: ["mylib.cpp"],
598 shared_libs: ["mylib4"],
599 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900600 stl: "none",
601 stubs: {
602 versions: ["10", "11", "12"],
603 },
604 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900605
606 cc_library {
607 name: "mylib4",
608 srcs: ["mylib.cpp"],
609 system_shared_libs: [],
610 stl: "none",
611 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900612 `)
613
614 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
615 copyCmds := apexRule.Args["copy_commands"]
616
617 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800618 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900619
620 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800621 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900622
623 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800624 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900625
Jiyong Parkda6eb592018-12-19 17:12:36 +0900626 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900627
628 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900629 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900630 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900631 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900632
633 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900634 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900635 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900636 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900637
638 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900639 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900640 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900641
642 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900643 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"])
Jiyong Park25fc6a92018-11-18 18:02:45 +0900644}
645
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900646func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700647 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900648 apex {
649 name: "myapex",
650 key: "myapex.key",
651 native_shared_libs: ["mylib"],
652 }
653
654 apex_key {
655 name: "myapex.key",
656 public_key: "testkey.avbpubkey",
657 private_key: "testkey.pem",
658 }
659
660 cc_library {
661 name: "mylib",
662 srcs: ["mylib.cpp"],
663 shared_libs: ["libfoo#10"],
664 system_shared_libs: [],
665 stl: "none",
666 }
667
668 cc_library {
669 name: "libfoo",
670 srcs: ["mylib.cpp"],
671 shared_libs: ["libbar"],
672 system_shared_libs: [],
673 stl: "none",
674 stubs: {
675 versions: ["10", "20", "30"],
676 },
677 }
678
679 cc_library {
680 name: "libbar",
681 srcs: ["mylib.cpp"],
682 system_shared_libs: [],
683 stl: "none",
684 }
685
686 `)
687
688 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
689 copyCmds := apexRule.Args["copy_commands"]
690
691 // Ensure that direct non-stubs dep is always included
692 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
693
694 // Ensure that indirect stubs dep is not included
695 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
696
697 // Ensure that dependency of stubs is not included
698 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
699
Jiyong Parkda6eb592018-12-19 17:12:36 +0900700 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900701
702 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900703 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900704 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900705 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900706
Jiyong Parkda6eb592018-12-19 17:12:36 +0900707 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900708
709 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
710 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
711}
712
Jooyung Hand3639552019-08-09 12:57:43 +0900713func TestApexWithRuntimeLibsDependency(t *testing.T) {
714 /*
715 myapex
716 |
717 v (runtime_libs)
718 mylib ------+------> libfoo [provides stub]
719 |
720 `------> libbar
721 */
722 ctx, _ := testApex(t, `
723 apex {
724 name: "myapex",
725 key: "myapex.key",
726 native_shared_libs: ["mylib"],
727 }
728
729 apex_key {
730 name: "myapex.key",
731 public_key: "testkey.avbpubkey",
732 private_key: "testkey.pem",
733 }
734
735 cc_library {
736 name: "mylib",
737 srcs: ["mylib.cpp"],
738 runtime_libs: ["libfoo", "libbar"],
739 system_shared_libs: [],
740 stl: "none",
741 }
742
743 cc_library {
744 name: "libfoo",
745 srcs: ["mylib.cpp"],
746 system_shared_libs: [],
747 stl: "none",
748 stubs: {
749 versions: ["10", "20", "30"],
750 },
751 }
752
753 cc_library {
754 name: "libbar",
755 srcs: ["mylib.cpp"],
756 system_shared_libs: [],
757 stl: "none",
758 }
759
760 `)
761
762 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
763 copyCmds := apexRule.Args["copy_commands"]
764
765 // Ensure that direct non-stubs dep is always included
766 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
767
768 // Ensure that indirect stubs dep is not included
769 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
770
771 // Ensure that runtime_libs dep in included
772 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
773
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900774 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
775 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
776 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900777
778}
779
Jooyung Han9c80bae2019-08-20 17:30:57 +0900780func TestApexDependencyToLLNDK(t *testing.T) {
781 ctx, _ := testApex(t, `
782 apex {
783 name: "myapex",
784 key: "myapex.key",
785 use_vendor: true,
786 native_shared_libs: ["mylib"],
787 }
788
789 apex_key {
790 name: "myapex.key",
791 public_key: "testkey.avbpubkey",
792 private_key: "testkey.pem",
793 }
794
795 cc_library {
796 name: "mylib",
797 srcs: ["mylib.cpp"],
798 vendor_available: true,
799 shared_libs: ["libbar"],
800 system_shared_libs: [],
801 stl: "none",
802 }
803
804 cc_library {
805 name: "libbar",
806 srcs: ["mylib.cpp"],
807 system_shared_libs: [],
808 stl: "none",
809 }
810
811 llndk_library {
812 name: "libbar",
813 symbol_file: "",
814 }
815
816 `)
817
818 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
819 copyCmds := apexRule.Args["copy_commands"]
820
821 // Ensure that LLNDK dep is not included
822 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
823
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900824 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
825 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900826
827 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900828 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900829
830}
831
Jiyong Park25fc6a92018-11-18 18:02:45 +0900832func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700833 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900834 apex {
835 name: "myapex",
836 key: "myapex.key",
837 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
838 }
839
840 apex_key {
841 name: "myapex.key",
842 public_key: "testkey.avbpubkey",
843 private_key: "testkey.pem",
844 }
845
846 cc_library {
847 name: "mylib",
848 srcs: ["mylib.cpp"],
849 shared_libs: ["libdl#27"],
850 stl: "none",
851 }
852
853 cc_library_shared {
854 name: "mylib_shared",
855 srcs: ["mylib.cpp"],
856 shared_libs: ["libdl#27"],
857 stl: "none",
858 }
859
860 cc_library {
861 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700862 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900863 nocrt: true,
864 system_shared_libs: [],
865 stl: "none",
866 stubs: {
867 versions: ["27", "28", "29"],
868 },
869 }
870
871 cc_library {
872 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700873 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900874 nocrt: true,
875 system_shared_libs: [],
876 stl: "none",
877 stubs: {
878 versions: ["27", "28", "29"],
879 },
880 }
881
882 cc_library {
883 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700884 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900885 nocrt: true,
886 system_shared_libs: [],
887 stl: "none",
888 stubs: {
889 versions: ["27", "28", "29"],
890 },
891 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900892
893 cc_library {
894 name: "libBootstrap",
895 srcs: ["mylib.cpp"],
896 stl: "none",
897 bootstrap: true,
898 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900899 `)
900
901 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
902 copyCmds := apexRule.Args["copy_commands"]
903
904 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800905 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900906 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
907 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900908
909 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900910 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900911
Jiyong Parkda6eb592018-12-19 17:12:36 +0900912 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
913 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
914 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900915
916 // For dependency to libc
917 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900918 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900919 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900920 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900921 // ... Cflags from stub is correctly exported to mylib
922 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
923 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
924
925 // For dependency to libm
926 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900927 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900928 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900929 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900930 // ... and is not compiling with the stub
931 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
932 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
933
934 // For dependency to libdl
935 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900936 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900938 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
939 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900940 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900941 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900942 // ... Cflags from stub is correctly exported to mylib
943 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
944 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900945
946 // Ensure that libBootstrap is depending on the platform variant of bionic libs
947 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
948 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
949 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
950 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900951}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900952
953func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700954 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900955 apex {
956 name: "myapex",
957 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900958 native_shared_libs: ["mylib"],
959 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900960 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900961 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900962 }
963
964 apex_key {
965 name: "myapex.key",
966 public_key: "testkey.avbpubkey",
967 private_key: "testkey.pem",
968 }
969
970 prebuilt_etc {
971 name: "myetc",
972 src: "myprebuilt",
973 sub_dir: "foo/bar",
974 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900975
976 cc_library {
977 name: "mylib",
978 srcs: ["mylib.cpp"],
979 relative_install_path: "foo/bar",
980 system_shared_libs: [],
981 stl: "none",
982 }
983
984 cc_binary {
985 name: "mybin",
986 srcs: ["mylib.cpp"],
987 relative_install_path: "foo/bar",
988 system_shared_libs: [],
989 static_executable: true,
990 stl: "none",
991 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900992 `)
993
994 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
995 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
996
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900997 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900998 ensureListContains(t, dirs, "etc")
999 ensureListContains(t, dirs, "etc/foo")
1000 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001001 ensureListContains(t, dirs, "lib64")
1002 ensureListContains(t, dirs, "lib64/foo")
1003 ensureListContains(t, dirs, "lib64/foo/bar")
1004 ensureListContains(t, dirs, "lib")
1005 ensureListContains(t, dirs, "lib/foo")
1006 ensureListContains(t, dirs, "lib/foo/bar")
1007
Jiyong Parkbd13e442019-03-15 18:10:35 +09001008 ensureListContains(t, dirs, "bin")
1009 ensureListContains(t, dirs, "bin/foo")
1010 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001011}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001012
1013func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001014 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001015 apex {
1016 name: "myapex",
1017 key: "myapex.key",
1018 native_shared_libs: ["mylib"],
1019 use_vendor: true,
1020 }
1021
1022 apex_key {
1023 name: "myapex.key",
1024 public_key: "testkey.avbpubkey",
1025 private_key: "testkey.pem",
1026 }
1027
1028 cc_library {
1029 name: "mylib",
1030 srcs: ["mylib.cpp"],
1031 shared_libs: ["mylib2"],
1032 system_shared_libs: [],
1033 vendor_available: true,
1034 stl: "none",
1035 }
1036
1037 cc_library {
1038 name: "mylib2",
1039 srcs: ["mylib.cpp"],
1040 system_shared_libs: [],
1041 vendor_available: true,
1042 stl: "none",
1043 }
1044 `)
1045
1046 inputsList := []string{}
1047 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
1048 for _, implicit := range i.Implicits {
1049 inputsList = append(inputsList, implicit.String())
1050 }
1051 }
1052 inputsString := strings.Join(inputsList, " ")
1053
1054 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001055 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1056 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001057
1058 // ensure that the apex does not include core variants
1059 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1060 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1061}
Jiyong Park16e91a02018-12-20 18:18:08 +09001062
Jooyung Han5c998b92019-06-27 11:30:33 +09001063func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1064 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1065 apex {
1066 name: "myapex",
1067 key: "myapex.key",
1068 native_shared_libs: ["mylib"],
1069 use_vendor: true,
1070 }
1071
1072 apex_key {
1073 name: "myapex.key",
1074 public_key: "testkey.avbpubkey",
1075 private_key: "testkey.pem",
1076 }
1077
1078 cc_library {
1079 name: "mylib",
1080 srcs: ["mylib.cpp"],
1081 system_shared_libs: [],
1082 stl: "none",
1083 }
1084 `)
1085}
1086
Jiyong Park16e91a02018-12-20 18:18:08 +09001087func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001088 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001089 apex {
1090 name: "myapex",
1091 key: "myapex.key",
1092 native_shared_libs: ["mylib"],
1093 }
1094
1095 apex_key {
1096 name: "myapex.key",
1097 public_key: "testkey.avbpubkey",
1098 private_key: "testkey.pem",
1099 }
1100
1101 cc_library {
1102 name: "mylib",
1103 srcs: ["mylib.cpp"],
1104 system_shared_libs: [],
1105 stl: "none",
1106 stubs: {
1107 versions: ["1", "2", "3"],
1108 },
1109 }
1110
1111 cc_binary {
1112 name: "not_in_apex",
1113 srcs: ["mylib.cpp"],
1114 static_libs: ["mylib"],
1115 static_executable: true,
1116 system_shared_libs: [],
1117 stl: "none",
1118 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001119 `)
1120
1121 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1122
1123 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001124 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001125}
Jiyong Park9335a262018-12-24 11:31:58 +09001126
1127func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001128 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001129 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001130 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001131 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001132 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001133 native_shared_libs: ["mylib"],
1134 }
1135
1136 cc_library {
1137 name: "mylib",
1138 srcs: ["mylib.cpp"],
1139 system_shared_libs: [],
1140 stl: "none",
1141 }
1142
1143 apex_key {
1144 name: "myapex.key",
1145 public_key: "testkey.avbpubkey",
1146 private_key: "testkey.pem",
1147 }
1148
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001149 android_app_certificate {
1150 name: "myapex.certificate",
1151 certificate: "testkey",
1152 }
1153
1154 android_app_certificate {
1155 name: "myapex.certificate.override",
1156 certificate: "testkey.override",
1157 }
1158
Jiyong Park9335a262018-12-24 11:31:58 +09001159 `)
1160
1161 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001162 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001163
1164 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1165 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1166 "vendor/foo/devkeys/testkey.avbpubkey")
1167 }
1168 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1169 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1170 "vendor/foo/devkeys/testkey.pem")
1171 }
1172
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001173 // check the APK certs. It should be overridden to myapex.certificate.override
1174 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
1175 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001176 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001177 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001178 }
1179}
Jiyong Park58e364a2019-01-19 19:24:06 +09001180
1181func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001182 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001183 apex {
1184 name: "myapex",
1185 key: "myapex.key",
1186 native_shared_libs: ["mylib"],
1187 }
1188
1189 apex {
1190 name: "otherapex",
1191 key: "myapex.key",
1192 native_shared_libs: ["mylib"],
1193 }
1194
1195 apex_key {
1196 name: "myapex.key",
1197 public_key: "testkey.avbpubkey",
1198 private_key: "testkey.pem",
1199 }
1200
1201 cc_library {
1202 name: "mylib",
1203 srcs: ["mylib.cpp"],
1204 system_shared_libs: [],
1205 stl: "none",
1206 }
1207 `)
1208
1209 // non-APEX variant does not have __ANDROID__APEX__ defined
1210 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1211 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1212 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1213
1214 // APEX variant has __ANDROID_APEX__=<apexname> defined
1215 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1216 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1217 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1218
1219 // APEX variant has __ANDROID_APEX__=<apexname> defined
1220 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1221 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1222 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1223}
Jiyong Park7e636d02019-01-28 16:16:54 +09001224
1225func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001226 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001227 apex {
1228 name: "myapex",
1229 key: "myapex.key",
1230 native_shared_libs: ["mylib"],
1231 }
1232
1233 apex_key {
1234 name: "myapex.key",
1235 public_key: "testkey.avbpubkey",
1236 private_key: "testkey.pem",
1237 }
1238
1239 cc_library_headers {
1240 name: "mylib_headers",
1241 export_include_dirs: ["my_include"],
1242 system_shared_libs: [],
1243 stl: "none",
1244 }
1245
1246 cc_library {
1247 name: "mylib",
1248 srcs: ["mylib.cpp"],
1249 system_shared_libs: [],
1250 stl: "none",
1251 header_libs: ["mylib_headers"],
1252 export_header_lib_headers: ["mylib_headers"],
1253 stubs: {
1254 versions: ["1", "2", "3"],
1255 },
1256 }
1257
1258 cc_library {
1259 name: "otherlib",
1260 srcs: ["mylib.cpp"],
1261 system_shared_libs: [],
1262 stl: "none",
1263 shared_libs: ["mylib"],
1264 }
1265 `)
1266
1267 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1268
1269 // Ensure that the include path of the header lib is exported to 'otherlib'
1270 ensureContains(t, cFlags, "-Imy_include")
1271}
Alex Light9670d332019-01-29 18:07:33 -08001272
Jooyung Han344d5432019-08-23 11:17:39 +09001273func TestVndkApexCurrent(t *testing.T) {
1274 ctx, _ := testApex(t, `
1275 apex_vndk {
1276 name: "myapex",
1277 key: "myapex.key",
1278 file_contexts: "myapex",
1279 }
1280
1281 apex_key {
1282 name: "myapex.key",
1283 public_key: "testkey.avbpubkey",
1284 private_key: "testkey.pem",
1285 }
1286
1287 cc_library {
1288 name: "libvndk",
1289 srcs: ["mylib.cpp"],
1290 vendor_available: true,
1291 vndk: {
1292 enabled: true,
1293 },
1294 system_shared_libs: [],
1295 stl: "none",
1296 }
1297
1298 cc_library {
1299 name: "libvndksp",
1300 srcs: ["mylib.cpp"],
1301 vendor_available: true,
1302 vndk: {
1303 enabled: true,
1304 support_system_process: true,
1305 },
1306 system_shared_libs: [],
1307 stl: "none",
1308 }
1309 `)
1310
1311 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1312 copyCmds := apexRule.Args["copy_commands"]
1313 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1314 ensureContains(t, copyCmds, "image.apex/lib/libvndksp.so")
1315 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1316 ensureContains(t, copyCmds, "image.apex/lib64/libvndksp.so")
1317}
1318
1319func TestVndkApexWithPrebuilt(t *testing.T) {
1320 ctx, _ := testApex(t, `
1321 apex_vndk {
1322 name: "myapex",
1323 key: "myapex.key",
1324 file_contexts: "myapex",
1325 }
1326
1327 apex_key {
1328 name: "myapex.key",
1329 public_key: "testkey.avbpubkey",
1330 private_key: "testkey.pem",
1331 }
1332
1333 cc_prebuilt_library_shared {
1334 name: "libvndkshared",
1335 srcs: ["libvndkshared.so"],
1336 vendor_available: true,
1337 vndk: {
1338 enabled: true,
1339 },
1340 system_shared_libs: [],
1341 stl: "none",
1342 }
1343 `, withFiles(map[string][]byte{
1344 "libvndkshared.so": nil,
1345 }))
1346
1347 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1348 copyCmds := apexRule.Args["copy_commands"]
1349 ensureContains(t, copyCmds, "image.apex/lib/libvndkshared.so")
1350}
1351
1352func TestVndkApexVersion(t *testing.T) {
1353 ctx, _ := testApex(t, `
1354 apex_vndk {
1355 name: "myapex_v27",
1356 key: "myapex.key",
1357 file_contexts: "myapex",
1358 vndk_version: "27",
1359 }
1360
1361 apex_key {
1362 name: "myapex.key",
1363 public_key: "testkey.avbpubkey",
1364 private_key: "testkey.pem",
1365 }
1366
1367 cc_library {
1368 name: "libvndk",
1369 srcs: ["mylib.cpp"],
1370 vendor_available: true,
1371 vndk: {
1372 enabled: true,
1373 },
1374 system_shared_libs: [],
1375 stl: "none",
1376 }
1377
1378 vndk_prebuilt_shared {
1379 name: "libvndk27",
1380 version: "27",
1381 vendor_available: true,
1382 vndk: {
1383 enabled: true,
1384 },
1385 srcs: ["libvndk27.so"],
1386 }
1387 `, withFiles(map[string][]byte{
1388 "libvndk27.so": nil,
1389 }))
1390
1391 apexRule := ctx.ModuleForTests("myapex_v27", "android_common_myapex_v27").Rule("apexRule")
1392 copyCmds := apexRule.Args["copy_commands"]
1393 ensureContains(t, copyCmds, "image.apex/lib/libvndk27.so")
1394 ensureContains(t, copyCmds, "image.apex/lib64/libvndk27.so")
1395 ensureNotContains(t, copyCmds, "image.apex/lib/libvndk.so")
1396}
1397
1398func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1399 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1400 apex_vndk {
1401 name: "myapex_v27",
1402 key: "myapex.key",
1403 file_contexts: "myapex",
1404 vndk_version: "27",
1405 }
1406 apex_vndk {
1407 name: "myapex_v27_other",
1408 key: "myapex.key",
1409 file_contexts: "myapex",
1410 vndk_version: "27",
1411 }
1412
1413 apex_key {
1414 name: "myapex.key",
1415 public_key: "testkey.avbpubkey",
1416 private_key: "testkey.pem",
1417 }
1418
1419 cc_library {
1420 name: "libvndk",
1421 srcs: ["mylib.cpp"],
1422 vendor_available: true,
1423 vndk: {
1424 enabled: true,
1425 },
1426 system_shared_libs: [],
1427 stl: "none",
1428 }
1429
1430 vndk_prebuilt_shared {
1431 name: "libvndk",
1432 version: "27",
1433 vendor_available: true,
1434 vndk: {
1435 enabled: true,
1436 },
1437 srcs: ["libvndk.so"],
1438 }
1439 `, withFiles(map[string][]byte{
1440 "libvndk.so": nil,
1441 }))
1442}
1443
Jooyung Han90eee022019-10-01 20:02:42 +09001444func TestVndkApexNameRule(t *testing.T) {
1445 ctx, _ := testApex(t, `
1446 apex_vndk {
1447 name: "myapex",
1448 key: "myapex.key",
1449 file_contexts: "myapex",
1450 }
1451 apex_vndk {
1452 name: "myapex_v28",
1453 key: "myapex.key",
1454 file_contexts: "myapex",
1455 vndk_version: "28",
1456 }
1457 apex_key {
1458 name: "myapex.key",
1459 public_key: "testkey.avbpubkey",
1460 private_key: "testkey.pem",
1461 }`)
1462
1463 assertApexName := func(expected, moduleName string) {
1464 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Module().(*apexBundle)
1465 actual := proptools.String(bundle.properties.Apex_name)
1466 if !reflect.DeepEqual(actual, expected) {
1467 t.Errorf("Got '%v', expected '%v'", actual, expected)
1468 }
1469 }
1470
1471 assertApexName("com.android.vndk.vVER", "myapex")
1472 assertApexName("com.android.vndk.v28", "myapex_v28")
1473}
1474
Jooyung Han344d5432019-08-23 11:17:39 +09001475func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1476 ctx, _ := testApex(t, `
1477 apex_vndk {
1478 name: "myapex",
1479 key: "myapex.key",
1480 file_contexts: "myapex",
1481 }
1482
1483 apex_key {
1484 name: "myapex.key",
1485 public_key: "testkey.avbpubkey",
1486 private_key: "testkey.pem",
1487 }
1488
1489 cc_library {
1490 name: "libvndk",
1491 srcs: ["mylib.cpp"],
1492 vendor_available: true,
1493 native_bridge_supported: true,
1494 host_supported: true,
1495 vndk: {
1496 enabled: true,
1497 },
1498 system_shared_libs: [],
1499 stl: "none",
1500 }
1501 `, withTargets(map[android.OsType][]android.Target{
1502 android.Android: []android.Target{
1503 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1504 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1505 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1506 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
1507 },
1508 }))
1509
1510 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1511 copyCmds := apexRule.Args["copy_commands"]
1512 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1513 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1514
1515 // apex
1516 ensureNotContains(t, copyCmds, "image.apex/lib/x86/libvndk.so")
1517 ensureNotContains(t, copyCmds, "image.apex/lib64/x86_64/libvndk.so")
1518}
1519
1520func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1521 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1522 apex_vndk {
1523 name: "myapex",
1524 key: "myapex.key",
1525 file_contexts: "myapex",
1526 native_bridge_supported: true,
1527 }
1528
1529 apex_key {
1530 name: "myapex.key",
1531 public_key: "testkey.avbpubkey",
1532 private_key: "testkey.pem",
1533 }
1534
1535 cc_library {
1536 name: "libvndk",
1537 srcs: ["mylib.cpp"],
1538 vendor_available: true,
1539 native_bridge_supported: true,
1540 host_supported: true,
1541 vndk: {
1542 enabled: true,
1543 },
1544 system_shared_libs: [],
1545 stl: "none",
1546 }
1547 `)
1548}
1549
Jooyung Hane1633032019-08-01 17:41:43 +09001550func TestDependenciesInApexManifest(t *testing.T) {
1551 ctx, _ := testApex(t, `
1552 apex {
1553 name: "myapex_nodep",
1554 key: "myapex.key",
1555 native_shared_libs: ["lib_nodep"],
1556 compile_multilib: "both",
1557 file_contexts: "myapex",
1558 }
1559
1560 apex {
1561 name: "myapex_dep",
1562 key: "myapex.key",
1563 native_shared_libs: ["lib_dep"],
1564 compile_multilib: "both",
1565 file_contexts: "myapex",
1566 }
1567
1568 apex {
1569 name: "myapex_provider",
1570 key: "myapex.key",
1571 native_shared_libs: ["libfoo"],
1572 compile_multilib: "both",
1573 file_contexts: "myapex",
1574 }
1575
1576 apex {
1577 name: "myapex_selfcontained",
1578 key: "myapex.key",
1579 native_shared_libs: ["lib_dep", "libfoo"],
1580 compile_multilib: "both",
1581 file_contexts: "myapex",
1582 }
1583
1584 apex_key {
1585 name: "myapex.key",
1586 public_key: "testkey.avbpubkey",
1587 private_key: "testkey.pem",
1588 }
1589
1590 cc_library {
1591 name: "lib_nodep",
1592 srcs: ["mylib.cpp"],
1593 system_shared_libs: [],
1594 stl: "none",
1595 }
1596
1597 cc_library {
1598 name: "lib_dep",
1599 srcs: ["mylib.cpp"],
1600 shared_libs: ["libfoo"],
1601 system_shared_libs: [],
1602 stl: "none",
1603 }
1604
1605 cc_library {
1606 name: "libfoo",
1607 srcs: ["mytest.cpp"],
1608 stubs: {
1609 versions: ["1"],
1610 },
1611 system_shared_libs: [],
1612 stl: "none",
1613 }
1614 `)
1615
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001616 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001617 var provideNativeLibs, requireNativeLibs []string
1618
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001619 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("apexManifestRule")
1620 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1621 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001622 ensureListEmpty(t, provideNativeLibs)
1623 ensureListEmpty(t, requireNativeLibs)
1624
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001625 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("apexManifestRule")
1626 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1627 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001628 ensureListEmpty(t, provideNativeLibs)
1629 ensureListContains(t, requireNativeLibs, "libfoo.so")
1630
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001631 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("apexManifestRule")
1632 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1633 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001634 ensureListContains(t, provideNativeLibs, "libfoo.so")
1635 ensureListEmpty(t, requireNativeLibs)
1636
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001637 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("apexManifestRule")
1638 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1639 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001640 ensureListContains(t, provideNativeLibs, "libfoo.so")
1641 ensureListEmpty(t, requireNativeLibs)
1642}
1643
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001644func TestApexName(t *testing.T) {
1645 ctx, _ := testApex(t, `
1646 apex {
1647 name: "myapex",
1648 key: "myapex.key",
1649 apex_name: "com.android.myapex",
1650 }
1651
1652 apex_key {
1653 name: "myapex.key",
1654 public_key: "testkey.avbpubkey",
1655 private_key: "testkey.pem",
1656 }
1657 `)
1658
1659 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1660 apexManifestRule := module.Rule("apexManifestRule")
1661 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1662 apexRule := module.Rule("apexRule")
1663 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1664}
1665
Alex Light0851b882019-02-07 13:20:53 -08001666func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001667 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001668 apex {
1669 name: "myapex",
1670 key: "myapex.key",
1671 native_shared_libs: ["mylib_common"],
1672 }
1673
1674 apex_key {
1675 name: "myapex.key",
1676 public_key: "testkey.avbpubkey",
1677 private_key: "testkey.pem",
1678 }
1679
1680 cc_library {
1681 name: "mylib_common",
1682 srcs: ["mylib.cpp"],
1683 system_shared_libs: [],
1684 stl: "none",
1685 }
1686 `)
1687
1688 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1689 apexRule := module.Rule("apexRule")
1690 copyCmds := apexRule.Args["copy_commands"]
1691
1692 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1693 t.Log("Apex was a test apex!")
1694 t.Fail()
1695 }
1696 // Ensure that main rule creates an output
1697 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1698
1699 // Ensure that apex variant is created for the direct dep
1700 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1701
1702 // Ensure that both direct and indirect deps are copied into apex
1703 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1704
1705 // Ensure that the platform variant ends with _core_shared
1706 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1707
1708 if !android.InAnyApex("mylib_common") {
1709 t.Log("Found mylib_common not in any apex!")
1710 t.Fail()
1711 }
1712}
1713
1714func TestTestApex(t *testing.T) {
1715 if android.InAnyApex("mylib_common_test") {
1716 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!")
1717 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001718 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001719 apex_test {
1720 name: "myapex",
1721 key: "myapex.key",
1722 native_shared_libs: ["mylib_common_test"],
1723 }
1724
1725 apex_key {
1726 name: "myapex.key",
1727 public_key: "testkey.avbpubkey",
1728 private_key: "testkey.pem",
1729 }
1730
1731 cc_library {
1732 name: "mylib_common_test",
1733 srcs: ["mylib.cpp"],
1734 system_shared_libs: [],
1735 stl: "none",
1736 }
1737 `)
1738
1739 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1740 apexRule := module.Rule("apexRule")
1741 copyCmds := apexRule.Args["copy_commands"]
1742
1743 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1744 t.Log("Apex was not a test apex!")
1745 t.Fail()
1746 }
1747 // Ensure that main rule creates an output
1748 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1749
1750 // Ensure that apex variant is created for the direct dep
1751 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1752
1753 // Ensure that both direct and indirect deps are copied into apex
1754 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1755
1756 // Ensure that the platform variant ends with _core_shared
1757 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1758
1759 if android.InAnyApex("mylib_common_test") {
1760 t.Log("Found mylib_common_test in some apex!")
1761 t.Fail()
1762 }
1763}
1764
Alex Light9670d332019-01-29 18:07:33 -08001765func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001766 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001767 apex {
1768 name: "myapex",
1769 key: "myapex.key",
1770 multilib: {
1771 first: {
1772 native_shared_libs: ["mylib_common"],
1773 }
1774 },
1775 target: {
1776 android: {
1777 multilib: {
1778 first: {
1779 native_shared_libs: ["mylib"],
1780 }
1781 }
1782 },
1783 host: {
1784 multilib: {
1785 first: {
1786 native_shared_libs: ["mylib2"],
1787 }
1788 }
1789 }
1790 }
1791 }
1792
1793 apex_key {
1794 name: "myapex.key",
1795 public_key: "testkey.avbpubkey",
1796 private_key: "testkey.pem",
1797 }
1798
1799 cc_library {
1800 name: "mylib",
1801 srcs: ["mylib.cpp"],
1802 system_shared_libs: [],
1803 stl: "none",
1804 }
1805
1806 cc_library {
1807 name: "mylib_common",
1808 srcs: ["mylib.cpp"],
1809 system_shared_libs: [],
1810 stl: "none",
1811 compile_multilib: "first",
1812 }
1813
1814 cc_library {
1815 name: "mylib2",
1816 srcs: ["mylib.cpp"],
1817 system_shared_libs: [],
1818 stl: "none",
1819 compile_multilib: "first",
1820 }
1821 `)
1822
1823 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1824 copyCmds := apexRule.Args["copy_commands"]
1825
1826 // Ensure that main rule creates an output
1827 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1828
1829 // Ensure that apex variant is created for the direct dep
1830 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1831 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1832 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1833
1834 // Ensure that both direct and indirect deps are copied into apex
1835 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1836 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1837 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1838
1839 // Ensure that the platform variant ends with _core_shared
1840 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1841 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1842 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1843}
Jiyong Park04480cf2019-02-06 00:16:29 +09001844
1845func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001846 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001847 apex {
1848 name: "myapex",
1849 key: "myapex.key",
1850 binaries: ["myscript"],
1851 }
1852
1853 apex_key {
1854 name: "myapex.key",
1855 public_key: "testkey.avbpubkey",
1856 private_key: "testkey.pem",
1857 }
1858
1859 sh_binary {
1860 name: "myscript",
1861 src: "mylib.cpp",
1862 filename: "myscript.sh",
1863 sub_dir: "script",
1864 }
1865 `)
1866
1867 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1868 copyCmds := apexRule.Args["copy_commands"]
1869
1870 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1871}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001872
1873func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001874 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001875 apex {
1876 name: "myapex",
1877 key: "myapex.key",
1878 native_shared_libs: ["mylib"],
1879 product_specific: true,
1880 }
1881
1882 apex_key {
1883 name: "myapex.key",
1884 public_key: "testkey.avbpubkey",
1885 private_key: "testkey.pem",
1886 product_specific: true,
1887 }
1888
1889 cc_library {
1890 name: "mylib",
1891 srcs: ["mylib.cpp"],
1892 system_shared_libs: [],
1893 stl: "none",
1894 }
1895 `)
1896
1897 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1898 expected := "target/product/test_device/product/apex"
1899 actual := apex.installDir.RelPathString()
1900 if actual != expected {
1901 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1902 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001903}
Jiyong Park67882562019-03-21 01:11:21 +09001904
1905func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001906 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001907 apex_key {
1908 name: "myapex.key",
1909 public_key: ":my.avbpubkey",
1910 private_key: ":my.pem",
1911 product_specific: true,
1912 }
1913
1914 filegroup {
1915 name: "my.avbpubkey",
1916 srcs: ["testkey2.avbpubkey"],
1917 }
1918
1919 filegroup {
1920 name: "my.pem",
1921 srcs: ["testkey2.pem"],
1922 }
1923 `)
1924
1925 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1926 expected_pubkey := "testkey2.avbpubkey"
1927 actual_pubkey := apex_key.public_key_file.String()
1928 if actual_pubkey != expected_pubkey {
1929 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1930 }
1931 expected_privkey := "testkey2.pem"
1932 actual_privkey := apex_key.private_key_file.String()
1933 if actual_privkey != expected_privkey {
1934 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1935 }
1936}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001937
1938func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001939 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001940 prebuilt_apex {
1941 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001942 arch: {
1943 arm64: {
1944 src: "myapex-arm64.apex",
1945 },
1946 arm: {
1947 src: "myapex-arm.apex",
1948 },
1949 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001950 }
1951 `)
1952
1953 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1954
Jiyong Parkc95714e2019-03-29 14:23:10 +09001955 expectedInput := "myapex-arm64.apex"
1956 if prebuilt.inputApex.String() != expectedInput {
1957 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1958 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001959}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001960
1961func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001962 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001963 prebuilt_apex {
1964 name: "myapex",
1965 src: "myapex-arm.apex",
1966 filename: "notmyapex.apex",
1967 }
1968 `)
1969
1970 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1971
1972 expected := "notmyapex.apex"
1973 if p.installFilename != expected {
1974 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1975 }
1976}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001977
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001978func TestPrebuiltOverrides(t *testing.T) {
1979 ctx, config := testApex(t, `
1980 prebuilt_apex {
1981 name: "myapex.prebuilt",
1982 src: "myapex-arm.apex",
1983 overrides: [
1984 "myapex",
1985 ],
1986 }
1987 `)
1988
1989 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1990
1991 expected := []string{"myapex"}
1992 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1993 if !reflect.DeepEqual(actual, expected) {
1994 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1995 }
1996}
1997
Roland Levillain630846d2019-06-26 12:48:34 +01001998func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001999 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002000 apex_test {
2001 name: "myapex",
2002 key: "myapex.key",
2003 tests: [
2004 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002005 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002006 ],
2007 }
2008
2009 apex_key {
2010 name: "myapex.key",
2011 public_key: "testkey.avbpubkey",
2012 private_key: "testkey.pem",
2013 }
2014
2015 cc_test {
2016 name: "mytest",
2017 gtest: false,
2018 srcs: ["mytest.cpp"],
2019 relative_install_path: "test",
2020 system_shared_libs: [],
2021 static_executable: true,
2022 stl: "none",
2023 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002024
2025 cc_test {
2026 name: "mytests",
2027 gtest: false,
2028 srcs: [
2029 "mytest1.cpp",
2030 "mytest2.cpp",
2031 "mytest3.cpp",
2032 ],
2033 test_per_src: true,
2034 relative_install_path: "test",
2035 system_shared_libs: [],
2036 static_executable: true,
2037 stl: "none",
2038 }
Roland Levillain630846d2019-06-26 12:48:34 +01002039 `)
2040
2041 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2042 copyCmds := apexRule.Args["copy_commands"]
2043
2044 // Ensure that test dep is copied into apex.
2045 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002046
2047 // Ensure that test deps built with `test_per_src` are copied into apex.
2048 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2049 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2050 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002051
2052 // Ensure the module is correctly translated.
2053 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
2054 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2055 name := apexBundle.BaseModuleName()
2056 prefix := "TARGET_"
2057 var builder strings.Builder
2058 data.Custom(&builder, name, prefix, "", data)
2059 androidMk := builder.String()
2060 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest\n")
2061 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest1\n")
2062 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest2\n")
2063 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest3\n")
2064 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_manifest.json\n")
2065 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_pubkey\n")
2066 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002067}
2068
Jooyung Han5c998b92019-06-27 11:30:33 +09002069func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002070 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002071 apex {
2072 name: "myapex",
2073 key: "myapex.key",
2074 native_shared_libs: ["mylib"],
2075 uses: ["commonapex"],
2076 }
2077
2078 apex {
2079 name: "commonapex",
2080 key: "myapex.key",
2081 native_shared_libs: ["libcommon"],
2082 provide_cpp_shared_libs: true,
2083 }
2084
2085 apex_key {
2086 name: "myapex.key",
2087 public_key: "testkey.avbpubkey",
2088 private_key: "testkey.pem",
2089 }
2090
2091 cc_library {
2092 name: "mylib",
2093 srcs: ["mylib.cpp"],
2094 shared_libs: ["libcommon"],
2095 system_shared_libs: [],
2096 stl: "none",
2097 }
2098
2099 cc_library {
2100 name: "libcommon",
2101 srcs: ["mylib_common.cpp"],
2102 system_shared_libs: [],
2103 stl: "none",
2104 }
2105 `)
2106
2107 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2108 apexRule1 := module1.Rule("apexRule")
2109 copyCmds1 := apexRule1.Args["copy_commands"]
2110
2111 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2112 apexRule2 := module2.Rule("apexRule")
2113 copyCmds2 := apexRule2.Args["copy_commands"]
2114
2115 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2116 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2117 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2118 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2119 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2120}
2121
2122func TestApexUsesFailsIfNotProvided(t *testing.T) {
2123 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2124 apex {
2125 name: "myapex",
2126 key: "myapex.key",
2127 uses: ["commonapex"],
2128 }
2129
2130 apex {
2131 name: "commonapex",
2132 key: "myapex.key",
2133 }
2134
2135 apex_key {
2136 name: "myapex.key",
2137 public_key: "testkey.avbpubkey",
2138 private_key: "testkey.pem",
2139 }
2140 `)
2141 testApexError(t, `uses: "commonapex" is not a provider`, `
2142 apex {
2143 name: "myapex",
2144 key: "myapex.key",
2145 uses: ["commonapex"],
2146 }
2147
2148 cc_library {
2149 name: "commonapex",
2150 system_shared_libs: [],
2151 stl: "none",
2152 }
2153
2154 apex_key {
2155 name: "myapex.key",
2156 public_key: "testkey.avbpubkey",
2157 private_key: "testkey.pem",
2158 }
2159 `)
2160}
2161
2162func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2163 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2164 apex {
2165 name: "myapex",
2166 key: "myapex.key",
2167 use_vendor: true,
2168 uses: ["commonapex"],
2169 }
2170
2171 apex {
2172 name: "commonapex",
2173 key: "myapex.key",
2174 provide_cpp_shared_libs: true,
2175 }
2176
2177 apex_key {
2178 name: "myapex.key",
2179 public_key: "testkey.avbpubkey",
2180 private_key: "testkey.pem",
2181 }
2182 `)
2183}
2184
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002185func TestApexUsesFailsIfUseNoApex(t *testing.T) {
Jooyung Hancc372c52019-09-25 15:18:44 +09002186 // 'no_apex' prevents a module to be included in an apex
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002187 testApexError(t, `tries to include no_apex module mylib2`, `
2188 apex {
2189 name: "commonapex",
2190 key: "myapex.key",
2191 native_shared_libs: ["mylib"],
2192 }
2193
2194 apex_key {
2195 name: "myapex.key",
2196 public_key: "testkey.avbpubkey",
2197 private_key: "testkey.pem",
2198 }
2199
2200 cc_library {
2201 name: "mylib",
2202 srcs: ["mylib.cpp"],
2203 shared_libs: ["mylib2"],
2204 system_shared_libs: [],
2205 stl: "none",
2206 }
2207
2208 cc_library {
2209 name: "mylib2",
2210 srcs: ["mylib.cpp"],
2211 system_shared_libs: [],
2212 stl: "none",
2213 no_apex: true,
2214 }
2215 `)
2216
Jooyung Hancc372c52019-09-25 15:18:44 +09002217 // respect 'no_apex' even with static link
Sundong Ahn2db7f462019-08-27 18:53:12 +09002218 testApexError(t, `tries to include no_apex module mylib2`, `
2219 apex {
2220 name: "commonapex",
2221 key: "myapex.key",
2222 native_shared_libs: ["mylib"],
2223 }
2224
2225 apex_key {
2226 name: "myapex.key",
2227 public_key: "testkey.avbpubkey",
2228 private_key: "testkey.pem",
2229 }
2230
2231 cc_library {
2232 name: "mylib",
2233 srcs: ["mylib.cpp"],
2234 static_libs: ["mylib2"],
2235 system_shared_libs: [],
2236 stl: "none",
2237 }
2238
2239 cc_library {
2240 name: "mylib2",
2241 srcs: ["mylib.cpp"],
2242 system_shared_libs: [],
2243 stl: "none",
2244 no_apex: true,
2245 }
2246 `)
2247
Jooyung Hancc372c52019-09-25 15:18:44 +09002248 // 'no_apex' can be applied via defaults
2249 testApexError(t, `tries to include no_apex module mylib2`, `
2250 apex {
2251 name: "commonapex",
2252 key: "myapex.key",
2253 native_shared_libs: ["mylib"],
2254 }
2255
2256 apex_key {
2257 name: "myapex.key",
2258 public_key: "testkey.avbpubkey",
2259 private_key: "testkey.pem",
2260 }
2261
2262 cc_library {
2263 name: "mylib",
2264 srcs: ["mylib.cpp"],
2265 static_libs: ["mylib2"],
2266 system_shared_libs: [],
2267 stl: "none",
2268 }
2269
2270 cc_defaults {
2271 name: "mylib2_defaults",
2272 system_shared_libs: [],
2273 stl: "none",
2274 no_apex: true,
2275 }
2276
2277 cc_library {
2278 name: "mylib2",
2279 srcs: ["mylib.cpp"],
2280 defaults: ["mylib2_defaults"],
2281 }
2282 `)
2283}
2284
2285func TestNoApexWorksWithWhitelist(t *testing.T) {
2286
2287 testApex(t, `
2288 apex {
2289 name: "myapex",
2290 key: "myapex.key",
2291 native_shared_libs: ["mylib"],
2292 }
2293
2294 apex_key {
2295 name: "myapex.key",
2296 public_key: "testkey.avbpubkey",
2297 private_key: "testkey.pem",
2298 }
2299
2300 cc_library {
2301 name: "mylib",
2302 srcs: ["mylib.cpp"],
2303 shared_libs: ["mylib2"],
2304 system_shared_libs: [],
2305 stl: "none",
2306 }
2307
2308 cc_defaults {
2309 name: "mylib2_defaults",
2310 system_shared_libs: [],
2311 stl: "none",
2312 no_apex: true,
2313 }
2314
2315 cc_library {
2316 name: "mylib2",
2317 srcs: ["mylib.cpp"],
2318 defaults: ["mylib2_defaults"],
2319 }
2320 `, func(fs map[string][]byte, config android.Config) {
2321 whitelistNoApex = map[string][]string{
2322 "myapex": []string{"mylib2"},
2323 }
2324 })
2325}
2326
2327func TestNoApexCanBeDependedOnViaStubs(t *testing.T) {
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002328 ctx, _ := testApex(t, `
2329 apex {
2330 name: "myapex",
2331 key: "myapex.key",
2332 native_shared_libs: ["mylib"],
2333 }
2334
2335 apex_key {
2336 name: "myapex.key",
2337 public_key: "testkey.avbpubkey",
2338 private_key: "testkey.pem",
2339 }
2340
2341 cc_library {
2342 name: "mylib",
2343 srcs: ["mylib.cpp"],
2344 shared_libs: ["mylib2"],
2345 system_shared_libs: [],
2346 stl: "none",
2347 }
2348
2349 cc_library {
2350 name: "mylib2",
2351 srcs: ["mylib.cpp"],
2352 shared_libs: ["mylib3"],
2353 system_shared_libs: [],
2354 stl: "none",
2355 stubs: {
2356 versions: ["1", "2", "3"],
2357 },
2358 }
2359
Jooyung Hancc372c52019-09-25 15:18:44 +09002360 // this won't be included in "myapex", so 'no_apex' is still valid in this case.
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002361 cc_library {
2362 name: "mylib3",
2363 srcs: ["mylib.cpp"],
2364 system_shared_libs: [],
2365 stl: "none",
2366 no_apex: true,
2367 }
2368 `)
2369
2370 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2371 apexRule := module.Rule("apexRule")
2372 copyCmds := apexRule.Args["copy_commands"]
2373
2374 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2375 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2376 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002377}
2378
Jooyung Hand48f3c32019-08-23 11:18:57 +09002379func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2380 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2381 apex {
2382 name: "myapex",
2383 key: "myapex.key",
2384 native_shared_libs: ["libfoo"],
2385 }
2386
2387 apex_key {
2388 name: "myapex.key",
2389 public_key: "testkey.avbpubkey",
2390 private_key: "testkey.pem",
2391 }
2392
2393 cc_library {
2394 name: "libfoo",
2395 stl: "none",
2396 system_shared_libs: [],
2397 enabled: false,
2398 }
2399 `)
2400 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2401 apex {
2402 name: "myapex",
2403 key: "myapex.key",
2404 java_libs: ["myjar"],
2405 }
2406
2407 apex_key {
2408 name: "myapex.key",
2409 public_key: "testkey.avbpubkey",
2410 private_key: "testkey.pem",
2411 }
2412
2413 java_library {
2414 name: "myjar",
2415 srcs: ["foo/bar/MyClass.java"],
2416 sdk_version: "none",
2417 system_modules: "none",
2418 compile_dex: true,
2419 enabled: false,
2420 }
2421 `)
2422}
2423
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002424func TestApexWithApps(t *testing.T) {
2425 ctx, _ := testApex(t, `
2426 apex {
2427 name: "myapex",
2428 key: "myapex.key",
2429 apps: [
2430 "AppFoo",
2431 ],
2432 }
2433
2434 apex_key {
2435 name: "myapex.key",
2436 public_key: "testkey.avbpubkey",
2437 private_key: "testkey.pem",
2438 }
2439
2440 android_app {
2441 name: "AppFoo",
2442 srcs: ["foo/bar/MyClass.java"],
2443 sdk_version: "none",
2444 system_modules: "none",
2445 }
2446 `)
2447
2448 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2449 apexRule := module.Rule("apexRule")
2450 copyCmds := apexRule.Args["copy_commands"]
2451
2452 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
2453
2454}
2455
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002456func TestMain(m *testing.M) {
2457 run := func() int {
2458 setUp()
2459 defer tearDown()
2460
2461 return m.Run()
2462 }
2463
2464 os.Exit(run())
2465}