blob: 8b49e9903168cb6daeabd6592e81e1371d019d01 [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070020 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090021 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090022 "strings"
23 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090024
25 "github.com/google/blueprint/proptools"
26
27 "android/soong/android"
28 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090029 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090030)
31
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070032var buildDir string
33
Jooyung Hand3639552019-08-09 12:57:43 +090034// names returns name list from white space separated string
35func names(s string) (ns []string) {
36 for _, n := range strings.Split(s, " ") {
37 if len(n) > 0 {
38 ns = append(ns, n)
39 }
40 }
41 return
42}
43
Jooyung Han344d5432019-08-23 11:17:39 +090044func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
45 t.Helper()
46 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090047 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
48 if len(errs) > 0 {
49 android.FailIfNoMatchingErrors(t, pattern, errs)
50 return
51 }
52 _, errs = ctx.PrepareBuildActions(config)
53 if len(errs) > 0 {
54 android.FailIfNoMatchingErrors(t, pattern, errs)
55 return
56 }
57
58 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
59}
60
Jooyung Han344d5432019-08-23 11:17:39 +090061func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
62 t.Helper()
63 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090064 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
65 android.FailIfErrored(t, errs)
66 _, errs = ctx.PrepareBuildActions(config)
67 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070068 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090069}
70
Jooyung Han344d5432019-08-23 11:17:39 +090071type testCustomizer func(fs map[string][]byte, config android.Config)
72
73func withFiles(files map[string][]byte) testCustomizer {
74 return func(fs map[string][]byte, config android.Config) {
75 for k, v := range files {
76 fs[k] = v
77 }
78 }
79}
80
81func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
82 return func(fs map[string][]byte, config android.Config) {
83 for k, v := range targets {
84 config.Targets[k] = v
85 }
86 }
87}
88
Jooyung Han31c470b2019-10-18 16:26:59 +090089func withBinder32bit(fs map[string][]byte, config android.Config) {
90 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
91}
92
Jooyung Han344d5432019-08-23 11:17:39 +090093func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070094 config := android.TestArchConfig(buildDir, nil)
95 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
96 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
97 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
98 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
99 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jooyung Han344d5432019-08-23 11:17:39 +0900100 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101
102 ctx := android.NewTestArchContext()
Jiyong Parkd1063c12019-07-17 20:08:41 +0900103 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(BundleFactory))
Alex Light0851b882019-02-07 13:20:53 -0800104 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900105 ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory))
Jiyong Parkd1063c12019-07-17 20:08:41 +0900106 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(ApexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +0900107 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700108 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900109
110 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
111 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +0900112 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900113 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory))
114 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +0900115 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900116 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +0100117 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +0900118 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jooyung Han344d5432019-08-23 11:17:39 +0900119 ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +0900120 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +0900121 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +0900122 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900123 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +0900124 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900125 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
Jiyong Park9e6c2422019-08-09 20:39:45 +0900126 ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
Dario Frenicde2a032019-10-27 00:29:22 +0100127 ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900128 ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
Dario Frenicde2a032019-10-27 00:29:22 +0100129 ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(java.AndroidAppImportFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +0900130
Jooyung Han344d5432019-08-23 11:17:39 +0900131 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jaewoong Jung939ebd52019-03-26 15:07:36 -0700132 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
133 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
134 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900135 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900136 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900137 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900138 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100139 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900140 ctx.BottomUp("version", cc.VersionMutator).Parallel()
141 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Jooyung Han344d5432019-08-23 11:17:39 +0900142 })
Jooyung Han31c470b2019-10-18 16:26:59 +0900143 ctx.PreDepsMutators(RegisterPreDepsMutators)
144 ctx.PostDepsMutators(RegisterPostDepsMutators)
Jooyung Han344d5432019-08-23 11:17:39 +0900145 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jooyung Han344d5432019-08-23 11:17:39 +0900146 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
147 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900148 })
149
150 ctx.Register()
151
152 bp = bp + `
153 toolchain_library {
154 name: "libcompiler_rt-extras",
155 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900156 vendor_available: true,
157 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900158 }
159
160 toolchain_library {
161 name: "libatomic",
162 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900163 vendor_available: true,
164 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900165 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900166 }
167
168 toolchain_library {
169 name: "libgcc",
170 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900171 vendor_available: true,
172 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900173 }
174
175 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700176 name: "libgcc_stripped",
177 src: "",
178 vendor_available: true,
179 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900180 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700181 }
182
183 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900184 name: "libclang_rt.builtins-aarch64-android",
185 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900186 vendor_available: true,
187 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900188 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900189 }
190
191 toolchain_library {
192 name: "libclang_rt.builtins-arm-android",
193 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900194 vendor_available: true,
195 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900196 native_bridge_supported: true,
197 }
198
199 toolchain_library {
200 name: "libclang_rt.builtins-x86_64-android",
201 src: "",
202 vendor_available: true,
203 recovery_available: true,
204 native_bridge_supported: true,
205 }
206
207 toolchain_library {
208 name: "libclang_rt.builtins-i686-android",
209 src: "",
210 vendor_available: true,
211 recovery_available: true,
212 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900213 }
214
215 cc_object {
216 name: "crtbegin_so",
217 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900218 vendor_available: true,
219 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900220 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900221 }
222
223 cc_object {
224 name: "crtend_so",
225 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900226 vendor_available: true,
227 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900228 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900229 }
230
Alex Light3d673592019-01-18 14:37:31 -0800231 cc_object {
232 name: "crtbegin_static",
233 stl: "none",
234 }
235
236 cc_object {
237 name: "crtend_android",
238 stl: "none",
239 }
240
Jiyong Parkda6eb592018-12-19 17:12:36 +0900241 llndk_library {
242 name: "libc",
243 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900244 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900245 }
246
247 llndk_library {
248 name: "libm",
249 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900250 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900251 }
252
253 llndk_library {
254 name: "libdl",
255 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900256 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900257 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900258 `
Dario Frenicde2a032019-10-27 00:29:22 +0100259 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900260
Jooyung Han344d5432019-08-23 11:17:39 +0900261 fs := map[string][]byte{
Dario Frenicde2a032019-10-27 00:29:22 +0100262 "Android.bp": []byte(bp),
263 "a.java": nil,
264 "PrebuiltAppFoo.apk": nil,
265 "PrebuiltAppFooPriv.apk": nil,
266 "build/make/target/product/security": nil,
267 "apex_manifest.json": nil,
268 "AndroidManifest.xml": nil,
269 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900270 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
271 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900272 "system/sepolicy/apex/commonapex-file_contexts": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900273 "mylib.cpp": nil,
274 "mylib_common.cpp": nil,
275 "mytest.cpp": nil,
276 "mytest1.cpp": nil,
277 "mytest2.cpp": nil,
278 "mytest3.cpp": nil,
279 "myprebuilt": nil,
280 "my_include": nil,
281 "foo/bar/MyClass.java": nil,
282 "prebuilt.jar": nil,
283 "vendor/foo/devkeys/test.x509.pem": nil,
284 "vendor/foo/devkeys/test.pk8": nil,
285 "testkey.x509.pem": nil,
286 "testkey.pk8": nil,
287 "testkey.override.x509.pem": nil,
288 "testkey.override.pk8": nil,
289 "vendor/foo/devkeys/testkey.avbpubkey": nil,
290 "vendor/foo/devkeys/testkey.pem": nil,
291 "NOTICE": nil,
292 "custom_notice": nil,
293 "testkey2.avbpubkey": nil,
294 "testkey2.pem": nil,
295 "myapex-arm64.apex": nil,
296 "myapex-arm.apex": nil,
297 "frameworks/base/api/current.txt": nil,
Dario Frenicde2a032019-10-27 00:29:22 +0100298 "framework/aidl/a.aidl": nil,
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900299 "build/make/core/proguard.flags": nil,
300 "build/make/core/proguard_basic_keeps.flags": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900301 }
302
303 for _, handler := range handlers {
304 handler(fs, config)
305 }
306
307 ctx.MockFileSystem(fs)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900308
Jooyung Han5c998b92019-06-27 11:30:33 +0900309 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310}
311
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700312func setUp() {
313 var err error
314 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700316 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900317 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900318}
319
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700320func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900321 os.RemoveAll(buildDir)
322}
323
324// ensure that 'result' contains 'expected'
325func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900326 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900327 if !strings.Contains(result, expected) {
328 t.Errorf("%q is not found in %q", expected, result)
329 }
330}
331
332// ensures that 'result' does not contain 'notExpected'
333func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900334 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900335 if strings.Contains(result, notExpected) {
336 t.Errorf("%q is found in %q", notExpected, result)
337 }
338}
339
340func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900341 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342 if !android.InList(expected, result) {
343 t.Errorf("%q is not found in %v", expected, result)
344 }
345}
346
347func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900348 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900349 if android.InList(notExpected, result) {
350 t.Errorf("%q is found in %v", notExpected, result)
351 }
352}
353
Jooyung Hane1633032019-08-01 17:41:43 +0900354func ensureListEmpty(t *testing.T, result []string) {
355 t.Helper()
356 if len(result) > 0 {
357 t.Errorf("%q is expected to be empty", result)
358 }
359}
360
Jiyong Park25fc6a92018-11-18 18:02:45 +0900361// Minimal test
362func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700363 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900364 apex_defaults {
365 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900366 manifest: ":myapex.manifest",
367 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900368 key: "myapex.key",
369 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800370 multilib: {
371 both: {
372 binaries: ["foo",],
373 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900374 },
Jiyong Park9e6c2422019-08-09 20:39:45 +0900375 java_libs: ["myjar", "myprebuiltjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900376 }
377
Jiyong Park30ca9372019-02-07 16:27:23 +0900378 apex {
379 name: "myapex",
380 defaults: ["myapex-defaults"],
381 }
382
Jiyong Park25fc6a92018-11-18 18:02:45 +0900383 apex_key {
384 name: "myapex.key",
385 public_key: "testkey.avbpubkey",
386 private_key: "testkey.pem",
387 }
388
Jiyong Park809bb722019-02-13 21:33:49 +0900389 filegroup {
390 name: "myapex.manifest",
391 srcs: ["apex_manifest.json"],
392 }
393
394 filegroup {
395 name: "myapex.androidmanifest",
396 srcs: ["AndroidManifest.xml"],
397 }
398
Jiyong Park25fc6a92018-11-18 18:02:45 +0900399 cc_library {
400 name: "mylib",
401 srcs: ["mylib.cpp"],
402 shared_libs: ["mylib2"],
403 system_shared_libs: [],
404 stl: "none",
405 }
406
Alex Light3d673592019-01-18 14:37:31 -0800407 cc_binary {
408 name: "foo",
409 srcs: ["mylib.cpp"],
410 compile_multilib: "both",
411 multilib: {
412 lib32: {
413 suffix: "32",
414 },
415 lib64: {
416 suffix: "64",
417 },
418 },
419 symlinks: ["foo_link_"],
420 symlink_preferred_arch: true,
421 system_shared_libs: [],
422 static_executable: true,
423 stl: "none",
424 }
425
Jiyong Park25fc6a92018-11-18 18:02:45 +0900426 cc_library {
427 name: "mylib2",
428 srcs: ["mylib.cpp"],
429 system_shared_libs: [],
430 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900431 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900432 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900433
434 java_library {
435 name: "myjar",
436 srcs: ["foo/bar/MyClass.java"],
437 sdk_version: "none",
438 system_modules: "none",
439 compile_dex: true,
440 static_libs: ["myotherjar"],
441 }
442
443 java_library {
444 name: "myotherjar",
445 srcs: ["foo/bar/MyClass.java"],
446 sdk_version: "none",
447 system_modules: "none",
448 compile_dex: true,
449 }
Jiyong Park9e6c2422019-08-09 20:39:45 +0900450
451 java_import {
452 name: "myprebuiltjar",
453 jars: ["prebuilt.jar"],
454 installable: true,
455 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900456 `)
457
Sundong Ahnabb64432019-10-22 13:58:29 +0900458 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900459
460 optFlags := apexRule.Args["opt_flags"]
461 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700462 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900463 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900464
Jiyong Park25fc6a92018-11-18 18:02:45 +0900465 copyCmds := apexRule.Args["copy_commands"]
466
467 // Ensure that main rule creates an output
468 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
469
470 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900471 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900472 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900473 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900474
475 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900476 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900477 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900478
479 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800480 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
481 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900482 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900483 ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900484 // .. but not for java libs
485 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800486
Jiyong Park7f7766d2019-07-25 22:02:35 +0900487 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800488 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
489 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900490 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
491 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park9e6c2422019-08-09 20:39:45 +0900492 ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800493
494 // Ensure that all symlinks are present.
495 found_foo_link_64 := false
496 found_foo := false
497 for _, cmd := range strings.Split(copyCmds, " && ") {
498 if strings.HasPrefix(cmd, "ln -s foo64") {
499 if strings.HasSuffix(cmd, "bin/foo") {
500 found_foo = true
501 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
502 found_foo_link_64 = true
503 }
504 }
505 }
506 good := found_foo && found_foo_link_64
507 if !good {
508 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
509 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900510
Sundong Ahnabb64432019-10-22 13:58:29 +0900511 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700512 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700513 if len(noticeInputs) != 2 {
514 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900515 }
516 ensureListContains(t, noticeInputs, "NOTICE")
517 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800518}
519
Jooyung Han01a3ee22019-11-02 02:52:25 +0900520func TestApexManifest(t *testing.T) {
521 ctx, _ := testApex(t, `
522 apex {
523 name: "myapex",
524 key: "myapex.key",
525 }
526
527 apex_key {
528 name: "myapex.key",
529 public_key: "testkey.avbpubkey",
530 private_key: "testkey.pem",
531 }
532 `)
533
534 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
535 module.Output("apex_manifest.pb")
536 module.Output("apex_manifest.json")
537 module.Output("apex_manifest_full.json")
538}
539
Alex Light5098a612018-11-29 17:12:15 -0800540func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700541 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800542 apex {
543 name: "myapex",
544 key: "myapex.key",
545 payload_type: "zip",
546 native_shared_libs: ["mylib"],
547 }
548
549 apex_key {
550 name: "myapex.key",
551 public_key: "testkey.avbpubkey",
552 private_key: "testkey.pem",
553 }
554
555 cc_library {
556 name: "mylib",
557 srcs: ["mylib.cpp"],
558 shared_libs: ["mylib2"],
559 system_shared_libs: [],
560 stl: "none",
561 }
562
563 cc_library {
564 name: "mylib2",
565 srcs: ["mylib.cpp"],
566 system_shared_libs: [],
567 stl: "none",
568 }
569 `)
570
Sundong Ahnabb64432019-10-22 13:58:29 +0900571 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800572 copyCmds := zipApexRule.Args["copy_commands"]
573
574 // Ensure that main rule creates an output
575 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
576
577 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900578 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800579
580 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900581 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800582
583 // Ensure that both direct and indirect deps are copied into apex
584 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
585 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900586}
587
588func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700589 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900590 apex {
591 name: "myapex",
592 key: "myapex.key",
593 native_shared_libs: ["mylib", "mylib3"],
594 }
595
596 apex_key {
597 name: "myapex.key",
598 public_key: "testkey.avbpubkey",
599 private_key: "testkey.pem",
600 }
601
602 cc_library {
603 name: "mylib",
604 srcs: ["mylib.cpp"],
605 shared_libs: ["mylib2", "mylib3"],
606 system_shared_libs: [],
607 stl: "none",
608 }
609
610 cc_library {
611 name: "mylib2",
612 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900613 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900614 system_shared_libs: [],
615 stl: "none",
616 stubs: {
617 versions: ["1", "2", "3"],
618 },
619 }
620
621 cc_library {
622 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900623 srcs: ["mylib.cpp"],
624 shared_libs: ["mylib4"],
625 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900626 stl: "none",
627 stubs: {
628 versions: ["10", "11", "12"],
629 },
630 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900631
632 cc_library {
633 name: "mylib4",
634 srcs: ["mylib.cpp"],
635 system_shared_libs: [],
636 stl: "none",
637 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900638 `)
639
Sundong Ahnabb64432019-10-22 13:58:29 +0900640 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900641 copyCmds := apexRule.Args["copy_commands"]
642
643 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800644 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900645
646 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800647 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900648
649 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800650 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900651
Jiyong Parkda6eb592018-12-19 17:12:36 +0900652 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900653
654 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900655 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900656 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900657 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900658
659 // 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 +0900660 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900662 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900663
664 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900665 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900666 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900667
668 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900669 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 +0900670}
671
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900672func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700673 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900674 apex {
675 name: "myapex",
676 key: "myapex.key",
677 native_shared_libs: ["mylib"],
678 }
679
680 apex_key {
681 name: "myapex.key",
682 public_key: "testkey.avbpubkey",
683 private_key: "testkey.pem",
684 }
685
686 cc_library {
687 name: "mylib",
688 srcs: ["mylib.cpp"],
689 shared_libs: ["libfoo#10"],
690 system_shared_libs: [],
691 stl: "none",
692 }
693
694 cc_library {
695 name: "libfoo",
696 srcs: ["mylib.cpp"],
697 shared_libs: ["libbar"],
698 system_shared_libs: [],
699 stl: "none",
700 stubs: {
701 versions: ["10", "20", "30"],
702 },
703 }
704
705 cc_library {
706 name: "libbar",
707 srcs: ["mylib.cpp"],
708 system_shared_libs: [],
709 stl: "none",
710 }
711
712 `)
713
Sundong Ahnabb64432019-10-22 13:58:29 +0900714 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900715 copyCmds := apexRule.Args["copy_commands"]
716
717 // Ensure that direct non-stubs dep is always included
718 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
719
720 // Ensure that indirect stubs dep is not included
721 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
722
723 // Ensure that dependency of stubs is not included
724 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
725
Jiyong Parkda6eb592018-12-19 17:12:36 +0900726 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900727
728 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900729 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900730 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900731 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900732
Jiyong Parkda6eb592018-12-19 17:12:36 +0900733 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900734
735 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
736 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
737}
738
Jooyung Hand3639552019-08-09 12:57:43 +0900739func TestApexWithRuntimeLibsDependency(t *testing.T) {
740 /*
741 myapex
742 |
743 v (runtime_libs)
744 mylib ------+------> libfoo [provides stub]
745 |
746 `------> libbar
747 */
748 ctx, _ := testApex(t, `
749 apex {
750 name: "myapex",
751 key: "myapex.key",
752 native_shared_libs: ["mylib"],
753 }
754
755 apex_key {
756 name: "myapex.key",
757 public_key: "testkey.avbpubkey",
758 private_key: "testkey.pem",
759 }
760
761 cc_library {
762 name: "mylib",
763 srcs: ["mylib.cpp"],
764 runtime_libs: ["libfoo", "libbar"],
765 system_shared_libs: [],
766 stl: "none",
767 }
768
769 cc_library {
770 name: "libfoo",
771 srcs: ["mylib.cpp"],
772 system_shared_libs: [],
773 stl: "none",
774 stubs: {
775 versions: ["10", "20", "30"],
776 },
777 }
778
779 cc_library {
780 name: "libbar",
781 srcs: ["mylib.cpp"],
782 system_shared_libs: [],
783 stl: "none",
784 }
785
786 `)
787
Sundong Ahnabb64432019-10-22 13:58:29 +0900788 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900789 copyCmds := apexRule.Args["copy_commands"]
790
791 // Ensure that direct non-stubs dep is always included
792 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
793
794 // Ensure that indirect stubs dep is not included
795 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
796
797 // Ensure that runtime_libs dep in included
798 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
799
Sundong Ahnabb64432019-10-22 13:58:29 +0900800 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900801 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
802 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900803
804}
805
Jooyung Han9c80bae2019-08-20 17:30:57 +0900806func TestApexDependencyToLLNDK(t *testing.T) {
807 ctx, _ := testApex(t, `
808 apex {
809 name: "myapex",
810 key: "myapex.key",
811 use_vendor: true,
812 native_shared_libs: ["mylib"],
813 }
814
815 apex_key {
816 name: "myapex.key",
817 public_key: "testkey.avbpubkey",
818 private_key: "testkey.pem",
819 }
820
821 cc_library {
822 name: "mylib",
823 srcs: ["mylib.cpp"],
824 vendor_available: true,
825 shared_libs: ["libbar"],
826 system_shared_libs: [],
827 stl: "none",
828 }
829
830 cc_library {
831 name: "libbar",
832 srcs: ["mylib.cpp"],
833 system_shared_libs: [],
834 stl: "none",
835 }
836
837 llndk_library {
838 name: "libbar",
839 symbol_file: "",
840 }
Jooyung Handc782442019-11-01 03:14:38 +0900841 `, func(fs map[string][]byte, config android.Config) {
842 setUseVendorWhitelistForTest(config, []string{"myapex"})
843 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900844
Sundong Ahnabb64432019-10-22 13:58:29 +0900845 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900846 copyCmds := apexRule.Args["copy_commands"]
847
848 // Ensure that LLNDK dep is not included
849 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
850
Sundong Ahnabb64432019-10-22 13:58:29 +0900851 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900852 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900853
854 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900855 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900856
857}
858
Jiyong Park25fc6a92018-11-18 18:02:45 +0900859func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700860 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900861 apex {
862 name: "myapex",
863 key: "myapex.key",
864 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
865 }
866
867 apex_key {
868 name: "myapex.key",
869 public_key: "testkey.avbpubkey",
870 private_key: "testkey.pem",
871 }
872
873 cc_library {
874 name: "mylib",
875 srcs: ["mylib.cpp"],
876 shared_libs: ["libdl#27"],
877 stl: "none",
878 }
879
880 cc_library_shared {
881 name: "mylib_shared",
882 srcs: ["mylib.cpp"],
883 shared_libs: ["libdl#27"],
884 stl: "none",
885 }
886
887 cc_library {
888 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700889 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900890 nocrt: true,
891 system_shared_libs: [],
892 stl: "none",
893 stubs: {
894 versions: ["27", "28", "29"],
895 },
896 }
897
898 cc_library {
899 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700900 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900901 nocrt: true,
902 system_shared_libs: [],
903 stl: "none",
904 stubs: {
905 versions: ["27", "28", "29"],
906 },
907 }
908
909 cc_library {
910 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700911 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900912 nocrt: true,
913 system_shared_libs: [],
914 stl: "none",
915 stubs: {
916 versions: ["27", "28", "29"],
917 },
918 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900919
920 cc_library {
921 name: "libBootstrap",
922 srcs: ["mylib.cpp"],
923 stl: "none",
924 bootstrap: true,
925 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900926 `)
927
Sundong Ahnabb64432019-10-22 13:58:29 +0900928 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900929 copyCmds := apexRule.Args["copy_commands"]
930
931 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800932 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900933 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
934 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900935
936 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900937 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900938
Jiyong Parkda6eb592018-12-19 17:12:36 +0900939 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
940 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
941 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900942
943 // For dependency to libc
944 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900945 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900946 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900947 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900948 // ... Cflags from stub is correctly exported to mylib
949 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
950 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
951
952 // For dependency to libm
953 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900954 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900955 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900956 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900957 // ... and is not compiling with the stub
958 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
959 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
960
961 // For dependency to libdl
962 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900963 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900964 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900965 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
966 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900967 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900968 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900969 // ... Cflags from stub is correctly exported to mylib
970 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
971 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900972
973 // Ensure that libBootstrap is depending on the platform variant of bionic libs
974 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
975 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
976 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
977 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900978}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900979
980func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700981 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900982 apex {
983 name: "myapex",
984 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900985 native_shared_libs: ["mylib"],
986 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900987 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900988 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900989 }
990
991 apex_key {
992 name: "myapex.key",
993 public_key: "testkey.avbpubkey",
994 private_key: "testkey.pem",
995 }
996
997 prebuilt_etc {
998 name: "myetc",
999 src: "myprebuilt",
1000 sub_dir: "foo/bar",
1001 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001002
1003 cc_library {
1004 name: "mylib",
1005 srcs: ["mylib.cpp"],
1006 relative_install_path: "foo/bar",
1007 system_shared_libs: [],
1008 stl: "none",
1009 }
1010
1011 cc_binary {
1012 name: "mybin",
1013 srcs: ["mylib.cpp"],
1014 relative_install_path: "foo/bar",
1015 system_shared_libs: [],
1016 static_executable: true,
1017 stl: "none",
1018 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001019 `)
1020
Sundong Ahnabb64432019-10-22 13:58:29 +09001021 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001022 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1023
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001024 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001025 ensureListContains(t, dirs, "etc")
1026 ensureListContains(t, dirs, "etc/foo")
1027 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001028 ensureListContains(t, dirs, "lib64")
1029 ensureListContains(t, dirs, "lib64/foo")
1030 ensureListContains(t, dirs, "lib64/foo/bar")
1031 ensureListContains(t, dirs, "lib")
1032 ensureListContains(t, dirs, "lib/foo")
1033 ensureListContains(t, dirs, "lib/foo/bar")
1034
Jiyong Parkbd13e442019-03-15 18:10:35 +09001035 ensureListContains(t, dirs, "bin")
1036 ensureListContains(t, dirs, "bin/foo")
1037 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001038}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001039
1040func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001041 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001042 apex {
1043 name: "myapex",
1044 key: "myapex.key",
1045 native_shared_libs: ["mylib"],
1046 use_vendor: true,
1047 }
1048
1049 apex_key {
1050 name: "myapex.key",
1051 public_key: "testkey.avbpubkey",
1052 private_key: "testkey.pem",
1053 }
1054
1055 cc_library {
1056 name: "mylib",
1057 srcs: ["mylib.cpp"],
1058 shared_libs: ["mylib2"],
1059 system_shared_libs: [],
1060 vendor_available: true,
1061 stl: "none",
1062 }
1063
1064 cc_library {
1065 name: "mylib2",
1066 srcs: ["mylib.cpp"],
1067 system_shared_libs: [],
1068 vendor_available: true,
1069 stl: "none",
1070 }
Jooyung Handc782442019-11-01 03:14:38 +09001071 `, func(fs map[string][]byte, config android.Config) {
1072 setUseVendorWhitelistForTest(config, []string{"myapex"})
1073 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001074
1075 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001076 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001077 for _, implicit := range i.Implicits {
1078 inputsList = append(inputsList, implicit.String())
1079 }
1080 }
1081 inputsString := strings.Join(inputsList, " ")
1082
1083 // ensure that the apex includes vendor variants of the direct and indirect deps
Inseob Kim64c43952019-08-26 16:52:35 +09001084 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib.so")
1085 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor.VER_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001086
1087 // ensure that the apex does not include core variants
1088 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
1089 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
1090}
Jiyong Park16e91a02018-12-20 18:18:08 +09001091
Jooyung Handc782442019-11-01 03:14:38 +09001092func TestUseVendorRestriction(t *testing.T) {
1093 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1094 apex {
1095 name: "myapex",
1096 key: "myapex.key",
1097 use_vendor: true,
1098 }
1099 apex_key {
1100 name: "myapex.key",
1101 public_key: "testkey.avbpubkey",
1102 private_key: "testkey.pem",
1103 }
1104 `, func(fs map[string][]byte, config android.Config) {
1105 setUseVendorWhitelistForTest(config, []string{""})
1106 })
1107 // no error with whitelist
1108 testApex(t, `
1109 apex {
1110 name: "myapex",
1111 key: "myapex.key",
1112 use_vendor: true,
1113 }
1114 apex_key {
1115 name: "myapex.key",
1116 public_key: "testkey.avbpubkey",
1117 private_key: "testkey.pem",
1118 }
1119 `, func(fs map[string][]byte, config android.Config) {
1120 setUseVendorWhitelistForTest(config, []string{"myapex"})
1121 })
1122}
1123
Jooyung Han5c998b92019-06-27 11:30:33 +09001124func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1125 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1126 apex {
1127 name: "myapex",
1128 key: "myapex.key",
1129 native_shared_libs: ["mylib"],
1130 use_vendor: true,
1131 }
1132
1133 apex_key {
1134 name: "myapex.key",
1135 public_key: "testkey.avbpubkey",
1136 private_key: "testkey.pem",
1137 }
1138
1139 cc_library {
1140 name: "mylib",
1141 srcs: ["mylib.cpp"],
1142 system_shared_libs: [],
1143 stl: "none",
1144 }
1145 `)
1146}
1147
Jiyong Park16e91a02018-12-20 18:18:08 +09001148func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001149 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001150 apex {
1151 name: "myapex",
1152 key: "myapex.key",
1153 native_shared_libs: ["mylib"],
1154 }
1155
1156 apex_key {
1157 name: "myapex.key",
1158 public_key: "testkey.avbpubkey",
1159 private_key: "testkey.pem",
1160 }
1161
1162 cc_library {
1163 name: "mylib",
1164 srcs: ["mylib.cpp"],
1165 system_shared_libs: [],
1166 stl: "none",
1167 stubs: {
1168 versions: ["1", "2", "3"],
1169 },
1170 }
1171
1172 cc_binary {
1173 name: "not_in_apex",
1174 srcs: ["mylib.cpp"],
1175 static_libs: ["mylib"],
1176 static_executable: true,
1177 system_shared_libs: [],
1178 stl: "none",
1179 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001180 `)
1181
1182 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
1183
1184 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +08001185 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001186}
Jiyong Park9335a262018-12-24 11:31:58 +09001187
1188func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001189 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001190 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001191 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001192 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001193 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001194 native_shared_libs: ["mylib"],
1195 }
1196
1197 cc_library {
1198 name: "mylib",
1199 srcs: ["mylib.cpp"],
1200 system_shared_libs: [],
1201 stl: "none",
1202 }
1203
1204 apex_key {
1205 name: "myapex.key",
1206 public_key: "testkey.avbpubkey",
1207 private_key: "testkey.pem",
1208 }
1209
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001210 android_app_certificate {
1211 name: "myapex.certificate",
1212 certificate: "testkey",
1213 }
1214
1215 android_app_certificate {
1216 name: "myapex.certificate.override",
1217 certificate: "testkey.override",
1218 }
1219
Jiyong Park9335a262018-12-24 11:31:58 +09001220 `)
1221
1222 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001223 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001224
1225 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1226 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1227 "vendor/foo/devkeys/testkey.avbpubkey")
1228 }
1229 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1230 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1231 "vendor/foo/devkeys/testkey.pem")
1232 }
1233
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001234 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001235 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001236 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001237 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001238 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001239 }
1240}
Jiyong Park58e364a2019-01-19 19:24:06 +09001241
1242func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001243 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001244 apex {
1245 name: "myapex",
1246 key: "myapex.key",
1247 native_shared_libs: ["mylib"],
1248 }
1249
1250 apex {
1251 name: "otherapex",
1252 key: "myapex.key",
1253 native_shared_libs: ["mylib"],
1254 }
1255
1256 apex_key {
1257 name: "myapex.key",
1258 public_key: "testkey.avbpubkey",
1259 private_key: "testkey.pem",
1260 }
1261
1262 cc_library {
1263 name: "mylib",
1264 srcs: ["mylib.cpp"],
1265 system_shared_libs: [],
1266 stl: "none",
1267 }
1268 `)
1269
Jooyung Han6b8459b2019-10-30 08:29:25 +09001270 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001271 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001272 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001273 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1274 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001275
Jooyung Han6b8459b2019-10-30 08:29:25 +09001276 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001277 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001278 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001279 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1280 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001281
Jooyung Han6b8459b2019-10-30 08:29:25 +09001282 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Jiyong Park58e364a2019-01-19 19:24:06 +09001283 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001284 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001285 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1286 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001287}
Jiyong Park7e636d02019-01-28 16:16:54 +09001288
1289func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001290 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001291 apex {
1292 name: "myapex",
1293 key: "myapex.key",
1294 native_shared_libs: ["mylib"],
1295 }
1296
1297 apex_key {
1298 name: "myapex.key",
1299 public_key: "testkey.avbpubkey",
1300 private_key: "testkey.pem",
1301 }
1302
1303 cc_library_headers {
1304 name: "mylib_headers",
1305 export_include_dirs: ["my_include"],
1306 system_shared_libs: [],
1307 stl: "none",
1308 }
1309
1310 cc_library {
1311 name: "mylib",
1312 srcs: ["mylib.cpp"],
1313 system_shared_libs: [],
1314 stl: "none",
1315 header_libs: ["mylib_headers"],
1316 export_header_lib_headers: ["mylib_headers"],
1317 stubs: {
1318 versions: ["1", "2", "3"],
1319 },
1320 }
1321
1322 cc_library {
1323 name: "otherlib",
1324 srcs: ["mylib.cpp"],
1325 system_shared_libs: [],
1326 stl: "none",
1327 shared_libs: ["mylib"],
1328 }
1329 `)
1330
1331 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1332
1333 // Ensure that the include path of the header lib is exported to 'otherlib'
1334 ensureContains(t, cFlags, "-Imy_include")
1335}
Alex Light9670d332019-01-29 18:07:33 -08001336
Jooyung Han31c470b2019-10-18 16:26:59 +09001337func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
1338 t.Helper()
Sundong Ahnabb64432019-10-22 13:58:29 +09001339 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001340 copyCmds := apexRule.Args["copy_commands"]
1341 imageApexDir := "/image.apex/"
1342 dstFiles := []string{}
1343 for _, cmd := range strings.Split(copyCmds, "&&") {
1344 cmd = strings.TrimSpace(cmd)
1345 if cmd == "" {
1346 continue
1347 }
1348 terms := strings.Split(cmd, " ")
1349 switch terms[0] {
1350 case "mkdir":
1351 case "cp":
1352 if len(terms) != 3 {
1353 t.Fatal("copyCmds contains invalid cp command", cmd)
1354 }
1355 dst := terms[2]
1356 index := strings.Index(dst, imageApexDir)
1357 if index == -1 {
1358 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1359 }
1360 dstFile := dst[index+len(imageApexDir):]
1361 dstFiles = append(dstFiles, dstFile)
1362 default:
1363 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1364 }
1365 }
1366 sort.Strings(dstFiles)
1367 sort.Strings(files)
1368 missing := []string{}
1369 surplus := []string{}
1370 i := 0
1371 j := 0
1372 for i < len(dstFiles) && j < len(files) {
1373 if dstFiles[i] == files[j] {
1374 i++
1375 j++
1376 } else if dstFiles[i] < files[j] {
1377 surplus = append(surplus, dstFiles[i])
1378 i++
1379 } else {
1380 missing = append(missing, files[j])
1381 j++
1382 }
1383 }
1384 if i < len(dstFiles) {
1385 surplus = append(surplus, dstFiles[i:]...)
1386 }
1387 if j < len(files) {
1388 missing = append(missing, files[j:]...)
1389 }
1390
1391 failed := false
1392 if len(surplus) > 0 {
1393 t.Log("surplus files", surplus)
1394 failed = true
1395 }
1396 if len(missing) > 0 {
1397 t.Log("missing files", missing)
1398 failed = true
1399 }
1400 if failed {
1401 t.Fail()
1402 }
1403}
1404
Jooyung Han344d5432019-08-23 11:17:39 +09001405func TestVndkApexCurrent(t *testing.T) {
1406 ctx, _ := testApex(t, `
1407 apex_vndk {
1408 name: "myapex",
1409 key: "myapex.key",
1410 file_contexts: "myapex",
1411 }
1412
1413 apex_key {
1414 name: "myapex.key",
1415 public_key: "testkey.avbpubkey",
1416 private_key: "testkey.pem",
1417 }
1418
1419 cc_library {
1420 name: "libvndk",
1421 srcs: ["mylib.cpp"],
1422 vendor_available: true,
1423 vndk: {
1424 enabled: true,
1425 },
1426 system_shared_libs: [],
1427 stl: "none",
1428 }
1429
1430 cc_library {
1431 name: "libvndksp",
1432 srcs: ["mylib.cpp"],
1433 vendor_available: true,
1434 vndk: {
1435 enabled: true,
1436 support_system_process: true,
1437 },
1438 system_shared_libs: [],
1439 stl: "none",
1440 }
1441 `)
1442
Jooyung Han31c470b2019-10-18 16:26:59 +09001443 ensureExactContents(t, ctx, "myapex", []string{
1444 "lib/libvndk.so",
1445 "lib/libvndksp.so",
1446 "lib64/libvndk.so",
1447 "lib64/libvndksp.so",
1448 })
Jooyung Han344d5432019-08-23 11:17:39 +09001449}
1450
1451func TestVndkApexWithPrebuilt(t *testing.T) {
1452 ctx, _ := testApex(t, `
1453 apex_vndk {
1454 name: "myapex",
1455 key: "myapex.key",
1456 file_contexts: "myapex",
1457 }
1458
1459 apex_key {
1460 name: "myapex.key",
1461 public_key: "testkey.avbpubkey",
1462 private_key: "testkey.pem",
1463 }
1464
1465 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001466 name: "libvndk",
1467 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001468 vendor_available: true,
1469 vndk: {
1470 enabled: true,
1471 },
1472 system_shared_libs: [],
1473 stl: "none",
1474 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001475
1476 cc_prebuilt_library_shared {
1477 name: "libvndk.arm",
1478 srcs: ["libvndk.arm.so"],
1479 vendor_available: true,
1480 vndk: {
1481 enabled: true,
1482 },
1483 enabled: false,
1484 arch: {
1485 arm: {
1486 enabled: true,
1487 },
1488 },
1489 system_shared_libs: [],
1490 stl: "none",
1491 }
Jooyung Han344d5432019-08-23 11:17:39 +09001492 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001493 "libvndk.so": nil,
1494 "libvndk.arm.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001495 }))
1496
Jooyung Han31c470b2019-10-18 16:26:59 +09001497 ensureExactContents(t, ctx, "myapex", []string{
1498 "lib/libvndk.so",
1499 "lib/libvndk.arm.so",
1500 "lib64/libvndk.so",
1501 })
Jooyung Han344d5432019-08-23 11:17:39 +09001502}
1503
1504func TestVndkApexVersion(t *testing.T) {
1505 ctx, _ := testApex(t, `
1506 apex_vndk {
1507 name: "myapex_v27",
1508 key: "myapex.key",
1509 file_contexts: "myapex",
1510 vndk_version: "27",
1511 }
1512
1513 apex_key {
1514 name: "myapex.key",
1515 public_key: "testkey.avbpubkey",
1516 private_key: "testkey.pem",
1517 }
1518
Jooyung Han31c470b2019-10-18 16:26:59 +09001519 vndk_prebuilt_shared {
1520 name: "libvndk27",
1521 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001522 vendor_available: true,
1523 vndk: {
1524 enabled: true,
1525 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001526 target_arch: "arm64",
1527 arch: {
1528 arm: {
1529 srcs: ["libvndk27_arm.so"],
1530 },
1531 arm64: {
1532 srcs: ["libvndk27_arm64.so"],
1533 },
1534 },
Jooyung Han344d5432019-08-23 11:17:39 +09001535 }
1536
1537 vndk_prebuilt_shared {
1538 name: "libvndk27",
1539 version: "27",
1540 vendor_available: true,
1541 vndk: {
1542 enabled: true,
1543 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001544 target_arch: "x86_64",
1545 arch: {
1546 x86: {
1547 srcs: ["libvndk27_x86.so"],
1548 },
1549 x86_64: {
1550 srcs: ["libvndk27_x86_64.so"],
1551 },
1552 },
1553 }
Jooyung Han344d5432019-08-23 11:17:39 +09001554 `, withFiles(map[string][]byte{
Jooyung Han31c470b2019-10-18 16:26:59 +09001555 "libvndk27_arm.so": nil,
1556 "libvndk27_arm64.so": nil,
1557 "libvndk27_x86.so": nil,
1558 "libvndk27_x86_64.so": nil,
Jooyung Han344d5432019-08-23 11:17:39 +09001559 }))
1560
Jooyung Han31c470b2019-10-18 16:26:59 +09001561 ensureExactContents(t, ctx, "myapex_v27", []string{
1562 "lib/libvndk27_arm.so",
1563 "lib64/libvndk27_arm64.so",
1564 })
Jooyung Han344d5432019-08-23 11:17:39 +09001565}
1566
1567func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1568 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1569 apex_vndk {
1570 name: "myapex_v27",
1571 key: "myapex.key",
1572 file_contexts: "myapex",
1573 vndk_version: "27",
1574 }
1575 apex_vndk {
1576 name: "myapex_v27_other",
1577 key: "myapex.key",
1578 file_contexts: "myapex",
1579 vndk_version: "27",
1580 }
1581
1582 apex_key {
1583 name: "myapex.key",
1584 public_key: "testkey.avbpubkey",
1585 private_key: "testkey.pem",
1586 }
1587
1588 cc_library {
1589 name: "libvndk",
1590 srcs: ["mylib.cpp"],
1591 vendor_available: true,
1592 vndk: {
1593 enabled: true,
1594 },
1595 system_shared_libs: [],
1596 stl: "none",
1597 }
1598
1599 vndk_prebuilt_shared {
1600 name: "libvndk",
1601 version: "27",
1602 vendor_available: true,
1603 vndk: {
1604 enabled: true,
1605 },
1606 srcs: ["libvndk.so"],
1607 }
1608 `, withFiles(map[string][]byte{
1609 "libvndk.so": nil,
1610 }))
1611}
1612
Jooyung Han90eee022019-10-01 20:02:42 +09001613func TestVndkApexNameRule(t *testing.T) {
1614 ctx, _ := testApex(t, `
1615 apex_vndk {
1616 name: "myapex",
1617 key: "myapex.key",
1618 file_contexts: "myapex",
1619 }
1620 apex_vndk {
1621 name: "myapex_v28",
1622 key: "myapex.key",
1623 file_contexts: "myapex",
1624 vndk_version: "28",
1625 }
1626 apex_key {
1627 name: "myapex.key",
1628 public_key: "testkey.avbpubkey",
1629 private_key: "testkey.pem",
1630 }`)
1631
1632 assertApexName := func(expected, moduleName string) {
Sundong Ahnabb64432019-10-22 13:58:29 +09001633 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001634 actual := proptools.String(bundle.properties.Apex_name)
1635 if !reflect.DeepEqual(actual, expected) {
1636 t.Errorf("Got '%v', expected '%v'", actual, expected)
1637 }
1638 }
1639
1640 assertApexName("com.android.vndk.vVER", "myapex")
1641 assertApexName("com.android.vndk.v28", "myapex_v28")
1642}
1643
Jooyung Han344d5432019-08-23 11:17:39 +09001644func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1645 ctx, _ := testApex(t, `
1646 apex_vndk {
1647 name: "myapex",
1648 key: "myapex.key",
1649 file_contexts: "myapex",
1650 }
1651
1652 apex_key {
1653 name: "myapex.key",
1654 public_key: "testkey.avbpubkey",
1655 private_key: "testkey.pem",
1656 }
1657
1658 cc_library {
1659 name: "libvndk",
1660 srcs: ["mylib.cpp"],
1661 vendor_available: true,
1662 native_bridge_supported: true,
1663 host_supported: true,
1664 vndk: {
1665 enabled: true,
1666 },
1667 system_shared_libs: [],
1668 stl: "none",
1669 }
1670 `, withTargets(map[android.OsType][]android.Target{
1671 android.Android: []android.Target{
Colin Cross3b19f5d2019-09-17 14:45:31 -07001672 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1673 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1674 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1675 {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 +09001676 },
1677 }))
1678
Jooyung Han31c470b2019-10-18 16:26:59 +09001679 ensureExactContents(t, ctx, "myapex", []string{
1680 "lib/libvndk.so",
1681 "lib64/libvndk.so",
1682 })
Jooyung Han344d5432019-08-23 11:17:39 +09001683}
1684
1685func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
1686 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
1687 apex_vndk {
1688 name: "myapex",
1689 key: "myapex.key",
1690 file_contexts: "myapex",
1691 native_bridge_supported: true,
1692 }
1693
1694 apex_key {
1695 name: "myapex.key",
1696 public_key: "testkey.avbpubkey",
1697 private_key: "testkey.pem",
1698 }
1699
1700 cc_library {
1701 name: "libvndk",
1702 srcs: ["mylib.cpp"],
1703 vendor_available: true,
1704 native_bridge_supported: true,
1705 host_supported: true,
1706 vndk: {
1707 enabled: true,
1708 },
1709 system_shared_libs: [],
1710 stl: "none",
1711 }
1712 `)
1713}
1714
Jooyung Han31c470b2019-10-18 16:26:59 +09001715func TestVndkApexWithBinder32(t *testing.T) {
1716 ctx, _ := testApex(t,
1717 `
1718 apex_vndk {
1719 name: "myapex_v27",
1720 key: "myapex.key",
1721 file_contexts: "myapex",
1722 vndk_version: "27",
1723 }
1724
1725 apex_key {
1726 name: "myapex.key",
1727 public_key: "testkey.avbpubkey",
1728 private_key: "testkey.pem",
1729 }
1730
1731 vndk_prebuilt_shared {
1732 name: "libvndk27",
1733 version: "27",
1734 target_arch: "arm",
1735 vendor_available: true,
1736 vndk: {
1737 enabled: true,
1738 },
1739 arch: {
1740 arm: {
1741 srcs: ["libvndk27.so"],
1742 }
1743 },
1744 }
1745
1746 vndk_prebuilt_shared {
1747 name: "libvndk27",
1748 version: "27",
1749 target_arch: "arm",
1750 binder32bit: true,
1751 vendor_available: true,
1752 vndk: {
1753 enabled: true,
1754 },
1755 arch: {
1756 arm: {
1757 srcs: ["libvndk27binder32.so"],
1758 }
1759 },
1760 }
1761 `,
1762 withFiles(map[string][]byte{
1763 "libvndk27.so": nil,
1764 "libvndk27binder32.so": nil,
1765 }),
1766 withBinder32bit,
1767 withTargets(map[android.OsType][]android.Target{
1768 android.Android: []android.Target{
1769 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1770 },
1771 }),
1772 )
1773
1774 ensureExactContents(t, ctx, "myapex_v27", []string{
1775 "lib/libvndk27binder32.so",
1776 })
1777}
1778
Jooyung Hane1633032019-08-01 17:41:43 +09001779func TestDependenciesInApexManifest(t *testing.T) {
1780 ctx, _ := testApex(t, `
1781 apex {
1782 name: "myapex_nodep",
1783 key: "myapex.key",
1784 native_shared_libs: ["lib_nodep"],
1785 compile_multilib: "both",
1786 file_contexts: "myapex",
1787 }
1788
1789 apex {
1790 name: "myapex_dep",
1791 key: "myapex.key",
1792 native_shared_libs: ["lib_dep"],
1793 compile_multilib: "both",
1794 file_contexts: "myapex",
1795 }
1796
1797 apex {
1798 name: "myapex_provider",
1799 key: "myapex.key",
1800 native_shared_libs: ["libfoo"],
1801 compile_multilib: "both",
1802 file_contexts: "myapex",
1803 }
1804
1805 apex {
1806 name: "myapex_selfcontained",
1807 key: "myapex.key",
1808 native_shared_libs: ["lib_dep", "libfoo"],
1809 compile_multilib: "both",
1810 file_contexts: "myapex",
1811 }
1812
1813 apex_key {
1814 name: "myapex.key",
1815 public_key: "testkey.avbpubkey",
1816 private_key: "testkey.pem",
1817 }
1818
1819 cc_library {
1820 name: "lib_nodep",
1821 srcs: ["mylib.cpp"],
1822 system_shared_libs: [],
1823 stl: "none",
1824 }
1825
1826 cc_library {
1827 name: "lib_dep",
1828 srcs: ["mylib.cpp"],
1829 shared_libs: ["libfoo"],
1830 system_shared_libs: [],
1831 stl: "none",
1832 }
1833
1834 cc_library {
1835 name: "libfoo",
1836 srcs: ["mytest.cpp"],
1837 stubs: {
1838 versions: ["1"],
1839 },
1840 system_shared_libs: [],
1841 stl: "none",
1842 }
1843 `)
1844
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001845 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09001846 var provideNativeLibs, requireNativeLibs []string
1847
Sundong Ahnabb64432019-10-22 13:58:29 +09001848 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001849 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1850 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001851 ensureListEmpty(t, provideNativeLibs)
1852 ensureListEmpty(t, requireNativeLibs)
1853
Sundong Ahnabb64432019-10-22 13:58:29 +09001854 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001855 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1856 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001857 ensureListEmpty(t, provideNativeLibs)
1858 ensureListContains(t, requireNativeLibs, "libfoo.so")
1859
Sundong Ahnabb64432019-10-22 13:58:29 +09001860 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001861 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1862 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001863 ensureListContains(t, provideNativeLibs, "libfoo.so")
1864 ensureListEmpty(t, requireNativeLibs)
1865
Sundong Ahnabb64432019-10-22 13:58:29 +09001866 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001867 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
1868 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09001869 ensureListContains(t, provideNativeLibs, "libfoo.so")
1870 ensureListEmpty(t, requireNativeLibs)
1871}
1872
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001873func TestApexName(t *testing.T) {
1874 ctx, _ := testApex(t, `
1875 apex {
1876 name: "myapex",
1877 key: "myapex.key",
1878 apex_name: "com.android.myapex",
1879 }
1880
1881 apex_key {
1882 name: "myapex.key",
1883 public_key: "testkey.avbpubkey",
1884 private_key: "testkey.pem",
1885 }
1886 `)
1887
Sundong Ahnabb64432019-10-22 13:58:29 +09001888 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09001889 apexManifestRule := module.Rule("apexManifestRule")
1890 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
1891 apexRule := module.Rule("apexRule")
1892 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
1893}
1894
Alex Light0851b882019-02-07 13:20:53 -08001895func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001896 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001897 apex {
1898 name: "myapex",
1899 key: "myapex.key",
1900 native_shared_libs: ["mylib_common"],
1901 }
1902
1903 apex_key {
1904 name: "myapex.key",
1905 public_key: "testkey.avbpubkey",
1906 private_key: "testkey.pem",
1907 }
1908
1909 cc_library {
1910 name: "mylib_common",
1911 srcs: ["mylib.cpp"],
1912 system_shared_libs: [],
1913 stl: "none",
1914 }
1915 `)
1916
Sundong Ahnabb64432019-10-22 13:58:29 +09001917 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001918 apexRule := module.Rule("apexRule")
1919 copyCmds := apexRule.Args["copy_commands"]
1920
1921 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1922 t.Log("Apex was a test apex!")
1923 t.Fail()
1924 }
1925 // Ensure that main rule creates an output
1926 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1927
1928 // Ensure that apex variant is created for the direct dep
1929 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1930
1931 // Ensure that both direct and indirect deps are copied into apex
1932 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1933
1934 // Ensure that the platform variant ends with _core_shared
1935 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1936
1937 if !android.InAnyApex("mylib_common") {
1938 t.Log("Found mylib_common not in any apex!")
1939 t.Fail()
1940 }
1941}
1942
1943func TestTestApex(t *testing.T) {
1944 if android.InAnyApex("mylib_common_test") {
1945 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!")
1946 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001947 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001948 apex_test {
1949 name: "myapex",
1950 key: "myapex.key",
1951 native_shared_libs: ["mylib_common_test"],
1952 }
1953
1954 apex_key {
1955 name: "myapex.key",
1956 public_key: "testkey.avbpubkey",
1957 private_key: "testkey.pem",
1958 }
1959
1960 cc_library {
1961 name: "mylib_common_test",
1962 srcs: ["mylib.cpp"],
1963 system_shared_libs: [],
1964 stl: "none",
1965 }
1966 `)
1967
Sundong Ahnabb64432019-10-22 13:58:29 +09001968 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08001969 apexRule := module.Rule("apexRule")
1970 copyCmds := apexRule.Args["copy_commands"]
1971
1972 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1973 t.Log("Apex was not a test apex!")
1974 t.Fail()
1975 }
1976 // Ensure that main rule creates an output
1977 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1978
1979 // Ensure that apex variant is created for the direct dep
1980 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1981
1982 // Ensure that both direct and indirect deps are copied into apex
1983 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1984
1985 // Ensure that the platform variant ends with _core_shared
1986 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1987
1988 if android.InAnyApex("mylib_common_test") {
1989 t.Log("Found mylib_common_test in some apex!")
1990 t.Fail()
1991 }
1992}
1993
Alex Light9670d332019-01-29 18:07:33 -08001994func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001995 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001996 apex {
1997 name: "myapex",
1998 key: "myapex.key",
1999 multilib: {
2000 first: {
2001 native_shared_libs: ["mylib_common"],
2002 }
2003 },
2004 target: {
2005 android: {
2006 multilib: {
2007 first: {
2008 native_shared_libs: ["mylib"],
2009 }
2010 }
2011 },
2012 host: {
2013 multilib: {
2014 first: {
2015 native_shared_libs: ["mylib2"],
2016 }
2017 }
2018 }
2019 }
2020 }
2021
2022 apex_key {
2023 name: "myapex.key",
2024 public_key: "testkey.avbpubkey",
2025 private_key: "testkey.pem",
2026 }
2027
2028 cc_library {
2029 name: "mylib",
2030 srcs: ["mylib.cpp"],
2031 system_shared_libs: [],
2032 stl: "none",
2033 }
2034
2035 cc_library {
2036 name: "mylib_common",
2037 srcs: ["mylib.cpp"],
2038 system_shared_libs: [],
2039 stl: "none",
2040 compile_multilib: "first",
2041 }
2042
2043 cc_library {
2044 name: "mylib2",
2045 srcs: ["mylib.cpp"],
2046 system_shared_libs: [],
2047 stl: "none",
2048 compile_multilib: "first",
2049 }
2050 `)
2051
Sundong Ahnabb64432019-10-22 13:58:29 +09002052 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002053 copyCmds := apexRule.Args["copy_commands"]
2054
2055 // Ensure that main rule creates an output
2056 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2057
2058 // Ensure that apex variant is created for the direct dep
2059 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2060 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
2061 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
2062
2063 // Ensure that both direct and indirect deps are copied into apex
2064 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2065 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2066 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2067
2068 // Ensure that the platform variant ends with _core_shared
2069 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
2070 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
2071 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
2072}
Jiyong Park04480cf2019-02-06 00:16:29 +09002073
2074func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002075 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002076 apex {
2077 name: "myapex",
2078 key: "myapex.key",
2079 binaries: ["myscript"],
2080 }
2081
2082 apex_key {
2083 name: "myapex.key",
2084 public_key: "testkey.avbpubkey",
2085 private_key: "testkey.pem",
2086 }
2087
2088 sh_binary {
2089 name: "myscript",
2090 src: "mylib.cpp",
2091 filename: "myscript.sh",
2092 sub_dir: "script",
2093 }
2094 `)
2095
Sundong Ahnabb64432019-10-22 13:58:29 +09002096 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002097 copyCmds := apexRule.Args["copy_commands"]
2098
2099 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2100}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002101
2102func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002103 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002104 apex {
2105 name: "myapex",
2106 key: "myapex.key",
2107 native_shared_libs: ["mylib"],
2108 product_specific: true,
2109 }
2110
2111 apex_key {
2112 name: "myapex.key",
2113 public_key: "testkey.avbpubkey",
2114 private_key: "testkey.pem",
2115 product_specific: true,
2116 }
2117
2118 cc_library {
2119 name: "mylib",
2120 srcs: ["mylib.cpp"],
2121 system_shared_libs: [],
2122 stl: "none",
2123 }
2124 `)
2125
Sundong Ahnabb64432019-10-22 13:58:29 +09002126 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Colin Crossff6c33d2019-10-02 16:01:35 -07002127 expected := buildDir + "/target/product/test_device/product/apex"
2128 actual := apex.installDir.String()
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002129 if actual != expected {
2130 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2131 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002132}
Jiyong Park67882562019-03-21 01:11:21 +09002133
2134func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002135 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002136 apex_key {
2137 name: "myapex.key",
2138 public_key: ":my.avbpubkey",
2139 private_key: ":my.pem",
2140 product_specific: true,
2141 }
2142
2143 filegroup {
2144 name: "my.avbpubkey",
2145 srcs: ["testkey2.avbpubkey"],
2146 }
2147
2148 filegroup {
2149 name: "my.pem",
2150 srcs: ["testkey2.pem"],
2151 }
2152 `)
2153
2154 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2155 expected_pubkey := "testkey2.avbpubkey"
2156 actual_pubkey := apex_key.public_key_file.String()
2157 if actual_pubkey != expected_pubkey {
2158 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2159 }
2160 expected_privkey := "testkey2.pem"
2161 actual_privkey := apex_key.private_key_file.String()
2162 if actual_privkey != expected_privkey {
2163 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2164 }
2165}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002166
2167func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002168 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002169 prebuilt_apex {
2170 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002171 arch: {
2172 arm64: {
2173 src: "myapex-arm64.apex",
2174 },
2175 arm: {
2176 src: "myapex-arm.apex",
2177 },
2178 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002179 }
2180 `)
2181
2182 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2183
Jiyong Parkc95714e2019-03-29 14:23:10 +09002184 expectedInput := "myapex-arm64.apex"
2185 if prebuilt.inputApex.String() != expectedInput {
2186 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2187 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002188}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002189
2190func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002191 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002192 prebuilt_apex {
2193 name: "myapex",
2194 src: "myapex-arm.apex",
2195 filename: "notmyapex.apex",
2196 }
2197 `)
2198
2199 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2200
2201 expected := "notmyapex.apex"
2202 if p.installFilename != expected {
2203 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2204 }
2205}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002206
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002207func TestPrebuiltOverrides(t *testing.T) {
2208 ctx, config := testApex(t, `
2209 prebuilt_apex {
2210 name: "myapex.prebuilt",
2211 src: "myapex-arm.apex",
2212 overrides: [
2213 "myapex",
2214 ],
2215 }
2216 `)
2217
2218 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2219
2220 expected := []string{"myapex"}
2221 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
2222 if !reflect.DeepEqual(actual, expected) {
2223 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
2224 }
2225}
2226
Roland Levillain630846d2019-06-26 12:48:34 +01002227func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002228 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002229 apex_test {
2230 name: "myapex",
2231 key: "myapex.key",
2232 tests: [
2233 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002234 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002235 ],
2236 }
2237
2238 apex_key {
2239 name: "myapex.key",
2240 public_key: "testkey.avbpubkey",
2241 private_key: "testkey.pem",
2242 }
2243
2244 cc_test {
2245 name: "mytest",
2246 gtest: false,
2247 srcs: ["mytest.cpp"],
2248 relative_install_path: "test",
2249 system_shared_libs: [],
2250 static_executable: true,
2251 stl: "none",
2252 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002253
2254 cc_test {
2255 name: "mytests",
2256 gtest: false,
2257 srcs: [
2258 "mytest1.cpp",
2259 "mytest2.cpp",
2260 "mytest3.cpp",
2261 ],
2262 test_per_src: true,
2263 relative_install_path: "test",
2264 system_shared_libs: [],
2265 static_executable: true,
2266 stl: "none",
2267 }
Roland Levillain630846d2019-06-26 12:48:34 +01002268 `)
2269
Sundong Ahnabb64432019-10-22 13:58:29 +09002270 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002271 copyCmds := apexRule.Args["copy_commands"]
2272
2273 // Ensure that test dep is copied into apex.
2274 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002275
2276 // Ensure that test deps built with `test_per_src` are copied into apex.
2277 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2278 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2279 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002280
2281 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002282 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002283 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2284 name := apexBundle.BaseModuleName()
2285 prefix := "TARGET_"
2286 var builder strings.Builder
2287 data.Custom(&builder, name, prefix, "", data)
2288 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002289 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2290 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2291 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2292 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
2293 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.json.myapex\n")
2294 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002295 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002296}
2297
Jooyung Han5c998b92019-06-27 11:30:33 +09002298func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002299 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002300 apex {
2301 name: "myapex",
2302 key: "myapex.key",
2303 native_shared_libs: ["mylib"],
2304 uses: ["commonapex"],
2305 }
2306
2307 apex {
2308 name: "commonapex",
2309 key: "myapex.key",
2310 native_shared_libs: ["libcommon"],
2311 provide_cpp_shared_libs: true,
2312 }
2313
2314 apex_key {
2315 name: "myapex.key",
2316 public_key: "testkey.avbpubkey",
2317 private_key: "testkey.pem",
2318 }
2319
2320 cc_library {
2321 name: "mylib",
2322 srcs: ["mylib.cpp"],
2323 shared_libs: ["libcommon"],
2324 system_shared_libs: [],
2325 stl: "none",
2326 }
2327
2328 cc_library {
2329 name: "libcommon",
2330 srcs: ["mylib_common.cpp"],
2331 system_shared_libs: [],
2332 stl: "none",
2333 }
2334 `)
2335
Sundong Ahnabb64432019-10-22 13:58:29 +09002336 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002337 apexRule1 := module1.Rule("apexRule")
2338 copyCmds1 := apexRule1.Args["copy_commands"]
2339
Sundong Ahnabb64432019-10-22 13:58:29 +09002340 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002341 apexRule2 := module2.Rule("apexRule")
2342 copyCmds2 := apexRule2.Args["copy_commands"]
2343
2344 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
2345 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
2346 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2347 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2348 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2349}
2350
2351func TestApexUsesFailsIfNotProvided(t *testing.T) {
2352 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2353 apex {
2354 name: "myapex",
2355 key: "myapex.key",
2356 uses: ["commonapex"],
2357 }
2358
2359 apex {
2360 name: "commonapex",
2361 key: "myapex.key",
2362 }
2363
2364 apex_key {
2365 name: "myapex.key",
2366 public_key: "testkey.avbpubkey",
2367 private_key: "testkey.pem",
2368 }
2369 `)
2370 testApexError(t, `uses: "commonapex" is not a provider`, `
2371 apex {
2372 name: "myapex",
2373 key: "myapex.key",
2374 uses: ["commonapex"],
2375 }
2376
2377 cc_library {
2378 name: "commonapex",
2379 system_shared_libs: [],
2380 stl: "none",
2381 }
2382
2383 apex_key {
2384 name: "myapex.key",
2385 public_key: "testkey.avbpubkey",
2386 private_key: "testkey.pem",
2387 }
2388 `)
2389}
2390
2391func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2392 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2393 apex {
2394 name: "myapex",
2395 key: "myapex.key",
2396 use_vendor: true,
2397 uses: ["commonapex"],
2398 }
2399
2400 apex {
2401 name: "commonapex",
2402 key: "myapex.key",
2403 provide_cpp_shared_libs: true,
2404 }
2405
2406 apex_key {
2407 name: "myapex.key",
2408 public_key: "testkey.avbpubkey",
2409 private_key: "testkey.pem",
2410 }
Jooyung Handc782442019-11-01 03:14:38 +09002411 `, func(fs map[string][]byte, config android.Config) {
2412 setUseVendorWhitelistForTest(config, []string{"myapex"})
2413 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002414}
2415
Jooyung Hand48f3c32019-08-23 11:18:57 +09002416func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2417 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2418 apex {
2419 name: "myapex",
2420 key: "myapex.key",
2421 native_shared_libs: ["libfoo"],
2422 }
2423
2424 apex_key {
2425 name: "myapex.key",
2426 public_key: "testkey.avbpubkey",
2427 private_key: "testkey.pem",
2428 }
2429
2430 cc_library {
2431 name: "libfoo",
2432 stl: "none",
2433 system_shared_libs: [],
2434 enabled: false,
2435 }
2436 `)
2437 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2438 apex {
2439 name: "myapex",
2440 key: "myapex.key",
2441 java_libs: ["myjar"],
2442 }
2443
2444 apex_key {
2445 name: "myapex.key",
2446 public_key: "testkey.avbpubkey",
2447 private_key: "testkey.pem",
2448 }
2449
2450 java_library {
2451 name: "myjar",
2452 srcs: ["foo/bar/MyClass.java"],
2453 sdk_version: "none",
2454 system_modules: "none",
2455 compile_dex: true,
2456 enabled: false,
2457 }
2458 `)
2459}
2460
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002461func TestApexWithApps(t *testing.T) {
2462 ctx, _ := testApex(t, `
2463 apex {
2464 name: "myapex",
2465 key: "myapex.key",
2466 apps: [
2467 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002468 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002469 ],
2470 }
2471
2472 apex_key {
2473 name: "myapex.key",
2474 public_key: "testkey.avbpubkey",
2475 private_key: "testkey.pem",
2476 }
2477
2478 android_app {
2479 name: "AppFoo",
2480 srcs: ["foo/bar/MyClass.java"],
2481 sdk_version: "none",
2482 system_modules: "none",
2483 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002484
2485 android_app {
2486 name: "AppFooPriv",
2487 srcs: ["foo/bar/MyClass.java"],
2488 sdk_version: "none",
2489 system_modules: "none",
2490 privileged: true,
2491 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002492 `)
2493
Sundong Ahnabb64432019-10-22 13:58:29 +09002494 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002495 apexRule := module.Rule("apexRule")
2496 copyCmds := apexRule.Args["copy_commands"]
2497
2498 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09002499 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Dario Frenicde2a032019-10-27 00:29:22 +01002500}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002501
Dario Frenicde2a032019-10-27 00:29:22 +01002502func TestApexWithAppImports(t *testing.T) {
2503 ctx, _ := testApex(t, `
2504 apex {
2505 name: "myapex",
2506 key: "myapex.key",
2507 apps: [
2508 "AppFooPrebuilt",
2509 "AppFooPrivPrebuilt",
2510 ],
2511 }
2512
2513 apex_key {
2514 name: "myapex.key",
2515 public_key: "testkey.avbpubkey",
2516 private_key: "testkey.pem",
2517 }
2518
2519 android_app_import {
2520 name: "AppFooPrebuilt",
2521 apk: "PrebuiltAppFoo.apk",
2522 presigned: true,
2523 dex_preopt: {
2524 enabled: false,
2525 },
2526 }
2527
2528 android_app_import {
2529 name: "AppFooPrivPrebuilt",
2530 apk: "PrebuiltAppFooPriv.apk",
2531 privileged: true,
2532 presigned: true,
2533 dex_preopt: {
2534 enabled: false,
2535 },
2536 }
2537 `)
2538
Sundong Ahnabb64432019-10-22 13:58:29 +09002539 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01002540 apexRule := module.Rule("apexRule")
2541 copyCmds := apexRule.Args["copy_commands"]
2542
2543 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
2544 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002545}
2546
Jiyong Park127b40b2019-09-30 16:04:35 +09002547func TestApexAvailable(t *testing.T) {
2548 // libfoo is not available to myapex, but only to otherapex
2549 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
2550 apex {
2551 name: "myapex",
2552 key: "myapex.key",
2553 native_shared_libs: ["libfoo"],
2554 }
2555
2556 apex_key {
2557 name: "myapex.key",
2558 public_key: "testkey.avbpubkey",
2559 private_key: "testkey.pem",
2560 }
2561
2562 apex {
2563 name: "otherapex",
2564 key: "otherapex.key",
2565 native_shared_libs: ["libfoo"],
2566 }
2567
2568 apex_key {
2569 name: "otherapex.key",
2570 public_key: "testkey.avbpubkey",
2571 private_key: "testkey.pem",
2572 }
2573
2574 cc_library {
2575 name: "libfoo",
2576 stl: "none",
2577 system_shared_libs: [],
2578 apex_available: ["otherapex"],
2579 }`)
2580
2581 // libbar is an indirect dep
2582 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
2583 apex {
2584 name: "myapex",
2585 key: "myapex.key",
2586 native_shared_libs: ["libfoo"],
2587 }
2588
2589 apex_key {
2590 name: "myapex.key",
2591 public_key: "testkey.avbpubkey",
2592 private_key: "testkey.pem",
2593 }
2594
2595 apex {
2596 name: "otherapex",
2597 key: "otherapex.key",
2598 native_shared_libs: ["libfoo"],
2599 }
2600
2601 apex_key {
2602 name: "otherapex.key",
2603 public_key: "testkey.avbpubkey",
2604 private_key: "testkey.pem",
2605 }
2606
2607 cc_library {
2608 name: "libfoo",
2609 stl: "none",
2610 shared_libs: ["libbar"],
2611 system_shared_libs: [],
2612 apex_available: ["myapex", "otherapex"],
2613 }
2614
2615 cc_library {
2616 name: "libbar",
2617 stl: "none",
2618 system_shared_libs: [],
2619 apex_available: ["otherapex"],
2620 }`)
2621
2622 testApexError(t, "\"otherapex\" is not a valid module name", `
2623 apex {
2624 name: "myapex",
2625 key: "myapex.key",
2626 native_shared_libs: ["libfoo"],
2627 }
2628
2629 apex_key {
2630 name: "myapex.key",
2631 public_key: "testkey.avbpubkey",
2632 private_key: "testkey.pem",
2633 }
2634
2635 cc_library {
2636 name: "libfoo",
2637 stl: "none",
2638 system_shared_libs: [],
2639 apex_available: ["otherapex"],
2640 }`)
2641
2642 ctx, _ := testApex(t, `
2643 apex {
2644 name: "myapex",
2645 key: "myapex.key",
2646 native_shared_libs: ["libfoo", "libbar"],
2647 }
2648
2649 apex_key {
2650 name: "myapex.key",
2651 public_key: "testkey.avbpubkey",
2652 private_key: "testkey.pem",
2653 }
2654
2655 cc_library {
2656 name: "libfoo",
2657 stl: "none",
2658 system_shared_libs: [],
2659 apex_available: ["myapex"],
2660 }
2661
2662 cc_library {
2663 name: "libbar",
2664 stl: "none",
2665 system_shared_libs: [],
2666 apex_available: ["//apex_available:anyapex"],
2667 }`)
2668
2669 // check that libfoo and libbar are created only for myapex, but not for the platform
2670 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2671 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2672 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared_myapex")
2673 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_core_shared")
2674
2675 ctx, _ = testApex(t, `
2676 apex {
2677 name: "myapex",
2678 key: "myapex.key",
2679 }
2680
2681 apex_key {
2682 name: "myapex.key",
2683 public_key: "testkey.avbpubkey",
2684 private_key: "testkey.pem",
2685 }
2686
2687 cc_library {
2688 name: "libfoo",
2689 stl: "none",
2690 system_shared_libs: [],
2691 apex_available: ["//apex_available:platform"],
2692 }`)
2693
2694 // check that libfoo is created only for the platform
2695 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2696 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09002697
2698 ctx, _ = testApex(t, `
2699 apex {
2700 name: "myapex",
2701 key: "myapex.key",
2702 native_shared_libs: ["libfoo"],
2703 }
2704
2705 apex_key {
2706 name: "myapex.key",
2707 public_key: "testkey.avbpubkey",
2708 private_key: "testkey.pem",
2709 }
2710
2711 cc_library {
2712 name: "libfoo",
2713 stl: "none",
2714 system_shared_libs: [],
2715 apex_available: ["myapex"],
2716 static: {
2717 apex_available: ["//apex_available:platform"],
2718 },
2719 }`)
2720
2721 // shared variant of libfoo is only available to myapex
2722 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex")
2723 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared")
2724 // but the static variant is available to both myapex and the platform
2725 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex")
2726 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09002727}
2728
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002729func TestMain(m *testing.M) {
2730 run := func() int {
2731 setUp()
2732 defer tearDown()
2733
2734 return m.Run()
2735 }
2736
2737 os.Exit(run())
2738}