blob: 4f28eaf15fbee0fe7abd1080a86220e83bcb09ea [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"
Paul Duffin3cb603e2021-02-19 13:57:10 +000023 "regexp"
Jeff Gaston294356f2017-09-27 17:05:30 -070024 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070025 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070026
27 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070028)
29
Jiyong Park6a43f042017-10-12 23:05:00 +090030var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_cc_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
Paul Duffin02a3d652021-02-24 18:51:54 +000055var ccFixtureFactory = android.NewFixtureFactory(
56 &buildDir,
57 PrepareForTestWithCcIncludeVndk,
58
59 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
60 variables.DeviceVndkVersion = StringPtr("current")
61 variables.ProductVndkVersion = StringPtr("current")
62 variables.Platform_vndk_version = StringPtr("VER")
63 }),
64)
65
66// testCcWithConfig runs tests using the ccFixtureFactory
67//
68// See testCc for an explanation as to how to stop using this deprecated method.
69//
70// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -080071func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070072 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000073 result := ccFixtureFactory.RunTestWithConfig(t, config)
74 return result.TestContext
Jiyong Park6a43f042017-10-12 23:05:00 +090075}
76
Paul Duffin02a3d652021-02-24 18:51:54 +000077// testCc runs tests using the ccFixtureFactory
78//
79// Do not add any new usages of this, instead use the ccFixtureFactory directly as it makes it much
80// easier to customize the test behavior.
81//
82// If it is necessary to customize the behavior of an existing test that uses this then please first
83// convert the test to using ccFixtureFactory first and then in a following change add the
84// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
85// that it did not change the test behavior unexpectedly.
86//
87// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080088func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080089 t.Helper()
Paul Duffin02a3d652021-02-24 18:51:54 +000090 result := ccFixtureFactory.RunTestWithBp(t, bp)
91 return result.TestContext
Logan Chienf3511742017-10-31 18:04:35 +080092}
93
Paul Duffin02a3d652021-02-24 18:51:54 +000094// testCcNoVndk runs tests using the ccFixtureFactory
95//
96// See testCc for an explanation as to how to stop using this deprecated method.
97//
98// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080099func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800100 t.Helper()
Colin Cross98be1bb2019-12-13 20:41:13 -0800101 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700102 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800103
Colin Cross98be1bb2019-12-13 20:41:13 -0800104 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800105}
106
Paul Duffin02a3d652021-02-24 18:51:54 +0000107// testCcNoProductVndk runs tests using the ccFixtureFactory
108//
109// See testCc for an explanation as to how to stop using this deprecated method.
110//
111// deprecated
Justin Yun8a2600c2020-12-07 12:44:03 +0900112func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
113 t.Helper()
114 config := TestConfig(buildDir, android.Android, nil, bp, nil)
115 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
116 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
117
118 return testCcWithConfig(t, config)
119}
120
Paul Duffin02a3d652021-02-24 18:51:54 +0000121// testCcErrorWithConfig runs tests using the ccFixtureFactory
122//
123// See testCc for an explanation as to how to stop using this deprecated method.
124//
125// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900126func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800127 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800128
Paul Duffin02a3d652021-02-24 18:51:54 +0000129 ccFixtureFactory.Extend().
130 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
131 RunTestWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800132}
133
Paul Duffin02a3d652021-02-24 18:51:54 +0000134// testCcError runs tests using the ccFixtureFactory
135//
136// See testCc for an explanation as to how to stop using this deprecated method.
137//
138// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900139func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900140 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900141 config := TestConfig(buildDir, android.Android, nil, bp, nil)
142 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
143 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
144 testCcErrorWithConfig(t, pattern, config)
145 return
146}
147
Paul Duffin02a3d652021-02-24 18:51:54 +0000148// testCcErrorProductVndk runs tests using the ccFixtureFactory
149//
150// See testCc for an explanation as to how to stop using this deprecated method.
151//
152// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900153func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900154 t.Helper()
Justin Yun5f7f7e82019-11-18 19:52:14 +0900155 config := TestConfig(buildDir, android.Android, nil, bp, nil)
156 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
157 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
158 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
159 testCcErrorWithConfig(t, pattern, config)
160 return
161}
162
Logan Chienf3511742017-10-31 18:04:35 +0800163const (
Colin Cross7113d202019-11-20 16:39:12 -0800164 coreVariant = "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800165 vendorVariant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun5f7f7e82019-11-18 19:52:14 +0900166 productVariant = "android_product.VER_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800167 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800168)
169
Doug Hornc32c6b02019-01-17 14:44:05 -0800170func TestFuchsiaDeps(t *testing.T) {
171 t.Helper()
172
173 bp := `
174 cc_library {
175 name: "libTest",
176 srcs: ["foo.c"],
177 target: {
178 fuchsia: {
179 srcs: ["bar.c"],
180 },
181 },
182 }`
183
Colin Cross98be1bb2019-12-13 20:41:13 -0800184 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
185 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800186
187 rt := false
188 fb := false
189
190 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
191 implicits := ld.Implicits
192 for _, lib := range implicits {
193 if strings.Contains(lib.Rel(), "libcompiler_rt") {
194 rt = true
195 }
196
197 if strings.Contains(lib.Rel(), "libbioniccompat") {
198 fb = true
199 }
200 }
201
202 if !rt || !fb {
203 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
204 }
205}
206
207func TestFuchsiaTargetDecl(t *testing.T) {
208 t.Helper()
209
210 bp := `
211 cc_library {
212 name: "libTest",
213 srcs: ["foo.c"],
214 target: {
215 fuchsia: {
216 srcs: ["bar.c"],
217 },
218 },
219 }`
220
Colin Cross98be1bb2019-12-13 20:41:13 -0800221 config := TestConfig(buildDir, android.Fuchsia, nil, bp, nil)
222 ctx := testCcWithConfig(t, config)
Doug Hornc32c6b02019-01-17 14:44:05 -0800223 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
224 var objs []string
225 for _, o := range ld.Inputs {
226 objs = append(objs, o.Base())
227 }
228 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
229 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
230 }
231}
232
Jiyong Park6a43f042017-10-12 23:05:00 +0900233func TestVendorSrc(t *testing.T) {
234 ctx := testCc(t, `
235 cc_library {
236 name: "libTest",
237 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700238 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800239 nocrt: true,
240 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900241 vendor_available: true,
242 target: {
243 vendor: {
244 srcs: ["bar.c"],
245 },
246 },
247 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900248 `)
249
Logan Chienf3511742017-10-31 18:04:35 +0800250 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900251 var objs []string
252 for _, o := range ld.Inputs {
253 objs = append(objs, o.Base())
254 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800255 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900256 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
257 }
258}
259
Logan Chienf3511742017-10-31 18:04:35 +0800260func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900261 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800262
Logan Chiend3c59a22018-03-29 14:08:15 +0800263 t.Helper()
264
Justin Yun0ecf0b22020-02-28 15:07:59 +0900265 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800266
267 // Check library properties.
268 lib, ok := mod.compiler.(*libraryDecorator)
269 if !ok {
270 t.Errorf("%q must have libraryDecorator", name)
271 } else if lib.baseInstaller.subDir != subDir {
272 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
273 lib.baseInstaller.subDir)
274 }
275
276 // Check VNDK properties.
277 if mod.vndkdep == nil {
278 t.Fatalf("%q must have `vndkdep`", name)
279 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700280 if !mod.IsVndk() {
281 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800282 }
283 if mod.isVndkSp() != isVndkSp {
284 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
285 }
286
287 // Check VNDK extension properties.
288 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500289 if mod.IsVndkExt() != isVndkExt {
290 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800291 }
292
293 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
294 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
295 }
296}
297
Jose Galmes0a942a02021-02-03 14:23:15 -0800298func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
Bill Peckham945441c2020-08-31 16:07:58 -0700299 t.Helper()
Jooyung Han39edb6c2019-11-06 16:53:07 +0900300 mod, ok := ctx.ModuleForTests(moduleName, variant).Module().(android.OutputFileProducer)
301 if !ok {
302 t.Errorf("%q must have output\n", moduleName)
Inseob Kim1f086e22019-05-09 13:29:15 +0900303 return
304 }
Jooyung Han39edb6c2019-11-06 16:53:07 +0900305 outputFiles, err := mod.OutputFiles("")
306 if err != nil || len(outputFiles) != 1 {
307 t.Errorf("%q must have single output\n", moduleName)
308 return
309 }
310 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900311
Bill Peckham945441c2020-08-31 16:07:58 -0700312 if include {
313 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800314 if fake {
315 if out.Rule == nil {
316 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
317 }
318 } else {
319 if out.Input.String() != outputFiles[0].String() {
320 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
321 }
Bill Peckham945441c2020-08-31 16:07:58 -0700322 }
323 } else {
324 out := singleton.MaybeOutput(snapshotPath)
325 if out.Rule != nil {
326 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
327 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900328 }
329}
330
Bill Peckham945441c2020-08-31 16:07:58 -0700331func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800332 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700333}
334
335func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Jose Galmes0a942a02021-02-03 14:23:15 -0800336 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
337}
338
339func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
340 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700341}
342
Jooyung Han2216fb12019-11-06 16:46:15 +0900343func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
344 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800345 content := android.ContentFromFileRuleForTests(t, params)
346 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900347 assertArrayString(t, actual, expected)
348}
349
Jooyung Han097087b2019-10-22 19:32:18 +0900350func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
351 t.Helper()
352 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900353 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
354}
355
356func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
357 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800358 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
359 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900360}
361
Logan Chienf3511742017-10-31 18:04:35 +0800362func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800363 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800364 cc_library {
365 name: "libvndk",
366 vendor_available: true,
367 vndk: {
368 enabled: true,
369 },
370 nocrt: true,
371 }
372
373 cc_library {
374 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900375 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800376 vndk: {
377 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900378 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800379 },
380 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900381 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800382 }
383
384 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900385 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800386 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900387 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800388 vndk: {
389 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900390 },
391 nocrt: true,
392 target: {
393 vendor: {
394 cflags: ["-DTEST"],
395 },
396 product: {
397 cflags: ["-DTEST"],
398 },
399 },
400 }
401
402 cc_library {
403 name: "libvndk_sp",
404 vendor_available: true,
405 vndk: {
406 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800407 support_system_process: true,
408 },
409 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900410 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800411 }
412
413 cc_library {
414 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900415 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800416 vndk: {
417 enabled: true,
418 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900419 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800420 },
421 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900422 target: {
423 vendor: {
424 suffix: "-x",
425 },
426 },
Logan Chienf3511742017-10-31 18:04:35 +0800427 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900428
429 cc_library {
430 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900431 vendor_available: true,
432 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900433 vndk: {
434 enabled: true,
435 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900436 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900437 },
438 nocrt: true,
439 target: {
440 vendor: {
441 suffix: "-x",
442 },
443 product: {
444 suffix: "-x",
445 },
446 },
447 }
448
Colin Crosse4e44bc2020-12-28 13:50:21 -0800449 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900450 name: "llndk.libraries.txt",
451 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800452 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900453 name: "vndkcore.libraries.txt",
454 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800455 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900456 name: "vndksp.libraries.txt",
457 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800458 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900459 name: "vndkprivate.libraries.txt",
460 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800461 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900462 name: "vndkproduct.libraries.txt",
463 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800464 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900465 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800466 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900467 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800468 `
469
470 config := TestConfig(buildDir, android.Android, nil, bp, nil)
471 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900472 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Colin Cross98be1bb2019-12-13 20:41:13 -0800473 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
474
475 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800476
Jooyung Han261e1582020-10-20 18:54:21 +0900477 // subdir == "" because VNDK libs are not supposed to be installed separately.
478 // They are installed as part of VNDK APEX instead.
479 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
480 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900481 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900482 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
483 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900484 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900485
Justin Yun6977e8a2020-10-29 18:24:11 +0900486 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
487 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900488
Inseob Kim1f086e22019-05-09 13:29:15 +0900489 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900490 snapshotDir := "vndk-snapshot"
491 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
492
493 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
494 "arm64", "armv8-a"))
495 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
496 "arm", "armv7-a-neon"))
497
498 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
499 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
500 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
501 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
502
Colin Crossfb0c16e2019-11-20 17:12:35 -0800503 variant := "android_vendor.VER_arm64_armv8-a_shared"
504 variant2nd := "android_vendor.VER_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900505
Inseob Kim7f283f42020-06-01 21:53:49 +0900506 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
507
508 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
509 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900510 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
511 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900512 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
513 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900514
Jooyung Han39edb6c2019-11-06 16:53:07 +0900515 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900516 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
517 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
518 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
519 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900520 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900521
Jooyung Han097087b2019-10-22 19:32:18 +0900522 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
523 "LLNDK: libc.so",
524 "LLNDK: libdl.so",
525 "LLNDK: libft2.so",
526 "LLNDK: libm.so",
527 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900528 "VNDK-SP: libvndk_sp-x.so",
529 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900530 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900531 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900532 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900533 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900534 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900535 "VNDK-private: libvndk-private.so",
536 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900537 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900538 "VNDK-product: libc++.so",
539 "VNDK-product: libvndk_product.so",
540 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900541 })
Jooyung Han2216fb12019-11-06 16:46:15 +0900542 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900543 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
544 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
545 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
Justin Yun8a2600c2020-12-07 12:44:03 +0900546 checkVndkLibrariesOutput(t, ctx, "vndkproduct.libraries.txt", []string{"libc++.so", "libvndk_product.so", "libvndk_sp_product_private-x.so"})
Jooyung Han2216fb12019-11-06 16:46:15 +0900547 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
548}
549
Yo Chiangbba545e2020-06-09 16:15:37 +0800550func TestVndkWithHostSupported(t *testing.T) {
551 ctx := testCc(t, `
552 cc_library {
553 name: "libvndk_host_supported",
554 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900555 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800556 vndk: {
557 enabled: true,
558 },
559 host_supported: true,
560 }
561
562 cc_library {
563 name: "libvndk_host_supported_but_disabled_on_device",
564 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900565 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800566 vndk: {
567 enabled: true,
568 },
569 host_supported: true,
570 enabled: false,
571 target: {
572 host: {
573 enabled: true,
574 }
575 }
576 }
577
Colin Crosse4e44bc2020-12-28 13:50:21 -0800578 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800579 name: "vndkcore.libraries.txt",
580 }
581 `)
582
583 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
584}
585
Jooyung Han2216fb12019-11-06 16:46:15 +0900586func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800587 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800588 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900589 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800590 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800591 }`
592 config := TestConfig(buildDir, android.Android, nil, bp, nil)
593 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
594 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
595 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900596
597 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Colin Crossaa255532020-07-03 13:18:24 -0700598 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jooyung Han2216fb12019-11-06 16:46:15 +0900599 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.VER.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900600}
601
602func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800603 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900604 cc_library {
605 name: "libvndk",
606 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900607 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900608 vndk: {
609 enabled: true,
610 },
611 nocrt: true,
612 }
613
614 cc_library {
615 name: "libvndk_sp",
616 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900617 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900618 vndk: {
619 enabled: true,
620 support_system_process: true,
621 },
622 nocrt: true,
623 }
624
625 cc_library {
626 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900627 vendor_available: true,
628 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900629 vndk: {
630 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900631 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900632 },
633 nocrt: true,
634 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900635
Colin Crosse4e44bc2020-12-28 13:50:21 -0800636 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900637 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800638 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900639 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800640 `
641
642 config := TestConfig(buildDir, android.Android, nil, bp, nil)
643 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
644 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
645 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
646
647 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
648
649 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900650
Jooyung Han2216fb12019-11-06 16:46:15 +0900651 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900652}
653
Chris Parsons79d66a52020-06-05 17:26:16 -0400654func TestDataLibs(t *testing.T) {
655 bp := `
656 cc_test_library {
657 name: "test_lib",
658 srcs: ["test_lib.cpp"],
659 gtest: false,
660 }
661
662 cc_test {
663 name: "main_test",
664 data_libs: ["test_lib"],
665 gtest: false,
666 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400667 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400668
669 config := TestConfig(buildDir, android.Android, nil, bp, nil)
670 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
671 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
672 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
673
674 ctx := testCcWithConfig(t, config)
675 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
676 testBinary := module.(*Module).linker.(*testBinary)
677 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
678 if err != nil {
679 t.Errorf("Expected cc_test to produce output files, error: %s", err)
680 return
681 }
682 if len(outputFiles) != 1 {
683 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
684 return
685 }
686 if len(testBinary.dataPaths()) != 1 {
687 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
688 return
689 }
690
691 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400692 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400693
694 if !strings.HasSuffix(outputPath, "/main_test") {
695 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
696 return
697 }
698 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
699 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
700 return
701 }
702}
703
Chris Parsons216e10a2020-07-09 17:12:52 -0400704func TestDataLibsRelativeInstallPath(t *testing.T) {
705 bp := `
706 cc_test_library {
707 name: "test_lib",
708 srcs: ["test_lib.cpp"],
709 relative_install_path: "foo/bar/baz",
710 gtest: false,
711 }
712
713 cc_test {
714 name: "main_test",
715 data_libs: ["test_lib"],
716 gtest: false,
717 }
718 `
719
720 config := TestConfig(buildDir, android.Android, nil, bp, nil)
721 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
722 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
723 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
724
725 ctx := testCcWithConfig(t, config)
726 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
727 testBinary := module.(*Module).linker.(*testBinary)
728 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
729 if err != nil {
730 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
731 }
732 if len(outputFiles) != 1 {
733 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
734 }
735 if len(testBinary.dataPaths()) != 1 {
736 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
737 }
738
739 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400740
741 if !strings.HasSuffix(outputPath, "/main_test") {
742 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
743 }
Colin Crossaa255532020-07-03 13:18:24 -0700744 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400745 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
746 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400747 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400748 }
749}
750
Jooyung Han0302a842019-10-30 18:43:49 +0900751func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900752 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900753 cc_library {
754 name: "libvndk",
755 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900756 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900757 vndk: {
758 enabled: true,
759 },
760 nocrt: true,
761 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900762 cc_library {
763 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900764 vendor_available: true,
765 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900766 vndk: {
767 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900768 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900769 },
770 nocrt: true,
771 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800772
773 cc_library {
774 name: "libllndk",
775 llndk_stubs: "libllndk.llndk",
776 }
777
778 llndk_library {
779 name: "libllndk.llndk",
780 symbol_file: "",
781 export_llndk_headers: ["libllndk_headers"],
782 }
783
784 llndk_headers {
785 name: "libllndk_headers",
786 export_include_dirs: ["include"],
787 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900788 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900789
790 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
791 "LLNDK: libc.so",
792 "LLNDK: libdl.so",
793 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800794 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900795 "LLNDK: libm.so",
796 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900797 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900798 "VNDK-core: libvndk.so",
799 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900800 "VNDK-private: libvndk-private.so",
801 "VNDK-product: libc++.so",
802 "VNDK-product: libvndk-private.so",
803 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900804 })
Logan Chienf3511742017-10-31 18:04:35 +0800805}
806
Justin Yun63e9ec72020-10-29 16:49:43 +0900807func TestVndkModuleError(t *testing.T) {
808 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900809 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900810 cc_library {
811 name: "libvndk",
812 vndk: {
813 enabled: true,
814 },
815 nocrt: true,
816 }
817 `)
818
Justin Yunc0d8c492021-01-07 17:45:31 +0900819 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900820 cc_library {
821 name: "libvndk",
822 product_available: true,
823 vndk: {
824 enabled: true,
825 },
826 nocrt: true,
827 }
828 `)
829
Justin Yun6977e8a2020-10-29 18:24:11 +0900830 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
831 cc_library {
832 name: "libvndkprop",
833 vendor_available: true,
834 product_available: true,
835 vndk: {
836 enabled: true,
837 },
838 nocrt: true,
839 target: {
840 vendor: {
841 cflags: ["-DTEST",],
842 },
843 },
844 }
845 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900846}
847
Logan Chiend3c59a22018-03-29 14:08:15 +0800848func TestVndkDepError(t *testing.T) {
849 // Check whether an error is emitted when a VNDK lib depends on a system lib.
850 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
851 cc_library {
852 name: "libvndk",
853 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900854 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800855 vndk: {
856 enabled: true,
857 },
858 shared_libs: ["libfwk"], // Cause error
859 nocrt: true,
860 }
861
862 cc_library {
863 name: "libfwk",
864 nocrt: true,
865 }
866 `)
867
868 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
869 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
870 cc_library {
871 name: "libvndk",
872 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900873 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800874 vndk: {
875 enabled: true,
876 },
877 shared_libs: ["libvendor"], // Cause error
878 nocrt: true,
879 }
880
881 cc_library {
882 name: "libvendor",
883 vendor: true,
884 nocrt: true,
885 }
886 `)
887
888 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
889 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
890 cc_library {
891 name: "libvndk_sp",
892 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900893 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800894 vndk: {
895 enabled: true,
896 support_system_process: true,
897 },
898 shared_libs: ["libfwk"], // Cause error
899 nocrt: true,
900 }
901
902 cc_library {
903 name: "libfwk",
904 nocrt: true,
905 }
906 `)
907
908 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
909 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
910 cc_library {
911 name: "libvndk_sp",
912 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900913 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800914 vndk: {
915 enabled: true,
916 support_system_process: true,
917 },
918 shared_libs: ["libvendor"], // Cause error
919 nocrt: true,
920 }
921
922 cc_library {
923 name: "libvendor",
924 vendor: true,
925 nocrt: true,
926 }
927 `)
928
929 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
930 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
931 cc_library {
932 name: "libvndk_sp",
933 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900934 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800935 vndk: {
936 enabled: true,
937 support_system_process: true,
938 },
939 shared_libs: ["libvndk"], // Cause error
940 nocrt: true,
941 }
942
943 cc_library {
944 name: "libvndk",
945 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900946 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800947 vndk: {
948 enabled: true,
949 },
950 nocrt: true,
951 }
952 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900953
954 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
955 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
956 cc_library {
957 name: "libvndk",
958 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900959 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900960 vndk: {
961 enabled: true,
962 },
963 shared_libs: ["libnonvndk"],
964 nocrt: true,
965 }
966
967 cc_library {
968 name: "libnonvndk",
969 vendor_available: true,
970 nocrt: true,
971 }
972 `)
973
974 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
975 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
976 cc_library {
977 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +0900978 vendor_available: true,
979 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900980 vndk: {
981 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900982 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900983 },
984 shared_libs: ["libnonvndk"],
985 nocrt: true,
986 }
987
988 cc_library {
989 name: "libnonvndk",
990 vendor_available: true,
991 nocrt: true,
992 }
993 `)
994
995 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
996 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
997 cc_library {
998 name: "libvndksp",
999 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001000 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001001 vndk: {
1002 enabled: true,
1003 support_system_process: true,
1004 },
1005 shared_libs: ["libnonvndk"],
1006 nocrt: true,
1007 }
1008
1009 cc_library {
1010 name: "libnonvndk",
1011 vendor_available: true,
1012 nocrt: true,
1013 }
1014 `)
1015
1016 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1017 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1018 cc_library {
1019 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001020 vendor_available: true,
1021 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001022 vndk: {
1023 enabled: true,
1024 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001025 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001026 },
1027 shared_libs: ["libnonvndk"],
1028 nocrt: true,
1029 }
1030
1031 cc_library {
1032 name: "libnonvndk",
1033 vendor_available: true,
1034 nocrt: true,
1035 }
1036 `)
1037}
1038
1039func TestDoubleLoadbleDep(t *testing.T) {
1040 // okay to link : LLNDK -> double_loadable VNDK
1041 testCc(t, `
1042 cc_library {
1043 name: "libllndk",
1044 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001045 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001046 }
1047
1048 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001049 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001050 symbol_file: "",
1051 }
1052
1053 cc_library {
1054 name: "libdoubleloadable",
1055 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001056 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001057 vndk: {
1058 enabled: true,
1059 },
1060 double_loadable: true,
1061 }
1062 `)
1063 // okay to link : LLNDK -> VNDK-SP
1064 testCc(t, `
1065 cc_library {
1066 name: "libllndk",
1067 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001068 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001069 }
1070
1071 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001072 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001073 symbol_file: "",
1074 }
1075
1076 cc_library {
1077 name: "libvndksp",
1078 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001079 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001080 vndk: {
1081 enabled: true,
1082 support_system_process: true,
1083 },
1084 }
1085 `)
1086 // okay to link : double_loadable -> double_loadable
1087 testCc(t, `
1088 cc_library {
1089 name: "libdoubleloadable1",
1090 shared_libs: ["libdoubleloadable2"],
1091 vendor_available: true,
1092 double_loadable: true,
1093 }
1094
1095 cc_library {
1096 name: "libdoubleloadable2",
1097 vendor_available: true,
1098 double_loadable: true,
1099 }
1100 `)
1101 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1102 testCc(t, `
1103 cc_library {
1104 name: "libdoubleloadable",
1105 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001106 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001107 vndk: {
1108 enabled: true,
1109 },
1110 double_loadable: true,
1111 shared_libs: ["libnondoubleloadable"],
1112 }
1113
1114 cc_library {
1115 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001116 vendor_available: true,
1117 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001118 vndk: {
1119 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001120 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001121 },
1122 double_loadable: true,
1123 }
1124 `)
1125 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1126 testCc(t, `
1127 cc_library {
1128 name: "libllndk",
1129 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001130 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001131 }
1132
1133 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001134 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001135 symbol_file: "",
1136 }
1137
1138 cc_library {
1139 name: "libcoreonly",
1140 shared_libs: ["libvendoravailable"],
1141 }
1142
1143 // indirect dependency of LLNDK
1144 cc_library {
1145 name: "libvendoravailable",
1146 vendor_available: true,
1147 double_loadable: true,
1148 }
1149 `)
1150}
1151
1152func TestDoubleLoadableDepError(t *testing.T) {
1153 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1154 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1155 cc_library {
1156 name: "libllndk",
1157 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001158 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001159 }
1160
1161 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001162 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001163 symbol_file: "",
1164 }
1165
1166 cc_library {
1167 name: "libnondoubleloadable",
1168 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001169 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001170 vndk: {
1171 enabled: true,
1172 },
1173 }
1174 `)
1175
1176 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1177 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1178 cc_library {
1179 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001180 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001181 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001182 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001183 }
1184
1185 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001186 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001187 symbol_file: "",
1188 }
1189
1190 cc_library {
1191 name: "libnondoubleloadable",
1192 vendor_available: true,
1193 }
1194 `)
1195
Jooyung Hana70f0672019-01-18 15:20:43 +09001196 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1197 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1198 cc_library {
1199 name: "libllndk",
1200 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001201 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001202 }
1203
1204 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001205 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001206 symbol_file: "",
1207 }
1208
1209 cc_library {
1210 name: "libcoreonly",
1211 shared_libs: ["libvendoravailable"],
1212 }
1213
1214 // indirect dependency of LLNDK
1215 cc_library {
1216 name: "libvendoravailable",
1217 vendor_available: true,
1218 }
1219 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001220
1221 // The error is not from 'client' but from 'libllndk'
1222 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1223 cc_library {
1224 name: "client",
1225 vendor_available: true,
1226 double_loadable: true,
1227 shared_libs: ["libllndk"],
1228 }
1229 cc_library {
1230 name: "libllndk",
1231 shared_libs: ["libnondoubleloadable"],
1232 llndk_stubs: "libllndk.llndk",
1233 }
1234 llndk_library {
1235 name: "libllndk.llndk",
1236 symbol_file: "",
1237 }
1238 cc_library {
1239 name: "libnondoubleloadable",
1240 vendor_available: true,
1241 }
1242 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001243}
1244
Jooyung Han479ca172020-10-19 18:51:07 +09001245func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1246 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1247 cc_library {
1248 name: "libvndksp",
1249 shared_libs: ["libanothervndksp"],
1250 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001251 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001252 vndk: {
1253 enabled: true,
1254 support_system_process: true,
1255 }
1256 }
1257
1258 cc_library {
1259 name: "libllndk",
1260 shared_libs: ["libanothervndksp"],
1261 }
1262
1263 llndk_library {
1264 name: "libllndk",
1265 symbol_file: "",
1266 }
1267
1268 cc_library {
1269 name: "libanothervndksp",
1270 vendor_available: true,
1271 }
1272 `)
1273}
1274
Logan Chienf3511742017-10-31 18:04:35 +08001275func TestVndkExt(t *testing.T) {
1276 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001277 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001278 cc_library {
1279 name: "libvndk",
1280 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001281 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001282 vndk: {
1283 enabled: true,
1284 },
1285 nocrt: true,
1286 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001287 cc_library {
1288 name: "libvndk2",
1289 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001290 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001291 vndk: {
1292 enabled: true,
1293 },
1294 target: {
1295 vendor: {
1296 suffix: "-suffix",
1297 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001298 product: {
1299 suffix: "-suffix",
1300 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001301 },
1302 nocrt: true,
1303 }
Logan Chienf3511742017-10-31 18:04:35 +08001304
1305 cc_library {
1306 name: "libvndk_ext",
1307 vendor: true,
1308 vndk: {
1309 enabled: true,
1310 extends: "libvndk",
1311 },
1312 nocrt: true,
1313 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001314
1315 cc_library {
1316 name: "libvndk2_ext",
1317 vendor: true,
1318 vndk: {
1319 enabled: true,
1320 extends: "libvndk2",
1321 },
1322 nocrt: true,
1323 }
Logan Chienf3511742017-10-31 18:04:35 +08001324
Justin Yun0ecf0b22020-02-28 15:07:59 +09001325 cc_library {
1326 name: "libvndk_ext_product",
1327 product_specific: true,
1328 vndk: {
1329 enabled: true,
1330 extends: "libvndk",
1331 },
1332 nocrt: true,
1333 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001334
Justin Yun0ecf0b22020-02-28 15:07:59 +09001335 cc_library {
1336 name: "libvndk2_ext_product",
1337 product_specific: true,
1338 vndk: {
1339 enabled: true,
1340 extends: "libvndk2",
1341 },
1342 nocrt: true,
1343 }
1344 `
1345 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1346 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1347 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1348 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1349
1350 ctx := testCcWithConfig(t, config)
1351
1352 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1353 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1354
1355 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1356 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1357
1358 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1359 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001360}
1361
Logan Chiend3c59a22018-03-29 14:08:15 +08001362func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001363 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1364 ctx := testCcNoVndk(t, `
1365 cc_library {
1366 name: "libvndk",
1367 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001368 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001369 vndk: {
1370 enabled: true,
1371 },
1372 nocrt: true,
1373 }
1374
1375 cc_library {
1376 name: "libvndk_ext",
1377 vendor: true,
1378 vndk: {
1379 enabled: true,
1380 extends: "libvndk",
1381 },
1382 nocrt: true,
1383 }
1384 `)
1385
1386 // Ensures that the core variant of "libvndk_ext" can be found.
1387 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1388 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1389 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1390 }
1391}
1392
Justin Yun0ecf0b22020-02-28 15:07:59 +09001393func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1394 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001395 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001396 cc_library {
1397 name: "libvndk",
1398 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001399 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001400 vndk: {
1401 enabled: true,
1402 },
1403 nocrt: true,
1404 }
1405
1406 cc_library {
1407 name: "libvndk_ext_product",
1408 product_specific: true,
1409 vndk: {
1410 enabled: true,
1411 extends: "libvndk",
1412 },
1413 nocrt: true,
1414 }
1415 `)
1416
1417 // Ensures that the core variant of "libvndk_ext_product" can be found.
1418 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1419 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1420 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1421 }
1422}
1423
Logan Chienf3511742017-10-31 18:04:35 +08001424func TestVndkExtError(t *testing.T) {
1425 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001426 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001427 cc_library {
1428 name: "libvndk",
1429 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001430 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001431 vndk: {
1432 enabled: true,
1433 },
1434 nocrt: true,
1435 }
1436
1437 cc_library {
1438 name: "libvndk_ext",
1439 vndk: {
1440 enabled: true,
1441 extends: "libvndk",
1442 },
1443 nocrt: true,
1444 }
1445 `)
1446
1447 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1448 cc_library {
1449 name: "libvndk",
1450 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001451 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001452 vndk: {
1453 enabled: true,
1454 },
1455 nocrt: true,
1456 }
1457
1458 cc_library {
1459 name: "libvndk_ext",
1460 vendor: true,
1461 vndk: {
1462 enabled: true,
1463 },
1464 nocrt: true,
1465 }
1466 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001467
1468 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1469 cc_library {
1470 name: "libvndk",
1471 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001472 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001473 vndk: {
1474 enabled: true,
1475 },
1476 nocrt: true,
1477 }
1478
1479 cc_library {
1480 name: "libvndk_ext_product",
1481 product_specific: true,
1482 vndk: {
1483 enabled: true,
1484 },
1485 nocrt: true,
1486 }
1487 `)
1488
1489 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1490 cc_library {
1491 name: "libvndk",
1492 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001493 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001494 vndk: {
1495 enabled: true,
1496 },
1497 nocrt: true,
1498 }
1499
1500 cc_library {
1501 name: "libvndk_ext_product",
1502 product_specific: true,
1503 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001504 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001505 vndk: {
1506 enabled: true,
1507 extends: "libvndk",
1508 },
1509 nocrt: true,
1510 }
1511 `)
Logan Chienf3511742017-10-31 18:04:35 +08001512}
1513
1514func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1515 // This test ensures an error is emitted for inconsistent support_system_process.
1516 testCcError(t, "module \".*\" with mismatched support_system_process", `
1517 cc_library {
1518 name: "libvndk",
1519 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001520 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001521 vndk: {
1522 enabled: true,
1523 },
1524 nocrt: true,
1525 }
1526
1527 cc_library {
1528 name: "libvndk_sp_ext",
1529 vendor: true,
1530 vndk: {
1531 enabled: true,
1532 extends: "libvndk",
1533 support_system_process: true,
1534 },
1535 nocrt: true,
1536 }
1537 `)
1538
1539 testCcError(t, "module \".*\" with mismatched support_system_process", `
1540 cc_library {
1541 name: "libvndk_sp",
1542 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001543 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001544 vndk: {
1545 enabled: true,
1546 support_system_process: true,
1547 },
1548 nocrt: true,
1549 }
1550
1551 cc_library {
1552 name: "libvndk_ext",
1553 vendor: true,
1554 vndk: {
1555 enabled: true,
1556 extends: "libvndk_sp",
1557 },
1558 nocrt: true,
1559 }
1560 `)
1561}
1562
1563func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001564 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001565 // with `private: true`.
1566 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001567 cc_library {
1568 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001569 vendor_available: true,
1570 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001571 vndk: {
1572 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001573 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001574 },
1575 nocrt: true,
1576 }
1577
1578 cc_library {
1579 name: "libvndk_ext",
1580 vendor: true,
1581 vndk: {
1582 enabled: true,
1583 extends: "libvndk",
1584 },
1585 nocrt: true,
1586 }
1587 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001588
Justin Yunfd9e8042020-12-23 18:23:14 +09001589 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001590 cc_library {
1591 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001592 vendor_available: true,
1593 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001594 vndk: {
1595 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001596 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001597 },
1598 nocrt: true,
1599 }
1600
1601 cc_library {
1602 name: "libvndk_ext_product",
1603 product_specific: true,
1604 vndk: {
1605 enabled: true,
1606 extends: "libvndk",
1607 },
1608 nocrt: true,
1609 }
1610 `)
Logan Chienf3511742017-10-31 18:04:35 +08001611}
1612
Logan Chiend3c59a22018-03-29 14:08:15 +08001613func TestVendorModuleUseVndkExt(t *testing.T) {
1614 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001615 testCc(t, `
1616 cc_library {
1617 name: "libvndk",
1618 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001619 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001620 vndk: {
1621 enabled: true,
1622 },
1623 nocrt: true,
1624 }
1625
1626 cc_library {
1627 name: "libvndk_ext",
1628 vendor: true,
1629 vndk: {
1630 enabled: true,
1631 extends: "libvndk",
1632 },
1633 nocrt: true,
1634 }
1635
1636 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001637 name: "libvndk_sp",
1638 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001639 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001640 vndk: {
1641 enabled: true,
1642 support_system_process: true,
1643 },
1644 nocrt: true,
1645 }
1646
1647 cc_library {
1648 name: "libvndk_sp_ext",
1649 vendor: true,
1650 vndk: {
1651 enabled: true,
1652 extends: "libvndk_sp",
1653 support_system_process: true,
1654 },
1655 nocrt: true,
1656 }
1657
1658 cc_library {
1659 name: "libvendor",
1660 vendor: true,
1661 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1662 nocrt: true,
1663 }
1664 `)
1665}
1666
Logan Chiend3c59a22018-03-29 14:08:15 +08001667func TestVndkExtUseVendorLib(t *testing.T) {
1668 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001669 testCc(t, `
1670 cc_library {
1671 name: "libvndk",
1672 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001673 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001674 vndk: {
1675 enabled: true,
1676 },
1677 nocrt: true,
1678 }
1679
1680 cc_library {
1681 name: "libvndk_ext",
1682 vendor: true,
1683 vndk: {
1684 enabled: true,
1685 extends: "libvndk",
1686 },
1687 shared_libs: ["libvendor"],
1688 nocrt: true,
1689 }
1690
1691 cc_library {
1692 name: "libvendor",
1693 vendor: true,
1694 nocrt: true,
1695 }
1696 `)
Logan Chienf3511742017-10-31 18:04:35 +08001697
Logan Chiend3c59a22018-03-29 14:08:15 +08001698 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1699 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001700 cc_library {
1701 name: "libvndk_sp",
1702 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001703 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001704 vndk: {
1705 enabled: true,
1706 support_system_process: true,
1707 },
1708 nocrt: true,
1709 }
1710
1711 cc_library {
1712 name: "libvndk_sp_ext",
1713 vendor: true,
1714 vndk: {
1715 enabled: true,
1716 extends: "libvndk_sp",
1717 support_system_process: true,
1718 },
1719 shared_libs: ["libvendor"], // Cause an error
1720 nocrt: true,
1721 }
1722
1723 cc_library {
1724 name: "libvendor",
1725 vendor: true,
1726 nocrt: true,
1727 }
1728 `)
1729}
1730
Justin Yun0ecf0b22020-02-28 15:07:59 +09001731func TestProductVndkExtDependency(t *testing.T) {
1732 bp := `
1733 cc_library {
1734 name: "libvndk",
1735 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001736 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001737 vndk: {
1738 enabled: true,
1739 },
1740 nocrt: true,
1741 }
1742
1743 cc_library {
1744 name: "libvndk_ext_product",
1745 product_specific: true,
1746 vndk: {
1747 enabled: true,
1748 extends: "libvndk",
1749 },
1750 shared_libs: ["libproduct_for_vndklibs"],
1751 nocrt: true,
1752 }
1753
1754 cc_library {
1755 name: "libvndk_sp",
1756 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001757 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001758 vndk: {
1759 enabled: true,
1760 support_system_process: true,
1761 },
1762 nocrt: true,
1763 }
1764
1765 cc_library {
1766 name: "libvndk_sp_ext_product",
1767 product_specific: true,
1768 vndk: {
1769 enabled: true,
1770 extends: "libvndk_sp",
1771 support_system_process: true,
1772 },
1773 shared_libs: ["libproduct_for_vndklibs"],
1774 nocrt: true,
1775 }
1776
1777 cc_library {
1778 name: "libproduct",
1779 product_specific: true,
1780 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1781 nocrt: true,
1782 }
1783
1784 cc_library {
1785 name: "libproduct_for_vndklibs",
1786 product_specific: true,
1787 nocrt: true,
1788 }
1789 `
1790 config := TestConfig(buildDir, android.Android, nil, bp, nil)
1791 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1792 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
1793 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1794
1795 testCcWithConfig(t, config)
1796}
1797
Logan Chiend3c59a22018-03-29 14:08:15 +08001798func TestVndkSpExtUseVndkError(t *testing.T) {
1799 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1800 // library.
1801 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1802 cc_library {
1803 name: "libvndk",
1804 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001805 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001806 vndk: {
1807 enabled: true,
1808 },
1809 nocrt: true,
1810 }
1811
1812 cc_library {
1813 name: "libvndk_sp",
1814 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001815 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001816 vndk: {
1817 enabled: true,
1818 support_system_process: true,
1819 },
1820 nocrt: true,
1821 }
1822
1823 cc_library {
1824 name: "libvndk_sp_ext",
1825 vendor: true,
1826 vndk: {
1827 enabled: true,
1828 extends: "libvndk_sp",
1829 support_system_process: true,
1830 },
1831 shared_libs: ["libvndk"], // Cause an error
1832 nocrt: true,
1833 }
1834 `)
1835
1836 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1837 // library.
1838 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1839 cc_library {
1840 name: "libvndk",
1841 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001842 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001843 vndk: {
1844 enabled: true,
1845 },
1846 nocrt: true,
1847 }
1848
1849 cc_library {
1850 name: "libvndk_ext",
1851 vendor: true,
1852 vndk: {
1853 enabled: true,
1854 extends: "libvndk",
1855 },
1856 nocrt: true,
1857 }
1858
1859 cc_library {
1860 name: "libvndk_sp",
1861 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001862 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001863 vndk: {
1864 enabled: true,
1865 support_system_process: true,
1866 },
1867 nocrt: true,
1868 }
1869
1870 cc_library {
1871 name: "libvndk_sp_ext",
1872 vendor: true,
1873 vndk: {
1874 enabled: true,
1875 extends: "libvndk_sp",
1876 support_system_process: true,
1877 },
1878 shared_libs: ["libvndk_ext"], // Cause an error
1879 nocrt: true,
1880 }
1881 `)
1882}
1883
1884func TestVndkUseVndkExtError(t *testing.T) {
1885 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1886 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001887 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1888 cc_library {
1889 name: "libvndk",
1890 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001891 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001892 vndk: {
1893 enabled: true,
1894 },
1895 nocrt: true,
1896 }
1897
1898 cc_library {
1899 name: "libvndk_ext",
1900 vendor: true,
1901 vndk: {
1902 enabled: true,
1903 extends: "libvndk",
1904 },
1905 nocrt: true,
1906 }
1907
1908 cc_library {
1909 name: "libvndk2",
1910 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001911 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001912 vndk: {
1913 enabled: true,
1914 },
1915 shared_libs: ["libvndk_ext"],
1916 nocrt: true,
1917 }
1918 `)
1919
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001920 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001921 cc_library {
1922 name: "libvndk",
1923 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001924 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001925 vndk: {
1926 enabled: true,
1927 },
1928 nocrt: true,
1929 }
1930
1931 cc_library {
1932 name: "libvndk_ext",
1933 vendor: true,
1934 vndk: {
1935 enabled: true,
1936 extends: "libvndk",
1937 },
1938 nocrt: true,
1939 }
1940
1941 cc_library {
1942 name: "libvndk2",
1943 vendor_available: true,
1944 vndk: {
1945 enabled: true,
1946 },
1947 target: {
1948 vendor: {
1949 shared_libs: ["libvndk_ext"],
1950 },
1951 },
1952 nocrt: true,
1953 }
1954 `)
1955
1956 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1957 cc_library {
1958 name: "libvndk_sp",
1959 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001960 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001961 vndk: {
1962 enabled: true,
1963 support_system_process: true,
1964 },
1965 nocrt: true,
1966 }
1967
1968 cc_library {
1969 name: "libvndk_sp_ext",
1970 vendor: true,
1971 vndk: {
1972 enabled: true,
1973 extends: "libvndk_sp",
1974 support_system_process: true,
1975 },
1976 nocrt: true,
1977 }
1978
1979 cc_library {
1980 name: "libvndk_sp_2",
1981 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001982 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001983 vndk: {
1984 enabled: true,
1985 support_system_process: true,
1986 },
1987 shared_libs: ["libvndk_sp_ext"],
1988 nocrt: true,
1989 }
1990 `)
1991
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001992 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001993 cc_library {
1994 name: "libvndk_sp",
1995 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001996 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001997 vndk: {
1998 enabled: true,
1999 },
2000 nocrt: true,
2001 }
2002
2003 cc_library {
2004 name: "libvndk_sp_ext",
2005 vendor: true,
2006 vndk: {
2007 enabled: true,
2008 extends: "libvndk_sp",
2009 },
2010 nocrt: true,
2011 }
2012
2013 cc_library {
2014 name: "libvndk_sp2",
2015 vendor_available: true,
2016 vndk: {
2017 enabled: true,
2018 },
2019 target: {
2020 vendor: {
2021 shared_libs: ["libvndk_sp_ext"],
2022 },
2023 },
2024 nocrt: true,
2025 }
2026 `)
2027}
2028
Justin Yun5f7f7e82019-11-18 19:52:14 +09002029func TestEnforceProductVndkVersion(t *testing.T) {
2030 bp := `
2031 cc_library {
2032 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002033 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002034 }
2035 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002036 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002037 symbol_file: "",
2038 }
2039 cc_library {
2040 name: "libvndk",
2041 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002042 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002043 vndk: {
2044 enabled: true,
2045 },
2046 nocrt: true,
2047 }
2048 cc_library {
2049 name: "libvndk_sp",
2050 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002051 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002052 vndk: {
2053 enabled: true,
2054 support_system_process: true,
2055 },
2056 nocrt: true,
2057 }
2058 cc_library {
2059 name: "libva",
2060 vendor_available: true,
2061 nocrt: true,
2062 }
2063 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002064 name: "libpa",
2065 product_available: true,
2066 nocrt: true,
2067 }
2068 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002069 name: "libboth_available",
2070 vendor_available: true,
2071 product_available: true,
2072 nocrt: true,
2073 target: {
2074 vendor: {
2075 suffix: "-vendor",
2076 },
2077 product: {
2078 suffix: "-product",
2079 },
2080 }
2081 }
2082 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002083 name: "libproduct_va",
2084 product_specific: true,
2085 vendor_available: true,
2086 nocrt: true,
2087 }
2088 cc_library {
2089 name: "libprod",
2090 product_specific: true,
2091 shared_libs: [
2092 "libllndk",
2093 "libvndk",
2094 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002095 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002096 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002097 "libproduct_va",
2098 ],
2099 nocrt: true,
2100 }
2101 cc_library {
2102 name: "libvendor",
2103 vendor: true,
2104 shared_libs: [
2105 "libllndk",
2106 "libvndk",
2107 "libvndk_sp",
2108 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002109 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002110 "libproduct_va",
2111 ],
2112 nocrt: true,
2113 }
2114 `
2115
2116 config := TestConfig(buildDir, android.Android, nil, bp, nil)
2117 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2118 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
2119 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2120
2121 ctx := testCcWithConfig(t, config)
2122
Jooyung Han261e1582020-10-20 18:54:21 +09002123 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2124 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002125
2126 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2127 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2128
2129 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2130 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002131}
2132
2133func TestEnforceProductVndkVersionErrors(t *testing.T) {
2134 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2135 cc_library {
2136 name: "libprod",
2137 product_specific: true,
2138 shared_libs: [
2139 "libvendor",
2140 ],
2141 nocrt: true,
2142 }
2143 cc_library {
2144 name: "libvendor",
2145 vendor: true,
2146 nocrt: true,
2147 }
2148 `)
2149 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2150 cc_library {
2151 name: "libprod",
2152 product_specific: true,
2153 shared_libs: [
2154 "libsystem",
2155 ],
2156 nocrt: true,
2157 }
2158 cc_library {
2159 name: "libsystem",
2160 nocrt: true,
2161 }
2162 `)
Justin Yun6977e8a2020-10-29 18:24:11 +09002163 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2164 cc_library {
2165 name: "libprod",
2166 product_specific: true,
2167 shared_libs: [
2168 "libva",
2169 ],
2170 nocrt: true,
2171 }
2172 cc_library {
2173 name: "libva",
2174 vendor_available: true,
2175 nocrt: true,
2176 }
2177 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002178 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002179 cc_library {
2180 name: "libprod",
2181 product_specific: true,
2182 shared_libs: [
2183 "libvndk_private",
2184 ],
2185 nocrt: true,
2186 }
2187 cc_library {
2188 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002189 vendor_available: true,
2190 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002191 vndk: {
2192 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002193 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002194 },
2195 nocrt: true,
2196 }
2197 `)
2198 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.VER", `
2199 cc_library {
2200 name: "libprod",
2201 product_specific: true,
2202 shared_libs: [
2203 "libsystem_ext",
2204 ],
2205 nocrt: true,
2206 }
2207 cc_library {
2208 name: "libsystem_ext",
2209 system_ext_specific: true,
2210 nocrt: true,
2211 }
2212 `)
2213 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2214 cc_library {
2215 name: "libsystem",
2216 shared_libs: [
2217 "libproduct_va",
2218 ],
2219 nocrt: true,
2220 }
2221 cc_library {
2222 name: "libproduct_va",
2223 product_specific: true,
2224 vendor_available: true,
2225 nocrt: true,
2226 }
2227 `)
2228}
2229
Jooyung Han38002912019-05-16 04:01:54 +09002230func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002231 bp := `
2232 cc_library {
2233 name: "libvndk",
2234 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002235 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002236 vndk: {
2237 enabled: true,
2238 },
2239 }
2240 cc_library {
2241 name: "libvndksp",
2242 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002243 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002244 vndk: {
2245 enabled: true,
2246 support_system_process: true,
2247 },
2248 }
2249 cc_library {
2250 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002251 vendor_available: true,
2252 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002253 vndk: {
2254 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002255 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002256 },
2257 }
2258 cc_library {
2259 name: "libvendor",
2260 vendor: true,
2261 }
2262 cc_library {
2263 name: "libvndkext",
2264 vendor: true,
2265 vndk: {
2266 enabled: true,
2267 extends: "libvndk",
2268 },
2269 }
2270 vndk_prebuilt_shared {
2271 name: "prevndk",
2272 version: "27",
2273 target_arch: "arm",
2274 binder32bit: true,
2275 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002276 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002277 vndk: {
2278 enabled: true,
2279 },
2280 arch: {
2281 arm: {
2282 srcs: ["liba.so"],
2283 },
2284 },
2285 }
2286 cc_library {
2287 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002288 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002289 }
2290 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002291 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002292 symbol_file: "",
2293 }
2294 cc_library {
2295 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002296 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002297 }
2298 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002299 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002300 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002301 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002302 }
2303
2304 llndk_libraries_txt {
2305 name: "llndk.libraries.txt",
2306 }
2307 vndkcore_libraries_txt {
2308 name: "vndkcore.libraries.txt",
2309 }
2310 vndksp_libraries_txt {
2311 name: "vndksp.libraries.txt",
2312 }
2313 vndkprivate_libraries_txt {
2314 name: "vndkprivate.libraries.txt",
2315 }
2316 vndkcorevariant_libraries_txt {
2317 name: "vndkcorevariant.libraries.txt",
2318 insert_vndk_version: false,
2319 }
2320 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002321
2322 config := TestConfig(buildDir, android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002323 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
2324 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
2325 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002326 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002327
Colin Cross78212242021-01-06 14:51:30 -08002328 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2329 []string{"libvndk.so", "libvndkprivate.so"})
2330 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2331 []string{"libc++.so", "libvndksp.so"})
2332 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2333 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2334 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2335 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002336
Colin Crossfb0c16e2019-11-20 17:12:35 -08002337 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002338
Jooyung Han38002912019-05-16 04:01:54 +09002339 tests := []struct {
2340 variant string
2341 name string
2342 expected string
2343 }{
2344 {vendorVariant, "libvndk", "native:vndk"},
2345 {vendorVariant, "libvndksp", "native:vndk"},
2346 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2347 {vendorVariant, "libvendor", "native:vendor"},
2348 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002349 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002350 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002351 {coreVariant, "libvndk", "native:platform"},
2352 {coreVariant, "libvndkprivate", "native:platform"},
2353 {coreVariant, "libllndk", "native:platform"},
2354 }
2355 for _, test := range tests {
2356 t.Run(test.name, func(t *testing.T) {
2357 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2358 assertString(t, module.makeLinkType, test.expected)
2359 })
2360 }
2361}
2362
Jeff Gaston294356f2017-09-27 17:05:30 -07002363var staticLinkDepOrderTestCases = []struct {
2364 // This is a string representation of a map[moduleName][]moduleDependency .
2365 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002366 inStatic string
2367
2368 // This is a string representation of a map[moduleName][]moduleDependency .
2369 // It models the dependencies declared in an Android.bp file.
2370 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002371
2372 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2373 // The keys of allOrdered specify which modules we would like to check.
2374 // The values of allOrdered specify the expected result (of the transitive closure of all
2375 // dependencies) for each module to test
2376 allOrdered string
2377
2378 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2379 // The keys of outOrdered specify which modules we would like to check.
2380 // The values of outOrdered specify the expected result (of the ordered linker command line)
2381 // for each module to test.
2382 outOrdered string
2383}{
2384 // Simple tests
2385 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002386 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002387 outOrdered: "",
2388 },
2389 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002390 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002391 outOrdered: "a:",
2392 },
2393 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002394 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002395 outOrdered: "a:b; b:",
2396 },
2397 // Tests of reordering
2398 {
2399 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002400 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002401 outOrdered: "a:b,c,d; b:d; c:d; d:",
2402 },
2403 {
2404 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002405 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002406 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2407 },
2408 {
2409 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002410 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002411 outOrdered: "a:d,b,e,c; d:b; e:c",
2412 },
2413 {
2414 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002415 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002416 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2417 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2418 },
2419 {
2420 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002421 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 -07002422 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2423 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2424 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002425 // shared dependencies
2426 {
2427 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2428 // So, we don't actually have to check that a shared dependency of c will change the order
2429 // of a library that depends statically on b and on c. We only need to check that if c has
2430 // a shared dependency on b, that that shows up in allOrdered.
2431 inShared: "c:b",
2432 allOrdered: "c:b",
2433 outOrdered: "c:",
2434 },
2435 {
2436 // This test doesn't actually include any shared dependencies but it's a reminder of what
2437 // the second phase of the above test would look like
2438 inStatic: "a:b,c; c:b",
2439 allOrdered: "a:c,b; c:b",
2440 outOrdered: "a:c,b; c:b",
2441 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002442 // tiebreakers for when two modules specifying different orderings and there is no dependency
2443 // to dictate an order
2444 {
2445 // 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 -08002446 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002447 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2448 },
2449 {
2450 // 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 -08002451 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 -07002452 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2453 },
2454 // Tests involving duplicate dependencies
2455 {
2456 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002457 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002458 outOrdered: "a:c,b",
2459 },
2460 {
2461 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002462 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002463 outOrdered: "a:d,c,b",
2464 },
2465 // Tests to confirm the nonexistence of infinite loops.
2466 // These cases should never happen, so as long as the test terminates and the
2467 // result is deterministic then that should be fine.
2468 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002469 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002470 outOrdered: "a:a",
2471 },
2472 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002473 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002474 allOrdered: "a:b,c; b:c,a; c:a,b",
2475 outOrdered: "a:b; b:c; c:a",
2476 },
2477 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002478 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002479 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2480 outOrdered: "a:c,b; b:a,c; c:b,a",
2481 },
2482}
2483
2484// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2485func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2486 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2487 strippedText := strings.Replace(text, " ", "", -1)
2488 if len(strippedText) < 1 {
2489 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2490 }
2491 allDeps = make(map[android.Path][]android.Path, 0)
2492
2493 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2494 moduleTexts := strings.Split(strippedText, ";")
2495
2496 outputForModuleName := func(moduleName string) android.Path {
2497 return android.PathForTesting(moduleName)
2498 }
2499
2500 for _, moduleText := range moduleTexts {
2501 // convert from "a:b,c" to ["a", "b,c"]
2502 components := strings.Split(moduleText, ":")
2503 if len(components) != 2 {
2504 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2505 }
2506 moduleName := components[0]
2507 moduleOutput := outputForModuleName(moduleName)
2508 modulesInOrder = append(modulesInOrder, moduleOutput)
2509
2510 depString := components[1]
2511 // convert from "b,c" to ["b", "c"]
2512 depNames := strings.Split(depString, ",")
2513 if len(depString) < 1 {
2514 depNames = []string{}
2515 }
2516 var deps []android.Path
2517 for _, depName := range depNames {
2518 deps = append(deps, outputForModuleName(depName))
2519 }
2520 allDeps[moduleOutput] = deps
2521 }
2522 return modulesInOrder, allDeps
2523}
2524
Jeff Gaston294356f2017-09-27 17:05:30 -07002525func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2526 for _, moduleName := range moduleNames {
2527 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
2528 output := module.outputFile.Path()
2529 paths = append(paths, output)
2530 }
2531 return paths
2532}
2533
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002534func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002535 ctx := testCc(t, `
2536 cc_library {
2537 name: "a",
2538 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002539 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002540 }
2541 cc_library {
2542 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002543 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002544 }
2545 cc_library {
2546 name: "c",
2547 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002548 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002549 }
2550 cc_library {
2551 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002552 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002553 }
2554
2555 `)
2556
Colin Cross7113d202019-11-20 16:39:12 -08002557 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002558 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002559 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2560 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002561
2562 if !reflect.DeepEqual(actual, expected) {
2563 t.Errorf("staticDeps orderings were not propagated correctly"+
2564 "\nactual: %v"+
2565 "\nexpected: %v",
2566 actual,
2567 expected,
2568 )
2569 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002570}
Jeff Gaston294356f2017-09-27 17:05:30 -07002571
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002572func TestStaticLibDepReorderingWithShared(t *testing.T) {
2573 ctx := testCc(t, `
2574 cc_library {
2575 name: "a",
2576 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002577 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002578 }
2579 cc_library {
2580 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002581 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002582 }
2583 cc_library {
2584 name: "c",
2585 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002586 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002587 }
2588
2589 `)
2590
Colin Cross7113d202019-11-20 16:39:12 -08002591 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002592 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002593 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
2594 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002595
2596 if !reflect.DeepEqual(actual, expected) {
2597 t.Errorf("staticDeps orderings did not account for shared libs"+
2598 "\nactual: %v"+
2599 "\nexpected: %v",
2600 actual,
2601 expected,
2602 )
2603 }
2604}
2605
Jooyung Hanb04a4992020-03-13 18:57:35 +09002606func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002607 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002608 if !reflect.DeepEqual(actual, expected) {
2609 t.Errorf(message+
2610 "\nactual: %v"+
2611 "\nexpected: %v",
2612 actual,
2613 expected,
2614 )
2615 }
2616}
2617
Jooyung Han61b66e92020-03-21 14:21:46 +00002618func TestLlndkLibrary(t *testing.T) {
2619 ctx := testCc(t, `
2620 cc_library {
2621 name: "libllndk",
2622 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002623 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002624 }
2625 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002626 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002627 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002628
2629 cc_prebuilt_library_shared {
2630 name: "libllndkprebuilt",
2631 stubs: { versions: ["1", "2"] },
2632 llndk_stubs: "libllndkprebuilt.llndk",
2633 }
2634 llndk_library {
2635 name: "libllndkprebuilt.llndk",
2636 }
2637
2638 cc_library {
2639 name: "libllndk_with_external_headers",
2640 stubs: { versions: ["1", "2"] },
2641 llndk_stubs: "libllndk_with_external_headers.llndk",
2642 header_libs: ["libexternal_headers"],
2643 export_header_lib_headers: ["libexternal_headers"],
2644 }
2645 llndk_library {
2646 name: "libllndk_with_external_headers.llndk",
2647 }
2648 cc_library_headers {
2649 name: "libexternal_headers",
2650 export_include_dirs: ["include"],
2651 vendor_available: true,
2652 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002653 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002654 actual := ctx.ModuleVariantsForTests("libllndk")
2655 for i := 0; i < len(actual); i++ {
2656 if !strings.HasPrefix(actual[i], "android_vendor.VER_") {
2657 actual = append(actual[:i], actual[i+1:]...)
2658 i--
2659 }
2660 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002661 expected := []string{
Jooyung Han61b66e92020-03-21 14:21:46 +00002662 "android_vendor.VER_arm64_armv8-a_shared_1",
2663 "android_vendor.VER_arm64_armv8-a_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002664 "android_vendor.VER_arm64_armv8-a_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002665 "android_vendor.VER_arm_armv7-a-neon_shared_1",
2666 "android_vendor.VER_arm_armv7-a-neon_shared_2",
Colin Cross0de8a1e2020-09-18 14:15:30 -07002667 "android_vendor.VER_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002668 }
2669 checkEquals(t, "variants for llndk stubs", expected, actual)
2670
Colin Cross127bb8b2020-12-16 16:46:01 -08002671 params := ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002672 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2673
Colin Cross127bb8b2020-12-16 16:46:01 -08002674 params = ctx.ModuleForTests("libllndk", "android_vendor.VER_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002675 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2676}
2677
Jiyong Parka46a4d52017-12-14 19:54:34 +09002678func TestLlndkHeaders(t *testing.T) {
2679 ctx := testCc(t, `
2680 llndk_headers {
2681 name: "libllndk_headers",
2682 export_include_dirs: ["my_include"],
2683 }
2684 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002685 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002686 export_llndk_headers: ["libllndk_headers"],
2687 }
2688 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002689 name: "libllndk",
2690 llndk_stubs: "libllndk.llndk",
2691 }
2692
2693 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002694 name: "libvendor",
2695 shared_libs: ["libllndk"],
2696 vendor: true,
2697 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002698 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002699 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002700 }
2701 `)
2702
2703 // _static variant is used since _shared reuses *.o from the static variant
Colin Crossfb0c16e2019-11-20 17:12:35 -08002704 cc := ctx.ModuleForTests("libvendor", "android_vendor.VER_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002705 cflags := cc.Args["cFlags"]
2706 if !strings.Contains(cflags, "-Imy_include") {
2707 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2708 }
2709}
2710
Logan Chien43d34c32017-12-20 01:17:32 +08002711func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2712 actual := module.Properties.AndroidMkRuntimeLibs
2713 if !reflect.DeepEqual(actual, expected) {
2714 t.Errorf("incorrect runtime_libs for shared libs"+
2715 "\nactual: %v"+
2716 "\nexpected: %v",
2717 actual,
2718 expected,
2719 )
2720 }
2721}
2722
2723const runtimeLibAndroidBp = `
2724 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002725 name: "liball_available",
2726 vendor_available: true,
2727 product_available: true,
2728 no_libcrt : true,
2729 nocrt : true,
2730 system_shared_libs : [],
2731 }
2732 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002733 name: "libvendor_available1",
2734 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002735 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002736 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002737 nocrt : true,
2738 system_shared_libs : [],
2739 }
2740 cc_library {
2741 name: "libvendor_available2",
2742 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002743 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002744 target: {
2745 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002746 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002747 }
2748 },
Yi Konge7fe9912019-06-02 00:53:50 -07002749 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002750 nocrt : true,
2751 system_shared_libs : [],
2752 }
2753 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002754 name: "libproduct_vendor",
2755 product_specific: true,
2756 vendor_available: true,
2757 no_libcrt : true,
2758 nocrt : true,
2759 system_shared_libs : [],
2760 }
2761 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002762 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002763 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002764 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002765 nocrt : true,
2766 system_shared_libs : [],
2767 }
2768 cc_library {
2769 name: "libvendor1",
2770 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002771 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002772 nocrt : true,
2773 system_shared_libs : [],
2774 }
2775 cc_library {
2776 name: "libvendor2",
2777 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002778 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002779 no_libcrt : true,
2780 nocrt : true,
2781 system_shared_libs : [],
2782 }
2783 cc_library {
2784 name: "libproduct_available1",
2785 product_available: true,
2786 runtime_libs: ["liball_available"],
2787 no_libcrt : true,
2788 nocrt : true,
2789 system_shared_libs : [],
2790 }
2791 cc_library {
2792 name: "libproduct1",
2793 product_specific: true,
2794 no_libcrt : true,
2795 nocrt : true,
2796 system_shared_libs : [],
2797 }
2798 cc_library {
2799 name: "libproduct2",
2800 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002801 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002802 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002803 nocrt : true,
2804 system_shared_libs : [],
2805 }
2806`
2807
2808func TestRuntimeLibs(t *testing.T) {
2809 ctx := testCc(t, runtimeLibAndroidBp)
2810
2811 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002812 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002813
Justin Yun8a2600c2020-12-07 12:44:03 +09002814 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2815 checkRuntimeLibs(t, []string{"liball_available"}, module)
2816
2817 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2818 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002819
2820 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002821 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002822
2823 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2824 // and vendor variants.
Colin Crossfb0c16e2019-11-20 17:12:35 -08002825 variant = "android_vendor.VER_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002826
Justin Yun8a2600c2020-12-07 12:44:03 +09002827 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2828 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002829
2830 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002831 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002832
2833 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2834 // and product variants.
2835 variant = "android_product.VER_arm64_armv8-a_shared"
2836
2837 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2838 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2839
2840 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002841 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002842}
2843
2844func TestExcludeRuntimeLibs(t *testing.T) {
2845 ctx := testCc(t, runtimeLibAndroidBp)
2846
Colin Cross7113d202019-11-20 16:39:12 -08002847 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002848 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2849 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002850
Colin Crossfb0c16e2019-11-20 17:12:35 -08002851 variant = "android_vendor.VER_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002852 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002853 checkRuntimeLibs(t, nil, module)
2854}
2855
2856func TestRuntimeLibsNoVndk(t *testing.T) {
2857 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2858
2859 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2860
Colin Cross7113d202019-11-20 16:39:12 -08002861 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002862
Justin Yun8a2600c2020-12-07 12:44:03 +09002863 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2864 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002865
2866 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002867 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002868
2869 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002870 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002871}
2872
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002873func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002874 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002875 actual := module.Properties.AndroidMkStaticLibs
2876 if !reflect.DeepEqual(actual, expected) {
2877 t.Errorf("incorrect static_libs"+
2878 "\nactual: %v"+
2879 "\nexpected: %v",
2880 actual,
2881 expected,
2882 )
2883 }
2884}
2885
2886const staticLibAndroidBp = `
2887 cc_library {
2888 name: "lib1",
2889 }
2890 cc_library {
2891 name: "lib2",
2892 static_libs: ["lib1"],
2893 }
2894`
2895
2896func TestStaticLibDepExport(t *testing.T) {
2897 ctx := testCc(t, staticLibAndroidBp)
2898
2899 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002900 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002901 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002902 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002903
2904 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002905 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002906 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2907 // libc++_static is linked additionally.
Peter Collingbournee5ba2862019-12-10 18:37:45 -08002908 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002909}
2910
Jiyong Parkd08b6972017-09-26 10:50:54 +09002911var compilerFlagsTestCases = []struct {
2912 in string
2913 out bool
2914}{
2915 {
2916 in: "a",
2917 out: false,
2918 },
2919 {
2920 in: "-a",
2921 out: true,
2922 },
2923 {
2924 in: "-Ipath/to/something",
2925 out: false,
2926 },
2927 {
2928 in: "-isystempath/to/something",
2929 out: false,
2930 },
2931 {
2932 in: "--coverage",
2933 out: false,
2934 },
2935 {
2936 in: "-include a/b",
2937 out: true,
2938 },
2939 {
2940 in: "-include a/b c/d",
2941 out: false,
2942 },
2943 {
2944 in: "-DMACRO",
2945 out: true,
2946 },
2947 {
2948 in: "-DMAC RO",
2949 out: false,
2950 },
2951 {
2952 in: "-a -b",
2953 out: false,
2954 },
2955 {
2956 in: "-DMACRO=definition",
2957 out: true,
2958 },
2959 {
2960 in: "-DMACRO=defi nition",
2961 out: true, // TODO(jiyong): this should be false
2962 },
2963 {
2964 in: "-DMACRO(x)=x + 1",
2965 out: true,
2966 },
2967 {
2968 in: "-DMACRO=\"defi nition\"",
2969 out: true,
2970 },
2971}
2972
2973type mockContext struct {
2974 BaseModuleContext
2975 result bool
2976}
2977
2978func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2979 // CheckBadCompilerFlags calls this function when the flag should be rejected
2980 ctx.result = false
2981}
2982
2983func TestCompilerFlags(t *testing.T) {
2984 for _, testCase := range compilerFlagsTestCases {
2985 ctx := &mockContext{result: true}
2986 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2987 if ctx.result != testCase.out {
2988 t.Errorf("incorrect output:")
2989 t.Errorf(" input: %#v", testCase.in)
2990 t.Errorf(" expected: %#v", testCase.out)
2991 t.Errorf(" got: %#v", ctx.result)
2992 }
2993 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002994}
Jiyong Park374510b2018-03-19 18:23:01 +09002995
2996func TestVendorPublicLibraries(t *testing.T) {
2997 ctx := testCc(t, `
2998 cc_library_headers {
2999 name: "libvendorpublic_headers",
3000 export_include_dirs: ["my_include"],
3001 }
3002 vendor_public_library {
3003 name: "libvendorpublic",
3004 symbol_file: "",
3005 export_public_headers: ["libvendorpublic_headers"],
3006 }
3007 cc_library {
3008 name: "libvendorpublic",
3009 srcs: ["foo.c"],
3010 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003011 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003012 nocrt: true,
3013 }
3014
3015 cc_library {
3016 name: "libsystem",
3017 shared_libs: ["libvendorpublic"],
3018 vendor: false,
3019 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003020 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003021 nocrt: true,
3022 }
3023 cc_library {
3024 name: "libvendor",
3025 shared_libs: ["libvendorpublic"],
3026 vendor: true,
3027 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003028 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003029 nocrt: true,
3030 }
3031 `)
3032
Colin Cross7113d202019-11-20 16:39:12 -08003033 coreVariant := "android_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -08003034 vendorVariant := "android_vendor.VER_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003035
3036 // test if header search paths are correctly added
3037 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003038 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003039 cflags := cc.Args["cFlags"]
3040 if !strings.Contains(cflags, "-Imy_include") {
3041 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3042 }
3043
3044 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003045 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003046 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003047 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003048 if !strings.Contains(libflags, stubPaths[0].String()) {
3049 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3050 }
3051
3052 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003053 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003054 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003055 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003056 if !strings.Contains(libflags, stubPaths[0].String()) {
3057 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3058 }
3059
3060}
Jiyong Park37b25202018-07-11 10:49:27 +09003061
3062func TestRecovery(t *testing.T) {
3063 ctx := testCc(t, `
3064 cc_library_shared {
3065 name: "librecovery",
3066 recovery: true,
3067 }
3068 cc_library_shared {
3069 name: "librecovery32",
3070 recovery: true,
3071 compile_multilib:"32",
3072 }
Jiyong Park5baac542018-08-28 09:55:37 +09003073 cc_library_shared {
3074 name: "libHalInRecovery",
3075 recovery_available: true,
3076 vendor: true,
3077 }
Jiyong Park37b25202018-07-11 10:49:27 +09003078 `)
3079
3080 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003081 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003082 if len(variants) != 1 || !android.InList(arm64, variants) {
3083 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3084 }
3085
3086 variants = ctx.ModuleVariantsForTests("librecovery32")
3087 if android.InList(arm64, variants) {
3088 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3089 }
Jiyong Park5baac542018-08-28 09:55:37 +09003090
3091 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3092 if !recoveryModule.Platform() {
3093 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3094 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003095}
Jiyong Park5baac542018-08-28 09:55:37 +09003096
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003097func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3098 bp := `
3099 cc_prebuilt_test_library_shared {
3100 name: "test_lib",
3101 relative_install_path: "foo/bar/baz",
3102 srcs: ["srcpath/dontusethispath/baz.so"],
3103 }
3104
3105 cc_test {
3106 name: "main_test",
3107 data_libs: ["test_lib"],
3108 gtest: false,
3109 }
3110 `
3111
3112 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3113 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
3114 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
3115 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3116
3117 ctx := testCcWithConfig(t, config)
3118 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3119 testBinary := module.(*Module).linker.(*testBinary)
3120 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3121 if err != nil {
3122 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3123 }
3124 if len(outputFiles) != 1 {
3125 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3126 }
3127 if len(testBinary.dataPaths()) != 1 {
3128 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3129 }
3130
3131 outputPath := outputFiles[0].String()
3132
3133 if !strings.HasSuffix(outputPath, "/main_test") {
3134 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3135 }
Colin Crossaa255532020-07-03 13:18:24 -07003136 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003137 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3138 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3139 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3140 }
3141}
3142
Jiyong Park7ed9de32018-10-15 22:25:07 +09003143func TestVersionedStubs(t *testing.T) {
3144 ctx := testCc(t, `
3145 cc_library_shared {
3146 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003147 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003148 stubs: {
3149 symbol_file: "foo.map.txt",
3150 versions: ["1", "2", "3"],
3151 },
3152 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003153
Jiyong Park7ed9de32018-10-15 22:25:07 +09003154 cc_library_shared {
3155 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003156 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003157 shared_libs: ["libFoo#1"],
3158 }`)
3159
3160 variants := ctx.ModuleVariantsForTests("libFoo")
3161 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003162 "android_arm64_armv8-a_shared",
3163 "android_arm64_armv8-a_shared_1",
3164 "android_arm64_armv8-a_shared_2",
3165 "android_arm64_armv8-a_shared_3",
3166 "android_arm_armv7-a-neon_shared",
3167 "android_arm_armv7-a-neon_shared_1",
3168 "android_arm_armv7-a-neon_shared_2",
3169 "android_arm_armv7-a-neon_shared_3",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003170 }
3171 variantsMismatch := false
3172 if len(variants) != len(expectedVariants) {
3173 variantsMismatch = true
3174 } else {
3175 for _, v := range expectedVariants {
3176 if !inList(v, variants) {
3177 variantsMismatch = false
3178 }
3179 }
3180 }
3181 if variantsMismatch {
3182 t.Errorf("variants of libFoo expected:\n")
3183 for _, v := range expectedVariants {
3184 t.Errorf("%q\n", v)
3185 }
3186 t.Errorf(", but got:\n")
3187 for _, v := range variants {
3188 t.Errorf("%q\n", v)
3189 }
3190 }
3191
Colin Cross7113d202019-11-20 16:39:12 -08003192 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003193 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003194 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003195 if !strings.Contains(libFlags, libFoo1StubPath) {
3196 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3197 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003198
Colin Cross7113d202019-11-20 16:39:12 -08003199 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003200 cFlags := libBarCompileRule.Args["cFlags"]
3201 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3202 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3203 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3204 }
Jiyong Park37b25202018-07-11 10:49:27 +09003205}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003206
Jooyung Hanb04a4992020-03-13 18:57:35 +09003207func TestVersioningMacro(t *testing.T) {
3208 for _, tc := range []struct{ moduleName, expected string }{
3209 {"libc", "__LIBC_API__"},
3210 {"libfoo", "__LIBFOO_API__"},
3211 {"libfoo@1", "__LIBFOO_1_API__"},
3212 {"libfoo-v1", "__LIBFOO_V1_API__"},
3213 {"libfoo.v1", "__LIBFOO_V1_API__"},
3214 } {
3215 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3216 }
3217}
3218
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003219func TestStaticExecutable(t *testing.T) {
3220 ctx := testCc(t, `
3221 cc_binary {
3222 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003223 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003224 static_executable: true,
3225 }`)
3226
Colin Cross7113d202019-11-20 16:39:12 -08003227 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003228 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3229 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003230 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003231 for _, lib := range systemStaticLibs {
3232 if !strings.Contains(libFlags, lib) {
3233 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3234 }
3235 }
3236 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3237 for _, lib := range systemSharedLibs {
3238 if strings.Contains(libFlags, lib) {
3239 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3240 }
3241 }
3242}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003243
3244func TestStaticDepsOrderWithStubs(t *testing.T) {
3245 ctx := testCc(t, `
3246 cc_binary {
3247 name: "mybin",
3248 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003249 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003250 static_executable: true,
3251 stl: "none",
3252 }
3253
3254 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003255 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003256 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003257 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003258 stl: "none",
3259 }
3260
3261 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003262 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003263 srcs: ["foo.c"],
3264 stl: "none",
3265 stubs: {
3266 versions: ["1"],
3267 },
3268 }`)
3269
Colin Cross0de8a1e2020-09-18 14:15:30 -07003270 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3271 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003272 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003273
3274 if !reflect.DeepEqual(actual, expected) {
3275 t.Errorf("staticDeps orderings were not propagated correctly"+
3276 "\nactual: %v"+
3277 "\nexpected: %v",
3278 actual,
3279 expected,
3280 )
3281 }
3282}
Jooyung Han38002912019-05-16 04:01:54 +09003283
Jooyung Hand48f3c32019-08-23 11:18:57 +09003284func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3285 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3286 cc_library {
3287 name: "libA",
3288 srcs: ["foo.c"],
3289 shared_libs: ["libB"],
3290 stl: "none",
3291 }
3292
3293 cc_library {
3294 name: "libB",
3295 srcs: ["foo.c"],
3296 enabled: false,
3297 stl: "none",
3298 }
3299 `)
3300}
3301
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003302// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3303// correctly.
3304func TestFuzzTarget(t *testing.T) {
3305 ctx := testCc(t, `
3306 cc_fuzz {
3307 name: "fuzz_smoke_test",
3308 srcs: ["foo.c"],
3309 }`)
3310
Paul Duffin075c4172019-12-19 19:06:13 +00003311 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003312 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3313}
3314
Jiyong Park29074592019-07-07 16:27:47 +09003315func TestAidl(t *testing.T) {
3316}
3317
Jooyung Han38002912019-05-16 04:01:54 +09003318func assertString(t *testing.T, got, expected string) {
3319 t.Helper()
3320 if got != expected {
3321 t.Errorf("expected %q got %q", expected, got)
3322 }
3323}
3324
3325func assertArrayString(t *testing.T, got, expected []string) {
3326 t.Helper()
3327 if len(got) != len(expected) {
3328 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3329 return
3330 }
3331 for i := range got {
3332 if got[i] != expected[i] {
3333 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3334 i, expected[i], expected, got[i], got)
3335 return
3336 }
3337 }
3338}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003339
Jooyung Han0302a842019-10-30 18:43:49 +09003340func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3341 t.Helper()
3342 assertArrayString(t, android.SortedStringKeys(m), expected)
3343}
3344
Colin Crosse1bb5d02019-09-24 14:55:04 -07003345func TestDefaults(t *testing.T) {
3346 ctx := testCc(t, `
3347 cc_defaults {
3348 name: "defaults",
3349 srcs: ["foo.c"],
3350 static: {
3351 srcs: ["bar.c"],
3352 },
3353 shared: {
3354 srcs: ["baz.c"],
3355 },
3356 }
3357
3358 cc_library_static {
3359 name: "libstatic",
3360 defaults: ["defaults"],
3361 }
3362
3363 cc_library_shared {
3364 name: "libshared",
3365 defaults: ["defaults"],
3366 }
3367
3368 cc_library {
3369 name: "libboth",
3370 defaults: ["defaults"],
3371 }
3372
3373 cc_binary {
3374 name: "binary",
3375 defaults: ["defaults"],
3376 }`)
3377
3378 pathsToBase := func(paths android.Paths) []string {
3379 var ret []string
3380 for _, p := range paths {
3381 ret = append(ret, p.Base())
3382 }
3383 return ret
3384 }
3385
Colin Cross7113d202019-11-20 16:39:12 -08003386 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003387 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3388 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3389 }
Colin Cross7113d202019-11-20 16:39:12 -08003390 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003391 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3392 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3393 }
Colin Cross7113d202019-11-20 16:39:12 -08003394 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003395 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3396 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3397 }
3398
Colin Cross7113d202019-11-20 16:39:12 -08003399 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003400 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3401 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3402 }
Colin Cross7113d202019-11-20 16:39:12 -08003403 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003404 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3405 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3406 }
3407}
Colin Crosseabaedd2020-02-06 17:01:55 -08003408
3409func TestProductVariableDefaults(t *testing.T) {
3410 bp := `
3411 cc_defaults {
3412 name: "libfoo_defaults",
3413 srcs: ["foo.c"],
3414 cppflags: ["-DFOO"],
3415 product_variables: {
3416 debuggable: {
3417 cppflags: ["-DBAR"],
3418 },
3419 },
3420 }
3421
3422 cc_library {
3423 name: "libfoo",
3424 defaults: ["libfoo_defaults"],
3425 }
3426 `
3427
3428 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3429 config.TestProductVariables.Debuggable = BoolPtr(true)
3430
Colin Crossae8600b2020-10-29 17:09:13 -07003431 ctx := CreateTestContext(config)
Colin Crosseabaedd2020-02-06 17:01:55 -08003432 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
3433 ctx.BottomUp("variable", android.VariableMutator).Parallel()
3434 })
Colin Crossae8600b2020-10-29 17:09:13 -07003435 ctx.Register()
Colin Crosseabaedd2020-02-06 17:01:55 -08003436
3437 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3438 android.FailIfErrored(t, errs)
3439 _, errs = ctx.PrepareBuildActions(config)
3440 android.FailIfErrored(t, errs)
3441
3442 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module)
3443 if !android.InList("-DBAR", libfoo.flags.Local.CppFlags) {
3444 t.Errorf("expected -DBAR in cppflags, got %q", libfoo.flags.Local.CppFlags)
3445 }
3446}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003447
3448func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3449 t.Parallel()
3450 bp := `
3451 cc_library_static {
3452 name: "libfoo",
3453 srcs: ["foo.c"],
3454 whole_static_libs: ["libbar"],
3455 }
3456
3457 cc_library_static {
3458 name: "libbar",
3459 whole_static_libs: ["libmissing"],
3460 }
3461 `
3462
3463 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3464 config.TestProductVariables.Allow_missing_dependencies = BoolPtr(true)
3465
Colin Crossae8600b2020-10-29 17:09:13 -07003466 ctx := CreateTestContext(config)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003467 ctx.SetAllowMissingDependencies(true)
Colin Crossae8600b2020-10-29 17:09:13 -07003468 ctx.Register()
Colin Crosse4f6eba2020-09-22 18:11:25 -07003469
3470 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
3471 android.FailIfErrored(t, errs)
3472 _, errs = ctx.PrepareBuildActions(config)
3473 android.FailIfErrored(t, errs)
3474
3475 libbar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
3476 if g, w := libbar.Rule, android.ErrorRule; g != w {
3477 t.Fatalf("Expected libbar rule to be %q, got %q", w, g)
3478 }
3479
3480 if g, w := libbar.Args["error"], "missing dependencies: libmissing"; !strings.Contains(g, w) {
3481 t.Errorf("Expected libbar error to contain %q, was %q", w, g)
3482 }
3483
3484 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
3485 if g, w := libfoo.Inputs.Strings(), libbar.Output.String(); !android.InList(w, g) {
3486 t.Errorf("Expected libfoo.a to depend on %q, got %q", w, g)
3487 }
3488
3489}
Colin Crosse9fe2942020-11-10 18:12:15 -08003490
3491func TestInstallSharedLibs(t *testing.T) {
3492 bp := `
3493 cc_binary {
3494 name: "bin",
3495 host_supported: true,
3496 shared_libs: ["libshared"],
3497 runtime_libs: ["libruntime"],
3498 srcs: [":gen"],
3499 }
3500
3501 cc_library_shared {
3502 name: "libshared",
3503 host_supported: true,
3504 shared_libs: ["libtransitive"],
3505 }
3506
3507 cc_library_shared {
3508 name: "libtransitive",
3509 host_supported: true,
3510 }
3511
3512 cc_library_shared {
3513 name: "libruntime",
3514 host_supported: true,
3515 }
3516
3517 cc_binary_host {
3518 name: "tool",
3519 srcs: ["foo.cpp"],
3520 }
3521
3522 genrule {
3523 name: "gen",
3524 tools: ["tool"],
3525 out: ["gen.cpp"],
3526 cmd: "$(location tool) $(out)",
3527 }
3528 `
3529
3530 config := TestConfig(buildDir, android.Android, nil, bp, nil)
3531 ctx := testCcWithConfig(t, config)
3532
3533 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3534 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3535 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3536 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3537 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3538
3539 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3540 t.Errorf("expected host bin dependency %q, got %q", w, g)
3541 }
3542
3543 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3544 t.Errorf("expected host bin dependency %q, got %q", w, g)
3545 }
3546
3547 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3548 t.Errorf("expected host bin dependency %q, got %q", w, g)
3549 }
3550
3551 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3552 t.Errorf("expected host bin dependency %q, got %q", w, g)
3553 }
3554
3555 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3556 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3557 }
3558
3559 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3560 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3561 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3562 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3563
3564 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3565 t.Errorf("expected device bin dependency %q, got %q", w, g)
3566 }
3567
3568 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3569 t.Errorf("expected device bin dependency %q, got %q", w, g)
3570 }
3571
3572 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3573 t.Errorf("expected device bin dependency %q, got %q", w, g)
3574 }
3575
3576 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3577 t.Errorf("expected device bin dependency %q, got %q", w, g)
3578 }
3579
3580 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3581 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3582 }
3583
3584}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003585
3586func TestStubsLibReexportsHeaders(t *testing.T) {
3587 ctx := testCc(t, `
3588 cc_library_shared {
3589 name: "libclient",
3590 srcs: ["foo.c"],
3591 shared_libs: ["libfoo#1"],
3592 }
3593
3594 cc_library_shared {
3595 name: "libfoo",
3596 srcs: ["foo.c"],
3597 shared_libs: ["libbar"],
3598 export_shared_lib_headers: ["libbar"],
3599 stubs: {
3600 symbol_file: "foo.map.txt",
3601 versions: ["1", "2", "3"],
3602 },
3603 }
3604
3605 cc_library_shared {
3606 name: "libbar",
3607 export_include_dirs: ["include/libbar"],
3608 srcs: ["foo.c"],
3609 }`)
3610
3611 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3612
3613 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3614 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3615 }
3616}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003617
3618func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3619 ctx := testCc(t, `
3620 cc_library {
3621 name: "libfoo",
3622 srcs: ["a/Foo.aidl"],
3623 aidl: { flags: ["-Werror"], },
3624 }
3625 `)
3626
3627 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3628 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3629 aidlCommand := manifest.Commands[0].GetCommand()
3630 expectedAidlFlag := "-Werror"
3631 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3632 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3633 }
3634}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003635
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003636type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003637
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003638const (
3639 None MemtagNoteType = iota + 1
3640 Sync
3641 Async
3642)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003643
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003644func (t MemtagNoteType) str() string {
3645 switch t {
3646 case None:
3647 return "none"
3648 case Sync:
3649 return "sync"
3650 case Async:
3651 return "async"
3652 default:
3653 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003654 }
3655}
3656
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003657func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3658 note_async := "note_memtag_heap_async"
3659 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003660
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003661 found := None
3662 implicits := m.Rule("ld").Implicits
3663 for _, lib := range implicits {
3664 if strings.Contains(lib.Rel(), note_async) {
3665 found = Async
3666 break
3667 } else if strings.Contains(lib.Rel(), note_sync) {
3668 found = Sync
3669 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003670 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003671 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003672
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003673 if found != expected {
3674 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3675 }
3676}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003677
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003678func makeMemtagTestConfig(t *testing.T) android.Config {
3679 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003680 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003681 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003682 gtest: false,
3683 }
3684
3685 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003686 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003687 gtest: false,
3688 sanitize: { memtag_heap: false },
3689 }
3690
3691 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003692 name: "%[1]s_test_true",
3693 gtest: false,
3694 sanitize: { memtag_heap: true },
3695 }
3696
3697 cc_test {
3698 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003699 gtest: false,
3700 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3701 }
3702
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003703 cc_test {
3704 name: "%[1]s_test_true_diag",
3705 gtest: false,
3706 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3707 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003708
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003709 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003710 name: "%[1]s_binary",
3711 }
3712
3713 cc_binary {
3714 name: "%[1]s_binary_false",
3715 sanitize: { memtag_heap: false },
3716 }
3717
3718 cc_binary {
3719 name: "%[1]s_binary_true",
3720 sanitize: { memtag_heap: true },
3721 }
3722
3723 cc_binary {
3724 name: "%[1]s_binary_true_nodiag",
3725 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3726 }
3727
3728 cc_binary {
3729 name: "%[1]s_binary_true_diag",
3730 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003731 }
3732 `
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003733 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3734 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3735 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3736 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003737
3738 mockFS := map[string][]byte{
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003739 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3740 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3741 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3742 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003743 }
3744
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003745 return TestConfig(buildDir, android.Android, nil, "", mockFS)
3746}
3747
3748func TestSanitizeMemtagHeap(t *testing.T) {
3749 variant := "android_arm64_armv8-a"
3750
3751 config := makeMemtagTestConfig(t)
3752 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003753 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003754 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003755 ctx := CreateTestContext(config)
3756 ctx.Register()
3757
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003758 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003759 android.FailIfErrored(t, errs)
3760 _, errs = ctx.PrepareBuildActions(config)
3761 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003762
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003763 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3764 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3765 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3766 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3767 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3768
3769 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3770 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3771 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3772 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3773 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3774
3775 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3776 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3777 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3778 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3779 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3780
3781 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3782 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3783 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3784 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3785 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3786
3787 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3788 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3789 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3790 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3791 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3792
3793 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3795 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3796 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3797 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3798
3799 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3803 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3804
3805 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3809 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3810}
3811
3812func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003813 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003814
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003815 config := makeMemtagTestConfig(t)
3816 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3817 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3818 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3819 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3820 ctx := CreateTestContext(config)
3821 ctx.Register()
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003822
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003823 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3824 android.FailIfErrored(t, errs)
3825 _, errs = ctx.PrepareBuildActions(config)
3826 android.FailIfErrored(t, errs)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003827
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003828 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003833
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003834 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3838 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3839
3840 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3841 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3842 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3843 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3844 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3845
3846 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3847 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3848 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3849 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3850 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3851
3852 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3853 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3854 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3855 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3857
3858 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3859 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3863
3864 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3865 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3869
3870 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3871 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3875}
3876
3877func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3878 variant := "android_arm64_armv8-a"
3879
3880 config := makeMemtagTestConfig(t)
3881 config.TestProductVariables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
3882 config.TestProductVariables.MemtagHeapSyncIncludePaths = []string{"subdir_sync"}
3883 config.TestProductVariables.MemtagHeapAsyncIncludePaths = []string{"subdir_async"}
3884 config.TestProductVariables.SanitizeDevice = []string{"memtag_heap"}
3885 config.TestProductVariables.SanitizeDeviceDiag = []string{"memtag_heap"}
3886 ctx := CreateTestContext(config)
3887 ctx.Register()
3888
3889 _, errs := ctx.ParseFileList(".", []string{"Android.bp", "subdir_default/Android.bp", "subdir_exclude/Android.bp", "subdir_sync/Android.bp", "subdir_async/Android.bp"})
3890 android.FailIfErrored(t, errs)
3891 _, errs = ctx.PrepareBuildActions(config)
3892 android.FailIfErrored(t, errs)
3893
3894 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3895 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3899
3900 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3901 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3902 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3903 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3904 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3905
3906 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3907 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3908 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3909 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3910 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3911
3912 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3913 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3914 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3915 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3916 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3917
3918 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3919 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3920 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3921 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3922 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3923
3924 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3925 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3926 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3927 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3928 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3929
3930 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3931 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3932 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3933 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3934 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3935
3936 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3937 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3938 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3939 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3940 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003941}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003942
3943func TestIncludeDirsExporting(t *testing.T) {
3944
3945 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3946 // embedded newline characters alone.
3947 trimIndentingSpaces := func(s string) string {
3948 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3949 }
3950
3951 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3952 t.Helper()
3953 expected = trimIndentingSpaces(expected)
3954 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3955 if expected != actual {
3956 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3957 }
3958 }
3959
3960 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3961
3962 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3963 t.Helper()
3964 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3965 name := module.Name()
3966
3967 for _, checker := range checkers {
3968 checker(t, name, exported)
3969 }
3970 }
3971
3972 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3973 return func(t *testing.T, name string, exported FlagExporterInfo) {
3974 t.Helper()
3975 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3976 }
3977 }
3978
3979 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3980 return func(t *testing.T, name string, exported FlagExporterInfo) {
3981 t.Helper()
3982 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3983 }
3984 }
3985
3986 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3987 return func(t *testing.T, name string, exported FlagExporterInfo) {
3988 t.Helper()
3989 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3990 }
3991 }
3992
3993 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3994 return func(t *testing.T, name string, exported FlagExporterInfo) {
3995 t.Helper()
3996 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3997 }
3998 }
3999
4000 genRuleModules := `
4001 genrule {
4002 name: "genrule_foo",
4003 cmd: "generate-foo",
4004 out: [
4005 "generated_headers/foo/generated_header.h",
4006 ],
4007 export_include_dirs: [
4008 "generated_headers",
4009 ],
4010 }
4011
4012 genrule {
4013 name: "genrule_bar",
4014 cmd: "generate-bar",
4015 out: [
4016 "generated_headers/bar/generated_header.h",
4017 ],
4018 export_include_dirs: [
4019 "generated_headers",
4020 ],
4021 }
4022 `
4023
4024 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
4025 ctx := testCc(t, genRuleModules+`
4026 cc_library {
4027 name: "libfoo",
4028 srcs: ["foo.c"],
4029 export_include_dirs: ["foo/standard"],
4030 export_system_include_dirs: ["foo/system"],
4031 generated_headers: ["genrule_foo"],
4032 export_generated_headers: ["genrule_foo"],
4033 }
4034
4035 cc_library {
4036 name: "libbar",
4037 srcs: ["bar.c"],
4038 shared_libs: ["libfoo"],
4039 export_include_dirs: ["bar/standard"],
4040 export_system_include_dirs: ["bar/system"],
4041 generated_headers: ["genrule_bar"],
4042 export_generated_headers: ["genrule_bar"],
4043 }
4044 `)
4045 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4046 checkIncludeDirs(t, ctx, foo,
4047 expectedIncludeDirs(`
4048 foo/standard
4049 .intermediates/genrule_foo/gen/generated_headers
4050 `),
4051 expectedSystemIncludeDirs(`foo/system`),
4052 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4053 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4054 )
4055
4056 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4057 checkIncludeDirs(t, ctx, bar,
4058 expectedIncludeDirs(`
4059 bar/standard
4060 .intermediates/genrule_bar/gen/generated_headers
4061 `),
4062 expectedSystemIncludeDirs(`bar/system`),
4063 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4064 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4065 )
4066 })
4067
4068 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4069 ctx := testCc(t, genRuleModules+`
4070 cc_library {
4071 name: "libfoo",
4072 srcs: ["foo.c"],
4073 export_include_dirs: ["foo/standard"],
4074 export_system_include_dirs: ["foo/system"],
4075 generated_headers: ["genrule_foo"],
4076 export_generated_headers: ["genrule_foo"],
4077 }
4078
4079 cc_library {
4080 name: "libbar",
4081 srcs: ["bar.c"],
4082 whole_static_libs: ["libfoo"],
4083 export_include_dirs: ["bar/standard"],
4084 export_system_include_dirs: ["bar/system"],
4085 generated_headers: ["genrule_bar"],
4086 export_generated_headers: ["genrule_bar"],
4087 }
4088 `)
4089 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4090 checkIncludeDirs(t, ctx, foo,
4091 expectedIncludeDirs(`
4092 foo/standard
4093 .intermediates/genrule_foo/gen/generated_headers
4094 `),
4095 expectedSystemIncludeDirs(`foo/system`),
4096 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4097 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4098 )
4099
4100 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4101 checkIncludeDirs(t, ctx, bar,
4102 expectedIncludeDirs(`
4103 bar/standard
4104 foo/standard
4105 .intermediates/genrule_foo/gen/generated_headers
4106 .intermediates/genrule_bar/gen/generated_headers
4107 `),
4108 expectedSystemIncludeDirs(`
4109 bar/system
4110 foo/system
4111 `),
4112 expectedGeneratedHeaders(`
4113 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4114 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4115 `),
4116 expectedOrderOnlyDeps(`
4117 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4118 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4119 `),
4120 )
4121 })
4122
Paul Duffin3cb603e2021-02-19 13:57:10 +00004123 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4124 ctx := testCc(t, genRuleModules+`
4125 cc_library_shared {
4126 name: "libfoo",
4127 srcs: [
4128 "foo.c",
4129 "b.aidl",
4130 "a.proto",
4131 ],
4132 aidl: {
4133 export_aidl_headers: true,
4134 }
4135 }
4136 `)
4137 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4138 checkIncludeDirs(t, ctx, foo,
4139 expectedIncludeDirs(`
4140 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4141 `),
4142 expectedSystemIncludeDirs(``),
4143 expectedGeneratedHeaders(`
4144 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4145 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4146 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004147 `),
4148 expectedOrderOnlyDeps(`
4149 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4150 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4151 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004152 `),
4153 )
4154 })
4155
Paul Duffin3cb603e2021-02-19 13:57:10 +00004156 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4157 ctx := testCc(t, genRuleModules+`
4158 cc_library_shared {
4159 name: "libfoo",
4160 srcs: [
4161 "foo.c",
4162 "b.aidl",
4163 "a.proto",
4164 ],
4165 proto: {
4166 export_proto_headers: true,
4167 }
4168 }
4169 `)
4170 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4171 checkIncludeDirs(t, ctx, foo,
4172 expectedIncludeDirs(`
4173 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4174 `),
4175 expectedSystemIncludeDirs(``),
4176 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004177 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4178 `),
4179 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004180 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4181 `),
4182 )
4183 })
4184
Paul Duffin33056e82021-02-19 13:49:08 +00004185 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004186 ctx := testCc(t, genRuleModules+`
4187 cc_library_shared {
4188 name: "libfoo",
4189 srcs: [
4190 "foo.c",
4191 "a.sysprop",
4192 "b.aidl",
4193 "a.proto",
4194 ],
4195 }
4196 `)
4197 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4198 checkIncludeDirs(t, ctx, foo,
4199 expectedIncludeDirs(`
4200 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4201 `),
4202 expectedSystemIncludeDirs(``),
4203 expectedGeneratedHeaders(`
4204 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004205 `),
4206 expectedOrderOnlyDeps(`
4207 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4208 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004209 `),
4210 )
4211 })
4212}