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