blob: c56643b23b046b45acb1d19cedd09bd20386bb6d [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 }
384 if mod.isVndkSp() != isVndkSp {
385 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
386 }
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
Jose Galmes0a942a02021-02-03 14:23:15 -0800399func checkSnapshotIncludeExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string, include bool, fake bool) {
Bill Peckham945441c2020-08-31 16:07:58 -0700400 t.Helper()
Paul Duffine8366da2021-03-24 10:40:38 +0000401 mod := ctx.ModuleForTests(moduleName, variant)
402 outputFiles := mod.OutputFiles(t, "")
403 if len(outputFiles) != 1 {
Jooyung Han39edb6c2019-11-06 16:53:07 +0900404 t.Errorf("%q must have single output\n", moduleName)
405 return
406 }
407 snapshotPath := filepath.Join(subDir, snapshotFilename)
Inseob Kim1f086e22019-05-09 13:29:15 +0900408
Bill Peckham945441c2020-08-31 16:07:58 -0700409 if include {
410 out := singleton.Output(snapshotPath)
Jose Galmes0a942a02021-02-03 14:23:15 -0800411 if fake {
412 if out.Rule == nil {
413 t.Errorf("Missing rule for module %q output file %q", moduleName, outputFiles[0])
414 }
415 } else {
416 if out.Input.String() != outputFiles[0].String() {
417 t.Errorf("The input of snapshot %q must be %q, but %q", moduleName, out.Input.String(), outputFiles[0])
418 }
Bill Peckham945441c2020-08-31 16:07:58 -0700419 }
420 } else {
421 out := singleton.MaybeOutput(snapshotPath)
422 if out.Rule != nil {
423 t.Errorf("There must be no rule for module %q output file %q", moduleName, outputFiles[0])
424 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900425 }
426}
427
Bill Peckham945441c2020-08-31 16:07:58 -0700428func checkSnapshot(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Paul Duffine8366da2021-03-24 10:40:38 +0000429 t.Helper()
Jose Galmes0a942a02021-02-03 14:23:15 -0800430 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, false)
Bill Peckham945441c2020-08-31 16:07:58 -0700431}
432
433func checkSnapshotExclude(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Paul Duffine8366da2021-03-24 10:40:38 +0000434 t.Helper()
Jose Galmes0a942a02021-02-03 14:23:15 -0800435 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, false, false)
436}
437
438func checkSnapshotRule(t *testing.T, ctx *android.TestContext, singleton android.TestingSingleton, moduleName, snapshotFilename, subDir, variant string) {
Paul Duffine8366da2021-03-24 10:40:38 +0000439 t.Helper()
Jose Galmes0a942a02021-02-03 14:23:15 -0800440 checkSnapshotIncludeExclude(t, ctx, singleton, moduleName, snapshotFilename, subDir, variant, true, true)
Bill Peckham945441c2020-08-31 16:07:58 -0700441}
442
Jooyung Han2216fb12019-11-06 16:46:15 +0900443func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
444 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800445 content := android.ContentFromFileRuleForTests(t, params)
446 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900447 assertArrayString(t, actual, expected)
448}
449
Jooyung Han097087b2019-10-22 19:32:18 +0900450func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
451 t.Helper()
452 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900453 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
454}
455
456func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
457 t.Helper()
Colin Cross78212242021-01-06 14:51:30 -0800458 got := ctx.ModuleForTests(module, "").Module().(*vndkLibrariesTxt).fileNames
459 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900460}
461
Logan Chienf3511742017-10-31 18:04:35 +0800462func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800463 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800464 cc_library {
465 name: "libvndk",
466 vendor_available: true,
467 vndk: {
468 enabled: true,
469 },
470 nocrt: true,
471 }
472
473 cc_library {
474 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900475 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800476 vndk: {
477 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900478 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800479 },
480 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900481 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800482 }
483
484 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900485 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800486 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900487 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800488 vndk: {
489 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900490 },
491 nocrt: true,
492 target: {
493 vendor: {
494 cflags: ["-DTEST"],
495 },
496 product: {
497 cflags: ["-DTEST"],
498 },
499 },
500 }
501
502 cc_library {
503 name: "libvndk_sp",
504 vendor_available: true,
505 vndk: {
506 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800507 support_system_process: true,
508 },
509 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900510 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800511 }
512
513 cc_library {
514 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900515 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800516 vndk: {
517 enabled: true,
518 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900519 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800520 },
521 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900522 target: {
523 vendor: {
524 suffix: "-x",
525 },
526 },
Logan Chienf3511742017-10-31 18:04:35 +0800527 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900528
529 cc_library {
530 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900531 vendor_available: true,
532 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900533 vndk: {
534 enabled: true,
535 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900536 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900537 },
538 nocrt: true,
539 target: {
540 vendor: {
541 suffix: "-x",
542 },
543 product: {
544 suffix: "-x",
545 },
546 },
547 }
548
Justin Yun450ae722021-04-16 19:58:18 +0900549 cc_library {
550 name: "libllndk",
551 llndk_stubs: "libllndk.llndk",
552 }
553
554 llndk_library {
555 name: "libllndk.llndk",
556 symbol_file: "",
557 export_llndk_headers: ["libllndk_headers"],
558 }
559
560 llndk_headers {
561 name: "libllndk_headers",
562 export_include_dirs: ["include"],
563 }
564
Colin Crosse4e44bc2020-12-28 13:50:21 -0800565 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900566 name: "llndk.libraries.txt",
567 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800568 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900569 name: "vndkcore.libraries.txt",
570 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800571 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900572 name: "vndksp.libraries.txt",
573 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800574 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900575 name: "vndkprivate.libraries.txt",
576 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800577 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900578 name: "vndkproduct.libraries.txt",
579 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800580 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900581 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800582 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900583 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800584 `
585
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000586 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800587 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900588 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900589 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800590
591 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800592
Jooyung Han261e1582020-10-20 18:54:21 +0900593 // subdir == "" because VNDK libs are not supposed to be installed separately.
594 // They are installed as part of VNDK APEX instead.
595 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
596 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900597 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900598 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
599 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900600 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900601
Justin Yun6977e8a2020-10-29 18:24:11 +0900602 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
603 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900604
Inseob Kim1f086e22019-05-09 13:29:15 +0900605 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900606 snapshotDir := "vndk-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000607 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Inseob Kim1f086e22019-05-09 13:29:15 +0900608
609 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
610 "arm64", "armv8-a"))
611 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
612 "arm", "armv7-a-neon"))
613
614 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
615 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900616 llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub")
617
Inseob Kim1f086e22019-05-09 13:29:15 +0900618 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
619 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900620 llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub")
Inseob Kim1f086e22019-05-09 13:29:15 +0900621
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900622 variant := "android_vendor.29_arm64_armv8-a_shared"
623 variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900624
Inseob Kim7f283f42020-06-01 21:53:49 +0900625 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
626
627 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
628 checkSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
Justin Yun6977e8a2020-10-29 18:24:11 +0900629 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
630 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
Inseob Kim7f283f42020-06-01 21:53:49 +0900631 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
632 checkSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
Justin Yun450ae722021-04-16 19:58:18 +0900633 checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant)
634 checkSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900635
Jooyung Han39edb6c2019-11-06 16:53:07 +0900636 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Inseob Kim7f283f42020-06-01 21:53:49 +0900637 checkSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "")
638 checkSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "")
639 checkSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "")
640 checkSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "")
Justin Yun8a2600c2020-12-07 12:44:03 +0900641 checkSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900642
Jooyung Han097087b2019-10-22 19:32:18 +0900643 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
644 "LLNDK: libc.so",
645 "LLNDK: libdl.so",
646 "LLNDK: libft2.so",
Justin Yun450ae722021-04-16 19:58:18 +0900647 "LLNDK: libllndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900648 "LLNDK: libm.so",
649 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900650 "VNDK-SP: libvndk_sp-x.so",
651 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900652 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900653 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900654 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900655 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900656 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900657 "VNDK-private: libvndk-private.so",
658 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900659 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900660 "VNDK-product: libc++.so",
661 "VNDK-product: libvndk_product.so",
662 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900663 })
Justin Yun450ae722021-04-16 19:58:18 +0900664 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900665 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
666 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
667 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 +0900668 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 +0900669 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
670}
671
Yo Chiangbba545e2020-06-09 16:15:37 +0800672func TestVndkWithHostSupported(t *testing.T) {
673 ctx := testCc(t, `
674 cc_library {
675 name: "libvndk_host_supported",
676 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900677 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800678 vndk: {
679 enabled: true,
680 },
681 host_supported: true,
682 }
683
684 cc_library {
685 name: "libvndk_host_supported_but_disabled_on_device",
686 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900687 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800688 vndk: {
689 enabled: true,
690 },
691 host_supported: true,
692 enabled: false,
693 target: {
694 host: {
695 enabled: true,
696 }
697 }
698 }
699
Colin Crosse4e44bc2020-12-28 13:50:21 -0800700 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800701 name: "vndkcore.libraries.txt",
702 }
703 `)
704
705 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
706}
707
Jooyung Han2216fb12019-11-06 16:46:15 +0900708func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800709 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800710 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900711 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800712 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800713 }`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000714 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800715 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900716 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800717 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900718
719 module := ctx.ModuleForTests("llndk.libraries.txt", "")
Colin Crossaa255532020-07-03 13:18:24 -0700720 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900721 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900722}
723
724func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800725 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900726 cc_library {
727 name: "libvndk",
728 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900729 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900730 vndk: {
731 enabled: true,
732 },
733 nocrt: true,
734 }
735
736 cc_library {
737 name: "libvndk_sp",
738 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900739 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900740 vndk: {
741 enabled: true,
742 support_system_process: true,
743 },
744 nocrt: true,
745 }
746
747 cc_library {
748 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900749 vendor_available: true,
750 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900751 vndk: {
752 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900753 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900754 },
755 nocrt: true,
756 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900757
Colin Crosse4e44bc2020-12-28 13:50:21 -0800758 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900759 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800760 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900761 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800762 `
763
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000764 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800765 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900766 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800767 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
768
769 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
770
771 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900772
Jooyung Han2216fb12019-11-06 16:46:15 +0900773 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900774}
775
Chris Parsons79d66a52020-06-05 17:26:16 -0400776func TestDataLibs(t *testing.T) {
777 bp := `
778 cc_test_library {
779 name: "test_lib",
780 srcs: ["test_lib.cpp"],
781 gtest: false,
782 }
783
784 cc_test {
785 name: "main_test",
786 data_libs: ["test_lib"],
787 gtest: false,
788 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400789 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400790
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000791 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons79d66a52020-06-05 17:26:16 -0400792 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900793 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons79d66a52020-06-05 17:26:16 -0400794 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
795
796 ctx := testCcWithConfig(t, config)
797 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
798 testBinary := module.(*Module).linker.(*testBinary)
799 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
800 if err != nil {
801 t.Errorf("Expected cc_test to produce output files, error: %s", err)
802 return
803 }
804 if len(outputFiles) != 1 {
805 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
806 return
807 }
808 if len(testBinary.dataPaths()) != 1 {
809 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
810 return
811 }
812
813 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400814 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400815
816 if !strings.HasSuffix(outputPath, "/main_test") {
817 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
818 return
819 }
820 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
821 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
822 return
823 }
824}
825
Chris Parsons216e10a2020-07-09 17:12:52 -0400826func TestDataLibsRelativeInstallPath(t *testing.T) {
827 bp := `
828 cc_test_library {
829 name: "test_lib",
830 srcs: ["test_lib.cpp"],
831 relative_install_path: "foo/bar/baz",
832 gtest: false,
833 }
834
835 cc_test {
836 name: "main_test",
837 data_libs: ["test_lib"],
838 gtest: false,
839 }
840 `
841
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000842 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons216e10a2020-07-09 17:12:52 -0400843 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900844 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons216e10a2020-07-09 17:12:52 -0400845 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
846
847 ctx := testCcWithConfig(t, config)
848 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
849 testBinary := module.(*Module).linker.(*testBinary)
850 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
851 if err != nil {
852 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
853 }
854 if len(outputFiles) != 1 {
855 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
856 }
857 if len(testBinary.dataPaths()) != 1 {
858 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
859 }
860
861 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400862
863 if !strings.HasSuffix(outputPath, "/main_test") {
864 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
865 }
Colin Crossaa255532020-07-03 13:18:24 -0700866 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400867 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
868 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400869 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400870 }
871}
872
Jooyung Han0302a842019-10-30 18:43:49 +0900873func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900874 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900875 cc_library {
876 name: "libvndk",
877 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900878 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900879 vndk: {
880 enabled: true,
881 },
882 nocrt: true,
883 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900884 cc_library {
885 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900886 vendor_available: true,
887 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900888 vndk: {
889 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900890 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900891 },
892 nocrt: true,
893 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800894
895 cc_library {
896 name: "libllndk",
897 llndk_stubs: "libllndk.llndk",
898 }
899
900 llndk_library {
901 name: "libllndk.llndk",
902 symbol_file: "",
903 export_llndk_headers: ["libllndk_headers"],
904 }
905
906 llndk_headers {
907 name: "libllndk_headers",
908 export_include_dirs: ["include"],
909 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900910 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900911
912 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
913 "LLNDK: libc.so",
914 "LLNDK: libdl.so",
915 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800916 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900917 "LLNDK: libm.so",
918 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900919 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900920 "VNDK-core: libvndk.so",
921 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900922 "VNDK-private: libvndk-private.so",
923 "VNDK-product: libc++.so",
924 "VNDK-product: libvndk-private.so",
925 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900926 })
Logan Chienf3511742017-10-31 18:04:35 +0800927}
928
Justin Yun63e9ec72020-10-29 16:49:43 +0900929func TestVndkModuleError(t *testing.T) {
930 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900931 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900932 cc_library {
933 name: "libvndk",
934 vndk: {
935 enabled: true,
936 },
937 nocrt: true,
938 }
939 `)
940
Justin Yunc0d8c492021-01-07 17:45:31 +0900941 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900942 cc_library {
943 name: "libvndk",
944 product_available: true,
945 vndk: {
946 enabled: true,
947 },
948 nocrt: true,
949 }
950 `)
951
Justin Yun6977e8a2020-10-29 18:24:11 +0900952 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
953 cc_library {
954 name: "libvndkprop",
955 vendor_available: true,
956 product_available: true,
957 vndk: {
958 enabled: true,
959 },
960 nocrt: true,
961 target: {
962 vendor: {
963 cflags: ["-DTEST",],
964 },
965 },
966 }
967 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900968}
969
Logan Chiend3c59a22018-03-29 14:08:15 +0800970func TestVndkDepError(t *testing.T) {
971 // Check whether an error is emitted when a VNDK lib depends on a system lib.
972 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
973 cc_library {
974 name: "libvndk",
975 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900976 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800977 vndk: {
978 enabled: true,
979 },
980 shared_libs: ["libfwk"], // Cause error
981 nocrt: true,
982 }
983
984 cc_library {
985 name: "libfwk",
986 nocrt: true,
987 }
988 `)
989
990 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
991 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
992 cc_library {
993 name: "libvndk",
994 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900995 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800996 vndk: {
997 enabled: true,
998 },
999 shared_libs: ["libvendor"], // Cause error
1000 nocrt: true,
1001 }
1002
1003 cc_library {
1004 name: "libvendor",
1005 vendor: true,
1006 nocrt: true,
1007 }
1008 `)
1009
1010 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
1011 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1012 cc_library {
1013 name: "libvndk_sp",
1014 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001015 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001016 vndk: {
1017 enabled: true,
1018 support_system_process: true,
1019 },
1020 shared_libs: ["libfwk"], // Cause error
1021 nocrt: true,
1022 }
1023
1024 cc_library {
1025 name: "libfwk",
1026 nocrt: true,
1027 }
1028 `)
1029
1030 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
1031 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1032 cc_library {
1033 name: "libvndk_sp",
1034 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001035 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001036 vndk: {
1037 enabled: true,
1038 support_system_process: true,
1039 },
1040 shared_libs: ["libvendor"], // Cause error
1041 nocrt: true,
1042 }
1043
1044 cc_library {
1045 name: "libvendor",
1046 vendor: true,
1047 nocrt: true,
1048 }
1049 `)
1050
1051 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
1052 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1053 cc_library {
1054 name: "libvndk_sp",
1055 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001056 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001057 vndk: {
1058 enabled: true,
1059 support_system_process: true,
1060 },
1061 shared_libs: ["libvndk"], // Cause error
1062 nocrt: true,
1063 }
1064
1065 cc_library {
1066 name: "libvndk",
1067 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001068 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001069 vndk: {
1070 enabled: true,
1071 },
1072 nocrt: true,
1073 }
1074 `)
Jooyung Hana70f0672019-01-18 15:20:43 +09001075
1076 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
1077 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1078 cc_library {
1079 name: "libvndk",
1080 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001081 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001082 vndk: {
1083 enabled: true,
1084 },
1085 shared_libs: ["libnonvndk"],
1086 nocrt: true,
1087 }
1088
1089 cc_library {
1090 name: "libnonvndk",
1091 vendor_available: true,
1092 nocrt: true,
1093 }
1094 `)
1095
1096 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
1097 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1098 cc_library {
1099 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001100 vendor_available: true,
1101 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001102 vndk: {
1103 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001104 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001105 },
1106 shared_libs: ["libnonvndk"],
1107 nocrt: true,
1108 }
1109
1110 cc_library {
1111 name: "libnonvndk",
1112 vendor_available: true,
1113 nocrt: true,
1114 }
1115 `)
1116
1117 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
1118 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1119 cc_library {
1120 name: "libvndksp",
1121 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001122 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001123 vndk: {
1124 enabled: true,
1125 support_system_process: true,
1126 },
1127 shared_libs: ["libnonvndk"],
1128 nocrt: true,
1129 }
1130
1131 cc_library {
1132 name: "libnonvndk",
1133 vendor_available: true,
1134 nocrt: true,
1135 }
1136 `)
1137
1138 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1139 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1140 cc_library {
1141 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001142 vendor_available: true,
1143 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001144 vndk: {
1145 enabled: true,
1146 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001147 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001148 },
1149 shared_libs: ["libnonvndk"],
1150 nocrt: true,
1151 }
1152
1153 cc_library {
1154 name: "libnonvndk",
1155 vendor_available: true,
1156 nocrt: true,
1157 }
1158 `)
1159}
1160
1161func TestDoubleLoadbleDep(t *testing.T) {
1162 // okay to link : LLNDK -> double_loadable VNDK
1163 testCc(t, `
1164 cc_library {
1165 name: "libllndk",
1166 shared_libs: ["libdoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001167 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001168 }
1169
1170 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001171 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001172 symbol_file: "",
1173 }
1174
1175 cc_library {
1176 name: "libdoubleloadable",
1177 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001178 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001179 vndk: {
1180 enabled: true,
1181 },
1182 double_loadable: true,
1183 }
1184 `)
1185 // okay to link : LLNDK -> VNDK-SP
1186 testCc(t, `
1187 cc_library {
1188 name: "libllndk",
1189 shared_libs: ["libvndksp"],
Colin Cross0477b422020-10-13 18:43:54 -07001190 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001191 }
1192
1193 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001194 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001195 symbol_file: "",
1196 }
1197
1198 cc_library {
1199 name: "libvndksp",
1200 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001201 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001202 vndk: {
1203 enabled: true,
1204 support_system_process: true,
1205 },
1206 }
1207 `)
1208 // okay to link : double_loadable -> double_loadable
1209 testCc(t, `
1210 cc_library {
1211 name: "libdoubleloadable1",
1212 shared_libs: ["libdoubleloadable2"],
1213 vendor_available: true,
1214 double_loadable: true,
1215 }
1216
1217 cc_library {
1218 name: "libdoubleloadable2",
1219 vendor_available: true,
1220 double_loadable: true,
1221 }
1222 `)
1223 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1224 testCc(t, `
1225 cc_library {
1226 name: "libdoubleloadable",
1227 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001228 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001229 vndk: {
1230 enabled: true,
1231 },
1232 double_loadable: true,
1233 shared_libs: ["libnondoubleloadable"],
1234 }
1235
1236 cc_library {
1237 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001238 vendor_available: true,
1239 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001240 vndk: {
1241 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001242 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001243 },
1244 double_loadable: true,
1245 }
1246 `)
1247 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1248 testCc(t, `
1249 cc_library {
1250 name: "libllndk",
1251 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001252 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001253 }
1254
1255 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001256 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001257 symbol_file: "",
1258 }
1259
1260 cc_library {
1261 name: "libcoreonly",
1262 shared_libs: ["libvendoravailable"],
1263 }
1264
1265 // indirect dependency of LLNDK
1266 cc_library {
1267 name: "libvendoravailable",
1268 vendor_available: true,
1269 double_loadable: true,
1270 }
1271 `)
1272}
1273
1274func TestDoubleLoadableDepError(t *testing.T) {
1275 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1276 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1277 cc_library {
1278 name: "libllndk",
1279 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001280 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001281 }
1282
1283 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001284 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001285 symbol_file: "",
1286 }
1287
1288 cc_library {
1289 name: "libnondoubleloadable",
1290 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001291 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001292 vndk: {
1293 enabled: true,
1294 },
1295 }
1296 `)
1297
1298 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1299 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1300 cc_library {
1301 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001302 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001303 shared_libs: ["libnondoubleloadable"],
Colin Cross0477b422020-10-13 18:43:54 -07001304 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001305 }
1306
1307 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001308 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001309 symbol_file: "",
1310 }
1311
1312 cc_library {
1313 name: "libnondoubleloadable",
1314 vendor_available: true,
1315 }
1316 `)
1317
Jooyung Hana70f0672019-01-18 15:20:43 +09001318 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1319 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1320 cc_library {
1321 name: "libllndk",
1322 shared_libs: ["libcoreonly"],
Colin Cross0477b422020-10-13 18:43:54 -07001323 llndk_stubs: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001324 }
1325
1326 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07001327 name: "libllndk.llndk",
Jooyung Hana70f0672019-01-18 15:20:43 +09001328 symbol_file: "",
1329 }
1330
1331 cc_library {
1332 name: "libcoreonly",
1333 shared_libs: ["libvendoravailable"],
1334 }
1335
1336 // indirect dependency of LLNDK
1337 cc_library {
1338 name: "libvendoravailable",
1339 vendor_available: true,
1340 }
1341 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001342
1343 // The error is not from 'client' but from 'libllndk'
1344 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1345 cc_library {
1346 name: "client",
1347 vendor_available: true,
1348 double_loadable: true,
1349 shared_libs: ["libllndk"],
1350 }
1351 cc_library {
1352 name: "libllndk",
1353 shared_libs: ["libnondoubleloadable"],
1354 llndk_stubs: "libllndk.llndk",
1355 }
1356 llndk_library {
1357 name: "libllndk.llndk",
1358 symbol_file: "",
1359 }
1360 cc_library {
1361 name: "libnondoubleloadable",
1362 vendor_available: true,
1363 }
1364 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001365}
1366
Jooyung Han479ca172020-10-19 18:51:07 +09001367func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1368 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1369 cc_library {
1370 name: "libvndksp",
1371 shared_libs: ["libanothervndksp"],
1372 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001373 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001374 vndk: {
1375 enabled: true,
1376 support_system_process: true,
1377 }
1378 }
1379
1380 cc_library {
1381 name: "libllndk",
1382 shared_libs: ["libanothervndksp"],
1383 }
1384
1385 llndk_library {
1386 name: "libllndk",
1387 symbol_file: "",
1388 }
1389
1390 cc_library {
1391 name: "libanothervndksp",
1392 vendor_available: true,
1393 }
1394 `)
1395}
1396
Logan Chienf3511742017-10-31 18:04:35 +08001397func TestVndkExt(t *testing.T) {
1398 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001399 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001400 cc_library {
1401 name: "libvndk",
1402 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001403 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001404 vndk: {
1405 enabled: true,
1406 },
1407 nocrt: true,
1408 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001409 cc_library {
1410 name: "libvndk2",
1411 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001412 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001413 vndk: {
1414 enabled: true,
1415 },
1416 target: {
1417 vendor: {
1418 suffix: "-suffix",
1419 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001420 product: {
1421 suffix: "-suffix",
1422 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001423 },
1424 nocrt: true,
1425 }
Logan Chienf3511742017-10-31 18:04:35 +08001426
1427 cc_library {
1428 name: "libvndk_ext",
1429 vendor: true,
1430 vndk: {
1431 enabled: true,
1432 extends: "libvndk",
1433 },
1434 nocrt: true,
1435 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001436
1437 cc_library {
1438 name: "libvndk2_ext",
1439 vendor: true,
1440 vndk: {
1441 enabled: true,
1442 extends: "libvndk2",
1443 },
1444 nocrt: true,
1445 }
Logan Chienf3511742017-10-31 18:04:35 +08001446
Justin Yun0ecf0b22020-02-28 15:07:59 +09001447 cc_library {
1448 name: "libvndk_ext_product",
1449 product_specific: true,
1450 vndk: {
1451 enabled: true,
1452 extends: "libvndk",
1453 },
1454 nocrt: true,
1455 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001456
Justin Yun0ecf0b22020-02-28 15:07:59 +09001457 cc_library {
1458 name: "libvndk2_ext_product",
1459 product_specific: true,
1460 vndk: {
1461 enabled: true,
1462 extends: "libvndk2",
1463 },
1464 nocrt: true,
1465 }
1466 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001467 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001468 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1469 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001470 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001471
1472 ctx := testCcWithConfig(t, config)
1473
1474 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1475 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1476
1477 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1478 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1479
1480 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1481 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001482}
1483
Logan Chiend3c59a22018-03-29 14:08:15 +08001484func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001485 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1486 ctx := testCcNoVndk(t, `
1487 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 vendor: true,
1500 vndk: {
1501 enabled: true,
1502 extends: "libvndk",
1503 },
1504 nocrt: true,
1505 }
1506 `)
1507
1508 // Ensures that the core variant of "libvndk_ext" can be found.
1509 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1510 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1511 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1512 }
1513}
1514
Justin Yun0ecf0b22020-02-28 15:07:59 +09001515func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1516 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001517 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001518 cc_library {
1519 name: "libvndk",
1520 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001521 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001522 vndk: {
1523 enabled: true,
1524 },
1525 nocrt: true,
1526 }
1527
1528 cc_library {
1529 name: "libvndk_ext_product",
1530 product_specific: true,
1531 vndk: {
1532 enabled: true,
1533 extends: "libvndk",
1534 },
1535 nocrt: true,
1536 }
1537 `)
1538
1539 // Ensures that the core variant of "libvndk_ext_product" can be found.
1540 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1541 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1542 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1543 }
1544}
1545
Logan Chienf3511742017-10-31 18:04:35 +08001546func TestVndkExtError(t *testing.T) {
1547 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001548 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001549 cc_library {
1550 name: "libvndk",
1551 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001552 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001553 vndk: {
1554 enabled: true,
1555 },
1556 nocrt: true,
1557 }
1558
1559 cc_library {
1560 name: "libvndk_ext",
1561 vndk: {
1562 enabled: true,
1563 extends: "libvndk",
1564 },
1565 nocrt: true,
1566 }
1567 `)
1568
1569 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1570 cc_library {
1571 name: "libvndk",
1572 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001573 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001574 vndk: {
1575 enabled: true,
1576 },
1577 nocrt: true,
1578 }
1579
1580 cc_library {
1581 name: "libvndk_ext",
1582 vendor: true,
1583 vndk: {
1584 enabled: true,
1585 },
1586 nocrt: true,
1587 }
1588 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001589
1590 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1591 cc_library {
1592 name: "libvndk",
1593 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001594 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001595 vndk: {
1596 enabled: true,
1597 },
1598 nocrt: true,
1599 }
1600
1601 cc_library {
1602 name: "libvndk_ext_product",
1603 product_specific: true,
1604 vndk: {
1605 enabled: true,
1606 },
1607 nocrt: true,
1608 }
1609 `)
1610
1611 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1612 cc_library {
1613 name: "libvndk",
1614 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001615 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001616 vndk: {
1617 enabled: true,
1618 },
1619 nocrt: true,
1620 }
1621
1622 cc_library {
1623 name: "libvndk_ext_product",
1624 product_specific: true,
1625 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001626 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001627 vndk: {
1628 enabled: true,
1629 extends: "libvndk",
1630 },
1631 nocrt: true,
1632 }
1633 `)
Logan Chienf3511742017-10-31 18:04:35 +08001634}
1635
1636func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1637 // This test ensures an error is emitted for inconsistent support_system_process.
1638 testCcError(t, "module \".*\" with mismatched support_system_process", `
1639 cc_library {
1640 name: "libvndk",
1641 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001642 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001643 vndk: {
1644 enabled: true,
1645 },
1646 nocrt: true,
1647 }
1648
1649 cc_library {
1650 name: "libvndk_sp_ext",
1651 vendor: true,
1652 vndk: {
1653 enabled: true,
1654 extends: "libvndk",
1655 support_system_process: true,
1656 },
1657 nocrt: true,
1658 }
1659 `)
1660
1661 testCcError(t, "module \".*\" with mismatched support_system_process", `
1662 cc_library {
1663 name: "libvndk_sp",
1664 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001665 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001666 vndk: {
1667 enabled: true,
1668 support_system_process: true,
1669 },
1670 nocrt: true,
1671 }
1672
1673 cc_library {
1674 name: "libvndk_ext",
1675 vendor: true,
1676 vndk: {
1677 enabled: true,
1678 extends: "libvndk_sp",
1679 },
1680 nocrt: true,
1681 }
1682 `)
1683}
1684
1685func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001686 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001687 // with `private: true`.
1688 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001689 cc_library {
1690 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001691 vendor_available: true,
1692 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001693 vndk: {
1694 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001695 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001696 },
1697 nocrt: true,
1698 }
1699
1700 cc_library {
1701 name: "libvndk_ext",
1702 vendor: true,
1703 vndk: {
1704 enabled: true,
1705 extends: "libvndk",
1706 },
1707 nocrt: true,
1708 }
1709 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001710
Justin Yunfd9e8042020-12-23 18:23:14 +09001711 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001712 cc_library {
1713 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001714 vendor_available: true,
1715 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001716 vndk: {
1717 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001718 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001719 },
1720 nocrt: true,
1721 }
1722
1723 cc_library {
1724 name: "libvndk_ext_product",
1725 product_specific: true,
1726 vndk: {
1727 enabled: true,
1728 extends: "libvndk",
1729 },
1730 nocrt: true,
1731 }
1732 `)
Logan Chienf3511742017-10-31 18:04:35 +08001733}
1734
Logan Chiend3c59a22018-03-29 14:08:15 +08001735func TestVendorModuleUseVndkExt(t *testing.T) {
1736 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001737 testCc(t, `
1738 cc_library {
1739 name: "libvndk",
1740 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001741 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001742 vndk: {
1743 enabled: true,
1744 },
1745 nocrt: true,
1746 }
1747
1748 cc_library {
1749 name: "libvndk_ext",
1750 vendor: true,
1751 vndk: {
1752 enabled: true,
1753 extends: "libvndk",
1754 },
1755 nocrt: true,
1756 }
1757
1758 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001759 name: "libvndk_sp",
1760 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001761 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001762 vndk: {
1763 enabled: true,
1764 support_system_process: true,
1765 },
1766 nocrt: true,
1767 }
1768
1769 cc_library {
1770 name: "libvndk_sp_ext",
1771 vendor: true,
1772 vndk: {
1773 enabled: true,
1774 extends: "libvndk_sp",
1775 support_system_process: true,
1776 },
1777 nocrt: true,
1778 }
1779
1780 cc_library {
1781 name: "libvendor",
1782 vendor: true,
1783 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1784 nocrt: true,
1785 }
1786 `)
1787}
1788
Logan Chiend3c59a22018-03-29 14:08:15 +08001789func TestVndkExtUseVendorLib(t *testing.T) {
1790 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001791 testCc(t, `
1792 cc_library {
1793 name: "libvndk",
1794 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001795 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001796 vndk: {
1797 enabled: true,
1798 },
1799 nocrt: true,
1800 }
1801
1802 cc_library {
1803 name: "libvndk_ext",
1804 vendor: true,
1805 vndk: {
1806 enabled: true,
1807 extends: "libvndk",
1808 },
1809 shared_libs: ["libvendor"],
1810 nocrt: true,
1811 }
1812
1813 cc_library {
1814 name: "libvendor",
1815 vendor: true,
1816 nocrt: true,
1817 }
1818 `)
Logan Chienf3511742017-10-31 18:04:35 +08001819
Logan Chiend3c59a22018-03-29 14:08:15 +08001820 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1821 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001822 cc_library {
1823 name: "libvndk_sp",
1824 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001825 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001826 vndk: {
1827 enabled: true,
1828 support_system_process: true,
1829 },
1830 nocrt: true,
1831 }
1832
1833 cc_library {
1834 name: "libvndk_sp_ext",
1835 vendor: true,
1836 vndk: {
1837 enabled: true,
1838 extends: "libvndk_sp",
1839 support_system_process: true,
1840 },
1841 shared_libs: ["libvendor"], // Cause an error
1842 nocrt: true,
1843 }
1844
1845 cc_library {
1846 name: "libvendor",
1847 vendor: true,
1848 nocrt: true,
1849 }
1850 `)
1851}
1852
Justin Yun0ecf0b22020-02-28 15:07:59 +09001853func TestProductVndkExtDependency(t *testing.T) {
1854 bp := `
1855 cc_library {
1856 name: "libvndk",
1857 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001858 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001859 vndk: {
1860 enabled: true,
1861 },
1862 nocrt: true,
1863 }
1864
1865 cc_library {
1866 name: "libvndk_ext_product",
1867 product_specific: true,
1868 vndk: {
1869 enabled: true,
1870 extends: "libvndk",
1871 },
1872 shared_libs: ["libproduct_for_vndklibs"],
1873 nocrt: true,
1874 }
1875
1876 cc_library {
1877 name: "libvndk_sp",
1878 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001879 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001880 vndk: {
1881 enabled: true,
1882 support_system_process: true,
1883 },
1884 nocrt: true,
1885 }
1886
1887 cc_library {
1888 name: "libvndk_sp_ext_product",
1889 product_specific: true,
1890 vndk: {
1891 enabled: true,
1892 extends: "libvndk_sp",
1893 support_system_process: true,
1894 },
1895 shared_libs: ["libproduct_for_vndklibs"],
1896 nocrt: true,
1897 }
1898
1899 cc_library {
1900 name: "libproduct",
1901 product_specific: true,
1902 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1903 nocrt: true,
1904 }
1905
1906 cc_library {
1907 name: "libproduct_for_vndklibs",
1908 product_specific: true,
1909 nocrt: true,
1910 }
1911 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001912 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001913 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1914 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001915 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001916
1917 testCcWithConfig(t, config)
1918}
1919
Logan Chiend3c59a22018-03-29 14:08:15 +08001920func TestVndkSpExtUseVndkError(t *testing.T) {
1921 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1922 // library.
1923 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1924 cc_library {
1925 name: "libvndk",
1926 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001927 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001928 vndk: {
1929 enabled: true,
1930 },
1931 nocrt: true,
1932 }
1933
1934 cc_library {
1935 name: "libvndk_sp",
1936 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001937 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001938 vndk: {
1939 enabled: true,
1940 support_system_process: true,
1941 },
1942 nocrt: true,
1943 }
1944
1945 cc_library {
1946 name: "libvndk_sp_ext",
1947 vendor: true,
1948 vndk: {
1949 enabled: true,
1950 extends: "libvndk_sp",
1951 support_system_process: true,
1952 },
1953 shared_libs: ["libvndk"], // Cause an error
1954 nocrt: true,
1955 }
1956 `)
1957
1958 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1959 // library.
1960 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1961 cc_library {
1962 name: "libvndk",
1963 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001964 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001965 vndk: {
1966 enabled: true,
1967 },
1968 nocrt: true,
1969 }
1970
1971 cc_library {
1972 name: "libvndk_ext",
1973 vendor: true,
1974 vndk: {
1975 enabled: true,
1976 extends: "libvndk",
1977 },
1978 nocrt: true,
1979 }
1980
1981 cc_library {
1982 name: "libvndk_sp",
1983 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001984 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001985 vndk: {
1986 enabled: true,
1987 support_system_process: true,
1988 },
1989 nocrt: true,
1990 }
1991
1992 cc_library {
1993 name: "libvndk_sp_ext",
1994 vendor: true,
1995 vndk: {
1996 enabled: true,
1997 extends: "libvndk_sp",
1998 support_system_process: true,
1999 },
2000 shared_libs: ["libvndk_ext"], // Cause an error
2001 nocrt: true,
2002 }
2003 `)
2004}
2005
2006func TestVndkUseVndkExtError(t *testing.T) {
2007 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
2008 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08002009 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2010 cc_library {
2011 name: "libvndk",
2012 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002013 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002014 vndk: {
2015 enabled: true,
2016 },
2017 nocrt: true,
2018 }
2019
2020 cc_library {
2021 name: "libvndk_ext",
2022 vendor: true,
2023 vndk: {
2024 enabled: true,
2025 extends: "libvndk",
2026 },
2027 nocrt: true,
2028 }
2029
2030 cc_library {
2031 name: "libvndk2",
2032 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002033 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002034 vndk: {
2035 enabled: true,
2036 },
2037 shared_libs: ["libvndk_ext"],
2038 nocrt: true,
2039 }
2040 `)
2041
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002042 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002043 cc_library {
2044 name: "libvndk",
2045 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002046 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002047 vndk: {
2048 enabled: true,
2049 },
2050 nocrt: true,
2051 }
2052
2053 cc_library {
2054 name: "libvndk_ext",
2055 vendor: true,
2056 vndk: {
2057 enabled: true,
2058 extends: "libvndk",
2059 },
2060 nocrt: true,
2061 }
2062
2063 cc_library {
2064 name: "libvndk2",
2065 vendor_available: true,
2066 vndk: {
2067 enabled: true,
2068 },
2069 target: {
2070 vendor: {
2071 shared_libs: ["libvndk_ext"],
2072 },
2073 },
2074 nocrt: true,
2075 }
2076 `)
2077
2078 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
2079 cc_library {
2080 name: "libvndk_sp",
2081 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002082 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002083 vndk: {
2084 enabled: true,
2085 support_system_process: true,
2086 },
2087 nocrt: true,
2088 }
2089
2090 cc_library {
2091 name: "libvndk_sp_ext",
2092 vendor: true,
2093 vndk: {
2094 enabled: true,
2095 extends: "libvndk_sp",
2096 support_system_process: true,
2097 },
2098 nocrt: true,
2099 }
2100
2101 cc_library {
2102 name: "libvndk_sp_2",
2103 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002104 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002105 vndk: {
2106 enabled: true,
2107 support_system_process: true,
2108 },
2109 shared_libs: ["libvndk_sp_ext"],
2110 nocrt: true,
2111 }
2112 `)
2113
Martin Stjernholmef449fe2018-11-06 16:12:13 +00002114 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08002115 cc_library {
2116 name: "libvndk_sp",
2117 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002118 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002119 vndk: {
2120 enabled: true,
2121 },
2122 nocrt: true,
2123 }
2124
2125 cc_library {
2126 name: "libvndk_sp_ext",
2127 vendor: true,
2128 vndk: {
2129 enabled: true,
2130 extends: "libvndk_sp",
2131 },
2132 nocrt: true,
2133 }
2134
2135 cc_library {
2136 name: "libvndk_sp2",
2137 vendor_available: true,
2138 vndk: {
2139 enabled: true,
2140 },
2141 target: {
2142 vendor: {
2143 shared_libs: ["libvndk_sp_ext"],
2144 },
2145 },
2146 nocrt: true,
2147 }
2148 `)
2149}
2150
Justin Yun5f7f7e82019-11-18 19:52:14 +09002151func TestEnforceProductVndkVersion(t *testing.T) {
2152 bp := `
2153 cc_library {
2154 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002155 llndk_stubs: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002156 }
2157 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002158 name: "libllndk.llndk",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002159 symbol_file: "",
2160 }
2161 cc_library {
2162 name: "libvndk",
2163 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002164 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002165 vndk: {
2166 enabled: true,
2167 },
2168 nocrt: true,
2169 }
2170 cc_library {
2171 name: "libvndk_sp",
2172 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002173 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002174 vndk: {
2175 enabled: true,
2176 support_system_process: true,
2177 },
2178 nocrt: true,
2179 }
2180 cc_library {
2181 name: "libva",
2182 vendor_available: true,
2183 nocrt: true,
2184 }
2185 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002186 name: "libpa",
2187 product_available: true,
2188 nocrt: true,
2189 }
2190 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002191 name: "libboth_available",
2192 vendor_available: true,
2193 product_available: true,
2194 nocrt: true,
Justin Yun13decfb2021-03-08 19:25:55 +09002195 srcs: ["foo.c"],
Justin Yun6977e8a2020-10-29 18:24:11 +09002196 target: {
2197 vendor: {
2198 suffix: "-vendor",
2199 },
2200 product: {
2201 suffix: "-product",
2202 },
2203 }
2204 }
2205 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002206 name: "libproduct_va",
2207 product_specific: true,
2208 vendor_available: true,
2209 nocrt: true,
2210 }
2211 cc_library {
2212 name: "libprod",
2213 product_specific: true,
2214 shared_libs: [
2215 "libllndk",
2216 "libvndk",
2217 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002218 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002219 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002220 "libproduct_va",
2221 ],
2222 nocrt: true,
2223 }
2224 cc_library {
2225 name: "libvendor",
2226 vendor: true,
2227 shared_libs: [
2228 "libllndk",
2229 "libvndk",
2230 "libvndk_sp",
2231 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002232 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002233 "libproduct_va",
2234 ],
2235 nocrt: true,
2236 }
2237 `
2238
Paul Duffin8567f222021-03-23 00:02:06 +00002239 ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
Justin Yun5f7f7e82019-11-18 19:52:14 +09002240
Jooyung Han261e1582020-10-20 18:54:21 +09002241 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2242 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002243
2244 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2245 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2246
2247 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2248 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun13decfb2021-03-08 19:25:55 +09002249
2250 ensureStringContains := func(t *testing.T, str string, substr string) {
2251 t.Helper()
2252 if !strings.Contains(str, substr) {
2253 t.Errorf("%q is not found in %v", substr, str)
2254 }
2255 }
2256 ensureStringNotContains := func(t *testing.T, str string, substr string) {
2257 t.Helper()
2258 if strings.Contains(str, substr) {
2259 t.Errorf("%q is found in %v", substr, str)
2260 }
2261 }
2262
2263 // _static variant is used since _shared reuses *.o from the static variant
2264 vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
2265 product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
2266
2267 vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
2268 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
2269 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
2270 ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
2271
2272 product_cflags := product_static.Rule("cc").Args["cFlags"]
2273 ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
2274 ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
2275 ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002276}
2277
2278func TestEnforceProductVndkVersionErrors(t *testing.T) {
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 "libvendor",
2285 ],
2286 nocrt: true,
2287 }
2288 cc_library {
2289 name: "libvendor",
2290 vendor: true,
2291 nocrt: true,
2292 }
2293 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002294 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002295 cc_library {
2296 name: "libprod",
2297 product_specific: true,
2298 shared_libs: [
2299 "libsystem",
2300 ],
2301 nocrt: true,
2302 }
2303 cc_library {
2304 name: "libsystem",
2305 nocrt: true,
2306 }
2307 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002308 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun6977e8a2020-10-29 18:24:11 +09002309 cc_library {
2310 name: "libprod",
2311 product_specific: true,
2312 shared_libs: [
2313 "libva",
2314 ],
2315 nocrt: true,
2316 }
2317 cc_library {
2318 name: "libva",
2319 vendor_available: true,
2320 nocrt: true,
2321 }
2322 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002323 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002324 cc_library {
2325 name: "libprod",
2326 product_specific: true,
2327 shared_libs: [
2328 "libvndk_private",
2329 ],
2330 nocrt: true,
2331 }
2332 cc_library {
2333 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002334 vendor_available: true,
2335 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002336 vndk: {
2337 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002338 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002339 },
2340 nocrt: true,
2341 }
2342 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002343 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002344 cc_library {
2345 name: "libprod",
2346 product_specific: true,
2347 shared_libs: [
2348 "libsystem_ext",
2349 ],
2350 nocrt: true,
2351 }
2352 cc_library {
2353 name: "libsystem_ext",
2354 system_ext_specific: true,
2355 nocrt: true,
2356 }
2357 `)
2358 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2359 cc_library {
2360 name: "libsystem",
2361 shared_libs: [
2362 "libproduct_va",
2363 ],
2364 nocrt: true,
2365 }
2366 cc_library {
2367 name: "libproduct_va",
2368 product_specific: true,
2369 vendor_available: true,
2370 nocrt: true,
2371 }
2372 `)
2373}
2374
Jooyung Han38002912019-05-16 04:01:54 +09002375func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002376 bp := `
2377 cc_library {
2378 name: "libvndk",
2379 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002380 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002381 vndk: {
2382 enabled: true,
2383 },
2384 }
2385 cc_library {
2386 name: "libvndksp",
2387 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002388 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002389 vndk: {
2390 enabled: true,
2391 support_system_process: true,
2392 },
2393 }
2394 cc_library {
2395 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002396 vendor_available: true,
2397 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002398 vndk: {
2399 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002400 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002401 },
2402 }
2403 cc_library {
2404 name: "libvendor",
2405 vendor: true,
2406 }
2407 cc_library {
2408 name: "libvndkext",
2409 vendor: true,
2410 vndk: {
2411 enabled: true,
2412 extends: "libvndk",
2413 },
2414 }
2415 vndk_prebuilt_shared {
2416 name: "prevndk",
2417 version: "27",
2418 target_arch: "arm",
2419 binder32bit: true,
2420 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002421 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002422 vndk: {
2423 enabled: true,
2424 },
2425 arch: {
2426 arm: {
2427 srcs: ["liba.so"],
2428 },
2429 },
2430 }
2431 cc_library {
2432 name: "libllndk",
Colin Cross0477b422020-10-13 18:43:54 -07002433 llndk_stubs: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002434 }
2435 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002436 name: "libllndk.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002437 symbol_file: "",
2438 }
2439 cc_library {
2440 name: "libllndkprivate",
Colin Cross0477b422020-10-13 18:43:54 -07002441 llndk_stubs: "libllndkprivate.llndk",
Colin Cross98be1bb2019-12-13 20:41:13 -08002442 }
2443 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002444 name: "libllndkprivate.llndk",
Justin Yunc0d8c492021-01-07 17:45:31 +09002445 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002446 symbol_file: "",
Colin Cross78212242021-01-06 14:51:30 -08002447 }
2448
2449 llndk_libraries_txt {
2450 name: "llndk.libraries.txt",
2451 }
2452 vndkcore_libraries_txt {
2453 name: "vndkcore.libraries.txt",
2454 }
2455 vndksp_libraries_txt {
2456 name: "vndksp.libraries.txt",
2457 }
2458 vndkprivate_libraries_txt {
2459 name: "vndkprivate.libraries.txt",
2460 }
2461 vndkcorevariant_libraries_txt {
2462 name: "vndkcorevariant.libraries.txt",
2463 insert_vndk_version: false,
2464 }
2465 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002466
Paul Duffinc3e6ce02021-03-22 23:21:32 +00002467 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002468 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002469 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jooyung Han38002912019-05-16 04:01:54 +09002470 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002471 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002472
Colin Cross78212242021-01-06 14:51:30 -08002473 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2474 []string{"libvndk.so", "libvndkprivate.so"})
2475 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2476 []string{"libc++.so", "libvndksp.so"})
2477 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2478 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2479 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2480 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002481
Colin Crossfb0c16e2019-11-20 17:12:35 -08002482 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002483
Jooyung Han38002912019-05-16 04:01:54 +09002484 tests := []struct {
2485 variant string
2486 name string
2487 expected string
2488 }{
2489 {vendorVariant, "libvndk", "native:vndk"},
2490 {vendorVariant, "libvndksp", "native:vndk"},
2491 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2492 {vendorVariant, "libvendor", "native:vendor"},
2493 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002494 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002495 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002496 {coreVariant, "libvndk", "native:platform"},
2497 {coreVariant, "libvndkprivate", "native:platform"},
2498 {coreVariant, "libllndk", "native:platform"},
2499 }
2500 for _, test := range tests {
2501 t.Run(test.name, func(t *testing.T) {
2502 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2503 assertString(t, module.makeLinkType, test.expected)
2504 })
2505 }
2506}
2507
Jeff Gaston294356f2017-09-27 17:05:30 -07002508var staticLinkDepOrderTestCases = []struct {
2509 // This is a string representation of a map[moduleName][]moduleDependency .
2510 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002511 inStatic string
2512
2513 // This is a string representation of a map[moduleName][]moduleDependency .
2514 // It models the dependencies declared in an Android.bp file.
2515 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002516
2517 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2518 // The keys of allOrdered specify which modules we would like to check.
2519 // The values of allOrdered specify the expected result (of the transitive closure of all
2520 // dependencies) for each module to test
2521 allOrdered string
2522
2523 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2524 // The keys of outOrdered specify which modules we would like to check.
2525 // The values of outOrdered specify the expected result (of the ordered linker command line)
2526 // for each module to test.
2527 outOrdered string
2528}{
2529 // Simple tests
2530 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002531 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002532 outOrdered: "",
2533 },
2534 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002535 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002536 outOrdered: "a:",
2537 },
2538 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002539 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002540 outOrdered: "a:b; b:",
2541 },
2542 // Tests of reordering
2543 {
2544 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002545 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002546 outOrdered: "a:b,c,d; b:d; c:d; d:",
2547 },
2548 {
2549 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002550 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002551 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2552 },
2553 {
2554 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002555 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002556 outOrdered: "a:d,b,e,c; d:b; e:c",
2557 },
2558 {
2559 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002560 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002561 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2562 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2563 },
2564 {
2565 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002566 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 -07002567 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2568 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2569 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002570 // shared dependencies
2571 {
2572 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2573 // So, we don't actually have to check that a shared dependency of c will change the order
2574 // of a library that depends statically on b and on c. We only need to check that if c has
2575 // a shared dependency on b, that that shows up in allOrdered.
2576 inShared: "c:b",
2577 allOrdered: "c:b",
2578 outOrdered: "c:",
2579 },
2580 {
2581 // This test doesn't actually include any shared dependencies but it's a reminder of what
2582 // the second phase of the above test would look like
2583 inStatic: "a:b,c; c:b",
2584 allOrdered: "a:c,b; c:b",
2585 outOrdered: "a:c,b; c:b",
2586 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002587 // tiebreakers for when two modules specifying different orderings and there is no dependency
2588 // to dictate an order
2589 {
2590 // 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 -08002591 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002592 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2593 },
2594 {
2595 // 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 -08002596 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 -07002597 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2598 },
2599 // Tests involving duplicate dependencies
2600 {
2601 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002602 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002603 outOrdered: "a:c,b",
2604 },
2605 {
2606 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002607 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002608 outOrdered: "a:d,c,b",
2609 },
2610 // Tests to confirm the nonexistence of infinite loops.
2611 // These cases should never happen, so as long as the test terminates and the
2612 // result is deterministic then that should be fine.
2613 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002614 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002615 outOrdered: "a:a",
2616 },
2617 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002618 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002619 allOrdered: "a:b,c; b:c,a; c:a,b",
2620 outOrdered: "a:b; b:c; c:a",
2621 },
2622 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002623 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002624 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2625 outOrdered: "a:c,b; b:a,c; c:b,a",
2626 },
2627}
2628
2629// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2630func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2631 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2632 strippedText := strings.Replace(text, " ", "", -1)
2633 if len(strippedText) < 1 {
2634 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2635 }
2636 allDeps = make(map[android.Path][]android.Path, 0)
2637
2638 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2639 moduleTexts := strings.Split(strippedText, ";")
2640
2641 outputForModuleName := func(moduleName string) android.Path {
2642 return android.PathForTesting(moduleName)
2643 }
2644
2645 for _, moduleText := range moduleTexts {
2646 // convert from "a:b,c" to ["a", "b,c"]
2647 components := strings.Split(moduleText, ":")
2648 if len(components) != 2 {
2649 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2650 }
2651 moduleName := components[0]
2652 moduleOutput := outputForModuleName(moduleName)
2653 modulesInOrder = append(modulesInOrder, moduleOutput)
2654
2655 depString := components[1]
2656 // convert from "b,c" to ["b", "c"]
2657 depNames := strings.Split(depString, ",")
2658 if len(depString) < 1 {
2659 depNames = []string{}
2660 }
2661 var deps []android.Path
2662 for _, depName := range depNames {
2663 deps = append(deps, outputForModuleName(depName))
2664 }
2665 allDeps[moduleOutput] = deps
2666 }
2667 return modulesInOrder, allDeps
2668}
2669
Jeff Gaston294356f2017-09-27 17:05:30 -07002670func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
2671 for _, moduleName := range moduleNames {
2672 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002673 output := module.outputFile.Path().RelativeToTop()
Jeff Gaston294356f2017-09-27 17:05:30 -07002674 paths = append(paths, output)
2675 }
2676 return paths
2677}
2678
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002679func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002680 ctx := testCc(t, `
2681 cc_library {
2682 name: "a",
2683 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002684 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002685 }
2686 cc_library {
2687 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002688 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002689 }
2690 cc_library {
2691 name: "c",
2692 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002693 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002694 }
2695 cc_library {
2696 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002697 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002698 }
2699
2700 `)
2701
Colin Cross7113d202019-11-20 16:39:12 -08002702 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002703 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002704 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2705 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Colin Cross0de8a1e2020-09-18 14:15:30 -07002706 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002707
2708 if !reflect.DeepEqual(actual, expected) {
2709 t.Errorf("staticDeps orderings were not propagated correctly"+
2710 "\nactual: %v"+
2711 "\nexpected: %v",
2712 actual,
2713 expected,
2714 )
2715 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002716}
Jeff Gaston294356f2017-09-27 17:05:30 -07002717
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002718func TestStaticLibDepReorderingWithShared(t *testing.T) {
2719 ctx := testCc(t, `
2720 cc_library {
2721 name: "a",
2722 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002723 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002724 }
2725 cc_library {
2726 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002727 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002728 }
2729 cc_library {
2730 name: "c",
2731 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002732 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002733 }
2734
2735 `)
2736
Colin Cross7113d202019-11-20 16:39:12 -08002737 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002738 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002739 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2740 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Colin Cross0de8a1e2020-09-18 14:15:30 -07002741 expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002742
2743 if !reflect.DeepEqual(actual, expected) {
2744 t.Errorf("staticDeps orderings did not account for shared libs"+
2745 "\nactual: %v"+
2746 "\nexpected: %v",
2747 actual,
2748 expected,
2749 )
2750 }
2751}
2752
Jooyung Hanb04a4992020-03-13 18:57:35 +09002753func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002754 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002755 if !reflect.DeepEqual(actual, expected) {
2756 t.Errorf(message+
2757 "\nactual: %v"+
2758 "\nexpected: %v",
2759 actual,
2760 expected,
2761 )
2762 }
2763}
2764
Jooyung Han61b66e92020-03-21 14:21:46 +00002765func TestLlndkLibrary(t *testing.T) {
2766 ctx := testCc(t, `
2767 cc_library {
2768 name: "libllndk",
2769 stubs: { versions: ["1", "2"] },
Colin Cross0477b422020-10-13 18:43:54 -07002770 llndk_stubs: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002771 }
2772 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002773 name: "libllndk.llndk",
Jooyung Han61b66e92020-03-21 14:21:46 +00002774 }
Colin Cross127bb8b2020-12-16 16:46:01 -08002775
2776 cc_prebuilt_library_shared {
2777 name: "libllndkprebuilt",
2778 stubs: { versions: ["1", "2"] },
2779 llndk_stubs: "libllndkprebuilt.llndk",
2780 }
2781 llndk_library {
2782 name: "libllndkprebuilt.llndk",
2783 }
2784
2785 cc_library {
2786 name: "libllndk_with_external_headers",
2787 stubs: { versions: ["1", "2"] },
2788 llndk_stubs: "libllndk_with_external_headers.llndk",
2789 header_libs: ["libexternal_headers"],
2790 export_header_lib_headers: ["libexternal_headers"],
2791 }
2792 llndk_library {
2793 name: "libllndk_with_external_headers.llndk",
2794 }
2795 cc_library_headers {
2796 name: "libexternal_headers",
2797 export_include_dirs: ["include"],
2798 vendor_available: true,
2799 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002800 `)
Colin Cross127bb8b2020-12-16 16:46:01 -08002801 actual := ctx.ModuleVariantsForTests("libllndk")
2802 for i := 0; i < len(actual); i++ {
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002803 if !strings.HasPrefix(actual[i], "android_vendor.29_") {
Colin Cross127bb8b2020-12-16 16:46:01 -08002804 actual = append(actual[:i], actual[i+1:]...)
2805 i--
2806 }
2807 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002808 expected := []string{
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002809 "android_vendor.29_arm64_armv8-a_shared_1",
2810 "android_vendor.29_arm64_armv8-a_shared_2",
2811 "android_vendor.29_arm64_armv8-a_shared_current",
2812 "android_vendor.29_arm64_armv8-a_shared",
2813 "android_vendor.29_arm_armv7-a-neon_shared_1",
2814 "android_vendor.29_arm_armv7-a-neon_shared_2",
2815 "android_vendor.29_arm_armv7-a-neon_shared_current",
2816 "android_vendor.29_arm_armv7-a-neon_shared",
Jooyung Han61b66e92020-03-21 14:21:46 +00002817 }
2818 checkEquals(t, "variants for llndk stubs", expected, actual)
2819
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002820 params := ctx.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002821 checkEquals(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2822
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002823 params = ctx.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared_1").Description("generate stub")
Jooyung Han61b66e92020-03-21 14:21:46 +00002824 checkEquals(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2825}
2826
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002827func TestEmbeddedLlndkLibrary(t *testing.T) {
2828 result := prepareForCcTest.RunTestWithBp(t, `
2829 cc_library {
2830 name: "libllndk",
2831 stubs: { versions: ["1", "2"] },
2832 llndk: {
2833 symbol_file: "libllndk.map.txt",
2834 },
2835 export_include_dirs: ["include"],
2836 }
2837
2838 cc_prebuilt_library_shared {
2839 name: "libllndkprebuilt",
2840 stubs: { versions: ["1", "2"] },
2841 llndk: {
2842 symbol_file: "libllndkprebuilt.map.txt",
2843 },
2844 }
2845
2846 cc_library {
2847 name: "libllndk_with_external_headers",
2848 stubs: { versions: ["1", "2"] },
2849 llndk: {
2850 symbol_file: "libllndk.map.txt",
2851 export_llndk_headers: ["libexternal_llndk_headers"],
2852 },
2853 header_libs: ["libexternal_headers"],
2854 export_header_lib_headers: ["libexternal_headers"],
2855 }
2856 cc_library_headers {
2857 name: "libexternal_headers",
2858 export_include_dirs: ["include"],
2859 vendor_available: true,
2860 }
2861 cc_library_headers {
2862 name: "libexternal_llndk_headers",
2863 export_include_dirs: ["include_llndk"],
2864 llndk: {
2865 symbol_file: "libllndk.map.txt",
2866 },
2867 vendor_available: true,
2868 }
2869
2870 cc_library {
2871 name: "libllndk_with_override_headers",
2872 stubs: { versions: ["1", "2"] },
2873 llndk: {
2874 symbol_file: "libllndk.map.txt",
2875 override_export_include_dirs: ["include_llndk"],
2876 },
2877 export_include_dirs: ["include"],
2878 }
2879 `)
2880 actual := result.ModuleVariantsForTests("libllndk")
2881 for i := 0; i < len(actual); i++ {
2882 if !strings.HasPrefix(actual[i], "android_vendor.29_") {
2883 actual = append(actual[:i], actual[i+1:]...)
2884 i--
2885 }
2886 }
2887 expected := []string{
2888 "android_vendor.29_arm64_armv8-a_shared_1",
2889 "android_vendor.29_arm64_armv8-a_shared_2",
2890 "android_vendor.29_arm64_armv8-a_shared_current",
2891 "android_vendor.29_arm64_armv8-a_shared",
2892 "android_vendor.29_arm_armv7-a-neon_shared_1",
2893 "android_vendor.29_arm_armv7-a-neon_shared_2",
2894 "android_vendor.29_arm_armv7-a-neon_shared_current",
2895 "android_vendor.29_arm_armv7-a-neon_shared",
2896 }
2897 android.AssertArrayString(t, "variants for llndk stubs", expected, actual)
2898
2899 params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
2900 android.AssertSame(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2901
2902 params = result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared_1").Description("generate stub")
2903 android.AssertSame(t, "override apiLevel for versioned stubs", "1", params.Args["apiLevel"])
2904
2905 checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) {
2906 t.Helper()
2907 m := result.ModuleForTests(module, variant).Module()
2908 f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
2909 android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]",
2910 expectedDirs, f.IncludeDirs)
2911 }
2912
2913 checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include")
2914 checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include")
2915 checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include")
2916 checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2917 checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include")
2918 checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2919}
2920
Jiyong Parka46a4d52017-12-14 19:54:34 +09002921func TestLlndkHeaders(t *testing.T) {
2922 ctx := testCc(t, `
2923 llndk_headers {
2924 name: "libllndk_headers",
2925 export_include_dirs: ["my_include"],
2926 }
2927 llndk_library {
Colin Cross0477b422020-10-13 18:43:54 -07002928 name: "libllndk.llndk",
Jiyong Parka46a4d52017-12-14 19:54:34 +09002929 export_llndk_headers: ["libllndk_headers"],
2930 }
2931 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002932 name: "libllndk",
2933 llndk_stubs: "libllndk.llndk",
2934 }
2935
2936 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002937 name: "libvendor",
2938 shared_libs: ["libllndk"],
2939 vendor: true,
2940 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002941 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002942 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002943 }
2944 `)
2945
2946 // _static variant is used since _shared reuses *.o from the static variant
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002947 cc := ctx.ModuleForTests("libvendor", "android_vendor.29_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002948 cflags := cc.Args["cFlags"]
2949 if !strings.Contains(cflags, "-Imy_include") {
2950 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2951 }
2952}
2953
Logan Chien43d34c32017-12-20 01:17:32 +08002954func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2955 actual := module.Properties.AndroidMkRuntimeLibs
2956 if !reflect.DeepEqual(actual, expected) {
2957 t.Errorf("incorrect runtime_libs for shared libs"+
2958 "\nactual: %v"+
2959 "\nexpected: %v",
2960 actual,
2961 expected,
2962 )
2963 }
2964}
2965
2966const runtimeLibAndroidBp = `
2967 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002968 name: "liball_available",
2969 vendor_available: true,
2970 product_available: true,
2971 no_libcrt : true,
2972 nocrt : true,
2973 system_shared_libs : [],
2974 }
2975 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002976 name: "libvendor_available1",
2977 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002978 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002979 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002980 nocrt : true,
2981 system_shared_libs : [],
2982 }
2983 cc_library {
2984 name: "libvendor_available2",
2985 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002986 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002987 target: {
2988 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002989 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002990 }
2991 },
Yi Konge7fe9912019-06-02 00:53:50 -07002992 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002993 nocrt : true,
2994 system_shared_libs : [],
2995 }
2996 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002997 name: "libproduct_vendor",
2998 product_specific: true,
2999 vendor_available: true,
3000 no_libcrt : true,
3001 nocrt : true,
3002 system_shared_libs : [],
3003 }
3004 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08003005 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09003006 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07003007 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003008 nocrt : true,
3009 system_shared_libs : [],
3010 }
3011 cc_library {
3012 name: "libvendor1",
3013 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003014 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003015 nocrt : true,
3016 system_shared_libs : [],
3017 }
3018 cc_library {
3019 name: "libvendor2",
3020 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09003021 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09003022 no_libcrt : true,
3023 nocrt : true,
3024 system_shared_libs : [],
3025 }
3026 cc_library {
3027 name: "libproduct_available1",
3028 product_available: true,
3029 runtime_libs: ["liball_available"],
3030 no_libcrt : true,
3031 nocrt : true,
3032 system_shared_libs : [],
3033 }
3034 cc_library {
3035 name: "libproduct1",
3036 product_specific: true,
3037 no_libcrt : true,
3038 nocrt : true,
3039 system_shared_libs : [],
3040 }
3041 cc_library {
3042 name: "libproduct2",
3043 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09003044 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07003045 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08003046 nocrt : true,
3047 system_shared_libs : [],
3048 }
3049`
3050
3051func TestRuntimeLibs(t *testing.T) {
3052 ctx := testCc(t, runtimeLibAndroidBp)
3053
3054 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08003055 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003056
Justin Yun8a2600c2020-12-07 12:44:03 +09003057 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3058 checkRuntimeLibs(t, []string{"liball_available"}, module)
3059
3060 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3061 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003062
3063 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003064 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003065
3066 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
3067 // and vendor variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003068 variant = "android_vendor.29_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003069
Justin Yun8a2600c2020-12-07 12:44:03 +09003070 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3071 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003072
3073 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09003074 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003075
3076 // runtime_libs for product variants have '.product' suffixes if the modules have both core
3077 // and product variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003078 variant = "android_product.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003079
3080 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
3081 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
3082
3083 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09003084 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003085}
3086
3087func TestExcludeRuntimeLibs(t *testing.T) {
3088 ctx := testCc(t, runtimeLibAndroidBp)
3089
Colin Cross7113d202019-11-20 16:39:12 -08003090 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003091 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
3092 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003093
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003094 variant = "android_vendor.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09003095 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08003096 checkRuntimeLibs(t, nil, module)
3097}
3098
3099func TestRuntimeLibsNoVndk(t *testing.T) {
3100 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
3101
3102 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
3103
Colin Cross7113d202019-11-20 16:39:12 -08003104 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08003105
Justin Yun8a2600c2020-12-07 12:44:03 +09003106 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
3107 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003108
3109 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09003110 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09003111
3112 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09003113 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08003114}
3115
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003116func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09003117 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003118 actual := module.Properties.AndroidMkStaticLibs
3119 if !reflect.DeepEqual(actual, expected) {
3120 t.Errorf("incorrect static_libs"+
3121 "\nactual: %v"+
3122 "\nexpected: %v",
3123 actual,
3124 expected,
3125 )
3126 }
3127}
3128
3129const staticLibAndroidBp = `
3130 cc_library {
3131 name: "lib1",
3132 }
3133 cc_library {
3134 name: "lib2",
3135 static_libs: ["lib1"],
3136 }
3137`
3138
3139func TestStaticLibDepExport(t *testing.T) {
3140 ctx := testCc(t, staticLibAndroidBp)
3141
3142 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003143 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003144 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Ryan Prichardc2018e22021-04-02 20:23:22 -07003145 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003146
3147 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08003148 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003149 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
3150 // libc++_static is linked additionally.
Ryan Prichardc2018e22021-04-02 20:23:22 -07003151 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00003152}
3153
Jiyong Parkd08b6972017-09-26 10:50:54 +09003154var compilerFlagsTestCases = []struct {
3155 in string
3156 out bool
3157}{
3158 {
3159 in: "a",
3160 out: false,
3161 },
3162 {
3163 in: "-a",
3164 out: true,
3165 },
3166 {
3167 in: "-Ipath/to/something",
3168 out: false,
3169 },
3170 {
3171 in: "-isystempath/to/something",
3172 out: false,
3173 },
3174 {
3175 in: "--coverage",
3176 out: false,
3177 },
3178 {
3179 in: "-include a/b",
3180 out: true,
3181 },
3182 {
3183 in: "-include a/b c/d",
3184 out: false,
3185 },
3186 {
3187 in: "-DMACRO",
3188 out: true,
3189 },
3190 {
3191 in: "-DMAC RO",
3192 out: false,
3193 },
3194 {
3195 in: "-a -b",
3196 out: false,
3197 },
3198 {
3199 in: "-DMACRO=definition",
3200 out: true,
3201 },
3202 {
3203 in: "-DMACRO=defi nition",
3204 out: true, // TODO(jiyong): this should be false
3205 },
3206 {
3207 in: "-DMACRO(x)=x + 1",
3208 out: true,
3209 },
3210 {
3211 in: "-DMACRO=\"defi nition\"",
3212 out: true,
3213 },
3214}
3215
3216type mockContext struct {
3217 BaseModuleContext
3218 result bool
3219}
3220
3221func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3222 // CheckBadCompilerFlags calls this function when the flag should be rejected
3223 ctx.result = false
3224}
3225
3226func TestCompilerFlags(t *testing.T) {
3227 for _, testCase := range compilerFlagsTestCases {
3228 ctx := &mockContext{result: true}
3229 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3230 if ctx.result != testCase.out {
3231 t.Errorf("incorrect output:")
3232 t.Errorf(" input: %#v", testCase.in)
3233 t.Errorf(" expected: %#v", testCase.out)
3234 t.Errorf(" got: %#v", ctx.result)
3235 }
3236 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003237}
Jiyong Park374510b2018-03-19 18:23:01 +09003238
3239func TestVendorPublicLibraries(t *testing.T) {
3240 ctx := testCc(t, `
3241 cc_library_headers {
3242 name: "libvendorpublic_headers",
3243 export_include_dirs: ["my_include"],
3244 }
3245 vendor_public_library {
3246 name: "libvendorpublic",
3247 symbol_file: "",
3248 export_public_headers: ["libvendorpublic_headers"],
3249 }
3250 cc_library {
3251 name: "libvendorpublic",
3252 srcs: ["foo.c"],
3253 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07003254 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003255 nocrt: true,
3256 }
3257
3258 cc_library {
3259 name: "libsystem",
3260 shared_libs: ["libvendorpublic"],
3261 vendor: false,
3262 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003263 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003264 nocrt: true,
3265 }
3266 cc_library {
3267 name: "libvendor",
3268 shared_libs: ["libvendorpublic"],
3269 vendor: true,
3270 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07003271 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09003272 nocrt: true,
3273 }
3274 `)
3275
Colin Cross7113d202019-11-20 16:39:12 -08003276 coreVariant := "android_arm64_armv8-a_shared"
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003277 vendorVariant := "android_vendor.29_arm64_armv8-a_shared"
Jiyong Park374510b2018-03-19 18:23:01 +09003278
3279 // test if header search paths are correctly added
3280 // _static variant is used since _shared reuses *.o from the static variant
Colin Cross7113d202019-11-20 16:39:12 -08003281 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
Jiyong Park374510b2018-03-19 18:23:01 +09003282 cflags := cc.Args["cFlags"]
3283 if !strings.Contains(cflags, "-Imy_include") {
3284 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
3285 }
3286
3287 // test if libsystem is linked to the stub
Colin Cross7113d202019-11-20 16:39:12 -08003288 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003289 libflags := ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003290 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
Jiyong Park374510b2018-03-19 18:23:01 +09003291 if !strings.Contains(libflags, stubPaths[0].String()) {
3292 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
3293 }
3294
3295 // test if libvendor is linked to the real shared lib
Colin Cross7113d202019-11-20 16:39:12 -08003296 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09003297 libflags = ld.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003298 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09003299 if !strings.Contains(libflags, stubPaths[0].String()) {
3300 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
3301 }
3302
3303}
Jiyong Park37b25202018-07-11 10:49:27 +09003304
3305func TestRecovery(t *testing.T) {
3306 ctx := testCc(t, `
3307 cc_library_shared {
3308 name: "librecovery",
3309 recovery: true,
3310 }
3311 cc_library_shared {
3312 name: "librecovery32",
3313 recovery: true,
3314 compile_multilib:"32",
3315 }
Jiyong Park5baac542018-08-28 09:55:37 +09003316 cc_library_shared {
3317 name: "libHalInRecovery",
3318 recovery_available: true,
3319 vendor: true,
3320 }
Jiyong Park37b25202018-07-11 10:49:27 +09003321 `)
3322
3323 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003324 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003325 if len(variants) != 1 || !android.InList(arm64, variants) {
3326 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3327 }
3328
3329 variants = ctx.ModuleVariantsForTests("librecovery32")
3330 if android.InList(arm64, variants) {
3331 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3332 }
Jiyong Park5baac542018-08-28 09:55:37 +09003333
3334 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3335 if !recoveryModule.Platform() {
3336 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3337 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003338}
Jiyong Park5baac542018-08-28 09:55:37 +09003339
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003340func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3341 bp := `
3342 cc_prebuilt_test_library_shared {
3343 name: "test_lib",
3344 relative_install_path: "foo/bar/baz",
3345 srcs: ["srcpath/dontusethispath/baz.so"],
3346 }
3347
3348 cc_test {
3349 name: "main_test",
3350 data_libs: ["test_lib"],
3351 gtest: false,
3352 }
3353 `
3354
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003355 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003356 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003357 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003358 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3359
3360 ctx := testCcWithConfig(t, config)
3361 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3362 testBinary := module.(*Module).linker.(*testBinary)
3363 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3364 if err != nil {
3365 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3366 }
3367 if len(outputFiles) != 1 {
3368 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3369 }
3370 if len(testBinary.dataPaths()) != 1 {
3371 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3372 }
3373
3374 outputPath := outputFiles[0].String()
3375
3376 if !strings.HasSuffix(outputPath, "/main_test") {
3377 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3378 }
Colin Crossaa255532020-07-03 13:18:24 -07003379 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003380 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3381 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3382 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3383 }
3384}
3385
Jiyong Park7ed9de32018-10-15 22:25:07 +09003386func TestVersionedStubs(t *testing.T) {
3387 ctx := testCc(t, `
3388 cc_library_shared {
3389 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003390 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003391 stubs: {
3392 symbol_file: "foo.map.txt",
3393 versions: ["1", "2", "3"],
3394 },
3395 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003396
Jiyong Park7ed9de32018-10-15 22:25:07 +09003397 cc_library_shared {
3398 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003399 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003400 shared_libs: ["libFoo#1"],
3401 }`)
3402
3403 variants := ctx.ModuleVariantsForTests("libFoo")
3404 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003405 "android_arm64_armv8-a_shared",
3406 "android_arm64_armv8-a_shared_1",
3407 "android_arm64_armv8-a_shared_2",
3408 "android_arm64_armv8-a_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003409 "android_arm64_armv8-a_shared_current",
Colin Cross7113d202019-11-20 16:39:12 -08003410 "android_arm_armv7-a-neon_shared",
3411 "android_arm_armv7-a-neon_shared_1",
3412 "android_arm_armv7-a-neon_shared_2",
3413 "android_arm_armv7-a-neon_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003414 "android_arm_armv7-a-neon_shared_current",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003415 }
3416 variantsMismatch := false
3417 if len(variants) != len(expectedVariants) {
3418 variantsMismatch = true
3419 } else {
3420 for _, v := range expectedVariants {
3421 if !inList(v, variants) {
3422 variantsMismatch = false
3423 }
3424 }
3425 }
3426 if variantsMismatch {
3427 t.Errorf("variants of libFoo expected:\n")
3428 for _, v := range expectedVariants {
3429 t.Errorf("%q\n", v)
3430 }
3431 t.Errorf(", but got:\n")
3432 for _, v := range variants {
3433 t.Errorf("%q\n", v)
3434 }
3435 }
3436
Colin Cross7113d202019-11-20 16:39:12 -08003437 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003438 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003439 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003440 if !strings.Contains(libFlags, libFoo1StubPath) {
3441 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3442 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003443
Colin Cross7113d202019-11-20 16:39:12 -08003444 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003445 cFlags := libBarCompileRule.Args["cFlags"]
3446 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3447 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3448 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3449 }
Jiyong Park37b25202018-07-11 10:49:27 +09003450}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003451
Jooyung Hanb04a4992020-03-13 18:57:35 +09003452func TestVersioningMacro(t *testing.T) {
3453 for _, tc := range []struct{ moduleName, expected string }{
3454 {"libc", "__LIBC_API__"},
3455 {"libfoo", "__LIBFOO_API__"},
3456 {"libfoo@1", "__LIBFOO_1_API__"},
3457 {"libfoo-v1", "__LIBFOO_V1_API__"},
3458 {"libfoo.v1", "__LIBFOO_V1_API__"},
3459 } {
3460 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3461 }
3462}
3463
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003464func TestStaticExecutable(t *testing.T) {
3465 ctx := testCc(t, `
3466 cc_binary {
3467 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003468 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003469 static_executable: true,
3470 }`)
3471
Colin Cross7113d202019-11-20 16:39:12 -08003472 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003473 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3474 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003475 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003476 for _, lib := range systemStaticLibs {
3477 if !strings.Contains(libFlags, lib) {
3478 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3479 }
3480 }
3481 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3482 for _, lib := range systemSharedLibs {
3483 if strings.Contains(libFlags, lib) {
3484 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3485 }
3486 }
3487}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003488
3489func TestStaticDepsOrderWithStubs(t *testing.T) {
3490 ctx := testCc(t, `
3491 cc_binary {
3492 name: "mybin",
3493 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003494 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003495 static_executable: true,
3496 stl: "none",
3497 }
3498
3499 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003500 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003501 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003502 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003503 stl: "none",
3504 }
3505
3506 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003507 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003508 srcs: ["foo.c"],
3509 stl: "none",
3510 stubs: {
3511 versions: ["1"],
3512 },
3513 }`)
3514
Colin Cross0de8a1e2020-09-18 14:15:30 -07003515 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3516 actual := mybin.Implicits[:2]
Colin Crossf9aabd72020-02-15 11:29:50 -08003517 expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003518
3519 if !reflect.DeepEqual(actual, expected) {
3520 t.Errorf("staticDeps orderings were not propagated correctly"+
3521 "\nactual: %v"+
3522 "\nexpected: %v",
3523 actual,
3524 expected,
3525 )
3526 }
3527}
Jooyung Han38002912019-05-16 04:01:54 +09003528
Jooyung Hand48f3c32019-08-23 11:18:57 +09003529func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3530 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3531 cc_library {
3532 name: "libA",
3533 srcs: ["foo.c"],
3534 shared_libs: ["libB"],
3535 stl: "none",
3536 }
3537
3538 cc_library {
3539 name: "libB",
3540 srcs: ["foo.c"],
3541 enabled: false,
3542 stl: "none",
3543 }
3544 `)
3545}
3546
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003547// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3548// correctly.
3549func TestFuzzTarget(t *testing.T) {
3550 ctx := testCc(t, `
3551 cc_fuzz {
3552 name: "fuzz_smoke_test",
3553 srcs: ["foo.c"],
3554 }`)
3555
Paul Duffin075c4172019-12-19 19:06:13 +00003556 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003557 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3558}
3559
Jiyong Park29074592019-07-07 16:27:47 +09003560func TestAidl(t *testing.T) {
3561}
3562
Jooyung Han38002912019-05-16 04:01:54 +09003563func assertString(t *testing.T, got, expected string) {
3564 t.Helper()
3565 if got != expected {
3566 t.Errorf("expected %q got %q", expected, got)
3567 }
3568}
3569
3570func assertArrayString(t *testing.T, got, expected []string) {
3571 t.Helper()
3572 if len(got) != len(expected) {
3573 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3574 return
3575 }
3576 for i := range got {
3577 if got[i] != expected[i] {
3578 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3579 i, expected[i], expected, got[i], got)
3580 return
3581 }
3582 }
3583}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003584
Jooyung Han0302a842019-10-30 18:43:49 +09003585func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3586 t.Helper()
3587 assertArrayString(t, android.SortedStringKeys(m), expected)
3588}
3589
Colin Crosse1bb5d02019-09-24 14:55:04 -07003590func TestDefaults(t *testing.T) {
3591 ctx := testCc(t, `
3592 cc_defaults {
3593 name: "defaults",
3594 srcs: ["foo.c"],
3595 static: {
3596 srcs: ["bar.c"],
3597 },
3598 shared: {
3599 srcs: ["baz.c"],
3600 },
Liz Kammer3cf52112021-03-31 15:42:03 -04003601 bazel_module: {
3602 bp2build_available: true,
3603 },
Colin Crosse1bb5d02019-09-24 14:55:04 -07003604 }
3605
3606 cc_library_static {
3607 name: "libstatic",
3608 defaults: ["defaults"],
3609 }
3610
3611 cc_library_shared {
3612 name: "libshared",
3613 defaults: ["defaults"],
3614 }
3615
3616 cc_library {
3617 name: "libboth",
3618 defaults: ["defaults"],
3619 }
3620
3621 cc_binary {
3622 name: "binary",
3623 defaults: ["defaults"],
3624 }`)
3625
3626 pathsToBase := func(paths android.Paths) []string {
3627 var ret []string
3628 for _, p := range paths {
3629 ret = append(ret, p.Base())
3630 }
3631 return ret
3632 }
3633
Colin Cross7113d202019-11-20 16:39:12 -08003634 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003635 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3636 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3637 }
Colin Cross7113d202019-11-20 16:39:12 -08003638 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003639 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3640 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3641 }
Colin Cross7113d202019-11-20 16:39:12 -08003642 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003643 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3644 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3645 }
3646
Colin Cross7113d202019-11-20 16:39:12 -08003647 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003648 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3649 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3650 }
Colin Cross7113d202019-11-20 16:39:12 -08003651 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003652 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3653 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3654 }
3655}
Colin Crosseabaedd2020-02-06 17:01:55 -08003656
3657func TestProductVariableDefaults(t *testing.T) {
3658 bp := `
3659 cc_defaults {
3660 name: "libfoo_defaults",
3661 srcs: ["foo.c"],
3662 cppflags: ["-DFOO"],
3663 product_variables: {
3664 debuggable: {
3665 cppflags: ["-DBAR"],
3666 },
3667 },
3668 }
3669
3670 cc_library {
3671 name: "libfoo",
3672 defaults: ["libfoo_defaults"],
3673 }
3674 `
3675
Paul Duffin8567f222021-03-23 00:02:06 +00003676 result := android.GroupFixturePreparers(
3677 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003678 android.PrepareForTestWithVariables,
Colin Crosseabaedd2020-02-06 17:01:55 -08003679
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003680 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3681 variables.Debuggable = BoolPtr(true)
3682 }),
3683 ).RunTestWithBp(t, bp)
Colin Crosseabaedd2020-02-06 17:01:55 -08003684
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003685 libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
Paul Duffine84b1332021-03-12 11:59:43 +00003686 android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
Colin Crosseabaedd2020-02-06 17:01:55 -08003687}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003688
3689func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3690 t.Parallel()
3691 bp := `
3692 cc_library_static {
3693 name: "libfoo",
3694 srcs: ["foo.c"],
3695 whole_static_libs: ["libbar"],
3696 }
3697
3698 cc_library_static {
3699 name: "libbar",
3700 whole_static_libs: ["libmissing"],
3701 }
3702 `
3703
Paul Duffin8567f222021-03-23 00:02:06 +00003704 result := android.GroupFixturePreparers(
3705 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003706 android.PrepareForTestWithAllowMissingDependencies,
3707 ).RunTestWithBp(t, bp)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003708
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003709 libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003710 android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003711
Paul Duffine84b1332021-03-12 11:59:43 +00003712 android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
Colin Crosse4f6eba2020-09-22 18:11:25 -07003713
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003714 libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003715 android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
Colin Crosse4f6eba2020-09-22 18:11:25 -07003716}
Colin Crosse9fe2942020-11-10 18:12:15 -08003717
3718func TestInstallSharedLibs(t *testing.T) {
3719 bp := `
3720 cc_binary {
3721 name: "bin",
3722 host_supported: true,
3723 shared_libs: ["libshared"],
3724 runtime_libs: ["libruntime"],
3725 srcs: [":gen"],
3726 }
3727
3728 cc_library_shared {
3729 name: "libshared",
3730 host_supported: true,
3731 shared_libs: ["libtransitive"],
3732 }
3733
3734 cc_library_shared {
3735 name: "libtransitive",
3736 host_supported: true,
3737 }
3738
3739 cc_library_shared {
3740 name: "libruntime",
3741 host_supported: true,
3742 }
3743
3744 cc_binary_host {
3745 name: "tool",
3746 srcs: ["foo.cpp"],
3747 }
3748
3749 genrule {
3750 name: "gen",
3751 tools: ["tool"],
3752 out: ["gen.cpp"],
3753 cmd: "$(location tool) $(out)",
3754 }
3755 `
3756
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003757 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Crosse9fe2942020-11-10 18:12:15 -08003758 ctx := testCcWithConfig(t, config)
3759
3760 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3761 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3762 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3763 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3764 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3765
3766 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3767 t.Errorf("expected host bin dependency %q, got %q", w, g)
3768 }
3769
3770 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3771 t.Errorf("expected host bin dependency %q, got %q", w, g)
3772 }
3773
3774 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3775 t.Errorf("expected host bin dependency %q, got %q", w, g)
3776 }
3777
3778 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3779 t.Errorf("expected host bin dependency %q, got %q", w, g)
3780 }
3781
3782 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3783 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3784 }
3785
3786 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3787 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3788 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3789 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3790
3791 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3792 t.Errorf("expected device bin dependency %q, got %q", w, g)
3793 }
3794
3795 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3796 t.Errorf("expected device bin dependency %q, got %q", w, g)
3797 }
3798
3799 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3800 t.Errorf("expected device bin dependency %q, got %q", w, g)
3801 }
3802
3803 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3804 t.Errorf("expected device bin dependency %q, got %q", w, g)
3805 }
3806
3807 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3808 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3809 }
3810
3811}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003812
3813func TestStubsLibReexportsHeaders(t *testing.T) {
3814 ctx := testCc(t, `
3815 cc_library_shared {
3816 name: "libclient",
3817 srcs: ["foo.c"],
3818 shared_libs: ["libfoo#1"],
3819 }
3820
3821 cc_library_shared {
3822 name: "libfoo",
3823 srcs: ["foo.c"],
3824 shared_libs: ["libbar"],
3825 export_shared_lib_headers: ["libbar"],
3826 stubs: {
3827 symbol_file: "foo.map.txt",
3828 versions: ["1", "2", "3"],
3829 },
3830 }
3831
3832 cc_library_shared {
3833 name: "libbar",
3834 export_include_dirs: ["include/libbar"],
3835 srcs: ["foo.c"],
3836 }`)
3837
3838 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3839
3840 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3841 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3842 }
3843}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003844
3845func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3846 ctx := testCc(t, `
3847 cc_library {
3848 name: "libfoo",
3849 srcs: ["a/Foo.aidl"],
3850 aidl: { flags: ["-Werror"], },
3851 }
3852 `)
3853
3854 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3855 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3856 aidlCommand := manifest.Commands[0].GetCommand()
3857 expectedAidlFlag := "-Werror"
3858 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3859 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3860 }
3861}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003862
Jiyong Parka008fb02021-03-16 17:15:53 +09003863func TestMinSdkVersionInClangTriple(t *testing.T) {
3864 ctx := testCc(t, `
3865 cc_library_shared {
3866 name: "libfoo",
3867 srcs: ["foo.c"],
3868 min_sdk_version: "29",
3869 }`)
3870
3871 cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3872 android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
3873}
3874
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003875type MemtagNoteType int
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003876
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003877const (
3878 None MemtagNoteType = iota + 1
3879 Sync
3880 Async
3881)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003882
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003883func (t MemtagNoteType) str() string {
3884 switch t {
3885 case None:
3886 return "none"
3887 case Sync:
3888 return "sync"
3889 case Async:
3890 return "async"
3891 default:
3892 panic("invalid note type")
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003893 }
3894}
3895
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003896func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
3897 note_async := "note_memtag_heap_async"
3898 note_sync := "note_memtag_heap_sync"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003899
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003900 found := None
3901 implicits := m.Rule("ld").Implicits
3902 for _, lib := range implicits {
3903 if strings.Contains(lib.Rel(), note_async) {
3904 found = Async
3905 break
3906 } else if strings.Contains(lib.Rel(), note_sync) {
3907 found = Sync
3908 break
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003909 }
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003910 }
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003911
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003912 if found != expected {
3913 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
3914 }
3915}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003916
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003917var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
3918 android.FixtureModifyMockFS(func(fs android.MockFS) {
3919 templateBp := `
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003920 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003921 name: "%[1]s_test",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003922 gtest: false,
3923 }
3924
3925 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003926 name: "%[1]s_test_false",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003927 gtest: false,
3928 sanitize: { memtag_heap: false },
3929 }
3930
3931 cc_test {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003932 name: "%[1]s_test_true",
3933 gtest: false,
3934 sanitize: { memtag_heap: true },
3935 }
3936
3937 cc_test {
3938 name: "%[1]s_test_true_nodiag",
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003939 gtest: false,
3940 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3941 }
3942
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003943 cc_test {
3944 name: "%[1]s_test_true_diag",
3945 gtest: false,
3946 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
3947 }
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003948
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003949 cc_binary {
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003950 name: "%[1]s_binary",
3951 }
3952
3953 cc_binary {
3954 name: "%[1]s_binary_false",
3955 sanitize: { memtag_heap: false },
3956 }
3957
3958 cc_binary {
3959 name: "%[1]s_binary_true",
3960 sanitize: { memtag_heap: true },
3961 }
3962
3963 cc_binary {
3964 name: "%[1]s_binary_true_nodiag",
3965 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
3966 }
3967
3968 cc_binary {
3969 name: "%[1]s_binary_true_diag",
3970 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003971 }
3972 `
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003973 subdirDefaultBp := fmt.Sprintf(templateBp, "default")
3974 subdirExcludeBp := fmt.Sprintf(templateBp, "exclude")
3975 subdirSyncBp := fmt.Sprintf(templateBp, "sync")
3976 subdirAsyncBp := fmt.Sprintf(templateBp, "async")
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08003977
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003978 fs.Merge(android.MockFS{
3979 "subdir_default/Android.bp": []byte(subdirDefaultBp),
3980 "subdir_exclude/Android.bp": []byte(subdirExcludeBp),
3981 "subdir_sync/Android.bp": []byte(subdirSyncBp),
3982 "subdir_async/Android.bp": []byte(subdirAsyncBp),
3983 })
3984 }),
3985 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3986 variables.MemtagHeapExcludePaths = []string{"subdir_exclude"}
Evgenii Stepanov779b64e2021-04-09 14:33:10 -07003987 // "subdir_exclude" is covered by both include and exclude paths. Exclude wins.
3988 variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync", "subdir_exclude"}
3989 variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async", "subdir_exclude"}
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003990 }),
3991)
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08003992
3993func TestSanitizeMemtagHeap(t *testing.T) {
3994 variant := "android_arm64_armv8-a"
3995
Paul Duffin8567f222021-03-23 00:02:06 +00003996 result := android.GroupFixturePreparers(
3997 prepareForCcTest,
3998 prepareForTestWithMemtagHeap,
3999 ).RunTest(t)
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00004000 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004001
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004002 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4003 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4004 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4005 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4006 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4007
4008 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), None)
4009 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4010 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4011 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4012 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4013
4014 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4015 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4016 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4017 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4018 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4019
4020 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4021 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4022 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4023 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4024 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4025
4026 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4027 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4028 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4029 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4030 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4031
4032 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4033 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4034 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4035 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4036 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4037
4038 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4039 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4040 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4041 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4042 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4043
4044 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4045 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4046 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4047 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4048 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4049}
4050
4051func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004052 variant := "android_arm64_armv8-a"
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004053
Paul Duffin8567f222021-03-23 00:02:06 +00004054 result := android.GroupFixturePreparers(
4055 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00004056 prepareForTestWithMemtagHeap,
4057 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
4058 variables.SanitizeDevice = []string{"memtag_heap"}
4059 }),
4060 ).RunTest(t)
4061 ctx := result.TestContext
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004062
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004063 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4064 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4065 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Async)
4066 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4067 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -08004068
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004069 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Async)
4070 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4071 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Async)
4072 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4073 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4074
4075 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4076 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4077 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Async)
4078 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4079 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4080
4081 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4082 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4083 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Async)
4084 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4085 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4086
4087 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4088 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4089 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Async)
4090 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4091 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4092
4093 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Async)
4094 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4095 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Async)
4096 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4097 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4098
4099 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4100 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4101 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4102 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4103 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4104
4105 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4106 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4107 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4108 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4109 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
4110}
4111
4112func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
4113 variant := "android_arm64_armv8-a"
4114
Paul Duffin8567f222021-03-23 00:02:06 +00004115 result := android.GroupFixturePreparers(
4116 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00004117 prepareForTestWithMemtagHeap,
4118 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
4119 variables.SanitizeDevice = []string{"memtag_heap"}
4120 variables.SanitizeDeviceDiag = []string{"memtag_heap"}
4121 }),
4122 ).RunTest(t)
4123 ctx := result.TestContext
Evgenii Stepanov04896ca2021-01-12 18:28:33 -08004124
4125 checkHasMemtagNote(t, ctx.ModuleForTests("default_test", variant), Sync)
4126 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_false", variant), None)
4127 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true", variant), Sync)
4128 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_nodiag", variant), Async)
4129 checkHasMemtagNote(t, ctx.ModuleForTests("default_test_true_diag", variant), Sync)
4130
4131 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary", variant), Sync)
4132 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_false", variant), None)
4133 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true", variant), Sync)
4134 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_nodiag", variant), Async)
4135 checkHasMemtagNote(t, ctx.ModuleForTests("default_binary_true_diag", variant), Sync)
4136
4137 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test", variant), Sync)
4138 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_false", variant), None)
4139 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true", variant), Sync)
4140 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_nodiag", variant), Async)
4141 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_test_true_diag", variant), Sync)
4142
4143 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary", variant), None)
4144 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_false", variant), None)
4145 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true", variant), Sync)
4146 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_nodiag", variant), Async)
4147 checkHasMemtagNote(t, ctx.ModuleForTests("exclude_binary_true_diag", variant), Sync)
4148
4149 checkHasMemtagNote(t, ctx.ModuleForTests("async_test", variant), Sync)
4150 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_false", variant), None)
4151 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true", variant), Sync)
4152 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_nodiag", variant), Async)
4153 checkHasMemtagNote(t, ctx.ModuleForTests("async_test_true_diag", variant), Sync)
4154
4155 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary", variant), Sync)
4156 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_false", variant), None)
4157 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true", variant), Sync)
4158 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_nodiag", variant), Async)
4159 checkHasMemtagNote(t, ctx.ModuleForTests("async_binary_true_diag", variant), Sync)
4160
4161 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test", variant), Sync)
4162 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_false", variant), None)
4163 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true", variant), Sync)
4164 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_nodiag", variant), Async)
4165 checkHasMemtagNote(t, ctx.ModuleForTests("sync_test_true_diag", variant), Sync)
4166
4167 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary", variant), Sync)
4168 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_false", variant), None)
4169 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true", variant), Sync)
4170 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_nodiag", variant), Async)
4171 checkHasMemtagNote(t, ctx.ModuleForTests("sync_binary_true_diag", variant), Sync)
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07004172}
Paul Duffin3cb603e2021-02-19 13:57:10 +00004173
4174func TestIncludeDirsExporting(t *testing.T) {
4175
4176 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
4177 // embedded newline characters alone.
4178 trimIndentingSpaces := func(s string) string {
4179 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
4180 }
4181
4182 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
4183 t.Helper()
4184 expected = trimIndentingSpaces(expected)
4185 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
4186 if expected != actual {
4187 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
4188 }
4189 }
4190
4191 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
4192
4193 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
4194 t.Helper()
4195 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
4196 name := module.Name()
4197
4198 for _, checker := range checkers {
4199 checker(t, name, exported)
4200 }
4201 }
4202
4203 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
4204 return func(t *testing.T, name string, exported FlagExporterInfo) {
4205 t.Helper()
4206 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
4207 }
4208 }
4209
4210 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
4211 return func(t *testing.T, name string, exported FlagExporterInfo) {
4212 t.Helper()
4213 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
4214 }
4215 }
4216
4217 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
4218 return func(t *testing.T, name string, exported FlagExporterInfo) {
4219 t.Helper()
4220 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
4221 }
4222 }
4223
4224 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
4225 return func(t *testing.T, name string, exported FlagExporterInfo) {
4226 t.Helper()
4227 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
4228 }
4229 }
4230
4231 genRuleModules := `
4232 genrule {
4233 name: "genrule_foo",
4234 cmd: "generate-foo",
4235 out: [
4236 "generated_headers/foo/generated_header.h",
4237 ],
4238 export_include_dirs: [
4239 "generated_headers",
4240 ],
4241 }
4242
4243 genrule {
4244 name: "genrule_bar",
4245 cmd: "generate-bar",
4246 out: [
4247 "generated_headers/bar/generated_header.h",
4248 ],
4249 export_include_dirs: [
4250 "generated_headers",
4251 ],
4252 }
4253 `
4254
4255 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
4256 ctx := testCc(t, genRuleModules+`
4257 cc_library {
4258 name: "libfoo",
4259 srcs: ["foo.c"],
4260 export_include_dirs: ["foo/standard"],
4261 export_system_include_dirs: ["foo/system"],
4262 generated_headers: ["genrule_foo"],
4263 export_generated_headers: ["genrule_foo"],
4264 }
4265
4266 cc_library {
4267 name: "libbar",
4268 srcs: ["bar.c"],
4269 shared_libs: ["libfoo"],
4270 export_include_dirs: ["bar/standard"],
4271 export_system_include_dirs: ["bar/system"],
4272 generated_headers: ["genrule_bar"],
4273 export_generated_headers: ["genrule_bar"],
4274 }
4275 `)
4276 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4277 checkIncludeDirs(t, ctx, foo,
4278 expectedIncludeDirs(`
4279 foo/standard
4280 .intermediates/genrule_foo/gen/generated_headers
4281 `),
4282 expectedSystemIncludeDirs(`foo/system`),
4283 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4284 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4285 )
4286
4287 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4288 checkIncludeDirs(t, ctx, bar,
4289 expectedIncludeDirs(`
4290 bar/standard
4291 .intermediates/genrule_bar/gen/generated_headers
4292 `),
4293 expectedSystemIncludeDirs(`bar/system`),
4294 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4295 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
4296 )
4297 })
4298
4299 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
4300 ctx := testCc(t, genRuleModules+`
4301 cc_library {
4302 name: "libfoo",
4303 srcs: ["foo.c"],
4304 export_include_dirs: ["foo/standard"],
4305 export_system_include_dirs: ["foo/system"],
4306 generated_headers: ["genrule_foo"],
4307 export_generated_headers: ["genrule_foo"],
4308 }
4309
4310 cc_library {
4311 name: "libbar",
4312 srcs: ["bar.c"],
4313 whole_static_libs: ["libfoo"],
4314 export_include_dirs: ["bar/standard"],
4315 export_system_include_dirs: ["bar/system"],
4316 generated_headers: ["genrule_bar"],
4317 export_generated_headers: ["genrule_bar"],
4318 }
4319 `)
4320 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4321 checkIncludeDirs(t, ctx, foo,
4322 expectedIncludeDirs(`
4323 foo/standard
4324 .intermediates/genrule_foo/gen/generated_headers
4325 `),
4326 expectedSystemIncludeDirs(`foo/system`),
4327 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4328 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
4329 )
4330
4331 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
4332 checkIncludeDirs(t, ctx, bar,
4333 expectedIncludeDirs(`
4334 bar/standard
4335 foo/standard
4336 .intermediates/genrule_foo/gen/generated_headers
4337 .intermediates/genrule_bar/gen/generated_headers
4338 `),
4339 expectedSystemIncludeDirs(`
4340 bar/system
4341 foo/system
4342 `),
4343 expectedGeneratedHeaders(`
4344 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4345 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4346 `),
4347 expectedOrderOnlyDeps(`
4348 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
4349 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
4350 `),
4351 )
4352 })
4353
Paul Duffin3cb603e2021-02-19 13:57:10 +00004354 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
4355 ctx := testCc(t, genRuleModules+`
4356 cc_library_shared {
4357 name: "libfoo",
4358 srcs: [
4359 "foo.c",
4360 "b.aidl",
4361 "a.proto",
4362 ],
4363 aidl: {
4364 export_aidl_headers: true,
4365 }
4366 }
4367 `)
4368 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4369 checkIncludeDirs(t, ctx, foo,
4370 expectedIncludeDirs(`
4371 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
4372 `),
4373 expectedSystemIncludeDirs(``),
4374 expectedGeneratedHeaders(`
4375 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4376 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4377 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004378 `),
4379 expectedOrderOnlyDeps(`
4380 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
4381 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
4382 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004383 `),
4384 )
4385 })
4386
Paul Duffin3cb603e2021-02-19 13:57:10 +00004387 t.Run("ensure only proto headers are exported", func(t *testing.T) {
4388 ctx := testCc(t, genRuleModules+`
4389 cc_library_shared {
4390 name: "libfoo",
4391 srcs: [
4392 "foo.c",
4393 "b.aidl",
4394 "a.proto",
4395 ],
4396 proto: {
4397 export_proto_headers: true,
4398 }
4399 }
4400 `)
4401 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4402 checkIncludeDirs(t, ctx, foo,
4403 expectedIncludeDirs(`
4404 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
4405 `),
4406 expectedSystemIncludeDirs(``),
4407 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004408 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4409 `),
4410 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00004411 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
4412 `),
4413 )
4414 })
4415
Paul Duffin33056e82021-02-19 13:49:08 +00004416 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00004417 ctx := testCc(t, genRuleModules+`
4418 cc_library_shared {
4419 name: "libfoo",
4420 srcs: [
4421 "foo.c",
4422 "a.sysprop",
4423 "b.aidl",
4424 "a.proto",
4425 ],
4426 }
4427 `)
4428 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
4429 checkIncludeDirs(t, ctx, foo,
4430 expectedIncludeDirs(`
4431 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
4432 `),
4433 expectedSystemIncludeDirs(``),
4434 expectedGeneratedHeaders(`
4435 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004436 `),
4437 expectedOrderOnlyDeps(`
4438 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
4439 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00004440 `),
4441 )
4442 })
4443}