blob: 91c642630622957e75847635369c350892a529f3 [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
774 injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency")
775 ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"]))
776 ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libfoo.so")
777
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
824 injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency")
825 ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"]))
826
827 // Ensure that LLNDK dep is required
828 ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libbar.so")
829
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 Hane1633032019-08-01 17:41:43 +09001585 var injectRule android.TestingBuildParams
1586 var provideNativeLibs, requireNativeLibs []string
1587
1588 injectRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("injectApexDependency")
1589 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1590 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1591 ensureListEmpty(t, provideNativeLibs)
1592 ensureListEmpty(t, requireNativeLibs)
1593
1594 injectRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("injectApexDependency")
1595 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1596 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1597 ensureListEmpty(t, provideNativeLibs)
1598 ensureListContains(t, requireNativeLibs, "libfoo.so")
1599
1600 injectRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("injectApexDependency")
1601 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1602 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1603 ensureListContains(t, provideNativeLibs, "libfoo.so")
1604 ensureListEmpty(t, requireNativeLibs)
1605
1606 injectRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("injectApexDependency")
1607 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1608 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1609 ensureListContains(t, provideNativeLibs, "libfoo.so")
1610 ensureListEmpty(t, requireNativeLibs)
1611}
1612
Alex Light0851b882019-02-07 13:20:53 -08001613func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001614 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001615 apex {
1616 name: "myapex",
1617 key: "myapex.key",
1618 native_shared_libs: ["mylib_common"],
1619 }
1620
1621 apex_key {
1622 name: "myapex.key",
1623 public_key: "testkey.avbpubkey",
1624 private_key: "testkey.pem",
1625 }
1626
1627 cc_library {
1628 name: "mylib_common",
1629 srcs: ["mylib.cpp"],
1630 system_shared_libs: [],
1631 stl: "none",
1632 }
1633 `)
1634
1635 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1636 apexRule := module.Rule("apexRule")
1637 copyCmds := apexRule.Args["copy_commands"]
1638
1639 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1640 t.Log("Apex was a test apex!")
1641 t.Fail()
1642 }
1643 // Ensure that main rule creates an output
1644 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1645
1646 // Ensure that apex variant is created for the direct dep
1647 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1648
1649 // Ensure that both direct and indirect deps are copied into apex
1650 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1651
1652 // Ensure that the platform variant ends with _core_shared
1653 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1654
1655 if !android.InAnyApex("mylib_common") {
1656 t.Log("Found mylib_common not in any apex!")
1657 t.Fail()
1658 }
1659}
1660
1661func TestTestApex(t *testing.T) {
1662 if android.InAnyApex("mylib_common_test") {
1663 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!")
1664 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001665 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001666 apex_test {
1667 name: "myapex",
1668 key: "myapex.key",
1669 native_shared_libs: ["mylib_common_test"],
1670 }
1671
1672 apex_key {
1673 name: "myapex.key",
1674 public_key: "testkey.avbpubkey",
1675 private_key: "testkey.pem",
1676 }
1677
1678 cc_library {
1679 name: "mylib_common_test",
1680 srcs: ["mylib.cpp"],
1681 system_shared_libs: [],
1682 stl: "none",
1683 }
1684 `)
1685
1686 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1687 apexRule := module.Rule("apexRule")
1688 copyCmds := apexRule.Args["copy_commands"]
1689
1690 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1691 t.Log("Apex was not a test apex!")
1692 t.Fail()
1693 }
1694 // Ensure that main rule creates an output
1695 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1696
1697 // Ensure that apex variant is created for the direct dep
1698 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1699
1700 // Ensure that both direct and indirect deps are copied into apex
1701 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1702
1703 // Ensure that the platform variant ends with _core_shared
1704 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1705
1706 if android.InAnyApex("mylib_common_test") {
1707 t.Log("Found mylib_common_test in some apex!")
1708 t.Fail()
1709 }
1710}
1711
Alex Light9670d332019-01-29 18:07:33 -08001712func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001713 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001714 apex {
1715 name: "myapex",
1716 key: "myapex.key",
1717 multilib: {
1718 first: {
1719 native_shared_libs: ["mylib_common"],
1720 }
1721 },
1722 target: {
1723 android: {
1724 multilib: {
1725 first: {
1726 native_shared_libs: ["mylib"],
1727 }
1728 }
1729 },
1730 host: {
1731 multilib: {
1732 first: {
1733 native_shared_libs: ["mylib2"],
1734 }
1735 }
1736 }
1737 }
1738 }
1739
1740 apex_key {
1741 name: "myapex.key",
1742 public_key: "testkey.avbpubkey",
1743 private_key: "testkey.pem",
1744 }
1745
1746 cc_library {
1747 name: "mylib",
1748 srcs: ["mylib.cpp"],
1749 system_shared_libs: [],
1750 stl: "none",
1751 }
1752
1753 cc_library {
1754 name: "mylib_common",
1755 srcs: ["mylib.cpp"],
1756 system_shared_libs: [],
1757 stl: "none",
1758 compile_multilib: "first",
1759 }
1760
1761 cc_library {
1762 name: "mylib2",
1763 srcs: ["mylib.cpp"],
1764 system_shared_libs: [],
1765 stl: "none",
1766 compile_multilib: "first",
1767 }
1768 `)
1769
1770 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1771 copyCmds := apexRule.Args["copy_commands"]
1772
1773 // Ensure that main rule creates an output
1774 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1775
1776 // Ensure that apex variant is created for the direct dep
1777 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1778 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1779 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1780
1781 // Ensure that both direct and indirect deps are copied into apex
1782 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1783 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1784 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1785
1786 // Ensure that the platform variant ends with _core_shared
1787 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1788 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1789 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1790}
Jiyong Park04480cf2019-02-06 00:16:29 +09001791
1792func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001793 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001794 apex {
1795 name: "myapex",
1796 key: "myapex.key",
1797 binaries: ["myscript"],
1798 }
1799
1800 apex_key {
1801 name: "myapex.key",
1802 public_key: "testkey.avbpubkey",
1803 private_key: "testkey.pem",
1804 }
1805
1806 sh_binary {
1807 name: "myscript",
1808 src: "mylib.cpp",
1809 filename: "myscript.sh",
1810 sub_dir: "script",
1811 }
1812 `)
1813
1814 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1815 copyCmds := apexRule.Args["copy_commands"]
1816
1817 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1818}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001819
1820func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001821 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001822 apex {
1823 name: "myapex",
1824 key: "myapex.key",
1825 native_shared_libs: ["mylib"],
1826 product_specific: true,
1827 }
1828
1829 apex_key {
1830 name: "myapex.key",
1831 public_key: "testkey.avbpubkey",
1832 private_key: "testkey.pem",
1833 product_specific: true,
1834 }
1835
1836 cc_library {
1837 name: "mylib",
1838 srcs: ["mylib.cpp"],
1839 system_shared_libs: [],
1840 stl: "none",
1841 }
1842 `)
1843
1844 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1845 expected := "target/product/test_device/product/apex"
1846 actual := apex.installDir.RelPathString()
1847 if actual != expected {
1848 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1849 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001850}
Jiyong Park67882562019-03-21 01:11:21 +09001851
1852func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001853 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001854 apex_key {
1855 name: "myapex.key",
1856 public_key: ":my.avbpubkey",
1857 private_key: ":my.pem",
1858 product_specific: true,
1859 }
1860
1861 filegroup {
1862 name: "my.avbpubkey",
1863 srcs: ["testkey2.avbpubkey"],
1864 }
1865
1866 filegroup {
1867 name: "my.pem",
1868 srcs: ["testkey2.pem"],
1869 }
1870 `)
1871
1872 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1873 expected_pubkey := "testkey2.avbpubkey"
1874 actual_pubkey := apex_key.public_key_file.String()
1875 if actual_pubkey != expected_pubkey {
1876 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1877 }
1878 expected_privkey := "testkey2.pem"
1879 actual_privkey := apex_key.private_key_file.String()
1880 if actual_privkey != expected_privkey {
1881 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1882 }
1883}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001884
1885func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001886 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001887 prebuilt_apex {
1888 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001889 arch: {
1890 arm64: {
1891 src: "myapex-arm64.apex",
1892 },
1893 arm: {
1894 src: "myapex-arm.apex",
1895 },
1896 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001897 }
1898 `)
1899
1900 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1901
Jiyong Parkc95714e2019-03-29 14:23:10 +09001902 expectedInput := "myapex-arm64.apex"
1903 if prebuilt.inputApex.String() != expectedInput {
1904 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1905 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001906}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001907
1908func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001909 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001910 prebuilt_apex {
1911 name: "myapex",
1912 src: "myapex-arm.apex",
1913 filename: "notmyapex.apex",
1914 }
1915 `)
1916
1917 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1918
1919 expected := "notmyapex.apex"
1920 if p.installFilename != expected {
1921 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1922 }
1923}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001924
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001925func TestPrebuiltOverrides(t *testing.T) {
1926 ctx, config := testApex(t, `
1927 prebuilt_apex {
1928 name: "myapex.prebuilt",
1929 src: "myapex-arm.apex",
1930 overrides: [
1931 "myapex",
1932 ],
1933 }
1934 `)
1935
1936 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1937
1938 expected := []string{"myapex"}
1939 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1940 if !reflect.DeepEqual(actual, expected) {
1941 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1942 }
1943}
1944
Roland Levillain630846d2019-06-26 12:48:34 +01001945func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001946 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01001947 apex_test {
1948 name: "myapex",
1949 key: "myapex.key",
1950 tests: [
1951 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01001952 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01001953 ],
1954 }
1955
1956 apex_key {
1957 name: "myapex.key",
1958 public_key: "testkey.avbpubkey",
1959 private_key: "testkey.pem",
1960 }
1961
1962 cc_test {
1963 name: "mytest",
1964 gtest: false,
1965 srcs: ["mytest.cpp"],
1966 relative_install_path: "test",
1967 system_shared_libs: [],
1968 static_executable: true,
1969 stl: "none",
1970 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01001971
1972 cc_test {
1973 name: "mytests",
1974 gtest: false,
1975 srcs: [
1976 "mytest1.cpp",
1977 "mytest2.cpp",
1978 "mytest3.cpp",
1979 ],
1980 test_per_src: true,
1981 relative_install_path: "test",
1982 system_shared_libs: [],
1983 static_executable: true,
1984 stl: "none",
1985 }
Roland Levillain630846d2019-06-26 12:48:34 +01001986 `)
1987
1988 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1989 copyCmds := apexRule.Args["copy_commands"]
1990
1991 // Ensure that test dep is copied into apex.
1992 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01001993
1994 // Ensure that test deps built with `test_per_src` are copied into apex.
1995 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
1996 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
1997 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01001998
1999 // Ensure the module is correctly translated.
2000 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
2001 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2002 name := apexBundle.BaseModuleName()
2003 prefix := "TARGET_"
2004 var builder strings.Builder
2005 data.Custom(&builder, name, prefix, "", data)
2006 androidMk := builder.String()
2007 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest\n")
2008 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest1\n")
2009 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest2\n")
2010 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest3\n")
2011 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_manifest.json\n")
2012 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_pubkey\n")
2013 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002014}
2015
Jooyung Han5c998b92019-06-27 11:30:33 +09002016func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002017 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002018 apex {
2019 name: "myapex",
2020 key: "myapex.key",
2021 native_shared_libs: ["mylib"],
2022 uses: ["commonapex"],
2023 }
2024
2025 apex {
2026 name: "commonapex",
2027 key: "myapex.key",
2028 native_shared_libs: ["libcommon"],
2029 provide_cpp_shared_libs: true,
2030 }
2031
2032 apex_key {
2033 name: "myapex.key",
2034 public_key: "testkey.avbpubkey",
2035 private_key: "testkey.pem",
2036 }
2037
2038 cc_library {
2039 name: "mylib",
2040 srcs: ["mylib.cpp"],
2041 shared_libs: ["libcommon"],
2042 system_shared_libs: [],
2043 stl: "none",
2044 }
2045
2046 cc_library {
2047 name: "libcommon",
2048 srcs: ["mylib_common.cpp"],
2049 system_shared_libs: [],
2050 stl: "none",
2051 }
2052 `)
2053
2054 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2055 apexRule1 := module1.Rule("apexRule")
2056 copyCmds1 := apexRule1.Args["copy_commands"]
2057
2058 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2059 apexRule2 := module2.Rule("apexRule")
2060 copyCmds2 := apexRule2.Args["copy_commands"]
2061
2062 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2063 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2064 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2065 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2066 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2067}
2068
2069func TestApexUsesFailsIfNotProvided(t *testing.T) {
2070 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2071 apex {
2072 name: "myapex",
2073 key: "myapex.key",
2074 uses: ["commonapex"],
2075 }
2076
2077 apex {
2078 name: "commonapex",
2079 key: "myapex.key",
2080 }
2081
2082 apex_key {
2083 name: "myapex.key",
2084 public_key: "testkey.avbpubkey",
2085 private_key: "testkey.pem",
2086 }
2087 `)
2088 testApexError(t, `uses: "commonapex" is not a provider`, `
2089 apex {
2090 name: "myapex",
2091 key: "myapex.key",
2092 uses: ["commonapex"],
2093 }
2094
2095 cc_library {
2096 name: "commonapex",
2097 system_shared_libs: [],
2098 stl: "none",
2099 }
2100
2101 apex_key {
2102 name: "myapex.key",
2103 public_key: "testkey.avbpubkey",
2104 private_key: "testkey.pem",
2105 }
2106 `)
2107}
2108
2109func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2110 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2111 apex {
2112 name: "myapex",
2113 key: "myapex.key",
2114 use_vendor: true,
2115 uses: ["commonapex"],
2116 }
2117
2118 apex {
2119 name: "commonapex",
2120 key: "myapex.key",
2121 provide_cpp_shared_libs: true,
2122 }
2123
2124 apex_key {
2125 name: "myapex.key",
2126 public_key: "testkey.avbpubkey",
2127 private_key: "testkey.pem",
2128 }
2129 `)
2130}
2131
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002132func TestApexUsesFailsIfUseNoApex(t *testing.T) {
Jooyung Hancc372c52019-09-25 15:18:44 +09002133 // 'no_apex' prevents a module to be included in an apex
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002134 testApexError(t, `tries to include no_apex module mylib2`, `
2135 apex {
2136 name: "commonapex",
2137 key: "myapex.key",
2138 native_shared_libs: ["mylib"],
2139 }
2140
2141 apex_key {
2142 name: "myapex.key",
2143 public_key: "testkey.avbpubkey",
2144 private_key: "testkey.pem",
2145 }
2146
2147 cc_library {
2148 name: "mylib",
2149 srcs: ["mylib.cpp"],
2150 shared_libs: ["mylib2"],
2151 system_shared_libs: [],
2152 stl: "none",
2153 }
2154
2155 cc_library {
2156 name: "mylib2",
2157 srcs: ["mylib.cpp"],
2158 system_shared_libs: [],
2159 stl: "none",
2160 no_apex: true,
2161 }
2162 `)
2163
Jooyung Hancc372c52019-09-25 15:18:44 +09002164 // respect 'no_apex' even with static link
Sundong Ahn2db7f462019-08-27 18:53:12 +09002165 testApexError(t, `tries to include no_apex module mylib2`, `
2166 apex {
2167 name: "commonapex",
2168 key: "myapex.key",
2169 native_shared_libs: ["mylib"],
2170 }
2171
2172 apex_key {
2173 name: "myapex.key",
2174 public_key: "testkey.avbpubkey",
2175 private_key: "testkey.pem",
2176 }
2177
2178 cc_library {
2179 name: "mylib",
2180 srcs: ["mylib.cpp"],
2181 static_libs: ["mylib2"],
2182 system_shared_libs: [],
2183 stl: "none",
2184 }
2185
2186 cc_library {
2187 name: "mylib2",
2188 srcs: ["mylib.cpp"],
2189 system_shared_libs: [],
2190 stl: "none",
2191 no_apex: true,
2192 }
2193 `)
2194
Jooyung Hancc372c52019-09-25 15:18:44 +09002195 // 'no_apex' can be applied via defaults
2196 testApexError(t, `tries to include no_apex module mylib2`, `
2197 apex {
2198 name: "commonapex",
2199 key: "myapex.key",
2200 native_shared_libs: ["mylib"],
2201 }
2202
2203 apex_key {
2204 name: "myapex.key",
2205 public_key: "testkey.avbpubkey",
2206 private_key: "testkey.pem",
2207 }
2208
2209 cc_library {
2210 name: "mylib",
2211 srcs: ["mylib.cpp"],
2212 static_libs: ["mylib2"],
2213 system_shared_libs: [],
2214 stl: "none",
2215 }
2216
2217 cc_defaults {
2218 name: "mylib2_defaults",
2219 system_shared_libs: [],
2220 stl: "none",
2221 no_apex: true,
2222 }
2223
2224 cc_library {
2225 name: "mylib2",
2226 srcs: ["mylib.cpp"],
2227 defaults: ["mylib2_defaults"],
2228 }
2229 `)
2230}
2231
2232func TestNoApexWorksWithWhitelist(t *testing.T) {
2233
2234 testApex(t, `
2235 apex {
2236 name: "myapex",
2237 key: "myapex.key",
2238 native_shared_libs: ["mylib"],
2239 }
2240
2241 apex_key {
2242 name: "myapex.key",
2243 public_key: "testkey.avbpubkey",
2244 private_key: "testkey.pem",
2245 }
2246
2247 cc_library {
2248 name: "mylib",
2249 srcs: ["mylib.cpp"],
2250 shared_libs: ["mylib2"],
2251 system_shared_libs: [],
2252 stl: "none",
2253 }
2254
2255 cc_defaults {
2256 name: "mylib2_defaults",
2257 system_shared_libs: [],
2258 stl: "none",
2259 no_apex: true,
2260 }
2261
2262 cc_library {
2263 name: "mylib2",
2264 srcs: ["mylib.cpp"],
2265 defaults: ["mylib2_defaults"],
2266 }
2267 `, func(fs map[string][]byte, config android.Config) {
2268 whitelistNoApex = map[string][]string{
2269 "myapex": []string{"mylib2"},
2270 }
2271 })
2272}
2273
2274func TestNoApexCanBeDependedOnViaStubs(t *testing.T) {
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002275 ctx, _ := testApex(t, `
2276 apex {
2277 name: "myapex",
2278 key: "myapex.key",
2279 native_shared_libs: ["mylib"],
2280 }
2281
2282 apex_key {
2283 name: "myapex.key",
2284 public_key: "testkey.avbpubkey",
2285 private_key: "testkey.pem",
2286 }
2287
2288 cc_library {
2289 name: "mylib",
2290 srcs: ["mylib.cpp"],
2291 shared_libs: ["mylib2"],
2292 system_shared_libs: [],
2293 stl: "none",
2294 }
2295
2296 cc_library {
2297 name: "mylib2",
2298 srcs: ["mylib.cpp"],
2299 shared_libs: ["mylib3"],
2300 system_shared_libs: [],
2301 stl: "none",
2302 stubs: {
2303 versions: ["1", "2", "3"],
2304 },
2305 }
2306
Jooyung Hancc372c52019-09-25 15:18:44 +09002307 // this won't be included in "myapex", so 'no_apex' is still valid in this case.
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002308 cc_library {
2309 name: "mylib3",
2310 srcs: ["mylib.cpp"],
2311 system_shared_libs: [],
2312 stl: "none",
2313 no_apex: true,
2314 }
2315 `)
2316
2317 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2318 apexRule := module.Rule("apexRule")
2319 copyCmds := apexRule.Args["copy_commands"]
2320
2321 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2322 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2323 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002324}
2325
Jooyung Hand48f3c32019-08-23 11:18:57 +09002326func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2327 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2328 apex {
2329 name: "myapex",
2330 key: "myapex.key",
2331 native_shared_libs: ["libfoo"],
2332 }
2333
2334 apex_key {
2335 name: "myapex.key",
2336 public_key: "testkey.avbpubkey",
2337 private_key: "testkey.pem",
2338 }
2339
2340 cc_library {
2341 name: "libfoo",
2342 stl: "none",
2343 system_shared_libs: [],
2344 enabled: false,
2345 }
2346 `)
2347 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2348 apex {
2349 name: "myapex",
2350 key: "myapex.key",
2351 java_libs: ["myjar"],
2352 }
2353
2354 apex_key {
2355 name: "myapex.key",
2356 public_key: "testkey.avbpubkey",
2357 private_key: "testkey.pem",
2358 }
2359
2360 java_library {
2361 name: "myjar",
2362 srcs: ["foo/bar/MyClass.java"],
2363 sdk_version: "none",
2364 system_modules: "none",
2365 compile_dex: true,
2366 enabled: false,
2367 }
2368 `)
2369}
2370
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002371func TestApexWithApps(t *testing.T) {
2372 ctx, _ := testApex(t, `
2373 apex {
2374 name: "myapex",
2375 key: "myapex.key",
2376 apps: [
2377 "AppFoo",
2378 ],
2379 }
2380
2381 apex_key {
2382 name: "myapex.key",
2383 public_key: "testkey.avbpubkey",
2384 private_key: "testkey.pem",
2385 }
2386
2387 android_app {
2388 name: "AppFoo",
2389 srcs: ["foo/bar/MyClass.java"],
2390 sdk_version: "none",
2391 system_modules: "none",
2392 }
2393 `)
2394
2395 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2396 apexRule := module.Rule("apexRule")
2397 copyCmds := apexRule.Args["copy_commands"]
2398
2399 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
2400
2401}
2402
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002403func TestMain(m *testing.M) {
2404 run := func() int {
2405 setUp()
2406 defer tearDown()
2407
2408 return m.Run()
2409 }
2410
2411 os.Exit(run())
2412}