blob: 2d0d78b868e012fdcecd903b7bd7ae1616371010 [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 "os"
Inseob Kim1f086e22019-05-09 13:29:15 +090020 "path/filepath"
Colin Cross74d1ec02015-04-28 13:30:13 -070021 "reflect"
Paul Duffin3cb603e2021-02-19 13:57:10 +000022 "regexp"
Jeff Gaston294356f2017-09-27 17:05:30 -070023 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070024 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070025
26 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070027)
28
Jiyong Park6a43f042017-10-12 23:05:00 +090029func TestMain(m *testing.M) {
Paul Duffinc3e6ce02021-03-22 23:21:32 +000030 os.Exit(m.Run())
Jiyong Park6a43f042017-10-12 23:05:00 +090031}
32
Paul Duffin2e6f90e2021-03-22 23:20:25 +000033var prepareForCcTest = android.GroupFixturePreparers(
Paul Duffin02a3d652021-02-24 18:51:54 +000034 PrepareForTestWithCcIncludeVndk,
Paul Duffin02a3d652021-02-24 18:51:54 +000035 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
36 variables.DeviceVndkVersion = StringPtr("current")
37 variables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090038 variables.Platform_vndk_version = StringPtr("29")
Paul Duffin02a3d652021-02-24 18:51:54 +000039 }),
40)
41
Paul Duffin8567f222021-03-23 00:02:06 +000042// testCcWithConfig runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +000043//
44// See testCc for an explanation as to how to stop using this deprecated method.
45//
46// deprecated
Colin Cross98be1bb2019-12-13 20:41:13 -080047func testCcWithConfig(t *testing.T, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070048 t.Helper()
Paul Duffin8567f222021-03-23 00:02:06 +000049 result := prepareForCcTest.RunTestWithConfig(t, config)
Paul Duffin02a3d652021-02-24 18:51:54 +000050 return result.TestContext
Jiyong Park6a43f042017-10-12 23:05:00 +090051}
52
Paul Duffin8567f222021-03-23 00:02:06 +000053// testCc runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +000054//
Paul Duffin8567f222021-03-23 00:02:06 +000055// Do not add any new usages of this, instead use the prepareForCcTest directly as it makes it much
Paul Duffin02a3d652021-02-24 18:51:54 +000056// easier to customize the test behavior.
57//
58// If it is necessary to customize the behavior of an existing test that uses this then please first
Paul Duffin8567f222021-03-23 00:02:06 +000059// convert the test to using prepareForCcTest first and then in a following change add the
Paul Duffin02a3d652021-02-24 18:51:54 +000060// appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify
61// that it did not change the test behavior unexpectedly.
62//
63// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080064func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080065 t.Helper()
Paul Duffin8567f222021-03-23 00:02:06 +000066 result := prepareForCcTest.RunTestWithBp(t, bp)
Paul Duffin02a3d652021-02-24 18:51:54 +000067 return result.TestContext
Logan Chienf3511742017-10-31 18:04:35 +080068}
69
Paul Duffin8567f222021-03-23 00:02:06 +000070// testCcNoVndk runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +000071//
72// See testCc for an explanation as to how to stop using this deprecated method.
73//
74// deprecated
Logan Chienf3511742017-10-31 18:04:35 +080075func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080076 t.Helper()
Paul Duffinc3e6ce02021-03-22 23:21:32 +000077 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jiyong Parkf58c46e2021-04-01 21:35:20 +090078 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Logan Chienf3511742017-10-31 18:04:35 +080079
Colin Cross98be1bb2019-12-13 20:41:13 -080080 return testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +080081}
82
Paul Duffin8567f222021-03-23 00:02:06 +000083// testCcNoProductVndk runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +000084//
85// See testCc for an explanation as to how to stop using this deprecated method.
86//
87// deprecated
Justin Yun8a2600c2020-12-07 12:44:03 +090088func testCcNoProductVndk(t *testing.T, bp string) *android.TestContext {
89 t.Helper()
Paul Duffinc3e6ce02021-03-22 23:21:32 +000090 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun8a2600c2020-12-07 12:44:03 +090091 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +090092 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun8a2600c2020-12-07 12:44:03 +090093
94 return testCcWithConfig(t, config)
95}
96
Paul Duffin8567f222021-03-23 00:02:06 +000097// testCcErrorWithConfig runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +000098//
99// See testCc for an explanation as to how to stop using this deprecated method.
100//
101// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900102func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800103 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800104
Paul Duffin8567f222021-03-23 00:02:06 +0000105 prepareForCcTest.
Paul Duffin02a3d652021-02-24 18:51:54 +0000106 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
107 RunTestWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800108}
109
Paul Duffin8567f222021-03-23 00:02:06 +0000110// testCcError runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +0000111//
112// See testCc for an explanation as to how to stop using this deprecated method.
113//
114// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900115func testCcError(t *testing.T, pattern string, bp string) {
Jooyung Han479ca172020-10-19 18:51:07 +0900116 t.Helper()
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000117 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun5f7f7e82019-11-18 19:52:14 +0900118 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900119 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun5f7f7e82019-11-18 19:52:14 +0900120 testCcErrorWithConfig(t, pattern, config)
121 return
122}
123
Paul Duffin8567f222021-03-23 00:02:06 +0000124// testCcErrorProductVndk runs tests using the prepareForCcTest
Paul Duffin02a3d652021-02-24 18:51:54 +0000125//
126// See testCc for an explanation as to how to stop using this deprecated method.
127//
128// deprecated
Justin Yun5f7f7e82019-11-18 19:52:14 +0900129func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
Jooyung Han261e1582020-10-20 18:54:21 +0900130 t.Helper()
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000131 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun5f7f7e82019-11-18 19:52:14 +0900132 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
133 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900134 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun5f7f7e82019-11-18 19:52:14 +0900135 testCcErrorWithConfig(t, pattern, config)
136 return
137}
138
Logan Chienf3511742017-10-31 18:04:35 +0800139const (
Colin Cross7113d202019-11-20 16:39:12 -0800140 coreVariant = "android_arm64_armv8-a_shared"
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900141 vendorVariant = "android_vendor.29_arm64_armv8-a_shared"
142 productVariant = "android_product.29_arm64_armv8-a_shared"
Colin Crossfb0c16e2019-11-20 17:12:35 -0800143 recoveryVariant = "android_recovery_arm64_armv8-a_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800144)
145
Paul Duffindb462dd2021-03-21 22:01:55 +0000146// Test that the PrepareForTestWithCcDefaultModules provides all the files that it uses by
147// running it in a fixture that requires all source files to exist.
148func TestPrepareForTestWithCcDefaultModules(t *testing.T) {
149 android.GroupFixturePreparers(
150 PrepareForTestWithCcDefaultModules,
151 android.PrepareForTestDisallowNonExistentPaths,
152 ).RunTest(t)
153}
154
Doug Hornc32c6b02019-01-17 14:44:05 -0800155func TestFuchsiaDeps(t *testing.T) {
156 t.Helper()
157
158 bp := `
159 cc_library {
160 name: "libTest",
161 srcs: ["foo.c"],
162 target: {
163 fuchsia: {
164 srcs: ["bar.c"],
165 },
166 },
167 }`
168
Paul Duffin8567f222021-03-23 00:02:06 +0000169 result := android.GroupFixturePreparers(
170 prepareForCcTest,
171 PrepareForTestOnFuchsia,
172 ).RunTestWithBp(t, bp)
Doug Hornc32c6b02019-01-17 14:44:05 -0800173
174 rt := false
175 fb := false
176
Paul Duffinecdac8a2021-02-24 19:18:42 +0000177 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800178 implicits := ld.Implicits
179 for _, lib := range implicits {
180 if strings.Contains(lib.Rel(), "libcompiler_rt") {
181 rt = true
182 }
183
184 if strings.Contains(lib.Rel(), "libbioniccompat") {
185 fb = true
186 }
187 }
188
189 if !rt || !fb {
190 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
191 }
192}
193
194func TestFuchsiaTargetDecl(t *testing.T) {
195 t.Helper()
196
197 bp := `
198 cc_library {
199 name: "libTest",
200 srcs: ["foo.c"],
201 target: {
202 fuchsia: {
203 srcs: ["bar.c"],
204 },
205 },
206 }`
207
Paul Duffin8567f222021-03-23 00:02:06 +0000208 result := android.GroupFixturePreparers(
209 prepareForCcTest,
210 PrepareForTestOnFuchsia,
211 ).RunTestWithBp(t, bp)
Paul Duffinecdac8a2021-02-24 19:18:42 +0000212 ld := result.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
Doug Hornc32c6b02019-01-17 14:44:05 -0800213 var objs []string
214 for _, o := range ld.Inputs {
215 objs = append(objs, o.Base())
216 }
Paul Duffine84b1332021-03-12 11:59:43 +0000217 android.AssertArrayString(t, "libTest inputs", []string{"foo.o", "bar.o"}, objs)
Doug Hornc32c6b02019-01-17 14:44:05 -0800218}
219
Jiyong Park6a43f042017-10-12 23:05:00 +0900220func TestVendorSrc(t *testing.T) {
221 ctx := testCc(t, `
222 cc_library {
223 name: "libTest",
224 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700225 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800226 nocrt: true,
227 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900228 vendor_available: true,
229 target: {
230 vendor: {
231 srcs: ["bar.c"],
232 },
233 },
234 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900235 `)
236
Logan Chienf3511742017-10-31 18:04:35 +0800237 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900238 var objs []string
239 for _, o := range ld.Inputs {
240 objs = append(objs, o.Base())
241 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800242 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900243 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
244 }
245}
246
Justin Yun7f99ec72021-04-12 13:19:28 +0900247func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) {
248 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
249 partitionDefined := false
250 checkPartition := func(specific bool, partition string) {
251 if specific {
252 if expected != partition && !partitionDefined {
253 // The variant is installed to the 'partition'
254 t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition)
255 }
256 partitionDefined = true
257 } else {
258 // The variant is not installed to the 'partition'
259 if expected == partition {
260 t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition)
261 }
262 }
263 }
264 socSpecific := func(m *Module) bool {
265 return m.SocSpecific() || m.socSpecificModuleContext()
266 }
267 deviceSpecific := func(m *Module) bool {
268 return m.DeviceSpecific() || m.deviceSpecificModuleContext()
269 }
270 productSpecific := func(m *Module) bool {
271 return m.ProductSpecific() || m.productSpecificModuleContext()
272 }
273 systemExtSpecific := func(m *Module) bool {
274 return m.SystemExtSpecific()
275 }
276 checkPartition(socSpecific(mod), "vendor")
277 checkPartition(deviceSpecific(mod), "odm")
278 checkPartition(productSpecific(mod), "product")
279 checkPartition(systemExtSpecific(mod), "system_ext")
280 if !partitionDefined && expected != "system" {
281 t.Errorf("%s variant of %q is expected to be installed to %s partition,"+
282 " but installed to system partition", variant, name, expected)
283 }
284}
285
286func TestInstallPartition(t *testing.T) {
287 t.Helper()
288 ctx := prepareForCcTest.RunTestWithBp(t, `
289 cc_library {
290 name: "libsystem",
291 }
292 cc_library {
293 name: "libsystem_ext",
294 system_ext_specific: true,
295 }
296 cc_library {
297 name: "libproduct",
298 product_specific: true,
299 }
300 cc_library {
301 name: "libvendor",
302 vendor: true,
303 }
304 cc_library {
305 name: "libodm",
306 device_specific: true,
307 }
308 cc_library {
309 name: "liball_available",
310 vendor_available: true,
311 product_available: true,
312 }
313 cc_library {
314 name: "libsystem_ext_all_available",
315 system_ext_specific: true,
316 vendor_available: true,
317 product_available: true,
318 }
319 cc_library {
320 name: "liball_available_odm",
321 odm_available: true,
322 product_available: true,
323 }
324 cc_library {
325 name: "libproduct_vendoravailable",
326 product_specific: true,
327 vendor_available: true,
328 }
329 cc_library {
330 name: "libproduct_odmavailable",
331 product_specific: true,
332 odm_available: true,
333 }
334 `).TestContext
335
336 checkInstallPartition(t, ctx, "libsystem", coreVariant, "system")
337 checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext")
338 checkInstallPartition(t, ctx, "libproduct", productVariant, "product")
339 checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor")
340 checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm")
341
342 checkInstallPartition(t, ctx, "liball_available", coreVariant, "system")
343 checkInstallPartition(t, ctx, "liball_available", productVariant, "product")
344 checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor")
345
346 checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext")
347 checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product")
348 checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor")
349
350 checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system")
351 checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product")
352 checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm")
353
354 checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product")
355 checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor")
356
357 checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product")
358 checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm")
359}
360
Logan Chienf3511742017-10-31 18:04:35 +0800361func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900362 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800363
Logan Chiend3c59a22018-03-29 14:08:15 +0800364 t.Helper()
365
Justin Yun0ecf0b22020-02-28 15:07:59 +0900366 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800367
368 // Check library properties.
369 lib, ok := mod.compiler.(*libraryDecorator)
370 if !ok {
371 t.Errorf("%q must have libraryDecorator", name)
372 } else if lib.baseInstaller.subDir != subDir {
373 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
374 lib.baseInstaller.subDir)
375 }
376
377 // Check VNDK properties.
378 if mod.vndkdep == nil {
379 t.Fatalf("%q must have `vndkdep`", name)
380 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700381 if !mod.IsVndk() {
382 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800383 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400384 if mod.IsVndkSp() != isVndkSp {
385 t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp)
Logan Chienf3511742017-10-31 18:04:35 +0800386 }
387
388 // Check VNDK extension properties.
389 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500390 if mod.IsVndkExt() != isVndkExt {
391 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800392 }
393
394 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
395 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
396 }
397}
398
Jooyung Han2216fb12019-11-06 16:46:15 +0900399func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
400 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800401 content := android.ContentFromFileRuleForTests(t, params)
402 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900403 assertArrayString(t, actual, expected)
404}
405
Jooyung Han097087b2019-10-22 19:32:18 +0900406func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
407 t.Helper()
408 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900409 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
410}
411
412func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
413 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800414 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
415 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900416}
417
Logan Chienf3511742017-10-31 18:04:35 +0800418func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800419 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800420 cc_library {
421 name: "libvndk",
422 vendor_available: true,
423 vndk: {
424 enabled: true,
425 },
426 nocrt: true,
427 }
428
429 cc_library {
430 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900431 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800432 vndk: {
433 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900434 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800435 },
436 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900437 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800438 }
439
440 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900441 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800442 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900443 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800444 vndk: {
445 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900446 },
447 nocrt: true,
448 target: {
449 vendor: {
450 cflags: ["-DTEST"],
451 },
452 product: {
453 cflags: ["-DTEST"],
454 },
455 },
456 }
457
458 cc_library {
459 name: "libvndk_sp",
460 vendor_available: true,
461 vndk: {
462 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800463 support_system_process: true,
464 },
465 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900466 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800467 }
468
469 cc_library {
470 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900471 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800472 vndk: {
473 enabled: true,
474 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900475 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800476 },
477 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900478 target: {
479 vendor: {
480 suffix: "-x",
481 },
482 },
Logan Chienf3511742017-10-31 18:04:35 +0800483 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900484
485 cc_library {
486 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900487 vendor_available: true,
488 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900489 vndk: {
490 enabled: true,
491 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900492 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900493 },
494 nocrt: true,
495 target: {
496 vendor: {
497 suffix: "-x",
498 },
499 product: {
500 suffix: "-x",
501 },
502 },
503 }
504
Justin Yun450ae722021-04-16 19:58:18 +0900505 cc_library {
506 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -0700507 llndk: {
508 symbol_file: "libllndk.map.txt",
509 export_llndk_headers: ["libllndk_headers"],
510 }
Justin Yun450ae722021-04-16 19:58:18 +0900511 }
512
Justin Yun611e8862021-05-24 18:17:33 +0900513 cc_library {
514 name: "libclang_rt.hwasan-llndk",
515 llndk: {
516 symbol_file: "libclang_rt.hwasan.map.txt",
517 }
518 }
519
Colin Cross627280f2021-04-26 16:53:58 -0700520 cc_library_headers {
Justin Yun450ae722021-04-16 19:58:18 +0900521 name: "libllndk_headers",
Colin Cross627280f2021-04-26 16:53:58 -0700522 llndk: {
523 llndk_headers: true,
524 },
Justin Yun450ae722021-04-16 19:58:18 +0900525 export_include_dirs: ["include"],
526 }
527
Colin Crosse4e44bc2020-12-28 13:50:21 -0800528 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900529 name: "llndk.libraries.txt",
530 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800531 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900532 name: "vndkcore.libraries.txt",
533 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800534 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900535 name: "vndksp.libraries.txt",
536 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800537 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900538 name: "vndkprivate.libraries.txt",
539 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800540 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900541 name: "vndkproduct.libraries.txt",
542 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800543 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900544 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800545 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900546 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800547 `
548
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000549 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800550 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900551 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900552 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800553
554 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800555
Jooyung Han261e1582020-10-20 18:54:21 +0900556 // subdir == "" because VNDK libs are not supposed to be installed separately.
557 // They are installed as part of VNDK APEX instead.
558 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
559 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900560 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900561 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
562 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900563 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900564
Justin Yun6977e8a2020-10-29 18:24:11 +0900565 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
566 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900567
Inseob Kim1f086e22019-05-09 13:29:15 +0900568 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900569 snapshotDir := "vndk-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000570 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Inseob Kim1f086e22019-05-09 13:29:15 +0900571
572 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
573 "arm64", "armv8-a"))
574 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
575 "arm", "armv7-a-neon"))
576
577 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
578 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900579 llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub")
580
Inseob Kim1f086e22019-05-09 13:29:15 +0900581 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
582 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900583 llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub")
Inseob Kim1f086e22019-05-09 13:29:15 +0900584
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900585 variant := "android_vendor.29_arm64_armv8-a_shared"
586 variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900587
Inseob Kim7f283f42020-06-01 21:53:49 +0900588 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
589
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400590 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
591 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
592 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
593 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
594 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
595 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
596 CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant)
597 CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900598
Jooyung Han39edb6c2019-11-06 16:53:07 +0900599 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400600 CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
601 CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
602 CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
603 CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
604 CheckSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900605
Jooyung Han097087b2019-10-22 19:32:18 +0900606 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
607 "LLNDK: libc.so",
608 "LLNDK: libdl.so",
609 "LLNDK: libft2.so",
Justin Yun450ae722021-04-16 19:58:18 +0900610 "LLNDK: libllndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900611 "LLNDK: libm.so",
612 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900613 "VNDK-SP: libvndk_sp-x.so",
614 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900615 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900616 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900617 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900618 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900619 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900620 "VNDK-private: libvndk-private.so",
621 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900622 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900623 "VNDK-product: libc++.so",
624 "VNDK-product: libvndk_product.so",
625 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900626 })
Justin Yun611e8862021-05-24 18:17:33 +0900627 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libclang_rt.hwasan-llndk.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900628 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
629 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
630 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 +0900631 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 +0900632 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
633}
634
Yo Chiangbba545e2020-06-09 16:15:37 +0800635func TestVndkWithHostSupported(t *testing.T) {
636 ctx := testCc(t, `
637 cc_library {
638 name: "libvndk_host_supported",
639 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900640 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800641 vndk: {
642 enabled: true,
643 },
644 host_supported: true,
645 }
646
647 cc_library {
648 name: "libvndk_host_supported_but_disabled_on_device",
649 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900650 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800651 vndk: {
652 enabled: true,
653 },
654 host_supported: true,
655 enabled: false,
656 target: {
657 host: {
658 enabled: true,
659 }
660 }
661 }
662
Colin Crosse4e44bc2020-12-28 13:50:21 -0800663 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800664 name: "vndkcore.libraries.txt",
665 }
666 `)
667
668 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
669}
670
Jooyung Han2216fb12019-11-06 16:46:15 +0900671func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800672 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800673 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900674 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800675 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800676 }`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000677 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800678 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900679 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800680 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900681
682 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Colin Crossaa255532020-07-03 13:18:24 -0700683 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900684 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900685}
686
687func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800688 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900689 cc_library {
690 name: "libvndk",
691 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900692 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900693 vndk: {
694 enabled: true,
695 },
696 nocrt: true,
697 }
698
699 cc_library {
700 name: "libvndk_sp",
701 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900702 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900703 vndk: {
704 enabled: true,
705 support_system_process: true,
706 },
707 nocrt: true,
708 }
709
710 cc_library {
711 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900712 vendor_available: true,
713 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900714 vndk: {
715 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900716 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900717 },
718 nocrt: true,
719 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900720
Colin Crosse4e44bc2020-12-28 13:50:21 -0800721 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900722 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800723 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900724 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800725 `
726
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000727 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800728 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900729 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800730 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
731
732 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
733
734 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900735
Jooyung Han2216fb12019-11-06 16:46:15 +0900736 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900737}
738
Chris Parsons79d66a52020-06-05 17:26:16 -0400739func TestDataLibs(t *testing.T) {
740 bp := `
741 cc_test_library {
742 name: "test_lib",
743 srcs: ["test_lib.cpp"],
744 gtest: false,
745 }
746
747 cc_test {
748 name: "main_test",
749 data_libs: ["test_lib"],
750 gtest: false,
751 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400752 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400753
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000754 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons79d66a52020-06-05 17:26:16 -0400755 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900756 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons79d66a52020-06-05 17:26:16 -0400757 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
758
759 ctx := testCcWithConfig(t, config)
760 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
761 testBinary := module.(*Module).linker.(*testBinary)
762 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
763 if err != nil {
764 t.Errorf("Expected cc_test to produce output files, error: %s", err)
765 return
766 }
767 if len(outputFiles) != 1 {
768 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
769 return
770 }
771 if len(testBinary.dataPaths()) != 1 {
772 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
773 return
774 }
775
776 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400777 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400778
779 if !strings.HasSuffix(outputPath, "/main_test") {
780 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
781 return
782 }
783 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
784 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
785 return
786 }
787}
788
Chris Parsons216e10a2020-07-09 17:12:52 -0400789func TestDataLibsRelativeInstallPath(t *testing.T) {
790 bp := `
791 cc_test_library {
792 name: "test_lib",
793 srcs: ["test_lib.cpp"],
794 relative_install_path: "foo/bar/baz",
795 gtest: false,
796 }
797
798 cc_test {
799 name: "main_test",
800 data_libs: ["test_lib"],
801 gtest: false,
802 }
803 `
804
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000805 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons216e10a2020-07-09 17:12:52 -0400806 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900807 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons216e10a2020-07-09 17:12:52 -0400808 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
809
810 ctx := testCcWithConfig(t, config)
811 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
812 testBinary := module.(*Module).linker.(*testBinary)
813 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
814 if err != nil {
815 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
816 }
817 if len(outputFiles) != 1 {
818 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
819 }
820 if len(testBinary.dataPaths()) != 1 {
821 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
822 }
823
824 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400825
826 if !strings.HasSuffix(outputPath, "/main_test") {
827 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
828 }
Colin Crossaa255532020-07-03 13:18:24 -0700829 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400830 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
831 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400832 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400833 }
834}
835
Jooyung Han0302a842019-10-30 18:43:49 +0900836func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900837 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900838 cc_library {
839 name: "libvndk",
840 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900841 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900842 vndk: {
843 enabled: true,
844 },
845 nocrt: true,
846 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900847 cc_library {
848 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900849 vendor_available: true,
850 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900851 vndk: {
852 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900853 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900854 },
855 nocrt: true,
856 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800857
858 cc_library {
859 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -0700860 llndk: {
861 symbol_file: "libllndk.map.txt",
862 export_llndk_headers: ["libllndk_headers"],
863 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800864 }
865
Colin Cross627280f2021-04-26 16:53:58 -0700866 cc_library_headers {
Colin Crossb5f6fa62021-01-06 17:05:04 -0800867 name: "libllndk_headers",
Colin Cross627280f2021-04-26 16:53:58 -0700868 llndk: {
869 symbol_file: "libllndk.map.txt",
870 },
Colin Crossb5f6fa62021-01-06 17:05:04 -0800871 export_include_dirs: ["include"],
872 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900873 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900874
875 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
876 "LLNDK: libc.so",
877 "LLNDK: libdl.so",
878 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800879 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900880 "LLNDK: libm.so",
881 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900882 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900883 "VNDK-core: libvndk.so",
884 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900885 "VNDK-private: libvndk-private.so",
886 "VNDK-product: libc++.so",
887 "VNDK-product: libvndk-private.so",
888 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900889 })
Logan Chienf3511742017-10-31 18:04:35 +0800890}
891
Justin Yun63e9ec72020-10-29 16:49:43 +0900892func TestVndkModuleError(t *testing.T) {
893 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900894 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900895 cc_library {
896 name: "libvndk",
897 vndk: {
898 enabled: true,
899 },
900 nocrt: true,
901 }
902 `)
903
Justin Yunc0d8c492021-01-07 17:45:31 +0900904 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900905 cc_library {
906 name: "libvndk",
907 product_available: true,
908 vndk: {
909 enabled: true,
910 },
911 nocrt: true,
912 }
913 `)
914
Justin Yun6977e8a2020-10-29 18:24:11 +0900915 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
916 cc_library {
917 name: "libvndkprop",
918 vendor_available: true,
919 product_available: true,
920 vndk: {
921 enabled: true,
922 },
923 nocrt: true,
924 target: {
925 vendor: {
926 cflags: ["-DTEST",],
927 },
928 },
929 }
930 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900931}
932
Logan Chiend3c59a22018-03-29 14:08:15 +0800933func TestVndkDepError(t *testing.T) {
934 // Check whether an error is emitted when a VNDK lib depends on a system lib.
935 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
936 cc_library {
937 name: "libvndk",
938 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900939 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800940 vndk: {
941 enabled: true,
942 },
943 shared_libs: ["libfwk"], // Cause error
944 nocrt: true,
945 }
946
947 cc_library {
948 name: "libfwk",
949 nocrt: true,
950 }
951 `)
952
953 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
954 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
955 cc_library {
956 name: "libvndk",
957 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900958 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800959 vndk: {
960 enabled: true,
961 },
962 shared_libs: ["libvendor"], // Cause error
963 nocrt: true,
964 }
965
966 cc_library {
967 name: "libvendor",
968 vendor: true,
969 nocrt: true,
970 }
971 `)
972
973 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
974 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
975 cc_library {
976 name: "libvndk_sp",
977 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900978 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800979 vndk: {
980 enabled: true,
981 support_system_process: true,
982 },
983 shared_libs: ["libfwk"], // Cause error
984 nocrt: true,
985 }
986
987 cc_library {
988 name: "libfwk",
989 nocrt: true,
990 }
991 `)
992
993 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
994 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
995 cc_library {
996 name: "libvndk_sp",
997 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900998 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800999 vndk: {
1000 enabled: true,
1001 support_system_process: true,
1002 },
1003 shared_libs: ["libvendor"], // Cause error
1004 nocrt: true,
1005 }
1006
1007 cc_library {
1008 name: "libvendor",
1009 vendor: true,
1010 nocrt: true,
1011 }
1012 `)
1013
1014 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
1015 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1016 cc_library {
1017 name: "libvndk_sp",
1018 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001019 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001020 vndk: {
1021 enabled: true,
1022 support_system_process: true,
1023 },
1024 shared_libs: ["libvndk"], // Cause error
1025 nocrt: true,
1026 }
1027
1028 cc_library {
1029 name: "libvndk",
1030 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001031 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001032 vndk: {
1033 enabled: true,
1034 },
1035 nocrt: true,
1036 }
1037 `)
Jooyung Hana70f0672019-01-18 15:20:43 +09001038
1039 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
1040 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1041 cc_library {
1042 name: "libvndk",
1043 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001044 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001045 vndk: {
1046 enabled: true,
1047 },
1048 shared_libs: ["libnonvndk"],
1049 nocrt: true,
1050 }
1051
1052 cc_library {
1053 name: "libnonvndk",
1054 vendor_available: true,
1055 nocrt: true,
1056 }
1057 `)
1058
1059 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
1060 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1061 cc_library {
1062 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001063 vendor_available: true,
1064 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001065 vndk: {
1066 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001067 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001068 },
1069 shared_libs: ["libnonvndk"],
1070 nocrt: true,
1071 }
1072
1073 cc_library {
1074 name: "libnonvndk",
1075 vendor_available: true,
1076 nocrt: true,
1077 }
1078 `)
1079
1080 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
1081 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1082 cc_library {
1083 name: "libvndksp",
1084 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001085 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001086 vndk: {
1087 enabled: true,
1088 support_system_process: true,
1089 },
1090 shared_libs: ["libnonvndk"],
1091 nocrt: true,
1092 }
1093
1094 cc_library {
1095 name: "libnonvndk",
1096 vendor_available: true,
1097 nocrt: true,
1098 }
1099 `)
1100
1101 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1102 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1103 cc_library {
1104 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001105 vendor_available: true,
1106 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001107 vndk: {
1108 enabled: true,
1109 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001110 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001111 },
1112 shared_libs: ["libnonvndk"],
1113 nocrt: true,
1114 }
1115
1116 cc_library {
1117 name: "libnonvndk",
1118 vendor_available: true,
1119 nocrt: true,
1120 }
1121 `)
1122}
1123
1124func TestDoubleLoadbleDep(t *testing.T) {
1125 // okay to link : LLNDK -> double_loadable VNDK
1126 testCc(t, `
1127 cc_library {
1128 name: "libllndk",
1129 shared_libs: ["libdoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001130 llndk: {
1131 symbol_file: "libllndk.map.txt",
1132 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001133 }
1134
1135 cc_library {
1136 name: "libdoubleloadable",
1137 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001138 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001139 vndk: {
1140 enabled: true,
1141 },
1142 double_loadable: true,
1143 }
1144 `)
1145 // okay to link : LLNDK -> VNDK-SP
1146 testCc(t, `
1147 cc_library {
1148 name: "libllndk",
1149 shared_libs: ["libvndksp"],
Colin Cross203b4212021-04-26 17:19:41 -07001150 llndk: {
1151 symbol_file: "libllndk.map.txt",
1152 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001153 }
1154
1155 cc_library {
1156 name: "libvndksp",
1157 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001158 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001159 vndk: {
1160 enabled: true,
1161 support_system_process: true,
1162 },
1163 }
1164 `)
1165 // okay to link : double_loadable -> double_loadable
1166 testCc(t, `
1167 cc_library {
1168 name: "libdoubleloadable1",
1169 shared_libs: ["libdoubleloadable2"],
1170 vendor_available: true,
1171 double_loadable: true,
1172 }
1173
1174 cc_library {
1175 name: "libdoubleloadable2",
1176 vendor_available: true,
1177 double_loadable: true,
1178 }
1179 `)
1180 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1181 testCc(t, `
1182 cc_library {
1183 name: "libdoubleloadable",
1184 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001185 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001186 vndk: {
1187 enabled: true,
1188 },
1189 double_loadable: true,
1190 shared_libs: ["libnondoubleloadable"],
1191 }
1192
1193 cc_library {
1194 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001195 vendor_available: true,
1196 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001197 vndk: {
1198 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001199 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001200 },
1201 double_loadable: true,
1202 }
1203 `)
1204 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1205 testCc(t, `
1206 cc_library {
1207 name: "libllndk",
1208 shared_libs: ["libcoreonly"],
Colin Cross203b4212021-04-26 17:19:41 -07001209 llndk: {
1210 symbol_file: "libllndk.map.txt",
1211 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001212 }
1213
1214 cc_library {
1215 name: "libcoreonly",
1216 shared_libs: ["libvendoravailable"],
1217 }
1218
1219 // indirect dependency of LLNDK
1220 cc_library {
1221 name: "libvendoravailable",
1222 vendor_available: true,
1223 double_loadable: true,
1224 }
1225 `)
1226}
1227
1228func TestDoubleLoadableDepError(t *testing.T) {
1229 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1230 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1231 cc_library {
1232 name: "libllndk",
1233 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001234 llndk: {
1235 symbol_file: "libllndk.map.txt",
1236 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001237 }
1238
1239 cc_library {
1240 name: "libnondoubleloadable",
1241 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001242 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001243 vndk: {
1244 enabled: true,
1245 },
1246 }
1247 `)
1248
1249 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1250 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1251 cc_library {
1252 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001253 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001254 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001255 llndk: {
1256 symbol_file: "libllndk.map.txt",
1257 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001258 }
1259
1260 cc_library {
1261 name: "libnondoubleloadable",
1262 vendor_available: true,
1263 }
1264 `)
1265
Jooyung Hana70f0672019-01-18 15:20:43 +09001266 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1267 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1268 cc_library {
1269 name: "libllndk",
1270 shared_libs: ["libcoreonly"],
Colin Cross203b4212021-04-26 17:19:41 -07001271 llndk: {
1272 symbol_file: "libllndk.map.txt",
1273 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001274 }
1275
1276 cc_library {
1277 name: "libcoreonly",
1278 shared_libs: ["libvendoravailable"],
1279 }
1280
1281 // indirect dependency of LLNDK
1282 cc_library {
1283 name: "libvendoravailable",
1284 vendor_available: true,
1285 }
1286 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001287
1288 // The error is not from 'client' but from 'libllndk'
1289 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1290 cc_library {
1291 name: "client",
1292 vendor_available: true,
1293 double_loadable: true,
1294 shared_libs: ["libllndk"],
1295 }
1296 cc_library {
1297 name: "libllndk",
1298 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001299 llndk: {
1300 symbol_file: "libllndk.map.txt",
1301 }
Jiyong Park0474e1f2021-01-14 14:26:06 +09001302 }
1303 cc_library {
1304 name: "libnondoubleloadable",
1305 vendor_available: true,
1306 }
1307 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001308}
1309
Jooyung Han479ca172020-10-19 18:51:07 +09001310func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1311 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1312 cc_library {
1313 name: "libvndksp",
1314 shared_libs: ["libanothervndksp"],
1315 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001316 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001317 vndk: {
1318 enabled: true,
1319 support_system_process: true,
1320 }
1321 }
1322
1323 cc_library {
1324 name: "libllndk",
1325 shared_libs: ["libanothervndksp"],
1326 }
1327
Jooyung Han479ca172020-10-19 18:51:07 +09001328 cc_library {
1329 name: "libanothervndksp",
1330 vendor_available: true,
1331 }
1332 `)
1333}
1334
Logan Chienf3511742017-10-31 18:04:35 +08001335func TestVndkExt(t *testing.T) {
1336 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001337 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001338 cc_library {
1339 name: "libvndk",
1340 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001341 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001342 vndk: {
1343 enabled: true,
1344 },
1345 nocrt: true,
1346 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001347 cc_library {
1348 name: "libvndk2",
1349 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001350 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001351 vndk: {
1352 enabled: true,
1353 },
1354 target: {
1355 vendor: {
1356 suffix: "-suffix",
1357 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001358 product: {
1359 suffix: "-suffix",
1360 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001361 },
1362 nocrt: true,
1363 }
Logan Chienf3511742017-10-31 18:04:35 +08001364
1365 cc_library {
1366 name: "libvndk_ext",
1367 vendor: true,
1368 vndk: {
1369 enabled: true,
1370 extends: "libvndk",
1371 },
1372 nocrt: true,
1373 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001374
1375 cc_library {
1376 name: "libvndk2_ext",
1377 vendor: true,
1378 vndk: {
1379 enabled: true,
1380 extends: "libvndk2",
1381 },
1382 nocrt: true,
1383 }
Logan Chienf3511742017-10-31 18:04:35 +08001384
Justin Yun0ecf0b22020-02-28 15:07:59 +09001385 cc_library {
1386 name: "libvndk_ext_product",
1387 product_specific: true,
1388 vndk: {
1389 enabled: true,
1390 extends: "libvndk",
1391 },
1392 nocrt: true,
1393 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001394
Justin Yun0ecf0b22020-02-28 15:07:59 +09001395 cc_library {
1396 name: "libvndk2_ext_product",
1397 product_specific: true,
1398 vndk: {
1399 enabled: true,
1400 extends: "libvndk2",
1401 },
1402 nocrt: true,
1403 }
1404 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001405 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001406 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1407 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001408 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001409
1410 ctx := testCcWithConfig(t, config)
1411
1412 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1413 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1414
1415 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1416 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1417
1418 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1419 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001420}
1421
Logan Chiend3c59a22018-03-29 14:08:15 +08001422func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001423 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1424 ctx := testCcNoVndk(t, `
1425 cc_library {
1426 name: "libvndk",
1427 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001428 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001429 vndk: {
1430 enabled: true,
1431 },
1432 nocrt: true,
1433 }
1434
1435 cc_library {
1436 name: "libvndk_ext",
1437 vendor: true,
1438 vndk: {
1439 enabled: true,
1440 extends: "libvndk",
1441 },
1442 nocrt: true,
1443 }
1444 `)
1445
1446 // Ensures that the core variant of "libvndk_ext" can be found.
1447 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1448 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1449 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1450 }
1451}
1452
Justin Yun0ecf0b22020-02-28 15:07:59 +09001453func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1454 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001455 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001456 cc_library {
1457 name: "libvndk",
1458 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001459 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001460 vndk: {
1461 enabled: true,
1462 },
1463 nocrt: true,
1464 }
1465
1466 cc_library {
1467 name: "libvndk_ext_product",
1468 product_specific: true,
1469 vndk: {
1470 enabled: true,
1471 extends: "libvndk",
1472 },
1473 nocrt: true,
1474 }
1475 `)
1476
1477 // Ensures that the core variant of "libvndk_ext_product" can be found.
1478 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1479 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1480 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1481 }
1482}
1483
Logan Chienf3511742017-10-31 18:04:35 +08001484func TestVndkExtError(t *testing.T) {
1485 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001486 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001487 cc_library {
1488 name: "libvndk",
1489 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001490 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001491 vndk: {
1492 enabled: true,
1493 },
1494 nocrt: true,
1495 }
1496
1497 cc_library {
1498 name: "libvndk_ext",
1499 vndk: {
1500 enabled: true,
1501 extends: "libvndk",
1502 },
1503 nocrt: true,
1504 }
1505 `)
1506
1507 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1508 cc_library {
1509 name: "libvndk",
1510 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001511 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001512 vndk: {
1513 enabled: true,
1514 },
1515 nocrt: true,
1516 }
1517
1518 cc_library {
1519 name: "libvndk_ext",
1520 vendor: true,
1521 vndk: {
1522 enabled: true,
1523 },
1524 nocrt: true,
1525 }
1526 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001527
1528 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1529 cc_library {
1530 name: "libvndk",
1531 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001532 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001533 vndk: {
1534 enabled: true,
1535 },
1536 nocrt: true,
1537 }
1538
1539 cc_library {
1540 name: "libvndk_ext_product",
1541 product_specific: true,
1542 vndk: {
1543 enabled: true,
1544 },
1545 nocrt: true,
1546 }
1547 `)
1548
1549 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1550 cc_library {
1551 name: "libvndk",
1552 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001553 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001554 vndk: {
1555 enabled: true,
1556 },
1557 nocrt: true,
1558 }
1559
1560 cc_library {
1561 name: "libvndk_ext_product",
1562 product_specific: true,
1563 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001564 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001565 vndk: {
1566 enabled: true,
1567 extends: "libvndk",
1568 },
1569 nocrt: true,
1570 }
1571 `)
Logan Chienf3511742017-10-31 18:04:35 +08001572}
1573
1574func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1575 // This test ensures an error is emitted for inconsistent support_system_process.
1576 testCcError(t, "module \".*\" with mismatched support_system_process", `
1577 cc_library {
1578 name: "libvndk",
1579 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001580 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001581 vndk: {
1582 enabled: true,
1583 },
1584 nocrt: true,
1585 }
1586
1587 cc_library {
1588 name: "libvndk_sp_ext",
1589 vendor: true,
1590 vndk: {
1591 enabled: true,
1592 extends: "libvndk",
1593 support_system_process: true,
1594 },
1595 nocrt: true,
1596 }
1597 `)
1598
1599 testCcError(t, "module \".*\" with mismatched support_system_process", `
1600 cc_library {
1601 name: "libvndk_sp",
1602 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001603 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001604 vndk: {
1605 enabled: true,
1606 support_system_process: true,
1607 },
1608 nocrt: true,
1609 }
1610
1611 cc_library {
1612 name: "libvndk_ext",
1613 vendor: true,
1614 vndk: {
1615 enabled: true,
1616 extends: "libvndk_sp",
1617 },
1618 nocrt: true,
1619 }
1620 `)
1621}
1622
1623func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001624 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001625 // with `private: true`.
1626 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001627 cc_library {
1628 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001629 vendor_available: true,
1630 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001631 vndk: {
1632 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001633 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001634 },
1635 nocrt: true,
1636 }
1637
1638 cc_library {
1639 name: "libvndk_ext",
1640 vendor: true,
1641 vndk: {
1642 enabled: true,
1643 extends: "libvndk",
1644 },
1645 nocrt: true,
1646 }
1647 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001648
Justin Yunfd9e8042020-12-23 18:23:14 +09001649 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001650 cc_library {
1651 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001652 vendor_available: true,
1653 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001654 vndk: {
1655 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001656 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001657 },
1658 nocrt: true,
1659 }
1660
1661 cc_library {
1662 name: "libvndk_ext_product",
1663 product_specific: true,
1664 vndk: {
1665 enabled: true,
1666 extends: "libvndk",
1667 },
1668 nocrt: true,
1669 }
1670 `)
Logan Chienf3511742017-10-31 18:04:35 +08001671}
1672
Logan Chiend3c59a22018-03-29 14:08:15 +08001673func TestVendorModuleUseVndkExt(t *testing.T) {
1674 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001675 testCc(t, `
1676 cc_library {
1677 name: "libvndk",
1678 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001679 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001680 vndk: {
1681 enabled: true,
1682 },
1683 nocrt: true,
1684 }
1685
1686 cc_library {
1687 name: "libvndk_ext",
1688 vendor: true,
1689 vndk: {
1690 enabled: true,
1691 extends: "libvndk",
1692 },
1693 nocrt: true,
1694 }
1695
1696 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001697 name: "libvndk_sp",
1698 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001699 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001700 vndk: {
1701 enabled: true,
1702 support_system_process: true,
1703 },
1704 nocrt: true,
1705 }
1706
1707 cc_library {
1708 name: "libvndk_sp_ext",
1709 vendor: true,
1710 vndk: {
1711 enabled: true,
1712 extends: "libvndk_sp",
1713 support_system_process: true,
1714 },
1715 nocrt: true,
1716 }
1717
1718 cc_library {
1719 name: "libvendor",
1720 vendor: true,
1721 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1722 nocrt: true,
1723 }
1724 `)
1725}
1726
Logan Chiend3c59a22018-03-29 14:08:15 +08001727func TestVndkExtUseVendorLib(t *testing.T) {
1728 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001729 testCc(t, `
1730 cc_library {
1731 name: "libvndk",
1732 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001733 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001734 vndk: {
1735 enabled: true,
1736 },
1737 nocrt: true,
1738 }
1739
1740 cc_library {
1741 name: "libvndk_ext",
1742 vendor: true,
1743 vndk: {
1744 enabled: true,
1745 extends: "libvndk",
1746 },
1747 shared_libs: ["libvendor"],
1748 nocrt: true,
1749 }
1750
1751 cc_library {
1752 name: "libvendor",
1753 vendor: true,
1754 nocrt: true,
1755 }
1756 `)
Logan Chienf3511742017-10-31 18:04:35 +08001757
Logan Chiend3c59a22018-03-29 14:08:15 +08001758 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1759 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001760 cc_library {
1761 name: "libvndk_sp",
1762 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001763 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001764 vndk: {
1765 enabled: true,
1766 support_system_process: true,
1767 },
1768 nocrt: true,
1769 }
1770
1771 cc_library {
1772 name: "libvndk_sp_ext",
1773 vendor: true,
1774 vndk: {
1775 enabled: true,
1776 extends: "libvndk_sp",
1777 support_system_process: true,
1778 },
1779 shared_libs: ["libvendor"], // Cause an error
1780 nocrt: true,
1781 }
1782
1783 cc_library {
1784 name: "libvendor",
1785 vendor: true,
1786 nocrt: true,
1787 }
1788 `)
1789}
1790
Justin Yun0ecf0b22020-02-28 15:07:59 +09001791func TestProductVndkExtDependency(t *testing.T) {
1792 bp := `
1793 cc_library {
1794 name: "libvndk",
1795 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001796 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001797 vndk: {
1798 enabled: true,
1799 },
1800 nocrt: true,
1801 }
1802
1803 cc_library {
1804 name: "libvndk_ext_product",
1805 product_specific: true,
1806 vndk: {
1807 enabled: true,
1808 extends: "libvndk",
1809 },
1810 shared_libs: ["libproduct_for_vndklibs"],
1811 nocrt: true,
1812 }
1813
1814 cc_library {
1815 name: "libvndk_sp",
1816 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001817 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001818 vndk: {
1819 enabled: true,
1820 support_system_process: true,
1821 },
1822 nocrt: true,
1823 }
1824
1825 cc_library {
1826 name: "libvndk_sp_ext_product",
1827 product_specific: true,
1828 vndk: {
1829 enabled: true,
1830 extends: "libvndk_sp",
1831 support_system_process: true,
1832 },
1833 shared_libs: ["libproduct_for_vndklibs"],
1834 nocrt: true,
1835 }
1836
1837 cc_library {
1838 name: "libproduct",
1839 product_specific: true,
1840 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1841 nocrt: true,
1842 }
1843
1844 cc_library {
1845 name: "libproduct_for_vndklibs",
1846 product_specific: true,
1847 nocrt: true,
1848 }
1849 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001850 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001851 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1852 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001853 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001854
1855 testCcWithConfig(t, config)
1856}
1857
Logan Chiend3c59a22018-03-29 14:08:15 +08001858func TestVndkSpExtUseVndkError(t *testing.T) {
1859 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1860 // library.
1861 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1862 cc_library {
1863 name: "libvndk",
1864 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001865 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001866 vndk: {
1867 enabled: true,
1868 },
1869 nocrt: true,
1870 }
1871
1872 cc_library {
1873 name: "libvndk_sp",
1874 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001875 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001876 vndk: {
1877 enabled: true,
1878 support_system_process: true,
1879 },
1880 nocrt: true,
1881 }
1882
1883 cc_library {
1884 name: "libvndk_sp_ext",
1885 vendor: true,
1886 vndk: {
1887 enabled: true,
1888 extends: "libvndk_sp",
1889 support_system_process: true,
1890 },
1891 shared_libs: ["libvndk"], // Cause an error
1892 nocrt: true,
1893 }
1894 `)
1895
1896 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1897 // library.
1898 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1899 cc_library {
1900 name: "libvndk",
1901 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001902 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001903 vndk: {
1904 enabled: true,
1905 },
1906 nocrt: true,
1907 }
1908
1909 cc_library {
1910 name: "libvndk_ext",
1911 vendor: true,
1912 vndk: {
1913 enabled: true,
1914 extends: "libvndk",
1915 },
1916 nocrt: true,
1917 }
1918
1919 cc_library {
1920 name: "libvndk_sp",
1921 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001922 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001923 vndk: {
1924 enabled: true,
1925 support_system_process: true,
1926 },
1927 nocrt: true,
1928 }
1929
1930 cc_library {
1931 name: "libvndk_sp_ext",
1932 vendor: true,
1933 vndk: {
1934 enabled: true,
1935 extends: "libvndk_sp",
1936 support_system_process: true,
1937 },
1938 shared_libs: ["libvndk_ext"], // Cause an error
1939 nocrt: true,
1940 }
1941 `)
1942}
1943
1944func TestVndkUseVndkExtError(t *testing.T) {
1945 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1946 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001947 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1948 cc_library {
1949 name: "libvndk",
1950 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001951 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001952 vndk: {
1953 enabled: true,
1954 },
1955 nocrt: true,
1956 }
1957
1958 cc_library {
1959 name: "libvndk_ext",
1960 vendor: true,
1961 vndk: {
1962 enabled: true,
1963 extends: "libvndk",
1964 },
1965 nocrt: true,
1966 }
1967
1968 cc_library {
1969 name: "libvndk2",
1970 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001971 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001972 vndk: {
1973 enabled: true,
1974 },
1975 shared_libs: ["libvndk_ext"],
1976 nocrt: true,
1977 }
1978 `)
1979
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001980 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001981 cc_library {
1982 name: "libvndk",
1983 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001984 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001985 vndk: {
1986 enabled: true,
1987 },
1988 nocrt: true,
1989 }
1990
1991 cc_library {
1992 name: "libvndk_ext",
1993 vendor: true,
1994 vndk: {
1995 enabled: true,
1996 extends: "libvndk",
1997 },
1998 nocrt: true,
1999 }
2000
2001 cc_library {
2002 name: "libvndk2",
2003 vendor_available: true,
2004 vndk: {
2005 enabled: true,
2006 },
2007 target: {
2008 vendor: {
2009 shared_libs: ["libvndk_ext"],
2010 },
2011 },
2012 nocrt: true,
2013 }
2014 `)
2015
2016 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2017 cc_library {
2018 name: "libvndk_sp",
2019 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002020 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002021 vndk: {
2022 enabled: true,
2023 support_system_process: true,
2024 },
2025 nocrt: true,
2026 }
2027
2028 cc_library {
2029 name: "libvndk_sp_ext",
2030 vendor: true,
2031 vndk: {
2032 enabled: true,
2033 extends: "libvndk_sp",
2034 support_system_process: true,
2035 },
2036 nocrt: true,
2037 }
2038
2039 cc_library {
2040 name: "libvndk_sp_2",
2041 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002042 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002043 vndk: {
2044 enabled: true,
2045 support_system_process: true,
2046 },
2047 shared_libs: ["libvndk_sp_ext"],
2048 nocrt: true,
2049 }
2050 `)
2051
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002052 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002053 cc_library {
2054 name: "libvndk_sp",
2055 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002056 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002057 vndk: {
2058 enabled: true,
2059 },
2060 nocrt: true,
2061 }
2062
2063 cc_library {
2064 name: "libvndk_sp_ext",
2065 vendor: true,
2066 vndk: {
2067 enabled: true,
2068 extends: "libvndk_sp",
2069 },
2070 nocrt: true,
2071 }
2072
2073 cc_library {
2074 name: "libvndk_sp2",
2075 vendor_available: true,
2076 vndk: {
2077 enabled: true,
2078 },
2079 target: {
2080 vendor: {
2081 shared_libs: ["libvndk_sp_ext"],
2082 },
2083 },
2084 nocrt: true,
2085 }
2086 `)
2087}
2088
Justin Yun5f7f7e82019-11-18 19:52:14 +09002089func TestEnforceProductVndkVersion(t *testing.T) {
2090 bp := `
2091 cc_library {
2092 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -07002093 llndk: {
2094 symbol_file: "libllndk.map.txt",
2095 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002096 }
2097 cc_library {
2098 name: "libvndk",
2099 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002100 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002101 vndk: {
2102 enabled: true,
2103 },
2104 nocrt: true,
2105 }
2106 cc_library {
2107 name: "libvndk_sp",
2108 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002109 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002110 vndk: {
2111 enabled: true,
2112 support_system_process: true,
2113 },
2114 nocrt: true,
2115 }
2116 cc_library {
2117 name: "libva",
2118 vendor_available: true,
2119 nocrt: true,
2120 }
2121 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002122 name: "libpa",
2123 product_available: true,
2124 nocrt: true,
2125 }
2126 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002127 name: "libboth_available",
2128 vendor_available: true,
2129 product_available: true,
2130 nocrt: true,
Justin Yun13decfb2021-03-08 19:25:55 +09002131 srcs: ["foo.c"],
Justin Yun6977e8a2020-10-29 18:24:11 +09002132 target: {
2133 vendor: {
2134 suffix: "-vendor",
2135 },
2136 product: {
2137 suffix: "-product",
2138 },
2139 }
2140 }
2141 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002142 name: "libproduct_va",
2143 product_specific: true,
2144 vendor_available: true,
2145 nocrt: true,
2146 }
2147 cc_library {
2148 name: "libprod",
2149 product_specific: true,
2150 shared_libs: [
2151 "libllndk",
2152 "libvndk",
2153 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002154 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002155 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002156 "libproduct_va",
2157 ],
2158 nocrt: true,
2159 }
2160 cc_library {
2161 name: "libvendor",
2162 vendor: true,
2163 shared_libs: [
2164 "libllndk",
2165 "libvndk",
2166 "libvndk_sp",
2167 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002168 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002169 "libproduct_va",
2170 ],
2171 nocrt: true,
2172 }
2173 `
2174
Paul Duffin8567f222021-03-23 00:02:06 +00002175 ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
Justin Yun5f7f7e82019-11-18 19:52:14 +09002176
Jooyung Han261e1582020-10-20 18:54:21 +09002177 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2178 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002179
2180 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2181 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2182
2183 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2184 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun13decfb2021-03-08 19:25:55 +09002185
2186 ensureStringContains := func(t *testing.T, str string, substr string) {
2187 t.Helper()
2188 if !strings.Contains(str, substr) {
2189 t.Errorf("%q is not found in %v", substr, str)
2190 }
2191 }
2192 ensureStringNotContains := func(t *testing.T, str string, substr string) {
2193 t.Helper()
2194 if strings.Contains(str, substr) {
2195 t.Errorf("%q is found in %v", substr, str)
2196 }
2197 }
2198
2199 // _static variant is used since _shared reuses *.o from the static variant
2200 vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
2201 product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
2202
2203 vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
2204 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
2205 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
2206 ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
2207
2208 product_cflags := product_static.Rule("cc").Args["cFlags"]
2209 ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
2210 ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
2211 ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002212}
2213
2214func TestEnforceProductVndkVersionErrors(t *testing.T) {
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002215 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002216 cc_library {
2217 name: "libprod",
2218 product_specific: true,
2219 shared_libs: [
2220 "libvendor",
2221 ],
2222 nocrt: true,
2223 }
2224 cc_library {
2225 name: "libvendor",
2226 vendor: true,
2227 nocrt: true,
2228 }
2229 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002230 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002231 cc_library {
2232 name: "libprod",
2233 product_specific: true,
2234 shared_libs: [
2235 "libsystem",
2236 ],
2237 nocrt: true,
2238 }
2239 cc_library {
2240 name: "libsystem",
2241 nocrt: true,
2242 }
2243 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002244 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun6977e8a2020-10-29 18:24:11 +09002245 cc_library {
2246 name: "libprod",
2247 product_specific: true,
2248 shared_libs: [
2249 "libva",
2250 ],
2251 nocrt: true,
2252 }
2253 cc_library {
2254 name: "libva",
2255 vendor_available: true,
2256 nocrt: true,
2257 }
2258 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002259 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002260 cc_library {
2261 name: "libprod",
2262 product_specific: true,
2263 shared_libs: [
2264 "libvndk_private",
2265 ],
2266 nocrt: true,
2267 }
2268 cc_library {
2269 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002270 vendor_available: true,
2271 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002272 vndk: {
2273 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002274 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002275 },
2276 nocrt: true,
2277 }
2278 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002279 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002280 cc_library {
2281 name: "libprod",
2282 product_specific: true,
2283 shared_libs: [
2284 "libsystem_ext",
2285 ],
2286 nocrt: true,
2287 }
2288 cc_library {
2289 name: "libsystem_ext",
2290 system_ext_specific: true,
2291 nocrt: true,
2292 }
2293 `)
2294 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2295 cc_library {
2296 name: "libsystem",
2297 shared_libs: [
2298 "libproduct_va",
2299 ],
2300 nocrt: true,
2301 }
2302 cc_library {
2303 name: "libproduct_va",
2304 product_specific: true,
2305 vendor_available: true,
2306 nocrt: true,
2307 }
2308 `)
2309}
2310
Jooyung Han38002912019-05-16 04:01:54 +09002311func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002312 bp := `
2313 cc_library {
2314 name: "libvndk",
2315 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002316 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002317 vndk: {
2318 enabled: true,
2319 },
2320 }
2321 cc_library {
2322 name: "libvndksp",
2323 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002324 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002325 vndk: {
2326 enabled: true,
2327 support_system_process: true,
2328 },
2329 }
2330 cc_library {
2331 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002332 vendor_available: true,
2333 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002334 vndk: {
2335 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002336 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002337 },
2338 }
2339 cc_library {
2340 name: "libvendor",
2341 vendor: true,
2342 }
2343 cc_library {
2344 name: "libvndkext",
2345 vendor: true,
2346 vndk: {
2347 enabled: true,
2348 extends: "libvndk",
2349 },
2350 }
2351 vndk_prebuilt_shared {
2352 name: "prevndk",
2353 version: "27",
2354 target_arch: "arm",
2355 binder32bit: true,
2356 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002357 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002358 vndk: {
2359 enabled: true,
2360 },
2361 arch: {
2362 arm: {
2363 srcs: ["liba.so"],
2364 },
2365 },
2366 }
2367 cc_library {
2368 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -07002369 llndk: {
2370 symbol_file: "libllndk.map.txt",
2371 }
Colin Cross98be1bb2019-12-13 20:41:13 -08002372 }
2373 cc_library {
2374 name: "libllndkprivate",
Colin Cross203b4212021-04-26 17:19:41 -07002375 llndk: {
2376 symbol_file: "libllndkprivate.map.txt",
2377 private: true,
2378 }
Colin Cross78212242021-01-06 14:51:30 -08002379 }
2380
2381 llndk_libraries_txt {
2382 name: "llndk.libraries.txt",
2383 }
2384 vndkcore_libraries_txt {
2385 name: "vndkcore.libraries.txt",
2386 }
2387 vndksp_libraries_txt {
2388 name: "vndksp.libraries.txt",
2389 }
2390 vndkprivate_libraries_txt {
2391 name: "vndkprivate.libraries.txt",
2392 }
2393 vndkcorevariant_libraries_txt {
2394 name: "vndkcorevariant.libraries.txt",
2395 insert_vndk_version: false,
2396 }
2397 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002398
Paul Duffinc3e6ce02021-03-22 23:21:32 +00002399 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002400 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002401 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jooyung Han38002912019-05-16 04:01:54 +09002402 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002403 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002404
Colin Cross78212242021-01-06 14:51:30 -08002405 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2406 []string{"libvndk.so", "libvndkprivate.so"})
2407 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2408 []string{"libc++.so", "libvndksp.so"})
2409 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2410 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2411 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2412 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002413
Colin Crossfb0c16e2019-11-20 17:12:35 -08002414 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002415
Jooyung Han38002912019-05-16 04:01:54 +09002416 tests := []struct {
2417 variant string
2418 name string
2419 expected string
2420 }{
2421 {vendorVariant, "libvndk", "native:vndk"},
2422 {vendorVariant, "libvndksp", "native:vndk"},
2423 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2424 {vendorVariant, "libvendor", "native:vendor"},
2425 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002426 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002427 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002428 {coreVariant, "libvndk", "native:platform"},
2429 {coreVariant, "libvndkprivate", "native:platform"},
2430 {coreVariant, "libllndk", "native:platform"},
2431 }
2432 for _, test := range tests {
2433 t.Run(test.name, func(t *testing.T) {
2434 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2435 assertString(t, module.makeLinkType, test.expected)
2436 })
2437 }
2438}
2439
Jeff Gaston294356f2017-09-27 17:05:30 -07002440var staticLinkDepOrderTestCases = []struct {
2441 // This is a string representation of a map[moduleName][]moduleDependency .
2442 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002443 inStatic string
2444
2445 // This is a string representation of a map[moduleName][]moduleDependency .
2446 // It models the dependencies declared in an Android.bp file.
2447 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002448
2449 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2450 // The keys of allOrdered specify which modules we would like to check.
2451 // The values of allOrdered specify the expected result (of the transitive closure of all
2452 // dependencies) for each module to test
2453 allOrdered string
2454
2455 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2456 // The keys of outOrdered specify which modules we would like to check.
2457 // The values of outOrdered specify the expected result (of the ordered linker command line)
2458 // for each module to test.
2459 outOrdered string
2460}{
2461 // Simple tests
2462 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002463 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002464 outOrdered: "",
2465 },
2466 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002467 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002468 outOrdered: "a:",
2469 },
2470 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002471 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002472 outOrdered: "a:b; b:",
2473 },
2474 // Tests of reordering
2475 {
2476 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002477 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002478 outOrdered: "a:b,c,d; b:d; c:d; d:",
2479 },
2480 {
2481 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002482 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002483 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2484 },
2485 {
2486 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002487 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002488 outOrdered: "a:d,b,e,c; d:b; e:c",
2489 },
2490 {
2491 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002492 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002493 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2494 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2495 },
2496 {
2497 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002498 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 -07002499 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2500 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2501 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002502 // shared dependencies
2503 {
2504 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2505 // So, we don't actually have to check that a shared dependency of c will change the order
2506 // of a library that depends statically on b and on c. We only need to check that if c has
2507 // a shared dependency on b, that that shows up in allOrdered.
2508 inShared: "c:b",
2509 allOrdered: "c:b",
2510 outOrdered: "c:",
2511 },
2512 {
2513 // This test doesn't actually include any shared dependencies but it's a reminder of what
2514 // the second phase of the above test would look like
2515 inStatic: "a:b,c; c:b",
2516 allOrdered: "a:c,b; c:b",
2517 outOrdered: "a:c,b; c:b",
2518 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002519 // tiebreakers for when two modules specifying different orderings and there is no dependency
2520 // to dictate an order
2521 {
2522 // 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 -08002523 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002524 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2525 },
2526 {
2527 // 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 -08002528 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 -07002529 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2530 },
2531 // Tests involving duplicate dependencies
2532 {
2533 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002534 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002535 outOrdered: "a:c,b",
2536 },
2537 {
2538 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002539 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002540 outOrdered: "a:d,c,b",
2541 },
2542 // Tests to confirm the nonexistence of infinite loops.
2543 // These cases should never happen, so as long as the test terminates and the
2544 // result is deterministic then that should be fine.
2545 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002546 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002547 outOrdered: "a:a",
2548 },
2549 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002550 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002551 allOrdered: "a:b,c; b:c,a; c:a,b",
2552 outOrdered: "a:b; b:c; c:a",
2553 },
2554 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002555 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002556 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2557 outOrdered: "a:c,b; b:a,c; c:b,a",
2558 },
2559}
2560
2561// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2562func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2563 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2564 strippedText := strings.Replace(text, " ", "", -1)
2565 if len(strippedText) < 1 {
2566 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2567 }
2568 allDeps = make(map[android.Path][]android.Path, 0)
2569
2570 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2571 moduleTexts := strings.Split(strippedText, ";")
2572
2573 outputForModuleName := func(moduleName string) android.Path {
2574 return android.PathForTesting(moduleName)
2575 }
2576
2577 for _, moduleText := range moduleTexts {
2578 // convert from "a:b,c" to ["a", "b,c"]
2579 components := strings.Split(moduleText, ":")
2580 if len(components) != 2 {
2581 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2582 }
2583 moduleName := components[0]
2584 moduleOutput := outputForModuleName(moduleName)
2585 modulesInOrder = append(modulesInOrder, moduleOutput)
2586
2587 depString := components[1]
2588 // convert from "b,c" to ["b", "c"]
2589 depNames := strings.Split(depString, ",")
2590 if len(depString) < 1 {
2591 depNames = []string{}
2592 }
2593 var deps []android.Path
2594 for _, depName := range depNames {
2595 deps = append(deps, outputForModuleName(depName))
2596 }
2597 allDeps[moduleOutput] = deps
2598 }
2599 return modulesInOrder, allDeps
2600}
2601
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002602func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002603 ctx := testCc(t, `
2604 cc_library {
2605 name: "a",
2606 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002607 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002608 }
2609 cc_library {
2610 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002611 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002612 }
2613 cc_library {
2614 name: "c",
2615 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002616 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002617 }
2618 cc_library {
2619 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002620 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002621 }
2622
2623 `)
2624
Colin Cross7113d202019-11-20 16:39:12 -08002625 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002626 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002627 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2628 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002629 expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002630
2631 if !reflect.DeepEqual(actual, expected) {
2632 t.Errorf("staticDeps orderings were not propagated correctly"+
2633 "\nactual: %v"+
2634 "\nexpected: %v",
2635 actual,
2636 expected,
2637 )
2638 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002639}
Jeff Gaston294356f2017-09-27 17:05:30 -07002640
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002641func TestStaticLibDepReorderingWithShared(t *testing.T) {
2642 ctx := testCc(t, `
2643 cc_library {
2644 name: "a",
2645 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002646 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002647 }
2648 cc_library {
2649 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002650 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002651 }
2652 cc_library {
2653 name: "c",
2654 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002655 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002656 }
2657
2658 `)
2659
Colin Cross7113d202019-11-20 16:39:12 -08002660 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002661 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002662 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2663 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002664 expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002665
2666 if !reflect.DeepEqual(actual, expected) {
2667 t.Errorf("staticDeps orderings did not account for shared libs"+
2668 "\nactual: %v"+
2669 "\nexpected: %v",
2670 actual,
2671 expected,
2672 )
2673 }
2674}
2675
Jooyung Hanb04a4992020-03-13 18:57:35 +09002676func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002677 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002678 if !reflect.DeepEqual(actual, expected) {
2679 t.Errorf(message+
2680 "\nactual: %v"+
2681 "\nexpected: %v",
2682 actual,
2683 expected,
2684 )
2685 }
2686}
2687
Jooyung Han61b66e92020-03-21 14:21:46 +00002688func TestLlndkLibrary(t *testing.T) {
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002689 result := prepareForCcTest.RunTestWithBp(t, `
2690 cc_library {
2691 name: "libllndk",
2692 stubs: { versions: ["1", "2"] },
2693 llndk: {
2694 symbol_file: "libllndk.map.txt",
2695 },
2696 export_include_dirs: ["include"],
2697 }
2698
2699 cc_prebuilt_library_shared {
2700 name: "libllndkprebuilt",
2701 stubs: { versions: ["1", "2"] },
2702 llndk: {
2703 symbol_file: "libllndkprebuilt.map.txt",
2704 },
2705 }
2706
2707 cc_library {
2708 name: "libllndk_with_external_headers",
2709 stubs: { versions: ["1", "2"] },
2710 llndk: {
2711 symbol_file: "libllndk.map.txt",
2712 export_llndk_headers: ["libexternal_llndk_headers"],
2713 },
2714 header_libs: ["libexternal_headers"],
2715 export_header_lib_headers: ["libexternal_headers"],
2716 }
2717 cc_library_headers {
2718 name: "libexternal_headers",
2719 export_include_dirs: ["include"],
2720 vendor_available: true,
2721 }
2722 cc_library_headers {
2723 name: "libexternal_llndk_headers",
2724 export_include_dirs: ["include_llndk"],
2725 llndk: {
2726 symbol_file: "libllndk.map.txt",
2727 },
2728 vendor_available: true,
2729 }
2730
2731 cc_library {
2732 name: "libllndk_with_override_headers",
2733 stubs: { versions: ["1", "2"] },
2734 llndk: {
2735 symbol_file: "libllndk.map.txt",
2736 override_export_include_dirs: ["include_llndk"],
2737 },
2738 export_include_dirs: ["include"],
2739 }
2740 `)
2741 actual := result.ModuleVariantsForTests("libllndk")
2742 for i := 0; i < len(actual); i++ {
2743 if !strings.HasPrefix(actual[i], "android_vendor.29_") {
2744 actual = append(actual[:i], actual[i+1:]...)
2745 i--
2746 }
2747 }
2748 expected := []string{
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002749 "android_vendor.29_arm64_armv8-a_shared_current",
2750 "android_vendor.29_arm64_armv8-a_shared",
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002751 "android_vendor.29_arm_armv7-a-neon_shared_current",
2752 "android_vendor.29_arm_armv7-a-neon_shared",
2753 }
2754 android.AssertArrayString(t, "variants for llndk stubs", expected, actual)
2755
2756 params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
2757 android.AssertSame(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2758
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002759 checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) {
2760 t.Helper()
2761 m := result.ModuleForTests(module, variant).Module()
2762 f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
2763 android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]",
2764 expectedDirs, f.IncludeDirs)
2765 }
2766
2767 checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include")
2768 checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include")
2769 checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include")
2770 checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2771 checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include")
2772 checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2773}
2774
Jiyong Parka46a4d52017-12-14 19:54:34 +09002775func TestLlndkHeaders(t *testing.T) {
2776 ctx := testCc(t, `
Colin Cross627280f2021-04-26 16:53:58 -07002777 cc_library_headers {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002778 name: "libllndk_headers",
2779 export_include_dirs: ["my_include"],
Colin Cross627280f2021-04-26 16:53:58 -07002780 llndk: {
2781 llndk_headers: true,
2782 },
Jiyong Parka46a4d52017-12-14 19:54:34 +09002783 }
2784 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002785 name: "libllndk",
Colin Cross627280f2021-04-26 16:53:58 -07002786 llndk: {
2787 symbol_file: "libllndk.map.txt",
2788 export_llndk_headers: ["libllndk_headers"],
2789 }
Colin Cross0477b422020-10-13 18:43:54 -07002790 }
2791
2792 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002793 name: "libvendor",
2794 shared_libs: ["libllndk"],
2795 vendor: true,
2796 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002797 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002798 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002799 }
2800 `)
2801
2802 // _static variant is used since _shared reuses *.o from the static variant
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002803 cc := ctx.ModuleForTests("libvendor", "android_vendor.29_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002804 cflags := cc.Args["cFlags"]
2805 if !strings.Contains(cflags, "-Imy_include") {
2806 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2807 }
2808}
2809
Logan Chien43d34c32017-12-20 01:17:32 +08002810func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2811 actual := module.Properties.AndroidMkRuntimeLibs
2812 if !reflect.DeepEqual(actual, expected) {
2813 t.Errorf("incorrect runtime_libs for shared libs"+
2814 "\nactual: %v"+
2815 "\nexpected: %v",
2816 actual,
2817 expected,
2818 )
2819 }
2820}
2821
2822const runtimeLibAndroidBp = `
2823 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002824 name: "liball_available",
2825 vendor_available: true,
2826 product_available: true,
2827 no_libcrt : true,
2828 nocrt : true,
2829 system_shared_libs : [],
2830 }
2831 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002832 name: "libvendor_available1",
2833 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002834 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002835 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002836 nocrt : true,
2837 system_shared_libs : [],
2838 }
2839 cc_library {
2840 name: "libvendor_available2",
2841 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002842 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002843 target: {
2844 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002845 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002846 }
2847 },
Yi Konge7fe9912019-06-02 00:53:50 -07002848 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002849 nocrt : true,
2850 system_shared_libs : [],
2851 }
2852 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002853 name: "libproduct_vendor",
2854 product_specific: true,
2855 vendor_available: true,
2856 no_libcrt : true,
2857 nocrt : true,
2858 system_shared_libs : [],
2859 }
2860 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002861 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002862 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002863 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002864 nocrt : true,
2865 system_shared_libs : [],
2866 }
2867 cc_library {
2868 name: "libvendor1",
2869 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002870 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002871 nocrt : true,
2872 system_shared_libs : [],
2873 }
2874 cc_library {
2875 name: "libvendor2",
2876 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002877 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002878 no_libcrt : true,
2879 nocrt : true,
2880 system_shared_libs : [],
2881 }
2882 cc_library {
2883 name: "libproduct_available1",
2884 product_available: true,
2885 runtime_libs: ["liball_available"],
2886 no_libcrt : true,
2887 nocrt : true,
2888 system_shared_libs : [],
2889 }
2890 cc_library {
2891 name: "libproduct1",
2892 product_specific: true,
2893 no_libcrt : true,
2894 nocrt : true,
2895 system_shared_libs : [],
2896 }
2897 cc_library {
2898 name: "libproduct2",
2899 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002900 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002901 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002902 nocrt : true,
2903 system_shared_libs : [],
2904 }
2905`
2906
2907func TestRuntimeLibs(t *testing.T) {
2908 ctx := testCc(t, runtimeLibAndroidBp)
2909
2910 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002911 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002912
Justin Yun8a2600c2020-12-07 12:44:03 +09002913 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2914 checkRuntimeLibs(t, []string{"liball_available"}, module)
2915
2916 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2917 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002918
2919 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002920 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002921
2922 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2923 // and vendor variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002924 variant = "android_vendor.29_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002925
Justin Yun8a2600c2020-12-07 12:44:03 +09002926 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2927 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002928
2929 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002930 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002931
2932 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2933 // and product variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002934 variant = "android_product.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002935
2936 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2937 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2938
2939 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002940 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002941}
2942
2943func TestExcludeRuntimeLibs(t *testing.T) {
2944 ctx := testCc(t, runtimeLibAndroidBp)
2945
Colin Cross7113d202019-11-20 16:39:12 -08002946 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002947 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2948 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002949
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002950 variant = "android_vendor.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002951 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002952 checkRuntimeLibs(t, nil, module)
2953}
2954
2955func TestRuntimeLibsNoVndk(t *testing.T) {
2956 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2957
2958 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2959
Colin Cross7113d202019-11-20 16:39:12 -08002960 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002961
Justin Yun8a2600c2020-12-07 12:44:03 +09002962 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2963 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002964
2965 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002966 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002967
2968 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002969 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002970}
2971
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002972func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002973 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002974 actual := module.Properties.AndroidMkStaticLibs
2975 if !reflect.DeepEqual(actual, expected) {
2976 t.Errorf("incorrect static_libs"+
2977 "\nactual: %v"+
2978 "\nexpected: %v",
2979 actual,
2980 expected,
2981 )
2982 }
2983}
2984
2985const staticLibAndroidBp = `
2986 cc_library {
2987 name: "lib1",
2988 }
2989 cc_library {
2990 name: "lib2",
2991 static_libs: ["lib1"],
2992 }
2993`
2994
2995func TestStaticLibDepExport(t *testing.T) {
2996 ctx := testCc(t, staticLibAndroidBp)
2997
2998 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002999 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003000 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Ryan Prichardc2018e22021-04-02 20:23:22 -07003001 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003002
3003 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003004 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003005 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3006 // libc++_static is linked additionally.
Ryan Prichardc2018e22021-04-02 20:23:22 -07003007 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003008}
3009
Jiyong Parkd08b6972017-09-26 10:50:54 +09003010var compilerFlagsTestCases = []struct {
3011 in string
3012 out bool
3013}{
3014 {
3015 in: "a",
3016 out: false,
3017 },
3018 {
3019 in: "-a",
3020 out: true,
3021 },
3022 {
3023 in: "-Ipath/to/something",
3024 out: false,
3025 },
3026 {
3027 in: "-isystempath/to/something",
3028 out: false,
3029 },
3030 {
3031 in: "--coverage",
3032 out: false,
3033 },
3034 {
3035 in: "-include a/b",
3036 out: true,
3037 },
3038 {
3039 in: "-include a/b c/d",
3040 out: false,
3041 },
3042 {
3043 in: "-DMACRO",
3044 out: true,
3045 },
3046 {
3047 in: "-DMAC RO",
3048 out: false,
3049 },
3050 {
3051 in: "-a -b",
3052 out: false,
3053 },
3054 {
3055 in: "-DMACRO=definition",
3056 out: true,
3057 },
3058 {
3059 in: "-DMACRO=defi nition",
3060 out: true, // TODO(jiyong): this should be false
3061 },
3062 {
3063 in: "-DMACRO(x)=x + 1",
3064 out: true,
3065 },
3066 {
3067 in: "-DMACRO=\"defi nition\"",
3068 out: true,
3069 },
3070}
3071
3072type mockContext struct {
3073 BaseModuleContext
3074 result bool
3075}
3076
3077func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3078 // CheckBadCompilerFlags calls this function when the flag should be rejected
3079 ctx.result = false
3080}
3081
3082func TestCompilerFlags(t *testing.T) {
3083 for _, testCase := range compilerFlagsTestCases {
3084 ctx := &mockContext{result: true}
3085 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3086 if ctx.result != testCase.out {
3087 t.Errorf("incorrect output:")
3088 t.Errorf(" input: %#v", testCase.in)
3089 t.Errorf(" expected: %#v", testCase.out)
3090 t.Errorf(" got: %#v", ctx.result)
3091 }
3092 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003093}
Jiyong Park374510b2018-03-19 18:23:01 +09003094
Jiyong Park37b25202018-07-11 10:49:27 +09003095func TestRecovery(t *testing.T) {
3096 ctx := testCc(t, `
3097 cc_library_shared {
3098 name: "librecovery",
3099 recovery: true,
3100 }
3101 cc_library_shared {
3102 name: "librecovery32",
3103 recovery: true,
3104 compile_multilib:"32",
3105 }
Jiyong Park5baac542018-08-28 09:55:37 +09003106 cc_library_shared {
3107 name: "libHalInRecovery",
3108 recovery_available: true,
3109 vendor: true,
3110 }
Jiyong Park37b25202018-07-11 10:49:27 +09003111 `)
3112
3113 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003114 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003115 if len(variants) != 1 || !android.InList(arm64, variants) {
3116 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3117 }
3118
3119 variants = ctx.ModuleVariantsForTests("librecovery32")
3120 if android.InList(arm64, variants) {
3121 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3122 }
Jiyong Park5baac542018-08-28 09:55:37 +09003123
3124 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3125 if !recoveryModule.Platform() {
3126 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3127 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003128}
Jiyong Park5baac542018-08-28 09:55:37 +09003129
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003130func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3131 bp := `
3132 cc_prebuilt_test_library_shared {
3133 name: "test_lib",
3134 relative_install_path: "foo/bar/baz",
3135 srcs: ["srcpath/dontusethispath/baz.so"],
3136 }
3137
3138 cc_test {
3139 name: "main_test",
3140 data_libs: ["test_lib"],
3141 gtest: false,
3142 }
3143 `
3144
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003145 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003146 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003147 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003148 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3149
3150 ctx := testCcWithConfig(t, config)
3151 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3152 testBinary := module.(*Module).linker.(*testBinary)
3153 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3154 if err != nil {
3155 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3156 }
3157 if len(outputFiles) != 1 {
3158 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3159 }
3160 if len(testBinary.dataPaths()) != 1 {
3161 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3162 }
3163
3164 outputPath := outputFiles[0].String()
3165
3166 if !strings.HasSuffix(outputPath, "/main_test") {
3167 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3168 }
Colin Crossaa255532020-07-03 13:18:24 -07003169 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003170 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3171 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3172 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3173 }
3174}
3175
Jiyong Park7ed9de32018-10-15 22:25:07 +09003176func TestVersionedStubs(t *testing.T) {
3177 ctx := testCc(t, `
3178 cc_library_shared {
3179 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003180 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003181 stubs: {
3182 symbol_file: "foo.map.txt",
3183 versions: ["1", "2", "3"],
3184 },
3185 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003186
Jiyong Park7ed9de32018-10-15 22:25:07 +09003187 cc_library_shared {
3188 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003189 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003190 shared_libs: ["libFoo#1"],
3191 }`)
3192
3193 variants := ctx.ModuleVariantsForTests("libFoo")
3194 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003195 "android_arm64_armv8-a_shared",
3196 "android_arm64_armv8-a_shared_1",
3197 "android_arm64_armv8-a_shared_2",
3198 "android_arm64_armv8-a_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003199 "android_arm64_armv8-a_shared_current",
Colin Cross7113d202019-11-20 16:39:12 -08003200 "android_arm_armv7-a-neon_shared",
3201 "android_arm_armv7-a-neon_shared_1",
3202 "android_arm_armv7-a-neon_shared_2",
3203 "android_arm_armv7-a-neon_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003204 "android_arm_armv7-a-neon_shared_current",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003205 }
3206 variantsMismatch := false
3207 if len(variants) != len(expectedVariants) {
3208 variantsMismatch = true
3209 } else {
3210 for _, v := range expectedVariants {
3211 if !inList(v, variants) {
3212 variantsMismatch = false
3213 }
3214 }
3215 }
3216 if variantsMismatch {
3217 t.Errorf("variants of libFoo expected:\n")
3218 for _, v := range expectedVariants {
3219 t.Errorf("%q\n", v)
3220 }
3221 t.Errorf(", but got:\n")
3222 for _, v := range variants {
3223 t.Errorf("%q\n", v)
3224 }
3225 }
3226
Colin Cross7113d202019-11-20 16:39:12 -08003227 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003228 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003229 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003230 if !strings.Contains(libFlags, libFoo1StubPath) {
3231 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3232 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003233
Colin Cross7113d202019-11-20 16:39:12 -08003234 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003235 cFlags := libBarCompileRule.Args["cFlags"]
3236 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3237 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3238 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3239 }
Jiyong Park37b25202018-07-11 10:49:27 +09003240}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003241
Jooyung Hanb04a4992020-03-13 18:57:35 +09003242func TestVersioningMacro(t *testing.T) {
3243 for _, tc := range []struct{ moduleName, expected string }{
3244 {"libc", "__LIBC_API__"},
3245 {"libfoo", "__LIBFOO_API__"},
3246 {"libfoo@1", "__LIBFOO_1_API__"},
3247 {"libfoo-v1", "__LIBFOO_V1_API__"},
3248 {"libfoo.v1", "__LIBFOO_V1_API__"},
3249 } {
3250 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3251 }
3252}
3253
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003254func TestStaticExecutable(t *testing.T) {
3255 ctx := testCc(t, `
3256 cc_binary {
3257 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003258 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003259 static_executable: true,
3260 }`)
3261
Colin Cross7113d202019-11-20 16:39:12 -08003262 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003263 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3264 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003265 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003266 for _, lib := range systemStaticLibs {
3267 if !strings.Contains(libFlags, lib) {
3268 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3269 }
3270 }
3271 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3272 for _, lib := range systemSharedLibs {
3273 if strings.Contains(libFlags, lib) {
3274 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3275 }
3276 }
3277}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003278
3279func TestStaticDepsOrderWithStubs(t *testing.T) {
3280 ctx := testCc(t, `
3281 cc_binary {
3282 name: "mybin",
3283 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003284 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003285 static_executable: true,
3286 stl: "none",
3287 }
3288
3289 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003290 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003291 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003292 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003293 stl: "none",
3294 }
3295
3296 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003297 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003298 srcs: ["foo.c"],
3299 stl: "none",
3300 stubs: {
3301 versions: ["1"],
3302 },
3303 }`)
3304
Colin Cross0de8a1e2020-09-18 14:15:30 -07003305 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3306 actual := mybin.Implicits[:2]
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003307 expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003308
3309 if !reflect.DeepEqual(actual, expected) {
3310 t.Errorf("staticDeps orderings were not propagated correctly"+
3311 "\nactual: %v"+
3312 "\nexpected: %v",
3313 actual,
3314 expected,
3315 )
3316 }
3317}
Jooyung Han38002912019-05-16 04:01:54 +09003318
Jooyung Hand48f3c32019-08-23 11:18:57 +09003319func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3320 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3321 cc_library {
3322 name: "libA",
3323 srcs: ["foo.c"],
3324 shared_libs: ["libB"],
3325 stl: "none",
3326 }
3327
3328 cc_library {
3329 name: "libB",
3330 srcs: ["foo.c"],
3331 enabled: false,
3332 stl: "none",
3333 }
3334 `)
3335}
3336
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003337// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3338// correctly.
3339func TestFuzzTarget(t *testing.T) {
3340 ctx := testCc(t, `
3341 cc_fuzz {
3342 name: "fuzz_smoke_test",
3343 srcs: ["foo.c"],
3344 }`)
3345
Paul Duffin075c4172019-12-19 19:06:13 +00003346 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003347 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3348}
3349
Jiyong Park29074592019-07-07 16:27:47 +09003350func TestAidl(t *testing.T) {
3351}
3352
Jooyung Han38002912019-05-16 04:01:54 +09003353func assertString(t *testing.T, got, expected string) {
3354 t.Helper()
3355 if got != expected {
3356 t.Errorf("expected %q got %q", expected, got)
3357 }
3358}
3359
3360func assertArrayString(t *testing.T, got, expected []string) {
3361 t.Helper()
3362 if len(got) != len(expected) {
3363 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3364 return
3365 }
3366 for i := range got {
3367 if got[i] != expected[i] {
3368 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3369 i, expected[i], expected, got[i], got)
3370 return
3371 }
3372 }
3373}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003374
Jooyung Han0302a842019-10-30 18:43:49 +09003375func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3376 t.Helper()
3377 assertArrayString(t, android.SortedStringKeys(m), expected)
3378}
3379
Colin Crosse1bb5d02019-09-24 14:55:04 -07003380func TestDefaults(t *testing.T) {
3381 ctx := testCc(t, `
3382 cc_defaults {
3383 name: "defaults",
3384 srcs: ["foo.c"],
3385 static: {
3386 srcs: ["bar.c"],
3387 },
3388 shared: {
3389 srcs: ["baz.c"],
3390 },
Liz Kammer3cf52112021-03-31 15:42:03 -04003391 bazel_module: {
3392 bp2build_available: true,
3393 },
Colin Crosse1bb5d02019-09-24 14:55:04 -07003394 }
3395
3396 cc_library_static {
3397 name: "libstatic",
3398 defaults: ["defaults"],
3399 }
3400
3401 cc_library_shared {
3402 name: "libshared",
3403 defaults: ["defaults"],
3404 }
3405
3406 cc_library {
3407 name: "libboth",
3408 defaults: ["defaults"],
3409 }
3410
3411 cc_binary {
3412 name: "binary",
3413 defaults: ["defaults"],
3414 }`)
3415
3416 pathsToBase := func(paths android.Paths) []string {
3417 var ret []string
3418 for _, p := range paths {
3419 ret = append(ret, p.Base())
3420 }
3421 return ret
3422 }
3423
Colin Cross7113d202019-11-20 16:39:12 -08003424 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003425 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3426 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3427 }
Colin Cross7113d202019-11-20 16:39:12 -08003428 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003429 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3430 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3431 }
Colin Cross7113d202019-11-20 16:39:12 -08003432 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003433 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3434 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3435 }
3436
Colin Cross7113d202019-11-20 16:39:12 -08003437 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003438 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3439 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3440 }
Colin Cross7113d202019-11-20 16:39:12 -08003441 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003442 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3443 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3444 }
3445}
Colin Crosseabaedd2020-02-06 17:01:55 -08003446
3447func TestProductVariableDefaults(t *testing.T) {
3448 bp := `
3449 cc_defaults {
3450 name: "libfoo_defaults",
3451 srcs: ["foo.c"],
3452 cppflags: ["-DFOO"],
3453 product_variables: {
3454 debuggable: {
3455 cppflags: ["-DBAR"],
3456 },
3457 },
3458 }
3459
3460 cc_library {
3461 name: "libfoo",
3462 defaults: ["libfoo_defaults"],
3463 }
3464 `
3465
Paul Duffin8567f222021-03-23 00:02:06 +00003466 result := android.GroupFixturePreparers(
3467 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003468 android.PrepareForTestWithVariables,
Colin Crosseabaedd2020-02-06 17:01:55 -08003469
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003470 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3471 variables.Debuggable = BoolPtr(true)
3472 }),
3473 ).RunTestWithBp(t, bp)
Colin Crosseabaedd2020-02-06 17:01:55 -08003474
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003475 libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
Paul Duffine84b1332021-03-12 11:59:43 +00003476 android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
Colin Crosseabaedd2020-02-06 17:01:55 -08003477}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003478
3479func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3480 t.Parallel()
3481 bp := `
3482 cc_library_static {
3483 name: "libfoo",
3484 srcs: ["foo.c"],
3485 whole_static_libs: ["libbar"],
3486 }
3487
3488 cc_library_static {
3489 name: "libbar",
3490 whole_static_libs: ["libmissing"],
3491 }
3492 `
3493
Paul Duffin8567f222021-03-23 00:02:06 +00003494 result := android.GroupFixturePreparers(
3495 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003496 android.PrepareForTestWithAllowMissingDependencies,
3497 ).RunTestWithBp(t, bp)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003498
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003499 libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003500 android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003501
Paul Duffine84b1332021-03-12 11:59:43 +00003502 android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
Colin Crosse4f6eba2020-09-22 18:11:25 -07003503
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003504 libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003505 android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
Colin Crosse4f6eba2020-09-22 18:11:25 -07003506}
Colin Crosse9fe2942020-11-10 18:12:15 -08003507
3508func TestInstallSharedLibs(t *testing.T) {
3509 bp := `
3510 cc_binary {
3511 name: "bin",
3512 host_supported: true,
3513 shared_libs: ["libshared"],
3514 runtime_libs: ["libruntime"],
3515 srcs: [":gen"],
3516 }
3517
3518 cc_library_shared {
3519 name: "libshared",
3520 host_supported: true,
3521 shared_libs: ["libtransitive"],
3522 }
3523
3524 cc_library_shared {
3525 name: "libtransitive",
3526 host_supported: true,
3527 }
3528
3529 cc_library_shared {
3530 name: "libruntime",
3531 host_supported: true,
3532 }
3533
3534 cc_binary_host {
3535 name: "tool",
3536 srcs: ["foo.cpp"],
3537 }
3538
3539 genrule {
3540 name: "gen",
3541 tools: ["tool"],
3542 out: ["gen.cpp"],
3543 cmd: "$(location tool) $(out)",
3544 }
3545 `
3546
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003547 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Crosse9fe2942020-11-10 18:12:15 -08003548 ctx := testCcWithConfig(t, config)
3549
3550 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3551 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3552 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3553 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3554 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3555
3556 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3557 t.Errorf("expected host bin dependency %q, got %q", w, g)
3558 }
3559
3560 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3561 t.Errorf("expected host bin dependency %q, got %q", w, g)
3562 }
3563
3564 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3565 t.Errorf("expected host bin dependency %q, got %q", w, g)
3566 }
3567
3568 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3569 t.Errorf("expected host bin dependency %q, got %q", w, g)
3570 }
3571
3572 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3573 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3574 }
3575
3576 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3577 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3578 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3579 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3580
3581 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3582 t.Errorf("expected device bin dependency %q, got %q", w, g)
3583 }
3584
3585 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3586 t.Errorf("expected device bin dependency %q, got %q", w, g)
3587 }
3588
3589 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3590 t.Errorf("expected device bin dependency %q, got %q", w, g)
3591 }
3592
3593 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3594 t.Errorf("expected device bin dependency %q, got %q", w, g)
3595 }
3596
3597 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3598 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3599 }
3600
3601}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003602
3603func TestStubsLibReexportsHeaders(t *testing.T) {
3604 ctx := testCc(t, `
3605 cc_library_shared {
3606 name: "libclient",
3607 srcs: ["foo.c"],
3608 shared_libs: ["libfoo#1"],
3609 }
3610
3611 cc_library_shared {
3612 name: "libfoo",
3613 srcs: ["foo.c"],
3614 shared_libs: ["libbar"],
3615 export_shared_lib_headers: ["libbar"],
3616 stubs: {
3617 symbol_file: "foo.map.txt",
3618 versions: ["1", "2", "3"],
3619 },
3620 }
3621
3622 cc_library_shared {
3623 name: "libbar",
3624 export_include_dirs: ["include/libbar"],
3625 srcs: ["foo.c"],
3626 }`)
3627
3628 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3629
3630 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3631 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3632 }
3633}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003634
3635func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3636 ctx := testCc(t, `
3637 cc_library {
3638 name: "libfoo",
3639 srcs: ["a/Foo.aidl"],
3640 aidl: { flags: ["-Werror"], },
3641 }
3642 `)
3643
3644 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3645 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3646 aidlCommand := manifest.Commands[0].GetCommand()
3647 expectedAidlFlag := "-Werror"
3648 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3649 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3650 }
3651}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003652
Jiyong Parka008fb02021-03-16 17:15:53 +09003653func TestMinSdkVersionInClangTriple(t *testing.T) {
3654 ctx := testCc(t, `
3655 cc_library_shared {
3656 name: "libfoo",
3657 srcs: ["foo.c"],
3658 min_sdk_version: "29",
3659 }`)
3660
3661 cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3662 android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
3663}
3664
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003665type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003666
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003667const (
3668 None MemtagNoteType = iota + 1
3669 Sync
3670 Async
3671)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003672
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003673func (t MemtagNoteType) str() string {
3674 switch t {
3675 case None:
3676 return "none"
3677 case Sync:
3678 return "sync"
3679 case Async:
3680 return "async"
3681 default:
3682 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003683 }
3684}
3685
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003686func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3687 note_async := "note_memtag_heap_async"
3688 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003689
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003690 found := None
3691 implicits := m.Rule("ld").Implicits
3692 for _, lib := range implicits {
3693 if strings.Contains(lib.Rel(), note_async) {
3694 found = Async
3695 break
3696 } else if strings.Contains(lib.Rel(), note_sync) {
3697 found = Sync
3698 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003699 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003700 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003701
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003702 if found != expected {
3703 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3704 }
3705}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003706
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003707var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
3708 android.FixtureModifyMockFS(func(fs android.MockFS) {
3709 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003710 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003711 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003712 gtest: false,
3713 }
3714
3715 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003716 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003717 gtest: false,
3718 sanitize: { memtag_heap: false },
3719 }
3720
3721 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003722 name: "%[1]s_test_true",
3723 gtest: false,
3724 sanitize: { memtag_heap: true },
3725 }
3726
3727 cc_test {
3728 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003729 gtest: false,
3730 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3731 }
3732
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003733 cc_test {
3734 name: "%[1]s_test_true_diag",
3735 gtest: false,
3736 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3737 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003738
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003739 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003740 name: "%[1]s_binary",
3741 }
3742
3743 cc_binary {
3744 name: "%[1]s_binary_false",
3745 sanitize: { memtag_heap: false },
3746 }
3747
3748 cc_binary {
3749 name: "%[1]s_binary_true",
3750 sanitize: { memtag_heap: true },
3751 }
3752
3753 cc_binary {
3754 name: "%[1]s_binary_true_nodiag",
3755 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3756 }
3757
3758 cc_binary {
3759 name: "%[1]s_binary_true_diag",
3760 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003761 }
3762 `
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003763 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3764 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3765 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3766 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003767
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003768 fs.Merge(android.MockFS{
3769 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3770 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3771 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3772 "subdir_async/Android.bp": []byte(subdirAsyncBp),
3773 })
3774 }),
3775 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3776 variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07003777 // "subdir_exclude" is covered by both include and exclude paths. Exclude wins.
3778 variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync", "subdir_exclude"}
3779 variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async", "subdir_exclude"}
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003780 }),
3781)
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003782
3783func TestSanitizeMemtagHeap(t *testing.T) {
3784 variant := "android_arm64_armv8-a"
3785
Paul Duffin8567f222021-03-23 00:02:06 +00003786 result := android.GroupFixturePreparers(
3787 prepareForCcTest,
3788 prepareForTestWithMemtagHeap,
3789 ).RunTest(t)
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003790 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003791
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003792 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3793 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3794 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3795 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3796 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3797
3798 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
3799 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3800 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3801 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3802 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3803
3804 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3805 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3806 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3807 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3808 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3809
3810 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3811 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3812 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3813 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3814 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3815
3816 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3817 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3818 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3819 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3820 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3821
3822 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3823 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3824 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3825 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3826 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3827
3828 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3829 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3830 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3831 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3832 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3833
3834 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3835 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3836 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3837 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3838 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3839}
3840
3841func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003842 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003843
Paul Duffin8567f222021-03-23 00:02:06 +00003844 result := android.GroupFixturePreparers(
3845 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003846 prepareForTestWithMemtagHeap,
3847 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3848 variables.SanitizeDevice = []string{"memtag_heap"}
3849 }),
3850 ).RunTest(t)
3851 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003852
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003853 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3854 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3855 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
3856 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3857 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003858
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003859 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
3860 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3861 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
3862 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3863 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3864
3865 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3866 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3867 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
3868 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3869 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3870
3871 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3872 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3873 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
3874 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3875 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3876
3877 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3878 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3879 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
3880 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3881 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3882
3883 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
3884 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3885 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
3886 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3887 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3888
3889 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3890 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3891 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3892 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3893 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3894
3895 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3896 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3897 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3898 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3899 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
3900}
3901
3902func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
3903 variant := "android_arm64_armv8-a"
3904
Paul Duffin8567f222021-03-23 00:02:06 +00003905 result := android.GroupFixturePreparers(
3906 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003907 prepareForTestWithMemtagHeap,
3908 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3909 variables.SanitizeDevice = []string{"memtag_heap"}
3910 variables.SanitizeDeviceDiag = []string{"memtag_heap"}
3911 }),
3912 ).RunTest(t)
3913 ctx := result.TestContext
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003914
3915 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
3916 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
3917 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
3918 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
3919 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
3920
3921 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
3922 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
3923 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
3924 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
3925 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
3926
3927 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
3928 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
3929 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
3930 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
3931 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
3932
3933 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
3934 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
3935 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
3936 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
3937 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
3938
3939 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
3940 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
3941 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
3942 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
3943 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
3944
3945 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
3946 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
3947 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
3948 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
3949 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
3950
3951 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
3952 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
3953 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
3954 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
3955 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
3956
3957 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
3958 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
3959 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
3960 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
3961 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003962}
Paul Duffin3cb603e2021-02-19 13:57:10 +00003963
3964func TestIncludeDirsExporting(t *testing.T) {
3965
3966 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3967 // embedded newline characters alone.
3968 trimIndentingSpaces := func(s string) string {
3969 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3970 }
3971
3972 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3973 t.Helper()
3974 expected = trimIndentingSpaces(expected)
3975 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3976 if expected != actual {
3977 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3978 }
3979 }
3980
3981 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3982
3983 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3984 t.Helper()
3985 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3986 name := module.Name()
3987
3988 for _, checker := range checkers {
3989 checker(t, name, exported)
3990 }
3991 }
3992
3993 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3994 return func(t *testing.T, name string, exported FlagExporterInfo) {
3995 t.Helper()
3996 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3997 }
3998 }
3999
4000 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
4001 return func(t *testing.T, name string, exported FlagExporterInfo) {
4002 t.Helper()
4003 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
4004 }
4005 }
4006
4007 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
4008 return func(t *testing.T, name string, exported FlagExporterInfo) {
4009 t.Helper()
4010 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
4011 }
4012 }
4013
4014 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
4015 return func(t *testing.T, name string, exported FlagExporterInfo) {
4016 t.Helper()
4017 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
4018 }
4019 }
4020
4021 genRuleModules := `
4022 genrule {
4023 name: "genrule_foo",
4024 cmd: "generate-foo",
4025 out: [
4026 "generated_headers/foo/generated_header.h",
4027 ],
4028 export_include_dirs: [
4029 "generated_headers",
4030 ],
4031 }
4032
4033 genrule {
4034 name: "genrule_bar",
4035 cmd: "generate-bar",
4036 out: [
4037 "generated_headers/bar/generated_header.h",
4038 ],
4039 export_include_dirs: [
4040 "generated_headers",
4041 ],
4042 }
4043 `
4044
4045 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
4046 ctx := testCc(t, genRuleModules+`
4047 cc_library {
4048 name: "libfoo",
4049 srcs: ["foo.c"],
4050 export_include_dirs: ["foo/standard"],
4051 export_system_include_dirs: ["foo/system"],
4052 generated_headers: ["genrule_foo"],
4053 export_generated_headers: ["genrule_foo"],
4054 }
4055
4056 cc_library {
4057 name: "libbar",
4058 srcs: ["bar.c"],
4059 shared_libs: ["libfoo"],
4060 export_include_dirs: ["bar/standard"],
4061 export_system_include_dirs: ["bar/system"],
4062 generated_headers: ["genrule_bar"],
4063 export_generated_headers: ["genrule_bar"],
4064 }
4065 `)
4066 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4067 checkIncludeDirs(t, ctx, foo,
4068 expectedIncludeDirs(`
4069 foo/standard
4070 .intermediates/genrule_foo/gen/generated_headers
4071 `),
4072 expectedSystemIncludeDirs(`foo/system`),
4073 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4074 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4075 )
4076
4077 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4078 checkIncludeDirs(t, ctx, bar,
4079 expectedIncludeDirs(`
4080 bar/standard
4081 .intermediates/genrule_bar/gen/generated_headers
4082 `),
4083 expectedSystemIncludeDirs(`bar/system`),
4084 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4085 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4086 )
4087 })
4088
4089 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4090 ctx := testCc(t, genRuleModules+`
4091 cc_library {
4092 name: "libfoo",
4093 srcs: ["foo.c"],
4094 export_include_dirs: ["foo/standard"],
4095 export_system_include_dirs: ["foo/system"],
4096 generated_headers: ["genrule_foo"],
4097 export_generated_headers: ["genrule_foo"],
4098 }
4099
4100 cc_library {
4101 name: "libbar",
4102 srcs: ["bar.c"],
4103 whole_static_libs: ["libfoo"],
4104 export_include_dirs: ["bar/standard"],
4105 export_system_include_dirs: ["bar/system"],
4106 generated_headers: ["genrule_bar"],
4107 export_generated_headers: ["genrule_bar"],
4108 }
4109 `)
4110 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4111 checkIncludeDirs(t, ctx, foo,
4112 expectedIncludeDirs(`
4113 foo/standard
4114 .intermediates/genrule_foo/gen/generated_headers
4115 `),
4116 expectedSystemIncludeDirs(`foo/system`),
4117 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4118 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4119 )
4120
4121 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4122 checkIncludeDirs(t, ctx, bar,
4123 expectedIncludeDirs(`
4124 bar/standard
4125 foo/standard
4126 .intermediates/genrule_foo/gen/generated_headers
4127 .intermediates/genrule_bar/gen/generated_headers
4128 `),
4129 expectedSystemIncludeDirs(`
4130 bar/system
4131 foo/system
4132 `),
4133 expectedGeneratedHeaders(`
4134 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4135 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4136 `),
4137 expectedOrderOnlyDeps(`
4138 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4139 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4140 `),
4141 )
4142 })
4143
Paul Duffin3cb603e2021-02-19 13:57:10 +00004144 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4145 ctx := testCc(t, genRuleModules+`
4146 cc_library_shared {
4147 name: "libfoo",
4148 srcs: [
4149 "foo.c",
4150 "b.aidl",
4151 "a.proto",
4152 ],
4153 aidl: {
4154 export_aidl_headers: true,
4155 }
4156 }
4157 `)
4158 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4159 checkIncludeDirs(t, ctx, foo,
4160 expectedIncludeDirs(`
4161 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4162 `),
4163 expectedSystemIncludeDirs(``),
4164 expectedGeneratedHeaders(`
4165 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4166 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4167 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004168 `),
4169 expectedOrderOnlyDeps(`
4170 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4171 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4172 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004173 `),
4174 )
4175 })
4176
Paul Duffin3cb603e2021-02-19 13:57:10 +00004177 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4178 ctx := testCc(t, genRuleModules+`
4179 cc_library_shared {
4180 name: "libfoo",
4181 srcs: [
4182 "foo.c",
4183 "b.aidl",
4184 "a.proto",
4185 ],
4186 proto: {
4187 export_proto_headers: true,
4188 }
4189 }
4190 `)
4191 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4192 checkIncludeDirs(t, ctx, foo,
4193 expectedIncludeDirs(`
4194 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4195 `),
4196 expectedSystemIncludeDirs(``),
4197 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004198 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4199 `),
4200 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004201 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4202 `),
4203 )
4204 })
4205
Paul Duffin33056e82021-02-19 13:49:08 +00004206 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004207 ctx := testCc(t, genRuleModules+`
4208 cc_library_shared {
4209 name: "libfoo",
4210 srcs: [
4211 "foo.c",
4212 "a.sysprop",
4213 "b.aidl",
4214 "a.proto",
4215 ],
4216 }
4217 `)
4218 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4219 checkIncludeDirs(t, ctx, foo,
4220 expectedIncludeDirs(`
4221 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4222 `),
4223 expectedSystemIncludeDirs(``),
4224 expectedGeneratedHeaders(`
4225 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004226 `),
4227 expectedOrderOnlyDeps(`
4228 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4229 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004230 `),
4231 )
4232 })
4233}
Colin Crossae628182021-06-14 16:52:28 -07004234
4235func TestIncludeDirectoryOrdering(t *testing.T) {
4236 bp := `
4237 cc_library {
4238 name: "libfoo",
4239 srcs: ["foo.c"],
4240 local_include_dirs: ["local_include_dirs"],
4241 export_include_dirs: ["export_include_dirs"],
4242 export_system_include_dirs: ["export_system_include_dirs"],
4243 static_libs: ["libstatic1", "libstatic2"],
4244 whole_static_libs: ["libwhole1", "libwhole2"],
4245 shared_libs: ["libshared1", "libshared2"],
4246 header_libs: ["libheader1", "libheader2"],
4247 target: {
4248 android: {
4249 shared_libs: ["libandroid"],
4250 local_include_dirs: ["android_local_include_dirs"],
4251 export_include_dirs: ["android_export_include_dirs"],
4252 },
4253 android_arm: {
4254 shared_libs: ["libandroid_arm"],
4255 local_include_dirs: ["android_arm_local_include_dirs"],
4256 export_include_dirs: ["android_arm_export_include_dirs"],
4257 },
4258 linux: {
4259 shared_libs: ["liblinux"],
4260 local_include_dirs: ["linux_local_include_dirs"],
4261 export_include_dirs: ["linux_export_include_dirs"],
4262 },
4263 },
4264 multilib: {
4265 lib32: {
4266 shared_libs: ["lib32"],
4267 local_include_dirs: ["lib32_local_include_dirs"],
4268 export_include_dirs: ["lib32_export_include_dirs"],
4269 },
4270 },
4271 arch: {
4272 arm: {
4273 shared_libs: ["libarm"],
4274 local_include_dirs: ["arm_local_include_dirs"],
4275 export_include_dirs: ["arm_export_include_dirs"],
4276 },
4277 },
4278 stl: "libc++",
4279 sdk_version: "20",
4280 }
4281
4282 cc_library_headers {
4283 name: "libheader1",
4284 export_include_dirs: ["libheader1"],
4285 sdk_version: "20",
4286 stl: "none",
4287 }
4288
4289 cc_library_headers {
4290 name: "libheader2",
4291 export_include_dirs: ["libheader2"],
4292 sdk_version: "20",
4293 stl: "none",
4294 }
4295 `
4296
4297 libs := []string{
4298 "libstatic1",
4299 "libstatic2",
4300 "libwhole1",
4301 "libwhole2",
4302 "libshared1",
4303 "libshared2",
4304 "libandroid",
4305 "libandroid_arm",
4306 "liblinux",
4307 "lib32",
4308 "libarm",
4309 }
4310
4311 for _, lib := range libs {
4312 bp += fmt.Sprintf(`
4313 cc_library {
4314 name: "%s",
4315 export_include_dirs: ["%s"],
4316 sdk_version: "20",
4317 stl: "none",
4318 }
4319 `, lib, lib)
4320 }
4321
4322 ctx := PrepareForIntegrationTestWithCc.RunTestWithBp(t, bp)
4323 // Use the arm variant instead of the arm64 variant so that it gets headers from
4324 // ndk_libandroid_support to test LateStaticLibs.
4325 cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/foo.o").Args["cFlags"]
4326
4327 var includes []string
4328 flags := strings.Split(cflags, " ")
4329 for i, flag := range flags {
4330 if strings.Contains(flag, "Cflags") {
4331 includes = append(includes, flag)
4332 } else if strings.HasPrefix(flag, "-I") {
4333 includes = append(includes, strings.TrimPrefix(flag, "-I"))
4334 } else if flag == "-isystem" {
4335 includes = append(includes, flags[i+1])
4336 }
4337 }
4338
4339 want := []string{
4340 "${config.ArmClangThumbCflags}",
4341 "${config.ArmClangCflags}",
4342 "${config.CommonClangGlobalCflags}",
4343 "${config.DeviceClangGlobalCflags}",
4344 "${config.ClangExternalCflags}",
4345 "${config.ArmToolchainClangCflags}",
4346 "${config.ArmClangArmv7ANeonCflags}",
4347 "${config.ArmClangGenericCflags}",
4348 "export_include_dirs",
4349 "linux_export_include_dirs",
4350 "android_export_include_dirs",
4351 "arm_export_include_dirs",
4352 "lib32_export_include_dirs",
4353 "android_arm_export_include_dirs",
4354 "android_arm_local_include_dirs",
4355 "lib32_local_include_dirs",
4356 "arm_local_include_dirs",
4357 "android_local_include_dirs",
4358 "linux_local_include_dirs",
4359 "local_include_dirs",
4360 ".",
4361 "libheader1",
4362 "libheader2",
4363 "libwhole1",
4364 "libwhole2",
4365 "libstatic1",
4366 "libstatic2",
4367 "libshared1",
4368 "libshared2",
4369 "liblinux",
4370 "libandroid",
4371 "libarm",
4372 "lib32",
4373 "libandroid_arm",
Colin Crossae628182021-06-14 16:52:28 -07004374 "defaults/cc/common/ndk_libc++_shared",
Colin Crossc113e3c2021-06-14 16:15:15 -07004375 "defaults/cc/common/ndk_libandroid_support",
Colin Crossae628182021-06-14 16:52:28 -07004376 "out/soong/ndk/sysroot/usr/include",
4377 "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
4378 "${config.NoOverrideClangGlobalCflags}",
4379 }
4380
4381 android.AssertArrayString(t, "includes", want, includes)
4382}