blob: e44163e97581c3248f1ad9fd2fd1797118f8f54e [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070020 "reflect"
Jiyong Park25fc6a92018-11-18 18:02:45 +090021 "strings"
22 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090023
24 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090028 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090029)
30
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070031var buildDir string
32
Jooyung Han5c998b92019-06-27 11:30:33 +090033func testApexError(t *testing.T, pattern, bp string) {
34 ctx, config := testApexContext(t, bp)
35 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
36 if len(errs) > 0 {
37 android.FailIfNoMatchingErrors(t, pattern, errs)
38 return
39 }
40 _, errs = ctx.PrepareBuildActions(config)
41 if len(errs) > 0 {
42 android.FailIfNoMatchingErrors(t, pattern, errs)
43 return
44 }
45
46 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
47}
48
Jaewoong Jung22f7d182019-07-16 18:25:41 -070049func testApex(t *testing.T, bp string) (*android.TestContext, android.Config) {
Jooyung Han5c998b92019-06-27 11:30:33 +090050 ctx, config := testApexContext(t, bp)
51 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
52 android.FailIfErrored(t, errs)
53 _, errs = ctx.PrepareBuildActions(config)
54 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070055 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090056}
57
58func testApexContext(t *testing.T, bp string) (*android.TestContext, android.Config) {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -070059 config := android.TestArchConfig(buildDir, nil)
60 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
61 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
62 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
63 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
64 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
Jiyong Park25fc6a92018-11-18 18:02:45 +090065
66 ctx := android.NewTestArchContext()
Alex Light0851b882019-02-07 13:20:53 -080067 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
68 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090069 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090070 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
Jaewoong Jung939ebd52019-03-26 15:07:36 -070071 ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090072 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jiyong Park25fc6a92018-11-18 18:02:45 +090073
74 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
75 ctx.TopDown("apex_deps", apexDepsMutator)
76 ctx.BottomUp("apex", apexMutator)
Jooyung Han5c998b92019-06-27 11:30:33 +090077 ctx.BottomUp("apex_uses", apexUsesMutator)
Jaewoong Jung939ebd52019-03-26 15:07:36 -070078 ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel()
79 ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090080 })
81
82 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
83 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +090084 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +090085 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090086 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Roland Levillain630846d2019-06-26 12:48:34 +010087 ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090088 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090089 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090090 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +090091 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +090092 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +090093 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park7f7766d2019-07-25 22:02:35 +090094 ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
95
Jaewoong Jung939ebd52019-03-26 15:07:36 -070096 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
97 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
98 })
Jiyong Park25fc6a92018-11-18 18:02:45 +090099 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900100 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900102 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100103 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900104 ctx.BottomUp("version", cc.VersionMutator).Parallel()
105 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
106 })
107
108 ctx.Register()
109
110 bp = bp + `
111 toolchain_library {
112 name: "libcompiler_rt-extras",
113 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900114 vendor_available: true,
115 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900116 }
117
118 toolchain_library {
119 name: "libatomic",
120 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900121 vendor_available: true,
122 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900123 }
124
125 toolchain_library {
126 name: "libgcc",
127 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900128 vendor_available: true,
129 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900130 }
131
132 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700133 name: "libgcc_stripped",
134 src: "",
135 vendor_available: true,
136 recovery_available: true,
137 }
138
139 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900140 name: "libclang_rt.builtins-aarch64-android",
141 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900142 vendor_available: true,
143 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900144 }
145
146 toolchain_library {
147 name: "libclang_rt.builtins-arm-android",
148 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900149 vendor_available: true,
150 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900151 }
152
153 cc_object {
154 name: "crtbegin_so",
155 stl: "none",
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 cc_object {
161 name: "crtend_so",
162 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900163 vendor_available: true,
164 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900165 }
166
Alex Light3d673592019-01-18 14:37:31 -0800167 cc_object {
168 name: "crtbegin_static",
169 stl: "none",
170 }
171
172 cc_object {
173 name: "crtend_android",
174 stl: "none",
175 }
176
Jiyong Parkda6eb592018-12-19 17:12:36 +0900177 llndk_library {
178 name: "libc",
179 symbol_file: "",
180 }
181
182 llndk_library {
183 name: "libm",
184 symbol_file: "",
185 }
186
187 llndk_library {
188 name: "libdl",
189 symbol_file: "",
190 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900191 `
192
193 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900194 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700195 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900196 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900197 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900198 "system/sepolicy/apex/myapex-file_contexts": nil,
199 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
200 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900201 "system/sepolicy/apex/commonapex-file_contexts": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900202 "mylib.cpp": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900203 "mylib_common.cpp": nil,
Roland Levillain9b5fde92019-06-28 15:41:19 +0100204 "mytest.cpp": nil,
205 "mytest1.cpp": nil,
206 "mytest2.cpp": nil,
207 "mytest3.cpp": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900208 "myprebuilt": nil,
209 "my_include": nil,
Jiyong Park7f7766d2019-07-25 22:02:35 +0900210 "foo/bar/MyClass.java": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900211 "vendor/foo/devkeys/test.x509.pem": nil,
212 "vendor/foo/devkeys/test.pk8": nil,
213 "testkey.x509.pem": nil,
214 "testkey.pk8": nil,
215 "testkey.override.x509.pem": nil,
216 "testkey.override.pk8": nil,
217 "vendor/foo/devkeys/testkey.avbpubkey": nil,
218 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park52818fc2019-03-18 12:01:38 +0900219 "NOTICE": nil,
220 "custom_notice": nil,
Jiyong Park67882562019-03-21 01:11:21 +0900221 "testkey2.avbpubkey": nil,
222 "testkey2.pem": nil,
Jiyong Parkc95714e2019-03-29 14:23:10 +0900223 "myapex-arm64.apex": nil,
224 "myapex-arm.apex": nil,
Jiyong Park71b519d2019-04-18 17:25:49 +0900225 "frameworks/base/api/current.txt": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900226 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900227
Jooyung Han5c998b92019-06-27 11:30:33 +0900228 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900229}
230
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700231func setUp() {
232 var err error
233 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900234 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700235 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900236 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900237}
238
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700239func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900240 os.RemoveAll(buildDir)
241}
242
243// ensure that 'result' contains 'expected'
244func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900245 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900246 if !strings.Contains(result, expected) {
247 t.Errorf("%q is not found in %q", expected, result)
248 }
249}
250
251// ensures that 'result' does not contain 'notExpected'
252func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900253 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900254 if strings.Contains(result, notExpected) {
255 t.Errorf("%q is found in %q", notExpected, result)
256 }
257}
258
259func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900260 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900261 if !android.InList(expected, result) {
262 t.Errorf("%q is not found in %v", expected, result)
263 }
264}
265
266func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900267 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900268 if android.InList(notExpected, result) {
269 t.Errorf("%q is found in %v", notExpected, result)
270 }
271}
272
273// Minimal test
274func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700275 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900276 apex_defaults {
277 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900278 manifest: ":myapex.manifest",
279 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900280 key: "myapex.key",
281 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800282 multilib: {
283 both: {
284 binaries: ["foo",],
285 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900286 },
287 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900288 }
289
Jiyong Park30ca9372019-02-07 16:27:23 +0900290 apex {
291 name: "myapex",
292 defaults: ["myapex-defaults"],
293 }
294
Jiyong Park25fc6a92018-11-18 18:02:45 +0900295 apex_key {
296 name: "myapex.key",
297 public_key: "testkey.avbpubkey",
298 private_key: "testkey.pem",
299 }
300
Jiyong Park809bb722019-02-13 21:33:49 +0900301 filegroup {
302 name: "myapex.manifest",
303 srcs: ["apex_manifest.json"],
304 }
305
306 filegroup {
307 name: "myapex.androidmanifest",
308 srcs: ["AndroidManifest.xml"],
309 }
310
Jiyong Park25fc6a92018-11-18 18:02:45 +0900311 cc_library {
312 name: "mylib",
313 srcs: ["mylib.cpp"],
314 shared_libs: ["mylib2"],
315 system_shared_libs: [],
316 stl: "none",
317 }
318
Alex Light3d673592019-01-18 14:37:31 -0800319 cc_binary {
320 name: "foo",
321 srcs: ["mylib.cpp"],
322 compile_multilib: "both",
323 multilib: {
324 lib32: {
325 suffix: "32",
326 },
327 lib64: {
328 suffix: "64",
329 },
330 },
331 symlinks: ["foo_link_"],
332 symlink_preferred_arch: true,
333 system_shared_libs: [],
334 static_executable: true,
335 stl: "none",
336 }
337
Jiyong Park25fc6a92018-11-18 18:02:45 +0900338 cc_library {
339 name: "mylib2",
340 srcs: ["mylib.cpp"],
341 system_shared_libs: [],
342 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900343 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900345
346 java_library {
347 name: "myjar",
348 srcs: ["foo/bar/MyClass.java"],
349 sdk_version: "none",
350 system_modules: "none",
351 compile_dex: true,
352 static_libs: ["myotherjar"],
353 }
354
355 java_library {
356 name: "myotherjar",
357 srcs: ["foo/bar/MyClass.java"],
358 sdk_version: "none",
359 system_modules: "none",
360 compile_dex: true,
361 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900362 `)
363
364 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900365
366 optFlags := apexRule.Args["opt_flags"]
367 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700368 // Ensure that the NOTICE output is being packaged as an asset.
369 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900370
Jiyong Park25fc6a92018-11-18 18:02:45 +0900371 copyCmds := apexRule.Args["copy_commands"]
372
373 // Ensure that main rule creates an output
374 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
375
376 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900377 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900378 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900379
380 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900381 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900382 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900383
384 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800385 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
386 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900387 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
388 // .. but not for java libs
389 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800390
Jiyong Park7f7766d2019-07-25 22:02:35 +0900391 // Ensure that the platform variant ends with _core_shared or _common
Logan Chien3aeedc92018-12-26 15:32:21 +0800392 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
393 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900394 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
395 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Alex Light3d673592019-01-18 14:37:31 -0800396
397 // Ensure that all symlinks are present.
398 found_foo_link_64 := false
399 found_foo := false
400 for _, cmd := range strings.Split(copyCmds, " && ") {
401 if strings.HasPrefix(cmd, "ln -s foo64") {
402 if strings.HasSuffix(cmd, "bin/foo") {
403 found_foo = true
404 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
405 found_foo_link_64 = true
406 }
407 }
408 }
409 good := found_foo && found_foo_link_64
410 if !good {
411 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
412 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900413
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700414 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
415 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700416 if len(noticeInputs) != 2 {
417 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900418 }
419 ensureListContains(t, noticeInputs, "NOTICE")
420 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800421}
422
423func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700424 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800425 apex {
426 name: "myapex",
427 key: "myapex.key",
428 payload_type: "zip",
429 native_shared_libs: ["mylib"],
430 }
431
432 apex_key {
433 name: "myapex.key",
434 public_key: "testkey.avbpubkey",
435 private_key: "testkey.pem",
436 }
437
438 cc_library {
439 name: "mylib",
440 srcs: ["mylib.cpp"],
441 shared_libs: ["mylib2"],
442 system_shared_libs: [],
443 stl: "none",
444 }
445
446 cc_library {
447 name: "mylib2",
448 srcs: ["mylib.cpp"],
449 system_shared_libs: [],
450 stl: "none",
451 }
452 `)
453
454 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
455 copyCmds := zipApexRule.Args["copy_commands"]
456
457 // Ensure that main rule creates an output
458 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
459
460 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900461 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800462
463 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900464 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800465
466 // Ensure that both direct and indirect deps are copied into apex
467 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
468 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900469}
470
471func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700472 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900473 apex {
474 name: "myapex",
475 key: "myapex.key",
476 native_shared_libs: ["mylib", "mylib3"],
477 }
478
479 apex_key {
480 name: "myapex.key",
481 public_key: "testkey.avbpubkey",
482 private_key: "testkey.pem",
483 }
484
485 cc_library {
486 name: "mylib",
487 srcs: ["mylib.cpp"],
488 shared_libs: ["mylib2", "mylib3"],
489 system_shared_libs: [],
490 stl: "none",
491 }
492
493 cc_library {
494 name: "mylib2",
495 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900496 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900497 system_shared_libs: [],
498 stl: "none",
499 stubs: {
500 versions: ["1", "2", "3"],
501 },
502 }
503
504 cc_library {
505 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900506 srcs: ["mylib.cpp"],
507 shared_libs: ["mylib4"],
508 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900509 stl: "none",
510 stubs: {
511 versions: ["10", "11", "12"],
512 },
513 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900514
515 cc_library {
516 name: "mylib4",
517 srcs: ["mylib.cpp"],
518 system_shared_libs: [],
519 stl: "none",
520 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900521 `)
522
523 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
524 copyCmds := apexRule.Args["copy_commands"]
525
526 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800527 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900528
529 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800530 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900531
532 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800533 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900534
Jiyong Parkda6eb592018-12-19 17:12:36 +0900535 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900536
537 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900538 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900539 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900540 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900541
542 // 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 +0900543 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900544 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900545 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900546
547 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900548 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900549 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900550
551 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900552 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 +0900553}
554
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900555func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700556 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900557 apex {
558 name: "myapex",
559 key: "myapex.key",
560 native_shared_libs: ["mylib"],
561 }
562
563 apex_key {
564 name: "myapex.key",
565 public_key: "testkey.avbpubkey",
566 private_key: "testkey.pem",
567 }
568
569 cc_library {
570 name: "mylib",
571 srcs: ["mylib.cpp"],
572 shared_libs: ["libfoo#10"],
573 system_shared_libs: [],
574 stl: "none",
575 }
576
577 cc_library {
578 name: "libfoo",
579 srcs: ["mylib.cpp"],
580 shared_libs: ["libbar"],
581 system_shared_libs: [],
582 stl: "none",
583 stubs: {
584 versions: ["10", "20", "30"],
585 },
586 }
587
588 cc_library {
589 name: "libbar",
590 srcs: ["mylib.cpp"],
591 system_shared_libs: [],
592 stl: "none",
593 }
594
595 `)
596
597 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
598 copyCmds := apexRule.Args["copy_commands"]
599
600 // Ensure that direct non-stubs dep is always included
601 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
602
603 // Ensure that indirect stubs dep is not included
604 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
605
606 // Ensure that dependency of stubs is not included
607 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
608
Jiyong Parkda6eb592018-12-19 17:12:36 +0900609 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900610
611 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900612 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900613 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900614 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900615
Jiyong Parkda6eb592018-12-19 17:12:36 +0900616 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900617
618 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
619 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
620}
621
Jiyong Park25fc6a92018-11-18 18:02:45 +0900622func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700623 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900624 apex {
625 name: "myapex",
626 key: "myapex.key",
627 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
628 }
629
630 apex_key {
631 name: "myapex.key",
632 public_key: "testkey.avbpubkey",
633 private_key: "testkey.pem",
634 }
635
636 cc_library {
637 name: "mylib",
638 srcs: ["mylib.cpp"],
639 shared_libs: ["libdl#27"],
640 stl: "none",
641 }
642
643 cc_library_shared {
644 name: "mylib_shared",
645 srcs: ["mylib.cpp"],
646 shared_libs: ["libdl#27"],
647 stl: "none",
648 }
649
650 cc_library {
651 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700652 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900653 nocrt: true,
654 system_shared_libs: [],
655 stl: "none",
656 stubs: {
657 versions: ["27", "28", "29"],
658 },
659 }
660
661 cc_library {
662 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700663 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900664 nocrt: true,
665 system_shared_libs: [],
666 stl: "none",
667 stubs: {
668 versions: ["27", "28", "29"],
669 },
670 }
671
672 cc_library {
673 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700674 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900675 nocrt: true,
676 system_shared_libs: [],
677 stl: "none",
678 stubs: {
679 versions: ["27", "28", "29"],
680 },
681 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900682
683 cc_library {
684 name: "libBootstrap",
685 srcs: ["mylib.cpp"],
686 stl: "none",
687 bootstrap: true,
688 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900689 `)
690
691 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
692 copyCmds := apexRule.Args["copy_commands"]
693
694 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800695 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900696 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
697 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900698
699 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900700 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900701
Jiyong Parkda6eb592018-12-19 17:12:36 +0900702 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
703 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
704 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900705
706 // For dependency to libc
707 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900708 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900709 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900710 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900711 // ... Cflags from stub is correctly exported to mylib
712 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
713 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
714
715 // For dependency to libm
716 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900717 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900718 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900719 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900720 // ... and is not compiling with the stub
721 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
722 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
723
724 // For dependency to libdl
725 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900726 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900727 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900728 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
729 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900730 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900731 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900732 // ... Cflags from stub is correctly exported to mylib
733 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
734 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900735
736 // Ensure that libBootstrap is depending on the platform variant of bionic libs
737 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
738 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
739 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
740 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900741}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900742
743func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700744 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900745 apex {
746 name: "myapex",
747 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900748 native_shared_libs: ["mylib"],
749 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900750 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900751 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900752 }
753
754 apex_key {
755 name: "myapex.key",
756 public_key: "testkey.avbpubkey",
757 private_key: "testkey.pem",
758 }
759
760 prebuilt_etc {
761 name: "myetc",
762 src: "myprebuilt",
763 sub_dir: "foo/bar",
764 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900765
766 cc_library {
767 name: "mylib",
768 srcs: ["mylib.cpp"],
769 relative_install_path: "foo/bar",
770 system_shared_libs: [],
771 stl: "none",
772 }
773
774 cc_binary {
775 name: "mybin",
776 srcs: ["mylib.cpp"],
777 relative_install_path: "foo/bar",
778 system_shared_libs: [],
779 static_executable: true,
780 stl: "none",
781 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900782 `)
783
784 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
785 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
786
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900787 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900788 ensureListContains(t, dirs, "etc")
789 ensureListContains(t, dirs, "etc/foo")
790 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900791 ensureListContains(t, dirs, "lib64")
792 ensureListContains(t, dirs, "lib64/foo")
793 ensureListContains(t, dirs, "lib64/foo/bar")
794 ensureListContains(t, dirs, "lib")
795 ensureListContains(t, dirs, "lib/foo")
796 ensureListContains(t, dirs, "lib/foo/bar")
797
Jiyong Parkbd13e442019-03-15 18:10:35 +0900798 ensureListContains(t, dirs, "bin")
799 ensureListContains(t, dirs, "bin/foo")
800 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900801}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900802
803func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700804 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +0900805 apex {
806 name: "myapex",
807 key: "myapex.key",
808 native_shared_libs: ["mylib"],
809 use_vendor: true,
810 }
811
812 apex_key {
813 name: "myapex.key",
814 public_key: "testkey.avbpubkey",
815 private_key: "testkey.pem",
816 }
817
818 cc_library {
819 name: "mylib",
820 srcs: ["mylib.cpp"],
821 shared_libs: ["mylib2"],
822 system_shared_libs: [],
823 vendor_available: true,
824 stl: "none",
825 }
826
827 cc_library {
828 name: "mylib2",
829 srcs: ["mylib.cpp"],
830 system_shared_libs: [],
831 vendor_available: true,
832 stl: "none",
833 }
834 `)
835
836 inputsList := []string{}
837 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
838 for _, implicit := range i.Implicits {
839 inputsList = append(inputsList, implicit.String())
840 }
841 }
842 inputsString := strings.Join(inputsList, " ")
843
844 // ensure that the apex includes vendor variants of the direct and indirect deps
845 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
846 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
847
848 // ensure that the apex does not include core variants
849 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
850 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
851}
Jiyong Park16e91a02018-12-20 18:18:08 +0900852
Jooyung Han5c998b92019-06-27 11:30:33 +0900853func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
854 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
855 apex {
856 name: "myapex",
857 key: "myapex.key",
858 native_shared_libs: ["mylib"],
859 use_vendor: true,
860 }
861
862 apex_key {
863 name: "myapex.key",
864 public_key: "testkey.avbpubkey",
865 private_key: "testkey.pem",
866 }
867
868 cc_library {
869 name: "mylib",
870 srcs: ["mylib.cpp"],
871 system_shared_libs: [],
872 stl: "none",
873 }
874 `)
875}
876
Jiyong Park16e91a02018-12-20 18:18:08 +0900877func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700878 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +0900879 apex {
880 name: "myapex",
881 key: "myapex.key",
882 native_shared_libs: ["mylib"],
883 }
884
885 apex_key {
886 name: "myapex.key",
887 public_key: "testkey.avbpubkey",
888 private_key: "testkey.pem",
889 }
890
891 cc_library {
892 name: "mylib",
893 srcs: ["mylib.cpp"],
894 system_shared_libs: [],
895 stl: "none",
896 stubs: {
897 versions: ["1", "2", "3"],
898 },
899 }
900
901 cc_binary {
902 name: "not_in_apex",
903 srcs: ["mylib.cpp"],
904 static_libs: ["mylib"],
905 static_executable: true,
906 system_shared_libs: [],
907 stl: "none",
908 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900909 `)
910
911 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
912
913 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800914 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900915}
Jiyong Park9335a262018-12-24 11:31:58 +0900916
917func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700918 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +0900919 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900920 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900921 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900922 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900923 native_shared_libs: ["mylib"],
924 }
925
926 cc_library {
927 name: "mylib",
928 srcs: ["mylib.cpp"],
929 system_shared_libs: [],
930 stl: "none",
931 }
932
933 apex_key {
934 name: "myapex.key",
935 public_key: "testkey.avbpubkey",
936 private_key: "testkey.pem",
937 }
938
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900939 android_app_certificate {
940 name: "myapex.certificate",
941 certificate: "testkey",
942 }
943
944 android_app_certificate {
945 name: "myapex.certificate.override",
946 certificate: "testkey.override",
947 }
948
Jiyong Park9335a262018-12-24 11:31:58 +0900949 `)
950
951 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +0900952 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +0900953
954 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
955 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
956 "vendor/foo/devkeys/testkey.avbpubkey")
957 }
958 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
959 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
960 "vendor/foo/devkeys/testkey.pem")
961 }
962
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900963 // check the APK certs. It should be overridden to myapex.certificate.override
964 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
965 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900966 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900967 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900968 }
969}
Jiyong Park58e364a2019-01-19 19:24:06 +0900970
971func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700972 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +0900973 apex {
974 name: "myapex",
975 key: "myapex.key",
976 native_shared_libs: ["mylib"],
977 }
978
979 apex {
980 name: "otherapex",
981 key: "myapex.key",
982 native_shared_libs: ["mylib"],
983 }
984
985 apex_key {
986 name: "myapex.key",
987 public_key: "testkey.avbpubkey",
988 private_key: "testkey.pem",
989 }
990
991 cc_library {
992 name: "mylib",
993 srcs: ["mylib.cpp"],
994 system_shared_libs: [],
995 stl: "none",
996 }
997 `)
998
999 // non-APEX variant does not have __ANDROID__APEX__ defined
1000 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1001 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1002 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1003
1004 // APEX variant has __ANDROID_APEX__=<apexname> defined
1005 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
1006 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1007 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1008
1009 // APEX variant has __ANDROID_APEX__=<apexname> defined
1010 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
1011 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
1012 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
1013}
Jiyong Park7e636d02019-01-28 16:16:54 +09001014
1015func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001016 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001017 apex {
1018 name: "myapex",
1019 key: "myapex.key",
1020 native_shared_libs: ["mylib"],
1021 }
1022
1023 apex_key {
1024 name: "myapex.key",
1025 public_key: "testkey.avbpubkey",
1026 private_key: "testkey.pem",
1027 }
1028
1029 cc_library_headers {
1030 name: "mylib_headers",
1031 export_include_dirs: ["my_include"],
1032 system_shared_libs: [],
1033 stl: "none",
1034 }
1035
1036 cc_library {
1037 name: "mylib",
1038 srcs: ["mylib.cpp"],
1039 system_shared_libs: [],
1040 stl: "none",
1041 header_libs: ["mylib_headers"],
1042 export_header_lib_headers: ["mylib_headers"],
1043 stubs: {
1044 versions: ["1", "2", "3"],
1045 },
1046 }
1047
1048 cc_library {
1049 name: "otherlib",
1050 srcs: ["mylib.cpp"],
1051 system_shared_libs: [],
1052 stl: "none",
1053 shared_libs: ["mylib"],
1054 }
1055 `)
1056
1057 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1058
1059 // Ensure that the include path of the header lib is exported to 'otherlib'
1060 ensureContains(t, cFlags, "-Imy_include")
1061}
Alex Light9670d332019-01-29 18:07:33 -08001062
Alex Light0851b882019-02-07 13:20:53 -08001063func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001064 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001065 apex {
1066 name: "myapex",
1067 key: "myapex.key",
1068 native_shared_libs: ["mylib_common"],
1069 }
1070
1071 apex_key {
1072 name: "myapex.key",
1073 public_key: "testkey.avbpubkey",
1074 private_key: "testkey.pem",
1075 }
1076
1077 cc_library {
1078 name: "mylib_common",
1079 srcs: ["mylib.cpp"],
1080 system_shared_libs: [],
1081 stl: "none",
1082 }
1083 `)
1084
1085 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1086 apexRule := module.Rule("apexRule")
1087 copyCmds := apexRule.Args["copy_commands"]
1088
1089 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1090 t.Log("Apex was a test apex!")
1091 t.Fail()
1092 }
1093 // Ensure that main rule creates an output
1094 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1095
1096 // Ensure that apex variant is created for the direct dep
1097 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1098
1099 // Ensure that both direct and indirect deps are copied into apex
1100 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1101
1102 // Ensure that the platform variant ends with _core_shared
1103 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1104
1105 if !android.InAnyApex("mylib_common") {
1106 t.Log("Found mylib_common not in any apex!")
1107 t.Fail()
1108 }
1109}
1110
1111func TestTestApex(t *testing.T) {
1112 if android.InAnyApex("mylib_common_test") {
1113 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!")
1114 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001115 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001116 apex_test {
1117 name: "myapex",
1118 key: "myapex.key",
1119 native_shared_libs: ["mylib_common_test"],
1120 }
1121
1122 apex_key {
1123 name: "myapex.key",
1124 public_key: "testkey.avbpubkey",
1125 private_key: "testkey.pem",
1126 }
1127
1128 cc_library {
1129 name: "mylib_common_test",
1130 srcs: ["mylib.cpp"],
1131 system_shared_libs: [],
1132 stl: "none",
1133 }
1134 `)
1135
1136 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1137 apexRule := module.Rule("apexRule")
1138 copyCmds := apexRule.Args["copy_commands"]
1139
1140 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1141 t.Log("Apex was not a test apex!")
1142 t.Fail()
1143 }
1144 // Ensure that main rule creates an output
1145 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1146
1147 // Ensure that apex variant is created for the direct dep
1148 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1149
1150 // Ensure that both direct and indirect deps are copied into apex
1151 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1152
1153 // Ensure that the platform variant ends with _core_shared
1154 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1155
1156 if android.InAnyApex("mylib_common_test") {
1157 t.Log("Found mylib_common_test in some apex!")
1158 t.Fail()
1159 }
1160}
1161
Alex Light9670d332019-01-29 18:07:33 -08001162func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001163 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001164 apex {
1165 name: "myapex",
1166 key: "myapex.key",
1167 multilib: {
1168 first: {
1169 native_shared_libs: ["mylib_common"],
1170 }
1171 },
1172 target: {
1173 android: {
1174 multilib: {
1175 first: {
1176 native_shared_libs: ["mylib"],
1177 }
1178 }
1179 },
1180 host: {
1181 multilib: {
1182 first: {
1183 native_shared_libs: ["mylib2"],
1184 }
1185 }
1186 }
1187 }
1188 }
1189
1190 apex_key {
1191 name: "myapex.key",
1192 public_key: "testkey.avbpubkey",
1193 private_key: "testkey.pem",
1194 }
1195
1196 cc_library {
1197 name: "mylib",
1198 srcs: ["mylib.cpp"],
1199 system_shared_libs: [],
1200 stl: "none",
1201 }
1202
1203 cc_library {
1204 name: "mylib_common",
1205 srcs: ["mylib.cpp"],
1206 system_shared_libs: [],
1207 stl: "none",
1208 compile_multilib: "first",
1209 }
1210
1211 cc_library {
1212 name: "mylib2",
1213 srcs: ["mylib.cpp"],
1214 system_shared_libs: [],
1215 stl: "none",
1216 compile_multilib: "first",
1217 }
1218 `)
1219
1220 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1221 copyCmds := apexRule.Args["copy_commands"]
1222
1223 // Ensure that main rule creates an output
1224 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1225
1226 // Ensure that apex variant is created for the direct dep
1227 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1228 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1229 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1230
1231 // Ensure that both direct and indirect deps are copied into apex
1232 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1233 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1234 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1235
1236 // Ensure that the platform variant ends with _core_shared
1237 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1238 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1239 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1240}
Jiyong Park04480cf2019-02-06 00:16:29 +09001241
1242func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001243 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001244 apex {
1245 name: "myapex",
1246 key: "myapex.key",
1247 binaries: ["myscript"],
1248 }
1249
1250 apex_key {
1251 name: "myapex.key",
1252 public_key: "testkey.avbpubkey",
1253 private_key: "testkey.pem",
1254 }
1255
1256 sh_binary {
1257 name: "myscript",
1258 src: "mylib.cpp",
1259 filename: "myscript.sh",
1260 sub_dir: "script",
1261 }
1262 `)
1263
1264 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1265 copyCmds := apexRule.Args["copy_commands"]
1266
1267 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1268}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001269
1270func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001271 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001272 apex {
1273 name: "myapex",
1274 key: "myapex.key",
1275 native_shared_libs: ["mylib"],
1276 product_specific: true,
1277 }
1278
1279 apex_key {
1280 name: "myapex.key",
1281 public_key: "testkey.avbpubkey",
1282 private_key: "testkey.pem",
1283 product_specific: true,
1284 }
1285
1286 cc_library {
1287 name: "mylib",
1288 srcs: ["mylib.cpp"],
1289 system_shared_libs: [],
1290 stl: "none",
1291 }
1292 `)
1293
1294 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1295 expected := "target/product/test_device/product/apex"
1296 actual := apex.installDir.RelPathString()
1297 if actual != expected {
1298 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1299 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001300}
Jiyong Park67882562019-03-21 01:11:21 +09001301
1302func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001303 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001304 apex_key {
1305 name: "myapex.key",
1306 public_key: ":my.avbpubkey",
1307 private_key: ":my.pem",
1308 product_specific: true,
1309 }
1310
1311 filegroup {
1312 name: "my.avbpubkey",
1313 srcs: ["testkey2.avbpubkey"],
1314 }
1315
1316 filegroup {
1317 name: "my.pem",
1318 srcs: ["testkey2.pem"],
1319 }
1320 `)
1321
1322 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1323 expected_pubkey := "testkey2.avbpubkey"
1324 actual_pubkey := apex_key.public_key_file.String()
1325 if actual_pubkey != expected_pubkey {
1326 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1327 }
1328 expected_privkey := "testkey2.pem"
1329 actual_privkey := apex_key.private_key_file.String()
1330 if actual_privkey != expected_privkey {
1331 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1332 }
1333}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001334
1335func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001336 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001337 prebuilt_apex {
1338 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001339 arch: {
1340 arm64: {
1341 src: "myapex-arm64.apex",
1342 },
1343 arm: {
1344 src: "myapex-arm.apex",
1345 },
1346 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001347 }
1348 `)
1349
1350 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1351
Jiyong Parkc95714e2019-03-29 14:23:10 +09001352 expectedInput := "myapex-arm64.apex"
1353 if prebuilt.inputApex.String() != expectedInput {
1354 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1355 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001356}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001357
1358func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001359 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001360 prebuilt_apex {
1361 name: "myapex",
1362 src: "myapex-arm.apex",
1363 filename: "notmyapex.apex",
1364 }
1365 `)
1366
1367 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1368
1369 expected := "notmyapex.apex"
1370 if p.installFilename != expected {
1371 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1372 }
1373}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001374
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001375func TestPrebuiltOverrides(t *testing.T) {
1376 ctx, config := testApex(t, `
1377 prebuilt_apex {
1378 name: "myapex.prebuilt",
1379 src: "myapex-arm.apex",
1380 overrides: [
1381 "myapex",
1382 ],
1383 }
1384 `)
1385
1386 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1387
1388 expected := []string{"myapex"}
1389 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1390 if !reflect.DeepEqual(actual, expected) {
1391 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1392 }
1393}
1394
Roland Levillain630846d2019-06-26 12:48:34 +01001395func TestApexWithTests(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001396 ctx, _ := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01001397 apex_test {
1398 name: "myapex",
1399 key: "myapex.key",
1400 tests: [
1401 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01001402 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01001403 ],
1404 }
1405
1406 apex_key {
1407 name: "myapex.key",
1408 public_key: "testkey.avbpubkey",
1409 private_key: "testkey.pem",
1410 }
1411
1412 cc_test {
1413 name: "mytest",
1414 gtest: false,
1415 srcs: ["mytest.cpp"],
1416 relative_install_path: "test",
1417 system_shared_libs: [],
1418 static_executable: true,
1419 stl: "none",
1420 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01001421
1422 cc_test {
1423 name: "mytests",
1424 gtest: false,
1425 srcs: [
1426 "mytest1.cpp",
1427 "mytest2.cpp",
1428 "mytest3.cpp",
1429 ],
1430 test_per_src: true,
1431 relative_install_path: "test",
1432 system_shared_libs: [],
1433 static_executable: true,
1434 stl: "none",
1435 }
Roland Levillain630846d2019-06-26 12:48:34 +01001436 `)
1437
1438 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1439 copyCmds := apexRule.Args["copy_commands"]
1440
1441 // Ensure that test dep is copied into apex.
1442 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01001443
1444 // Ensure that test deps built with `test_per_src` are copied into apex.
1445 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
1446 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
1447 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillain630846d2019-06-26 12:48:34 +01001448}
1449
Jooyung Han5c998b92019-06-27 11:30:33 +09001450func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001451 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09001452 apex {
1453 name: "myapex",
1454 key: "myapex.key",
1455 native_shared_libs: ["mylib"],
1456 uses: ["commonapex"],
1457 }
1458
1459 apex {
1460 name: "commonapex",
1461 key: "myapex.key",
1462 native_shared_libs: ["libcommon"],
1463 provide_cpp_shared_libs: true,
1464 }
1465
1466 apex_key {
1467 name: "myapex.key",
1468 public_key: "testkey.avbpubkey",
1469 private_key: "testkey.pem",
1470 }
1471
1472 cc_library {
1473 name: "mylib",
1474 srcs: ["mylib.cpp"],
1475 shared_libs: ["libcommon"],
1476 system_shared_libs: [],
1477 stl: "none",
1478 }
1479
1480 cc_library {
1481 name: "libcommon",
1482 srcs: ["mylib_common.cpp"],
1483 system_shared_libs: [],
1484 stl: "none",
1485 }
1486 `)
1487
1488 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
1489 apexRule1 := module1.Rule("apexRule")
1490 copyCmds1 := apexRule1.Args["copy_commands"]
1491
1492 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
1493 apexRule2 := module2.Rule("apexRule")
1494 copyCmds2 := apexRule2.Args["copy_commands"]
1495
1496 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1497 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
1498 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
1499 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
1500 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
1501}
1502
1503func TestApexUsesFailsIfNotProvided(t *testing.T) {
1504 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
1505 apex {
1506 name: "myapex",
1507 key: "myapex.key",
1508 uses: ["commonapex"],
1509 }
1510
1511 apex {
1512 name: "commonapex",
1513 key: "myapex.key",
1514 }
1515
1516 apex_key {
1517 name: "myapex.key",
1518 public_key: "testkey.avbpubkey",
1519 private_key: "testkey.pem",
1520 }
1521 `)
1522 testApexError(t, `uses: "commonapex" is not a provider`, `
1523 apex {
1524 name: "myapex",
1525 key: "myapex.key",
1526 uses: ["commonapex"],
1527 }
1528
1529 cc_library {
1530 name: "commonapex",
1531 system_shared_libs: [],
1532 stl: "none",
1533 }
1534
1535 apex_key {
1536 name: "myapex.key",
1537 public_key: "testkey.avbpubkey",
1538 private_key: "testkey.pem",
1539 }
1540 `)
1541}
1542
1543func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
1544 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
1545 apex {
1546 name: "myapex",
1547 key: "myapex.key",
1548 use_vendor: true,
1549 uses: ["commonapex"],
1550 }
1551
1552 apex {
1553 name: "commonapex",
1554 key: "myapex.key",
1555 provide_cpp_shared_libs: true,
1556 }
1557
1558 apex_key {
1559 name: "myapex.key",
1560 public_key: "testkey.avbpubkey",
1561 private_key: "testkey.pem",
1562 }
1563 `)
1564}
1565
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001566func TestMain(m *testing.M) {
1567 run := func() int {
1568 setUp()
1569 defer tearDown()
1570
1571 return m.Run()
1572 }
1573
1574 os.Exit(run())
1575}