blob: fe9db37a15122915d7e9ba054df10f17bc849c23 [file] [log] [blame]
Colin Crossd00350c2017-11-17 10:55:38 -08001// Copyright 2017 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
Colin Cross74d1ec02015-04-28 13:30:13 -070015package cc
16
17import (
Jeff Gaston294356f2017-09-27 17:05:30 -070018 "fmt"
Jiyong Park6a43f042017-10-12 23:05:00 +090019 "io/ioutil"
20 "os"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Colin Cross74d1ec02015-04-28 13:30:13 -070022 "reflect"
Jeff Gaston294356f2017-09-27 17:05:30 -070023 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070024 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070025
26 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070027)
28
Jiyong Park6a43f042017-10-12 23:05:00 +090029var buildDir string
30
31func setUp() {
32 var err error
33 buildDir, err = ioutil.TempDir("", "soong_cc_test")
34 if err != nil {
35 panic(err)
36 }
37}
38
39func tearDown() {
40 os.RemoveAll(buildDir)
41}
42
43func TestMain(m *testing.M) {
44 run := func() int {
45 setUp()
46 defer tearDown()
47
48 return m.Run()
49 }
50
51 os.Exit(run())
52}
53
Colin Cross98be1bb2019-12-13 20:41:13 -080054func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070055 t.Helper()
Colin Crossae8600b2020-10-29 17:09:13 -070056 ctx := CreateTestContext(config)
57 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080058
Jeff Gastond3e141d2017-08-08 17:46:01 -070059 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080060 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090061 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080062 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090063
64 return ctx
65}
66
Logan Chienf3511742017-10-31 18:04:35 +080067func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080068 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080069 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070070 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
71 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080072
Colin Cross98be1bb2019-12-13 20:41:13 -080073 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080074}
75
76func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080077 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -080078 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070079 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080080
Colin Cross98be1bb2019-12-13 20:41:13 -080081 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080082}
83
Justin Yun5f7f7e82019-11-18 19:52:14 +090084func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +080085 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080086
Colin Crossae8600b2020-10-29 17:09:13 -070087 ctx := CreateTestContext(config)
88 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080089
90 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
91 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080092 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +080093 return
94 }
95
96 _, errs = ctx.PrepareBuildActions(config)
97 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +080098 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +080099 return
100 }
101
102 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
103}
104
Justin Yun5f7f7e82019-11-18 19:52:14 +0900105func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900106 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900107 config := TestConfig(buildDir, android.Android, nil, bp, nil)
108 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
109 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
110 testCcErrorWithConfig(t, pattern, config)
111 return
112}
113
114func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900115 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900116 config := TestConfig(buildDir, android.Android, nil, bp, nil)
117 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
118 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
119 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
120 testCcErrorWithConfig(t, pattern, config)
121 return
122}
123
Logan Chienf3511742017-10-31 18:04:35 +0800124const (
Colin Cross7113d202019-11-20 16:39:12 -0800125 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800126 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900127 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800128 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800129)
130
Doug Hornc32c6b02019-01-17 14:44:05 -0800131func TestFuchsiaDeps(t *testing.T) {
132 t.Helper()
133
134 bp := `
135 cc_library {
136 name: "libTest",
137 srcs: ["foo.c"],
138 target: {
139 fuchsia: {
140 srcs: ["bar.c"],
141 },
142 },
143 }`
144
Colin Cross98be1bb2019-12-13 20:41:13 -0800145 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
146 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800147
148 rt := false
149 fb := false
150
151 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
152 implicits := ld.Implicits
153 for _, lib := range implicits {
154 if strings.Contains(lib.Rel(), "libcompiler_rt") {
155 rt = true
156 }
157
158 if strings.Contains(lib.Rel(), "libbioniccompat") {
159 fb = true
160 }
161 }
162
163 if !rt || !fb {
164 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
165 }
166}
167
168func TestFuchsiaTargetDecl(t *testing.T) {
169 t.Helper()
170
171 bp := `
172 cc_library {
173 name: "libTest",
174 srcs: ["foo.c"],
175 target: {
176 fuchsia: {
177 srcs: ["bar.c"],
178 },
179 },
180 }`
181
Colin Cross98be1bb2019-12-13 20:41:13 -0800182 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
183 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800184 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
185 var objs []string
186 for _, o := range ld.Inputs {
187 objs = append(objs, o.Base())
188 }
189 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
190 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
191 }
192}
193
Jiyong Park6a43f042017-10-12 23:05:00 +0900194func TestVendorSrc(t *testing.T) {
195 ctx := testCc(t, `
196 cc_library {
197 name: "libTest",
198 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700199 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800200 nocrt: true,
201 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900202 vendor_available: true,
203 target: {
204 vendor: {
205 srcs: ["bar.c"],
206 },
207 },
208 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900209 `)
210
Logan Chienf3511742017-10-31 18:04:35 +0800211 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900212 var objs []string
213 for _, o := range ld.Inputs {
214 objs = append(objs, o.Base())
215 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800216 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900217 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
218 }
219}
220
Logan Chienf3511742017-10-31 18:04:35 +0800221func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900222 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800223
Logan Chiend3c59a22018-03-29 14:08:15 +0800224 t.Helper()
225
Justin Yun0ecf0b22020-02-28 15:07:59 +0900226 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Ivan Lozano52767be2019-10-18 14:49:46 -0700227 if !mod.HasVendorVariant() {
Justin Yun0ecf0b22020-02-28 15:07:59 +0900228 t.Errorf("%q must have variant %q", name, variant)
Logan Chienf3511742017-10-31 18:04:35 +0800229 }
230
231 // Check library properties.
232 lib, ok := mod.compiler.(*libraryDecorator)
233 if !ok {
234 t.Errorf("%q must have libraryDecorator", name)
235 } else if lib.baseInstaller.subDir != subDir {
236 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
237 lib.baseInstaller.subDir)
238 }
239
240 // Check VNDK properties.
241 if mod.vndkdep == nil {
242 t.Fatalf("%q must have `vndkdep`", name)
243 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700244 if !mod.IsVndk() {
245 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800246 }
247 if mod.isVndkSp() != isVndkSp {
248 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
249 }
250
251 // Check VNDK extension properties.
252 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500253 if mod.IsVndkExt() != isVndkExt {
254 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800255 }
256
257 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
258 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
259 }
260}
261
Bill Peckham945441c2020-08-31 16:07:58 -0700262func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool) {
263 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900264 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
265 if !ok {
266 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900267 return
268 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900269 outputFiles, err := mod.OutputFiles("")
270 if err != nil || len(outputFiles) != 1 {
271 t.Errorf("%q must have single output\n", moduleName)
272 return
273 }
274 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900275
Bill Peckham945441c2020-08-31 16:07:58 -0700276 if include {
277 out := singleton.Output(snapshotPath)
278 if out.Input.String() != outputFiles[0].String() {
279 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
280 }
281 } else {
282 out := singleton.MaybeOutput(snapshotPath)
283 if out.Rule != nil {
284 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
285 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900286 }
287}
288
Bill Peckham945441c2020-08-31 16:07:58 -0700289func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
290 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true)
291}
292
293func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
294 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false)
295}
296
Jooyung Han2216fb12019-11-06 16:46:15 +0900297func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
298 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800299 content := android.ContentFromFileRuleForTests(t, params)
300 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900301 assertArrayString(t, actual, expected)
302}
303
Jooyung Han097087b2019-10-22 19:32:18 +0900304func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
305 t.Helper()
306 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900307 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
308}
309
310func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
311 t.Helper()
312 vndkLibraries := ctx.ModuleForTests(module, "")
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +0900313
314 var output string
315 if module != "vndkcorevariant.libraries.txt" {
316 output = insertVndkVersion(module, "VER")
317 } else {
318 output = module
319 }
320
Jooyung Han2216fb12019-11-06 16:46:15 +0900321 checkWriteFileOutput(t, vndkLibraries.Output(output), expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900322}
323
Logan Chienf3511742017-10-31 18:04:35 +0800324func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800325 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800326 cc_library {
327 name: "libvndk",
328 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900329 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800330 vndk: {
331 enabled: true,
332 },
333 nocrt: true,
334 }
335
336 cc_library {
337 name: "libvndk_private",
338 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900339 product_available: false,
Logan Chienf3511742017-10-31 18:04:35 +0800340 vndk: {
341 enabled: true,
342 },
343 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900344 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800345 }
346
347 cc_library {
348 name: "libvndk_sp",
349 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900350 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800351 vndk: {
352 enabled: true,
353 support_system_process: true,
354 },
355 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900356 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800357 }
358
359 cc_library {
360 name: "libvndk_sp_private",
361 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900362 product_available: false,
Logan Chienf3511742017-10-31 18:04:35 +0800363 vndk: {
364 enabled: true,
365 support_system_process: true,
366 },
367 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900368 target: {
369 vendor: {
370 suffix: "-x",
371 },
372 },
Logan Chienf3511742017-10-31 18:04:35 +0800373 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900374 vndk_libraries_txt {
375 name: "llndk.libraries.txt",
376 }
377 vndk_libraries_txt {
378 name: "vndkcore.libraries.txt",
379 }
380 vndk_libraries_txt {
381 name: "vndksp.libraries.txt",
382 }
383 vndk_libraries_txt {
384 name: "vndkprivate.libraries.txt",
385 }
386 vndk_libraries_txt {
387 name: "vndkcorevariant.libraries.txt",
388 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800389 `
390
391 config := TestConfig(buildDir, android.Android, nil, bp, nil)
392 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900393 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800394 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
395
396 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800397
Jooyung Han261e1582020-10-20 18:54:21 +0900398 // subdir == "" because VNDK libs are not supposed to be installed separately.
399 // They are installed as part of VNDK APEX instead.
400 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
401 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
402 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
403 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900404
Justin Yun63e9ec72020-10-29 16:49:43 +0900405 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
406 checkVndkModule(t, ctx, "libvndk_private", "", false, "", productVariant)
407 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
408 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", productVariant)
409
Inseob Kim1f086e22019-05-09 13:29:15 +0900410 // Check VNDK snapshot output.
411
412 snapshotDir := "vndk-snapshot"
413 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
414
415 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
416 "arm64", "armv8-a"))
417 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
418 "arm", "armv7-a-neon"))
419
420 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
421 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
422 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
423 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
424
Colin Crossfb0c16e2019-11-20 17:12:35 -0800425 variant := "android_vendor.VER_arm64_armv8-a_shared"
426 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900427
Inseob Kim7f283f42020-06-01 21:53:49 +0900428 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
429
430 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
431 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
432 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
433 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900434
Jooyung Han39edb6c2019-11-06 16:53:07 +0900435 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900436 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
437 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
438 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
439 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900440
Jooyung Han097087b2019-10-22 19:32:18 +0900441 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
442 "LLNDK: libc.so",
443 "LLNDK: libdl.so",
444 "LLNDK: libft2.so",
445 "LLNDK: libm.so",
446 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900447 "VNDK-SP: libvndk_sp-x.so",
448 "VNDK-SP: libvndk_sp_private-x.so",
449 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900450 "VNDK-core: libvndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900451 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900452 "VNDK-private: libvndk-private.so",
453 "VNDK-private: libvndk_sp_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900454 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900455 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
456 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
457 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
458 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
459 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
460}
461
Yo Chiangbba545e2020-06-09 16:15:37 +0800462func TestVndkWithHostSupported(t *testing.T) {
463 ctx := testCc(t, `
464 cc_library {
465 name: "libvndk_host_supported",
466 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900467 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800468 vndk: {
469 enabled: true,
470 },
471 host_supported: true,
472 }
473
474 cc_library {
475 name: "libvndk_host_supported_but_disabled_on_device",
476 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900477 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800478 vndk: {
479 enabled: true,
480 },
481 host_supported: true,
482 enabled: false,
483 target: {
484 host: {
485 enabled: true,
486 }
487 }
488 }
489
490 vndk_libraries_txt {
491 name: "vndkcore.libraries.txt",
492 }
493 `)
494
495 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
496}
497
Jooyung Han2216fb12019-11-06 16:46:15 +0900498func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800499 bp := `
Jooyung Han2216fb12019-11-06 16:46:15 +0900500 vndk_libraries_txt {
501 name: "llndk.libraries.txt",
Colin Cross98be1bb2019-12-13 20:41:13 -0800502 }`
503 config := TestConfig(buildDir, android.Android, nil, bp, nil)
504 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
505 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
506 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900507
508 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900509 entries := android.AndroidMkEntriesForTest(t, config, "", module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900510 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900511}
512
513func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800514 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900515 cc_library {
516 name: "libvndk",
517 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900518 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900519 vndk: {
520 enabled: true,
521 },
522 nocrt: true,
523 }
524
525 cc_library {
526 name: "libvndk_sp",
527 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900528 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900529 vndk: {
530 enabled: true,
531 support_system_process: true,
532 },
533 nocrt: true,
534 }
535
536 cc_library {
537 name: "libvndk2",
538 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900539 product_available: false,
Jooyung Han097087b2019-10-22 19:32:18 +0900540 vndk: {
541 enabled: true,
542 },
543 nocrt: true,
544 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900545
546 vndk_libraries_txt {
547 name: "vndkcorevariant.libraries.txt",
548 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800549 `
550
551 config := TestConfig(buildDir, android.Android, nil, bp, nil)
552 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
553 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
554 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
555
556 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
557
558 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900559
Jooyung Han2216fb12019-11-06 16:46:15 +0900560 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900561}
562
Chris Parsons79d66a52020-06-05 17:26:16 -0400563func TestDataLibs(t *testing.T) {
564 bp := `
565 cc_test_library {
566 name: "test_lib",
567 srcs: ["test_lib.cpp"],
568 gtest: false,
569 }
570
571 cc_test {
572 name: "main_test",
573 data_libs: ["test_lib"],
574 gtest: false,
575 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400576 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400577
578 config := TestConfig(buildDir, android.Android, nil, bp, nil)
579 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
580 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
581 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
582
583 ctx := testCcWithConfig(t, config)
584 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
585 testBinary := module.(*Module).linker.(*testBinary)
586 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
587 if err != nil {
588 t.Errorf("Expected cc_test to produce output files, error: %s", err)
589 return
590 }
591 if len(outputFiles) != 1 {
592 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
593 return
594 }
595 if len(testBinary.dataPaths()) != 1 {
596 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
597 return
598 }
599
600 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400601 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400602
603 if !strings.HasSuffix(outputPath, "/main_test") {
604 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
605 return
606 }
607 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
608 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
609 return
610 }
611}
612
Chris Parsons216e10a2020-07-09 17:12:52 -0400613func TestDataLibsRelativeInstallPath(t *testing.T) {
614 bp := `
615 cc_test_library {
616 name: "test_lib",
617 srcs: ["test_lib.cpp"],
618 relative_install_path: "foo/bar/baz",
619 gtest: false,
620 }
621
622 cc_test {
623 name: "main_test",
624 data_libs: ["test_lib"],
625 gtest: false,
626 }
627 `
628
629 config := TestConfig(buildDir, android.Android, nil, bp, nil)
630 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
631 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
632 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
633
634 ctx := testCcWithConfig(t, config)
635 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
636 testBinary := module.(*Module).linker.(*testBinary)
637 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
638 if err != nil {
639 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
640 }
641 if len(outputFiles) != 1 {
642 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
643 }
644 if len(testBinary.dataPaths()) != 1 {
645 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
646 }
647
648 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400649
650 if !strings.HasSuffix(outputPath, "/main_test") {
651 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
652 }
653 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
654 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
655 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400656 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400657 }
658}
659
Jooyung Han0302a842019-10-30 18:43:49 +0900660func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900661 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900662 cc_library {
663 name: "libvndk",
664 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900665 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900666 vndk: {
667 enabled: true,
668 },
669 nocrt: true,
670 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900671 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900672
673 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
674 "LLNDK: libc.so",
675 "LLNDK: libdl.so",
676 "LLNDK: libft2.so",
677 "LLNDK: libm.so",
678 "VNDK-SP: libc++.so",
679 "VNDK-core: libvndk.so",
680 "VNDK-private: libft2.so",
681 })
Logan Chienf3511742017-10-31 18:04:35 +0800682}
683
Justin Yun63e9ec72020-10-29 16:49:43 +0900684func TestVndkModuleError(t *testing.T) {
685 // Check the error message for vendor_available and product_available properties.
686 testCcError(t, "product_available: may not have different value than `vendor_available`", `
687 cc_library {
688 name: "libvndk",
689 vendor_available: true,
690 product_available: false,
691 vndk: {
692 enabled: true,
693 },
694 nocrt: true,
695 }
696 `)
697}
698
Logan Chiend3c59a22018-03-29 14:08:15 +0800699func TestVndkDepError(t *testing.T) {
700 // Check whether an error is emitted when a VNDK lib depends on a system lib.
701 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
702 cc_library {
703 name: "libvndk",
704 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900705 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800706 vndk: {
707 enabled: true,
708 },
709 shared_libs: ["libfwk"], // Cause error
710 nocrt: true,
711 }
712
713 cc_library {
714 name: "libfwk",
715 nocrt: true,
716 }
717 `)
718
719 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
720 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
721 cc_library {
722 name: "libvndk",
723 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900724 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800725 vndk: {
726 enabled: true,
727 },
728 shared_libs: ["libvendor"], // Cause error
729 nocrt: true,
730 }
731
732 cc_library {
733 name: "libvendor",
734 vendor: true,
735 nocrt: true,
736 }
737 `)
738
739 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
740 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
741 cc_library {
742 name: "libvndk_sp",
743 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900744 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800745 vndk: {
746 enabled: true,
747 support_system_process: true,
748 },
749 shared_libs: ["libfwk"], // Cause error
750 nocrt: true,
751 }
752
753 cc_library {
754 name: "libfwk",
755 nocrt: true,
756 }
757 `)
758
759 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
760 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
761 cc_library {
762 name: "libvndk_sp",
763 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900764 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800765 vndk: {
766 enabled: true,
767 support_system_process: true,
768 },
769 shared_libs: ["libvendor"], // Cause error
770 nocrt: true,
771 }
772
773 cc_library {
774 name: "libvendor",
775 vendor: true,
776 nocrt: true,
777 }
778 `)
779
780 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
781 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
782 cc_library {
783 name: "libvndk_sp",
784 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900785 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800786 vndk: {
787 enabled: true,
788 support_system_process: true,
789 },
790 shared_libs: ["libvndk"], // Cause error
791 nocrt: true,
792 }
793
794 cc_library {
795 name: "libvndk",
796 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900797 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800798 vndk: {
799 enabled: true,
800 },
801 nocrt: true,
802 }
803 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900804
805 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
806 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
807 cc_library {
808 name: "libvndk",
809 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900810 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900811 vndk: {
812 enabled: true,
813 },
814 shared_libs: ["libnonvndk"],
815 nocrt: true,
816 }
817
818 cc_library {
819 name: "libnonvndk",
820 vendor_available: true,
821 nocrt: true,
822 }
823 `)
824
825 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
826 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
827 cc_library {
828 name: "libvndkprivate",
829 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900830 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +0900831 vndk: {
832 enabled: true,
833 },
834 shared_libs: ["libnonvndk"],
835 nocrt: true,
836 }
837
838 cc_library {
839 name: "libnonvndk",
840 vendor_available: true,
841 nocrt: true,
842 }
843 `)
844
845 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
846 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
847 cc_library {
848 name: "libvndksp",
849 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900850 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900851 vndk: {
852 enabled: true,
853 support_system_process: true,
854 },
855 shared_libs: ["libnonvndk"],
856 nocrt: true,
857 }
858
859 cc_library {
860 name: "libnonvndk",
861 vendor_available: true,
862 nocrt: true,
863 }
864 `)
865
866 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
867 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
868 cc_library {
869 name: "libvndkspprivate",
870 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900871 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +0900872 vndk: {
873 enabled: true,
874 support_system_process: true,
875 },
876 shared_libs: ["libnonvndk"],
877 nocrt: true,
878 }
879
880 cc_library {
881 name: "libnonvndk",
882 vendor_available: true,
883 nocrt: true,
884 }
885 `)
886}
887
888func TestDoubleLoadbleDep(t *testing.T) {
889 // okay to link : LLNDK -> double_loadable VNDK
890 testCc(t, `
891 cc_library {
892 name: "libllndk",
893 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -0700894 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900895 }
896
897 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700898 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900899 symbol_file: "",
900 }
901
902 cc_library {
903 name: "libdoubleloadable",
904 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900905 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900906 vndk: {
907 enabled: true,
908 },
909 double_loadable: true,
910 }
911 `)
912 // okay to link : LLNDK -> VNDK-SP
913 testCc(t, `
914 cc_library {
915 name: "libllndk",
916 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -0700917 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900918 }
919
920 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700921 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900922 symbol_file: "",
923 }
924
925 cc_library {
926 name: "libvndksp",
927 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900928 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900929 vndk: {
930 enabled: true,
931 support_system_process: true,
932 },
933 }
934 `)
935 // okay to link : double_loadable -> double_loadable
936 testCc(t, `
937 cc_library {
938 name: "libdoubleloadable1",
939 shared_libs: ["libdoubleloadable2"],
940 vendor_available: true,
941 double_loadable: true,
942 }
943
944 cc_library {
945 name: "libdoubleloadable2",
946 vendor_available: true,
947 double_loadable: true,
948 }
949 `)
950 // okay to link : double_loadable VNDK -> double_loadable VNDK private
951 testCc(t, `
952 cc_library {
953 name: "libdoubleloadable",
954 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900955 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900956 vndk: {
957 enabled: true,
958 },
959 double_loadable: true,
960 shared_libs: ["libnondoubleloadable"],
961 }
962
963 cc_library {
964 name: "libnondoubleloadable",
965 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +0900966 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +0900967 vndk: {
968 enabled: true,
969 },
970 double_loadable: true,
971 }
972 `)
973 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
974 testCc(t, `
975 cc_library {
976 name: "libllndk",
977 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -0700978 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900979 }
980
981 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -0700982 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +0900983 symbol_file: "",
984 }
985
986 cc_library {
987 name: "libcoreonly",
988 shared_libs: ["libvendoravailable"],
989 }
990
991 // indirect dependency of LLNDK
992 cc_library {
993 name: "libvendoravailable",
994 vendor_available: true,
995 double_loadable: true,
996 }
997 `)
998}
999
Inseob Kim5f58ff72020-09-07 19:53:31 +09001000func TestVendorSnapshotCapture(t *testing.T) {
Inseob Kim8471cda2019-11-15 09:59:12 +09001001 bp := `
1002 cc_library {
1003 name: "libvndk",
1004 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001005 product_available: true,
Inseob Kim8471cda2019-11-15 09:59:12 +09001006 vndk: {
1007 enabled: true,
1008 },
1009 nocrt: true,
1010 }
1011
1012 cc_library {
1013 name: "libvendor",
1014 vendor: true,
1015 nocrt: true,
1016 }
1017
1018 cc_library {
1019 name: "libvendor_available",
1020 vendor_available: true,
1021 nocrt: true,
1022 }
1023
1024 cc_library_headers {
1025 name: "libvendor_headers",
1026 vendor_available: true,
1027 nocrt: true,
1028 }
1029
1030 cc_binary {
1031 name: "vendor_bin",
1032 vendor: true,
1033 nocrt: true,
1034 }
1035
1036 cc_binary {
1037 name: "vendor_available_bin",
1038 vendor_available: true,
1039 nocrt: true,
1040 }
Inseob Kim7f283f42020-06-01 21:53:49 +09001041
1042 toolchain_library {
1043 name: "libb",
1044 vendor_available: true,
1045 src: "libb.a",
1046 }
Inseob Kim1042d292020-06-01 23:23:05 +09001047
1048 cc_object {
1049 name: "obj",
1050 vendor_available: true,
1051 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001052
1053 cc_library {
1054 name: "libllndk",
1055 llndk_stubs: "libllndk.llndk",
1056 }
1057
1058 llndk_library {
1059 name: "libllndk.llndk",
1060 symbol_file: "",
1061 }
Inseob Kim8471cda2019-11-15 09:59:12 +09001062`
1063 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1064 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1065 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1066 ctx := testCcWithConfig(t, config)
1067
1068 // Check Vendor snapshot output.
1069
1070 snapshotDir := "vendor-snapshot"
1071 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
Inseob Kim7f283f42020-06-01 21:53:49 +09001072 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1073
1074 var jsonFiles []string
Inseob Kim8471cda2019-11-15 09:59:12 +09001075
1076 for _, arch := range [][]string{
1077 []string{"arm64", "armv8-a"},
1078 []string{"arm", "armv7-a-neon"},
1079 } {
1080 archType := arch[0]
1081 archVariant := arch[1]
1082 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1083
1084 // For shared libraries, only non-VNDK vendor_available modules are captured
1085 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1086 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
Inseob Kim7f283f42020-06-01 21:53:49 +09001087 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1088 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
1089 jsonFiles = append(jsonFiles,
1090 filepath.Join(sharedDir, "libvendor.so.json"),
1091 filepath.Join(sharedDir, "libvendor_available.so.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001092
Colin Cross127bb8b2020-12-16 16:46:01 -08001093 // LLNDK modules are not captured
1094 checkSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
1095
Inseob Kim8471cda2019-11-15 09:59:12 +09001096 // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
Inseob Kimc42f2f22020-07-29 20:32:10 +09001097 // Also cfi variants are captured, except for prebuilts like toolchain_library
Inseob Kim8471cda2019-11-15 09:59:12 +09001098 staticVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static", archType, archVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001099 staticCfiVariant := fmt.Sprintf("android_vendor.VER_%s_%s_static_cfi", archType, archVariant)
Inseob Kim8471cda2019-11-15 09:59:12 +09001100 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
Inseob Kim7f283f42020-06-01 21:53:49 +09001101 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1102 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001103 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001104 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001105 checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001106 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
Inseob Kimc42f2f22020-07-29 20:32:10 +09001107 checkSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
Inseob Kim7f283f42020-06-01 21:53:49 +09001108 jsonFiles = append(jsonFiles,
1109 filepath.Join(staticDir, "libb.a.json"),
1110 filepath.Join(staticDir, "libvndk.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001111 filepath.Join(staticDir, "libvndk.cfi.a.json"),
Inseob Kim7f283f42020-06-01 21:53:49 +09001112 filepath.Join(staticDir, "libvendor.a.json"),
Inseob Kimc42f2f22020-07-29 20:32:10 +09001113 filepath.Join(staticDir, "libvendor.cfi.a.json"),
1114 filepath.Join(staticDir, "libvendor_available.a.json"),
1115 filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
Inseob Kim8471cda2019-11-15 09:59:12 +09001116
Inseob Kim7f283f42020-06-01 21:53:49 +09001117 // For binary executables, all vendor:true and vendor_available modules are captured.
Inseob Kim8471cda2019-11-15 09:59:12 +09001118 if archType == "arm64" {
1119 binaryVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1120 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
Inseob Kim7f283f42020-06-01 21:53:49 +09001121 checkSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
1122 checkSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
1123 jsonFiles = append(jsonFiles,
1124 filepath.Join(binaryDir, "vendor_bin.json"),
1125 filepath.Join(binaryDir, "vendor_available_bin.json"))
1126 }
1127
1128 // For header libraries, all vendor:true and vendor_available modules are captured.
1129 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1130 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
Inseob Kim1042d292020-06-01 23:23:05 +09001131
1132 // For object modules, all vendor:true and vendor_available modules are captured.
1133 objectVariant := fmt.Sprintf("android_vendor.VER_%s_%s", archType, archVariant)
1134 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1135 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1136 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
Inseob Kim7f283f42020-06-01 21:53:49 +09001137 }
1138
1139 for _, jsonFile := range jsonFiles {
1140 // verify all json files exist
1141 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1142 t.Errorf("%q expected but not found", jsonFile)
Inseob Kim8471cda2019-11-15 09:59:12 +09001143 }
1144 }
1145}
1146
Inseob Kim5f58ff72020-09-07 19:53:31 +09001147func TestVendorSnapshotUse(t *testing.T) {
1148 frameworkBp := `
1149 cc_library {
1150 name: "libvndk",
1151 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001152 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001153 vndk: {
1154 enabled: true,
1155 },
1156 nocrt: true,
1157 compile_multilib: "64",
1158 }
1159
1160 cc_library {
1161 name: "libvendor",
1162 vendor: true,
1163 nocrt: true,
1164 no_libcrt: true,
1165 stl: "none",
1166 system_shared_libs: [],
1167 compile_multilib: "64",
1168 }
1169
1170 cc_binary {
1171 name: "bin",
1172 vendor: true,
1173 nocrt: true,
1174 no_libcrt: true,
1175 stl: "none",
1176 system_shared_libs: [],
1177 compile_multilib: "64",
1178 }
1179`
1180
1181 vndkBp := `
1182 vndk_prebuilt_shared {
1183 name: "libvndk",
1184 version: "BOARD",
1185 target_arch: "arm64",
1186 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001187 product_available: true,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001188 vndk: {
1189 enabled: true,
1190 },
1191 arch: {
1192 arm64: {
1193 srcs: ["libvndk.so"],
Inseob Kim67be7322020-10-19 10:15:28 +09001194 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001195 },
1196 },
1197 }
1198`
1199
1200 vendorProprietaryBp := `
1201 cc_library {
1202 name: "libvendor_without_snapshot",
1203 vendor: true,
1204 nocrt: true,
1205 no_libcrt: true,
1206 stl: "none",
1207 system_shared_libs: [],
1208 compile_multilib: "64",
1209 }
1210
1211 cc_library_shared {
1212 name: "libclient",
1213 vendor: true,
1214 nocrt: true,
1215 no_libcrt: true,
1216 stl: "none",
1217 system_shared_libs: [],
1218 shared_libs: ["libvndk"],
1219 static_libs: ["libvendor", "libvendor_without_snapshot"],
1220 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001221 srcs: ["client.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001222 }
1223
1224 cc_binary {
1225 name: "bin_without_snapshot",
1226 vendor: true,
1227 nocrt: true,
1228 no_libcrt: true,
1229 stl: "none",
1230 system_shared_libs: [],
1231 static_libs: ["libvndk"],
1232 compile_multilib: "64",
Inseob Kim67be7322020-10-19 10:15:28 +09001233 srcs: ["bin.cpp"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001234 }
1235
1236 vendor_snapshot_static {
1237 name: "libvndk",
1238 version: "BOARD",
1239 target_arch: "arm64",
1240 vendor: true,
1241 arch: {
1242 arm64: {
1243 src: "libvndk.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001244 export_include_dirs: ["include/libvndk"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001245 },
1246 },
1247 }
1248
1249 vendor_snapshot_shared {
1250 name: "libvendor",
1251 version: "BOARD",
1252 target_arch: "arm64",
1253 vendor: true,
1254 arch: {
1255 arm64: {
1256 src: "libvendor.so",
Inseob Kim67be7322020-10-19 10:15:28 +09001257 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001258 },
1259 },
1260 }
1261
1262 vendor_snapshot_static {
1263 name: "libvendor",
1264 version: "BOARD",
1265 target_arch: "arm64",
1266 vendor: true,
1267 arch: {
1268 arm64: {
1269 src: "libvendor.a",
Inseob Kim67be7322020-10-19 10:15:28 +09001270 export_include_dirs: ["include/libvendor"],
Inseob Kim5f58ff72020-09-07 19:53:31 +09001271 },
1272 },
1273 }
1274
1275 vendor_snapshot_binary {
1276 name: "bin",
1277 version: "BOARD",
1278 target_arch: "arm64",
1279 vendor: true,
1280 arch: {
1281 arm64: {
1282 src: "bin",
1283 },
1284 },
1285 }
1286`
1287 depsBp := GatherRequiredDepsForTest(android.Android)
1288
1289 mockFS := map[string][]byte{
Inseob Kim67be7322020-10-19 10:15:28 +09001290 "deps/Android.bp": []byte(depsBp),
1291 "framework/Android.bp": []byte(frameworkBp),
1292 "vendor/Android.bp": []byte(vendorProprietaryBp),
1293 "vendor/bin": nil,
1294 "vendor/bin.cpp": nil,
1295 "vendor/client.cpp": nil,
1296 "vendor/include/libvndk/a.h": nil,
1297 "vendor/include/libvendor/b.h": nil,
1298 "vendor/libvndk.a": nil,
1299 "vendor/libvendor.a": nil,
1300 "vendor/libvendor.so": nil,
1301 "vndk/Android.bp": []byte(vndkBp),
1302 "vndk/include/libvndk/a.h": nil,
1303 "vndk/libvndk.so": nil,
Inseob Kim5f58ff72020-09-07 19:53:31 +09001304 }
1305
1306 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1307 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1308 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001309 ctx := CreateTestContext(config)
1310 ctx.Register()
Inseob Kim5f58ff72020-09-07 19:53:31 +09001311
1312 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
1313 android.FailIfErrored(t, errs)
1314 _, errs = ctx.PrepareBuildActions(config)
1315 android.FailIfErrored(t, errs)
1316
1317 sharedVariant := "android_vendor.BOARD_arm64_armv8-a_shared"
1318 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1319 binaryVariant := "android_vendor.BOARD_arm64_armv8-a"
1320
1321 // libclient uses libvndk.vndk.BOARD.arm64, libvendor.vendor_static.BOARD.arm64, libvendor_without_snapshot
Inseob Kim67be7322020-10-19 10:15:28 +09001322 libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
1323 for _, includeFlags := range []string{
1324 "-Ivndk/include/libvndk", // libvndk
1325 "-Ivendor/include/libvendor", // libvendor
1326 } {
1327 if !strings.Contains(libclientCcFlags, includeFlags) {
1328 t.Errorf("flags for libclient must contain %#v, but was %#v.",
1329 includeFlags, libclientCcFlags)
1330 }
1331 }
Inseob Kim5f58ff72020-09-07 19:53:31 +09001332
Inseob Kim67be7322020-10-19 10:15:28 +09001333 libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001334 for _, input := range [][]string{
1335 []string{sharedVariant, "libvndk.vndk.BOARD.arm64"},
1336 []string{staticVariant, "libvendor.vendor_static.BOARD.arm64"},
1337 []string{staticVariant, "libvendor_without_snapshot"},
1338 } {
1339 outputPaths := getOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
Inseob Kim67be7322020-10-19 10:15:28 +09001340 if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
1341 t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001342 }
1343 }
1344
1345 // bin_without_snapshot uses libvndk.vendor_static.BOARD.arm64
Inseob Kim67be7322020-10-19 10:15:28 +09001346 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
1347 if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {
1348 t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
1349 "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
1350 }
1351
1352 binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
Inseob Kim5f58ff72020-09-07 19:53:31 +09001353 libVndkStaticOutputPaths := getOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.BOARD.arm64"})
Inseob Kim67be7322020-10-19 10:15:28 +09001354 if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
Inseob Kim5f58ff72020-09-07 19:53:31 +09001355 t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
Inseob Kim67be7322020-10-19 10:15:28 +09001356 libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
Inseob Kim5f58ff72020-09-07 19:53:31 +09001357 }
1358
1359 // libvendor.so is installed by libvendor.vendor_shared.BOARD.arm64
1360 ctx.ModuleForTests("libvendor.vendor_shared.BOARD.arm64", sharedVariant).Output("libvendor.so")
1361
1362 // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
1363 ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
1364
1365 // bin is installed by bin.vendor_binary.BOARD.arm64
1366 ctx.ModuleForTests("bin.vendor_binary.BOARD.arm64", binaryVariant).Output("bin")
1367
1368 // bin_without_snapshot is installed by bin_without_snapshot
1369 ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
1370
1371 // libvendor and bin don't have vendor.BOARD variant
1372 libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
1373 if inList(sharedVariant, libvendorVariants) {
1374 t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
1375 }
1376
1377 binVariants := ctx.ModuleVariantsForTests("bin")
1378 if inList(binaryVariant, binVariants) {
1379 t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
1380 }
1381}
1382
Inseob Kimc42f2f22020-07-29 20:32:10 +09001383func TestVendorSnapshotSanitizer(t *testing.T) {
1384 bp := `
1385 vendor_snapshot_static {
1386 name: "libsnapshot",
1387 vendor: true,
1388 target_arch: "arm64",
1389 version: "BOARD",
1390 arch: {
1391 arm64: {
1392 src: "libsnapshot.a",
1393 cfi: {
1394 src: "libsnapshot.cfi.a",
1395 }
1396 },
1397 },
1398 }
1399`
1400 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1401 config.TestProductVariables.DeviceVndkVersion = StringPtr("BOARD")
1402 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1403 ctx := testCcWithConfig(t, config)
1404
1405 // Check non-cfi and cfi variant.
1406 staticVariant := "android_vendor.BOARD_arm64_armv8-a_static"
1407 staticCfiVariant := "android_vendor.BOARD_arm64_armv8-a_static_cfi"
1408
1409 staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticVariant).Module().(*Module)
1410 assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
1411
1412 staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.BOARD.arm64", staticCfiVariant).Module().(*Module)
1413 assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
1414}
1415
Bill Peckham945441c2020-08-31 16:07:58 -07001416func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
1417 t.Helper()
1418 if c.ExcludeFromVendorSnapshot() != expected {
1419 t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
1420 }
1421}
1422
1423func TestVendorSnapshotExclude(t *testing.T) {
1424
1425 // This test verifies that the exclude_from_vendor_snapshot property
1426 // makes its way from the Android.bp source file into the module data
1427 // structure. It also verifies that modules are correctly included or
1428 // excluded in the vendor snapshot based on their path (framework or
1429 // vendor) and the exclude_from_vendor_snapshot property.
1430
1431 frameworkBp := `
1432 cc_library_shared {
1433 name: "libinclude",
1434 srcs: ["src/include.cpp"],
1435 vendor_available: true,
1436 }
1437 cc_library_shared {
1438 name: "libexclude",
1439 srcs: ["src/exclude.cpp"],
1440 vendor: true,
1441 exclude_from_vendor_snapshot: true,
1442 }
1443 `
1444
1445 vendorProprietaryBp := `
1446 cc_library_shared {
1447 name: "libvendor",
1448 srcs: ["vendor.cpp"],
1449 vendor: true,
1450 }
1451 `
1452
1453 depsBp := GatherRequiredDepsForTest(android.Android)
1454
1455 mockFS := map[string][]byte{
1456 "deps/Android.bp": []byte(depsBp),
1457 "framework/Android.bp": []byte(frameworkBp),
1458 "framework/include.cpp": nil,
1459 "framework/exclude.cpp": nil,
1460 "device/Android.bp": []byte(vendorProprietaryBp),
1461 "device/vendor.cpp": nil,
1462 }
1463
1464 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1465 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1466 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001467 ctx := CreateTestContext(config)
1468 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001469
1470 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
1471 android.FailIfErrored(t, errs)
1472 _, errs = ctx.PrepareBuildActions(config)
1473 android.FailIfErrored(t, errs)
1474
1475 // Test an include and exclude framework module.
1476 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
1477 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
1478 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
1479
1480 // A vendor module is excluded, but by its path, not the
1481 // exclude_from_vendor_snapshot property.
1482 assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
1483
1484 // Verify the content of the vendor snapshot.
1485
1486 snapshotDir := "vendor-snapshot"
1487 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1488 snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
1489
1490 var includeJsonFiles []string
1491 var excludeJsonFiles []string
1492
1493 for _, arch := range [][]string{
1494 []string{"arm64", "armv8-a"},
1495 []string{"arm", "armv7-a-neon"},
1496 } {
1497 archType := arch[0]
1498 archVariant := arch[1]
1499 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1500
1501 sharedVariant := fmt.Sprintf("android_vendor.VER_%s_%s_shared", archType, archVariant)
1502 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1503
1504 // Included modules
1505 checkSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
1506 includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
1507
1508 // Excluded modules
1509 checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
1510 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
1511 checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
1512 excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
1513 }
1514
1515 // Verify that each json file for an included module has a rule.
1516 for _, jsonFile := range includeJsonFiles {
1517 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1518 t.Errorf("include json file %q not found", jsonFile)
1519 }
1520 }
1521
1522 // Verify that each json file for an excluded module has no rule.
1523 for _, jsonFile := range excludeJsonFiles {
1524 if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
1525 t.Errorf("exclude json file %q found", jsonFile)
1526 }
1527 }
1528}
1529
1530func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
1531
1532 // This test verifies that using the exclude_from_vendor_snapshot
1533 // property on a module in a vendor proprietary path generates an
1534 // error. These modules are already excluded, so we prohibit using the
1535 // property in this way, which could add to confusion.
1536
1537 vendorProprietaryBp := `
1538 cc_library_shared {
1539 name: "libvendor",
1540 srcs: ["vendor.cpp"],
1541 vendor: true,
1542 exclude_from_vendor_snapshot: true,
1543 }
1544 `
1545
1546 depsBp := GatherRequiredDepsForTest(android.Android)
1547
1548 mockFS := map[string][]byte{
1549 "deps/Android.bp": []byte(depsBp),
1550 "device/Android.bp": []byte(vendorProprietaryBp),
1551 "device/vendor.cpp": nil,
1552 }
1553
1554 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1555 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1556 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001557 ctx := CreateTestContext(config)
1558 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001559
1560 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
1561 android.FailIfErrored(t, errs)
1562
1563 _, errs = ctx.PrepareBuildActions(config)
1564 android.CheckErrorsAgainstExpectations(t, errs, []string{
1565 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1566 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Jose Galmesf7294582020-11-13 12:07:36 -08001567 `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
1568 `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
Bill Peckham945441c2020-08-31 16:07:58 -07001569 })
1570}
1571
1572func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {
1573
1574 // This test verifies that using the exclude_from_vendor_snapshot
1575 // property on a module that is vendor available generates an error. A
1576 // vendor available module must be captured in the vendor snapshot and
1577 // must not built from source when building the vendor image against
1578 // the vendor snapshot.
1579
1580 frameworkBp := `
1581 cc_library_shared {
1582 name: "libinclude",
1583 srcs: ["src/include.cpp"],
1584 vendor_available: true,
1585 exclude_from_vendor_snapshot: true,
1586 }
1587 `
1588
1589 depsBp := GatherRequiredDepsForTest(android.Android)
1590
1591 mockFS := map[string][]byte{
1592 "deps/Android.bp": []byte(depsBp),
1593 "framework/Android.bp": []byte(frameworkBp),
1594 "framework/include.cpp": nil,
1595 }
1596
1597 config := TestConfig(buildDir, android.Android, nil, "", mockFS)
1598 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1599 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Colin Crossae8600b2020-10-29 17:09:13 -07001600 ctx := CreateTestContext(config)
1601 ctx.Register()
Bill Peckham945441c2020-08-31 16:07:58 -07001602
1603 _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
1604 android.FailIfErrored(t, errs)
1605
1606 _, errs = ctx.PrepareBuildActions(config)
1607 android.CheckErrorsAgainstExpectations(t, errs, []string{
1608 `module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1609 `module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1610 `module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1611 `module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
1612 })
1613}
1614
Jose Galmesf7294582020-11-13 12:07:36 -08001615func TestRecoverySnapshotCapture(t *testing.T) {
1616 bp := `
1617 cc_library {
1618 name: "libvndk",
1619 vendor_available: true,
1620 recovery_available: true,
1621 product_available: true,
1622 vndk: {
1623 enabled: true,
1624 },
1625 nocrt: true,
1626 }
1627
1628 cc_library {
1629 name: "librecovery",
1630 recovery: true,
1631 nocrt: true,
1632 }
1633
1634 cc_library {
1635 name: "librecovery_available",
1636 recovery_available: true,
1637 nocrt: true,
1638 }
1639
1640 cc_library_headers {
1641 name: "librecovery_headers",
1642 recovery_available: true,
1643 nocrt: true,
1644 }
1645
1646 cc_binary {
1647 name: "recovery_bin",
1648 recovery: true,
1649 nocrt: true,
1650 }
1651
1652 cc_binary {
1653 name: "recovery_available_bin",
1654 recovery_available: true,
1655 nocrt: true,
1656 }
1657
1658 toolchain_library {
1659 name: "libb",
1660 recovery_available: true,
1661 src: "libb.a",
1662 }
1663
1664 cc_object {
1665 name: "obj",
1666 recovery_available: true,
1667 }
1668`
1669 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1670 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1671 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1672 ctx := testCcWithConfig(t, config)
1673
1674 // Check Recovery snapshot output.
1675
1676 snapshotDir := "recovery-snapshot"
1677 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
1678 snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
1679
1680 var jsonFiles []string
1681
1682 for _, arch := range [][]string{
1683 []string{"arm64", "armv8-a"},
1684 } {
1685 archType := arch[0]
1686 archVariant := arch[1]
1687 archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
1688
1689 // For shared libraries, only recovery_available modules are captured.
1690 sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
1691 sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
1692 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
1693 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
1694 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
1695 jsonFiles = append(jsonFiles,
1696 filepath.Join(sharedDir, "libvndk.so.json"),
1697 filepath.Join(sharedDir, "librecovery.so.json"),
1698 filepath.Join(sharedDir, "librecovery_available.so.json"))
1699
1700 // For static libraries, all recovery:true and recovery_available modules are captured.
1701 staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
1702 staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
1703 checkSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
1704 checkSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
1705 checkSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
1706 jsonFiles = append(jsonFiles,
1707 filepath.Join(staticDir, "libb.a.json"),
1708 filepath.Join(staticDir, "librecovery.a.json"),
1709 filepath.Join(staticDir, "librecovery_available.a.json"))
1710
1711 // For binary executables, all recovery:true and recovery_available modules are captured.
1712 if archType == "arm64" {
1713 binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1714 binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
1715 checkSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
1716 checkSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
1717 jsonFiles = append(jsonFiles,
1718 filepath.Join(binaryDir, "recovery_bin.json"),
1719 filepath.Join(binaryDir, "recovery_available_bin.json"))
1720 }
1721
1722 // For header libraries, all vendor:true and vendor_available modules are captured.
1723 headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
1724 jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
1725
1726 // For object modules, all vendor:true and vendor_available modules are captured.
1727 objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
1728 objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
1729 checkSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
1730 jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
1731 }
1732
1733 for _, jsonFile := range jsonFiles {
1734 // verify all json files exist
1735 if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
1736 t.Errorf("%q expected but not found", jsonFile)
1737 }
1738 }
1739}
1740
Jooyung Hana70f0672019-01-18 15:20:43 +09001741func TestDoubleLoadableDepError(t *testing.T) {
1742 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1743 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1744 cc_library {
1745 name: "libllndk",
1746 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001747 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001748 }
1749
1750 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001751 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001752 symbol_file: "",
1753 }
1754
1755 cc_library {
1756 name: "libnondoubleloadable",
1757 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001758 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001759 vndk: {
1760 enabled: true,
1761 },
1762 }
1763 `)
1764
1765 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1766 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1767 cc_library {
1768 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001769 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001770 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001771 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001772 }
1773
1774 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001775 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001776 symbol_file: "",
1777 }
1778
1779 cc_library {
1780 name: "libnondoubleloadable",
1781 vendor_available: true,
1782 }
1783 `)
1784
1785 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
1786 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1787 cc_library {
1788 name: "libdoubleloadable",
1789 vendor_available: true,
1790 double_loadable: true,
1791 shared_libs: ["libnondoubleloadable"],
1792 }
1793
1794 cc_library {
1795 name: "libnondoubleloadable",
1796 vendor_available: true,
1797 }
1798 `)
1799
1800 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
1801 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1802 cc_library {
1803 name: "libdoubleloadable",
1804 vendor_available: true,
1805 double_loadable: true,
1806 shared_libs: ["libnondoubleloadable"],
1807 }
1808
1809 cc_library {
1810 name: "libnondoubleloadable",
1811 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001812 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001813 vndk: {
1814 enabled: true,
1815 },
1816 }
1817 `)
1818
1819 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
1820 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1821 cc_library {
1822 name: "libdoubleloadable",
1823 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001824 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001825 vndk: {
1826 enabled: true,
1827 },
1828 double_loadable: true,
1829 shared_libs: ["libnondoubleloadable"],
1830 }
1831
1832 cc_library {
1833 name: "libnondoubleloadable",
1834 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09001835 product_available: false,
Jooyung Hana70f0672019-01-18 15:20:43 +09001836 vndk: {
1837 enabled: true,
1838 },
1839 }
1840 `)
1841
1842 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1843 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1844 cc_library {
1845 name: "libllndk",
1846 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001847 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001848 }
1849
1850 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001851 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001852 symbol_file: "",
1853 }
1854
1855 cc_library {
1856 name: "libcoreonly",
1857 shared_libs: ["libvendoravailable"],
1858 }
1859
1860 // indirect dependency of LLNDK
1861 cc_library {
1862 name: "libvendoravailable",
1863 vendor_available: true,
1864 }
1865 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001866}
1867
Jooyung Han479ca172020-10-19 18:51:07 +09001868func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1869 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1870 cc_library {
1871 name: "libvndksp",
1872 shared_libs: ["libanothervndksp"],
1873 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001874 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001875 vndk: {
1876 enabled: true,
1877 support_system_process: true,
1878 }
1879 }
1880
1881 cc_library {
1882 name: "libllndk",
1883 shared_libs: ["libanothervndksp"],
1884 }
1885
1886 llndk_library {
1887 name: "libllndk",
1888 symbol_file: "",
1889 }
1890
1891 cc_library {
1892 name: "libanothervndksp",
1893 vendor_available: true,
1894 }
1895 `)
1896}
1897
Logan Chienf3511742017-10-31 18:04:35 +08001898func TestVndkExt(t *testing.T) {
1899 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001900 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001901 cc_library {
1902 name: "libvndk",
1903 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001904 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001905 vndk: {
1906 enabled: true,
1907 },
1908 nocrt: true,
1909 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001910 cc_library {
1911 name: "libvndk2",
1912 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001913 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001914 vndk: {
1915 enabled: true,
1916 },
1917 target: {
1918 vendor: {
1919 suffix: "-suffix",
1920 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001921 product: {
1922 suffix: "-suffix",
1923 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001924 },
1925 nocrt: true,
1926 }
Logan Chienf3511742017-10-31 18:04:35 +08001927
1928 cc_library {
1929 name: "libvndk_ext",
1930 vendor: true,
1931 vndk: {
1932 enabled: true,
1933 extends: "libvndk",
1934 },
1935 nocrt: true,
1936 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001937
1938 cc_library {
1939 name: "libvndk2_ext",
1940 vendor: true,
1941 vndk: {
1942 enabled: true,
1943 extends: "libvndk2",
1944 },
1945 nocrt: true,
1946 }
Logan Chienf3511742017-10-31 18:04:35 +08001947
Justin Yun0ecf0b22020-02-28 15:07:59 +09001948 cc_library {
1949 name: "libvndk_ext_product",
1950 product_specific: true,
1951 vndk: {
1952 enabled: true,
1953 extends: "libvndk",
1954 },
1955 nocrt: true,
1956 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001957
Justin Yun0ecf0b22020-02-28 15:07:59 +09001958 cc_library {
1959 name: "libvndk2_ext_product",
1960 product_specific: true,
1961 vndk: {
1962 enabled: true,
1963 extends: "libvndk2",
1964 },
1965 nocrt: true,
1966 }
1967 `
1968 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1969 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1970 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1971 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1972
1973 ctx := testCcWithConfig(t, config)
1974
1975 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1976 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1977
1978 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1979 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1980
1981 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1982 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001983}
1984
Logan Chiend3c59a22018-03-29 14:08:15 +08001985func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001986 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1987 ctx := testCcNoVndk(t, `
1988 cc_library {
1989 name: "libvndk",
1990 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001991 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001992 vndk: {
1993 enabled: true,
1994 },
1995 nocrt: true,
1996 }
1997
1998 cc_library {
1999 name: "libvndk_ext",
2000 vendor: true,
2001 vndk: {
2002 enabled: true,
2003 extends: "libvndk",
2004 },
2005 nocrt: true,
2006 }
2007 `)
2008
2009 // Ensures that the core variant of "libvndk_ext" can be found.
2010 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
2011 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2012 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
2013 }
2014}
2015
Justin Yun0ecf0b22020-02-28 15:07:59 +09002016func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
2017 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
2018 ctx := testCc(t, `
2019 cc_library {
2020 name: "libvndk",
2021 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002022 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002023 vndk: {
2024 enabled: true,
2025 },
2026 nocrt: true,
2027 }
2028
2029 cc_library {
2030 name: "libvndk_ext_product",
2031 product_specific: true,
2032 vndk: {
2033 enabled: true,
2034 extends: "libvndk",
2035 },
2036 nocrt: true,
2037 }
2038 `)
2039
2040 // Ensures that the core variant of "libvndk_ext_product" can be found.
2041 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
2042 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
2043 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
2044 }
2045}
2046
Logan Chienf3511742017-10-31 18:04:35 +08002047func TestVndkExtError(t *testing.T) {
2048 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09002049 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08002050 cc_library {
2051 name: "libvndk",
2052 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002053 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002054 vndk: {
2055 enabled: true,
2056 },
2057 nocrt: true,
2058 }
2059
2060 cc_library {
2061 name: "libvndk_ext",
2062 vndk: {
2063 enabled: true,
2064 extends: "libvndk",
2065 },
2066 nocrt: true,
2067 }
2068 `)
2069
2070 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2071 cc_library {
2072 name: "libvndk",
2073 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002074 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002075 vndk: {
2076 enabled: true,
2077 },
2078 nocrt: true,
2079 }
2080
2081 cc_library {
2082 name: "libvndk_ext",
2083 vendor: true,
2084 vndk: {
2085 enabled: true,
2086 },
2087 nocrt: true,
2088 }
2089 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002090
2091 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
2092 cc_library {
2093 name: "libvndk",
2094 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002095 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002096 vndk: {
2097 enabled: true,
2098 },
2099 nocrt: true,
2100 }
2101
2102 cc_library {
2103 name: "libvndk_ext_product",
2104 product_specific: true,
2105 vndk: {
2106 enabled: true,
2107 },
2108 nocrt: true,
2109 }
2110 `)
2111
2112 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
2113 cc_library {
2114 name: "libvndk",
2115 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002116 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002117 vndk: {
2118 enabled: true,
2119 },
2120 nocrt: true,
2121 }
2122
2123 cc_library {
2124 name: "libvndk_ext_product",
2125 product_specific: true,
2126 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002127 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002128 vndk: {
2129 enabled: true,
2130 extends: "libvndk",
2131 },
2132 nocrt: true,
2133 }
2134 `)
Logan Chienf3511742017-10-31 18:04:35 +08002135}
2136
2137func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
2138 // This test ensures an error is emitted for inconsistent support_system_process.
2139 testCcError(t, "module \".*\" with mismatched support_system_process", `
2140 cc_library {
2141 name: "libvndk",
2142 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002143 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002144 vndk: {
2145 enabled: true,
2146 },
2147 nocrt: true,
2148 }
2149
2150 cc_library {
2151 name: "libvndk_sp_ext",
2152 vendor: true,
2153 vndk: {
2154 enabled: true,
2155 extends: "libvndk",
2156 support_system_process: true,
2157 },
2158 nocrt: true,
2159 }
2160 `)
2161
2162 testCcError(t, "module \".*\" with mismatched support_system_process", `
2163 cc_library {
2164 name: "libvndk_sp",
2165 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002166 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002167 vndk: {
2168 enabled: true,
2169 support_system_process: true,
2170 },
2171 nocrt: true,
2172 }
2173
2174 cc_library {
2175 name: "libvndk_ext",
2176 vendor: true,
2177 vndk: {
2178 enabled: true,
2179 extends: "libvndk_sp",
2180 },
2181 nocrt: true,
2182 }
2183 `)
2184}
2185
2186func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08002187 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08002188 // with `vendor_available: false`.
2189 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
2190 cc_library {
2191 name: "libvndk",
2192 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002193 product_available: false,
Logan Chienf3511742017-10-31 18:04:35 +08002194 vndk: {
2195 enabled: true,
2196 },
2197 nocrt: true,
2198 }
2199
2200 cc_library {
2201 name: "libvndk_ext",
2202 vendor: true,
2203 vndk: {
2204 enabled: true,
2205 extends: "libvndk",
2206 },
2207 nocrt: true,
2208 }
2209 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09002210
2211 testCcErrorProductVndk(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
2212 cc_library {
2213 name: "libvndk",
2214 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002215 product_available: false,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002216 vndk: {
2217 enabled: true,
2218 },
2219 nocrt: true,
2220 }
2221
2222 cc_library {
2223 name: "libvndk_ext_product",
2224 product_specific: true,
2225 vndk: {
2226 enabled: true,
2227 extends: "libvndk",
2228 },
2229 nocrt: true,
2230 }
2231 `)
Logan Chienf3511742017-10-31 18:04:35 +08002232}
2233
Logan Chiend3c59a22018-03-29 14:08:15 +08002234func TestVendorModuleUseVndkExt(t *testing.T) {
2235 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002236 testCc(t, `
2237 cc_library {
2238 name: "libvndk",
2239 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002240 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002241 vndk: {
2242 enabled: true,
2243 },
2244 nocrt: true,
2245 }
2246
2247 cc_library {
2248 name: "libvndk_ext",
2249 vendor: true,
2250 vndk: {
2251 enabled: true,
2252 extends: "libvndk",
2253 },
2254 nocrt: true,
2255 }
2256
2257 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08002258 name: "libvndk_sp",
2259 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002260 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002261 vndk: {
2262 enabled: true,
2263 support_system_process: true,
2264 },
2265 nocrt: true,
2266 }
2267
2268 cc_library {
2269 name: "libvndk_sp_ext",
2270 vendor: true,
2271 vndk: {
2272 enabled: true,
2273 extends: "libvndk_sp",
2274 support_system_process: true,
2275 },
2276 nocrt: true,
2277 }
2278
2279 cc_library {
2280 name: "libvendor",
2281 vendor: true,
2282 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
2283 nocrt: true,
2284 }
2285 `)
2286}
2287
Logan Chiend3c59a22018-03-29 14:08:15 +08002288func TestVndkExtUseVendorLib(t *testing.T) {
2289 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08002290 testCc(t, `
2291 cc_library {
2292 name: "libvndk",
2293 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002294 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002295 vndk: {
2296 enabled: true,
2297 },
2298 nocrt: true,
2299 }
2300
2301 cc_library {
2302 name: "libvndk_ext",
2303 vendor: true,
2304 vndk: {
2305 enabled: true,
2306 extends: "libvndk",
2307 },
2308 shared_libs: ["libvendor"],
2309 nocrt: true,
2310 }
2311
2312 cc_library {
2313 name: "libvendor",
2314 vendor: true,
2315 nocrt: true,
2316 }
2317 `)
Logan Chienf3511742017-10-31 18:04:35 +08002318
Logan Chiend3c59a22018-03-29 14:08:15 +08002319 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
2320 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08002321 cc_library {
2322 name: "libvndk_sp",
2323 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002324 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002325 vndk: {
2326 enabled: true,
2327 support_system_process: true,
2328 },
2329 nocrt: true,
2330 }
2331
2332 cc_library {
2333 name: "libvndk_sp_ext",
2334 vendor: true,
2335 vndk: {
2336 enabled: true,
2337 extends: "libvndk_sp",
2338 support_system_process: true,
2339 },
2340 shared_libs: ["libvendor"], // Cause an error
2341 nocrt: true,
2342 }
2343
2344 cc_library {
2345 name: "libvendor",
2346 vendor: true,
2347 nocrt: true,
2348 }
2349 `)
2350}
2351
Justin Yun0ecf0b22020-02-28 15:07:59 +09002352func TestProductVndkExtDependency(t *testing.T) {
2353 bp := `
2354 cc_library {
2355 name: "libvndk",
2356 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002357 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002358 vndk: {
2359 enabled: true,
2360 },
2361 nocrt: true,
2362 }
2363
2364 cc_library {
2365 name: "libvndk_ext_product",
2366 product_specific: true,
2367 vndk: {
2368 enabled: true,
2369 extends: "libvndk",
2370 },
2371 shared_libs: ["libproduct_for_vndklibs"],
2372 nocrt: true,
2373 }
2374
2375 cc_library {
2376 name: "libvndk_sp",
2377 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002378 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09002379 vndk: {
2380 enabled: true,
2381 support_system_process: true,
2382 },
2383 nocrt: true,
2384 }
2385
2386 cc_library {
2387 name: "libvndk_sp_ext_product",
2388 product_specific: true,
2389 vndk: {
2390 enabled: true,
2391 extends: "libvndk_sp",
2392 support_system_process: true,
2393 },
2394 shared_libs: ["libproduct_for_vndklibs"],
2395 nocrt: true,
2396 }
2397
2398 cc_library {
2399 name: "libproduct",
2400 product_specific: true,
2401 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
2402 nocrt: true,
2403 }
2404
2405 cc_library {
2406 name: "libproduct_for_vndklibs",
2407 product_specific: true,
2408 nocrt: true,
2409 }
2410 `
2411 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2412 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2413 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2414 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2415
2416 testCcWithConfig(t, config)
2417}
2418
Logan Chiend3c59a22018-03-29 14:08:15 +08002419func TestVndkSpExtUseVndkError(t *testing.T) {
2420 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
2421 // library.
2422 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2423 cc_library {
2424 name: "libvndk",
2425 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002426 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002427 vndk: {
2428 enabled: true,
2429 },
2430 nocrt: true,
2431 }
2432
2433 cc_library {
2434 name: "libvndk_sp",
2435 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002436 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002437 vndk: {
2438 enabled: true,
2439 support_system_process: true,
2440 },
2441 nocrt: true,
2442 }
2443
2444 cc_library {
2445 name: "libvndk_sp_ext",
2446 vendor: true,
2447 vndk: {
2448 enabled: true,
2449 extends: "libvndk_sp",
2450 support_system_process: true,
2451 },
2452 shared_libs: ["libvndk"], // Cause an error
2453 nocrt: true,
2454 }
2455 `)
2456
2457 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
2458 // library.
2459 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
2460 cc_library {
2461 name: "libvndk",
2462 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002463 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002464 vndk: {
2465 enabled: true,
2466 },
2467 nocrt: true,
2468 }
2469
2470 cc_library {
2471 name: "libvndk_ext",
2472 vendor: true,
2473 vndk: {
2474 enabled: true,
2475 extends: "libvndk",
2476 },
2477 nocrt: true,
2478 }
2479
2480 cc_library {
2481 name: "libvndk_sp",
2482 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002483 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08002484 vndk: {
2485 enabled: true,
2486 support_system_process: true,
2487 },
2488 nocrt: true,
2489 }
2490
2491 cc_library {
2492 name: "libvndk_sp_ext",
2493 vendor: true,
2494 vndk: {
2495 enabled: true,
2496 extends: "libvndk_sp",
2497 support_system_process: true,
2498 },
2499 shared_libs: ["libvndk_ext"], // Cause an error
2500 nocrt: true,
2501 }
2502 `)
2503}
2504
2505func TestVndkUseVndkExtError(t *testing.T) {
2506 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2507 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002508 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2509 cc_library {
2510 name: "libvndk",
2511 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002512 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002513 vndk: {
2514 enabled: true,
2515 },
2516 nocrt: true,
2517 }
2518
2519 cc_library {
2520 name: "libvndk_ext",
2521 vendor: true,
2522 vndk: {
2523 enabled: true,
2524 extends: "libvndk",
2525 },
2526 nocrt: true,
2527 }
2528
2529 cc_library {
2530 name: "libvndk2",
2531 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002532 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002533 vndk: {
2534 enabled: true,
2535 },
2536 shared_libs: ["libvndk_ext"],
2537 nocrt: true,
2538 }
2539 `)
2540
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002541 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002542 cc_library {
2543 name: "libvndk",
2544 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002545 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002546 vndk: {
2547 enabled: true,
2548 },
2549 nocrt: true,
2550 }
2551
2552 cc_library {
2553 name: "libvndk_ext",
2554 vendor: true,
2555 vndk: {
2556 enabled: true,
2557 extends: "libvndk",
2558 },
2559 nocrt: true,
2560 }
2561
2562 cc_library {
2563 name: "libvndk2",
2564 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002565 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002566 vndk: {
2567 enabled: true,
2568 },
2569 target: {
2570 vendor: {
2571 shared_libs: ["libvndk_ext"],
2572 },
2573 },
2574 nocrt: true,
2575 }
2576 `)
2577
2578 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2579 cc_library {
2580 name: "libvndk_sp",
2581 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002582 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002583 vndk: {
2584 enabled: true,
2585 support_system_process: true,
2586 },
2587 nocrt: true,
2588 }
2589
2590 cc_library {
2591 name: "libvndk_sp_ext",
2592 vendor: true,
2593 vndk: {
2594 enabled: true,
2595 extends: "libvndk_sp",
2596 support_system_process: true,
2597 },
2598 nocrt: true,
2599 }
2600
2601 cc_library {
2602 name: "libvndk_sp_2",
2603 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002604 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002605 vndk: {
2606 enabled: true,
2607 support_system_process: true,
2608 },
2609 shared_libs: ["libvndk_sp_ext"],
2610 nocrt: true,
2611 }
2612 `)
2613
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002614 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002615 cc_library {
2616 name: "libvndk_sp",
2617 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002618 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002619 vndk: {
2620 enabled: true,
2621 },
2622 nocrt: true,
2623 }
2624
2625 cc_library {
2626 name: "libvndk_sp_ext",
2627 vendor: true,
2628 vndk: {
2629 enabled: true,
2630 extends: "libvndk_sp",
2631 },
2632 nocrt: true,
2633 }
2634
2635 cc_library {
2636 name: "libvndk_sp2",
2637 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002638 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002639 vndk: {
2640 enabled: true,
2641 },
2642 target: {
2643 vendor: {
2644 shared_libs: ["libvndk_sp_ext"],
2645 },
2646 },
2647 nocrt: true,
2648 }
2649 `)
2650}
2651
Justin Yun5f7f7e82019-11-18 19:52:14 +09002652func TestEnforceProductVndkVersion(t *testing.T) {
2653 bp := `
2654 cc_library {
2655 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002656 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002657 }
2658 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002659 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002660 symbol_file: "",
2661 }
2662 cc_library {
2663 name: "libvndk",
2664 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002665 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002666 vndk: {
2667 enabled: true,
2668 },
2669 nocrt: true,
2670 }
2671 cc_library {
2672 name: "libvndk_sp",
2673 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002674 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002675 vndk: {
2676 enabled: true,
2677 support_system_process: true,
2678 },
2679 nocrt: true,
2680 }
2681 cc_library {
2682 name: "libva",
2683 vendor_available: true,
2684 nocrt: true,
2685 }
2686 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002687 name: "libpa",
2688 product_available: true,
2689 nocrt: true,
2690 }
2691 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002692 name: "libproduct_va",
2693 product_specific: true,
2694 vendor_available: true,
2695 nocrt: true,
2696 }
2697 cc_library {
2698 name: "libprod",
2699 product_specific: true,
2700 shared_libs: [
2701 "libllndk",
2702 "libvndk",
2703 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002704 "libpa",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002705 "libproduct_va",
2706 ],
2707 nocrt: true,
2708 }
2709 cc_library {
2710 name: "libvendor",
2711 vendor: true,
2712 shared_libs: [
2713 "libllndk",
2714 "libvndk",
2715 "libvndk_sp",
2716 "libva",
2717 "libproduct_va",
2718 ],
2719 nocrt: true,
2720 }
2721 `
2722
2723 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2724 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2725 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2726 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2727
2728 ctx := testCcWithConfig(t, config)
2729
Jooyung Han261e1582020-10-20 18:54:21 +09002730 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2731 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002732}
2733
2734func TestEnforceProductVndkVersionErrors(t *testing.T) {
2735 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2736 cc_library {
2737 name: "libprod",
2738 product_specific: true,
2739 shared_libs: [
2740 "libvendor",
2741 ],
2742 nocrt: true,
2743 }
2744 cc_library {
2745 name: "libvendor",
2746 vendor: true,
2747 nocrt: true,
2748 }
2749 `)
2750 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2751 cc_library {
2752 name: "libprod",
2753 product_specific: true,
2754 shared_libs: [
2755 "libsystem",
2756 ],
2757 nocrt: true,
2758 }
2759 cc_library {
2760 name: "libsystem",
2761 nocrt: true,
2762 }
2763 `)
2764 testCcErrorProductVndk(t, "Vendor module that is not VNDK should not link to \".*\" which is marked as `vendor_available: false`", `
2765 cc_library {
2766 name: "libprod",
2767 product_specific: true,
2768 shared_libs: [
2769 "libvndk_private",
2770 ],
2771 nocrt: true,
2772 }
2773 cc_library {
2774 name: "libvndk_private",
2775 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002776 product_available: false,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002777 vndk: {
2778 enabled: true,
2779 },
2780 nocrt: true,
2781 }
2782 `)
2783 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2784 cc_library {
2785 name: "libprod",
2786 product_specific: true,
2787 shared_libs: [
2788 "libsystem_ext",
2789 ],
2790 nocrt: true,
2791 }
2792 cc_library {
2793 name: "libsystem_ext",
2794 system_ext_specific: true,
2795 nocrt: true,
2796 }
2797 `)
2798 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2799 cc_library {
2800 name: "libsystem",
2801 shared_libs: [
2802 "libproduct_va",
2803 ],
2804 nocrt: true,
2805 }
2806 cc_library {
2807 name: "libproduct_va",
2808 product_specific: true,
2809 vendor_available: true,
2810 nocrt: true,
2811 }
2812 `)
2813}
2814
Jooyung Han38002912019-05-16 04:01:54 +09002815func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002816 bp := `
2817 cc_library {
2818 name: "libvndk",
2819 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002820 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002821 vndk: {
2822 enabled: true,
2823 },
2824 }
2825 cc_library {
2826 name: "libvndksp",
2827 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002828 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002829 vndk: {
2830 enabled: true,
2831 support_system_process: true,
2832 },
2833 }
2834 cc_library {
2835 name: "libvndkprivate",
2836 vendor_available: false,
Justin Yun63e9ec72020-10-29 16:49:43 +09002837 product_available: false,
Colin Cross98be1bb2019-12-13 20:41:13 -08002838 vndk: {
2839 enabled: true,
2840 },
2841 }
2842 cc_library {
2843 name: "libvendor",
2844 vendor: true,
2845 }
2846 cc_library {
2847 name: "libvndkext",
2848 vendor: true,
2849 vndk: {
2850 enabled: true,
2851 extends: "libvndk",
2852 },
2853 }
2854 vndk_prebuilt_shared {
2855 name: "prevndk",
2856 version: "27",
2857 target_arch: "arm",
2858 binder32bit: true,
2859 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002860 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002861 vndk: {
2862 enabled: true,
2863 },
2864 arch: {
2865 arm: {
2866 srcs: ["liba.so"],
2867 },
2868 },
2869 }
2870 cc_library {
2871 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002872 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002873 }
2874 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002875 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002876 symbol_file: "",
2877 }
2878 cc_library {
2879 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002880 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002881 }
2882 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002883 name: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002884 vendor_available: false,
2885 symbol_file: "",
2886 }`
2887
2888 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002889 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2890 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2891 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002892 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002893
Jooyung Han0302a842019-10-30 18:43:49 +09002894 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09002895 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09002896 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09002897 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09002898 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09002899 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09002900 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09002901 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09002902
Colin Crossfb0c16e2019-11-20 17:12:35 -08002903 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002904
Jooyung Han38002912019-05-16 04:01:54 +09002905 tests := []struct {
2906 variant string
2907 name string
2908 expected string
2909 }{
2910 {vendorVariant, "libvndk", "native:vndk"},
2911 {vendorVariant, "libvndksp", "native:vndk"},
2912 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2913 {vendorVariant, "libvendor", "native:vendor"},
2914 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002915 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002916 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002917 {coreVariant, "libvndk", "native:platform"},
2918 {coreVariant, "libvndkprivate", "native:platform"},
2919 {coreVariant, "libllndk", "native:platform"},
2920 }
2921 for _, test := range tests {
2922 t.Run(test.name, func(t *testing.T) {
2923 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2924 assertString(t, module.makeLinkType, test.expected)
2925 })
2926 }
2927}
2928
Jeff Gaston294356f2017-09-27 17:05:30 -07002929var staticLinkDepOrderTestCases = []struct {
2930 // This is a string representation of a map[moduleName][]moduleDependency .
2931 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002932 inStatic string
2933
2934 // This is a string representation of a map[moduleName][]moduleDependency .
2935 // It models the dependencies declared in an Android.bp file.
2936 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002937
2938 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2939 // The keys of allOrdered specify which modules we would like to check.
2940 // The values of allOrdered specify the expected result (of the transitive closure of all
2941 // dependencies) for each module to test
2942 allOrdered string
2943
2944 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2945 // The keys of outOrdered specify which modules we would like to check.
2946 // The values of outOrdered specify the expected result (of the ordered linker command line)
2947 // for each module to test.
2948 outOrdered string
2949}{
2950 // Simple tests
2951 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002952 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002953 outOrdered: "",
2954 },
2955 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002956 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002957 outOrdered: "a:",
2958 },
2959 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002960 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002961 outOrdered: "a:b; b:",
2962 },
2963 // Tests of reordering
2964 {
2965 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002966 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002967 outOrdered: "a:b,c,d; b:d; c:d; d:",
2968 },
2969 {
2970 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002971 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002972 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2973 },
2974 {
2975 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002976 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002977 outOrdered: "a:d,b,e,c; d:b; e:c",
2978 },
2979 {
2980 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002981 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002982 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2983 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2984 },
2985 {
2986 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002987 inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002988 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2989 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2990 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002991 // shared dependencies
2992 {
2993 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2994 // So, we don't actually have to check that a shared dependency of c will change the order
2995 // of a library that depends statically on b and on c. We only need to check that if c has
2996 // a shared dependency on b, that that shows up in allOrdered.
2997 inShared: "c:b",
2998 allOrdered: "c:b",
2999 outOrdered: "c:",
3000 },
3001 {
3002 // This test doesn't actually include any shared dependencies but it's a reminder of what
3003 // the second phase of the above test would look like
3004 inStatic: "a:b,c; c:b",
3005 allOrdered: "a:c,b; c:b",
3006 outOrdered: "a:c,b; c:b",
3007 },
Jeff Gaston294356f2017-09-27 17:05:30 -07003008 // tiebreakers for when two modules specifying different orderings and there is no dependency
3009 // to dictate an order
3010 {
3011 // if the tie is between two modules at the end of a's deps, then a's order wins
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003012 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07003013 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
3014 },
3015 {
3016 // if the tie is between two modules at the start of a's deps, then c's order is used
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003017 inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e",
Jeff Gaston294356f2017-09-27 17:05:30 -07003018 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
3019 },
3020 // Tests involving duplicate dependencies
3021 {
3022 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003023 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003024 outOrdered: "a:c,b",
3025 },
3026 {
3027 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003028 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003029 outOrdered: "a:d,c,b",
3030 },
3031 // Tests to confirm the nonexistence of infinite loops.
3032 // These cases should never happen, so as long as the test terminates and the
3033 // result is deterministic then that should be fine.
3034 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003035 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003036 outOrdered: "a:a",
3037 },
3038 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003039 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07003040 allOrdered: "a:b,c; b:c,a; c:a,b",
3041 outOrdered: "a:b; b:c; c:a",
3042 },
3043 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003044 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07003045 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
3046 outOrdered: "a:c,b; b:a,c; c:b,a",
3047 },
3048}
3049
3050// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
3051func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
3052 // convert from "a:b,c; d:e" to "a:b,c;d:e"
3053 strippedText := strings.Replace(text, " ", "", -1)
3054 if len(strippedText) < 1 {
3055 return []android.Path{}, make(map[android.Path][]android.Path, 0)
3056 }
3057 allDeps = make(map[android.Path][]android.Path, 0)
3058
3059 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
3060 moduleTexts := strings.Split(strippedText, ";")
3061
3062 outputForModuleName := func(moduleName string) android.Path {
3063 return android.PathForTesting(moduleName)
3064 }
3065
3066 for _, moduleText := range moduleTexts {
3067 // convert from "a:b,c" to ["a", "b,c"]
3068 components := strings.Split(moduleText, ":")
3069 if len(components) != 2 {
3070 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
3071 }
3072 moduleName := components[0]
3073 moduleOutput := outputForModuleName(moduleName)
3074 modulesInOrder = append(modulesInOrder, moduleOutput)
3075
3076 depString := components[1]
3077 // convert from "b,c" to ["b", "c"]
3078 depNames := strings.Split(depString, ",")
3079 if len(depString) < 1 {
3080 depNames = []string{}
3081 }
3082 var deps []android.Path
3083 for _, depName := range depNames {
3084 deps = append(deps, outputForModuleName(depName))
3085 }
3086 allDeps[moduleOutput] = deps
3087 }
3088 return modulesInOrder, allDeps
3089}
3090
Jeff Gaston294356f2017-09-27 17:05:30 -07003091func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
3092 for _, moduleName := range moduleNames {
3093 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
3094 output := module.outputFile.Path()
3095 paths = append(paths, output)
3096 }
3097 return paths
3098}
3099
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003100func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07003101 ctx := testCc(t, `
3102 cc_library {
3103 name: "a",
3104 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09003105 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003106 }
3107 cc_library {
3108 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003109 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003110 }
3111 cc_library {
3112 name: "c",
3113 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003114 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003115 }
3116 cc_library {
3117 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09003118 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07003119 }
3120
3121 `)
3122
Colin Cross7113d202019-11-20 16:39:12 -08003123 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07003124 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003125 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3126 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07003127
3128 if !reflect.DeepEqual(actual, expected) {
3129 t.Errorf("staticDeps orderings were not propagated correctly"+
3130 "\nactual: %v"+
3131 "\nexpected: %v",
3132 actual,
3133 expected,
3134 )
3135 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09003136}
Jeff Gaston294356f2017-09-27 17:05:30 -07003137
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003138func TestStaticLibDepReorderingWithShared(t *testing.T) {
3139 ctx := testCc(t, `
3140 cc_library {
3141 name: "a",
3142 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09003143 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003144 }
3145 cc_library {
3146 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09003147 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003148 }
3149 cc_library {
3150 name: "c",
3151 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09003152 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003153 }
3154
3155 `)
3156
Colin Cross7113d202019-11-20 16:39:12 -08003157 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003158 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003159 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
3160 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08003161
3162 if !reflect.DeepEqual(actual, expected) {
3163 t.Errorf("staticDeps orderings did not account for shared libs"+
3164 "\nactual: %v"+
3165 "\nexpected: %v",
3166 actual,
3167 expected,
3168 )
3169 }
3170}
3171
Jooyung Hanb04a4992020-03-13 18:57:35 +09003172func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07003173 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09003174 if !reflect.DeepEqual(actual, expected) {
3175 t.Errorf(message+
3176 "\nactual: %v"+
3177 "\nexpected: %v",
3178 actual,
3179 expected,
3180 )
3181 }
3182}
3183
Jooyung Han61b66e92020-03-21 14:21:46 +00003184func TestLlndkLibrary(t *testing.T) {
3185 ctx := testCc(t, `
3186 cc_library {
3187 name: "libllndk",
3188 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07003189 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003190 }
3191 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003192 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00003193 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003194
3195 cc_prebuilt_library_shared {
3196 name: "libllndkprebuilt",
3197 stubs: { versions: ["1", "2"] },
3198 llndk_stubs: "libllndkprebuilt.llndk",
3199 }
3200 llndk_library {
3201 name: "libllndkprebuilt.llndk",
3202 }
3203
3204 cc_library {
3205 name: "libllndk_with_external_headers",
3206 stubs: { versions: ["1", "2"] },
3207 llndk_stubs: "libllndk_with_external_headers.llndk",
3208 header_libs: ["libexternal_headers"],
3209 export_header_lib_headers: ["libexternal_headers"],
3210 }
3211 llndk_library {
3212 name: "libllndk_with_external_headers.llndk",
3213 }
3214 cc_library_headers {
3215 name: "libexternal_headers",
3216 export_include_dirs: ["include"],
3217 vendor_available: true,
3218 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003219 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08003220 actual := ctx.ModuleVariantsForTests("libllndk")
3221 for i := 0; i < len(actual); i++ {
3222 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
3223 actual = append(actual[:i], actual[i+1:]...)
3224 i--
3225 }
3226 }
Jooyung Han61b66e92020-03-21 14:21:46 +00003227 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00003228 "android_vendor.VER_arm64_armv8-a_shared_1",
3229 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003230 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003231 "android_vendor.VER_arm_armv7-a-neon_shared_1",
3232 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07003233 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00003234 }
3235 checkEquals(t, "variants for llndk stubs", expected, actual)
3236
Colin Cross127bb8b2020-12-16 16:46:01 -08003237 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003238 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
3239
Colin Cross127bb8b2020-12-16 16:46:01 -08003240 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00003241 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
3242}
3243
Jiyong Parka46a4d52017-12-14 19:54:34 +09003244func TestLlndkHeaders(t *testing.T) {
3245 ctx := testCc(t, `
3246 llndk_headers {
3247 name: "libllndk_headers",
3248 export_include_dirs: ["my_include"],
3249 }
3250 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07003251 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09003252 export_llndk_headers: ["libllndk_headers"],
3253 }
3254 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07003255 name: "libllndk",
3256 llndk_stubs: "libllndk.llndk",
3257 }
3258
3259 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09003260 name: "libvendor",
3261 shared_libs: ["libllndk"],
3262 vendor: true,
3263 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003264 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08003265 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09003266 }
3267 `)
3268
3269 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08003270 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09003271 cflags := cc.Args["cFlags"]
3272 if !strings.Contains(cflags, "-Imy_include") {
3273 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
3274 }
3275}
3276
Logan Chien43d34c32017-12-20 01:17:32 +08003277func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
3278 actual := module.Properties.AndroidMkRuntimeLibs
3279 if !reflect.DeepEqual(actual, expected) {
3280 t.Errorf("incorrect runtime_libs for shared libs"+
3281 "\nactual: %v"+
3282 "\nexpected: %v",
3283 actual,
3284 expected,
3285 )
3286 }
3287}
3288
3289const runtimeLibAndroidBp = `
3290 cc_library {
3291 name: "libvendor_available1",
3292 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003293 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003294 nocrt : true,
3295 system_shared_libs : [],
3296 }
3297 cc_library {
3298 name: "libvendor_available2",
3299 vendor_available: true,
3300 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003301 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003302 nocrt : true,
3303 system_shared_libs : [],
3304 }
3305 cc_library {
3306 name: "libvendor_available3",
3307 vendor_available: true,
3308 runtime_libs: ["libvendor_available1"],
3309 target: {
3310 vendor: {
3311 exclude_runtime_libs: ["libvendor_available1"],
3312 }
3313 },
Yi Konge7fe9912019-06-02 00:53:50 -07003314 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003315 nocrt : true,
3316 system_shared_libs : [],
3317 }
3318 cc_library {
3319 name: "libcore",
3320 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003321 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003322 nocrt : true,
3323 system_shared_libs : [],
3324 }
3325 cc_library {
3326 name: "libvendor1",
3327 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003328 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003329 nocrt : true,
3330 system_shared_libs : [],
3331 }
3332 cc_library {
3333 name: "libvendor2",
3334 vendor: true,
3335 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07003336 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003337 nocrt : true,
3338 system_shared_libs : [],
3339 }
3340`
3341
3342func TestRuntimeLibs(t *testing.T) {
3343 ctx := testCc(t, runtimeLibAndroidBp)
3344
3345 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003346 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003347
3348 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3349 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3350
3351 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
3352 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3353
3354 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3355 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08003356 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003357
3358 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3359 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
3360
3361 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
3362 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
3363}
3364
3365func TestExcludeRuntimeLibs(t *testing.T) {
3366 ctx := testCc(t, runtimeLibAndroidBp)
3367
Colin Cross7113d202019-11-20 16:39:12 -08003368 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003369 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
3370 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3371
Colin Crossfb0c16e2019-11-20 17:12:35 -08003372 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003373 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
3374 checkRuntimeLibs(t, nil, module)
3375}
3376
3377func TestRuntimeLibsNoVndk(t *testing.T) {
3378 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3379
3380 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3381
Colin Cross7113d202019-11-20 16:39:12 -08003382 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003383
3384 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3385 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
3386
3387 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
3388 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
3389}
3390
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003391func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003392 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003393 actual := module.Properties.AndroidMkStaticLibs
3394 if !reflect.DeepEqual(actual, expected) {
3395 t.Errorf("incorrect static_libs"+
3396 "\nactual: %v"+
3397 "\nexpected: %v",
3398 actual,
3399 expected,
3400 )
3401 }
3402}
3403
3404const staticLibAndroidBp = `
3405 cc_library {
3406 name: "lib1",
3407 }
3408 cc_library {
3409 name: "lib2",
3410 static_libs: ["lib1"],
3411 }
3412`
3413
3414func TestStaticLibDepExport(t *testing.T) {
3415 ctx := testCc(t, staticLibAndroidBp)
3416
3417 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003418 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003419 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003420 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003421
3422 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003423 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003424 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3425 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08003426 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003427}
3428
Jiyong Parkd08b6972017-09-26 10:50:54 +09003429var compilerFlagsTestCases = []struct {
3430 in string
3431 out bool
3432}{
3433 {
3434 in: "a",
3435 out: false,
3436 },
3437 {
3438 in: "-a",
3439 out: true,
3440 },
3441 {
3442 in: "-Ipath/to/something",
3443 out: false,
3444 },
3445 {
3446 in: "-isystempath/to/something",
3447 out: false,
3448 },
3449 {
3450 in: "--coverage",
3451 out: false,
3452 },
3453 {
3454 in: "-include a/b",
3455 out: true,
3456 },
3457 {
3458 in: "-include a/b c/d",
3459 out: false,
3460 },
3461 {
3462 in: "-DMACRO",
3463 out: true,
3464 },
3465 {
3466 in: "-DMAC RO",
3467 out: false,
3468 },
3469 {
3470 in: "-a -b",
3471 out: false,
3472 },
3473 {
3474 in: "-DMACRO=definition",
3475 out: true,
3476 },
3477 {
3478 in: "-DMACRO=defi nition",
3479 out: true, // TODO(jiyong): this should be false
3480 },
3481 {
3482 in: "-DMACRO(x)=x + 1",
3483 out: true,
3484 },
3485 {
3486 in: "-DMACRO=\"defi nition\"",
3487 out: true,
3488 },
3489}
3490
3491type mockContext struct {
3492 BaseModuleContext
3493 result bool
3494}
3495
3496func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3497 // CheckBadCompilerFlags calls this function when the flag should be rejected
3498 ctx.result = false
3499}
3500
3501func TestCompilerFlags(t *testing.T) {
3502 for _, testCase := range compilerFlagsTestCases {
3503 ctx := &mockContext{result: true}
3504 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3505 if ctx.result != testCase.out {
3506 t.Errorf("incorrect output:")
3507 t.Errorf(" input: %#v", testCase.in)
3508 t.Errorf(" expected: %#v", testCase.out)
3509 t.Errorf(" got: %#v", ctx.result)
3510 }
3511 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003512}
Jiyong Park374510b2018-03-19 18:23:01 +09003513
3514func TestVendorPublicLibraries(t *testing.T) {
3515 ctx := testCc(t, `
3516 cc_library_headers {
3517 name: "libvendorpublic_headers",
3518 export_include_dirs: ["my_include"],
3519 }
3520 vendor_public_library {
3521 name: "libvendorpublic",
3522 symbol_file: "",
3523 export_public_headers: ["libvendorpublic_headers"],
3524 }
3525 cc_library {
3526 name: "libvendorpublic",
3527 srcs: ["foo.c"],
3528 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003529 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003530 nocrt: true,
3531 }
3532
3533 cc_library {
3534 name: "libsystem",
3535 shared_libs: ["libvendorpublic"],
3536 vendor: false,
3537 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003538 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003539 nocrt: true,
3540 }
3541 cc_library {
3542 name: "libvendor",
3543 shared_libs: ["libvendorpublic"],
3544 vendor: true,
3545 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003546 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003547 nocrt: true,
3548 }
3549 `)
3550
Colin Cross7113d202019-11-20 16:39:12 -08003551 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003552 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003553
3554 // test if header search paths are correctly added
3555 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003556 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003557 cflags := cc.Args["cFlags"]
3558 if !strings.Contains(cflags, "-Imy_include") {
3559 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3560 }
3561
3562 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003563 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003564 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003565 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003566 if !strings.Contains(libflags, stubPaths[0].String()) {
3567 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3568 }
3569
3570 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003571 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003572 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003573 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003574 if !strings.Contains(libflags, stubPaths[0].String()) {
3575 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3576 }
3577
3578}
Jiyong Park37b25202018-07-11 10:49:27 +09003579
3580func TestRecovery(t *testing.T) {
3581 ctx := testCc(t, `
3582 cc_library_shared {
3583 name: "librecovery",
3584 recovery: true,
3585 }
3586 cc_library_shared {
3587 name: "librecovery32",
3588 recovery: true,
3589 compile_multilib:"32",
3590 }
Jiyong Park5baac542018-08-28 09:55:37 +09003591 cc_library_shared {
3592 name: "libHalInRecovery",
3593 recovery_available: true,
3594 vendor: true,
3595 }
Jiyong Park37b25202018-07-11 10:49:27 +09003596 `)
3597
3598 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003599 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003600 if len(variants) != 1 || !android.InList(arm64, variants) {
3601 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3602 }
3603
3604 variants = ctx.ModuleVariantsForTests("librecovery32")
3605 if android.InList(arm64, variants) {
3606 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3607 }
Jiyong Park5baac542018-08-28 09:55:37 +09003608
3609 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3610 if !recoveryModule.Platform() {
3611 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3612 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003613}
Jiyong Park5baac542018-08-28 09:55:37 +09003614
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003615func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3616 bp := `
3617 cc_prebuilt_test_library_shared {
3618 name: "test_lib",
3619 relative_install_path: "foo/bar/baz",
3620 srcs: ["srcpath/dontusethispath/baz.so"],
3621 }
3622
3623 cc_test {
3624 name: "main_test",
3625 data_libs: ["test_lib"],
3626 gtest: false,
3627 }
3628 `
3629
3630 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3631 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3632 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3633 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3634
3635 ctx := testCcWithConfig(t, config)
3636 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3637 testBinary := module.(*Module).linker.(*testBinary)
3638 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3639 if err != nil {
3640 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3641 }
3642 if len(outputFiles) != 1 {
3643 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3644 }
3645 if len(testBinary.dataPaths()) != 1 {
3646 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3647 }
3648
3649 outputPath := outputFiles[0].String()
3650
3651 if !strings.HasSuffix(outputPath, "/main_test") {
3652 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3653 }
3654 entries := android.AndroidMkEntriesForTest(t, config, "", module)[0]
3655 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3656 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3657 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3658 }
3659}
3660
Jiyong Park7ed9de32018-10-15 22:25:07 +09003661func TestVersionedStubs(t *testing.T) {
3662 ctx := testCc(t, `
3663 cc_library_shared {
3664 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003665 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003666 stubs: {
3667 symbol_file: "foo.map.txt",
3668 versions: ["1", "2", "3"],
3669 },
3670 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003671
Jiyong Park7ed9de32018-10-15 22:25:07 +09003672 cc_library_shared {
3673 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003674 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003675 shared_libs: ["libFoo#1"],
3676 }`)
3677
3678 variants := ctx.ModuleVariantsForTests("libFoo")
3679 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003680 "android_arm64_armv8-a_shared",
3681 "android_arm64_armv8-a_shared_1",
3682 "android_arm64_armv8-a_shared_2",
3683 "android_arm64_armv8-a_shared_3",
3684 "android_arm_armv7-a-neon_shared",
3685 "android_arm_armv7-a-neon_shared_1",
3686 "android_arm_armv7-a-neon_shared_2",
3687 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003688 }
3689 variantsMismatch := false
3690 if len(variants) != len(expectedVariants) {
3691 variantsMismatch = true
3692 } else {
3693 for _, v := range expectedVariants {
3694 if !inList(v, variants) {
3695 variantsMismatch = false
3696 }
3697 }
3698 }
3699 if variantsMismatch {
3700 t.Errorf("variants of libFoo expected:\n")
3701 for _, v := range expectedVariants {
3702 t.Errorf("%q\n", v)
3703 }
3704 t.Errorf(", but got:\n")
3705 for _, v := range variants {
3706 t.Errorf("%q\n", v)
3707 }
3708 }
3709
Colin Cross7113d202019-11-20 16:39:12 -08003710 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003711 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003712 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003713 if !strings.Contains(libFlags, libFoo1StubPath) {
3714 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3715 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003716
Colin Cross7113d202019-11-20 16:39:12 -08003717 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003718 cFlags := libBarCompileRule.Args["cFlags"]
3719 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3720 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3721 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3722 }
Jiyong Park37b25202018-07-11 10:49:27 +09003723}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003724
Jooyung Hanb04a4992020-03-13 18:57:35 +09003725func TestVersioningMacro(t *testing.T) {
3726 for _, tc := range []struct{ moduleName, expected string }{
3727 {"libc", "__LIBC_API__"},
3728 {"libfoo", "__LIBFOO_API__"},
3729 {"libfoo@1", "__LIBFOO_1_API__"},
3730 {"libfoo-v1", "__LIBFOO_V1_API__"},
3731 {"libfoo.v1", "__LIBFOO_V1_API__"},
3732 } {
3733 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3734 }
3735}
3736
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003737func TestStaticExecutable(t *testing.T) {
3738 ctx := testCc(t, `
3739 cc_binary {
3740 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003741 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003742 static_executable: true,
3743 }`)
3744
Colin Cross7113d202019-11-20 16:39:12 -08003745 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003746 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3747 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003748 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003749 for _, lib := range systemStaticLibs {
3750 if !strings.Contains(libFlags, lib) {
3751 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3752 }
3753 }
3754 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3755 for _, lib := range systemSharedLibs {
3756 if strings.Contains(libFlags, lib) {
3757 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3758 }
3759 }
3760}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003761
3762func TestStaticDepsOrderWithStubs(t *testing.T) {
3763 ctx := testCc(t, `
3764 cc_binary {
3765 name: "mybin",
3766 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003767 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003768 static_executable: true,
3769 stl: "none",
3770 }
3771
3772 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003773 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003774 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003775 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003776 stl: "none",
3777 }
3778
3779 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003780 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003781 srcs: ["foo.c"],
3782 stl: "none",
3783 stubs: {
3784 versions: ["1"],
3785 },
3786 }`)
3787
Colin Cross0de8a1e2020-09-18 14:15:30 -07003788 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3789 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003790 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003791
3792 if !reflect.DeepEqual(actual, expected) {
3793 t.Errorf("staticDeps orderings were not propagated correctly"+
3794 "\nactual: %v"+
3795 "\nexpected: %v",
3796 actual,
3797 expected,
3798 )
3799 }
3800}
Jooyung Han38002912019-05-16 04:01:54 +09003801
Jooyung Hand48f3c32019-08-23 11:18:57 +09003802func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3803 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3804 cc_library {
3805 name: "libA",
3806 srcs: ["foo.c"],
3807 shared_libs: ["libB"],
3808 stl: "none",
3809 }
3810
3811 cc_library {
3812 name: "libB",
3813 srcs: ["foo.c"],
3814 enabled: false,
3815 stl: "none",
3816 }
3817 `)
3818}
3819
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003820// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3821// correctly.
3822func TestFuzzTarget(t *testing.T) {
3823 ctx := testCc(t, `
3824 cc_fuzz {
3825 name: "fuzz_smoke_test",
3826 srcs: ["foo.c"],
3827 }`)
3828
Paul Duffin075c4172019-12-19 19:06:13 +00003829 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003830 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3831}
3832
Jiyong Park29074592019-07-07 16:27:47 +09003833func TestAidl(t *testing.T) {
3834}
3835
Jooyung Han38002912019-05-16 04:01:54 +09003836func assertString(t *testing.T, got, expected string) {
3837 t.Helper()
3838 if got != expected {
3839 t.Errorf("expected %q got %q", expected, got)
3840 }
3841}
3842
3843func assertArrayString(t *testing.T, got, expected []string) {
3844 t.Helper()
3845 if len(got) != len(expected) {
3846 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3847 return
3848 }
3849 for i := range got {
3850 if got[i] != expected[i] {
3851 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3852 i, expected[i], expected, got[i], got)
3853 return
3854 }
3855 }
3856}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003857
Jooyung Han0302a842019-10-30 18:43:49 +09003858func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3859 t.Helper()
3860 assertArrayString(t, android.SortedStringKeys(m), expected)
3861}
3862
Colin Crosse1bb5d02019-09-24 14:55:04 -07003863func TestDefaults(t *testing.T) {
3864 ctx := testCc(t, `
3865 cc_defaults {
3866 name: "defaults",
3867 srcs: ["foo.c"],
3868 static: {
3869 srcs: ["bar.c"],
3870 },
3871 shared: {
3872 srcs: ["baz.c"],
3873 },
3874 }
3875
3876 cc_library_static {
3877 name: "libstatic",
3878 defaults: ["defaults"],
3879 }
3880
3881 cc_library_shared {
3882 name: "libshared",
3883 defaults: ["defaults"],
3884 }
3885
3886 cc_library {
3887 name: "libboth",
3888 defaults: ["defaults"],
3889 }
3890
3891 cc_binary {
3892 name: "binary",
3893 defaults: ["defaults"],
3894 }`)
3895
3896 pathsToBase := func(paths android.Paths) []string {
3897 var ret []string
3898 for _, p := range paths {
3899 ret = append(ret, p.Base())
3900 }
3901 return ret
3902 }
3903
Colin Cross7113d202019-11-20 16:39:12 -08003904 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003905 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3906 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3907 }
Colin Cross7113d202019-11-20 16:39:12 -08003908 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003909 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3910 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3911 }
Colin Cross7113d202019-11-20 16:39:12 -08003912 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003913 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3914 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3915 }
3916
Colin Cross7113d202019-11-20 16:39:12 -08003917 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003918 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3919 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3920 }
Colin Cross7113d202019-11-20 16:39:12 -08003921 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003922 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3923 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3924 }
3925}
Colin Crosseabaedd2020-02-06 17:01:55 -08003926
3927func TestProductVariableDefaults(t *testing.T) {
3928 bp := `
3929 cc_defaults {
3930 name: "libfoo_defaults",
3931 srcs: ["foo.c"],
3932 cppflags: ["-DFOO"],
3933 product_variables: {
3934 debuggable: {
3935 cppflags: ["-DBAR"],
3936 },
3937 },
3938 }
3939
3940 cc_library {
3941 name: "libfoo",
3942 defaults: ["libfoo_defaults"],
3943 }
3944 `
3945
3946 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3947 config.TestProductVariables.Debuggable = BoolPtr(true)
3948
Colin Crossae8600b2020-10-29 17:09:13 -07003949 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003950 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3951 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3952 })
Colin Crossae8600b2020-10-29 17:09:13 -07003953 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003954
3955 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3956 android.FailIfErrored(t, errs)
3957 _, errs = ctx.PrepareBuildActions(config)
3958 android.FailIfErrored(t, errs)
3959
3960 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3961 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3962 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3963 }
3964}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003965
3966func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3967 t.Parallel()
3968 bp := `
3969 cc_library_static {
3970 name: "libfoo",
3971 srcs: ["foo.c"],
3972 whole_static_libs: ["libbar"],
3973 }
3974
3975 cc_library_static {
3976 name: "libbar",
3977 whole_static_libs: ["libmissing"],
3978 }
3979 `
3980
3981 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3982 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3983
Colin Crossae8600b2020-10-29 17:09:13 -07003984 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003985 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003986 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003987
3988 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3989 android.FailIfErrored(t, errs)
3990 _, errs = ctx.PrepareBuildActions(config)
3991 android.FailIfErrored(t, errs)
3992
3993 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3994 if g, w := libbar.Rule, android.ErrorRule; g != w {
3995 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3996 }
3997
3998 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3999 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
4000 }
4001
4002 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
4003 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
4004 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
4005 }
4006
4007}
Colin Crosse9fe2942020-11-10 18:12:15 -08004008
4009func TestInstallSharedLibs(t *testing.T) {
4010 bp := `
4011 cc_binary {
4012 name: "bin",
4013 host_supported: true,
4014 shared_libs: ["libshared"],
4015 runtime_libs: ["libruntime"],
4016 srcs: [":gen"],
4017 }
4018
4019 cc_library_shared {
4020 name: "libshared",
4021 host_supported: true,
4022 shared_libs: ["libtransitive"],
4023 }
4024
4025 cc_library_shared {
4026 name: "libtransitive",
4027 host_supported: true,
4028 }
4029
4030 cc_library_shared {
4031 name: "libruntime",
4032 host_supported: true,
4033 }
4034
4035 cc_binary_host {
4036 name: "tool",
4037 srcs: ["foo.cpp"],
4038 }
4039
4040 genrule {
4041 name: "gen",
4042 tools: ["tool"],
4043 out: ["gen.cpp"],
4044 cmd: "$(location tool) $(out)",
4045 }
4046 `
4047
4048 config := TestConfig(buildDir, android.Android, nil, bp, nil)
4049 ctx := testCcWithConfig(t, config)
4050
4051 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
4052 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
4053 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
4054 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
4055 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
4056
4057 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
4058 t.Errorf("expected host bin dependency %q, got %q", w, g)
4059 }
4060
4061 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4062 t.Errorf("expected host bin dependency %q, got %q", w, g)
4063 }
4064
4065 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
4066 t.Errorf("expected host bin dependency %q, got %q", w, g)
4067 }
4068
4069 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
4070 t.Errorf("expected host bin dependency %q, got %q", w, g)
4071 }
4072
4073 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
4074 t.Errorf("expected no host bin dependency %q, got %q", w, g)
4075 }
4076
4077 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
4078 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
4079 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
4080 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
4081
4082 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
4083 t.Errorf("expected device bin dependency %q, got %q", w, g)
4084 }
4085
4086 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4087 t.Errorf("expected device bin dependency %q, got %q", w, g)
4088 }
4089
4090 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
4091 t.Errorf("expected device bin dependency %q, got %q", w, g)
4092 }
4093
4094 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
4095 t.Errorf("expected device bin dependency %q, got %q", w, g)
4096 }
4097
4098 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
4099 t.Errorf("expected no device bin dependency %q, got %q", w, g)
4100 }
4101
4102}
Jiyong Park1ad8e162020-12-01 23:40:09 +09004103
4104func TestStubsLibReexportsHeaders(t *testing.T) {
4105 ctx := testCc(t, `
4106 cc_library_shared {
4107 name: "libclient",
4108 srcs: ["foo.c"],
4109 shared_libs: ["libfoo#1"],
4110 }
4111
4112 cc_library_shared {
4113 name: "libfoo",
4114 srcs: ["foo.c"],
4115 shared_libs: ["libbar"],
4116 export_shared_lib_headers: ["libbar"],
4117 stubs: {
4118 symbol_file: "foo.map.txt",
4119 versions: ["1", "2", "3"],
4120 },
4121 }
4122
4123 cc_library_shared {
4124 name: "libbar",
4125 export_include_dirs: ["include/libbar"],
4126 srcs: ["foo.c"],
4127 }`)
4128
4129 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
4130
4131 if !strings.Contains(cFlags, "-Iinclude/libbar") {
4132 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
4133 }
4134}