blob: 577cf8fe16f424865fc8c0ab62d959575facdb9b [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.DeviceVndkVersion = proptools.StringPtr("current")
96 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Jiyong Park25fc6a92018-11-18 18:02:45 +090097
98 ctx := android.NewTestArchContext()
Alex Light0851b882019-02-07 13:20:53 -080099 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
100 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900101 ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900102 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +0900103 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700104 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900105
106 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
107 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900108 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900109 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
110 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900111 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900112 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100113 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900114 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900115 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900116 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900117 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900118 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900119 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900120 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900121 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900122 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900123 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900124
Jooyung Han344d5432019-08-23 11:17:39 +0900125 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700126 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
127 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
128 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900129 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900130 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900131 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900132 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100133 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900134 ctx.BottomUp("version", cc.VersionMutator).Parallel()
135 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900136 ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator)
137 ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator)
138 })
139 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
140 ctx.TopDown("apex_deps", apexDepsMutator)
141 ctx.BottomUp("apex", apexMutator)
142 ctx.BottomUp("apex_uses", apexUsesMutator)
143 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
144 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900145 })
146
147 ctx.Register()
148
149 bp = bp + `
150 toolchain_library {
151 name: "libcompiler_rt-extras",
152 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900153 vendor_available: true,
154 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900155 }
156
157 toolchain_library {
158 name: "libatomic",
159 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900160 vendor_available: true,
161 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900162 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900163 }
164
165 toolchain_library {
166 name: "libgcc",
167 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900168 vendor_available: true,
169 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900170 }
171
172 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700173 name: "libgcc_stripped",
174 src: "",
175 vendor_available: true,
176 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900177 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700178 }
179
180 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900181 name: "libclang_rt.builtins-aarch64-android",
182 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900183 vendor_available: true,
184 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900185 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900186 }
187
188 toolchain_library {
189 name: "libclang_rt.builtins-arm-android",
190 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900191 vendor_available: true,
192 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900193 native_bridge_supported: true,
194 }
195
196 toolchain_library {
197 name: "libclang_rt.builtins-x86_64-android",
198 src: "",
199 vendor_available: true,
200 recovery_available: true,
201 native_bridge_supported: true,
202 }
203
204 toolchain_library {
205 name: "libclang_rt.builtins-i686-android",
206 src: "",
207 vendor_available: true,
208 recovery_available: true,
209 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900210 }
211
212 cc_object {
213 name: "crtbegin_so",
214 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900215 vendor_available: true,
216 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900217 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900218 }
219
220 cc_object {
221 name: "crtend_so",
222 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900223 vendor_available: true,
224 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900225 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900226 }
227
Alex Light3d673592019-01-18 14:37:31 -0800228 cc_object {
229 name: "crtbegin_static",
230 stl: "none",
231 }
232
233 cc_object {
234 name: "crtend_android",
235 stl: "none",
236 }
237
Jiyong Parkda6eb592018-12-19 17:12:36 +0900238 llndk_library {
239 name: "libc",
240 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900241 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900242 }
243
244 llndk_library {
245 name: "libm",
246 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900247 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900248 }
249
250 llndk_library {
251 name: "libdl",
252 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900253 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900254 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900255 `
256
Jooyung Han344d5432019-08-23 11:17:39 +0900257 fs := map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900258 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700259 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900260 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900261 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900262 "system/sepolicy/apex/myapex-file_contexts": nil,
263 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
264 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900265 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900266 "mylib.cpp": nil,
267 "mylib_common.cpp": nil,
268 "mytest.cpp": nil,
269 "mytest1.cpp": nil,
270 "mytest2.cpp": nil,
271 "mytest3.cpp": nil,
272 "myprebuilt": nil,
273 "my_include": nil,
274 "foo/bar/MyClass.java": nil,
275 "prebuilt.jar": nil,
276 "vendor/foo/devkeys/test.x509.pem": nil,
277 "vendor/foo/devkeys/test.pk8": nil,
278 "testkey.x509.pem": nil,
279 "testkey.pk8": nil,
280 "testkey.override.x509.pem": nil,
281 "testkey.override.pk8": nil,
282 "vendor/foo/devkeys/testkey.avbpubkey": nil,
283 "vendor/foo/devkeys/testkey.pem": nil,
284 "NOTICE": nil,
285 "custom_notice": nil,
286 "testkey2.avbpubkey": nil,
287 "testkey2.pem": nil,
288 "myapex-arm64.apex": nil,
289 "myapex-arm.apex": nil,
290 "frameworks/base/api/current.txt": nil,
291 "build/make/core/proguard.flags": nil,
292 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900293 }
294
295 for _, handler := range handlers {
296 handler(fs, config)
297 }
298
299 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900300
Jooyung Han5c998b92019-06-27 11:30:33 +0900301 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900302}
303
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700304func setUp() {
305 var err error
306 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900307 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700308 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900309 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310}
311
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700312func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900313 os.RemoveAll(buildDir)
314}
315
316// ensure that 'result' contains 'expected'
317func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900318 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900319 if !strings.Contains(result, expected) {
320 t.Errorf("%q is not found in %q", expected, result)
321 }
322}
323
324// ensures that 'result' does not contain 'notExpected'
325func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900326 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900327 if strings.Contains(result, notExpected) {
328 t.Errorf("%q is found in %q", notExpected, result)
329 }
330}
331
332func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900333 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900334 if !android.InList(expected, result) {
335 t.Errorf("%q is not found in %v", expected, result)
336 }
337}
338
339func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900340 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900341 if android.InList(notExpected, result) {
342 t.Errorf("%q is found in %v", notExpected, result)
343 }
344}
345
Jooyung Hane1633032019-08-01 17:41:43 +0900346func ensureListEmpty(t *testing.T, result []string) {
347 t.Helper()
348 if len(result) > 0 {
349 t.Errorf("%q is expected to be empty", result)
350 }
351}
352
Jiyong Park25fc6a92018-11-18 18:02:45 +0900353// Minimal test
354func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700355 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900356 apex_defaults {
357 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900358 manifest: ":myapex.manifest",
359 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900360 key: "myapex.key",
361 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800362 multilib: {
363 both: {
364 binaries: ["foo",],
365 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900366 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900367 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900368 }
369
Jiyong Park30ca9372019-02-07 16:27:23 +0900370 apex {
371 name: "myapex",
372 defaults: ["myapex-defaults"],
373 }
374
Jiyong Park25fc6a92018-11-18 18:02:45 +0900375 apex_key {
376 name: "myapex.key",
377 public_key: "testkey.avbpubkey",
378 private_key: "testkey.pem",
379 }
380
Jiyong Park809bb722019-02-13 21:33:49 +0900381 filegroup {
382 name: "myapex.manifest",
383 srcs: ["apex_manifest.json"],
384 }
385
386 filegroup {
387 name: "myapex.androidmanifest",
388 srcs: ["AndroidManifest.xml"],
389 }
390
Jiyong Park25fc6a92018-11-18 18:02:45 +0900391 cc_library {
392 name: "mylib",
393 srcs: ["mylib.cpp"],
394 shared_libs: ["mylib2"],
395 system_shared_libs: [],
396 stl: "none",
397 }
398
Alex Light3d673592019-01-18 14:37:31 -0800399 cc_binary {
400 name: "foo",
401 srcs: ["mylib.cpp"],
402 compile_multilib: "both",
403 multilib: {
404 lib32: {
405 suffix: "32",
406 },
407 lib64: {
408 suffix: "64",
409 },
410 },
411 symlinks: ["foo_link_"],
412 symlink_preferred_arch: true,
413 system_shared_libs: [],
414 static_executable: true,
415 stl: "none",
416 }
417
Jiyong Park25fc6a92018-11-18 18:02:45 +0900418 cc_library {
419 name: "mylib2",
420 srcs: ["mylib.cpp"],
421 system_shared_libs: [],
422 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900423 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900424 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900425
426 java_library {
427 name: "myjar",
428 srcs: ["foo/bar/MyClass.java"],
429 sdk_version: "none",
430 system_modules: "none",
431 compile_dex: true,
432 static_libs: ["myotherjar"],
433 }
434
435 java_library {
436 name: "myotherjar",
437 srcs: ["foo/bar/MyClass.java"],
438 sdk_version: "none",
439 system_modules: "none",
440 compile_dex: true,
441 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900442
443 java_import {
444 name: "myprebuiltjar",
445 jars: ["prebuilt.jar"],
446 installable: true,
447 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900448 `)
449
450 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900451
452 optFlags := apexRule.Args["opt_flags"]
453 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700454 // Ensure that the NOTICE output is being packaged as an asset.
455 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900456
Jiyong Park25fc6a92018-11-18 18:02:45 +0900457 copyCmds := apexRule.Args["copy_commands"]
458
459 // Ensure that main rule creates an output
460 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
461
462 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900463 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900464 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900465 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900466
467 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900468 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900469 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900470
471 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800472 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
473 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900474 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900475 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900476 // .. but not for java libs
477 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800478
Jiyong Park7f7766d2019-07-25 22:02:35 +0900479 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800480 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
481 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900482 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
483 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900484 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800485
486 // Ensure that all symlinks are present.
487 found_foo_link_64 := false
488 found_foo := false
489 for _, cmd := range strings.Split(copyCmds, " && ") {
490 if strings.HasPrefix(cmd, "ln -s foo64") {
491 if strings.HasSuffix(cmd, "bin/foo") {
492 found_foo = true
493 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
494 found_foo_link_64 = true
495 }
496 }
497 }
498 good := found_foo && found_foo_link_64
499 if !good {
500 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
501 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900502
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700503 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
504 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700505 if len(noticeInputs) != 2 {
506 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900507 }
508 ensureListContains(t, noticeInputs, "NOTICE")
509 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800510}
511
512func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700513 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800514 apex {
515 name: "myapex",
516 key: "myapex.key",
517 payload_type: "zip",
518 native_shared_libs: ["mylib"],
519 }
520
521 apex_key {
522 name: "myapex.key",
523 public_key: "testkey.avbpubkey",
524 private_key: "testkey.pem",
525 }
526
527 cc_library {
528 name: "mylib",
529 srcs: ["mylib.cpp"],
530 shared_libs: ["mylib2"],
531 system_shared_libs: [],
532 stl: "none",
533 }
534
535 cc_library {
536 name: "mylib2",
537 srcs: ["mylib.cpp"],
538 system_shared_libs: [],
539 stl: "none",
540 }
541 `)
542
543 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
544 copyCmds := zipApexRule.Args["copy_commands"]
545
546 // Ensure that main rule creates an output
547 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
548
549 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900550 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800551
552 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900553 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800554
555 // Ensure that both direct and indirect deps are copied into apex
556 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
557 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900558}
559
560func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700561 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900562 apex {
563 name: "myapex",
564 key: "myapex.key",
565 native_shared_libs: ["mylib", "mylib3"],
566 }
567
568 apex_key {
569 name: "myapex.key",
570 public_key: "testkey.avbpubkey",
571 private_key: "testkey.pem",
572 }
573
574 cc_library {
575 name: "mylib",
576 srcs: ["mylib.cpp"],
577 shared_libs: ["mylib2", "mylib3"],
578 system_shared_libs: [],
579 stl: "none",
580 }
581
582 cc_library {
583 name: "mylib2",
584 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900585 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900586 system_shared_libs: [],
587 stl: "none",
588 stubs: {
589 versions: ["1", "2", "3"],
590 },
591 }
592
593 cc_library {
594 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900595 srcs: ["mylib.cpp"],
596 shared_libs: ["mylib4"],
597 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900598 stl: "none",
599 stubs: {
600 versions: ["10", "11", "12"],
601 },
602 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900603
604 cc_library {
605 name: "mylib4",
606 srcs: ["mylib.cpp"],
607 system_shared_libs: [],
608 stl: "none",
609 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900610 `)
611
612 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
613 copyCmds := apexRule.Args["copy_commands"]
614
615 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800616 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900617
618 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800619 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900620
621 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800622 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900623
Jiyong Parkda6eb592018-12-19 17:12:36 +0900624 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900625
626 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900627 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900628 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900629 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900630
631 // 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 +0900632 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900633 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900634 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900635
636 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900637 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900638 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900639
640 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900641 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 +0900642}
643
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900644func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700645 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900646 apex {
647 name: "myapex",
648 key: "myapex.key",
649 native_shared_libs: ["mylib"],
650 }
651
652 apex_key {
653 name: "myapex.key",
654 public_key: "testkey.avbpubkey",
655 private_key: "testkey.pem",
656 }
657
658 cc_library {
659 name: "mylib",
660 srcs: ["mylib.cpp"],
661 shared_libs: ["libfoo#10"],
662 system_shared_libs: [],
663 stl: "none",
664 }
665
666 cc_library {
667 name: "libfoo",
668 srcs: ["mylib.cpp"],
669 shared_libs: ["libbar"],
670 system_shared_libs: [],
671 stl: "none",
672 stubs: {
673 versions: ["10", "20", "30"],
674 },
675 }
676
677 cc_library {
678 name: "libbar",
679 srcs: ["mylib.cpp"],
680 system_shared_libs: [],
681 stl: "none",
682 }
683
684 `)
685
686 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
687 copyCmds := apexRule.Args["copy_commands"]
688
689 // Ensure that direct non-stubs dep is always included
690 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
691
692 // Ensure that indirect stubs dep is not included
693 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
694
695 // Ensure that dependency of stubs is not included
696 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
697
Jiyong Parkda6eb592018-12-19 17:12:36 +0900698 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900699
700 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900701 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900702 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900703 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900704
Jiyong Parkda6eb592018-12-19 17:12:36 +0900705 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900706
707 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
708 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
709}
710
Jooyung Hand3639552019-08-09 12:57:43 +0900711func TestApexWithRuntimeLibsDependency(t *testing.T) {
712 /*
713 myapex
714 |
715 v (runtime_libs)
716 mylib ------+------> libfoo [provides stub]
717 |
718 `------> libbar
719 */
720 ctx, _ := testApex(t, `
721 apex {
722 name: "myapex",
723 key: "myapex.key",
724 native_shared_libs: ["mylib"],
725 }
726
727 apex_key {
728 name: "myapex.key",
729 public_key: "testkey.avbpubkey",
730 private_key: "testkey.pem",
731 }
732
733 cc_library {
734 name: "mylib",
735 srcs: ["mylib.cpp"],
736 runtime_libs: ["libfoo", "libbar"],
737 system_shared_libs: [],
738 stl: "none",
739 }
740
741 cc_library {
742 name: "libfoo",
743 srcs: ["mylib.cpp"],
744 system_shared_libs: [],
745 stl: "none",
746 stubs: {
747 versions: ["10", "20", "30"],
748 },
749 }
750
751 cc_library {
752 name: "libbar",
753 srcs: ["mylib.cpp"],
754 system_shared_libs: [],
755 stl: "none",
756 }
757
758 `)
759
760 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
761 copyCmds := apexRule.Args["copy_commands"]
762
763 // Ensure that direct non-stubs dep is always included
764 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
765
766 // Ensure that indirect stubs dep is not included
767 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
768
769 // Ensure that runtime_libs dep in included
770 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
771
772 injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency")
773 ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"]))
774 ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libfoo.so")
775
776}
777
Jooyung Han9c80bae2019-08-20 17:30:57 +0900778func TestApexDependencyToLLNDK(t *testing.T) {
779 ctx, _ := testApex(t, `
780 apex {
781 name: "myapex",
782 key: "myapex.key",
783 use_vendor: true,
784 native_shared_libs: ["mylib"],
785 }
786
787 apex_key {
788 name: "myapex.key",
789 public_key: "testkey.avbpubkey",
790 private_key: "testkey.pem",
791 }
792
793 cc_library {
794 name: "mylib",
795 srcs: ["mylib.cpp"],
796 vendor_available: true,
797 shared_libs: ["libbar"],
798 system_shared_libs: [],
799 stl: "none",
800 }
801
802 cc_library {
803 name: "libbar",
804 srcs: ["mylib.cpp"],
805 system_shared_libs: [],
806 stl: "none",
807 }
808
809 llndk_library {
810 name: "libbar",
811 symbol_file: "",
812 }
813
814 `)
815
816 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
817 copyCmds := apexRule.Args["copy_commands"]
818
819 // Ensure that LLNDK dep is not included
820 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
821
822 injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency")
823 ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"]))
824
825 // Ensure that LLNDK dep is required
826 ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libbar.so")
827
828}
829
Jiyong Park25fc6a92018-11-18 18:02:45 +0900830func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700831 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900832 apex {
833 name: "myapex",
834 key: "myapex.key",
835 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
836 }
837
838 apex_key {
839 name: "myapex.key",
840 public_key: "testkey.avbpubkey",
841 private_key: "testkey.pem",
842 }
843
844 cc_library {
845 name: "mylib",
846 srcs: ["mylib.cpp"],
847 shared_libs: ["libdl#27"],
848 stl: "none",
849 }
850
851 cc_library_shared {
852 name: "mylib_shared",
853 srcs: ["mylib.cpp"],
854 shared_libs: ["libdl#27"],
855 stl: "none",
856 }
857
858 cc_library {
859 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700860 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900861 nocrt: true,
862 system_shared_libs: [],
863 stl: "none",
864 stubs: {
865 versions: ["27", "28", "29"],
866 },
867 }
868
869 cc_library {
870 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700871 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900872 nocrt: true,
873 system_shared_libs: [],
874 stl: "none",
875 stubs: {
876 versions: ["27", "28", "29"],
877 },
878 }
879
880 cc_library {
881 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700882 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900883 nocrt: true,
884 system_shared_libs: [],
885 stl: "none",
886 stubs: {
887 versions: ["27", "28", "29"],
888 },
889 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900890
891 cc_library {
892 name: "libBootstrap",
893 srcs: ["mylib.cpp"],
894 stl: "none",
895 bootstrap: true,
896 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900897 `)
898
899 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
900 copyCmds := apexRule.Args["copy_commands"]
901
902 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800903 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900904 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
905 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900906
907 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900908 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900909
Jiyong Parkda6eb592018-12-19 17:12:36 +0900910 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
911 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
912 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900913
914 // For dependency to libc
915 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900916 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900917 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900918 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900919 // ... Cflags from stub is correctly exported to mylib
920 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
921 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
922
923 // For dependency to libm
924 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900925 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900926 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900927 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900928 // ... and is not compiling with the stub
929 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
930 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
931
932 // For dependency to libdl
933 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900934 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900935 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900936 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
937 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900938 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900939 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900940 // ... Cflags from stub is correctly exported to mylib
941 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
942 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900943
944 // Ensure that libBootstrap is depending on the platform variant of bionic libs
945 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
946 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
947 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
948 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900949}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900950
951func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700952 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900953 apex {
954 name: "myapex",
955 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900956 native_shared_libs: ["mylib"],
957 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900958 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900959 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900960 }
961
962 apex_key {
963 name: "myapex.key",
964 public_key: "testkey.avbpubkey",
965 private_key: "testkey.pem",
966 }
967
968 prebuilt_etc {
969 name: "myetc",
970 src: "myprebuilt",
971 sub_dir: "foo/bar",
972 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900973
974 cc_library {
975 name: "mylib",
976 srcs: ["mylib.cpp"],
977 relative_install_path: "foo/bar",
978 system_shared_libs: [],
979 stl: "none",
980 }
981
982 cc_binary {
983 name: "mybin",
984 srcs: ["mylib.cpp"],
985 relative_install_path: "foo/bar",
986 system_shared_libs: [],
987 static_executable: true,
988 stl: "none",
989 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900990 `)
991
992 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
993 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
994
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900995 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900996 ensureListContains(t, dirs, "etc")
997 ensureListContains(t, dirs, "etc/foo")
998 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900999 ensureListContains(t, dirs, "lib64")
1000 ensureListContains(t, dirs, "lib64/foo")
1001 ensureListContains(t, dirs, "lib64/foo/bar")
1002 ensureListContains(t, dirs, "lib")
1003 ensureListContains(t, dirs, "lib/foo")
1004 ensureListContains(t, dirs, "lib/foo/bar")
1005
Jiyong Parkbd13e442019-03-15 18:10:35 +09001006 ensureListContains(t, dirs, "bin")
1007 ensureListContains(t, dirs, "bin/foo")
1008 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001009}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001010
1011func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001012 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001013 apex {
1014 name: "myapex",
1015 key: "myapex.key",
1016 native_shared_libs: ["mylib"],
1017 use_vendor: true,
1018 }
1019
1020 apex_key {
1021 name: "myapex.key",
1022 public_key: "testkey.avbpubkey",
1023 private_key: "testkey.pem",
1024 }
1025
1026 cc_library {
1027 name: "mylib",
1028 srcs: ["mylib.cpp"],
1029 shared_libs: ["mylib2"],
1030 system_shared_libs: [],
1031 vendor_available: true,
1032 stl: "none",
1033 }
1034
1035 cc_library {
1036 name: "mylib2",
1037 srcs: ["mylib.cpp"],
1038 system_shared_libs: [],
1039 vendor_available: true,
1040 stl: "none",
1041 }
1042 `)
1043
1044 inputsList := []string{}
1045 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
1046 for _, implicit := range i.Implicits {
1047 inputsList = append(inputsList, implicit.String())
1048 }
1049 }
1050 inputsString := strings.Join(inputsList, " ")
1051
1052 // ensure that the apex includes vendor variants of the direct and indirect deps
1053 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
1054 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
1055
1056 // ensure that the apex does not include core variants
1057 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1058 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1059}
Jiyong Park16e91a02018-12-20 18:18:08 +09001060
Jooyung Han5c998b92019-06-27 11:30:33 +09001061func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1062 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1063 apex {
1064 name: "myapex",
1065 key: "myapex.key",
1066 native_shared_libs: ["mylib"],
1067 use_vendor: true,
1068 }
1069
1070 apex_key {
1071 name: "myapex.key",
1072 public_key: "testkey.avbpubkey",
1073 private_key: "testkey.pem",
1074 }
1075
1076 cc_library {
1077 name: "mylib",
1078 srcs: ["mylib.cpp"],
1079 system_shared_libs: [],
1080 stl: "none",
1081 }
1082 `)
1083}
1084
Jiyong Park16e91a02018-12-20 18:18:08 +09001085func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001086 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001087 apex {
1088 name: "myapex",
1089 key: "myapex.key",
1090 native_shared_libs: ["mylib"],
1091 }
1092
1093 apex_key {
1094 name: "myapex.key",
1095 public_key: "testkey.avbpubkey",
1096 private_key: "testkey.pem",
1097 }
1098
1099 cc_library {
1100 name: "mylib",
1101 srcs: ["mylib.cpp"],
1102 system_shared_libs: [],
1103 stl: "none",
1104 stubs: {
1105 versions: ["1", "2", "3"],
1106 },
1107 }
1108
1109 cc_binary {
1110 name: "not_in_apex",
1111 srcs: ["mylib.cpp"],
1112 static_libs: ["mylib"],
1113 static_executable: true,
1114 system_shared_libs: [],
1115 stl: "none",
1116 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001117 `)
1118
1119 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1120
1121 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001122 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001123}
Jiyong Park9335a262018-12-24 11:31:58 +09001124
1125func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001126 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001127 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001128 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001129 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001130 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001131 native_shared_libs: ["mylib"],
1132 }
1133
1134 cc_library {
1135 name: "mylib",
1136 srcs: ["mylib.cpp"],
1137 system_shared_libs: [],
1138 stl: "none",
1139 }
1140
1141 apex_key {
1142 name: "myapex.key",
1143 public_key: "testkey.avbpubkey",
1144 private_key: "testkey.pem",
1145 }
1146
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001147 android_app_certificate {
1148 name: "myapex.certificate",
1149 certificate: "testkey",
1150 }
1151
1152 android_app_certificate {
1153 name: "myapex.certificate.override",
1154 certificate: "testkey.override",
1155 }
1156
Jiyong Park9335a262018-12-24 11:31:58 +09001157 `)
1158
1159 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001160 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001161
1162 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1163 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1164 "vendor/foo/devkeys/testkey.avbpubkey")
1165 }
1166 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1167 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1168 "vendor/foo/devkeys/testkey.pem")
1169 }
1170
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001171 // check the APK certs. It should be overridden to myapex.certificate.override
1172 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
1173 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001174 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001175 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001176 }
1177}
Jiyong Park58e364a2019-01-19 19:24:06 +09001178
1179func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001180 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001181 apex {
1182 name: "myapex",
1183 key: "myapex.key",
1184 native_shared_libs: ["mylib"],
1185 }
1186
1187 apex {
1188 name: "otherapex",
1189 key: "myapex.key",
1190 native_shared_libs: ["mylib"],
1191 }
1192
1193 apex_key {
1194 name: "myapex.key",
1195 public_key: "testkey.avbpubkey",
1196 private_key: "testkey.pem",
1197 }
1198
1199 cc_library {
1200 name: "mylib",
1201 srcs: ["mylib.cpp"],
1202 system_shared_libs: [],
1203 stl: "none",
1204 }
1205 `)
1206
1207 // non-APEX variant does not have __ANDROID__APEX__ defined
1208 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1209 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1210 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1211
1212 // APEX variant has __ANDROID_APEX__=<apexname> defined
1213 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1214 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1215 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1216
1217 // APEX variant has __ANDROID_APEX__=<apexname> defined
1218 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1219 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1220 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1221}
Jiyong Park7e636d02019-01-28 16:16:54 +09001222
1223func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001224 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001225 apex {
1226 name: "myapex",
1227 key: "myapex.key",
1228 native_shared_libs: ["mylib"],
1229 }
1230
1231 apex_key {
1232 name: "myapex.key",
1233 public_key: "testkey.avbpubkey",
1234 private_key: "testkey.pem",
1235 }
1236
1237 cc_library_headers {
1238 name: "mylib_headers",
1239 export_include_dirs: ["my_include"],
1240 system_shared_libs: [],
1241 stl: "none",
1242 }
1243
1244 cc_library {
1245 name: "mylib",
1246 srcs: ["mylib.cpp"],
1247 system_shared_libs: [],
1248 stl: "none",
1249 header_libs: ["mylib_headers"],
1250 export_header_lib_headers: ["mylib_headers"],
1251 stubs: {
1252 versions: ["1", "2", "3"],
1253 },
1254 }
1255
1256 cc_library {
1257 name: "otherlib",
1258 srcs: ["mylib.cpp"],
1259 system_shared_libs: [],
1260 stl: "none",
1261 shared_libs: ["mylib"],
1262 }
1263 `)
1264
1265 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1266
1267 // Ensure that the include path of the header lib is exported to 'otherlib'
1268 ensureContains(t, cFlags, "-Imy_include")
1269}
Alex Light9670d332019-01-29 18:07:33 -08001270
Jooyung Han344d5432019-08-23 11:17:39 +09001271func TestVndkApexCurrent(t *testing.T) {
1272 ctx, _ := testApex(t, `
1273 apex_vndk {
1274 name: "myapex",
1275 key: "myapex.key",
1276 file_contexts: "myapex",
1277 }
1278
1279 apex_key {
1280 name: "myapex.key",
1281 public_key: "testkey.avbpubkey",
1282 private_key: "testkey.pem",
1283 }
1284
1285 cc_library {
1286 name: "libvndk",
1287 srcs: ["mylib.cpp"],
1288 vendor_available: true,
1289 vndk: {
1290 enabled: true,
1291 },
1292 system_shared_libs: [],
1293 stl: "none",
1294 }
1295
1296 cc_library {
1297 name: "libvndksp",
1298 srcs: ["mylib.cpp"],
1299 vendor_available: true,
1300 vndk: {
1301 enabled: true,
1302 support_system_process: true,
1303 },
1304 system_shared_libs: [],
1305 stl: "none",
1306 }
1307 `)
1308
1309 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1310 copyCmds := apexRule.Args["copy_commands"]
1311 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1312 ensureContains(t, copyCmds, "image.apex/lib/libvndksp.so")
1313 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1314 ensureContains(t, copyCmds, "image.apex/lib64/libvndksp.so")
1315}
1316
1317func TestVndkApexWithPrebuilt(t *testing.T) {
1318 ctx, _ := testApex(t, `
1319 apex_vndk {
1320 name: "myapex",
1321 key: "myapex.key",
1322 file_contexts: "myapex",
1323 }
1324
1325 apex_key {
1326 name: "myapex.key",
1327 public_key: "testkey.avbpubkey",
1328 private_key: "testkey.pem",
1329 }
1330
1331 cc_prebuilt_library_shared {
1332 name: "libvndkshared",
1333 srcs: ["libvndkshared.so"],
1334 vendor_available: true,
1335 vndk: {
1336 enabled: true,
1337 },
1338 system_shared_libs: [],
1339 stl: "none",
1340 }
1341 `, withFiles(map[string][]byte{
1342 "libvndkshared.so": nil,
1343 }))
1344
1345 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1346 copyCmds := apexRule.Args["copy_commands"]
1347 ensureContains(t, copyCmds, "image.apex/lib/libvndkshared.so")
1348}
1349
1350func TestVndkApexVersion(t *testing.T) {
1351 ctx, _ := testApex(t, `
1352 apex_vndk {
1353 name: "myapex_v27",
1354 key: "myapex.key",
1355 file_contexts: "myapex",
1356 vndk_version: "27",
1357 }
1358
1359 apex_key {
1360 name: "myapex.key",
1361 public_key: "testkey.avbpubkey",
1362 private_key: "testkey.pem",
1363 }
1364
1365 cc_library {
1366 name: "libvndk",
1367 srcs: ["mylib.cpp"],
1368 vendor_available: true,
1369 vndk: {
1370 enabled: true,
1371 },
1372 system_shared_libs: [],
1373 stl: "none",
1374 }
1375
1376 vndk_prebuilt_shared {
1377 name: "libvndk27",
1378 version: "27",
1379 vendor_available: true,
1380 vndk: {
1381 enabled: true,
1382 },
1383 srcs: ["libvndk27.so"],
1384 }
1385 `, withFiles(map[string][]byte{
1386 "libvndk27.so": nil,
1387 }))
1388
1389 apexRule := ctx.ModuleForTests("myapex_v27", "android_common_myapex_v27").Rule("apexRule")
1390 copyCmds := apexRule.Args["copy_commands"]
1391 ensureContains(t, copyCmds, "image.apex/lib/libvndk27.so")
1392 ensureContains(t, copyCmds, "image.apex/lib64/libvndk27.so")
1393 ensureNotContains(t, copyCmds, "image.apex/lib/libvndk.so")
1394}
1395
1396func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1397 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1398 apex_vndk {
1399 name: "myapex_v27",
1400 key: "myapex.key",
1401 file_contexts: "myapex",
1402 vndk_version: "27",
1403 }
1404 apex_vndk {
1405 name: "myapex_v27_other",
1406 key: "myapex.key",
1407 file_contexts: "myapex",
1408 vndk_version: "27",
1409 }
1410
1411 apex_key {
1412 name: "myapex.key",
1413 public_key: "testkey.avbpubkey",
1414 private_key: "testkey.pem",
1415 }
1416
1417 cc_library {
1418 name: "libvndk",
1419 srcs: ["mylib.cpp"],
1420 vendor_available: true,
1421 vndk: {
1422 enabled: true,
1423 },
1424 system_shared_libs: [],
1425 stl: "none",
1426 }
1427
1428 vndk_prebuilt_shared {
1429 name: "libvndk",
1430 version: "27",
1431 vendor_available: true,
1432 vndk: {
1433 enabled: true,
1434 },
1435 srcs: ["libvndk.so"],
1436 }
1437 `, withFiles(map[string][]byte{
1438 "libvndk.so": nil,
1439 }))
1440}
1441
1442func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1443 ctx, _ := testApex(t, `
1444 apex_vndk {
1445 name: "myapex",
1446 key: "myapex.key",
1447 file_contexts: "myapex",
1448 }
1449
1450 apex_key {
1451 name: "myapex.key",
1452 public_key: "testkey.avbpubkey",
1453 private_key: "testkey.pem",
1454 }
1455
1456 cc_library {
1457 name: "libvndk",
1458 srcs: ["mylib.cpp"],
1459 vendor_available: true,
1460 native_bridge_supported: true,
1461 host_supported: true,
1462 vndk: {
1463 enabled: true,
1464 },
1465 system_shared_libs: [],
1466 stl: "none",
1467 }
1468 `, withTargets(map[android.OsType][]android.Target{
1469 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001470 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1471 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1472 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1473 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
Jooyung Han344d5432019-08-23 11:17:39 +09001474 },
1475 }))
1476
1477 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1478 copyCmds := apexRule.Args["copy_commands"]
1479 ensureContains(t, copyCmds, "image.apex/lib/libvndk.so")
1480 ensureContains(t, copyCmds, "image.apex/lib64/libvndk.so")
1481
1482 // apex
1483 ensureNotContains(t, copyCmds, "image.apex/lib/x86/libvndk.so")
1484 ensureNotContains(t, copyCmds, "image.apex/lib64/x86_64/libvndk.so")
1485}
1486
1487func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1488 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1489 apex_vndk {
1490 name: "myapex",
1491 key: "myapex.key",
1492 file_contexts: "myapex",
1493 native_bridge_supported: true,
1494 }
1495
1496 apex_key {
1497 name: "myapex.key",
1498 public_key: "testkey.avbpubkey",
1499 private_key: "testkey.pem",
1500 }
1501
1502 cc_library {
1503 name: "libvndk",
1504 srcs: ["mylib.cpp"],
1505 vendor_available: true,
1506 native_bridge_supported: true,
1507 host_supported: true,
1508 vndk: {
1509 enabled: true,
1510 },
1511 system_shared_libs: [],
1512 stl: "none",
1513 }
1514 `)
1515}
1516
Jooyung Hane1633032019-08-01 17:41:43 +09001517func TestDependenciesInApexManifest(t *testing.T) {
1518 ctx, _ := testApex(t, `
1519 apex {
1520 name: "myapex_nodep",
1521 key: "myapex.key",
1522 native_shared_libs: ["lib_nodep"],
1523 compile_multilib: "both",
1524 file_contexts: "myapex",
1525 }
1526
1527 apex {
1528 name: "myapex_dep",
1529 key: "myapex.key",
1530 native_shared_libs: ["lib_dep"],
1531 compile_multilib: "both",
1532 file_contexts: "myapex",
1533 }
1534
1535 apex {
1536 name: "myapex_provider",
1537 key: "myapex.key",
1538 native_shared_libs: ["libfoo"],
1539 compile_multilib: "both",
1540 file_contexts: "myapex",
1541 }
1542
1543 apex {
1544 name: "myapex_selfcontained",
1545 key: "myapex.key",
1546 native_shared_libs: ["lib_dep", "libfoo"],
1547 compile_multilib: "both",
1548 file_contexts: "myapex",
1549 }
1550
1551 apex_key {
1552 name: "myapex.key",
1553 public_key: "testkey.avbpubkey",
1554 private_key: "testkey.pem",
1555 }
1556
1557 cc_library {
1558 name: "lib_nodep",
1559 srcs: ["mylib.cpp"],
1560 system_shared_libs: [],
1561 stl: "none",
1562 }
1563
1564 cc_library {
1565 name: "lib_dep",
1566 srcs: ["mylib.cpp"],
1567 shared_libs: ["libfoo"],
1568 system_shared_libs: [],
1569 stl: "none",
1570 }
1571
1572 cc_library {
1573 name: "libfoo",
1574 srcs: ["mytest.cpp"],
1575 stubs: {
1576 versions: ["1"],
1577 },
1578 system_shared_libs: [],
1579 stl: "none",
1580 }
1581 `)
1582
Jooyung Hane1633032019-08-01 17:41:43 +09001583 var injectRule android.TestingBuildParams
1584 var provideNativeLibs, requireNativeLibs []string
1585
1586 injectRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("injectApexDependency")
1587 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1588 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1589 ensureListEmpty(t, provideNativeLibs)
1590 ensureListEmpty(t, requireNativeLibs)
1591
1592 injectRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("injectApexDependency")
1593 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1594 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1595 ensureListEmpty(t, provideNativeLibs)
1596 ensureListContains(t, requireNativeLibs, "libfoo.so")
1597
1598 injectRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("injectApexDependency")
1599 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1600 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1601 ensureListContains(t, provideNativeLibs, "libfoo.so")
1602 ensureListEmpty(t, requireNativeLibs)
1603
1604 injectRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("injectApexDependency")
1605 provideNativeLibs = names(injectRule.Args["provideNativeLibs"])
1606 requireNativeLibs = names(injectRule.Args["requireNativeLibs"])
1607 ensureListContains(t, provideNativeLibs, "libfoo.so")
1608 ensureListEmpty(t, requireNativeLibs)
1609}
1610
Alex Light0851b882019-02-07 13:20:53 -08001611func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001612 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001613 apex {
1614 name: "myapex",
1615 key: "myapex.key",
1616 native_shared_libs: ["mylib_common"],
1617 }
1618
1619 apex_key {
1620 name: "myapex.key",
1621 public_key: "testkey.avbpubkey",
1622 private_key: "testkey.pem",
1623 }
1624
1625 cc_library {
1626 name: "mylib_common",
1627 srcs: ["mylib.cpp"],
1628 system_shared_libs: [],
1629 stl: "none",
1630 }
1631 `)
1632
1633 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1634 apexRule := module.Rule("apexRule")
1635 copyCmds := apexRule.Args["copy_commands"]
1636
1637 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1638 t.Log("Apex was a test apex!")
1639 t.Fail()
1640 }
1641 // Ensure that main rule creates an output
1642 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1643
1644 // Ensure that apex variant is created for the direct dep
1645 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1646
1647 // Ensure that both direct and indirect deps are copied into apex
1648 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1649
1650 // Ensure that the platform variant ends with _core_shared
1651 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1652
1653 if !android.InAnyApex("mylib_common") {
1654 t.Log("Found mylib_common not in any apex!")
1655 t.Fail()
1656 }
1657}
1658
1659func TestTestApex(t *testing.T) {
1660 if android.InAnyApex("mylib_common_test") {
1661 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!")
1662 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001663 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001664 apex_test {
1665 name: "myapex",
1666 key: "myapex.key",
1667 native_shared_libs: ["mylib_common_test"],
1668 }
1669
1670 apex_key {
1671 name: "myapex.key",
1672 public_key: "testkey.avbpubkey",
1673 private_key: "testkey.pem",
1674 }
1675
1676 cc_library {
1677 name: "mylib_common_test",
1678 srcs: ["mylib.cpp"],
1679 system_shared_libs: [],
1680 stl: "none",
1681 }
1682 `)
1683
1684 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1685 apexRule := module.Rule("apexRule")
1686 copyCmds := apexRule.Args["copy_commands"]
1687
1688 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1689 t.Log("Apex was not a test apex!")
1690 t.Fail()
1691 }
1692 // Ensure that main rule creates an output
1693 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1694
1695 // Ensure that apex variant is created for the direct dep
1696 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1697
1698 // Ensure that both direct and indirect deps are copied into apex
1699 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1700
1701 // Ensure that the platform variant ends with _core_shared
1702 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1703
1704 if android.InAnyApex("mylib_common_test") {
1705 t.Log("Found mylib_common_test in some apex!")
1706 t.Fail()
1707 }
1708}
1709
Alex Light9670d332019-01-29 18:07:33 -08001710func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001711 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001712 apex {
1713 name: "myapex",
1714 key: "myapex.key",
1715 multilib: {
1716 first: {
1717 native_shared_libs: ["mylib_common"],
1718 }
1719 },
1720 target: {
1721 android: {
1722 multilib: {
1723 first: {
1724 native_shared_libs: ["mylib"],
1725 }
1726 }
1727 },
1728 host: {
1729 multilib: {
1730 first: {
1731 native_shared_libs: ["mylib2"],
1732 }
1733 }
1734 }
1735 }
1736 }
1737
1738 apex_key {
1739 name: "myapex.key",
1740 public_key: "testkey.avbpubkey",
1741 private_key: "testkey.pem",
1742 }
1743
1744 cc_library {
1745 name: "mylib",
1746 srcs: ["mylib.cpp"],
1747 system_shared_libs: [],
1748 stl: "none",
1749 }
1750
1751 cc_library {
1752 name: "mylib_common",
1753 srcs: ["mylib.cpp"],
1754 system_shared_libs: [],
1755 stl: "none",
1756 compile_multilib: "first",
1757 }
1758
1759 cc_library {
1760 name: "mylib2",
1761 srcs: ["mylib.cpp"],
1762 system_shared_libs: [],
1763 stl: "none",
1764 compile_multilib: "first",
1765 }
1766 `)
1767
1768 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1769 copyCmds := apexRule.Args["copy_commands"]
1770
1771 // Ensure that main rule creates an output
1772 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1773
1774 // Ensure that apex variant is created for the direct dep
1775 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1776 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1777 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1778
1779 // Ensure that both direct and indirect deps are copied into apex
1780 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1781 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1782 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1783
1784 // Ensure that the platform variant ends with _core_shared
1785 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1786 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1787 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1788}
Jiyong Park04480cf2019-02-06 00:16:29 +09001789
1790func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001791 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001792 apex {
1793 name: "myapex",
1794 key: "myapex.key",
1795 binaries: ["myscript"],
1796 }
1797
1798 apex_key {
1799 name: "myapex.key",
1800 public_key: "testkey.avbpubkey",
1801 private_key: "testkey.pem",
1802 }
1803
1804 sh_binary {
1805 name: "myscript",
1806 src: "mylib.cpp",
1807 filename: "myscript.sh",
1808 sub_dir: "script",
1809 }
1810 `)
1811
1812 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1813 copyCmds := apexRule.Args["copy_commands"]
1814
1815 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1816}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001817
1818func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001819 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001820 apex {
1821 name: "myapex",
1822 key: "myapex.key",
1823 native_shared_libs: ["mylib"],
1824 product_specific: true,
1825 }
1826
1827 apex_key {
1828 name: "myapex.key",
1829 public_key: "testkey.avbpubkey",
1830 private_key: "testkey.pem",
1831 product_specific: true,
1832 }
1833
1834 cc_library {
1835 name: "mylib",
1836 srcs: ["mylib.cpp"],
1837 system_shared_libs: [],
1838 stl: "none",
1839 }
1840 `)
1841
1842 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1843 expected := "target/product/test_device/product/apex"
1844 actual := apex.installDir.RelPathString()
1845 if actual != expected {
1846 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1847 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001848}
Jiyong Park67882562019-03-21 01:11:21 +09001849
1850func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001851 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001852 apex_key {
1853 name: "myapex.key",
1854 public_key: ":my.avbpubkey",
1855 private_key: ":my.pem",
1856 product_specific: true,
1857 }
1858
1859 filegroup {
1860 name: "my.avbpubkey",
1861 srcs: ["testkey2.avbpubkey"],
1862 }
1863
1864 filegroup {
1865 name: "my.pem",
1866 srcs: ["testkey2.pem"],
1867 }
1868 `)
1869
1870 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1871 expected_pubkey := "testkey2.avbpubkey"
1872 actual_pubkey := apex_key.public_key_file.String()
1873 if actual_pubkey != expected_pubkey {
1874 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1875 }
1876 expected_privkey := "testkey2.pem"
1877 actual_privkey := apex_key.private_key_file.String()
1878 if actual_privkey != expected_privkey {
1879 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1880 }
1881}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001882
1883func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001884 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001885 prebuilt_apex {
1886 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001887 arch: {
1888 arm64: {
1889 src: "myapex-arm64.apex",
1890 },
1891 arm: {
1892 src: "myapex-arm.apex",
1893 },
1894 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001895 }
1896 `)
1897
1898 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1899
Jiyong Parkc95714e2019-03-29 14:23:10 +09001900 expectedInput := "myapex-arm64.apex"
1901 if prebuilt.inputApex.String() != expectedInput {
1902 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1903 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001904}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001905
1906func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001907 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001908 prebuilt_apex {
1909 name: "myapex",
1910 src: "myapex-arm.apex",
1911 filename: "notmyapex.apex",
1912 }
1913 `)
1914
1915 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1916
1917 expected := "notmyapex.apex"
1918 if p.installFilename != expected {
1919 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1920 }
1921}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001922
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001923func TestPrebuiltOverrides(t *testing.T) {
1924 ctx, config := testApex(t, `
1925 prebuilt_apex {
1926 name: "myapex.prebuilt",
1927 src: "myapex-arm.apex",
1928 overrides: [
1929 "myapex",
1930 ],
1931 }
1932 `)
1933
1934 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1935
1936 expected := []string{"myapex"}
1937 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1938 if !reflect.DeepEqual(actual, expected) {
1939 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1940 }
1941}
1942
Roland Levillain630846d2019-06-26 12:48:34 +01001943func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01001944 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01001945 apex_test {
1946 name: "myapex",
1947 key: "myapex.key",
1948 tests: [
1949 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01001950 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01001951 ],
1952 }
1953
1954 apex_key {
1955 name: "myapex.key",
1956 public_key: "testkey.avbpubkey",
1957 private_key: "testkey.pem",
1958 }
1959
1960 cc_test {
1961 name: "mytest",
1962 gtest: false,
1963 srcs: ["mytest.cpp"],
1964 relative_install_path: "test",
1965 system_shared_libs: [],
1966 static_executable: true,
1967 stl: "none",
1968 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01001969
1970 cc_test {
1971 name: "mytests",
1972 gtest: false,
1973 srcs: [
1974 "mytest1.cpp",
1975 "mytest2.cpp",
1976 "mytest3.cpp",
1977 ],
1978 test_per_src: true,
1979 relative_install_path: "test",
1980 system_shared_libs: [],
1981 static_executable: true,
1982 stl: "none",
1983 }
Roland Levillain630846d2019-06-26 12:48:34 +01001984 `)
1985
1986 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1987 copyCmds := apexRule.Args["copy_commands"]
1988
1989 // Ensure that test dep is copied into apex.
1990 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01001991
1992 // Ensure that test deps built with `test_per_src` are copied into apex.
1993 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
1994 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
1995 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01001996
1997 // Ensure the module is correctly translated.
1998 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1999 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2000 name := apexBundle.BaseModuleName()
2001 prefix := "TARGET_"
2002 var builder strings.Builder
2003 data.Custom(&builder, name, prefix, "", data)
2004 androidMk := builder.String()
2005 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest\n")
2006 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest1\n")
2007 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest2\n")
2008 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest3\n")
2009 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_manifest.json\n")
2010 ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_pubkey\n")
2011 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002012}
2013
Jooyung Han5c998b92019-06-27 11:30:33 +09002014func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002015 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002016 apex {
2017 name: "myapex",
2018 key: "myapex.key",
2019 native_shared_libs: ["mylib"],
2020 uses: ["commonapex"],
2021 }
2022
2023 apex {
2024 name: "commonapex",
2025 key: "myapex.key",
2026 native_shared_libs: ["libcommon"],
2027 provide_cpp_shared_libs: true,
2028 }
2029
2030 apex_key {
2031 name: "myapex.key",
2032 public_key: "testkey.avbpubkey",
2033 private_key: "testkey.pem",
2034 }
2035
2036 cc_library {
2037 name: "mylib",
2038 srcs: ["mylib.cpp"],
2039 shared_libs: ["libcommon"],
2040 system_shared_libs: [],
2041 stl: "none",
2042 }
2043
2044 cc_library {
2045 name: "libcommon",
2046 srcs: ["mylib_common.cpp"],
2047 system_shared_libs: [],
2048 stl: "none",
2049 }
2050 `)
2051
2052 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
2053 apexRule1 := module1.Rule("apexRule")
2054 copyCmds1 := apexRule1.Args["copy_commands"]
2055
2056 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
2057 apexRule2 := module2.Rule("apexRule")
2058 copyCmds2 := apexRule2.Args["copy_commands"]
2059
2060 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2061 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2062 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2063 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2064 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2065}
2066
2067func TestApexUsesFailsIfNotProvided(t *testing.T) {
2068 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2069 apex {
2070 name: "myapex",
2071 key: "myapex.key",
2072 uses: ["commonapex"],
2073 }
2074
2075 apex {
2076 name: "commonapex",
2077 key: "myapex.key",
2078 }
2079
2080 apex_key {
2081 name: "myapex.key",
2082 public_key: "testkey.avbpubkey",
2083 private_key: "testkey.pem",
2084 }
2085 `)
2086 testApexError(t, `uses: "commonapex" is not a provider`, `
2087 apex {
2088 name: "myapex",
2089 key: "myapex.key",
2090 uses: ["commonapex"],
2091 }
2092
2093 cc_library {
2094 name: "commonapex",
2095 system_shared_libs: [],
2096 stl: "none",
2097 }
2098
2099 apex_key {
2100 name: "myapex.key",
2101 public_key: "testkey.avbpubkey",
2102 private_key: "testkey.pem",
2103 }
2104 `)
2105}
2106
2107func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2108 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2109 apex {
2110 name: "myapex",
2111 key: "myapex.key",
2112 use_vendor: true,
2113 uses: ["commonapex"],
2114 }
2115
2116 apex {
2117 name: "commonapex",
2118 key: "myapex.key",
2119 provide_cpp_shared_libs: true,
2120 }
2121
2122 apex_key {
2123 name: "myapex.key",
2124 public_key: "testkey.avbpubkey",
2125 private_key: "testkey.pem",
2126 }
2127 `)
2128}
2129
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002130func TestApexUsesFailsIfUseNoApex(t *testing.T) {
2131 testApexError(t, `tries to include no_apex module mylib2`, `
2132 apex {
2133 name: "commonapex",
2134 key: "myapex.key",
2135 native_shared_libs: ["mylib"],
2136 }
2137
2138 apex_key {
2139 name: "myapex.key",
2140 public_key: "testkey.avbpubkey",
2141 private_key: "testkey.pem",
2142 }
2143
2144 cc_library {
2145 name: "mylib",
2146 srcs: ["mylib.cpp"],
2147 shared_libs: ["mylib2"],
2148 system_shared_libs: [],
2149 stl: "none",
2150 }
2151
2152 cc_library {
2153 name: "mylib2",
2154 srcs: ["mylib.cpp"],
2155 system_shared_libs: [],
2156 stl: "none",
2157 no_apex: true,
2158 }
2159 `)
2160
Sundong Ahn2db7f462019-08-27 18:53:12 +09002161 testApexError(t, `tries to include no_apex module mylib2`, `
2162 apex {
2163 name: "commonapex",
2164 key: "myapex.key",
2165 native_shared_libs: ["mylib"],
2166 }
2167
2168 apex_key {
2169 name: "myapex.key",
2170 public_key: "testkey.avbpubkey",
2171 private_key: "testkey.pem",
2172 }
2173
2174 cc_library {
2175 name: "mylib",
2176 srcs: ["mylib.cpp"],
2177 static_libs: ["mylib2"],
2178 system_shared_libs: [],
2179 stl: "none",
2180 }
2181
2182 cc_library {
2183 name: "mylib2",
2184 srcs: ["mylib.cpp"],
2185 system_shared_libs: [],
2186 stl: "none",
2187 no_apex: true,
2188 }
2189 `)
2190
Jiyong Park4f7dd9b2019-08-12 10:37:49 +09002191 ctx, _ := testApex(t, `
2192 apex {
2193 name: "myapex",
2194 key: "myapex.key",
2195 native_shared_libs: ["mylib"],
2196 }
2197
2198 apex_key {
2199 name: "myapex.key",
2200 public_key: "testkey.avbpubkey",
2201 private_key: "testkey.pem",
2202 }
2203
2204 cc_library {
2205 name: "mylib",
2206 srcs: ["mylib.cpp"],
2207 shared_libs: ["mylib2"],
2208 system_shared_libs: [],
2209 stl: "none",
2210 }
2211
2212 cc_library {
2213 name: "mylib2",
2214 srcs: ["mylib.cpp"],
2215 shared_libs: ["mylib3"],
2216 system_shared_libs: [],
2217 stl: "none",
2218 stubs: {
2219 versions: ["1", "2", "3"],
2220 },
2221 }
2222
2223 cc_library {
2224 name: "mylib3",
2225 srcs: ["mylib.cpp"],
2226 system_shared_libs: [],
2227 stl: "none",
2228 no_apex: true,
2229 }
2230 `)
2231
2232 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2233 apexRule := module.Rule("apexRule")
2234 copyCmds := apexRule.Args["copy_commands"]
2235
2236 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2237 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2238 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib3.so")
2239
2240}
2241
Jooyung Hand48f3c32019-08-23 11:18:57 +09002242func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2243 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2244 apex {
2245 name: "myapex",
2246 key: "myapex.key",
2247 native_shared_libs: ["libfoo"],
2248 }
2249
2250 apex_key {
2251 name: "myapex.key",
2252 public_key: "testkey.avbpubkey",
2253 private_key: "testkey.pem",
2254 }
2255
2256 cc_library {
2257 name: "libfoo",
2258 stl: "none",
2259 system_shared_libs: [],
2260 enabled: false,
2261 }
2262 `)
2263 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2264 apex {
2265 name: "myapex",
2266 key: "myapex.key",
2267 java_libs: ["myjar"],
2268 }
2269
2270 apex_key {
2271 name: "myapex.key",
2272 public_key: "testkey.avbpubkey",
2273 private_key: "testkey.pem",
2274 }
2275
2276 java_library {
2277 name: "myjar",
2278 srcs: ["foo/bar/MyClass.java"],
2279 sdk_version: "none",
2280 system_modules: "none",
2281 compile_dex: true,
2282 enabled: false,
2283 }
2284 `)
2285}
2286
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002287func TestApexWithApps(t *testing.T) {
2288 ctx, _ := testApex(t, `
2289 apex {
2290 name: "myapex",
2291 key: "myapex.key",
2292 apps: [
2293 "AppFoo",
2294 ],
2295 }
2296
2297 apex_key {
2298 name: "myapex.key",
2299 public_key: "testkey.avbpubkey",
2300 private_key: "testkey.pem",
2301 }
2302
2303 android_app {
2304 name: "AppFoo",
2305 srcs: ["foo/bar/MyClass.java"],
2306 sdk_version: "none",
2307 system_modules: "none",
2308 }
2309 `)
2310
2311 module := ctx.ModuleForTests("myapex", "android_common_myapex")
2312 apexRule := module.Rule("apexRule")
2313 copyCmds := apexRule.Args["copy_commands"]
2314
2315 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
2316
2317}
2318
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002319func TestMain(m *testing.M) {
2320 run := func() int {
2321 setUp()
2322 defer tearDown()
2323
2324 return m.Run()
2325 }
2326
2327 os.Exit(run())
2328}