blob: bb0c4c5be788c66137021dfe85b91bd8a2b85b33 [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))
Jaewoong Jung939ebd52019-03-26 15:07:36 -070094 ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
95 ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
96 })
Jiyong Park25fc6a92018-11-18 18:02:45 +090097 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090098 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090099 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +0900100 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +0100101 ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900102 ctx.BottomUp("version", cc.VersionMutator).Parallel()
103 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
104 })
105
106 ctx.Register()
107
108 bp = bp + `
109 toolchain_library {
110 name: "libcompiler_rt-extras",
111 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900112 vendor_available: true,
113 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900114 }
115
116 toolchain_library {
117 name: "libatomic",
118 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900119 vendor_available: true,
120 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900121 }
122
123 toolchain_library {
124 name: "libgcc",
125 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900126 vendor_available: true,
127 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900128 }
129
130 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700131 name: "libgcc_stripped",
132 src: "",
133 vendor_available: true,
134 recovery_available: true,
135 }
136
137 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900138 name: "libclang_rt.builtins-aarch64-android",
139 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900140 vendor_available: true,
141 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900142 }
143
144 toolchain_library {
145 name: "libclang_rt.builtins-arm-android",
146 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900147 vendor_available: true,
148 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900149 }
150
151 cc_object {
152 name: "crtbegin_so",
153 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900154 vendor_available: true,
155 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900156 }
157
158 cc_object {
159 name: "crtend_so",
160 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900161 vendor_available: true,
162 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900163 }
164
Alex Light3d673592019-01-18 14:37:31 -0800165 cc_object {
166 name: "crtbegin_static",
167 stl: "none",
168 }
169
170 cc_object {
171 name: "crtend_android",
172 stl: "none",
173 }
174
Jiyong Parkda6eb592018-12-19 17:12:36 +0900175 llndk_library {
176 name: "libc",
177 symbol_file: "",
178 }
179
180 llndk_library {
181 name: "libm",
182 symbol_file: "",
183 }
184
185 llndk_library {
186 name: "libdl",
187 symbol_file: "",
188 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900189 `
190
191 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900192 "Android.bp": []byte(bp),
Dan Willemsen412160e2019-04-09 21:36:26 -0700193 "build/make/target/product/security": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900194 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900195 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900196 "system/sepolicy/apex/myapex-file_contexts": nil,
197 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
198 "system/sepolicy/apex/otherapex-file_contexts": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900199 "system/sepolicy/apex/commonapex-file_contexts": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900200 "mylib.cpp": nil,
Jooyung Han5c998b92019-06-27 11:30:33 +0900201 "mylib_common.cpp": nil,
Roland Levillain9b5fde92019-06-28 15:41:19 +0100202 "mytest.cpp": nil,
203 "mytest1.cpp": nil,
204 "mytest2.cpp": nil,
205 "mytest3.cpp": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900206 "myprebuilt": nil,
207 "my_include": nil,
208 "vendor/foo/devkeys/test.x509.pem": nil,
209 "vendor/foo/devkeys/test.pk8": nil,
210 "testkey.x509.pem": nil,
211 "testkey.pk8": nil,
212 "testkey.override.x509.pem": nil,
213 "testkey.override.pk8": nil,
214 "vendor/foo/devkeys/testkey.avbpubkey": nil,
215 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park52818fc2019-03-18 12:01:38 +0900216 "NOTICE": nil,
217 "custom_notice": nil,
Jiyong Park67882562019-03-21 01:11:21 +0900218 "testkey2.avbpubkey": nil,
219 "testkey2.pem": nil,
Jiyong Parkc95714e2019-03-29 14:23:10 +0900220 "myapex-arm64.apex": nil,
221 "myapex-arm.apex": nil,
Jiyong Park71b519d2019-04-18 17:25:49 +0900222 "frameworks/base/api/current.txt": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900223 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900224
Jooyung Han5c998b92019-06-27 11:30:33 +0900225 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900226}
227
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700228func setUp() {
229 var err error
230 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900231 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700232 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900233 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900234}
235
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700236func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900237 os.RemoveAll(buildDir)
238}
239
240// ensure that 'result' contains 'expected'
241func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900242 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900243 if !strings.Contains(result, expected) {
244 t.Errorf("%q is not found in %q", expected, result)
245 }
246}
247
248// ensures that 'result' does not contain 'notExpected'
249func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900250 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900251 if strings.Contains(result, notExpected) {
252 t.Errorf("%q is found in %q", notExpected, result)
253 }
254}
255
256func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900257 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900258 if !android.InList(expected, result) {
259 t.Errorf("%q is not found in %v", expected, result)
260 }
261}
262
263func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900264 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900265 if android.InList(notExpected, result) {
266 t.Errorf("%q is found in %v", notExpected, result)
267 }
268}
269
270// Minimal test
271func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700272 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900273 apex_defaults {
274 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900275 manifest: ":myapex.manifest",
276 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900277 key: "myapex.key",
278 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800279 multilib: {
280 both: {
281 binaries: ["foo",],
282 }
Jiyong Parkf0f7ca82019-07-25 04:38:02 +0000283 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900284 }
285
Jiyong Park30ca9372019-02-07 16:27:23 +0900286 apex {
287 name: "myapex",
288 defaults: ["myapex-defaults"],
289 }
290
Jiyong Park25fc6a92018-11-18 18:02:45 +0900291 apex_key {
292 name: "myapex.key",
293 public_key: "testkey.avbpubkey",
294 private_key: "testkey.pem",
295 }
296
Jiyong Park809bb722019-02-13 21:33:49 +0900297 filegroup {
298 name: "myapex.manifest",
299 srcs: ["apex_manifest.json"],
300 }
301
302 filegroup {
303 name: "myapex.androidmanifest",
304 srcs: ["AndroidManifest.xml"],
305 }
306
Jiyong Park25fc6a92018-11-18 18:02:45 +0900307 cc_library {
308 name: "mylib",
309 srcs: ["mylib.cpp"],
310 shared_libs: ["mylib2"],
311 system_shared_libs: [],
312 stl: "none",
313 }
314
Alex Light3d673592019-01-18 14:37:31 -0800315 cc_binary {
316 name: "foo",
317 srcs: ["mylib.cpp"],
318 compile_multilib: "both",
319 multilib: {
320 lib32: {
321 suffix: "32",
322 },
323 lib64: {
324 suffix: "64",
325 },
326 },
327 symlinks: ["foo_link_"],
328 symlink_preferred_arch: true,
329 system_shared_libs: [],
330 static_executable: true,
331 stl: "none",
332 }
333
Jiyong Park25fc6a92018-11-18 18:02:45 +0900334 cc_library {
335 name: "mylib2",
336 srcs: ["mylib.cpp"],
337 system_shared_libs: [],
338 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900339 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900340 }
341 `)
342
343 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900344
345 optFlags := apexRule.Args["opt_flags"]
346 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700347 // Ensure that the NOTICE output is being packaged as an asset.
348 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900349
Jiyong Park25fc6a92018-11-18 18:02:45 +0900350 copyCmds := apexRule.Args["copy_commands"]
351
352 // Ensure that main rule creates an output
353 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
354
355 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900356 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900357
358 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900359 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900360
361 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800362 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
363 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800364
Jiyong Parkf0f7ca82019-07-25 04:38:02 +0000365 // Ensure that the platform variant ends with _core_shared
Logan Chien3aeedc92018-12-26 15:32:21 +0800366 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
367 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light3d673592019-01-18 14:37:31 -0800368
369 // Ensure that all symlinks are present.
370 found_foo_link_64 := false
371 found_foo := false
372 for _, cmd := range strings.Split(copyCmds, " && ") {
373 if strings.HasPrefix(cmd, "ln -s foo64") {
374 if strings.HasSuffix(cmd, "bin/foo") {
375 found_foo = true
376 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
377 found_foo_link_64 = true
378 }
379 }
380 }
381 good := found_foo && found_foo_link_64
382 if !good {
383 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
384 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900385
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700386 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule")
387 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700388 if len(noticeInputs) != 2 {
389 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900390 }
391 ensureListContains(t, noticeInputs, "NOTICE")
392 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800393}
394
395func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700396 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800397 apex {
398 name: "myapex",
399 key: "myapex.key",
400 payload_type: "zip",
401 native_shared_libs: ["mylib"],
402 }
403
404 apex_key {
405 name: "myapex.key",
406 public_key: "testkey.avbpubkey",
407 private_key: "testkey.pem",
408 }
409
410 cc_library {
411 name: "mylib",
412 srcs: ["mylib.cpp"],
413 shared_libs: ["mylib2"],
414 system_shared_libs: [],
415 stl: "none",
416 }
417
418 cc_library {
419 name: "mylib2",
420 srcs: ["mylib.cpp"],
421 system_shared_libs: [],
422 stl: "none",
423 }
424 `)
425
426 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
427 copyCmds := zipApexRule.Args["copy_commands"]
428
429 // Ensure that main rule creates an output
430 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
431
432 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900433 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800434
435 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900436 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800437
438 // Ensure that both direct and indirect deps are copied into apex
439 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
440 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900441}
442
443func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700444 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900445 apex {
446 name: "myapex",
447 key: "myapex.key",
448 native_shared_libs: ["mylib", "mylib3"],
449 }
450
451 apex_key {
452 name: "myapex.key",
453 public_key: "testkey.avbpubkey",
454 private_key: "testkey.pem",
455 }
456
457 cc_library {
458 name: "mylib",
459 srcs: ["mylib.cpp"],
460 shared_libs: ["mylib2", "mylib3"],
461 system_shared_libs: [],
462 stl: "none",
463 }
464
465 cc_library {
466 name: "mylib2",
467 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900468 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900469 system_shared_libs: [],
470 stl: "none",
471 stubs: {
472 versions: ["1", "2", "3"],
473 },
474 }
475
476 cc_library {
477 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900478 srcs: ["mylib.cpp"],
479 shared_libs: ["mylib4"],
480 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900481 stl: "none",
482 stubs: {
483 versions: ["10", "11", "12"],
484 },
485 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900486
487 cc_library {
488 name: "mylib4",
489 srcs: ["mylib.cpp"],
490 system_shared_libs: [],
491 stl: "none",
492 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900493 `)
494
495 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
496 copyCmds := apexRule.Args["copy_commands"]
497
498 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800499 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900500
501 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800502 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900503
504 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800505 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900506
Jiyong Parkda6eb592018-12-19 17:12:36 +0900507 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900508
509 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900510 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900511 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900512 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900513
514 // 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 +0900515 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900516 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900517 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900518
519 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900520 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900521 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900522
523 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900524 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 +0900525}
526
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900527func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700528 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900529 apex {
530 name: "myapex",
531 key: "myapex.key",
532 native_shared_libs: ["mylib"],
533 }
534
535 apex_key {
536 name: "myapex.key",
537 public_key: "testkey.avbpubkey",
538 private_key: "testkey.pem",
539 }
540
541 cc_library {
542 name: "mylib",
543 srcs: ["mylib.cpp"],
544 shared_libs: ["libfoo#10"],
545 system_shared_libs: [],
546 stl: "none",
547 }
548
549 cc_library {
550 name: "libfoo",
551 srcs: ["mylib.cpp"],
552 shared_libs: ["libbar"],
553 system_shared_libs: [],
554 stl: "none",
555 stubs: {
556 versions: ["10", "20", "30"],
557 },
558 }
559
560 cc_library {
561 name: "libbar",
562 srcs: ["mylib.cpp"],
563 system_shared_libs: [],
564 stl: "none",
565 }
566
567 `)
568
569 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
570 copyCmds := apexRule.Args["copy_commands"]
571
572 // Ensure that direct non-stubs dep is always included
573 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
574
575 // Ensure that indirect stubs dep is not included
576 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
577
578 // Ensure that dependency of stubs is not included
579 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
580
Jiyong Parkda6eb592018-12-19 17:12:36 +0900581 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900582
583 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900584 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900585 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900586 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900587
Jiyong Parkda6eb592018-12-19 17:12:36 +0900588 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900589
590 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
591 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
592}
593
Jiyong Park25fc6a92018-11-18 18:02:45 +0900594func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700595 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900596 apex {
597 name: "myapex",
598 key: "myapex.key",
599 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
600 }
601
602 apex_key {
603 name: "myapex.key",
604 public_key: "testkey.avbpubkey",
605 private_key: "testkey.pem",
606 }
607
608 cc_library {
609 name: "mylib",
610 srcs: ["mylib.cpp"],
611 shared_libs: ["libdl#27"],
612 stl: "none",
613 }
614
615 cc_library_shared {
616 name: "mylib_shared",
617 srcs: ["mylib.cpp"],
618 shared_libs: ["libdl#27"],
619 stl: "none",
620 }
621
622 cc_library {
623 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -0700624 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900625 nocrt: true,
626 system_shared_libs: [],
627 stl: "none",
628 stubs: {
629 versions: ["27", "28", "29"],
630 },
631 }
632
633 cc_library {
634 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -0700635 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900636 nocrt: true,
637 system_shared_libs: [],
638 stl: "none",
639 stubs: {
640 versions: ["27", "28", "29"],
641 },
642 }
643
644 cc_library {
645 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -0700646 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900647 nocrt: true,
648 system_shared_libs: [],
649 stl: "none",
650 stubs: {
651 versions: ["27", "28", "29"],
652 },
653 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900654
655 cc_library {
656 name: "libBootstrap",
657 srcs: ["mylib.cpp"],
658 stl: "none",
659 bootstrap: true,
660 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661 `)
662
663 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
664 copyCmds := apexRule.Args["copy_commands"]
665
666 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800667 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900668 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
669 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900670
671 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900672 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900673
Jiyong Parkda6eb592018-12-19 17:12:36 +0900674 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
675 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
676 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900677
678 // For dependency to libc
679 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900680 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900681 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900682 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900683 // ... Cflags from stub is correctly exported to mylib
684 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
685 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
686
687 // For dependency to libm
688 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900689 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900690 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900691 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900692 // ... and is not compiling with the stub
693 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
694 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
695
696 // For dependency to libdl
697 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900698 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900699 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900700 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
701 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900702 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900703 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900704 // ... Cflags from stub is correctly exported to mylib
705 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
706 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900707
708 // Ensure that libBootstrap is depending on the platform variant of bionic libs
709 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
710 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
711 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
712 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900713}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900714
715func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700716 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +0900717 apex {
718 name: "myapex",
719 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900720 native_shared_libs: ["mylib"],
721 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900722 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900723 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900724 }
725
726 apex_key {
727 name: "myapex.key",
728 public_key: "testkey.avbpubkey",
729 private_key: "testkey.pem",
730 }
731
732 prebuilt_etc {
733 name: "myetc",
734 src: "myprebuilt",
735 sub_dir: "foo/bar",
736 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900737
738 cc_library {
739 name: "mylib",
740 srcs: ["mylib.cpp"],
741 relative_install_path: "foo/bar",
742 system_shared_libs: [],
743 stl: "none",
744 }
745
746 cc_binary {
747 name: "mybin",
748 srcs: ["mylib.cpp"],
749 relative_install_path: "foo/bar",
750 system_shared_libs: [],
751 static_executable: true,
752 stl: "none",
753 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900754 `)
755
756 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
757 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
758
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900759 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900760 ensureListContains(t, dirs, "etc")
761 ensureListContains(t, dirs, "etc/foo")
762 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900763 ensureListContains(t, dirs, "lib64")
764 ensureListContains(t, dirs, "lib64/foo")
765 ensureListContains(t, dirs, "lib64/foo/bar")
766 ensureListContains(t, dirs, "lib")
767 ensureListContains(t, dirs, "lib/foo")
768 ensureListContains(t, dirs, "lib/foo/bar")
769
Jiyong Parkbd13e442019-03-15 18:10:35 +0900770 ensureListContains(t, dirs, "bin")
771 ensureListContains(t, dirs, "bin/foo")
772 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900773}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900774
775func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700776 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +0900777 apex {
778 name: "myapex",
779 key: "myapex.key",
780 native_shared_libs: ["mylib"],
781 use_vendor: true,
782 }
783
784 apex_key {
785 name: "myapex.key",
786 public_key: "testkey.avbpubkey",
787 private_key: "testkey.pem",
788 }
789
790 cc_library {
791 name: "mylib",
792 srcs: ["mylib.cpp"],
793 shared_libs: ["mylib2"],
794 system_shared_libs: [],
795 vendor_available: true,
796 stl: "none",
797 }
798
799 cc_library {
800 name: "mylib2",
801 srcs: ["mylib.cpp"],
802 system_shared_libs: [],
803 vendor_available: true,
804 stl: "none",
805 }
806 `)
807
808 inputsList := []string{}
809 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
810 for _, implicit := range i.Implicits {
811 inputsList = append(inputsList, implicit.String())
812 }
813 }
814 inputsString := strings.Join(inputsList, " ")
815
816 // ensure that the apex includes vendor variants of the direct and indirect deps
817 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
818 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
819
820 // ensure that the apex does not include core variants
821 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
822 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
823}
Jiyong Park16e91a02018-12-20 18:18:08 +0900824
Jooyung Han5c998b92019-06-27 11:30:33 +0900825func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
826 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
827 apex {
828 name: "myapex",
829 key: "myapex.key",
830 native_shared_libs: ["mylib"],
831 use_vendor: true,
832 }
833
834 apex_key {
835 name: "myapex.key",
836 public_key: "testkey.avbpubkey",
837 private_key: "testkey.pem",
838 }
839
840 cc_library {
841 name: "mylib",
842 srcs: ["mylib.cpp"],
843 system_shared_libs: [],
844 stl: "none",
845 }
846 `)
847}
848
Jiyong Park16e91a02018-12-20 18:18:08 +0900849func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700850 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +0900851 apex {
852 name: "myapex",
853 key: "myapex.key",
854 native_shared_libs: ["mylib"],
855 }
856
857 apex_key {
858 name: "myapex.key",
859 public_key: "testkey.avbpubkey",
860 private_key: "testkey.pem",
861 }
862
863 cc_library {
864 name: "mylib",
865 srcs: ["mylib.cpp"],
866 system_shared_libs: [],
867 stl: "none",
868 stubs: {
869 versions: ["1", "2", "3"],
870 },
871 }
872
873 cc_binary {
874 name: "not_in_apex",
875 srcs: ["mylib.cpp"],
876 static_libs: ["mylib"],
877 static_executable: true,
878 system_shared_libs: [],
879 stl: "none",
880 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900881 `)
882
883 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
884
885 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800886 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900887}
Jiyong Park9335a262018-12-24 11:31:58 +0900888
889func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700890 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +0900891 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900892 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900893 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900894 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900895 native_shared_libs: ["mylib"],
896 }
897
898 cc_library {
899 name: "mylib",
900 srcs: ["mylib.cpp"],
901 system_shared_libs: [],
902 stl: "none",
903 }
904
905 apex_key {
906 name: "myapex.key",
907 public_key: "testkey.avbpubkey",
908 private_key: "testkey.pem",
909 }
910
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900911 android_app_certificate {
912 name: "myapex.certificate",
913 certificate: "testkey",
914 }
915
916 android_app_certificate {
917 name: "myapex.certificate.override",
918 certificate: "testkey.override",
919 }
920
Jiyong Park9335a262018-12-24 11:31:58 +0900921 `)
922
923 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +0900924 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +0900925
926 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
927 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
928 "vendor/foo/devkeys/testkey.avbpubkey")
929 }
930 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
931 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
932 "vendor/foo/devkeys/testkey.pem")
933 }
934
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900935 // check the APK certs. It should be overridden to myapex.certificate.override
936 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
937 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900938 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900939 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900940 }
941}
Jiyong Park58e364a2019-01-19 19:24:06 +0900942
943func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700944 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +0900945 apex {
946 name: "myapex",
947 key: "myapex.key",
948 native_shared_libs: ["mylib"],
949 }
950
951 apex {
952 name: "otherapex",
953 key: "myapex.key",
954 native_shared_libs: ["mylib"],
955 }
956
957 apex_key {
958 name: "myapex.key",
959 public_key: "testkey.avbpubkey",
960 private_key: "testkey.pem",
961 }
962
963 cc_library {
964 name: "mylib",
965 srcs: ["mylib.cpp"],
966 system_shared_libs: [],
967 stl: "none",
968 }
969 `)
970
971 // non-APEX variant does not have __ANDROID__APEX__ defined
972 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
973 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
974 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
975
976 // APEX variant has __ANDROID_APEX__=<apexname> defined
977 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
978 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
979 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
980
981 // APEX variant has __ANDROID_APEX__=<apexname> defined
982 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
983 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
984 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
985}
Jiyong Park7e636d02019-01-28 16:16:54 +0900986
987func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700988 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +0900989 apex {
990 name: "myapex",
991 key: "myapex.key",
992 native_shared_libs: ["mylib"],
993 }
994
995 apex_key {
996 name: "myapex.key",
997 public_key: "testkey.avbpubkey",
998 private_key: "testkey.pem",
999 }
1000
1001 cc_library_headers {
1002 name: "mylib_headers",
1003 export_include_dirs: ["my_include"],
1004 system_shared_libs: [],
1005 stl: "none",
1006 }
1007
1008 cc_library {
1009 name: "mylib",
1010 srcs: ["mylib.cpp"],
1011 system_shared_libs: [],
1012 stl: "none",
1013 header_libs: ["mylib_headers"],
1014 export_header_lib_headers: ["mylib_headers"],
1015 stubs: {
1016 versions: ["1", "2", "3"],
1017 },
1018 }
1019
1020 cc_library {
1021 name: "otherlib",
1022 srcs: ["mylib.cpp"],
1023 system_shared_libs: [],
1024 stl: "none",
1025 shared_libs: ["mylib"],
1026 }
1027 `)
1028
1029 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
1030
1031 // Ensure that the include path of the header lib is exported to 'otherlib'
1032 ensureContains(t, cFlags, "-Imy_include")
1033}
Alex Light9670d332019-01-29 18:07:33 -08001034
Alex Light0851b882019-02-07 13:20:53 -08001035func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001036 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001037 apex {
1038 name: "myapex",
1039 key: "myapex.key",
1040 native_shared_libs: ["mylib_common"],
1041 }
1042
1043 apex_key {
1044 name: "myapex.key",
1045 public_key: "testkey.avbpubkey",
1046 private_key: "testkey.pem",
1047 }
1048
1049 cc_library {
1050 name: "mylib_common",
1051 srcs: ["mylib.cpp"],
1052 system_shared_libs: [],
1053 stl: "none",
1054 }
1055 `)
1056
1057 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1058 apexRule := module.Rule("apexRule")
1059 copyCmds := apexRule.Args["copy_commands"]
1060
1061 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
1062 t.Log("Apex was a test apex!")
1063 t.Fail()
1064 }
1065 // Ensure that main rule creates an output
1066 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1067
1068 // Ensure that apex variant is created for the direct dep
1069 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1070
1071 // Ensure that both direct and indirect deps are copied into apex
1072 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1073
1074 // Ensure that the platform variant ends with _core_shared
1075 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1076
1077 if !android.InAnyApex("mylib_common") {
1078 t.Log("Found mylib_common not in any apex!")
1079 t.Fail()
1080 }
1081}
1082
1083func TestTestApex(t *testing.T) {
1084 if android.InAnyApex("mylib_common_test") {
1085 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!")
1086 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001087 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08001088 apex_test {
1089 name: "myapex",
1090 key: "myapex.key",
1091 native_shared_libs: ["mylib_common_test"],
1092 }
1093
1094 apex_key {
1095 name: "myapex.key",
1096 public_key: "testkey.avbpubkey",
1097 private_key: "testkey.pem",
1098 }
1099
1100 cc_library {
1101 name: "mylib_common_test",
1102 srcs: ["mylib.cpp"],
1103 system_shared_libs: [],
1104 stl: "none",
1105 }
1106 `)
1107
1108 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1109 apexRule := module.Rule("apexRule")
1110 copyCmds := apexRule.Args["copy_commands"]
1111
1112 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1113 t.Log("Apex was not a test apex!")
1114 t.Fail()
1115 }
1116 // Ensure that main rule creates an output
1117 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1118
1119 // Ensure that apex variant is created for the direct dep
1120 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1121
1122 // Ensure that both direct and indirect deps are copied into apex
1123 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1124
1125 // Ensure that the platform variant ends with _core_shared
1126 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1127
1128 if android.InAnyApex("mylib_common_test") {
1129 t.Log("Found mylib_common_test in some apex!")
1130 t.Fail()
1131 }
1132}
1133
Alex Light9670d332019-01-29 18:07:33 -08001134func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001135 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08001136 apex {
1137 name: "myapex",
1138 key: "myapex.key",
1139 multilib: {
1140 first: {
1141 native_shared_libs: ["mylib_common"],
1142 }
1143 },
1144 target: {
1145 android: {
1146 multilib: {
1147 first: {
1148 native_shared_libs: ["mylib"],
1149 }
1150 }
1151 },
1152 host: {
1153 multilib: {
1154 first: {
1155 native_shared_libs: ["mylib2"],
1156 }
1157 }
1158 }
1159 }
1160 }
1161
1162 apex_key {
1163 name: "myapex.key",
1164 public_key: "testkey.avbpubkey",
1165 private_key: "testkey.pem",
1166 }
1167
1168 cc_library {
1169 name: "mylib",
1170 srcs: ["mylib.cpp"],
1171 system_shared_libs: [],
1172 stl: "none",
1173 }
1174
1175 cc_library {
1176 name: "mylib_common",
1177 srcs: ["mylib.cpp"],
1178 system_shared_libs: [],
1179 stl: "none",
1180 compile_multilib: "first",
1181 }
1182
1183 cc_library {
1184 name: "mylib2",
1185 srcs: ["mylib.cpp"],
1186 system_shared_libs: [],
1187 stl: "none",
1188 compile_multilib: "first",
1189 }
1190 `)
1191
1192 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1193 copyCmds := apexRule.Args["copy_commands"]
1194
1195 // Ensure that main rule creates an output
1196 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1197
1198 // Ensure that apex variant is created for the direct dep
1199 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1200 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1201 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1202
1203 // Ensure that both direct and indirect deps are copied into apex
1204 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1205 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1206 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1207
1208 // Ensure that the platform variant ends with _core_shared
1209 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1210 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1211 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1212}
Jiyong Park04480cf2019-02-06 00:16:29 +09001213
1214func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001215 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09001216 apex {
1217 name: "myapex",
1218 key: "myapex.key",
1219 binaries: ["myscript"],
1220 }
1221
1222 apex_key {
1223 name: "myapex.key",
1224 public_key: "testkey.avbpubkey",
1225 private_key: "testkey.pem",
1226 }
1227
1228 sh_binary {
1229 name: "myscript",
1230 src: "mylib.cpp",
1231 filename: "myscript.sh",
1232 sub_dir: "script",
1233 }
1234 `)
1235
1236 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1237 copyCmds := apexRule.Args["copy_commands"]
1238
1239 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1240}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001241
1242func TestApexInProductPartition(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001243 ctx, _ := testApex(t, `
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001244 apex {
1245 name: "myapex",
1246 key: "myapex.key",
1247 native_shared_libs: ["mylib"],
1248 product_specific: true,
1249 }
1250
1251 apex_key {
1252 name: "myapex.key",
1253 public_key: "testkey.avbpubkey",
1254 private_key: "testkey.pem",
1255 product_specific: true,
1256 }
1257
1258 cc_library {
1259 name: "mylib",
1260 srcs: ["mylib.cpp"],
1261 system_shared_libs: [],
1262 stl: "none",
1263 }
1264 `)
1265
1266 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1267 expected := "target/product/test_device/product/apex"
1268 actual := apex.installDir.RelPathString()
1269 if actual != expected {
1270 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1271 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001272}
Jiyong Park67882562019-03-21 01:11:21 +09001273
1274func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001275 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09001276 apex_key {
1277 name: "myapex.key",
1278 public_key: ":my.avbpubkey",
1279 private_key: ":my.pem",
1280 product_specific: true,
1281 }
1282
1283 filegroup {
1284 name: "my.avbpubkey",
1285 srcs: ["testkey2.avbpubkey"],
1286 }
1287
1288 filegroup {
1289 name: "my.pem",
1290 srcs: ["testkey2.pem"],
1291 }
1292 `)
1293
1294 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1295 expected_pubkey := "testkey2.avbpubkey"
1296 actual_pubkey := apex_key.public_key_file.String()
1297 if actual_pubkey != expected_pubkey {
1298 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
1299 }
1300 expected_privkey := "testkey2.pem"
1301 actual_privkey := apex_key.private_key_file.String()
1302 if actual_privkey != expected_privkey {
1303 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
1304 }
1305}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001306
1307func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001308 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001309 prebuilt_apex {
1310 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09001311 arch: {
1312 arm64: {
1313 src: "myapex-arm64.apex",
1314 },
1315 arm: {
1316 src: "myapex-arm.apex",
1317 },
1318 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001319 }
1320 `)
1321
1322 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1323
Jiyong Parkc95714e2019-03-29 14:23:10 +09001324 expectedInput := "myapex-arm64.apex"
1325 if prebuilt.inputApex.String() != expectedInput {
1326 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
1327 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07001328}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001329
1330func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001331 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01001332 prebuilt_apex {
1333 name: "myapex",
1334 src: "myapex-arm.apex",
1335 filename: "notmyapex.apex",
1336 }
1337 `)
1338
1339 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
1340
1341 expected := "notmyapex.apex"
1342 if p.installFilename != expected {
1343 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
1344 }
1345}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001346
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001347func TestPrebuiltOverrides(t *testing.T) {
1348 ctx, config := testApex(t, `
1349 prebuilt_apex {
1350 name: "myapex.prebuilt",
1351 src: "myapex-arm.apex",
1352 overrides: [
1353 "myapex",
1354 ],
1355 }
1356 `)
1357
1358 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
1359
1360 expected := []string{"myapex"}
1361 actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"]
1362 if !reflect.DeepEqual(actual, expected) {
1363 t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected)
1364 }
1365}
1366
Roland Levillain630846d2019-06-26 12:48:34 +01001367func TestApexWithTests(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001368 ctx, _ := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01001369 apex_test {
1370 name: "myapex",
1371 key: "myapex.key",
1372 tests: [
1373 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01001374 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01001375 ],
1376 }
1377
1378 apex_key {
1379 name: "myapex.key",
1380 public_key: "testkey.avbpubkey",
1381 private_key: "testkey.pem",
1382 }
1383
1384 cc_test {
1385 name: "mytest",
1386 gtest: false,
1387 srcs: ["mytest.cpp"],
1388 relative_install_path: "test",
1389 system_shared_libs: [],
1390 static_executable: true,
1391 stl: "none",
1392 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01001393
1394 cc_test {
1395 name: "mytests",
1396 gtest: false,
1397 srcs: [
1398 "mytest1.cpp",
1399 "mytest2.cpp",
1400 "mytest3.cpp",
1401 ],
1402 test_per_src: true,
1403 relative_install_path: "test",
1404 system_shared_libs: [],
1405 static_executable: true,
1406 stl: "none",
1407 }
Roland Levillain630846d2019-06-26 12:48:34 +01001408 `)
1409
1410 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1411 copyCmds := apexRule.Args["copy_commands"]
1412
1413 // Ensure that test dep is copied into apex.
1414 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01001415
1416 // Ensure that test deps built with `test_per_src` are copied into apex.
1417 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
1418 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
1419 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillain630846d2019-06-26 12:48:34 +01001420}
1421
Jooyung Han5c998b92019-06-27 11:30:33 +09001422func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001423 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09001424 apex {
1425 name: "myapex",
1426 key: "myapex.key",
1427 native_shared_libs: ["mylib"],
1428 uses: ["commonapex"],
1429 }
1430
1431 apex {
1432 name: "commonapex",
1433 key: "myapex.key",
1434 native_shared_libs: ["libcommon"],
1435 provide_cpp_shared_libs: true,
1436 }
1437
1438 apex_key {
1439 name: "myapex.key",
1440 public_key: "testkey.avbpubkey",
1441 private_key: "testkey.pem",
1442 }
1443
1444 cc_library {
1445 name: "mylib",
1446 srcs: ["mylib.cpp"],
1447 shared_libs: ["libcommon"],
1448 system_shared_libs: [],
1449 stl: "none",
1450 }
1451
1452 cc_library {
1453 name: "libcommon",
1454 srcs: ["mylib_common.cpp"],
1455 system_shared_libs: [],
1456 stl: "none",
1457 }
1458 `)
1459
1460 module1 := ctx.ModuleForTests("myapex", "android_common_myapex")
1461 apexRule1 := module1.Rule("apexRule")
1462 copyCmds1 := apexRule1.Args["copy_commands"]
1463
1464 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex")
1465 apexRule2 := module2.Rule("apexRule")
1466 copyCmds2 := apexRule2.Args["copy_commands"]
1467
1468 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1469 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex")
1470 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
1471 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
1472 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
1473}
1474
1475func TestApexUsesFailsIfNotProvided(t *testing.T) {
1476 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
1477 apex {
1478 name: "myapex",
1479 key: "myapex.key",
1480 uses: ["commonapex"],
1481 }
1482
1483 apex {
1484 name: "commonapex",
1485 key: "myapex.key",
1486 }
1487
1488 apex_key {
1489 name: "myapex.key",
1490 public_key: "testkey.avbpubkey",
1491 private_key: "testkey.pem",
1492 }
1493 `)
1494 testApexError(t, `uses: "commonapex" is not a provider`, `
1495 apex {
1496 name: "myapex",
1497 key: "myapex.key",
1498 uses: ["commonapex"],
1499 }
1500
1501 cc_library {
1502 name: "commonapex",
1503 system_shared_libs: [],
1504 stl: "none",
1505 }
1506
1507 apex_key {
1508 name: "myapex.key",
1509 public_key: "testkey.avbpubkey",
1510 private_key: "testkey.pem",
1511 }
1512 `)
1513}
1514
1515func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
1516 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
1517 apex {
1518 name: "myapex",
1519 key: "myapex.key",
1520 use_vendor: true,
1521 uses: ["commonapex"],
1522 }
1523
1524 apex {
1525 name: "commonapex",
1526 key: "myapex.key",
1527 provide_cpp_shared_libs: true,
1528 }
1529
1530 apex_key {
1531 name: "myapex.key",
1532 public_key: "testkey.avbpubkey",
1533 private_key: "testkey.pem",
1534 }
1535 `)
1536}
1537
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07001538func TestMain(m *testing.M) {
1539 run := func() int {
1540 setUp()
1541 defer tearDown()
1542
1543 return m.Run()
1544 }
1545
1546 os.Exit(run())
1547}