blob: d1cd9699de2bec511f6c26d8b878e216d2ed0eaa [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
105 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
106 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900107 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900108 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
109 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900110 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900111 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100112 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900113 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900114 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900115 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900116 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900117 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900118 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900119 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900120 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900121 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900122 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900123
Jooyung Han344d5432019-08-23 11:17:39 +0900124 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700125 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
126 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
127 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900128 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900129 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900130 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900131 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100132 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 ctx.BottomUp("version", cc.VersionMutator).Parallel()
134 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900135 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator)
136 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator)
137 })
138 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
139 ctx.TopDown("apex_deps", apexDepsMutator)
140 ctx.BottomUp("apex", apexMutator)
141 ctx.BottomUp("apex_uses", apexUsesMutator)
142 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
143 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900144 })
145
146 ctx.Register()
147
148 bp = bp + `
149 toolchain_library {
150 name: "libcompiler_rt-extras",
151 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900152 vendor_available: true,
153 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900154 }
155
156 toolchain_library {
157 name: "libatomic",
158 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900159 vendor_available: true,
160 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900161 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900162 }
163
164 toolchain_library {
165 name: "libgcc",
166 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900167 vendor_available: true,
168 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900169 }
170
171 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700172 name: "libgcc_stripped",
173 src: "",
174 vendor_available: true,
175 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900176 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700177 }
178
179 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900180 name: "libclang_rt.builtins-aarch64-android",
181 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900182 vendor_available: true,
183 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900184 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900185 }
186
187 toolchain_library {
188 name: "libclang_rt.builtins-arm-android",
189 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900190 vendor_available: true,
191 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900192 native_bridge_supported: true,
193 }
194
195 toolchain_library {
196 name: "libclang_rt.builtins-x86_64-android",
197 src: "",
198 vendor_available: true,
199 recovery_available: true,
200 native_bridge_supported: true,
201 }
202
203 toolchain_library {
204 name: "libclang_rt.builtins-i686-android",
205 src: "",
206 vendor_available: true,
207 recovery_available: true,
208 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900209 }
210
211 cc_object {
212 name: "crtbegin_so",
213 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900214 vendor_available: true,
215 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900216 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900217 }
218
219 cc_object {
220 name: "crtend_so",
221 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900222 vendor_available: true,
223 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900224 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900225 }
226
Alex Light3d673592019-01-18 14:37:31 -0800227 cc_object {
228 name: "crtbegin_static",
229 stl: "none",
230 }
231
232 cc_object {
233 name: "crtend_android",
234 stl: "none",
235 }
236
Jiyong Parkda6eb592018-12-19 17:12:36 +0900237 llndk_library {
238 name: "libc",
239 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900240 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900241 }
242
243 llndk_library {
244 name: "libm",
245 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900246 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900247 }
248
249 llndk_library {
250 name: "libdl",
251 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900252 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900253 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900254 `
255
Jooyung Han344d5432019-08-23 11:17:39 +0900256 fs := map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900257 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700258 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900259 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900260 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900261 "system/sepolicy/apex/myapex-file_contexts": nil,
262 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
263 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900264 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900265 "mylib.cpp": nil,
266 "mylib_common.cpp": nil,
267 "mytest.cpp": nil,
268 "mytest1.cpp": nil,
269 "mytest2.cpp": nil,
270 "mytest3.cpp": nil,
271 "myprebuilt": nil,
272 "my_include": nil,
273 "foo/bar/MyClass.java": nil,
274 "prebuilt.jar": nil,
275 "vendor/foo/devkeys/test.x509.pem": nil,
276 "vendor/foo/devkeys/test.pk8": nil,
277 "testkey.x509.pem": nil,
278 "testkey.pk8": nil,
279 "testkey.override.x509.pem": nil,
280 "testkey.override.pk8": nil,
281 "vendor/foo/devkeys/testkey.avbpubkey": nil,
282 "vendor/foo/devkeys/testkey.pem": nil,
283 "NOTICE": nil,
284 "custom_notice": nil,
285 "testkey2.avbpubkey": nil,
286 "testkey2.pem": nil,
287 "myapex-arm64.apex": nil,
288 "myapex-arm.apex": nil,
289 "frameworks/base/api/current.txt": nil,
290 "build/make/core/proguard.flags": nil,
291 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900292 }
293
294 for _, handler := range handlers {
295 handler(fs, config)
296 }
297
298 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900299
Jooyung Han5c998b92019-06-27 11:30:33 +0900300 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900301}
302
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700303func setUp() {
304 var err error
305 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900306 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700307 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900308 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900309}
310
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700311func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900312 os.RemoveAll(buildDir)
313}
314
315// ensure that 'result' contains 'expected'
316func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900317 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900318 if !strings.Contains(result, expected) {
319 t.Errorf("%q is not found in %q", expected, result)
320 }
321}
322
323// ensures that 'result' does not contain 'notExpected'
324func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900325 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900326 if strings.Contains(result, notExpected) {
327 t.Errorf("%q is found in %q", notExpected, result)
328 }
329}
330
331func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900332 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900333 if !android.InList(expected, result) {
334 t.Errorf("%q is not found in %v", expected, result)
335 }
336}
337
338func ensureListNotContains(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 android.InList(notExpected, result) {
341 t.Errorf("%q is found in %v", notExpected, result)
342 }
343}
344
Jooyung Hane1633032019-08-01 17:41:43 +0900345func ensureListEmpty(t *testing.T, result []string) {
346 t.Helper()
347 if len(result) > 0 {
348 t.Errorf("%q is expected to be empty", result)
349 }
350}
351
Jiyong Park25fc6a92018-11-18 18:02:45 +0900352// Minimal test
353func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700354 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900355 apex_defaults {
356 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900357 manifest: ":myapex.manifest",
358 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900359 key: "myapex.key",
360 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800361 multilib: {
362 both: {
363 binaries: ["foo",],
364 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900365 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900366 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900367 }
368
Jiyong Park30ca9372019-02-07 16:27:23 +0900369 apex {
370 name: "myapex",
371 defaults: ["myapex-defaults"],
372 }
373
Jiyong Park25fc6a92018-11-18 18:02:45 +0900374 apex_key {
375 name: "myapex.key",
376 public_key: "testkey.avbpubkey",
377 private_key: "testkey.pem",
378 }
379
Jiyong Park809bb722019-02-13 21:33:49 +0900380 filegroup {
381 name: "myapex.manifest",
382 srcs: ["apex_manifest.json"],
383 }
384
385 filegroup {
386 name: "myapex.androidmanifest",
387 srcs: ["AndroidManifest.xml"],
388 }
389
Jiyong Park25fc6a92018-11-18 18:02:45 +0900390 cc_library {
391 name: "mylib",
392 srcs: ["mylib.cpp"],
393 shared_libs: ["mylib2"],
394 system_shared_libs: [],
395 stl: "none",
396 }
397
Alex Light3d673592019-01-18 14:37:31 -0800398 cc_binary {
399 name: "foo",
400 srcs: ["mylib.cpp"],
401 compile_multilib: "both",
402 multilib: {
403 lib32: {
404 suffix: "32",
405 },
406 lib64: {
407 suffix: "64",
408 },
409 },
410 symlinks: ["foo_link_"],
411 symlink_preferred_arch: true,
412 system_shared_libs: [],
413 static_executable: true,
414 stl: "none",
415 }
416
Jiyong Park25fc6a92018-11-18 18:02:45 +0900417 cc_library {
418 name: "mylib2",
419 srcs: ["mylib.cpp"],
420 system_shared_libs: [],
421 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900422 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900423 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900424
425 java_library {
426 name: "myjar",
427 srcs: ["foo/bar/MyClass.java"],
428 sdk_version: "none",
429 system_modules: "none",
430 compile_dex: true,
431 static_libs: ["myotherjar"],
432 }
433
434 java_library {
435 name: "myotherjar",
436 srcs: ["foo/bar/MyClass.java"],
437 sdk_version: "none",
438 system_modules: "none",
439 compile_dex: true,
440 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900441
442 java_import {
443 name: "myprebuiltjar",
444 jars: ["prebuilt.jar"],
445 installable: true,
446 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900447 `)
448
449 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900450
451 optFlags := apexRule.Args["opt_flags"]
452 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700453 // Ensure that the NOTICE output is being packaged as an asset.
454 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900455
Jiyong Park25fc6a92018-11-18 18:02:45 +0900456 copyCmds := apexRule.Args["copy_commands"]
457
458 // Ensure that main rule creates an output
459 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
460
461 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900462 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900463 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900464 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900465
466 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900467 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900468 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900469
470 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800471 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
472 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900473 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900474 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900475 // .. but not for java libs
476 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800477
Jiyong Park7f7766d2019-07-25 22:02:35 +0900478 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800479 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
480 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900481 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
482 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900483 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800484
485 // Ensure that all symlinks are present.
486 found_foo_link_64 := false
487 found_foo := false
488 for _, cmd := range strings.Split(copyCmds, " && ") {
489 if strings.HasPrefix(cmd, "ln -s foo64") {
490 if strings.HasSuffix(cmd, "bin/foo") {
491 found_foo = true
492 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
493 found_foo_link_64 = true
494 }
495 }
496 }
497 good := found_foo && found_foo_link_64
498 if !good {
499 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
500 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900501
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700502 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
503 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700504 if len(noticeInputs) != 2 {
505 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900506 }
507 ensureListContains(t, noticeInputs, "NOTICE")
508 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800509}
510
511func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700512 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800513 apex {
514 name: "myapex",
515 key: "myapex.key",
516 payload_type: "zip",
517 native_shared_libs: ["mylib"],
518 }
519
520 apex_key {
521 name: "myapex.key",
522 public_key: "testkey.avbpubkey",
523 private_key: "testkey.pem",
524 }
525
526 cc_library {
527 name: "mylib",
528 srcs: ["mylib.cpp"],
529 shared_libs: ["mylib2"],
530 system_shared_libs: [],
531 stl: "none",
532 }
533
534 cc_library {
535 name: "mylib2",
536 srcs: ["mylib.cpp"],
537 system_shared_libs: [],
538 stl: "none",
539 }
540 `)
541
542 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
543 copyCmds := zipApexRule.Args["copy_commands"]
544
545 // Ensure that main rule creates an output
546 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
547
548 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900549 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800550
551 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900552 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800553
554 // Ensure that both direct and indirect deps are copied into apex
555 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
556 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900557}
558
559func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700560 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900561 apex {
562 name: "myapex",
563 key: "myapex.key",
564 native_shared_libs: ["mylib", "mylib3"],
565 }
566
567 apex_key {
568 name: "myapex.key",
569 public_key: "testkey.avbpubkey",
570 private_key: "testkey.pem",
571 }
572
573 cc_library {
574 name: "mylib",
575 srcs: ["mylib.cpp"],
576 shared_libs: ["mylib2", "mylib3"],
577 system_shared_libs: [],
578 stl: "none",
579 }
580
581 cc_library {
582 name: "mylib2",
583 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900584 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900585 system_shared_libs: [],
586 stl: "none",
587 stubs: {
588 versions: ["1", "2", "3"],
589 },
590 }
591
592 cc_library {
593 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900594 srcs: ["mylib.cpp"],
595 shared_libs: ["mylib4"],
596 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900597 stl: "none",
598 stubs: {
599 versions: ["10", "11", "12"],
600 },
601 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900602
603 cc_library {
604 name: "mylib4",
605 srcs: ["mylib.cpp"],
606 system_shared_libs: [],
607 stl: "none",
608 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900609 `)
610
611 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
612 copyCmds := apexRule.Args["copy_commands"]
613
614 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800615 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900616
617 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800618 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900619
620 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800621 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900622
Jiyong Parkda6eb592018-12-19 17:12:36 +0900623 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900624
625 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900626 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900627 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900628 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900629
630 // 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 +0900631 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900632 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900633 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900634
635 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900636 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900637 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900638
639 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900640 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 +0900641}
642
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900643func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700644 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900645 apex {
646 name: "myapex",
647 key: "myapex.key",
648 native_shared_libs: ["mylib"],
649 }
650
651 apex_key {
652 name: "myapex.key",
653 public_key: "testkey.avbpubkey",
654 private_key: "testkey.pem",
655 }
656
657 cc_library {
658 name: "mylib",
659 srcs: ["mylib.cpp"],
660 shared_libs: ["libfoo#10"],
661 system_shared_libs: [],
662 stl: "none",
663 }
664
665 cc_library {
666 name: "libfoo",
667 srcs: ["mylib.cpp"],
668 shared_libs: ["libbar"],
669 system_shared_libs: [],
670 stl: "none",
671 stubs: {
672 versions: ["10", "20", "30"],
673 },
674 }
675
676 cc_library {
677 name: "libbar",
678 srcs: ["mylib.cpp"],
679 system_shared_libs: [],
680 stl: "none",
681 }
682
683 `)
684
685 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
686 copyCmds := apexRule.Args["copy_commands"]
687
688 // Ensure that direct non-stubs dep is always included
689 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
690
691 // Ensure that indirect stubs dep is not included
692 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
693
694 // Ensure that dependency of stubs is not included
695 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
696
Jiyong Parkda6eb592018-12-19 17:12:36 +0900697 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900698
699 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900700 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900701 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900702 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900703
Jiyong Parkda6eb592018-12-19 17:12:36 +0900704 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900705
706 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
707 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
708}
709
Jooyung Hand3639552019-08-09 12:57:43 +0900710func TestApexWithRuntimeLibsDependency(t *testing.T) {
711 /*
712 myapex
713 |
714 v (runtime_libs)
715 mylib ------+------> libfoo [provides stub]
716 |
717 `------> libbar
718 */
719 ctx, _ := testApex(t, `
720 apex {
721 name: "myapex",
722 key: "myapex.key",
723 native_shared_libs: ["mylib"],
724 }
725
726 apex_key {
727 name: "myapex.key",
728 public_key: "testkey.avbpubkey",
729 private_key: "testkey.pem",
730 }
731
732 cc_library {
733 name: "mylib",
734 srcs: ["mylib.cpp"],
735 runtime_libs: ["libfoo", "libbar"],
736 system_shared_libs: [],
737 stl: "none",
738 }
739
740 cc_library {
741 name: "libfoo",
742 srcs: ["mylib.cpp"],
743 system_shared_libs: [],
744 stl: "none",
745 stubs: {
746 versions: ["10", "20", "30"],
747 },
748 }
749
750 cc_library {
751 name: "libbar",
752 srcs: ["mylib.cpp"],
753 system_shared_libs: [],
754 stl: "none",
755 }
756
757 `)
758
759 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
760 copyCmds := apexRule.Args["copy_commands"]
761
762 // Ensure that direct non-stubs dep is always included
763 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
764
765 // Ensure that indirect stubs dep is not included
766 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
767
768 // Ensure that runtime_libs dep in included
769 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
770
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900771 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
772 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
773 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900774
775}
776
Jooyung Han9c80bae2019-08-20 17:30:57 +0900777func TestApexDependencyToLLNDK(t *testing.T) {
778 ctx, _ := testApex(t, `
779 apex {
780 name: "myapex",
781 key: "myapex.key",
782 use_vendor: true,
783 native_shared_libs: ["mylib"],
784 }
785
786 apex_key {
787 name: "myapex.key",
788 public_key: "testkey.avbpubkey",
789 private_key: "testkey.pem",
790 }
791
792 cc_library {
793 name: "mylib",
794 srcs: ["mylib.cpp"],
795 vendor_available: true,
796 shared_libs: ["libbar"],
797 system_shared_libs: [],
798 stl: "none",
799 }
800
801 cc_library {
802 name: "libbar",
803 srcs: ["mylib.cpp"],
804 system_shared_libs: [],
805 stl: "none",
806 }
807
808 llndk_library {
809 name: "libbar",
810 symbol_file: "",
811 }
812
813 `)
814
815 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
816 copyCmds := apexRule.Args["copy_commands"]
817
818 // Ensure that LLNDK dep is not included
819 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
820
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900821 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
822 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900823
824 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900825 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900826
827}
828
Jiyong Park25fc6a92018-11-18 18:02:45 +0900829func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700830 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900831 apex {
832 name: "myapex",
833 key: "myapex.key",
834 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
835 }
836
837 apex_key {
838 name: "myapex.key",
839 public_key: "testkey.avbpubkey",
840 private_key: "testkey.pem",
841 }
842
843 cc_library {
844 name: "mylib",
845 srcs: ["mylib.cpp"],
846 shared_libs: ["libdl#27"],
847 stl: "none",
848 }
849
850 cc_library_shared {
851 name: "mylib_shared",
852 srcs: ["mylib.cpp"],
853 shared_libs: ["libdl#27"],
854 stl: "none",
855 }
856
857 cc_library {
858 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700859 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900860 nocrt: true,
861 system_shared_libs: [],
862 stl: "none",
863 stubs: {
864 versions: ["27", "28", "29"],
865 },
866 }
867
868 cc_library {
869 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700870 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900871 nocrt: true,
872 system_shared_libs: [],
873 stl: "none",
874 stubs: {
875 versions: ["27", "28", "29"],
876 },
877 }
878
879 cc_library {
880 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700881 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900882 nocrt: true,
883 system_shared_libs: [],
884 stl: "none",
885 stubs: {
886 versions: ["27", "28", "29"],
887 },
888 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900889
890 cc_library {
891 name: "libBootstrap",
892 srcs: ["mylib.cpp"],
893 stl: "none",
894 bootstrap: true,
895 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900896 `)
897
898 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
899 copyCmds := apexRule.Args["copy_commands"]
900
901 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800902 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900903 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
904 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900905
906 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900907 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900908
Jiyong Parkda6eb592018-12-19 17:12:36 +0900909 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
910 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
911 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900912
913 // For dependency to libc
914 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900915 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900916 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900917 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900918 // ... Cflags from stub is correctly exported to mylib
919 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
920 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
921
922 // For dependency to libm
923 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900924 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900926 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900927 // ... and is not compiling with the stub
928 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
929 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
930
931 // For dependency to libdl
932 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900933 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900934 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900935 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
936 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900938 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900939 // ... Cflags from stub is correctly exported to mylib
940 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
941 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900942
943 // Ensure that libBootstrap is depending on the platform variant of bionic libs
944 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
945 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
946 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
947 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900948}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900949
950func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700951 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900952 apex {
953 name: "myapex",
954 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900955 native_shared_libs: ["mylib"],
956 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900957 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900958 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900959 }
960
961 apex_key {
962 name: "myapex.key",
963 public_key: "testkey.avbpubkey",
964 private_key: "testkey.pem",
965 }
966
967 prebuilt_etc {
968 name: "myetc",
969 src: "myprebuilt",
970 sub_dir: "foo/bar",
971 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900972
973 cc_library {
974 name: "mylib",
975 srcs: ["mylib.cpp"],
976 relative_install_path: "foo/bar",
977 system_shared_libs: [],
978 stl: "none",
979 }
980
981 cc_binary {
982 name: "mybin",
983 srcs: ["mylib.cpp"],
984 relative_install_path: "foo/bar",
985 system_shared_libs: [],
986 static_executable: true,
987 stl: "none",
988 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900989 `)
990
991 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
992 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
993
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900994 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900995 ensureListContains(t, dirs, "etc")
996 ensureListContains(t, dirs, "etc/foo")
997 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900998 ensureListContains(t, dirs, "lib64")
999 ensureListContains(t, dirs, "lib64/foo")
1000 ensureListContains(t, dirs, "lib64/foo/bar")
1001 ensureListContains(t, dirs, "lib")
1002 ensureListContains(t, dirs, "lib/foo")
1003 ensureListContains(t, dirs, "lib/foo/bar")
1004
Jiyong Parkbd13e442019-03-15 18:10:35 +09001005 ensureListContains(t, dirs, "bin")
1006 ensureListContains(t, dirs, "bin/foo")
1007 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001008}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001009
1010func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001011 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001012 apex {
1013 name: "myapex",
1014 key: "myapex.key",
1015 native_shared_libs: ["mylib"],
1016 use_vendor: true,
1017 }
1018
1019 apex_key {
1020 name: "myapex.key",
1021 public_key: "testkey.avbpubkey",
1022 private_key: "testkey.pem",
1023 }
1024
1025 cc_library {
1026 name: "mylib",
1027 srcs: ["mylib.cpp"],
1028 shared_libs: ["mylib2"],
1029 system_shared_libs: [],
1030 vendor_available: true,
1031 stl: "none",
1032 }
1033
1034 cc_library {
1035 name: "mylib2",
1036 srcs: ["mylib.cpp"],
1037 system_shared_libs: [],
1038 vendor_available: true,
1039 stl: "none",
1040 }
1041 `)
1042
1043 inputsList := []string{}
1044 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
1045 for _, implicit := range i.Implicits {
1046 inputsList = append(inputsList, implicit.String())
1047 }
1048 }
1049 inputsString := strings.Join(inputsList, " ")
1050
1051 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001052 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1053 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001054
1055 // ensure that the apex does not include core variants
1056 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1057 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1058}
Jiyong Park16e91a02018-12-20 18:18:08 +09001059
Jooyung Han5c998b92019-06-27 11:30:33 +09001060func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1061 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1062 apex {
1063 name: "myapex",
1064 key: "myapex.key",
1065 native_shared_libs: ["mylib"],
1066 use_vendor: true,
1067 }
1068
1069 apex_key {
1070 name: "myapex.key",
1071 public_key: "testkey.avbpubkey",
1072 private_key: "testkey.pem",
1073 }
1074
1075 cc_library {
1076 name: "mylib",
1077 srcs: ["mylib.cpp"],
1078 system_shared_libs: [],
1079 stl: "none",
1080 }
1081 `)
1082}
1083
Jiyong Park16e91a02018-12-20 18:18:08 +09001084func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001085 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001086 apex {
1087 name: "myapex",
1088 key: "myapex.key",
1089 native_shared_libs: ["mylib"],
1090 }
1091
1092 apex_key {
1093 name: "myapex.key",
1094 public_key: "testkey.avbpubkey",
1095 private_key: "testkey.pem",
1096 }
1097
1098 cc_library {
1099 name: "mylib",
1100 srcs: ["mylib.cpp"],
1101 system_shared_libs: [],
1102 stl: "none",
1103 stubs: {
1104 versions: ["1", "2", "3"],
1105 },
1106 }
1107
1108 cc_binary {
1109 name: "not_in_apex",
1110 srcs: ["mylib.cpp"],
1111 static_libs: ["mylib"],
1112 static_executable: true,
1113 system_shared_libs: [],
1114 stl: "none",
1115 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001116 `)
1117
1118 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1119
1120 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001121 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001122}
Jiyong Park9335a262018-12-24 11:31:58 +09001123
1124func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001125 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001126 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001127 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001128 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001129 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001130 native_shared_libs: ["mylib"],
1131 }
1132
1133 cc_library {
1134 name: "mylib",
1135 srcs: ["mylib.cpp"],
1136 system_shared_libs: [],
1137 stl: "none",
1138 }
1139
1140 apex_key {
1141 name: "myapex.key",
1142 public_key: "testkey.avbpubkey",
1143 private_key: "testkey.pem",
1144 }
1145
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001146 android_app_certificate {
1147 name: "myapex.certificate",
1148 certificate: "testkey",
1149 }
1150
1151 android_app_certificate {
1152 name: "myapex.certificate.override",
1153 certificate: "testkey.override",
1154 }
1155
Jiyong Park9335a262018-12-24 11:31:58 +09001156 `)
1157
1158 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001159 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001160
1161 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1162 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1163 "vendor/foo/devkeys/testkey.avbpubkey")
1164 }
1165 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1166 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1167 "vendor/foo/devkeys/testkey.pem")
1168 }
1169
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001170 // check the APK certs. It should be overridden to myapex.certificate.override
1171 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
1172 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001173 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001174 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001175 }
1176}
Jiyong Park58e364a2019-01-19 19:24:06 +09001177
1178func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001179 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001180 apex {
1181 name: "myapex",
1182 key: "myapex.key",
1183 native_shared_libs: ["mylib"],
1184 }
1185
1186 apex {
1187 name: "otherapex",
1188 key: "myapex.key",
1189 native_shared_libs: ["mylib"],
1190 }
1191
1192 apex_key {
1193 name: "myapex.key",
1194 public_key: "testkey.avbpubkey",
1195 private_key: "testkey.pem",
1196 }
1197
1198 cc_library {
1199 name: "mylib",
1200 srcs: ["mylib.cpp"],
1201 system_shared_libs: [],
1202 stl: "none",
1203 }
1204 `)
1205
1206 // non-APEX variant does not have __ANDROID__APEX__ defined
1207 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1208 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1209 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1210
1211 // APEX variant has __ANDROID_APEX__=<apexname> defined
1212 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1213 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1214 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1215
1216 // APEX variant has __ANDROID_APEX__=<apexname> defined
1217 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1218 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1219 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1220}
Jiyong Park7e636d02019-01-28 16:16:54 +09001221
1222func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001223 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001224 apex {
1225 name: "myapex",
1226 key: "myapex.key",
1227 native_shared_libs: ["mylib"],
1228 }
1229
1230 apex_key {
1231 name: "myapex.key",
1232 public_key: "testkey.avbpubkey",
1233 private_key: "testkey.pem",
1234 }
1235
1236 cc_library_headers {
1237 name: "mylib_headers",
1238 export_include_dirs: ["my_include"],
1239 system_shared_libs: [],
1240 stl: "none",
1241 }
1242
1243 cc_library {
1244 name: "mylib",
1245 srcs: ["mylib.cpp"],
1246 system_shared_libs: [],
1247 stl: "none",
1248 header_libs: ["mylib_headers"],
1249 export_header_lib_headers: ["mylib_headers"],
1250 stubs: {
1251 versions: ["1", "2", "3"],
1252 },
1253 }
1254
1255 cc_library {
1256 name: "otherlib",
1257 srcs: ["mylib.cpp"],
1258 system_shared_libs: [],
1259 stl: "none",
1260 shared_libs: ["mylib"],
1261 }
1262 `)
1263
1264 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1265
1266 // Ensure that the include path of the header lib is exported to 'otherlib'
1267 ensureContains(t, cFlags, "-Imy_include")
1268}
Alex Light9670d332019-01-29 18:07:33 -08001269
Jooyung Han344d5432019-08-23 11:17:39 +09001270func TestVndkApexCurrent(t *testing.T) {
1271 ctx, _ := testApex(t, `
1272 apex_vndk {
1273 name: "myapex",
1274 key: "myapex.key",
1275 file_contexts: "myapex",
1276 }
1277
1278 apex_key {
1279 name: "myapex.key",
1280 public_key: "testkey.avbpubkey",
1281 private_key: "testkey.pem",
1282 }
1283
1284 cc_library {
1285 name: "libvndk",
1286 srcs: ["mylib.cpp"],
1287 vendor_available: true,
1288 vndk: {
1289 enabled: true,
1290 },
1291 system_shared_libs: [],
1292 stl: "none",
1293 }
1294
1295 cc_library {
1296 name: "libvndksp",
1297 srcs: ["mylib.cpp"],
1298 vendor_available: true,
1299 vndk: {
1300 enabled: true,
1301 support_system_process: true,
1302 },
1303 system_shared_libs: [],
1304 stl: "none",
1305 }
1306 `)
1307
1308 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1309 copyCmds := apexRule.Args["copy_commands"]
1310 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1311 ensureContains(t, copyCmds, "image.apex/lib/libvndksp.so")
1312 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1313 ensureContains(t, copyCmds, "image.apex/lib64/libvndksp.so")
1314}
1315
1316func TestVndkApexWithPrebuilt(t *testing.T) {
1317 ctx, _ := testApex(t, `
1318 apex_vndk {
1319 name: "myapex",
1320 key: "myapex.key",
1321 file_contexts: "myapex",
1322 }
1323
1324 apex_key {
1325 name: "myapex.key",
1326 public_key: "testkey.avbpubkey",
1327 private_key: "testkey.pem",
1328 }
1329
1330 cc_prebuilt_library_shared {
1331 name: "libvndkshared",
1332 srcs: ["libvndkshared.so"],
1333 vendor_available: true,
1334 vndk: {
1335 enabled: true,
1336 },
1337 system_shared_libs: [],
1338 stl: "none",
1339 }
1340 `, withFiles(map[string][]byte{
1341 "libvndkshared.so": nil,
1342 }))
1343
1344 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1345 copyCmds := apexRule.Args["copy_commands"]
1346 ensureContains(t, copyCmds, "image.apex/lib/libvndkshared.so")
1347}
1348
1349func TestVndkApexVersion(t *testing.T) {
1350 ctx, _ := testApex(t, `
1351 apex_vndk {
1352 name: "myapex_v27",
1353 key: "myapex.key",
1354 file_contexts: "myapex",
1355 vndk_version: "27",
1356 }
1357
1358 apex_key {
1359 name: "myapex.key",
1360 public_key: "testkey.avbpubkey",
1361 private_key: "testkey.pem",
1362 }
1363
1364 cc_library {
1365 name: "libvndk",
1366 srcs: ["mylib.cpp"],
1367 vendor_available: true,
1368 vndk: {
1369 enabled: true,
1370 },
1371 system_shared_libs: [],
1372 stl: "none",
1373 }
1374
1375 vndk_prebuilt_shared {
1376 name: "libvndk27",
1377 version: "27",
1378 vendor_available: true,
1379 vndk: {
1380 enabled: true,
1381 },
Colin Crossff6c33d2019-10-02 16:01:35 -07001382 target_arch: "arm64",
Jooyung Han344d5432019-08-23 11:17:39 +09001383 srcs: ["libvndk27.so"],
1384 }
1385 `, withFiles(map[string][]byte{
1386 "libvndk27.so": nil,
1387 }))
1388
1389 apexRule := ctx.ModuleForTests("myapex_v27", "android_common_myapex_v27").Rule("apexRule")
1390 copyCmds := apexRule.Args["copy_commands"]
1391 ensureContains(t, copyCmds, "image.apex/lib/libvndk27.so")
1392 ensureContains(t, copyCmds, "image.apex/lib64/libvndk27.so")
1393 ensureNotContains(t, copyCmds, "image.apex/lib/libvndk.so")
1394}
1395
1396func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1397 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1398 apex_vndk {
1399 name: "myapex_v27",
1400 key: "myapex.key",
1401 file_contexts: "myapex",
1402 vndk_version: "27",
1403 }
1404 apex_vndk {
1405 name: "myapex_v27_other",
1406 key: "myapex.key",
1407 file_contexts: "myapex",
1408 vndk_version: "27",
1409 }
1410
1411 apex_key {
1412 name: "myapex.key",
1413 public_key: "testkey.avbpubkey",
1414 private_key: "testkey.pem",
1415 }
1416
1417 cc_library {
1418 name: "libvndk",
1419 srcs: ["mylib.cpp"],
1420 vendor_available: true,
1421 vndk: {
1422 enabled: true,
1423 },
1424 system_shared_libs: [],
1425 stl: "none",
1426 }
1427
1428 vndk_prebuilt_shared {
1429 name: "libvndk",
1430 version: "27",
1431 vendor_available: true,
1432 vndk: {
1433 enabled: true,
1434 },
1435 srcs: ["libvndk.so"],
1436 }
1437 `, withFiles(map[string][]byte{
1438 "libvndk.so": nil,
1439 }))
1440}
1441
Jooyung Han90eee022019-10-01 20:02:42 +09001442func TestVndkApexNameRule(t *testing.T) {
1443 ctx, _ := testApex(t, `
1444 apex_vndk {
1445 name: "myapex",
1446 key: "myapex.key",
1447 file_contexts: "myapex",
1448 }
1449 apex_vndk {
1450 name: "myapex_v28",
1451 key: "myapex.key",
1452 file_contexts: "myapex",
1453 vndk_version: "28",
1454 }
1455 apex_key {
1456 name: "myapex.key",
1457 public_key: "testkey.avbpubkey",
1458 private_key: "testkey.pem",
1459 }`)
1460
1461 assertApexName := func(expected, moduleName string) {
1462 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Module().(*apexBundle)
1463 actual := proptools.String(bundle.properties.Apex_name)
1464 if !reflect.DeepEqual(actual, expected) {
1465 t.Errorf("Got '%v', expected '%v'", actual, expected)
1466 }
1467 }
1468
1469 assertApexName("com.android.vndk.vVER", "myapex")
1470 assertApexName("com.android.vndk.v28", "myapex_v28")
1471}
1472
Jooyung Han344d5432019-08-23 11:17:39 +09001473func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1474 ctx, _ := testApex(t, `
1475 apex_vndk {
1476 name: "myapex",
1477 key: "myapex.key",
1478 file_contexts: "myapex",
1479 }
1480
1481 apex_key {
1482 name: "myapex.key",
1483 public_key: "testkey.avbpubkey",
1484 private_key: "testkey.pem",
1485 }
1486
1487 cc_library {
1488 name: "libvndk",
1489 srcs: ["mylib.cpp"],
1490 vendor_available: true,
1491 native_bridge_supported: true,
1492 host_supported: true,
1493 vndk: {
1494 enabled: true,
1495 },
1496 system_shared_libs: [],
1497 stl: "none",
1498 }
1499 `, withTargets(map[android.OsType][]android.Target{
1500 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001501 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1502 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1503 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1504 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
Jooyung Han344d5432019-08-23 11:17:39 +09001505 },
1506 }))
1507
1508 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1509 copyCmds := apexRule.Args["copy_commands"]
1510 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1511 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1512
1513 // apex
1514 ensureNotContains(t, copyCmds, "image.apex/lib/x86/libvndk.so")
1515 ensureNotContains(t, copyCmds, "image.apex/lib64/x86_64/libvndk.so")
1516}
1517
1518func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1519 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1520 apex_vndk {
1521 name: "myapex",
1522 key: "myapex.key",
1523 file_contexts: "myapex",
1524 native_bridge_supported: true,
1525 }
1526
1527 apex_key {
1528 name: "myapex.key",
1529 public_key: "testkey.avbpubkey",
1530 private_key: "testkey.pem",
1531 }
1532
1533 cc_library {
1534 name: "libvndk",
1535 srcs: ["mylib.cpp"],
1536 vendor_available: true,
1537 native_bridge_supported: true,
1538 host_supported: true,
1539 vndk: {
1540 enabled: true,
1541 },
1542 system_shared_libs: [],
1543 stl: "none",
1544 }
1545 `)
1546}
1547
Jooyung Hane1633032019-08-01 17:41:43 +09001548func TestDependenciesInApexManifest(t *testing.T) {
1549 ctx, _ := testApex(t, `
1550 apex {
1551 name: "myapex_nodep",
1552 key: "myapex.key",
1553 native_shared_libs: ["lib_nodep"],
1554 compile_multilib: "both",
1555 file_contexts: "myapex",
1556 }
1557
1558 apex {
1559 name: "myapex_dep",
1560 key: "myapex.key",
1561 native_shared_libs: ["lib_dep"],
1562 compile_multilib: "both",
1563 file_contexts: "myapex",
1564 }
1565
1566 apex {
1567 name: "myapex_provider",
1568 key: "myapex.key",
1569 native_shared_libs: ["libfoo"],
1570 compile_multilib: "both",
1571 file_contexts: "myapex",
1572 }
1573
1574 apex {
1575 name: "myapex_selfcontained",
1576 key: "myapex.key",
1577 native_shared_libs: ["lib_dep", "libfoo"],
1578 compile_multilib: "both",
1579 file_contexts: "myapex",
1580 }
1581
1582 apex_key {
1583 name: "myapex.key",
1584 public_key: "testkey.avbpubkey",
1585 private_key: "testkey.pem",
1586 }
1587
1588 cc_library {
1589 name: "lib_nodep",
1590 srcs: ["mylib.cpp"],
1591 system_shared_libs: [],
1592 stl: "none",
1593 }
1594
1595 cc_library {
1596 name: "lib_dep",
1597 srcs: ["mylib.cpp"],
1598 shared_libs: ["libfoo"],
1599 system_shared_libs: [],
1600 stl: "none",
1601 }
1602
1603 cc_library {
1604 name: "libfoo",
1605 srcs: ["mytest.cpp"],
1606 stubs: {
1607 versions: ["1"],
1608 },
1609 system_shared_libs: [],
1610 stl: "none",
1611 }
1612 `)
1613
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001614 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001615 var provideNativeLibs, requireNativeLibs []string
1616
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001617 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("apexManifestRule")
1618 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1619 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001620 ensureListEmpty(t, provideNativeLibs)
1621 ensureListEmpty(t, requireNativeLibs)
1622
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001623 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("apexManifestRule")
1624 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1625 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001626 ensureListEmpty(t, provideNativeLibs)
1627 ensureListContains(t, requireNativeLibs, "libfoo.so")
1628
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001629 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("apexManifestRule")
1630 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1631 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001632 ensureListContains(t, provideNativeLibs, "libfoo.so")
1633 ensureListEmpty(t, requireNativeLibs)
1634
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001635 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("apexManifestRule")
1636 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1637 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001638 ensureListContains(t, provideNativeLibs, "libfoo.so")
1639 ensureListEmpty(t, requireNativeLibs)
1640}
1641
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001642func TestApexName(t *testing.T) {
1643 ctx, _ := testApex(t, `
1644 apex {
1645 name: "myapex",
1646 key: "myapex.key",
1647 apex_name: "com.android.myapex",
1648 }
1649
1650 apex_key {
1651 name: "myapex.key",
1652 public_key: "testkey.avbpubkey",
1653 private_key: "testkey.pem",
1654 }
1655 `)
1656
1657 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1658 apexManifestRule := module.Rule("apexManifestRule")
1659 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1660 apexRule := module.Rule("apexRule")
1661 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1662}
1663
Alex Light0851b882019-02-07 13:20:53 -08001664func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001665 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001666 apex {
1667 name: "myapex",
1668 key: "myapex.key",
1669 native_shared_libs: ["mylib_common"],
1670 }
1671
1672 apex_key {
1673 name: "myapex.key",
1674 public_key: "testkey.avbpubkey",
1675 private_key: "testkey.pem",
1676 }
1677
1678 cc_library {
1679 name: "mylib_common",
1680 srcs: ["mylib.cpp"],
1681 system_shared_libs: [],
1682 stl: "none",
1683 }
1684 `)
1685
1686 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1687 apexRule := module.Rule("apexRule")
1688 copyCmds := apexRule.Args["copy_commands"]
1689
1690 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1691 t.Log("Apex was a test apex!")
1692 t.Fail()
1693 }
1694 // Ensure that main rule creates an output
1695 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1696
1697 // Ensure that apex variant is created for the direct dep
1698 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1699
1700 // Ensure that both direct and indirect deps are copied into apex
1701 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1702
1703 // Ensure that the platform variant ends with _core_shared
1704 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1705
1706 if !android.InAnyApex("mylib_common") {
1707 t.Log("Found mylib_common not in any apex!")
1708 t.Fail()
1709 }
1710}
1711
1712func TestTestApex(t *testing.T) {
1713 if android.InAnyApex("mylib_common_test") {
1714 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!")
1715 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001716 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001717 apex_test {
1718 name: "myapex",
1719 key: "myapex.key",
1720 native_shared_libs: ["mylib_common_test"],
1721 }
1722
1723 apex_key {
1724 name: "myapex.key",
1725 public_key: "testkey.avbpubkey",
1726 private_key: "testkey.pem",
1727 }
1728
1729 cc_library {
1730 name: "mylib_common_test",
1731 srcs: ["mylib.cpp"],
1732 system_shared_libs: [],
1733 stl: "none",
1734 }
1735 `)
1736
1737 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1738 apexRule := module.Rule("apexRule")
1739 copyCmds := apexRule.Args["copy_commands"]
1740
1741 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1742 t.Log("Apex was not a test apex!")
1743 t.Fail()
1744 }
1745 // Ensure that main rule creates an output
1746 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1747
1748 // Ensure that apex variant is created for the direct dep
1749 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1750
1751 // Ensure that both direct and indirect deps are copied into apex
1752 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1753
1754 // Ensure that the platform variant ends with _core_shared
1755 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1756
1757 if android.InAnyApex("mylib_common_test") {
1758 t.Log("Found mylib_common_test in some apex!")
1759 t.Fail()
1760 }
1761}
1762
Alex Light9670d332019-01-29 18:07:33 -08001763func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001764 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001765 apex {
1766 name: "myapex",
1767 key: "myapex.key",
1768 multilib: {
1769 first: {
1770 native_shared_libs: ["mylib_common"],
1771 }
1772 },
1773 target: {
1774 android: {
1775 multilib: {
1776 first: {
1777 native_shared_libs: ["mylib"],
1778 }
1779 }
1780 },
1781 host: {
1782 multilib: {
1783 first: {
1784 native_shared_libs: ["mylib2"],
1785 }
1786 }
1787 }
1788 }
1789 }
1790
1791 apex_key {
1792 name: "myapex.key",
1793 public_key: "testkey.avbpubkey",
1794 private_key: "testkey.pem",
1795 }
1796
1797 cc_library {
1798 name: "mylib",
1799 srcs: ["mylib.cpp"],
1800 system_shared_libs: [],
1801 stl: "none",
1802 }
1803
1804 cc_library {
1805 name: "mylib_common",
1806 srcs: ["mylib.cpp"],
1807 system_shared_libs: [],
1808 stl: "none",
1809 compile_multilib: "first",
1810 }
1811
1812 cc_library {
1813 name: "mylib2",
1814 srcs: ["mylib.cpp"],
1815 system_shared_libs: [],
1816 stl: "none",
1817 compile_multilib: "first",
1818 }
1819 `)
1820
1821 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1822 copyCmds := apexRule.Args["copy_commands"]
1823
1824 // Ensure that main rule creates an output
1825 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1826
1827 // Ensure that apex variant is created for the direct dep
1828 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1829 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1830 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1831
1832 // Ensure that both direct and indirect deps are copied into apex
1833 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1834 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1835 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1836
1837 // Ensure that the platform variant ends with _core_shared
1838 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1839 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1840 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1841}
Jiyong Park04480cf2019-02-06 00:16:29 +09001842
1843func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001844 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001845 apex {
1846 name: "myapex",
1847 key: "myapex.key",
1848 binaries: ["myscript"],
1849 }
1850
1851 apex_key {
1852 name: "myapex.key",
1853 public_key: "testkey.avbpubkey",
1854 private_key: "testkey.pem",
1855 }
1856
1857 sh_binary {
1858 name: "myscript",
1859 src: "mylib.cpp",
1860 filename: "myscript.sh",
1861 sub_dir: "script",
1862 }
1863 `)
1864
1865 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1866 copyCmds := apexRule.Args["copy_commands"]
1867
1868 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1869}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001870
1871func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001872 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001873 apex {
1874 name: "myapex",
1875 key: "myapex.key",
1876 native_shared_libs: ["mylib"],
1877 product_specific: true,
1878 }
1879
1880 apex_key {
1881 name: "myapex.key",
1882 public_key: "testkey.avbpubkey",
1883 private_key: "testkey.pem",
1884 product_specific: true,
1885 }
1886
1887 cc_library {
1888 name: "mylib",
1889 srcs: ["mylib.cpp"],
1890 system_shared_libs: [],
1891 stl: "none",
1892 }
1893 `)
1894
1895 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07001896 expected := buildDir + "/target/product/test_device/product/apex"
1897 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001898 if actual != expected {
1899 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1900 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001901}
Jiyong Park67882562019-03-21 01:11:21 +09001902
1903func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001904 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001905 apex_key {
1906 name: "myapex.key",
1907 public_key: ":my.avbpubkey",
1908 private_key: ":my.pem",
1909 product_specific: true,
1910 }
1911
1912 filegroup {
1913 name: "my.avbpubkey",
1914 srcs: ["testkey2.avbpubkey"],
1915 }
1916
1917 filegroup {
1918 name: "my.pem",
1919 srcs: ["testkey2.pem"],
1920 }
1921 `)
1922
1923 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1924 expected_pubkey := "testkey2.avbpubkey"
1925 actual_pubkey := apex_key.public_key_file.String()
1926 if actual_pubkey != expected_pubkey {
1927 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1928 }
1929 expected_privkey := "testkey2.pem"
1930 actual_privkey := apex_key.private_key_file.String()
1931 if actual_privkey != expected_privkey {
1932 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1933 }
1934}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001935
1936func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001937 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001938 prebuilt_apex {
1939 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001940 arch: {
1941 arm64: {
1942 src: "myapex-arm64.apex",
1943 },
1944 arm: {
1945 src: "myapex-arm.apex",
1946 },
1947 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001948 }
1949 `)
1950
1951 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1952
Jiyong Parkc95714e2019-03-29 14:23:10 +09001953 expectedInput := "myapex-arm64.apex"
1954 if prebuilt.inputApex.String() != expectedInput {
1955 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1956 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001957}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001958
1959func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001960 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001961 prebuilt_apex {
1962 name: "myapex",
1963 src: "myapex-arm.apex",
1964 filename: "notmyapex.apex",
1965 }
1966 `)
1967
1968 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1969
1970 expected := "notmyapex.apex"
1971 if p.installFilename != expected {
1972 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1973 }
1974}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001975
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001976func TestPrebuiltOverrides(t *testing.T) {
1977 ctx, config := testApex(t, `
1978 prebuilt_apex {
1979 name: "myapex.prebuilt",
1980 src: "myapex-arm.apex",
1981 overrides: [
1982 "myapex",
1983 ],
1984 }
1985 `)
1986
1987 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1988
1989 expected := []string{"myapex"}
1990 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1991 if !reflect.DeepEqual(actual, expected) {
1992 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1993 }
1994}
1995
Roland Levillain630846d2019-06-26 12:48:34 +01001996func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001997 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01001998 apex_test {
1999 name: "myapex",
2000 key: "myapex.key",
2001 tests: [
2002 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002003 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002004 ],
2005 }
2006
2007 apex_key {
2008 name: "myapex.key",
2009 public_key: "testkey.avbpubkey",
2010 private_key: "testkey.pem",
2011 }
2012
2013 cc_test {
2014 name: "mytest",
2015 gtest: false,
2016 srcs: ["mytest.cpp"],
2017 relative_install_path: "test",
2018 system_shared_libs: [],
2019 static_executable: true,
2020 stl: "none",
2021 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002022
2023 cc_test {
2024 name: "mytests",
2025 gtest: false,
2026 srcs: [
2027 "mytest1.cpp",
2028 "mytest2.cpp",
2029 "mytest3.cpp",
2030 ],
2031 test_per_src: true,
2032 relative_install_path: "test",
2033 system_shared_libs: [],
2034 static_executable: true,
2035 stl: "none",
2036 }
Roland Levillain630846d2019-06-26 12:48:34 +01002037 `)
2038
2039 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2040 copyCmds := apexRule.Args["copy_commands"]
2041
2042 // Ensure that test dep is copied into apex.
2043 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002044
2045 // Ensure that test deps built with `test_per_src` are copied into apex.
2046 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2047 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2048 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002049
2050 // Ensure the module is correctly translated.
2051 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
2052 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2053 name := apexBundle.BaseModuleName()
2054 prefix := "TARGET_"
2055 var builder strings.Builder
2056 data.Custom(&builder, name, prefix, "", data)
2057 androidMk := builder.String()
2058 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest\n")
2059 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest1\n")
2060 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest2\n")
2061 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest3\n")
2062 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_manifest.json\n")
2063 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_pubkey\n")
2064 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002065}
2066
Jooyung Han5c998b92019-06-27 11:30:33 +09002067func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002068 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002069 apex {
2070 name: "myapex",
2071 key: "myapex.key",
2072 native_shared_libs: ["mylib"],
2073 uses: ["commonapex"],
2074 }
2075
2076 apex {
2077 name: "commonapex",
2078 key: "myapex.key",
2079 native_shared_libs: ["libcommon"],
2080 provide_cpp_shared_libs: true,
2081 }
2082
2083 apex_key {
2084 name: "myapex.key",
2085 public_key: "testkey.avbpubkey",
2086 private_key: "testkey.pem",
2087 }
2088
2089 cc_library {
2090 name: "mylib",
2091 srcs: ["mylib.cpp"],
2092 shared_libs: ["libcommon"],
2093 system_shared_libs: [],
2094 stl: "none",
2095 }
2096
2097 cc_library {
2098 name: "libcommon",
2099 srcs: ["mylib_common.cpp"],
2100 system_shared_libs: [],
2101 stl: "none",
2102 }
2103 `)
2104
2105 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2106 apexRule1 := module1.Rule("apexRule")
2107 copyCmds1 := apexRule1.Args["copy_commands"]
2108
2109 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2110 apexRule2 := module2.Rule("apexRule")
2111 copyCmds2 := apexRule2.Args["copy_commands"]
2112
2113 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2114 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2115 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2116 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2117 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2118}
2119
2120func TestApexUsesFailsIfNotProvided(t *testing.T) {
2121 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2122 apex {
2123 name: "myapex",
2124 key: "myapex.key",
2125 uses: ["commonapex"],
2126 }
2127
2128 apex {
2129 name: "commonapex",
2130 key: "myapex.key",
2131 }
2132
2133 apex_key {
2134 name: "myapex.key",
2135 public_key: "testkey.avbpubkey",
2136 private_key: "testkey.pem",
2137 }
2138 `)
2139 testApexError(t, `uses: "commonapex" is not a provider`, `
2140 apex {
2141 name: "myapex",
2142 key: "myapex.key",
2143 uses: ["commonapex"],
2144 }
2145
2146 cc_library {
2147 name: "commonapex",
2148 system_shared_libs: [],
2149 stl: "none",
2150 }
2151
2152 apex_key {
2153 name: "myapex.key",
2154 public_key: "testkey.avbpubkey",
2155 private_key: "testkey.pem",
2156 }
2157 `)
2158}
2159
2160func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2161 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2162 apex {
2163 name: "myapex",
2164 key: "myapex.key",
2165 use_vendor: true,
2166 uses: ["commonapex"],
2167 }
2168
2169 apex {
2170 name: "commonapex",
2171 key: "myapex.key",
2172 provide_cpp_shared_libs: true,
2173 }
2174
2175 apex_key {
2176 name: "myapex.key",
2177 public_key: "testkey.avbpubkey",
2178 private_key: "testkey.pem",
2179 }
2180 `)
2181}
2182
Jooyung Hand48f3c32019-08-23 11:18:57 +09002183func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2184 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2185 apex {
2186 name: "myapex",
2187 key: "myapex.key",
2188 native_shared_libs: ["libfoo"],
2189 }
2190
2191 apex_key {
2192 name: "myapex.key",
2193 public_key: "testkey.avbpubkey",
2194 private_key: "testkey.pem",
2195 }
2196
2197 cc_library {
2198 name: "libfoo",
2199 stl: "none",
2200 system_shared_libs: [],
2201 enabled: false,
2202 }
2203 `)
2204 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2205 apex {
2206 name: "myapex",
2207 key: "myapex.key",
2208 java_libs: ["myjar"],
2209 }
2210
2211 apex_key {
2212 name: "myapex.key",
2213 public_key: "testkey.avbpubkey",
2214 private_key: "testkey.pem",
2215 }
2216
2217 java_library {
2218 name: "myjar",
2219 srcs: ["foo/bar/MyClass.java"],
2220 sdk_version: "none",
2221 system_modules: "none",
2222 compile_dex: true,
2223 enabled: false,
2224 }
2225 `)
2226}
2227
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002228func TestApexWithApps(t *testing.T) {
2229 ctx, _ := testApex(t, `
2230 apex {
2231 name: "myapex",
2232 key: "myapex.key",
2233 apps: [
2234 "AppFoo",
2235 ],
2236 }
2237
2238 apex_key {
2239 name: "myapex.key",
2240 public_key: "testkey.avbpubkey",
2241 private_key: "testkey.pem",
2242 }
2243
2244 android_app {
2245 name: "AppFoo",
2246 srcs: ["foo/bar/MyClass.java"],
2247 sdk_version: "none",
2248 system_modules: "none",
2249 }
2250 `)
2251
2252 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2253 apexRule := module.Rule("apexRule")
2254 copyCmds := apexRule.Args["copy_commands"]
2255
2256 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
2257
2258}
2259
Jiyong Park127b40b2019-09-30 16:04:35 +09002260func TestApexAvailable(t *testing.T) {
2261 // libfoo is not available to myapex, but only to otherapex
2262 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2263 apex {
2264 name: "myapex",
2265 key: "myapex.key",
2266 native_shared_libs: ["libfoo"],
2267 }
2268
2269 apex_key {
2270 name: "myapex.key",
2271 public_key: "testkey.avbpubkey",
2272 private_key: "testkey.pem",
2273 }
2274
2275 apex {
2276 name: "otherapex",
2277 key: "otherapex.key",
2278 native_shared_libs: ["libfoo"],
2279 }
2280
2281 apex_key {
2282 name: "otherapex.key",
2283 public_key: "testkey.avbpubkey",
2284 private_key: "testkey.pem",
2285 }
2286
2287 cc_library {
2288 name: "libfoo",
2289 stl: "none",
2290 system_shared_libs: [],
2291 apex_available: ["otherapex"],
2292 }`)
2293
2294 // libbar is an indirect dep
2295 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2296 apex {
2297 name: "myapex",
2298 key: "myapex.key",
2299 native_shared_libs: ["libfoo"],
2300 }
2301
2302 apex_key {
2303 name: "myapex.key",
2304 public_key: "testkey.avbpubkey",
2305 private_key: "testkey.pem",
2306 }
2307
2308 apex {
2309 name: "otherapex",
2310 key: "otherapex.key",
2311 native_shared_libs: ["libfoo"],
2312 }
2313
2314 apex_key {
2315 name: "otherapex.key",
2316 public_key: "testkey.avbpubkey",
2317 private_key: "testkey.pem",
2318 }
2319
2320 cc_library {
2321 name: "libfoo",
2322 stl: "none",
2323 shared_libs: ["libbar"],
2324 system_shared_libs: [],
2325 apex_available: ["myapex", "otherapex"],
2326 }
2327
2328 cc_library {
2329 name: "libbar",
2330 stl: "none",
2331 system_shared_libs: [],
2332 apex_available: ["otherapex"],
2333 }`)
2334
2335 testApexError(t, "\"otherapex\" is not a valid module name", `
2336 apex {
2337 name: "myapex",
2338 key: "myapex.key",
2339 native_shared_libs: ["libfoo"],
2340 }
2341
2342 apex_key {
2343 name: "myapex.key",
2344 public_key: "testkey.avbpubkey",
2345 private_key: "testkey.pem",
2346 }
2347
2348 cc_library {
2349 name: "libfoo",
2350 stl: "none",
2351 system_shared_libs: [],
2352 apex_available: ["otherapex"],
2353 }`)
2354
2355 ctx, _ := testApex(t, `
2356 apex {
2357 name: "myapex",
2358 key: "myapex.key",
2359 native_shared_libs: ["libfoo", "libbar"],
2360 }
2361
2362 apex_key {
2363 name: "myapex.key",
2364 public_key: "testkey.avbpubkey",
2365 private_key: "testkey.pem",
2366 }
2367
2368 cc_library {
2369 name: "libfoo",
2370 stl: "none",
2371 system_shared_libs: [],
2372 apex_available: ["myapex"],
2373 }
2374
2375 cc_library {
2376 name: "libbar",
2377 stl: "none",
2378 system_shared_libs: [],
2379 apex_available: ["//apex_available:anyapex"],
2380 }`)
2381
2382 // check that libfoo and libbar are created only for myapex, but not for the platform
2383 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2384 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2385 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2386 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2387
2388 ctx, _ = testApex(t, `
2389 apex {
2390 name: "myapex",
2391 key: "myapex.key",
2392 }
2393
2394 apex_key {
2395 name: "myapex.key",
2396 public_key: "testkey.avbpubkey",
2397 private_key: "testkey.pem",
2398 }
2399
2400 cc_library {
2401 name: "libfoo",
2402 stl: "none",
2403 system_shared_libs: [],
2404 apex_available: ["//apex_available:platform"],
2405 }`)
2406
2407 // check that libfoo is created only for the platform
2408 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2409 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09002410
2411 ctx, _ = testApex(t, `
2412 apex {
2413 name: "myapex",
2414 key: "myapex.key",
2415 native_shared_libs: ["libfoo"],
2416 }
2417
2418 apex_key {
2419 name: "myapex.key",
2420 public_key: "testkey.avbpubkey",
2421 private_key: "testkey.pem",
2422 }
2423
2424 cc_library {
2425 name: "libfoo",
2426 stl: "none",
2427 system_shared_libs: [],
2428 apex_available: ["myapex"],
2429 static: {
2430 apex_available: ["//apex_available:platform"],
2431 },
2432 }`)
2433
2434 // shared variant of libfoo is only available to myapex
2435 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2436 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2437 // but the static variant is available to both myapex and the platform
2438 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
2439 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09002440}
2441
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002442func TestMain(m *testing.M) {
2443 run := func() int {
2444 setUp()
2445 defer tearDown()
2446
2447 return m.Run()
2448 }
2449
2450 os.Exit(run())
2451}