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