blob: 5f4cfac3f7877944a6603bdc778533040ddd5afc [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"
Jooyung Han394951d2019-10-07 15:34:50 +090021 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090022 "strings"
23 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090024
25 "github.com/google/blueprint/proptools"
26
27 "android/soong/android"
28 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090029 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090030)
31
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070032var buildDir string
33
Jooyung Hand3639552019-08-09 12:57:43 +090034// names returns name list from white space separated string
35func names(s string) (ns []string) {
36 for _, n := range strings.Split(s, " ") {
37 if len(n) > 0 {
38 ns = append(ns, n)
39 }
40 }
41 return
42}
43
Jooyung Han344d5432019-08-23 11:17:39 +090044func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
45 t.Helper()
46 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090047 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
48 if len(errs) > 0 {
49 android.FailIfNoMatchingErrors(t, pattern, errs)
50 return
51 }
52 _, errs = ctx.PrepareBuildActions(config)
53 if len(errs) > 0 {
54 android.FailIfNoMatchingErrors(t, pattern, errs)
55 return
56 }
57
58 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
59}
60
Jooyung Han344d5432019-08-23 11:17:39 +090061func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
62 t.Helper()
63 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090064 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
65 android.FailIfErrored(t, errs)
66 _, errs = ctx.PrepareBuildActions(config)
67 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070068 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090069}
70
Jooyung Han344d5432019-08-23 11:17:39 +090071type testCustomizer func(fs map[string][]byte, config android.Config)
72
73func withFiles(files map[string][]byte) testCustomizer {
74 return func(fs map[string][]byte, config android.Config) {
75 for k, v := range files {
76 fs[k] = v
77 }
78 }
79}
80
81func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
82 return func(fs map[string][]byte, config android.Config) {
83 for k, v := range targets {
84 config.Targets[k] = v
85 }
86 }
87}
88
Jooyung Han394951d2019-10-07 15:34:50 +090089func withBinder32bit(fs map[string][]byte, config android.Config) {
90 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
91}
92
Jooyung Han344d5432019-08-23 11:17:39 +090093func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070094 config := android.TestArchConfig(buildDir, nil)
95 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
96 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
97 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
98 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
99 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jooyung Han344d5432019-08-23 11:17:39 +0900100 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101
102 ctx := android.NewTestArchContext()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900103 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(BundleFactory))
Alex Light0851b882019-02-07 13:20:53 -0800104 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900105 ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory))
Jiyong Parkd1063c12019-07-17 20:08:41 +0900106 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(ApexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +0900107 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700108 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900109
110 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
111 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900112 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900113 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
114 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900115 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900116 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100117 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900118 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900119 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900120 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900121 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900122 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900123 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900124 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900125 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900126 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900127 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900128
Jooyung Han344d5432019-08-23 11:17:39 +0900129 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700130 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
131 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
132 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900134 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900135 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900136 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100137 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900138 ctx.BottomUp("version", cc.VersionMutator).Parallel()
139 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900140 })
Jooyung Han394951d2019-10-07 15:34:50 +0900141 ctx.PreDepsMutators(RegisterPreDepsMutators)
142 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han344d5432019-08-23 11:17:39 +0900143 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jooyung Han344d5432019-08-23 11:17:39 +0900144 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
145 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900146 })
147
148 ctx.Register()
149
150 bp = bp + `
151 toolchain_library {
152 name: "libcompiler_rt-extras",
153 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900154 vendor_available: true,
155 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900156 }
157
158 toolchain_library {
159 name: "libatomic",
160 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900161 vendor_available: true,
162 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900163 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900164 }
165
166 toolchain_library {
167 name: "libgcc",
168 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900169 vendor_available: true,
170 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900171 }
172
173 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700174 name: "libgcc_stripped",
175 src: "",
176 vendor_available: true,
177 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900178 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700179 }
180
181 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900182 name: "libclang_rt.builtins-aarch64-android",
183 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900184 vendor_available: true,
185 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900186 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900187 }
188
189 toolchain_library {
190 name: "libclang_rt.builtins-arm-android",
191 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900192 vendor_available: true,
193 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900194 native_bridge_supported: true,
195 }
196
197 toolchain_library {
198 name: "libclang_rt.builtins-x86_64-android",
199 src: "",
200 vendor_available: true,
201 recovery_available: true,
202 native_bridge_supported: true,
203 }
204
205 toolchain_library {
206 name: "libclang_rt.builtins-i686-android",
207 src: "",
208 vendor_available: true,
209 recovery_available: true,
210 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900211 }
212
213 cc_object {
214 name: "crtbegin_so",
215 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900216 vendor_available: true,
217 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900218 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900219 }
220
221 cc_object {
222 name: "crtend_so",
223 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900224 vendor_available: true,
225 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900226 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900227 }
228
Alex Light3d673592019-01-18 14:37:31 -0800229 cc_object {
230 name: "crtbegin_static",
231 stl: "none",
232 }
233
234 cc_object {
235 name: "crtend_android",
236 stl: "none",
237 }
238
Jiyong Parkda6eb592018-12-19 17:12:36 +0900239 llndk_library {
240 name: "libc",
241 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900242 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900243 }
244
245 llndk_library {
246 name: "libm",
247 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900248 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900249 }
250
251 llndk_library {
252 name: "libdl",
253 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900254 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900255 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900256 `
257
Jooyung Han344d5432019-08-23 11:17:39 +0900258 fs := map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900259 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700260 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900261 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900262 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900263 "system/sepolicy/apex/myapex-file_contexts": nil,
264 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
265 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900266 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900267 "mylib.cpp": nil,
268 "mylib_common.cpp": nil,
269 "mytest.cpp": nil,
270 "mytest1.cpp": nil,
271 "mytest2.cpp": nil,
272 "mytest3.cpp": nil,
273 "myprebuilt": nil,
274 "my_include": nil,
275 "foo/bar/MyClass.java": nil,
276 "prebuilt.jar": nil,
277 "vendor/foo/devkeys/test.x509.pem": nil,
278 "vendor/foo/devkeys/test.pk8": nil,
279 "testkey.x509.pem": nil,
280 "testkey.pk8": nil,
281 "testkey.override.x509.pem": nil,
282 "testkey.override.pk8": nil,
283 "vendor/foo/devkeys/testkey.avbpubkey": nil,
284 "vendor/foo/devkeys/testkey.pem": nil,
285 "NOTICE": nil,
286 "custom_notice": nil,
287 "testkey2.avbpubkey": nil,
288 "testkey2.pem": nil,
289 "myapex-arm64.apex": nil,
290 "myapex-arm.apex": nil,
291 "frameworks/base/api/current.txt": nil,
292 "build/make/core/proguard.flags": nil,
293 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900294 }
295
296 for _, handler := range handlers {
297 handler(fs, config)
298 }
299
300 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900301
Jooyung Han5c998b92019-06-27 11:30:33 +0900302 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900303}
304
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700305func setUp() {
306 var err error
307 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900308 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700309 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900311}
312
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700313func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900314 os.RemoveAll(buildDir)
315}
316
317// ensure that 'result' contains 'expected'
318func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900319 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900320 if !strings.Contains(result, expected) {
321 t.Errorf("%q is not found in %q", expected, result)
322 }
323}
324
325// ensures that 'result' does not contain 'notExpected'
326func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900327 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900328 if strings.Contains(result, notExpected) {
329 t.Errorf("%q is found in %q", notExpected, result)
330 }
331}
332
333func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900334 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900335 if !android.InList(expected, result) {
336 t.Errorf("%q is not found in %v", expected, result)
337 }
338}
339
340func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900341 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342 if android.InList(notExpected, result) {
343 t.Errorf("%q is found in %v", notExpected, result)
344 }
345}
346
Jooyung Hane1633032019-08-01 17:41:43 +0900347func ensureListEmpty(t *testing.T, result []string) {
348 t.Helper()
349 if len(result) > 0 {
350 t.Errorf("%q is expected to be empty", result)
351 }
352}
353
Jiyong Park25fc6a92018-11-18 18:02:45 +0900354// Minimal test
355func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700356 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900357 apex_defaults {
358 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900359 manifest: ":myapex.manifest",
360 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900361 key: "myapex.key",
362 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800363 multilib: {
364 both: {
365 binaries: ["foo",],
366 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900367 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900368 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900369 }
370
Jiyong Park30ca9372019-02-07 16:27:23 +0900371 apex {
372 name: "myapex",
373 defaults: ["myapex-defaults"],
374 }
375
Jiyong Park25fc6a92018-11-18 18:02:45 +0900376 apex_key {
377 name: "myapex.key",
378 public_key: "testkey.avbpubkey",
379 private_key: "testkey.pem",
380 }
381
Jiyong Park809bb722019-02-13 21:33:49 +0900382 filegroup {
383 name: "myapex.manifest",
384 srcs: ["apex_manifest.json"],
385 }
386
387 filegroup {
388 name: "myapex.androidmanifest",
389 srcs: ["AndroidManifest.xml"],
390 }
391
Jiyong Park25fc6a92018-11-18 18:02:45 +0900392 cc_library {
393 name: "mylib",
394 srcs: ["mylib.cpp"],
395 shared_libs: ["mylib2"],
396 system_shared_libs: [],
397 stl: "none",
398 }
399
Alex Light3d673592019-01-18 14:37:31 -0800400 cc_binary {
401 name: "foo",
402 srcs: ["mylib.cpp"],
403 compile_multilib: "both",
404 multilib: {
405 lib32: {
406 suffix: "32",
407 },
408 lib64: {
409 suffix: "64",
410 },
411 },
412 symlinks: ["foo_link_"],
413 symlink_preferred_arch: true,
414 system_shared_libs: [],
415 static_executable: true,
416 stl: "none",
417 }
418
Jiyong Park25fc6a92018-11-18 18:02:45 +0900419 cc_library {
420 name: "mylib2",
421 srcs: ["mylib.cpp"],
422 system_shared_libs: [],
423 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900424 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900425 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900426
427 java_library {
428 name: "myjar",
429 srcs: ["foo/bar/MyClass.java"],
430 sdk_version: "none",
431 system_modules: "none",
432 compile_dex: true,
433 static_libs: ["myotherjar"],
434 }
435
436 java_library {
437 name: "myotherjar",
438 srcs: ["foo/bar/MyClass.java"],
439 sdk_version: "none",
440 system_modules: "none",
441 compile_dex: true,
442 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900443
444 java_import {
445 name: "myprebuiltjar",
446 jars: ["prebuilt.jar"],
447 installable: true,
448 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900449 `)
450
451 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900452
453 optFlags := apexRule.Args["opt_flags"]
454 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700455 // Ensure that the NOTICE output is being packaged as an asset.
456 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900457
Jiyong Park25fc6a92018-11-18 18:02:45 +0900458 copyCmds := apexRule.Args["copy_commands"]
459
460 // Ensure that main rule creates an output
461 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
462
463 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900464 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900465 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900466 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900467
468 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900469 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900470 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900471
472 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800473 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
474 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900475 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900476 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900477 // .. but not for java libs
478 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800479
Jiyong Park7f7766d2019-07-25 22:02:35 +0900480 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800481 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
482 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900483 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
484 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900485 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800486
487 // Ensure that all symlinks are present.
488 found_foo_link_64 := false
489 found_foo := false
490 for _, cmd := range strings.Split(copyCmds, " && ") {
491 if strings.HasPrefix(cmd, "ln -s foo64") {
492 if strings.HasSuffix(cmd, "bin/foo") {
493 found_foo = true
494 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
495 found_foo_link_64 = true
496 }
497 }
498 }
499 good := found_foo && found_foo_link_64
500 if !good {
501 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
502 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900503
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700504 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
505 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700506 if len(noticeInputs) != 2 {
507 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900508 }
509 ensureListContains(t, noticeInputs, "NOTICE")
510 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800511}
512
513func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700514 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800515 apex {
516 name: "myapex",
517 key: "myapex.key",
518 payload_type: "zip",
519 native_shared_libs: ["mylib"],
520 }
521
522 apex_key {
523 name: "myapex.key",
524 public_key: "testkey.avbpubkey",
525 private_key: "testkey.pem",
526 }
527
528 cc_library {
529 name: "mylib",
530 srcs: ["mylib.cpp"],
531 shared_libs: ["mylib2"],
532 system_shared_libs: [],
533 stl: "none",
534 }
535
536 cc_library {
537 name: "mylib2",
538 srcs: ["mylib.cpp"],
539 system_shared_libs: [],
540 stl: "none",
541 }
542 `)
543
544 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
545 copyCmds := zipApexRule.Args["copy_commands"]
546
547 // Ensure that main rule creates an output
548 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
549
550 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900551 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800552
553 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900554 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800555
556 // Ensure that both direct and indirect deps are copied into apex
557 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
558 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900559}
560
561func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700562 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900563 apex {
564 name: "myapex",
565 key: "myapex.key",
566 native_shared_libs: ["mylib", "mylib3"],
567 }
568
569 apex_key {
570 name: "myapex.key",
571 public_key: "testkey.avbpubkey",
572 private_key: "testkey.pem",
573 }
574
575 cc_library {
576 name: "mylib",
577 srcs: ["mylib.cpp"],
578 shared_libs: ["mylib2", "mylib3"],
579 system_shared_libs: [],
580 stl: "none",
581 }
582
583 cc_library {
584 name: "mylib2",
585 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900586 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900587 system_shared_libs: [],
588 stl: "none",
589 stubs: {
590 versions: ["1", "2", "3"],
591 },
592 }
593
594 cc_library {
595 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900596 srcs: ["mylib.cpp"],
597 shared_libs: ["mylib4"],
598 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900599 stl: "none",
600 stubs: {
601 versions: ["10", "11", "12"],
602 },
603 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900604
605 cc_library {
606 name: "mylib4",
607 srcs: ["mylib.cpp"],
608 system_shared_libs: [],
609 stl: "none",
610 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900611 `)
612
613 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
614 copyCmds := apexRule.Args["copy_commands"]
615
616 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800617 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900618
619 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800620 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900621
622 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800623 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900624
Jiyong Parkda6eb592018-12-19 17:12:36 +0900625 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900626
627 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900628 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900629 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900630 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900631
632 // 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 +0900633 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900634 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900635 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900636
637 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900638 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900639 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900640
641 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900642 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 +0900643}
644
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900645func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700646 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900647 apex {
648 name: "myapex",
649 key: "myapex.key",
650 native_shared_libs: ["mylib"],
651 }
652
653 apex_key {
654 name: "myapex.key",
655 public_key: "testkey.avbpubkey",
656 private_key: "testkey.pem",
657 }
658
659 cc_library {
660 name: "mylib",
661 srcs: ["mylib.cpp"],
662 shared_libs: ["libfoo#10"],
663 system_shared_libs: [],
664 stl: "none",
665 }
666
667 cc_library {
668 name: "libfoo",
669 srcs: ["mylib.cpp"],
670 shared_libs: ["libbar"],
671 system_shared_libs: [],
672 stl: "none",
673 stubs: {
674 versions: ["10", "20", "30"],
675 },
676 }
677
678 cc_library {
679 name: "libbar",
680 srcs: ["mylib.cpp"],
681 system_shared_libs: [],
682 stl: "none",
683 }
684
685 `)
686
687 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
688 copyCmds := apexRule.Args["copy_commands"]
689
690 // Ensure that direct non-stubs dep is always included
691 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
692
693 // Ensure that indirect stubs dep is not included
694 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
695
696 // Ensure that dependency of stubs is not included
697 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
698
Jiyong Parkda6eb592018-12-19 17:12:36 +0900699 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900700
701 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900702 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900703 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900704 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900705
Jiyong Parkda6eb592018-12-19 17:12:36 +0900706 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900707
708 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
709 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
710}
711
Jooyung Hand3639552019-08-09 12:57:43 +0900712func TestApexWithRuntimeLibsDependency(t *testing.T) {
713 /*
714 myapex
715 |
716 v (runtime_libs)
717 mylib ------+------> libfoo [provides stub]
718 |
719 `------> libbar
720 */
721 ctx, _ := testApex(t, `
722 apex {
723 name: "myapex",
724 key: "myapex.key",
725 native_shared_libs: ["mylib"],
726 }
727
728 apex_key {
729 name: "myapex.key",
730 public_key: "testkey.avbpubkey",
731 private_key: "testkey.pem",
732 }
733
734 cc_library {
735 name: "mylib",
736 srcs: ["mylib.cpp"],
737 runtime_libs: ["libfoo", "libbar"],
738 system_shared_libs: [],
739 stl: "none",
740 }
741
742 cc_library {
743 name: "libfoo",
744 srcs: ["mylib.cpp"],
745 system_shared_libs: [],
746 stl: "none",
747 stubs: {
748 versions: ["10", "20", "30"],
749 },
750 }
751
752 cc_library {
753 name: "libbar",
754 srcs: ["mylib.cpp"],
755 system_shared_libs: [],
756 stl: "none",
757 }
758
759 `)
760
761 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
762 copyCmds := apexRule.Args["copy_commands"]
763
764 // Ensure that direct non-stubs dep is always included
765 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
766
767 // Ensure that indirect stubs dep is not included
768 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
769
770 // Ensure that runtime_libs dep in included
771 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
772
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900773 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
774 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
775 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900776
777}
778
Jooyung Han9c80bae2019-08-20 17:30:57 +0900779func TestApexDependencyToLLNDK(t *testing.T) {
780 ctx, _ := testApex(t, `
781 apex {
782 name: "myapex",
783 key: "myapex.key",
784 use_vendor: true,
785 native_shared_libs: ["mylib"],
786 }
787
788 apex_key {
789 name: "myapex.key",
790 public_key: "testkey.avbpubkey",
791 private_key: "testkey.pem",
792 }
793
794 cc_library {
795 name: "mylib",
796 srcs: ["mylib.cpp"],
797 vendor_available: true,
798 shared_libs: ["libbar"],
799 system_shared_libs: [],
800 stl: "none",
801 }
802
803 cc_library {
804 name: "libbar",
805 srcs: ["mylib.cpp"],
806 system_shared_libs: [],
807 stl: "none",
808 }
809
810 llndk_library {
811 name: "libbar",
812 symbol_file: "",
813 }
814
815 `)
816
817 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
818 copyCmds := apexRule.Args["copy_commands"]
819
820 // Ensure that LLNDK dep is not included
821 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
822
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900823 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule")
824 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900825
826 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900827 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900828
829}
830
Jiyong Park25fc6a92018-11-18 18:02:45 +0900831func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700832 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900833 apex {
834 name: "myapex",
835 key: "myapex.key",
836 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
837 }
838
839 apex_key {
840 name: "myapex.key",
841 public_key: "testkey.avbpubkey",
842 private_key: "testkey.pem",
843 }
844
845 cc_library {
846 name: "mylib",
847 srcs: ["mylib.cpp"],
848 shared_libs: ["libdl#27"],
849 stl: "none",
850 }
851
852 cc_library_shared {
853 name: "mylib_shared",
854 srcs: ["mylib.cpp"],
855 shared_libs: ["libdl#27"],
856 stl: "none",
857 }
858
859 cc_library {
860 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700861 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900862 nocrt: true,
863 system_shared_libs: [],
864 stl: "none",
865 stubs: {
866 versions: ["27", "28", "29"],
867 },
868 }
869
870 cc_library {
871 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700872 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900873 nocrt: true,
874 system_shared_libs: [],
875 stl: "none",
876 stubs: {
877 versions: ["27", "28", "29"],
878 },
879 }
880
881 cc_library {
882 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700883 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900884 nocrt: true,
885 system_shared_libs: [],
886 stl: "none",
887 stubs: {
888 versions: ["27", "28", "29"],
889 },
890 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900891
892 cc_library {
893 name: "libBootstrap",
894 srcs: ["mylib.cpp"],
895 stl: "none",
896 bootstrap: true,
897 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900898 `)
899
900 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
901 copyCmds := apexRule.Args["copy_commands"]
902
903 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800904 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900905 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
906 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900907
908 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900909 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900910
Jiyong Parkda6eb592018-12-19 17:12:36 +0900911 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
912 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
913 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900914
915 // For dependency to libc
916 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900917 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900918 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900919 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900920 // ... Cflags from stub is correctly exported to mylib
921 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
922 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
923
924 // For dependency to libm
925 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900926 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900927 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900928 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900929 // ... and is not compiling with the stub
930 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
931 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
932
933 // For dependency to libdl
934 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900935 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900937 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
938 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900939 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900940 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900941 // ... Cflags from stub is correctly exported to mylib
942 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
943 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900944
945 // Ensure that libBootstrap is depending on the platform variant of bionic libs
946 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
947 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
948 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
949 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900950}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900951
952func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700953 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900954 apex {
955 name: "myapex",
956 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900957 native_shared_libs: ["mylib"],
958 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900959 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900960 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900961 }
962
963 apex_key {
964 name: "myapex.key",
965 public_key: "testkey.avbpubkey",
966 private_key: "testkey.pem",
967 }
968
969 prebuilt_etc {
970 name: "myetc",
971 src: "myprebuilt",
972 sub_dir: "foo/bar",
973 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900974
975 cc_library {
976 name: "mylib",
977 srcs: ["mylib.cpp"],
978 relative_install_path: "foo/bar",
979 system_shared_libs: [],
980 stl: "none",
981 }
982
983 cc_binary {
984 name: "mybin",
985 srcs: ["mylib.cpp"],
986 relative_install_path: "foo/bar",
987 system_shared_libs: [],
988 static_executable: true,
989 stl: "none",
990 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900991 `)
992
993 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
994 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
995
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900996 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900997 ensureListContains(t, dirs, "etc")
998 ensureListContains(t, dirs, "etc/foo")
999 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001000 ensureListContains(t, dirs, "lib64")
1001 ensureListContains(t, dirs, "lib64/foo")
1002 ensureListContains(t, dirs, "lib64/foo/bar")
1003 ensureListContains(t, dirs, "lib")
1004 ensureListContains(t, dirs, "lib/foo")
1005 ensureListContains(t, dirs, "lib/foo/bar")
1006
Jiyong Parkbd13e442019-03-15 18:10:35 +09001007 ensureListContains(t, dirs, "bin")
1008 ensureListContains(t, dirs, "bin/foo")
1009 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001010}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001011
1012func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001013 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001014 apex {
1015 name: "myapex",
1016 key: "myapex.key",
1017 native_shared_libs: ["mylib"],
1018 use_vendor: true,
1019 }
1020
1021 apex_key {
1022 name: "myapex.key",
1023 public_key: "testkey.avbpubkey",
1024 private_key: "testkey.pem",
1025 }
1026
1027 cc_library {
1028 name: "mylib",
1029 srcs: ["mylib.cpp"],
1030 shared_libs: ["mylib2"],
1031 system_shared_libs: [],
1032 vendor_available: true,
1033 stl: "none",
1034 }
1035
1036 cc_library {
1037 name: "mylib2",
1038 srcs: ["mylib.cpp"],
1039 system_shared_libs: [],
1040 vendor_available: true,
1041 stl: "none",
1042 }
1043 `)
1044
1045 inputsList := []string{}
1046 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
1047 for _, implicit := range i.Implicits {
1048 inputsList = append(inputsList, implicit.String())
1049 }
1050 }
1051 inputsString := strings.Join(inputsList, " ")
1052
1053 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001054 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1055 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001056
1057 // ensure that the apex does not include core variants
1058 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1059 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1060}
Jiyong Park16e91a02018-12-20 18:18:08 +09001061
Jooyung Han5c998b92019-06-27 11:30:33 +09001062func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1063 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1064 apex {
1065 name: "myapex",
1066 key: "myapex.key",
1067 native_shared_libs: ["mylib"],
1068 use_vendor: true,
1069 }
1070
1071 apex_key {
1072 name: "myapex.key",
1073 public_key: "testkey.avbpubkey",
1074 private_key: "testkey.pem",
1075 }
1076
1077 cc_library {
1078 name: "mylib",
1079 srcs: ["mylib.cpp"],
1080 system_shared_libs: [],
1081 stl: "none",
1082 }
1083 `)
1084}
1085
Jiyong Park16e91a02018-12-20 18:18:08 +09001086func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001087 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001088 apex {
1089 name: "myapex",
1090 key: "myapex.key",
1091 native_shared_libs: ["mylib"],
1092 }
1093
1094 apex_key {
1095 name: "myapex.key",
1096 public_key: "testkey.avbpubkey",
1097 private_key: "testkey.pem",
1098 }
1099
1100 cc_library {
1101 name: "mylib",
1102 srcs: ["mylib.cpp"],
1103 system_shared_libs: [],
1104 stl: "none",
1105 stubs: {
1106 versions: ["1", "2", "3"],
1107 },
1108 }
1109
1110 cc_binary {
1111 name: "not_in_apex",
1112 srcs: ["mylib.cpp"],
1113 static_libs: ["mylib"],
1114 static_executable: true,
1115 system_shared_libs: [],
1116 stl: "none",
1117 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001118 `)
1119
1120 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1121
1122 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001123 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001124}
Jiyong Park9335a262018-12-24 11:31:58 +09001125
1126func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001127 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001128 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001129 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001130 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001131 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001132 native_shared_libs: ["mylib"],
1133 }
1134
1135 cc_library {
1136 name: "mylib",
1137 srcs: ["mylib.cpp"],
1138 system_shared_libs: [],
1139 stl: "none",
1140 }
1141
1142 apex_key {
1143 name: "myapex.key",
1144 public_key: "testkey.avbpubkey",
1145 private_key: "testkey.pem",
1146 }
1147
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001148 android_app_certificate {
1149 name: "myapex.certificate",
1150 certificate: "testkey",
1151 }
1152
1153 android_app_certificate {
1154 name: "myapex.certificate.override",
1155 certificate: "testkey.override",
1156 }
1157
Jiyong Park9335a262018-12-24 11:31:58 +09001158 `)
1159
1160 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001161 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001162
1163 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1164 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1165 "vendor/foo/devkeys/testkey.avbpubkey")
1166 }
1167 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1168 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1169 "vendor/foo/devkeys/testkey.pem")
1170 }
1171
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001172 // check the APK certs. It should be overridden to myapex.certificate.override
1173 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
1174 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001175 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001176 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001177 }
1178}
Jiyong Park58e364a2019-01-19 19:24:06 +09001179
1180func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001181 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001182 apex {
1183 name: "myapex",
1184 key: "myapex.key",
1185 native_shared_libs: ["mylib"],
1186 }
1187
1188 apex {
1189 name: "otherapex",
1190 key: "myapex.key",
1191 native_shared_libs: ["mylib"],
1192 }
1193
1194 apex_key {
1195 name: "myapex.key",
1196 public_key: "testkey.avbpubkey",
1197 private_key: "testkey.pem",
1198 }
1199
1200 cc_library {
1201 name: "mylib",
1202 srcs: ["mylib.cpp"],
1203 system_shared_libs: [],
1204 stl: "none",
1205 }
1206 `)
1207
1208 // non-APEX variant does not have __ANDROID__APEX__ defined
1209 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1210 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1211 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Hand29e5512019-10-12 17:32:26 +09001212 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1213 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001214
1215 // APEX variant has __ANDROID_APEX__=<apexname> defined
1216 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1217 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1218 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Hand29e5512019-10-12 17:32:26 +09001219 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1220 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001221
1222 // APEX variant has __ANDROID_APEX__=<apexname> defined
1223 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1224 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1225 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
Jooyung Hand29e5512019-10-12 17:32:26 +09001226 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1227 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001228}
Jiyong Park7e636d02019-01-28 16:16:54 +09001229
1230func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001231 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001232 apex {
1233 name: "myapex",
1234 key: "myapex.key",
1235 native_shared_libs: ["mylib"],
1236 }
1237
1238 apex_key {
1239 name: "myapex.key",
1240 public_key: "testkey.avbpubkey",
1241 private_key: "testkey.pem",
1242 }
1243
1244 cc_library_headers {
1245 name: "mylib_headers",
1246 export_include_dirs: ["my_include"],
1247 system_shared_libs: [],
1248 stl: "none",
1249 }
1250
1251 cc_library {
1252 name: "mylib",
1253 srcs: ["mylib.cpp"],
1254 system_shared_libs: [],
1255 stl: "none",
1256 header_libs: ["mylib_headers"],
1257 export_header_lib_headers: ["mylib_headers"],
1258 stubs: {
1259 versions: ["1", "2", "3"],
1260 },
1261 }
1262
1263 cc_library {
1264 name: "otherlib",
1265 srcs: ["mylib.cpp"],
1266 system_shared_libs: [],
1267 stl: "none",
1268 shared_libs: ["mylib"],
1269 }
1270 `)
1271
1272 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1273
1274 // Ensure that the include path of the header lib is exported to 'otherlib'
1275 ensureContains(t, cFlags, "-Imy_include")
1276}
Alex Light9670d332019-01-29 18:07:33 -08001277
Jooyung Han394951d2019-10-07 15:34:50 +09001278func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1279 t.Helper()
1280 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Rule("apexRule")
1281 copyCmds := apexRule.Args["copy_commands"]
1282 imageApexDir := "/image.apex/"
1283 dstFiles := []string{}
1284 for _, cmd := range strings.Split(copyCmds, "&&") {
1285 cmd = strings.TrimSpace(cmd)
1286 if cmd == "" {
1287 continue
1288 }
1289 terms := strings.Split(cmd, " ")
1290 switch terms[0] {
1291 case "mkdir":
1292 case "cp":
1293 if len(terms) != 3 {
1294 t.Fatal("copyCmds contains invalid cp command", cmd)
1295 }
1296 dst := terms[2]
1297 index := strings.Index(dst, imageApexDir)
1298 if index == -1 {
1299 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1300 }
1301 dstFile := dst[index+len(imageApexDir):]
1302 dstFiles = append(dstFiles, dstFile)
1303 default:
1304 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1305 }
1306 }
1307 sort.Strings(dstFiles)
1308 sort.Strings(files)
1309 missing := []string{}
1310 surplus := []string{}
1311 i := 0
1312 j := 0
1313 for i < len(dstFiles) && j < len(files) {
1314 if dstFiles[i] == files[j] {
1315 i++
1316 j++
1317 } else if dstFiles[i] < files[j] {
1318 surplus = append(surplus, dstFiles[i])
1319 i++
1320 } else {
1321 missing = append(missing, files[j])
1322 j++
1323 }
1324 }
1325 if i < len(dstFiles) {
1326 surplus = append(surplus, dstFiles[i:]...)
1327 }
1328 if j < len(files) {
1329 missing = append(missing, files[j:]...)
1330 }
1331
1332 failed := false
1333 if len(surplus) > 0 {
1334 t.Log("surplus files", surplus)
1335 failed = true
1336 }
1337 if len(missing) > 0 {
1338 t.Log("missing files", missing)
1339 failed = true
1340 }
1341 if failed {
1342 t.Fail()
1343 }
1344}
1345
Jooyung Han344d5432019-08-23 11:17:39 +09001346func TestVndkApexCurrent(t *testing.T) {
1347 ctx, _ := testApex(t, `
1348 apex_vndk {
1349 name: "myapex",
1350 key: "myapex.key",
1351 file_contexts: "myapex",
1352 }
1353
1354 apex_key {
1355 name: "myapex.key",
1356 public_key: "testkey.avbpubkey",
1357 private_key: "testkey.pem",
1358 }
1359
1360 cc_library {
1361 name: "libvndk",
1362 srcs: ["mylib.cpp"],
1363 vendor_available: true,
1364 vndk: {
1365 enabled: true,
1366 },
1367 system_shared_libs: [],
1368 stl: "none",
1369 }
1370
1371 cc_library {
1372 name: "libvndksp",
1373 srcs: ["mylib.cpp"],
1374 vendor_available: true,
1375 vndk: {
1376 enabled: true,
1377 support_system_process: true,
1378 },
1379 system_shared_libs: [],
1380 stl: "none",
1381 }
1382 `)
1383
Jooyung Han394951d2019-10-07 15:34:50 +09001384 ensureExactContents(t, ctx, "myapex", []string{
1385 "lib/libvndk.so",
1386 "lib/libvndksp.so",
1387 "lib64/libvndk.so",
1388 "lib64/libvndksp.so",
1389 })
Jooyung Han344d5432019-08-23 11:17:39 +09001390}
1391
1392func TestVndkApexWithPrebuilt(t *testing.T) {
1393 ctx, _ := testApex(t, `
1394 apex_vndk {
1395 name: "myapex",
1396 key: "myapex.key",
1397 file_contexts: "myapex",
1398 }
1399
1400 apex_key {
1401 name: "myapex.key",
1402 public_key: "testkey.avbpubkey",
1403 private_key: "testkey.pem",
1404 }
1405
1406 cc_prebuilt_library_shared {
Jooyung Han394951d2019-10-07 15:34:50 +09001407 name: "libvndk",
1408 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001409 vendor_available: true,
1410 vndk: {
1411 enabled: true,
1412 },
1413 system_shared_libs: [],
1414 stl: "none",
1415 }
Jooyung Han394951d2019-10-07 15:34:50 +09001416
1417 cc_prebuilt_library_shared {
1418 name: "libvndk.arm",
1419 srcs: ["libvndk.arm.so"],
1420 vendor_available: true,
1421 vndk: {
1422 enabled: true,
1423 },
1424 enabled: false,
1425 arch: {
1426 arm: {
1427 enabled: true,
1428 },
1429 },
1430 system_shared_libs: [],
1431 stl: "none",
1432 }
Jooyung Han344d5432019-08-23 11:17:39 +09001433 `, withFiles(map[string][]byte{
Jooyung Han394951d2019-10-07 15:34:50 +09001434 "libvndk.so": nil,
1435 "libvndk.arm.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001436 }))
1437
Jooyung Han394951d2019-10-07 15:34:50 +09001438 ensureExactContents(t, ctx, "myapex", []string{
1439 "lib/libvndk.so",
1440 "lib/libvndk.arm.so",
1441 "lib64/libvndk.so",
1442 })
Jooyung Han344d5432019-08-23 11:17:39 +09001443}
1444
1445func TestVndkApexVersion(t *testing.T) {
1446 ctx, _ := testApex(t, `
1447 apex_vndk {
1448 name: "myapex_v27",
1449 key: "myapex.key",
1450 file_contexts: "myapex",
1451 vndk_version: "27",
1452 }
1453
1454 apex_key {
1455 name: "myapex.key",
1456 public_key: "testkey.avbpubkey",
1457 private_key: "testkey.pem",
1458 }
1459
Jooyung Han394951d2019-10-07 15:34:50 +09001460 vndk_prebuilt_shared {
1461 name: "libvndk27",
1462 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001463 vendor_available: true,
1464 vndk: {
1465 enabled: true,
1466 },
Jooyung Han394951d2019-10-07 15:34:50 +09001467 target_arch: "arm64",
1468 arch: {
1469 arm: {
1470 srcs: ["libvndk27_arm.so"],
1471 },
1472 arm64: {
1473 srcs: ["libvndk27_arm64.so"],
1474 },
1475 },
Jooyung Han344d5432019-08-23 11:17:39 +09001476 }
1477
1478 vndk_prebuilt_shared {
1479 name: "libvndk27",
1480 version: "27",
1481 vendor_available: true,
1482 vndk: {
1483 enabled: true,
1484 },
Jooyung Han394951d2019-10-07 15:34:50 +09001485 target_arch: "x86_64",
1486 arch: {
1487 x86: {
1488 srcs: ["libvndk27_x86.so"],
1489 },
1490 x86_64: {
1491 srcs: ["libvndk27_x86_64.so"],
1492 },
1493 },
1494 }
Jooyung Han344d5432019-08-23 11:17:39 +09001495 `, withFiles(map[string][]byte{
Jooyung Han394951d2019-10-07 15:34:50 +09001496 "libvndk27_arm.so": nil,
1497 "libvndk27_arm64.so": nil,
1498 "libvndk27_x86.so": nil,
1499 "libvndk27_x86_64.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001500 }))
1501
Jooyung Han394951d2019-10-07 15:34:50 +09001502 ensureExactContents(t, ctx, "myapex_v27", []string{
1503 "lib/libvndk27_arm.so",
1504 "lib64/libvndk27_arm64.so",
1505 })
Jooyung Han344d5432019-08-23 11:17:39 +09001506}
1507
1508func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1509 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1510 apex_vndk {
1511 name: "myapex_v27",
1512 key: "myapex.key",
1513 file_contexts: "myapex",
1514 vndk_version: "27",
1515 }
1516 apex_vndk {
1517 name: "myapex_v27_other",
1518 key: "myapex.key",
1519 file_contexts: "myapex",
1520 vndk_version: "27",
1521 }
1522
1523 apex_key {
1524 name: "myapex.key",
1525 public_key: "testkey.avbpubkey",
1526 private_key: "testkey.pem",
1527 }
1528
1529 cc_library {
1530 name: "libvndk",
1531 srcs: ["mylib.cpp"],
1532 vendor_available: true,
1533 vndk: {
1534 enabled: true,
1535 },
1536 system_shared_libs: [],
1537 stl: "none",
1538 }
1539
1540 vndk_prebuilt_shared {
1541 name: "libvndk",
1542 version: "27",
1543 vendor_available: true,
1544 vndk: {
1545 enabled: true,
1546 },
1547 srcs: ["libvndk.so"],
1548 }
1549 `, withFiles(map[string][]byte{
1550 "libvndk.so": nil,
1551 }))
1552}
1553
Jooyung Han90eee022019-10-01 20:02:42 +09001554func TestVndkApexNameRule(t *testing.T) {
1555 ctx, _ := testApex(t, `
1556 apex_vndk {
1557 name: "myapex",
1558 key: "myapex.key",
1559 file_contexts: "myapex",
1560 }
1561 apex_vndk {
1562 name: "myapex_v28",
1563 key: "myapex.key",
1564 file_contexts: "myapex",
1565 vndk_version: "28",
1566 }
1567 apex_key {
1568 name: "myapex.key",
1569 public_key: "testkey.avbpubkey",
1570 private_key: "testkey.pem",
1571 }`)
1572
1573 assertApexName := func(expected, moduleName string) {
1574 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName).Module().(*apexBundle)
1575 actual := proptools.String(bundle.properties.Apex_name)
1576 if !reflect.DeepEqual(actual, expected) {
1577 t.Errorf("Got '%v', expected '%v'", actual, expected)
1578 }
1579 }
1580
1581 assertApexName("com.android.vndk.vVER", "myapex")
1582 assertApexName("com.android.vndk.v28", "myapex_v28")
1583}
1584
Jooyung Han344d5432019-08-23 11:17:39 +09001585func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1586 ctx, _ := testApex(t, `
1587 apex_vndk {
1588 name: "myapex",
1589 key: "myapex.key",
1590 file_contexts: "myapex",
1591 }
1592
1593 apex_key {
1594 name: "myapex.key",
1595 public_key: "testkey.avbpubkey",
1596 private_key: "testkey.pem",
1597 }
1598
1599 cc_library {
1600 name: "libvndk",
1601 srcs: ["mylib.cpp"],
1602 vendor_available: true,
1603 native_bridge_supported: true,
1604 host_supported: true,
1605 vndk: {
1606 enabled: true,
1607 },
1608 system_shared_libs: [],
1609 stl: "none",
1610 }
1611 `, withTargets(map[android.OsType][]android.Target{
1612 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001613 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1614 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1615 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1616 {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 +09001617 },
1618 }))
1619
Jooyung Han394951d2019-10-07 15:34:50 +09001620 ensureExactContents(t, ctx, "myapex", []string{
1621 "lib/libvndk.so",
1622 "lib64/libvndk.so",
1623 })
Jooyung Han344d5432019-08-23 11:17:39 +09001624}
1625
1626func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1627 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1628 apex_vndk {
1629 name: "myapex",
1630 key: "myapex.key",
1631 file_contexts: "myapex",
1632 native_bridge_supported: true,
1633 }
1634
1635 apex_key {
1636 name: "myapex.key",
1637 public_key: "testkey.avbpubkey",
1638 private_key: "testkey.pem",
1639 }
1640
1641 cc_library {
1642 name: "libvndk",
1643 srcs: ["mylib.cpp"],
1644 vendor_available: true,
1645 native_bridge_supported: true,
1646 host_supported: true,
1647 vndk: {
1648 enabled: true,
1649 },
1650 system_shared_libs: [],
1651 stl: "none",
1652 }
1653 `)
1654}
1655
Jooyung Han394951d2019-10-07 15:34:50 +09001656func TestVndkApexWithBinder32(t *testing.T) {
1657 ctx, _ := testApex(t,
1658 `
1659 apex_vndk {
1660 name: "myapex_v27",
1661 key: "myapex.key",
1662 file_contexts: "myapex",
1663 vndk_version: "27",
1664 }
1665
1666 apex_key {
1667 name: "myapex.key",
1668 public_key: "testkey.avbpubkey",
1669 private_key: "testkey.pem",
1670 }
1671
1672 vndk_prebuilt_shared {
1673 name: "libvndk27",
1674 version: "27",
1675 target_arch: "arm",
1676 vendor_available: true,
1677 vndk: {
1678 enabled: true,
1679 },
1680 arch: {
1681 arm: {
1682 srcs: ["libvndk27.so"],
1683 }
1684 },
1685 }
1686
1687 vndk_prebuilt_shared {
1688 name: "libvndk27",
1689 version: "27",
1690 target_arch: "arm",
1691 binder32bit: true,
1692 vendor_available: true,
1693 vndk: {
1694 enabled: true,
1695 },
1696 arch: {
1697 arm: {
1698 srcs: ["libvndk27binder32.so"],
1699 }
1700 },
1701 }
1702 `,
1703 withFiles(map[string][]byte{
1704 "libvndk27.so": nil,
1705 "libvndk27binder32.so": nil,
1706 }),
1707 withBinder32bit,
1708 withTargets(map[android.OsType][]android.Target{
1709 android.Android: []android.Target{
1710 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1711 },
1712 }),
1713 )
1714
1715 ensureExactContents(t, ctx, "myapex_v27", []string{
1716 "lib/libvndk27binder32.so",
1717 })
1718}
1719
Jooyung Hane1633032019-08-01 17:41:43 +09001720func TestDependenciesInApexManifest(t *testing.T) {
1721 ctx, _ := testApex(t, `
1722 apex {
1723 name: "myapex_nodep",
1724 key: "myapex.key",
1725 native_shared_libs: ["lib_nodep"],
1726 compile_multilib: "both",
1727 file_contexts: "myapex",
1728 }
1729
1730 apex {
1731 name: "myapex_dep",
1732 key: "myapex.key",
1733 native_shared_libs: ["lib_dep"],
1734 compile_multilib: "both",
1735 file_contexts: "myapex",
1736 }
1737
1738 apex {
1739 name: "myapex_provider",
1740 key: "myapex.key",
1741 native_shared_libs: ["libfoo"],
1742 compile_multilib: "both",
1743 file_contexts: "myapex",
1744 }
1745
1746 apex {
1747 name: "myapex_selfcontained",
1748 key: "myapex.key",
1749 native_shared_libs: ["lib_dep", "libfoo"],
1750 compile_multilib: "both",
1751 file_contexts: "myapex",
1752 }
1753
1754 apex_key {
1755 name: "myapex.key",
1756 public_key: "testkey.avbpubkey",
1757 private_key: "testkey.pem",
1758 }
1759
1760 cc_library {
1761 name: "lib_nodep",
1762 srcs: ["mylib.cpp"],
1763 system_shared_libs: [],
1764 stl: "none",
1765 }
1766
1767 cc_library {
1768 name: "lib_dep",
1769 srcs: ["mylib.cpp"],
1770 shared_libs: ["libfoo"],
1771 system_shared_libs: [],
1772 stl: "none",
1773 }
1774
1775 cc_library {
1776 name: "libfoo",
1777 srcs: ["mytest.cpp"],
1778 stubs: {
1779 versions: ["1"],
1780 },
1781 system_shared_libs: [],
1782 stl: "none",
1783 }
1784 `)
1785
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001786 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001787 var provideNativeLibs, requireNativeLibs []string
1788
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001789 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("apexManifestRule")
1790 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1791 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001792 ensureListEmpty(t, provideNativeLibs)
1793 ensureListEmpty(t, requireNativeLibs)
1794
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001795 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("apexManifestRule")
1796 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1797 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001798 ensureListEmpty(t, provideNativeLibs)
1799 ensureListContains(t, requireNativeLibs, "libfoo.so")
1800
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001801 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("apexManifestRule")
1802 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1803 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001804 ensureListContains(t, provideNativeLibs, "libfoo.so")
1805 ensureListEmpty(t, requireNativeLibs)
1806
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001807 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("apexManifestRule")
1808 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1809 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001810 ensureListContains(t, provideNativeLibs, "libfoo.so")
1811 ensureListEmpty(t, requireNativeLibs)
1812}
1813
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001814func TestApexName(t *testing.T) {
1815 ctx, _ := testApex(t, `
1816 apex {
1817 name: "myapex",
1818 key: "myapex.key",
1819 apex_name: "com.android.myapex",
1820 }
1821
1822 apex_key {
1823 name: "myapex.key",
1824 public_key: "testkey.avbpubkey",
1825 private_key: "testkey.pem",
1826 }
1827 `)
1828
1829 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1830 apexManifestRule := module.Rule("apexManifestRule")
1831 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1832 apexRule := module.Rule("apexRule")
1833 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1834}
1835
Alex Light0851b882019-02-07 13:20:53 -08001836func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001837 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001838 apex {
1839 name: "myapex",
1840 key: "myapex.key",
1841 native_shared_libs: ["mylib_common"],
1842 }
1843
1844 apex_key {
1845 name: "myapex.key",
1846 public_key: "testkey.avbpubkey",
1847 private_key: "testkey.pem",
1848 }
1849
1850 cc_library {
1851 name: "mylib_common",
1852 srcs: ["mylib.cpp"],
1853 system_shared_libs: [],
1854 stl: "none",
1855 }
1856 `)
1857
1858 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1859 apexRule := module.Rule("apexRule")
1860 copyCmds := apexRule.Args["copy_commands"]
1861
1862 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1863 t.Log("Apex was a test apex!")
1864 t.Fail()
1865 }
1866 // Ensure that main rule creates an output
1867 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1868
1869 // Ensure that apex variant is created for the direct dep
1870 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1871
1872 // Ensure that both direct and indirect deps are copied into apex
1873 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1874
1875 // Ensure that the platform variant ends with _core_shared
1876 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1877
1878 if !android.InAnyApex("mylib_common") {
1879 t.Log("Found mylib_common not in any apex!")
1880 t.Fail()
1881 }
1882}
1883
1884func TestTestApex(t *testing.T) {
1885 if android.InAnyApex("mylib_common_test") {
1886 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!")
1887 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001888 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001889 apex_test {
1890 name: "myapex",
1891 key: "myapex.key",
1892 native_shared_libs: ["mylib_common_test"],
1893 }
1894
1895 apex_key {
1896 name: "myapex.key",
1897 public_key: "testkey.avbpubkey",
1898 private_key: "testkey.pem",
1899 }
1900
1901 cc_library {
1902 name: "mylib_common_test",
1903 srcs: ["mylib.cpp"],
1904 system_shared_libs: [],
1905 stl: "none",
1906 }
1907 `)
1908
1909 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1910 apexRule := module.Rule("apexRule")
1911 copyCmds := apexRule.Args["copy_commands"]
1912
1913 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1914 t.Log("Apex was not a test apex!")
1915 t.Fail()
1916 }
1917 // Ensure that main rule creates an output
1918 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1919
1920 // Ensure that apex variant is created for the direct dep
1921 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1922
1923 // Ensure that both direct and indirect deps are copied into apex
1924 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1925
1926 // Ensure that the platform variant ends with _core_shared
1927 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1928
1929 if android.InAnyApex("mylib_common_test") {
1930 t.Log("Found mylib_common_test in some apex!")
1931 t.Fail()
1932 }
1933}
1934
Alex Light9670d332019-01-29 18:07:33 -08001935func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001936 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001937 apex {
1938 name: "myapex",
1939 key: "myapex.key",
1940 multilib: {
1941 first: {
1942 native_shared_libs: ["mylib_common"],
1943 }
1944 },
1945 target: {
1946 android: {
1947 multilib: {
1948 first: {
1949 native_shared_libs: ["mylib"],
1950 }
1951 }
1952 },
1953 host: {
1954 multilib: {
1955 first: {
1956 native_shared_libs: ["mylib2"],
1957 }
1958 }
1959 }
1960 }
1961 }
1962
1963 apex_key {
1964 name: "myapex.key",
1965 public_key: "testkey.avbpubkey",
1966 private_key: "testkey.pem",
1967 }
1968
1969 cc_library {
1970 name: "mylib",
1971 srcs: ["mylib.cpp"],
1972 system_shared_libs: [],
1973 stl: "none",
1974 }
1975
1976 cc_library {
1977 name: "mylib_common",
1978 srcs: ["mylib.cpp"],
1979 system_shared_libs: [],
1980 stl: "none",
1981 compile_multilib: "first",
1982 }
1983
1984 cc_library {
1985 name: "mylib2",
1986 srcs: ["mylib.cpp"],
1987 system_shared_libs: [],
1988 stl: "none",
1989 compile_multilib: "first",
1990 }
1991 `)
1992
1993 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1994 copyCmds := apexRule.Args["copy_commands"]
1995
1996 // Ensure that main rule creates an output
1997 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1998
1999 // Ensure that apex variant is created for the direct dep
2000 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2001 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
2002 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
2003
2004 // Ensure that both direct and indirect deps are copied into apex
2005 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2006 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2007 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2008
2009 // Ensure that the platform variant ends with _core_shared
2010 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
2011 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
2012 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
2013}
Jiyong Park04480cf2019-02-06 00:16:29 +09002014
2015func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002016 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002017 apex {
2018 name: "myapex",
2019 key: "myapex.key",
2020 binaries: ["myscript"],
2021 }
2022
2023 apex_key {
2024 name: "myapex.key",
2025 public_key: "testkey.avbpubkey",
2026 private_key: "testkey.pem",
2027 }
2028
2029 sh_binary {
2030 name: "myscript",
2031 src: "mylib.cpp",
2032 filename: "myscript.sh",
2033 sub_dir: "script",
2034 }
2035 `)
2036
2037 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2038 copyCmds := apexRule.Args["copy_commands"]
2039
2040 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2041}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002042
2043func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002044 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002045 apex {
2046 name: "myapex",
2047 key: "myapex.key",
2048 native_shared_libs: ["mylib"],
2049 product_specific: true,
2050 }
2051
2052 apex_key {
2053 name: "myapex.key",
2054 public_key: "testkey.avbpubkey",
2055 private_key: "testkey.pem",
2056 product_specific: true,
2057 }
2058
2059 cc_library {
2060 name: "mylib",
2061 srcs: ["mylib.cpp"],
2062 system_shared_libs: [],
2063 stl: "none",
2064 }
2065 `)
2066
2067 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07002068 expected := buildDir + "/target/product/test_device/product/apex"
2069 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002070 if actual != expected {
2071 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2072 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002073}
Jiyong Park67882562019-03-21 01:11:21 +09002074
2075func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002076 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002077 apex_key {
2078 name: "myapex.key",
2079 public_key: ":my.avbpubkey",
2080 private_key: ":my.pem",
2081 product_specific: true,
2082 }
2083
2084 filegroup {
2085 name: "my.avbpubkey",
2086 srcs: ["testkey2.avbpubkey"],
2087 }
2088
2089 filegroup {
2090 name: "my.pem",
2091 srcs: ["testkey2.pem"],
2092 }
2093 `)
2094
2095 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2096 expected_pubkey := "testkey2.avbpubkey"
2097 actual_pubkey := apex_key.public_key_file.String()
2098 if actual_pubkey != expected_pubkey {
2099 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2100 }
2101 expected_privkey := "testkey2.pem"
2102 actual_privkey := apex_key.private_key_file.String()
2103 if actual_privkey != expected_privkey {
2104 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2105 }
2106}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002107
2108func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002109 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002110 prebuilt_apex {
2111 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002112 arch: {
2113 arm64: {
2114 src: "myapex-arm64.apex",
2115 },
2116 arm: {
2117 src: "myapex-arm.apex",
2118 },
2119 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002120 }
2121 `)
2122
2123 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2124
Jiyong Parkc95714e2019-03-29 14:23:10 +09002125 expectedInput := "myapex-arm64.apex"
2126 if prebuilt.inputApex.String() != expectedInput {
2127 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2128 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002129}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002130
2131func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002132 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002133 prebuilt_apex {
2134 name: "myapex",
2135 src: "myapex-arm.apex",
2136 filename: "notmyapex.apex",
2137 }
2138 `)
2139
2140 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2141
2142 expected := "notmyapex.apex"
2143 if p.installFilename != expected {
2144 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2145 }
2146}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002147
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002148func TestPrebuiltOverrides(t *testing.T) {
2149 ctx, config := testApex(t, `
2150 prebuilt_apex {
2151 name: "myapex.prebuilt",
2152 src: "myapex-arm.apex",
2153 overrides: [
2154 "myapex",
2155 ],
2156 }
2157 `)
2158
2159 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2160
2161 expected := []string{"myapex"}
2162 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
2163 if !reflect.DeepEqual(actual, expected) {
2164 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
2165 }
2166}
2167
Roland Levillain630846d2019-06-26 12:48:34 +01002168func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002169 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002170 apex_test {
2171 name: "myapex",
2172 key: "myapex.key",
2173 tests: [
2174 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002175 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002176 ],
2177 }
2178
2179 apex_key {
2180 name: "myapex.key",
2181 public_key: "testkey.avbpubkey",
2182 private_key: "testkey.pem",
2183 }
2184
2185 cc_test {
2186 name: "mytest",
2187 gtest: false,
2188 srcs: ["mytest.cpp"],
2189 relative_install_path: "test",
2190 system_shared_libs: [],
2191 static_executable: true,
2192 stl: "none",
2193 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002194
2195 cc_test {
2196 name: "mytests",
2197 gtest: false,
2198 srcs: [
2199 "mytest1.cpp",
2200 "mytest2.cpp",
2201 "mytest3.cpp",
2202 ],
2203 test_per_src: true,
2204 relative_install_path: "test",
2205 system_shared_libs: [],
2206 static_executable: true,
2207 stl: "none",
2208 }
Roland Levillain630846d2019-06-26 12:48:34 +01002209 `)
2210
2211 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
2212 copyCmds := apexRule.Args["copy_commands"]
2213
2214 // Ensure that test dep is copied into apex.
2215 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002216
2217 // Ensure that test deps built with `test_per_src` are copied into apex.
2218 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2219 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2220 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002221
2222 // Ensure the module is correctly translated.
2223 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
2224 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2225 name := apexBundle.BaseModuleName()
2226 prefix := "TARGET_"
2227 var builder strings.Builder
2228 data.Custom(&builder, name, prefix, "", data)
2229 androidMk := builder.String()
Jooyung Han394951d2019-10-07 15:34:50 +09002230 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2231 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2232 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2233 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
2234 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.json.myapex\n")
2235 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002236 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002237}
2238
Jooyung Han5c998b92019-06-27 11:30:33 +09002239func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002240 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002241 apex {
2242 name: "myapex",
2243 key: "myapex.key",
2244 native_shared_libs: ["mylib"],
2245 uses: ["commonapex"],
2246 }
2247
2248 apex {
2249 name: "commonapex",
2250 key: "myapex.key",
2251 native_shared_libs: ["libcommon"],
2252 provide_cpp_shared_libs: true,
2253 }
2254
2255 apex_key {
2256 name: "myapex.key",
2257 public_key: "testkey.avbpubkey",
2258 private_key: "testkey.pem",
2259 }
2260
2261 cc_library {
2262 name: "mylib",
2263 srcs: ["mylib.cpp"],
2264 shared_libs: ["libcommon"],
2265 system_shared_libs: [],
2266 stl: "none",
2267 }
2268
2269 cc_library {
2270 name: "libcommon",
2271 srcs: ["mylib_common.cpp"],
2272 system_shared_libs: [],
2273 stl: "none",
2274 }
2275 `)
2276
2277 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2278 apexRule1 := module1.Rule("apexRule")
2279 copyCmds1 := apexRule1.Args["copy_commands"]
2280
2281 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2282 apexRule2 := module2.Rule("apexRule")
2283 copyCmds2 := apexRule2.Args["copy_commands"]
2284
2285 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2286 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2287 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2288 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2289 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2290}
2291
2292func TestApexUsesFailsIfNotProvided(t *testing.T) {
2293 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2294 apex {
2295 name: "myapex",
2296 key: "myapex.key",
2297 uses: ["commonapex"],
2298 }
2299
2300 apex {
2301 name: "commonapex",
2302 key: "myapex.key",
2303 }
2304
2305 apex_key {
2306 name: "myapex.key",
2307 public_key: "testkey.avbpubkey",
2308 private_key: "testkey.pem",
2309 }
2310 `)
2311 testApexError(t, `uses: "commonapex" is not a provider`, `
2312 apex {
2313 name: "myapex",
2314 key: "myapex.key",
2315 uses: ["commonapex"],
2316 }
2317
2318 cc_library {
2319 name: "commonapex",
2320 system_shared_libs: [],
2321 stl: "none",
2322 }
2323
2324 apex_key {
2325 name: "myapex.key",
2326 public_key: "testkey.avbpubkey",
2327 private_key: "testkey.pem",
2328 }
2329 `)
2330}
2331
2332func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2333 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2334 apex {
2335 name: "myapex",
2336 key: "myapex.key",
2337 use_vendor: true,
2338 uses: ["commonapex"],
2339 }
2340
2341 apex {
2342 name: "commonapex",
2343 key: "myapex.key",
2344 provide_cpp_shared_libs: true,
2345 }
2346
2347 apex_key {
2348 name: "myapex.key",
2349 public_key: "testkey.avbpubkey",
2350 private_key: "testkey.pem",
2351 }
2352 `)
2353}
2354
Jooyung Hand48f3c32019-08-23 11:18:57 +09002355func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2356 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2357 apex {
2358 name: "myapex",
2359 key: "myapex.key",
2360 native_shared_libs: ["libfoo"],
2361 }
2362
2363 apex_key {
2364 name: "myapex.key",
2365 public_key: "testkey.avbpubkey",
2366 private_key: "testkey.pem",
2367 }
2368
2369 cc_library {
2370 name: "libfoo",
2371 stl: "none",
2372 system_shared_libs: [],
2373 enabled: false,
2374 }
2375 `)
2376 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2377 apex {
2378 name: "myapex",
2379 key: "myapex.key",
2380 java_libs: ["myjar"],
2381 }
2382
2383 apex_key {
2384 name: "myapex.key",
2385 public_key: "testkey.avbpubkey",
2386 private_key: "testkey.pem",
2387 }
2388
2389 java_library {
2390 name: "myjar",
2391 srcs: ["foo/bar/MyClass.java"],
2392 sdk_version: "none",
2393 system_modules: "none",
2394 compile_dex: true,
2395 enabled: false,
2396 }
2397 `)
2398}
2399
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002400func TestApexWithApps(t *testing.T) {
2401 ctx, _ := testApex(t, `
2402 apex {
2403 name: "myapex",
2404 key: "myapex.key",
2405 apps: [
2406 "AppFoo",
2407 ],
2408 }
2409
2410 apex_key {
2411 name: "myapex.key",
2412 public_key: "testkey.avbpubkey",
2413 private_key: "testkey.pem",
2414 }
2415
2416 android_app {
2417 name: "AppFoo",
2418 srcs: ["foo/bar/MyClass.java"],
2419 sdk_version: "none",
2420 system_modules: "none",
2421 }
2422 `)
2423
2424 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2425 apexRule := module.Rule("apexRule")
2426 copyCmds := apexRule.Args["copy_commands"]
2427
2428 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
2429
2430}
2431
Jiyong Park127b40b2019-09-30 16:04:35 +09002432func TestApexAvailable(t *testing.T) {
2433 // libfoo is not available to myapex, but only to otherapex
2434 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2435 apex {
2436 name: "myapex",
2437 key: "myapex.key",
2438 native_shared_libs: ["libfoo"],
2439 }
2440
2441 apex_key {
2442 name: "myapex.key",
2443 public_key: "testkey.avbpubkey",
2444 private_key: "testkey.pem",
2445 }
2446
2447 apex {
2448 name: "otherapex",
2449 key: "otherapex.key",
2450 native_shared_libs: ["libfoo"],
2451 }
2452
2453 apex_key {
2454 name: "otherapex.key",
2455 public_key: "testkey.avbpubkey",
2456 private_key: "testkey.pem",
2457 }
2458
2459 cc_library {
2460 name: "libfoo",
2461 stl: "none",
2462 system_shared_libs: [],
2463 apex_available: ["otherapex"],
2464 }`)
2465
2466 // libbar is an indirect dep
2467 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2468 apex {
2469 name: "myapex",
2470 key: "myapex.key",
2471 native_shared_libs: ["libfoo"],
2472 }
2473
2474 apex_key {
2475 name: "myapex.key",
2476 public_key: "testkey.avbpubkey",
2477 private_key: "testkey.pem",
2478 }
2479
2480 apex {
2481 name: "otherapex",
2482 key: "otherapex.key",
2483 native_shared_libs: ["libfoo"],
2484 }
2485
2486 apex_key {
2487 name: "otherapex.key",
2488 public_key: "testkey.avbpubkey",
2489 private_key: "testkey.pem",
2490 }
2491
2492 cc_library {
2493 name: "libfoo",
2494 stl: "none",
2495 shared_libs: ["libbar"],
2496 system_shared_libs: [],
2497 apex_available: ["myapex", "otherapex"],
2498 }
2499
2500 cc_library {
2501 name: "libbar",
2502 stl: "none",
2503 system_shared_libs: [],
2504 apex_available: ["otherapex"],
2505 }`)
2506
2507 testApexError(t, "\"otherapex\" is not a valid module name", `
2508 apex {
2509 name: "myapex",
2510 key: "myapex.key",
2511 native_shared_libs: ["libfoo"],
2512 }
2513
2514 apex_key {
2515 name: "myapex.key",
2516 public_key: "testkey.avbpubkey",
2517 private_key: "testkey.pem",
2518 }
2519
2520 cc_library {
2521 name: "libfoo",
2522 stl: "none",
2523 system_shared_libs: [],
2524 apex_available: ["otherapex"],
2525 }`)
2526
2527 ctx, _ := testApex(t, `
2528 apex {
2529 name: "myapex",
2530 key: "myapex.key",
2531 native_shared_libs: ["libfoo", "libbar"],
2532 }
2533
2534 apex_key {
2535 name: "myapex.key",
2536 public_key: "testkey.avbpubkey",
2537 private_key: "testkey.pem",
2538 }
2539
2540 cc_library {
2541 name: "libfoo",
2542 stl: "none",
2543 system_shared_libs: [],
2544 apex_available: ["myapex"],
2545 }
2546
2547 cc_library {
2548 name: "libbar",
2549 stl: "none",
2550 system_shared_libs: [],
2551 apex_available: ["//apex_available:anyapex"],
2552 }`)
2553
2554 // check that libfoo and libbar are created only for myapex, but not for the platform
2555 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2556 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2557 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2558 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2559
2560 ctx, _ = testApex(t, `
2561 apex {
2562 name: "myapex",
2563 key: "myapex.key",
2564 }
2565
2566 apex_key {
2567 name: "myapex.key",
2568 public_key: "testkey.avbpubkey",
2569 private_key: "testkey.pem",
2570 }
2571
2572 cc_library {
2573 name: "libfoo",
2574 stl: "none",
2575 system_shared_libs: [],
2576 apex_available: ["//apex_available:platform"],
2577 }`)
2578
2579 // check that libfoo is created only for the platform
2580 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2581 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2582}
2583
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002584func TestMain(m *testing.M) {
2585 run := func() int {
2586 setUp()
2587 defer tearDown()
2588
2589 return m.Run()
2590 }
2591
2592 os.Exit(run())
2593}