blob: 51a6a271f3e44d65cc926eff99fd1b2b705914bc [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
Jiyong Park6a43f042017-10-12 23:05:00 +0900155func TestVendorSrc(t *testing.T) {
156 ctx := testCc(t, `
157 cc_library {
158 name: "libTest",
159 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700160 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800161 nocrt: true,
162 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900163 vendor_available: true,
164 target: {
165 vendor: {
166 srcs: ["bar.c"],
167 },
168 },
169 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900170 `)
171
Logan Chienf3511742017-10-31 18:04:35 +0800172 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900173 var objs []string
174 for _, o := range ld.Inputs {
175 objs = append(objs, o.Base())
176 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800177 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900178 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
179 }
180}
181
Justin Yun7f99ec72021-04-12 13:19:28 +0900182func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) {
183 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
184 partitionDefined := false
185 checkPartition := func(specific bool, partition string) {
186 if specific {
187 if expected != partition && !partitionDefined {
188 // The variant is installed to the 'partition'
189 t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition)
190 }
191 partitionDefined = true
192 } else {
193 // The variant is not installed to the 'partition'
194 if expected == partition {
195 t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition)
196 }
197 }
198 }
199 socSpecific := func(m *Module) bool {
200 return m.SocSpecific() || m.socSpecificModuleContext()
201 }
202 deviceSpecific := func(m *Module) bool {
203 return m.DeviceSpecific() || m.deviceSpecificModuleContext()
204 }
205 productSpecific := func(m *Module) bool {
206 return m.ProductSpecific() || m.productSpecificModuleContext()
207 }
208 systemExtSpecific := func(m *Module) bool {
209 return m.SystemExtSpecific()
210 }
211 checkPartition(socSpecific(mod), "vendor")
212 checkPartition(deviceSpecific(mod), "odm")
213 checkPartition(productSpecific(mod), "product")
214 checkPartition(systemExtSpecific(mod), "system_ext")
215 if !partitionDefined && expected != "system" {
216 t.Errorf("%s variant of %q is expected to be installed to %s partition,"+
217 " but installed to system partition", variant, name, expected)
218 }
219}
220
221func TestInstallPartition(t *testing.T) {
222 t.Helper()
223 ctx := prepareForCcTest.RunTestWithBp(t, `
224 cc_library {
225 name: "libsystem",
226 }
227 cc_library {
228 name: "libsystem_ext",
229 system_ext_specific: true,
230 }
231 cc_library {
232 name: "libproduct",
233 product_specific: true,
234 }
235 cc_library {
236 name: "libvendor",
237 vendor: true,
238 }
239 cc_library {
240 name: "libodm",
241 device_specific: true,
242 }
243 cc_library {
244 name: "liball_available",
245 vendor_available: true,
246 product_available: true,
247 }
248 cc_library {
249 name: "libsystem_ext_all_available",
250 system_ext_specific: true,
251 vendor_available: true,
252 product_available: true,
253 }
254 cc_library {
255 name: "liball_available_odm",
256 odm_available: true,
257 product_available: true,
258 }
259 cc_library {
260 name: "libproduct_vendoravailable",
261 product_specific: true,
262 vendor_available: true,
263 }
264 cc_library {
265 name: "libproduct_odmavailable",
266 product_specific: true,
267 odm_available: true,
268 }
269 `).TestContext
270
271 checkInstallPartition(t, ctx, "libsystem", coreVariant, "system")
272 checkInstallPartition(t, ctx, "libsystem_ext", coreVariant, "system_ext")
273 checkInstallPartition(t, ctx, "libproduct", productVariant, "product")
274 checkInstallPartition(t, ctx, "libvendor", vendorVariant, "vendor")
275 checkInstallPartition(t, ctx, "libodm", vendorVariant, "odm")
276
277 checkInstallPartition(t, ctx, "liball_available", coreVariant, "system")
278 checkInstallPartition(t, ctx, "liball_available", productVariant, "product")
279 checkInstallPartition(t, ctx, "liball_available", vendorVariant, "vendor")
280
281 checkInstallPartition(t, ctx, "libsystem_ext_all_available", coreVariant, "system_ext")
282 checkInstallPartition(t, ctx, "libsystem_ext_all_available", productVariant, "product")
283 checkInstallPartition(t, ctx, "libsystem_ext_all_available", vendorVariant, "vendor")
284
285 checkInstallPartition(t, ctx, "liball_available_odm", coreVariant, "system")
286 checkInstallPartition(t, ctx, "liball_available_odm", productVariant, "product")
287 checkInstallPartition(t, ctx, "liball_available_odm", vendorVariant, "odm")
288
289 checkInstallPartition(t, ctx, "libproduct_vendoravailable", productVariant, "product")
290 checkInstallPartition(t, ctx, "libproduct_vendoravailable", vendorVariant, "vendor")
291
292 checkInstallPartition(t, ctx, "libproduct_odmavailable", productVariant, "product")
293 checkInstallPartition(t, ctx, "libproduct_odmavailable", vendorVariant, "odm")
294}
295
Logan Chienf3511742017-10-31 18:04:35 +0800296func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
Justin Yun0ecf0b22020-02-28 15:07:59 +0900297 isVndkSp bool, extends string, variant string) {
Logan Chienf3511742017-10-31 18:04:35 +0800298
Logan Chiend3c59a22018-03-29 14:08:15 +0800299 t.Helper()
300
Justin Yun0ecf0b22020-02-28 15:07:59 +0900301 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
Logan Chienf3511742017-10-31 18:04:35 +0800302
303 // Check library properties.
304 lib, ok := mod.compiler.(*libraryDecorator)
305 if !ok {
306 t.Errorf("%q must have libraryDecorator", name)
307 } else if lib.baseInstaller.subDir != subDir {
308 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
309 lib.baseInstaller.subDir)
310 }
311
312 // Check VNDK properties.
313 if mod.vndkdep == nil {
314 t.Fatalf("%q must have `vndkdep`", name)
315 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700316 if !mod.IsVndk() {
317 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800318 }
Ivan Lozanod7586b62021-04-01 09:49:36 -0400319 if mod.IsVndkSp() != isVndkSp {
320 t.Errorf("%q IsVndkSp() must equal to %t", name, isVndkSp)
Logan Chienf3511742017-10-31 18:04:35 +0800321 }
322
323 // Check VNDK extension properties.
324 isVndkExt := extends != ""
Ivan Lozanof9e21722020-12-02 09:00:51 -0500325 if mod.IsVndkExt() != isVndkExt {
326 t.Errorf("%q IsVndkExt() must equal to %t", name, isVndkExt)
Logan Chienf3511742017-10-31 18:04:35 +0800327 }
328
329 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
330 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
331 }
332}
333
Jooyung Han2216fb12019-11-06 16:46:15 +0900334func checkWriteFileOutput(t *testing.T, params android.TestingBuildParams, expected []string) {
335 t.Helper()
Colin Crosscf371cc2020-11-13 11:48:42 -0800336 content := android.ContentFromFileRuleForTests(t, params)
337 actual := strings.FieldsFunc(content, func(r rune) bool { return r == '\n' })
Jooyung Han2216fb12019-11-06 16:46:15 +0900338 assertArrayString(t, actual, expected)
339}
340
Jooyung Han097087b2019-10-22 19:32:18 +0900341func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
342 t.Helper()
343 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
Jooyung Han2216fb12019-11-06 16:46:15 +0900344 checkWriteFileOutput(t, vndkSnapshot.Output(output), expected)
345}
346
347func checkVndkLibrariesOutput(t *testing.T, ctx *android.TestContext, module string, expected []string) {
348 t.Helper()
Colin Cross45bce852021-11-11 22:47:54 -0800349 got := ctx.ModuleForTests(module, "android_common").Module().(*vndkLibrariesTxt).fileNames
Colin Cross78212242021-01-06 14:51:30 -0800350 assertArrayString(t, got, expected)
Jooyung Han097087b2019-10-22 19:32:18 +0900351}
352
Logan Chienf3511742017-10-31 18:04:35 +0800353func TestVndk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800354 bp := `
Logan Chienf3511742017-10-31 18:04:35 +0800355 cc_library {
356 name: "libvndk",
357 vendor_available: true,
358 vndk: {
359 enabled: true,
360 },
361 nocrt: true,
362 }
363
364 cc_library {
365 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900366 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800367 vndk: {
368 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900369 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800370 },
371 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900372 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800373 }
374
375 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +0900376 name: "libvndk_product",
Logan Chienf3511742017-10-31 18:04:35 +0800377 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900378 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800379 vndk: {
380 enabled: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900381 },
382 nocrt: true,
383 target: {
384 vendor: {
385 cflags: ["-DTEST"],
386 },
387 product: {
388 cflags: ["-DTEST"],
389 },
390 },
391 }
392
393 cc_library {
394 name: "libvndk_sp",
395 vendor_available: true,
396 vndk: {
397 enabled: true,
Logan Chienf3511742017-10-31 18:04:35 +0800398 support_system_process: true,
399 },
400 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900401 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800402 }
403
404 cc_library {
405 name: "libvndk_sp_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900406 vendor_available: true,
Logan Chienf3511742017-10-31 18:04:35 +0800407 vndk: {
408 enabled: true,
409 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900410 private: true,
Logan Chienf3511742017-10-31 18:04:35 +0800411 },
412 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900413 target: {
414 vendor: {
415 suffix: "-x",
416 },
417 },
Logan Chienf3511742017-10-31 18:04:35 +0800418 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900419
420 cc_library {
421 name: "libvndk_sp_product_private",
Justin Yunfd9e8042020-12-23 18:23:14 +0900422 vendor_available: true,
423 product_available: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900424 vndk: {
425 enabled: true,
426 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900427 private: true,
Justin Yun6977e8a2020-10-29 18:24:11 +0900428 },
429 nocrt: true,
430 target: {
431 vendor: {
432 suffix: "-x",
433 },
434 product: {
435 suffix: "-x",
436 },
437 },
438 }
439
Justin Yun450ae722021-04-16 19:58:18 +0900440 cc_library {
441 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -0700442 llndk: {
443 symbol_file: "libllndk.map.txt",
444 export_llndk_headers: ["libllndk_headers"],
445 }
Justin Yun450ae722021-04-16 19:58:18 +0900446 }
447
Justin Yun611e8862021-05-24 18:17:33 +0900448 cc_library {
449 name: "libclang_rt.hwasan-llndk",
450 llndk: {
451 symbol_file: "libclang_rt.hwasan.map.txt",
452 }
453 }
454
Colin Cross627280f2021-04-26 16:53:58 -0700455 cc_library_headers {
Justin Yun450ae722021-04-16 19:58:18 +0900456 name: "libllndk_headers",
Colin Cross627280f2021-04-26 16:53:58 -0700457 llndk: {
458 llndk_headers: true,
459 },
Justin Yun450ae722021-04-16 19:58:18 +0900460 export_include_dirs: ["include"],
461 }
462
Colin Crosse4e44bc2020-12-28 13:50:21 -0800463 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900464 name: "llndk.libraries.txt",
465 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800466 vndkcore_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900467 name: "vndkcore.libraries.txt",
468 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800469 vndksp_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900470 name: "vndksp.libraries.txt",
471 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800472 vndkprivate_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900473 name: "vndkprivate.libraries.txt",
474 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800475 vndkproduct_libraries_txt {
Justin Yun8a2600c2020-12-07 12:44:03 +0900476 name: "vndkproduct.libraries.txt",
477 }
Colin Crosse4e44bc2020-12-28 13:50:21 -0800478 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900479 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800480 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900481 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800482 `
483
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000484 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800485 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Justin Yun63e9ec72020-10-29 16:49:43 +0900486 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900487 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800488
489 ctx := testCcWithConfig(t, config)
Logan Chienf3511742017-10-31 18:04:35 +0800490
Jooyung Han261e1582020-10-20 18:54:21 +0900491 // subdir == "" because VNDK libs are not supposed to be installed separately.
492 // They are installed as part of VNDK APEX instead.
493 checkVndkModule(t, ctx, "libvndk", "", false, "", vendorVariant)
494 checkVndkModule(t, ctx, "libvndk_private", "", false, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900495 checkVndkModule(t, ctx, "libvndk_product", "", false, "", vendorVariant)
Jooyung Han261e1582020-10-20 18:54:21 +0900496 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", vendorVariant)
497 checkVndkModule(t, ctx, "libvndk_sp_private", "", true, "", vendorVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +0900498 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", vendorVariant)
Inseob Kim1f086e22019-05-09 13:29:15 +0900499
Justin Yun6977e8a2020-10-29 18:24:11 +0900500 checkVndkModule(t, ctx, "libvndk_product", "", false, "", productVariant)
501 checkVndkModule(t, ctx, "libvndk_sp_product_private", "", true, "", productVariant)
Justin Yun63e9ec72020-10-29 16:49:43 +0900502
Inseob Kim1f086e22019-05-09 13:29:15 +0900503 // Check VNDK snapshot output.
Inseob Kim1f086e22019-05-09 13:29:15 +0900504 snapshotDir := "vndk-snapshot"
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000505 snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
Inseob Kim1f086e22019-05-09 13:29:15 +0900506
507 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
508 "arm64", "armv8-a"))
509 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
510 "arm", "armv7-a-neon"))
511
512 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
513 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900514 llndkLibPath := filepath.Join(vndkLibPath, "shared", "llndk-stub")
515
Inseob Kim1f086e22019-05-09 13:29:15 +0900516 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
517 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
Justin Yun450ae722021-04-16 19:58:18 +0900518 llndkLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "llndk-stub")
Inseob Kim1f086e22019-05-09 13:29:15 +0900519
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900520 variant := "android_vendor.29_arm64_armv8-a_shared"
521 variant2nd := "android_vendor.29_arm_armv7-a-neon_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900522
Inseob Kim7f283f42020-06-01 21:53:49 +0900523 snapshotSingleton := ctx.SingletonForTests("vndk-snapshot")
524
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400525 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLibPath, variant)
526 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", vndkCoreLib2ndPath, variant2nd)
527 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLibPath, variant)
528 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_product", "libvndk_product.so", vndkCoreLib2ndPath, variant2nd)
529 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLibPath, variant)
530 CheckSnapshot(t, ctx, snapshotSingleton, "libvndk_sp", "libvndk_sp-x.so", vndkSpLib2ndPath, variant2nd)
531 CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLibPath, variant)
532 CheckSnapshot(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", llndkLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900533
Jooyung Han39edb6c2019-11-06 16:53:07 +0900534 snapshotConfigsPath := filepath.Join(snapshotVariantPath, "configs")
Colin Cross45bce852021-11-11 22:47:54 -0800535 CheckSnapshot(t, ctx, snapshotSingleton, "llndk.libraries.txt", "llndk.libraries.txt", snapshotConfigsPath, "android_common")
536 CheckSnapshot(t, ctx, snapshotSingleton, "vndkcore.libraries.txt", "vndkcore.libraries.txt", snapshotConfigsPath, "android_common")
537 CheckSnapshot(t, ctx, snapshotSingleton, "vndksp.libraries.txt", "vndksp.libraries.txt", snapshotConfigsPath, "android_common")
538 CheckSnapshot(t, ctx, snapshotSingleton, "vndkprivate.libraries.txt", "vndkprivate.libraries.txt", snapshotConfigsPath, "android_common")
539 CheckSnapshot(t, ctx, snapshotSingleton, "vndkproduct.libraries.txt", "vndkproduct.libraries.txt", snapshotConfigsPath, "android_common")
Jooyung Han39edb6c2019-11-06 16:53:07 +0900540
Jooyung Han097087b2019-10-22 19:32:18 +0900541 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
542 "LLNDK: libc.so",
543 "LLNDK: libdl.so",
544 "LLNDK: libft2.so",
Justin Yun450ae722021-04-16 19:58:18 +0900545 "LLNDK: libllndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900546 "LLNDK: libm.so",
547 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900548 "VNDK-SP: libvndk_sp-x.so",
549 "VNDK-SP: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900550 "VNDK-SP: libvndk_sp_product_private-x.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900551 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900552 "VNDK-core: libvndk.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900553 "VNDK-core: libvndk_product.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900554 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900555 "VNDK-private: libvndk-private.so",
556 "VNDK-private: libvndk_sp_private-x.so",
Justin Yun6977e8a2020-10-29 18:24:11 +0900557 "VNDK-private: libvndk_sp_product_private-x.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900558 "VNDK-product: libc++.so",
559 "VNDK-product: libvndk_product.so",
560 "VNDK-product: libvndk_sp_product_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900561 })
Justin Yun611e8862021-05-24 18:17:33 +0900562 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt", []string{"libc.so", "libclang_rt.hwasan-llndk.so", "libdl.so", "libft2.so", "libllndk.so", "libm.so"})
Justin Yun6977e8a2020-10-29 18:24:11 +0900563 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so", "libvndk_product.so"})
564 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so", "libvndk_sp_product_private-x.so"})
565 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 +0900566 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 +0900567 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", nil)
568}
569
Yo Chiangbba545e2020-06-09 16:15:37 +0800570func TestVndkWithHostSupported(t *testing.T) {
571 ctx := testCc(t, `
572 cc_library {
573 name: "libvndk_host_supported",
574 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900575 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800576 vndk: {
577 enabled: true,
578 },
579 host_supported: true,
580 }
581
582 cc_library {
583 name: "libvndk_host_supported_but_disabled_on_device",
584 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900585 product_available: true,
Yo Chiangbba545e2020-06-09 16:15:37 +0800586 vndk: {
587 enabled: true,
588 },
589 host_supported: true,
590 enabled: false,
591 target: {
592 host: {
593 enabled: true,
594 }
595 }
596 }
597
Colin Crosse4e44bc2020-12-28 13:50:21 -0800598 vndkcore_libraries_txt {
Yo Chiangbba545e2020-06-09 16:15:37 +0800599 name: "vndkcore.libraries.txt",
600 }
601 `)
602
603 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt", []string{"libvndk_host_supported.so"})
604}
605
Jooyung Han2216fb12019-11-06 16:46:15 +0900606func TestVndkLibrariesTxtAndroidMk(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800607 bp := `
Colin Crosse4e44bc2020-12-28 13:50:21 -0800608 llndk_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900609 name: "llndk.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800610 insert_vndk_version: true,
Colin Cross98be1bb2019-12-13 20:41:13 -0800611 }`
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000612 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800613 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900614 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800615 ctx := testCcWithConfig(t, config)
Jooyung Han2216fb12019-11-06 16:46:15 +0900616
Colin Cross45bce852021-11-11 22:47:54 -0800617 module := ctx.ModuleForTests("llndk.libraries.txt", "android_common")
Colin Crossaa255532020-07-03 13:18:24 -0700618 entries := android.AndroidMkEntriesForTest(t, ctx, module.Module())[0]
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900619 assertArrayString(t, entries.EntryMap["LOCAL_MODULE_STEM"], []string{"llndk.libraries.29.txt"})
Jooyung Han097087b2019-10-22 19:32:18 +0900620}
621
622func TestVndkUsingCoreVariant(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800623 bp := `
Jooyung Han097087b2019-10-22 19:32:18 +0900624 cc_library {
625 name: "libvndk",
626 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900627 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900628 vndk: {
629 enabled: true,
630 },
631 nocrt: true,
632 }
633
634 cc_library {
635 name: "libvndk_sp",
636 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900637 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900638 vndk: {
639 enabled: true,
640 support_system_process: true,
641 },
642 nocrt: true,
643 }
644
645 cc_library {
646 name: "libvndk2",
Justin Yunfd9e8042020-12-23 18:23:14 +0900647 vendor_available: true,
648 product_available: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900649 vndk: {
650 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +0900651 private: true,
Jooyung Han097087b2019-10-22 19:32:18 +0900652 },
653 nocrt: true,
654 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900655
Colin Crosse4e44bc2020-12-28 13:50:21 -0800656 vndkcorevariant_libraries_txt {
Jooyung Han2216fb12019-11-06 16:46:15 +0900657 name: "vndkcorevariant.libraries.txt",
Colin Crosse4e44bc2020-12-28 13:50:21 -0800658 insert_vndk_version: false,
Jooyung Han2216fb12019-11-06 16:46:15 +0900659 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800660 `
661
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000662 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Cross98be1bb2019-12-13 20:41:13 -0800663 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900664 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Colin Cross98be1bb2019-12-13 20:41:13 -0800665 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
666
667 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
668
669 ctx := testCcWithConfig(t, config)
Jooyung Han097087b2019-10-22 19:32:18 +0900670
Jooyung Han2216fb12019-11-06 16:46:15 +0900671 checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900672}
673
Chris Parsons79d66a52020-06-05 17:26:16 -0400674func TestDataLibs(t *testing.T) {
675 bp := `
676 cc_test_library {
677 name: "test_lib",
678 srcs: ["test_lib.cpp"],
679 gtest: false,
680 }
681
682 cc_test {
683 name: "main_test",
684 data_libs: ["test_lib"],
685 gtest: false,
686 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400687 `
Chris Parsons79d66a52020-06-05 17:26:16 -0400688
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000689 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons79d66a52020-06-05 17:26:16 -0400690 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900691 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons79d66a52020-06-05 17:26:16 -0400692 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
693
694 ctx := testCcWithConfig(t, config)
695 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
696 testBinary := module.(*Module).linker.(*testBinary)
697 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
698 if err != nil {
699 t.Errorf("Expected cc_test to produce output files, error: %s", err)
700 return
701 }
702 if len(outputFiles) != 1 {
703 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
704 return
705 }
706 if len(testBinary.dataPaths()) != 1 {
707 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
708 return
709 }
710
711 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400712 testBinaryPath := testBinary.dataPaths()[0].SrcPath.String()
Chris Parsons79d66a52020-06-05 17:26:16 -0400713
714 if !strings.HasSuffix(outputPath, "/main_test") {
715 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
716 return
717 }
718 if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
719 t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
720 return
721 }
722}
723
Chris Parsons216e10a2020-07-09 17:12:52 -0400724func TestDataLibsRelativeInstallPath(t *testing.T) {
725 bp := `
726 cc_test_library {
727 name: "test_lib",
728 srcs: ["test_lib.cpp"],
729 relative_install_path: "foo/bar/baz",
730 gtest: false,
731 }
732
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400733 cc_binary {
734 name: "test_bin",
735 relative_install_path: "foo/bar/baz",
736 compile_multilib: "both",
737 }
738
Chris Parsons216e10a2020-07-09 17:12:52 -0400739 cc_test {
740 name: "main_test",
741 data_libs: ["test_lib"],
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400742 data_bins: ["test_bin"],
Chris Parsons216e10a2020-07-09 17:12:52 -0400743 gtest: false,
744 }
745 `
746
Paul Duffinc3e6ce02021-03-22 23:21:32 +0000747 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons216e10a2020-07-09 17:12:52 -0400748 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +0900749 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons216e10a2020-07-09 17:12:52 -0400750 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
751
752 ctx := testCcWithConfig(t, config)
753 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
754 testBinary := module.(*Module).linker.(*testBinary)
755 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
756 if err != nil {
757 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
758 }
759 if len(outputFiles) != 1 {
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400760 t.Fatalf("expected exactly one output file. output files: [%s]", outputFiles)
Chris Parsons216e10a2020-07-09 17:12:52 -0400761 }
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400762 if len(testBinary.dataPaths()) != 2 {
763 t.Fatalf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
Chris Parsons216e10a2020-07-09 17:12:52 -0400764 }
765
766 outputPath := outputFiles[0].String()
Chris Parsons216e10a2020-07-09 17:12:52 -0400767
768 if !strings.HasSuffix(outputPath, "/main_test") {
769 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
770 }
Colin Crossaa255532020-07-03 13:18:24 -0700771 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons216e10a2020-07-09 17:12:52 -0400772 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
773 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
Chris Parsons1f6d90f2020-06-17 16:10:42 -0400774 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
Chris Parsons216e10a2020-07-09 17:12:52 -0400775 }
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400776 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][1], ":test_bin:foo/bar/baz") {
777 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_bin:foo/bar/baz`,"+
778 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][1])
779 }
Chris Parsons216e10a2020-07-09 17:12:52 -0400780}
781
Jooyung Han0302a842019-10-30 18:43:49 +0900782func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
Jooyung Han2216fb12019-11-06 16:46:15 +0900783 ctx := testCcNoVndk(t, `
Jooyung Han0302a842019-10-30 18:43:49 +0900784 cc_library {
785 name: "libvndk",
786 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900787 product_available: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900788 vndk: {
789 enabled: true,
790 },
791 nocrt: true,
792 }
Justin Yun8a2600c2020-12-07 12:44:03 +0900793 cc_library {
794 name: "libvndk-private",
Justin Yunc0d8c492021-01-07 17:45:31 +0900795 vendor_available: true,
796 product_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900797 vndk: {
798 enabled: true,
Justin Yunc0d8c492021-01-07 17:45:31 +0900799 private: true,
Justin Yun8a2600c2020-12-07 12:44:03 +0900800 },
801 nocrt: true,
802 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800803
804 cc_library {
805 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -0700806 llndk: {
807 symbol_file: "libllndk.map.txt",
808 export_llndk_headers: ["libllndk_headers"],
809 }
Colin Crossb5f6fa62021-01-06 17:05:04 -0800810 }
811
Colin Cross627280f2021-04-26 16:53:58 -0700812 cc_library_headers {
Colin Crossb5f6fa62021-01-06 17:05:04 -0800813 name: "libllndk_headers",
Colin Cross627280f2021-04-26 16:53:58 -0700814 llndk: {
815 symbol_file: "libllndk.map.txt",
816 },
Colin Crossb5f6fa62021-01-06 17:05:04 -0800817 export_include_dirs: ["include"],
818 }
Jooyung Han2216fb12019-11-06 16:46:15 +0900819 `)
Jooyung Han0302a842019-10-30 18:43:49 +0900820
821 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
822 "LLNDK: libc.so",
823 "LLNDK: libdl.so",
824 "LLNDK: libft2.so",
Colin Crossb5f6fa62021-01-06 17:05:04 -0800825 "LLNDK: libllndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900826 "LLNDK: libm.so",
827 "VNDK-SP: libc++.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900828 "VNDK-core: libvndk-private.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900829 "VNDK-core: libvndk.so",
830 "VNDK-private: libft2.so",
Justin Yun8a2600c2020-12-07 12:44:03 +0900831 "VNDK-private: libvndk-private.so",
832 "VNDK-product: libc++.so",
833 "VNDK-product: libvndk-private.so",
834 "VNDK-product: libvndk.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900835 })
Logan Chienf3511742017-10-31 18:04:35 +0800836}
837
Justin Yun63e9ec72020-10-29 16:49:43 +0900838func TestVndkModuleError(t *testing.T) {
839 // Check the error message for vendor_available and product_available properties.
Justin Yunc0d8c492021-01-07 17:45:31 +0900840 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900841 cc_library {
842 name: "libvndk",
843 vndk: {
844 enabled: true,
845 },
846 nocrt: true,
847 }
848 `)
849
Justin Yunc0d8c492021-01-07 17:45:31 +0900850 testCcErrorProductVndk(t, "vndk: vendor_available must be set to true when `vndk: {enabled: true}`", `
Justin Yun6977e8a2020-10-29 18:24:11 +0900851 cc_library {
852 name: "libvndk",
853 product_available: true,
854 vndk: {
855 enabled: true,
856 },
857 nocrt: true,
858 }
859 `)
860
Justin Yun6977e8a2020-10-29 18:24:11 +0900861 testCcErrorProductVndk(t, "product properties must have the same values with the vendor properties for VNDK modules", `
862 cc_library {
863 name: "libvndkprop",
864 vendor_available: true,
865 product_available: true,
866 vndk: {
867 enabled: true,
868 },
869 nocrt: true,
870 target: {
871 vendor: {
872 cflags: ["-DTEST",],
873 },
874 },
875 }
876 `)
Justin Yun63e9ec72020-10-29 16:49:43 +0900877}
878
Logan Chiend3c59a22018-03-29 14:08:15 +0800879func TestVndkDepError(t *testing.T) {
880 // Check whether an error is emitted when a VNDK lib depends on a system lib.
881 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
882 cc_library {
883 name: "libvndk",
884 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900885 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800886 vndk: {
887 enabled: true,
888 },
889 shared_libs: ["libfwk"], // Cause error
890 nocrt: true,
891 }
892
893 cc_library {
894 name: "libfwk",
895 nocrt: true,
896 }
897 `)
898
899 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
900 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
901 cc_library {
902 name: "libvndk",
903 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900904 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800905 vndk: {
906 enabled: true,
907 },
908 shared_libs: ["libvendor"], // Cause error
909 nocrt: true,
910 }
911
912 cc_library {
913 name: "libvendor",
914 vendor: true,
915 nocrt: true,
916 }
917 `)
918
919 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
920 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
921 cc_library {
922 name: "libvndk_sp",
923 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900924 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800925 vndk: {
926 enabled: true,
927 support_system_process: true,
928 },
929 shared_libs: ["libfwk"], // Cause error
930 nocrt: true,
931 }
932
933 cc_library {
934 name: "libfwk",
935 nocrt: true,
936 }
937 `)
938
939 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
940 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
941 cc_library {
942 name: "libvndk_sp",
943 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900944 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800945 vndk: {
946 enabled: true,
947 support_system_process: true,
948 },
949 shared_libs: ["libvendor"], // Cause error
950 nocrt: true,
951 }
952
953 cc_library {
954 name: "libvendor",
955 vendor: true,
956 nocrt: true,
957 }
958 `)
959
960 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
961 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
962 cc_library {
963 name: "libvndk_sp",
964 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900965 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800966 vndk: {
967 enabled: true,
968 support_system_process: true,
969 },
970 shared_libs: ["libvndk"], // Cause error
971 nocrt: true,
972 }
973
974 cc_library {
975 name: "libvndk",
976 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900977 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +0800978 vndk: {
979 enabled: true,
980 },
981 nocrt: true,
982 }
983 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900984
985 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
986 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
987 cc_library {
988 name: "libvndk",
989 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +0900990 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900991 vndk: {
992 enabled: true,
993 },
994 shared_libs: ["libnonvndk"],
995 nocrt: true,
996 }
997
998 cc_library {
999 name: "libnonvndk",
1000 vendor_available: true,
1001 nocrt: true,
1002 }
1003 `)
1004
1005 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
1006 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1007 cc_library {
1008 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001009 vendor_available: true,
1010 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001011 vndk: {
1012 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001013 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001014 },
1015 shared_libs: ["libnonvndk"],
1016 nocrt: true,
1017 }
1018
1019 cc_library {
1020 name: "libnonvndk",
1021 vendor_available: true,
1022 nocrt: true,
1023 }
1024 `)
1025
1026 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
1027 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1028 cc_library {
1029 name: "libvndksp",
1030 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001031 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001032 vndk: {
1033 enabled: true,
1034 support_system_process: true,
1035 },
1036 shared_libs: ["libnonvndk"],
1037 nocrt: true,
1038 }
1039
1040 cc_library {
1041 name: "libnonvndk",
1042 vendor_available: true,
1043 nocrt: true,
1044 }
1045 `)
1046
1047 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
1048 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1049 cc_library {
1050 name: "libvndkspprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09001051 vendor_available: true,
1052 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001053 vndk: {
1054 enabled: true,
1055 support_system_process: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001056 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001057 },
1058 shared_libs: ["libnonvndk"],
1059 nocrt: true,
1060 }
1061
1062 cc_library {
1063 name: "libnonvndk",
1064 vendor_available: true,
1065 nocrt: true,
1066 }
1067 `)
1068}
1069
1070func TestDoubleLoadbleDep(t *testing.T) {
1071 // okay to link : LLNDK -> double_loadable VNDK
1072 testCc(t, `
1073 cc_library {
1074 name: "libllndk",
1075 shared_libs: ["libdoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001076 llndk: {
1077 symbol_file: "libllndk.map.txt",
1078 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001079 }
1080
1081 cc_library {
1082 name: "libdoubleloadable",
1083 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001084 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001085 vndk: {
1086 enabled: true,
1087 },
1088 double_loadable: true,
1089 }
1090 `)
1091 // okay to link : LLNDK -> VNDK-SP
1092 testCc(t, `
1093 cc_library {
1094 name: "libllndk",
1095 shared_libs: ["libvndksp"],
Colin Cross203b4212021-04-26 17:19:41 -07001096 llndk: {
1097 symbol_file: "libllndk.map.txt",
1098 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001099 }
1100
1101 cc_library {
1102 name: "libvndksp",
1103 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001104 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001105 vndk: {
1106 enabled: true,
1107 support_system_process: true,
1108 },
1109 }
1110 `)
1111 // okay to link : double_loadable -> double_loadable
1112 testCc(t, `
1113 cc_library {
1114 name: "libdoubleloadable1",
1115 shared_libs: ["libdoubleloadable2"],
1116 vendor_available: true,
1117 double_loadable: true,
1118 }
1119
1120 cc_library {
1121 name: "libdoubleloadable2",
1122 vendor_available: true,
1123 double_loadable: true,
1124 }
1125 `)
1126 // okay to link : double_loadable VNDK -> double_loadable VNDK private
1127 testCc(t, `
1128 cc_library {
1129 name: "libdoubleloadable",
1130 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001131 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001132 vndk: {
1133 enabled: true,
1134 },
1135 double_loadable: true,
1136 shared_libs: ["libnondoubleloadable"],
1137 }
1138
1139 cc_library {
1140 name: "libnondoubleloadable",
Justin Yunfd9e8042020-12-23 18:23:14 +09001141 vendor_available: true,
1142 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001143 vndk: {
1144 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001145 private: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001146 },
1147 double_loadable: true,
1148 }
1149 `)
1150 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
1151 testCc(t, `
1152 cc_library {
1153 name: "libllndk",
1154 shared_libs: ["libcoreonly"],
Colin Cross203b4212021-04-26 17:19:41 -07001155 llndk: {
1156 symbol_file: "libllndk.map.txt",
1157 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001158 }
1159
1160 cc_library {
1161 name: "libcoreonly",
1162 shared_libs: ["libvendoravailable"],
1163 }
1164
1165 // indirect dependency of LLNDK
1166 cc_library {
1167 name: "libvendoravailable",
1168 vendor_available: true,
1169 double_loadable: true,
1170 }
1171 `)
1172}
1173
1174func TestDoubleLoadableDepError(t *testing.T) {
1175 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
1176 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1177 cc_library {
1178 name: "libllndk",
1179 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001180 llndk: {
1181 symbol_file: "libllndk.map.txt",
1182 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001183 }
1184
1185 cc_library {
1186 name: "libnondoubleloadable",
1187 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001188 product_available: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001189 vndk: {
1190 enabled: true,
1191 },
1192 }
1193 `)
1194
1195 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
1196 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1197 cc_library {
1198 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -07001199 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +09001200 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001201 llndk: {
1202 symbol_file: "libllndk.map.txt",
1203 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001204 }
1205
1206 cc_library {
1207 name: "libnondoubleloadable",
1208 vendor_available: true,
1209 }
1210 `)
1211
Jooyung Hana70f0672019-01-18 15:20:43 +09001212 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
1213 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
1214 cc_library {
1215 name: "libllndk",
1216 shared_libs: ["libcoreonly"],
Colin Cross203b4212021-04-26 17:19:41 -07001217 llndk: {
1218 symbol_file: "libllndk.map.txt",
1219 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001220 }
1221
1222 cc_library {
1223 name: "libcoreonly",
1224 shared_libs: ["libvendoravailable"],
1225 }
1226
1227 // indirect dependency of LLNDK
1228 cc_library {
1229 name: "libvendoravailable",
1230 vendor_available: true,
1231 }
1232 `)
Jiyong Park0474e1f2021-01-14 14:26:06 +09001233
1234 // The error is not from 'client' but from 'libllndk'
1235 testCcError(t, "module \"libllndk\".* links a library \"libnondoubleloadable\".*double_loadable", `
1236 cc_library {
1237 name: "client",
1238 vendor_available: true,
1239 double_loadable: true,
1240 shared_libs: ["libllndk"],
1241 }
1242 cc_library {
1243 name: "libllndk",
1244 shared_libs: ["libnondoubleloadable"],
Colin Cross203b4212021-04-26 17:19:41 -07001245 llndk: {
1246 symbol_file: "libllndk.map.txt",
1247 }
Jiyong Park0474e1f2021-01-14 14:26:06 +09001248 }
1249 cc_library {
1250 name: "libnondoubleloadable",
1251 vendor_available: true,
1252 }
1253 `)
Logan Chiend3c59a22018-03-29 14:08:15 +08001254}
1255
Jooyung Han479ca172020-10-19 18:51:07 +09001256func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
1257 testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
1258 cc_library {
1259 name: "libvndksp",
1260 shared_libs: ["libanothervndksp"],
1261 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001262 product_available: true,
Jooyung Han479ca172020-10-19 18:51:07 +09001263 vndk: {
1264 enabled: true,
1265 support_system_process: true,
1266 }
1267 }
1268
1269 cc_library {
1270 name: "libllndk",
1271 shared_libs: ["libanothervndksp"],
1272 }
1273
Jooyung Han479ca172020-10-19 18:51:07 +09001274 cc_library {
1275 name: "libanothervndksp",
1276 vendor_available: true,
1277 }
1278 `)
1279}
1280
Logan Chienf3511742017-10-31 18:04:35 +08001281func TestVndkExt(t *testing.T) {
1282 // This test checks the VNDK-Ext properties.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001283 bp := `
Logan Chienf3511742017-10-31 18:04:35 +08001284 cc_library {
1285 name: "libvndk",
1286 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001287 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001288 vndk: {
1289 enabled: true,
1290 },
1291 nocrt: true,
1292 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001293 cc_library {
1294 name: "libvndk2",
1295 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001296 product_available: true,
Jooyung Han4c2b9422019-10-22 19:53:47 +09001297 vndk: {
1298 enabled: true,
1299 },
1300 target: {
1301 vendor: {
1302 suffix: "-suffix",
1303 },
Justin Yun63e9ec72020-10-29 16:49:43 +09001304 product: {
1305 suffix: "-suffix",
1306 },
Jooyung Han4c2b9422019-10-22 19:53:47 +09001307 },
1308 nocrt: true,
1309 }
Logan Chienf3511742017-10-31 18:04:35 +08001310
1311 cc_library {
1312 name: "libvndk_ext",
1313 vendor: true,
1314 vndk: {
1315 enabled: true,
1316 extends: "libvndk",
1317 },
1318 nocrt: true,
1319 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001320
1321 cc_library {
1322 name: "libvndk2_ext",
1323 vendor: true,
1324 vndk: {
1325 enabled: true,
1326 extends: "libvndk2",
1327 },
1328 nocrt: true,
1329 }
Logan Chienf3511742017-10-31 18:04:35 +08001330
Justin Yun0ecf0b22020-02-28 15:07:59 +09001331 cc_library {
1332 name: "libvndk_ext_product",
1333 product_specific: true,
1334 vndk: {
1335 enabled: true,
1336 extends: "libvndk",
1337 },
1338 nocrt: true,
1339 }
Jooyung Han4c2b9422019-10-22 19:53:47 +09001340
Justin Yun0ecf0b22020-02-28 15:07:59 +09001341 cc_library {
1342 name: "libvndk2_ext_product",
1343 product_specific: true,
1344 vndk: {
1345 enabled: true,
1346 extends: "libvndk2",
1347 },
1348 nocrt: true,
1349 }
1350 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001351 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001352 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1353 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001354 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001355
1356 ctx := testCcWithConfig(t, config)
1357
1358 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk", vendorVariant)
1359 checkVndkModule(t, ctx, "libvndk_ext_product", "vndk", false, "libvndk", productVariant)
1360
1361 mod_vendor := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
1362 assertString(t, mod_vendor.outputFile.Path().Base(), "libvndk2-suffix.so")
1363
1364 mod_product := ctx.ModuleForTests("libvndk2_ext_product", productVariant).Module().(*Module)
1365 assertString(t, mod_product.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +08001366}
1367
Logan Chiend3c59a22018-03-29 14:08:15 +08001368func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +08001369 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
1370 ctx := testCcNoVndk(t, `
1371 cc_library {
1372 name: "libvndk",
1373 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001374 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001375 vndk: {
1376 enabled: true,
1377 },
1378 nocrt: true,
1379 }
1380
1381 cc_library {
1382 name: "libvndk_ext",
1383 vendor: true,
1384 vndk: {
1385 enabled: true,
1386 extends: "libvndk",
1387 },
1388 nocrt: true,
1389 }
1390 `)
1391
1392 // Ensures that the core variant of "libvndk_ext" can be found.
1393 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
1394 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1395 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
1396 }
1397}
1398
Justin Yun0ecf0b22020-02-28 15:07:59 +09001399func TestVndkExtWithoutProductVndkVersion(t *testing.T) {
1400 // This test checks the VNDK-Ext properties when PRODUCT_PRODUCT_VNDK_VERSION is not set.
Justin Yun8a2600c2020-12-07 12:44:03 +09001401 ctx := testCcNoProductVndk(t, `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001402 cc_library {
1403 name: "libvndk",
1404 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001405 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001406 vndk: {
1407 enabled: true,
1408 },
1409 nocrt: true,
1410 }
1411
1412 cc_library {
1413 name: "libvndk_ext_product",
1414 product_specific: true,
1415 vndk: {
1416 enabled: true,
1417 extends: "libvndk",
1418 },
1419 nocrt: true,
1420 }
1421 `)
1422
1423 // Ensures that the core variant of "libvndk_ext_product" can be found.
1424 mod := ctx.ModuleForTests("libvndk_ext_product", coreVariant).Module().(*Module)
1425 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
1426 t.Errorf("\"libvndk_ext_product\" must extend from \"libvndk\" but get %q", extends)
1427 }
1428}
1429
Logan Chienf3511742017-10-31 18:04:35 +08001430func TestVndkExtError(t *testing.T) {
1431 // This test ensures an error is emitted in ill-formed vndk-ext definition.
Justin Yun0ecf0b22020-02-28 15:07:59 +09001432 testCcError(t, "must set `vendor: true` or `product_specific: true` to set `extends: \".*\"`", `
Logan Chienf3511742017-10-31 18:04:35 +08001433 cc_library {
1434 name: "libvndk",
1435 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001436 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001437 vndk: {
1438 enabled: true,
1439 },
1440 nocrt: true,
1441 }
1442
1443 cc_library {
1444 name: "libvndk_ext",
1445 vndk: {
1446 enabled: true,
1447 extends: "libvndk",
1448 },
1449 nocrt: true,
1450 }
1451 `)
1452
1453 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1454 cc_library {
1455 name: "libvndk",
1456 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001457 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001458 vndk: {
1459 enabled: true,
1460 },
1461 nocrt: true,
1462 }
1463
1464 cc_library {
1465 name: "libvndk_ext",
1466 vendor: true,
1467 vndk: {
1468 enabled: true,
1469 },
1470 nocrt: true,
1471 }
1472 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001473
1474 testCcErrorProductVndk(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
1475 cc_library {
1476 name: "libvndk",
1477 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001478 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001479 vndk: {
1480 enabled: true,
1481 },
1482 nocrt: true,
1483 }
1484
1485 cc_library {
1486 name: "libvndk_ext_product",
1487 product_specific: true,
1488 vndk: {
1489 enabled: true,
1490 },
1491 nocrt: true,
1492 }
1493 `)
1494
1495 testCcErrorProductVndk(t, "must not set at the same time as `vndk: {extends: \"\\.\\.\\.\"}`", `
1496 cc_library {
1497 name: "libvndk",
1498 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001499 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001500 vndk: {
1501 enabled: true,
1502 },
1503 nocrt: true,
1504 }
1505
1506 cc_library {
1507 name: "libvndk_ext_product",
1508 product_specific: true,
1509 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001510 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001511 vndk: {
1512 enabled: true,
1513 extends: "libvndk",
1514 },
1515 nocrt: true,
1516 }
1517 `)
Logan Chienf3511742017-10-31 18:04:35 +08001518}
1519
1520func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1521 // This test ensures an error is emitted for inconsistent support_system_process.
1522 testCcError(t, "module \".*\" with mismatched support_system_process", `
1523 cc_library {
1524 name: "libvndk",
1525 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001526 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001527 vndk: {
1528 enabled: true,
1529 },
1530 nocrt: true,
1531 }
1532
1533 cc_library {
1534 name: "libvndk_sp_ext",
1535 vendor: true,
1536 vndk: {
1537 enabled: true,
1538 extends: "libvndk",
1539 support_system_process: true,
1540 },
1541 nocrt: true,
1542 }
1543 `)
1544
1545 testCcError(t, "module \".*\" with mismatched support_system_process", `
1546 cc_library {
1547 name: "libvndk_sp",
1548 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001549 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001550 vndk: {
1551 enabled: true,
1552 support_system_process: true,
1553 },
1554 nocrt: true,
1555 }
1556
1557 cc_library {
1558 name: "libvndk_ext",
1559 vendor: true,
1560 vndk: {
1561 enabled: true,
1562 extends: "libvndk_sp",
1563 },
1564 nocrt: true,
1565 }
1566 `)
1567}
1568
1569func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001570 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Justin Yunfd9e8042020-12-23 18:23:14 +09001571 // with `private: true`.
1572 testCcError(t, "`extends` refers module \".*\" which has `private: true`", `
Logan Chienf3511742017-10-31 18:04:35 +08001573 cc_library {
1574 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001575 vendor_available: true,
1576 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001577 vndk: {
1578 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001579 private: true,
Logan Chienf3511742017-10-31 18:04:35 +08001580 },
1581 nocrt: true,
1582 }
1583
1584 cc_library {
1585 name: "libvndk_ext",
1586 vendor: true,
1587 vndk: {
1588 enabled: true,
1589 extends: "libvndk",
1590 },
1591 nocrt: true,
1592 }
1593 `)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001594
Justin Yunfd9e8042020-12-23 18:23:14 +09001595 testCcErrorProductVndk(t, "`extends` refers module \".*\" which has `private: true`", `
Justin Yun0ecf0b22020-02-28 15:07:59 +09001596 cc_library {
1597 name: "libvndk",
Justin Yunfd9e8042020-12-23 18:23:14 +09001598 vendor_available: true,
1599 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001600 vndk: {
1601 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09001602 private: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001603 },
1604 nocrt: true,
1605 }
1606
1607 cc_library {
1608 name: "libvndk_ext_product",
1609 product_specific: true,
1610 vndk: {
1611 enabled: true,
1612 extends: "libvndk",
1613 },
1614 nocrt: true,
1615 }
1616 `)
Logan Chienf3511742017-10-31 18:04:35 +08001617}
1618
Logan Chiend3c59a22018-03-29 14:08:15 +08001619func TestVendorModuleUseVndkExt(t *testing.T) {
1620 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001621 testCc(t, `
1622 cc_library {
1623 name: "libvndk",
1624 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001625 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001626 vndk: {
1627 enabled: true,
1628 },
1629 nocrt: true,
1630 }
1631
1632 cc_library {
1633 name: "libvndk_ext",
1634 vendor: true,
1635 vndk: {
1636 enabled: true,
1637 extends: "libvndk",
1638 },
1639 nocrt: true,
1640 }
1641
1642 cc_library {
Logan Chienf3511742017-10-31 18:04:35 +08001643 name: "libvndk_sp",
1644 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001645 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001646 vndk: {
1647 enabled: true,
1648 support_system_process: true,
1649 },
1650 nocrt: true,
1651 }
1652
1653 cc_library {
1654 name: "libvndk_sp_ext",
1655 vendor: true,
1656 vndk: {
1657 enabled: true,
1658 extends: "libvndk_sp",
1659 support_system_process: true,
1660 },
1661 nocrt: true,
1662 }
1663
1664 cc_library {
1665 name: "libvendor",
1666 vendor: true,
1667 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1668 nocrt: true,
1669 }
1670 `)
1671}
1672
Logan Chiend3c59a22018-03-29 14:08:15 +08001673func TestVndkExtUseVendorLib(t *testing.T) {
1674 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001675 testCc(t, `
1676 cc_library {
1677 name: "libvndk",
1678 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001679 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001680 vndk: {
1681 enabled: true,
1682 },
1683 nocrt: true,
1684 }
1685
1686 cc_library {
1687 name: "libvndk_ext",
1688 vendor: true,
1689 vndk: {
1690 enabled: true,
1691 extends: "libvndk",
1692 },
1693 shared_libs: ["libvendor"],
1694 nocrt: true,
1695 }
1696
1697 cc_library {
1698 name: "libvendor",
1699 vendor: true,
1700 nocrt: true,
1701 }
1702 `)
Logan Chienf3511742017-10-31 18:04:35 +08001703
Logan Chiend3c59a22018-03-29 14:08:15 +08001704 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1705 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001706 cc_library {
1707 name: "libvndk_sp",
1708 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001709 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001710 vndk: {
1711 enabled: true,
1712 support_system_process: true,
1713 },
1714 nocrt: true,
1715 }
1716
1717 cc_library {
1718 name: "libvndk_sp_ext",
1719 vendor: true,
1720 vndk: {
1721 enabled: true,
1722 extends: "libvndk_sp",
1723 support_system_process: true,
1724 },
1725 shared_libs: ["libvendor"], // Cause an error
1726 nocrt: true,
1727 }
1728
1729 cc_library {
1730 name: "libvendor",
1731 vendor: true,
1732 nocrt: true,
1733 }
1734 `)
1735}
1736
Justin Yun0ecf0b22020-02-28 15:07:59 +09001737func TestProductVndkExtDependency(t *testing.T) {
1738 bp := `
1739 cc_library {
1740 name: "libvndk",
1741 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001742 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001743 vndk: {
1744 enabled: true,
1745 },
1746 nocrt: true,
1747 }
1748
1749 cc_library {
1750 name: "libvndk_ext_product",
1751 product_specific: true,
1752 vndk: {
1753 enabled: true,
1754 extends: "libvndk",
1755 },
1756 shared_libs: ["libproduct_for_vndklibs"],
1757 nocrt: true,
1758 }
1759
1760 cc_library {
1761 name: "libvndk_sp",
1762 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001763 product_available: true,
Justin Yun0ecf0b22020-02-28 15:07:59 +09001764 vndk: {
1765 enabled: true,
1766 support_system_process: true,
1767 },
1768 nocrt: true,
1769 }
1770
1771 cc_library {
1772 name: "libvndk_sp_ext_product",
1773 product_specific: true,
1774 vndk: {
1775 enabled: true,
1776 extends: "libvndk_sp",
1777 support_system_process: true,
1778 },
1779 shared_libs: ["libproduct_for_vndklibs"],
1780 nocrt: true,
1781 }
1782
1783 cc_library {
1784 name: "libproduct",
1785 product_specific: true,
1786 shared_libs: ["libvndk_ext_product", "libvndk_sp_ext_product"],
1787 nocrt: true,
1788 }
1789
1790 cc_library {
1791 name: "libproduct_for_vndklibs",
1792 product_specific: true,
1793 nocrt: true,
1794 }
1795 `
Paul Duffinc3e6ce02021-03-22 23:21:32 +00001796 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Justin Yun0ecf0b22020-02-28 15:07:59 +09001797 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1798 config.TestProductVariables.ProductVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09001799 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Justin Yun0ecf0b22020-02-28 15:07:59 +09001800
1801 testCcWithConfig(t, config)
1802}
1803
Logan Chiend3c59a22018-03-29 14:08:15 +08001804func TestVndkSpExtUseVndkError(t *testing.T) {
1805 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1806 // library.
1807 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1808 cc_library {
1809 name: "libvndk",
1810 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001811 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001812 vndk: {
1813 enabled: true,
1814 },
1815 nocrt: true,
1816 }
1817
1818 cc_library {
1819 name: "libvndk_sp",
1820 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001821 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001822 vndk: {
1823 enabled: true,
1824 support_system_process: true,
1825 },
1826 nocrt: true,
1827 }
1828
1829 cc_library {
1830 name: "libvndk_sp_ext",
1831 vendor: true,
1832 vndk: {
1833 enabled: true,
1834 extends: "libvndk_sp",
1835 support_system_process: true,
1836 },
1837 shared_libs: ["libvndk"], // Cause an error
1838 nocrt: true,
1839 }
1840 `)
1841
1842 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1843 // library.
1844 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1845 cc_library {
1846 name: "libvndk",
1847 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001848 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001849 vndk: {
1850 enabled: true,
1851 },
1852 nocrt: true,
1853 }
1854
1855 cc_library {
1856 name: "libvndk_ext",
1857 vendor: true,
1858 vndk: {
1859 enabled: true,
1860 extends: "libvndk",
1861 },
1862 nocrt: true,
1863 }
1864
1865 cc_library {
1866 name: "libvndk_sp",
1867 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001868 product_available: true,
Logan Chiend3c59a22018-03-29 14:08:15 +08001869 vndk: {
1870 enabled: true,
1871 support_system_process: true,
1872 },
1873 nocrt: true,
1874 }
1875
1876 cc_library {
1877 name: "libvndk_sp_ext",
1878 vendor: true,
1879 vndk: {
1880 enabled: true,
1881 extends: "libvndk_sp",
1882 support_system_process: true,
1883 },
1884 shared_libs: ["libvndk_ext"], // Cause an error
1885 nocrt: true,
1886 }
1887 `)
1888}
1889
1890func TestVndkUseVndkExtError(t *testing.T) {
1891 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1892 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001893 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1894 cc_library {
1895 name: "libvndk",
1896 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001897 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001898 vndk: {
1899 enabled: true,
1900 },
1901 nocrt: true,
1902 }
1903
1904 cc_library {
1905 name: "libvndk_ext",
1906 vendor: true,
1907 vndk: {
1908 enabled: true,
1909 extends: "libvndk",
1910 },
1911 nocrt: true,
1912 }
1913
1914 cc_library {
1915 name: "libvndk2",
1916 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001917 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001918 vndk: {
1919 enabled: true,
1920 },
1921 shared_libs: ["libvndk_ext"],
1922 nocrt: true,
1923 }
1924 `)
1925
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001926 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001927 cc_library {
1928 name: "libvndk",
1929 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001930 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001931 vndk: {
1932 enabled: true,
1933 },
1934 nocrt: true,
1935 }
1936
1937 cc_library {
1938 name: "libvndk_ext",
1939 vendor: true,
1940 vndk: {
1941 enabled: true,
1942 extends: "libvndk",
1943 },
1944 nocrt: true,
1945 }
1946
1947 cc_library {
1948 name: "libvndk2",
1949 vendor_available: true,
1950 vndk: {
1951 enabled: true,
1952 },
1953 target: {
1954 vendor: {
1955 shared_libs: ["libvndk_ext"],
1956 },
1957 },
1958 nocrt: true,
1959 }
1960 `)
1961
1962 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1963 cc_library {
1964 name: "libvndk_sp",
1965 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001966 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001967 vndk: {
1968 enabled: true,
1969 support_system_process: true,
1970 },
1971 nocrt: true,
1972 }
1973
1974 cc_library {
1975 name: "libvndk_sp_ext",
1976 vendor: true,
1977 vndk: {
1978 enabled: true,
1979 extends: "libvndk_sp",
1980 support_system_process: true,
1981 },
1982 nocrt: true,
1983 }
1984
1985 cc_library {
1986 name: "libvndk_sp_2",
1987 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09001988 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08001989 vndk: {
1990 enabled: true,
1991 support_system_process: true,
1992 },
1993 shared_libs: ["libvndk_sp_ext"],
1994 nocrt: true,
1995 }
1996 `)
1997
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001998 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001999 cc_library {
2000 name: "libvndk_sp",
2001 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002002 product_available: true,
Logan Chienf3511742017-10-31 18:04:35 +08002003 vndk: {
2004 enabled: true,
2005 },
2006 nocrt: true,
2007 }
2008
2009 cc_library {
2010 name: "libvndk_sp_ext",
2011 vendor: true,
2012 vndk: {
2013 enabled: true,
2014 extends: "libvndk_sp",
2015 },
2016 nocrt: true,
2017 }
2018
2019 cc_library {
2020 name: "libvndk_sp2",
2021 vendor_available: true,
2022 vndk: {
2023 enabled: true,
2024 },
2025 target: {
2026 vendor: {
2027 shared_libs: ["libvndk_sp_ext"],
2028 },
2029 },
2030 nocrt: true,
2031 }
2032 `)
2033}
2034
Justin Yun5f7f7e82019-11-18 19:52:14 +09002035func TestEnforceProductVndkVersion(t *testing.T) {
2036 bp := `
2037 cc_library {
2038 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -07002039 llndk: {
2040 symbol_file: "libllndk.map.txt",
2041 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002042 }
2043 cc_library {
2044 name: "libvndk",
2045 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002046 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002047 vndk: {
2048 enabled: true,
2049 },
2050 nocrt: true,
2051 }
2052 cc_library {
2053 name: "libvndk_sp",
2054 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002055 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002056 vndk: {
2057 enabled: true,
2058 support_system_process: true,
2059 },
2060 nocrt: true,
2061 }
2062 cc_library {
2063 name: "libva",
2064 vendor_available: true,
2065 nocrt: true,
2066 }
2067 cc_library {
Justin Yun63e9ec72020-10-29 16:49:43 +09002068 name: "libpa",
2069 product_available: true,
2070 nocrt: true,
2071 }
2072 cc_library {
Justin Yun6977e8a2020-10-29 18:24:11 +09002073 name: "libboth_available",
2074 vendor_available: true,
2075 product_available: true,
2076 nocrt: true,
Justin Yun13decfb2021-03-08 19:25:55 +09002077 srcs: ["foo.c"],
Justin Yun6977e8a2020-10-29 18:24:11 +09002078 target: {
2079 vendor: {
2080 suffix: "-vendor",
2081 },
2082 product: {
2083 suffix: "-product",
2084 },
2085 }
2086 }
2087 cc_library {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002088 name: "libproduct_va",
2089 product_specific: true,
2090 vendor_available: true,
2091 nocrt: true,
2092 }
2093 cc_library {
2094 name: "libprod",
2095 product_specific: true,
2096 shared_libs: [
2097 "libllndk",
2098 "libvndk",
2099 "libvndk_sp",
Justin Yun63e9ec72020-10-29 16:49:43 +09002100 "libpa",
Justin Yun6977e8a2020-10-29 18:24:11 +09002101 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002102 "libproduct_va",
2103 ],
2104 nocrt: true,
2105 }
2106 cc_library {
2107 name: "libvendor",
2108 vendor: true,
2109 shared_libs: [
2110 "libllndk",
2111 "libvndk",
2112 "libvndk_sp",
2113 "libva",
Justin Yun6977e8a2020-10-29 18:24:11 +09002114 "libboth_available",
Justin Yun5f7f7e82019-11-18 19:52:14 +09002115 "libproduct_va",
2116 ],
2117 nocrt: true,
2118 }
2119 `
2120
Paul Duffin8567f222021-03-23 00:02:06 +00002121 ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
Justin Yun5f7f7e82019-11-18 19:52:14 +09002122
Jooyung Han261e1582020-10-20 18:54:21 +09002123 checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
2124 checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
Justin Yun6977e8a2020-10-29 18:24:11 +09002125
2126 mod_vendor := ctx.ModuleForTests("libboth_available", vendorVariant).Module().(*Module)
2127 assertString(t, mod_vendor.outputFile.Path().Base(), "libboth_available-vendor.so")
2128
2129 mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
2130 assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
Justin Yun13decfb2021-03-08 19:25:55 +09002131
2132 ensureStringContains := func(t *testing.T, str string, substr string) {
2133 t.Helper()
2134 if !strings.Contains(str, substr) {
2135 t.Errorf("%q is not found in %v", substr, str)
2136 }
2137 }
2138 ensureStringNotContains := func(t *testing.T, str string, substr string) {
2139 t.Helper()
2140 if strings.Contains(str, substr) {
2141 t.Errorf("%q is found in %v", substr, str)
2142 }
2143 }
2144
2145 // _static variant is used since _shared reuses *.o from the static variant
2146 vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
2147 product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
2148
2149 vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
2150 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
2151 ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
2152 ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
2153
2154 product_cflags := product_static.Rule("cc").Args["cFlags"]
2155 ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
2156 ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
2157 ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
Justin Yun5f7f7e82019-11-18 19:52:14 +09002158}
2159
2160func TestEnforceProductVndkVersionErrors(t *testing.T) {
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002161 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002162 cc_library {
2163 name: "libprod",
2164 product_specific: true,
2165 shared_libs: [
2166 "libvendor",
2167 ],
2168 nocrt: true,
2169 }
2170 cc_library {
2171 name: "libvendor",
2172 vendor: true,
2173 nocrt: true,
2174 }
2175 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002176 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002177 cc_library {
2178 name: "libprod",
2179 product_specific: true,
2180 shared_libs: [
2181 "libsystem",
2182 ],
2183 nocrt: true,
2184 }
2185 cc_library {
2186 name: "libsystem",
2187 nocrt: true,
2188 }
2189 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002190 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun6977e8a2020-10-29 18:24:11 +09002191 cc_library {
2192 name: "libprod",
2193 product_specific: true,
2194 shared_libs: [
2195 "libva",
2196 ],
2197 nocrt: true,
2198 }
2199 cc_library {
2200 name: "libva",
2201 vendor_available: true,
2202 nocrt: true,
2203 }
2204 `)
Justin Yunfd9e8042020-12-23 18:23:14 +09002205 testCcErrorProductVndk(t, "non-VNDK module should not link to \".*\" which has `private: true`", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002206 cc_library {
2207 name: "libprod",
2208 product_specific: true,
2209 shared_libs: [
2210 "libvndk_private",
2211 ],
2212 nocrt: true,
2213 }
2214 cc_library {
2215 name: "libvndk_private",
Justin Yunfd9e8042020-12-23 18:23:14 +09002216 vendor_available: true,
2217 product_available: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002218 vndk: {
2219 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002220 private: true,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002221 },
2222 nocrt: true,
2223 }
2224 `)
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002225 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:product.29", `
Justin Yun5f7f7e82019-11-18 19:52:14 +09002226 cc_library {
2227 name: "libprod",
2228 product_specific: true,
2229 shared_libs: [
2230 "libsystem_ext",
2231 ],
2232 nocrt: true,
2233 }
2234 cc_library {
2235 name: "libsystem_ext",
2236 system_ext_specific: true,
2237 nocrt: true,
2238 }
2239 `)
2240 testCcErrorProductVndk(t, "dependency \".*\" of \".*\" missing variant:\n.*image:", `
2241 cc_library {
2242 name: "libsystem",
2243 shared_libs: [
2244 "libproduct_va",
2245 ],
2246 nocrt: true,
2247 }
2248 cc_library {
2249 name: "libproduct_va",
2250 product_specific: true,
2251 vendor_available: true,
2252 nocrt: true,
2253 }
2254 `)
2255}
2256
Jooyung Han38002912019-05-16 04:01:54 +09002257func TestMakeLinkType(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -08002258 bp := `
2259 cc_library {
2260 name: "libvndk",
2261 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002262 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002263 vndk: {
2264 enabled: true,
2265 },
2266 }
2267 cc_library {
2268 name: "libvndksp",
2269 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002270 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002271 vndk: {
2272 enabled: true,
2273 support_system_process: true,
2274 },
2275 }
2276 cc_library {
2277 name: "libvndkprivate",
Justin Yunfd9e8042020-12-23 18:23:14 +09002278 vendor_available: true,
2279 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002280 vndk: {
2281 enabled: true,
Justin Yunfd9e8042020-12-23 18:23:14 +09002282 private: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002283 },
2284 }
2285 cc_library {
2286 name: "libvendor",
2287 vendor: true,
2288 }
2289 cc_library {
2290 name: "libvndkext",
2291 vendor: true,
2292 vndk: {
2293 enabled: true,
2294 extends: "libvndk",
2295 },
2296 }
2297 vndk_prebuilt_shared {
2298 name: "prevndk",
2299 version: "27",
2300 target_arch: "arm",
2301 binder32bit: true,
2302 vendor_available: true,
Justin Yun63e9ec72020-10-29 16:49:43 +09002303 product_available: true,
Colin Cross98be1bb2019-12-13 20:41:13 -08002304 vndk: {
2305 enabled: true,
2306 },
2307 arch: {
2308 arm: {
2309 srcs: ["liba.so"],
2310 },
2311 },
2312 }
2313 cc_library {
2314 name: "libllndk",
Colin Cross203b4212021-04-26 17:19:41 -07002315 llndk: {
2316 symbol_file: "libllndk.map.txt",
2317 }
Colin Cross98be1bb2019-12-13 20:41:13 -08002318 }
2319 cc_library {
2320 name: "libllndkprivate",
Colin Cross203b4212021-04-26 17:19:41 -07002321 llndk: {
2322 symbol_file: "libllndkprivate.map.txt",
2323 private: true,
2324 }
Colin Cross78212242021-01-06 14:51:30 -08002325 }
2326
2327 llndk_libraries_txt {
2328 name: "llndk.libraries.txt",
2329 }
2330 vndkcore_libraries_txt {
2331 name: "vndkcore.libraries.txt",
2332 }
2333 vndksp_libraries_txt {
2334 name: "vndksp.libraries.txt",
2335 }
2336 vndkprivate_libraries_txt {
2337 name: "vndkprivate.libraries.txt",
2338 }
2339 vndkcorevariant_libraries_txt {
2340 name: "vndkcorevariant.libraries.txt",
2341 insert_vndk_version: false,
2342 }
2343 `
Colin Cross98be1bb2019-12-13 20:41:13 -08002344
Paul Duffinc3e6ce02021-03-22 23:21:32 +00002345 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Jooyung Han38002912019-05-16 04:01:54 +09002346 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002347 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Jooyung Han38002912019-05-16 04:01:54 +09002348 // native:vndk
Colin Cross98be1bb2019-12-13 20:41:13 -08002349 ctx := testCcWithConfig(t, config)
Jooyung Han38002912019-05-16 04:01:54 +09002350
Colin Cross78212242021-01-06 14:51:30 -08002351 checkVndkLibrariesOutput(t, ctx, "vndkcore.libraries.txt",
2352 []string{"libvndk.so", "libvndkprivate.so"})
2353 checkVndkLibrariesOutput(t, ctx, "vndksp.libraries.txt",
2354 []string{"libc++.so", "libvndksp.so"})
2355 checkVndkLibrariesOutput(t, ctx, "llndk.libraries.txt",
2356 []string{"libc.so", "libdl.so", "libft2.so", "libllndk.so", "libllndkprivate.so", "libm.so"})
2357 checkVndkLibrariesOutput(t, ctx, "vndkprivate.libraries.txt",
2358 []string{"libft2.so", "libllndkprivate.so", "libvndkprivate.so"})
Jooyung Han38002912019-05-16 04:01:54 +09002359
Colin Crossfb0c16e2019-11-20 17:12:35 -08002360 vendorVariant27 := "android_vendor.27_arm64_armv8-a_shared"
Inseob Kim64c43952019-08-26 16:52:35 +09002361
Jooyung Han38002912019-05-16 04:01:54 +09002362 tests := []struct {
2363 variant string
2364 name string
2365 expected string
2366 }{
2367 {vendorVariant, "libvndk", "native:vndk"},
2368 {vendorVariant, "libvndksp", "native:vndk"},
2369 {vendorVariant, "libvndkprivate", "native:vndk_private"},
2370 {vendorVariant, "libvendor", "native:vendor"},
2371 {vendorVariant, "libvndkext", "native:vendor"},
Colin Cross127bb8b2020-12-16 16:46:01 -08002372 {vendorVariant, "libllndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09002373 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09002374 {coreVariant, "libvndk", "native:platform"},
2375 {coreVariant, "libvndkprivate", "native:platform"},
2376 {coreVariant, "libllndk", "native:platform"},
2377 }
2378 for _, test := range tests {
2379 t.Run(test.name, func(t *testing.T) {
2380 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
2381 assertString(t, module.makeLinkType, test.expected)
2382 })
2383 }
2384}
2385
Jeff Gaston294356f2017-09-27 17:05:30 -07002386var staticLinkDepOrderTestCases = []struct {
2387 // This is a string representation of a map[moduleName][]moduleDependency .
2388 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002389 inStatic string
2390
2391 // This is a string representation of a map[moduleName][]moduleDependency .
2392 // It models the dependencies declared in an Android.bp file.
2393 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07002394
2395 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
2396 // The keys of allOrdered specify which modules we would like to check.
2397 // The values of allOrdered specify the expected result (of the transitive closure of all
2398 // dependencies) for each module to test
2399 allOrdered string
2400
2401 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
2402 // The keys of outOrdered specify which modules we would like to check.
2403 // The values of outOrdered specify the expected result (of the ordered linker command line)
2404 // for each module to test.
2405 outOrdered string
2406}{
2407 // Simple tests
2408 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002409 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07002410 outOrdered: "",
2411 },
2412 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002413 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002414 outOrdered: "a:",
2415 },
2416 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002417 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002418 outOrdered: "a:b; b:",
2419 },
2420 // Tests of reordering
2421 {
2422 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002423 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07002424 outOrdered: "a:b,c,d; b:d; c:d; d:",
2425 },
2426 {
2427 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002428 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002429 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
2430 },
2431 {
2432 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002433 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07002434 outOrdered: "a:d,b,e,c; d:b; e:c",
2435 },
2436 {
2437 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002438 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07002439 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
2440 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
2441 },
2442 {
2443 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002444 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 -07002445 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2446 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
2447 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002448 // shared dependencies
2449 {
2450 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
2451 // So, we don't actually have to check that a shared dependency of c will change the order
2452 // of a library that depends statically on b and on c. We only need to check that if c has
2453 // a shared dependency on b, that that shows up in allOrdered.
2454 inShared: "c:b",
2455 allOrdered: "c:b",
2456 outOrdered: "c:",
2457 },
2458 {
2459 // This test doesn't actually include any shared dependencies but it's a reminder of what
2460 // the second phase of the above test would look like
2461 inStatic: "a:b,c; c:b",
2462 allOrdered: "a:c,b; c:b",
2463 outOrdered: "a:c,b; c:b",
2464 },
Jeff Gaston294356f2017-09-27 17:05:30 -07002465 // tiebreakers for when two modules specifying different orderings and there is no dependency
2466 // to dictate an order
2467 {
2468 // 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 -08002469 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07002470 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
2471 },
2472 {
2473 // 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 -08002474 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 -07002475 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
2476 },
2477 // Tests involving duplicate dependencies
2478 {
2479 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002480 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002481 outOrdered: "a:c,b",
2482 },
2483 {
2484 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002485 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002486 outOrdered: "a:d,c,b",
2487 },
2488 // Tests to confirm the nonexistence of infinite loops.
2489 // These cases should never happen, so as long as the test terminates and the
2490 // result is deterministic then that should be fine.
2491 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002492 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002493 outOrdered: "a:a",
2494 },
2495 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002496 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07002497 allOrdered: "a:b,c; b:c,a; c:a,b",
2498 outOrdered: "a:b; b:c; c:a",
2499 },
2500 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002501 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07002502 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
2503 outOrdered: "a:c,b; b:a,c; c:b,a",
2504 },
2505}
2506
2507// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
2508func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
2509 // convert from "a:b,c; d:e" to "a:b,c;d:e"
2510 strippedText := strings.Replace(text, " ", "", -1)
2511 if len(strippedText) < 1 {
2512 return []android.Path{}, make(map[android.Path][]android.Path, 0)
2513 }
2514 allDeps = make(map[android.Path][]android.Path, 0)
2515
2516 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
2517 moduleTexts := strings.Split(strippedText, ";")
2518
2519 outputForModuleName := func(moduleName string) android.Path {
2520 return android.PathForTesting(moduleName)
2521 }
2522
2523 for _, moduleText := range moduleTexts {
2524 // convert from "a:b,c" to ["a", "b,c"]
2525 components := strings.Split(moduleText, ":")
2526 if len(components) != 2 {
2527 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
2528 }
2529 moduleName := components[0]
2530 moduleOutput := outputForModuleName(moduleName)
2531 modulesInOrder = append(modulesInOrder, moduleOutput)
2532
2533 depString := components[1]
2534 // convert from "b,c" to ["b", "c"]
2535 depNames := strings.Split(depString, ",")
2536 if len(depString) < 1 {
2537 depNames = []string{}
2538 }
2539 var deps []android.Path
2540 for _, depName := range depNames {
2541 deps = append(deps, outputForModuleName(depName))
2542 }
2543 allDeps[moduleOutput] = deps
2544 }
2545 return modulesInOrder, allDeps
2546}
2547
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002548func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07002549 ctx := testCc(t, `
2550 cc_library {
2551 name: "a",
2552 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09002553 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002554 }
2555 cc_library {
2556 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002557 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002558 }
2559 cc_library {
2560 name: "c",
2561 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002562 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002563 }
2564 cc_library {
2565 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09002566 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07002567 }
2568
2569 `)
2570
Colin Cross7113d202019-11-20 16:39:12 -08002571 variant := "android_arm64_armv8-a_static"
Jeff Gaston294356f2017-09-27 17:05:30 -07002572 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002573 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2574 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002575 expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
Jeff Gaston294356f2017-09-27 17:05:30 -07002576
2577 if !reflect.DeepEqual(actual, expected) {
2578 t.Errorf("staticDeps orderings were not propagated correctly"+
2579 "\nactual: %v"+
2580 "\nexpected: %v",
2581 actual,
2582 expected,
2583 )
2584 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09002585}
Jeff Gaston294356f2017-09-27 17:05:30 -07002586
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002587func TestStaticLibDepReorderingWithShared(t *testing.T) {
2588 ctx := testCc(t, `
2589 cc_library {
2590 name: "a",
2591 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09002592 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002593 }
2594 cc_library {
2595 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09002596 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002597 }
2598 cc_library {
2599 name: "c",
2600 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09002601 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002602 }
2603
2604 `)
2605
Colin Cross7113d202019-11-20 16:39:12 -08002606 variant := "android_arm64_armv8-a_static"
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002607 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Paul Duffine8366da2021-03-24 10:40:38 +00002608 actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).
2609 TransitiveStaticLibrariesForOrdering.ToList().RelativeToTop()
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002610 expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002611
2612 if !reflect.DeepEqual(actual, expected) {
2613 t.Errorf("staticDeps orderings did not account for shared libs"+
2614 "\nactual: %v"+
2615 "\nexpected: %v",
2616 actual,
2617 expected,
2618 )
2619 }
2620}
2621
Jooyung Hanb04a4992020-03-13 18:57:35 +09002622func checkEquals(t *testing.T, message string, expected, actual interface{}) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002623 t.Helper()
Jooyung Hanb04a4992020-03-13 18:57:35 +09002624 if !reflect.DeepEqual(actual, expected) {
2625 t.Errorf(message+
2626 "\nactual: %v"+
2627 "\nexpected: %v",
2628 actual,
2629 expected,
2630 )
2631 }
2632}
2633
Jooyung Han61b66e92020-03-21 14:21:46 +00002634func TestLlndkLibrary(t *testing.T) {
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002635 result := prepareForCcTest.RunTestWithBp(t, `
2636 cc_library {
2637 name: "libllndk",
2638 stubs: { versions: ["1", "2"] },
2639 llndk: {
2640 symbol_file: "libllndk.map.txt",
2641 },
2642 export_include_dirs: ["include"],
2643 }
2644
2645 cc_prebuilt_library_shared {
2646 name: "libllndkprebuilt",
2647 stubs: { versions: ["1", "2"] },
2648 llndk: {
2649 symbol_file: "libllndkprebuilt.map.txt",
2650 },
2651 }
2652
2653 cc_library {
2654 name: "libllndk_with_external_headers",
2655 stubs: { versions: ["1", "2"] },
2656 llndk: {
2657 symbol_file: "libllndk.map.txt",
2658 export_llndk_headers: ["libexternal_llndk_headers"],
2659 },
2660 header_libs: ["libexternal_headers"],
2661 export_header_lib_headers: ["libexternal_headers"],
2662 }
2663 cc_library_headers {
2664 name: "libexternal_headers",
2665 export_include_dirs: ["include"],
2666 vendor_available: true,
2667 }
2668 cc_library_headers {
2669 name: "libexternal_llndk_headers",
2670 export_include_dirs: ["include_llndk"],
2671 llndk: {
2672 symbol_file: "libllndk.map.txt",
2673 },
2674 vendor_available: true,
2675 }
2676
2677 cc_library {
2678 name: "libllndk_with_override_headers",
2679 stubs: { versions: ["1", "2"] },
2680 llndk: {
2681 symbol_file: "libllndk.map.txt",
2682 override_export_include_dirs: ["include_llndk"],
2683 },
2684 export_include_dirs: ["include"],
2685 }
2686 `)
2687 actual := result.ModuleVariantsForTests("libllndk")
2688 for i := 0; i < len(actual); i++ {
2689 if !strings.HasPrefix(actual[i], "android_vendor.29_") {
2690 actual = append(actual[:i], actual[i+1:]...)
2691 i--
2692 }
2693 }
2694 expected := []string{
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002695 "android_vendor.29_arm64_armv8-a_shared_current",
2696 "android_vendor.29_arm64_armv8-a_shared",
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002697 "android_vendor.29_arm_armv7-a-neon_shared_current",
2698 "android_vendor.29_arm_armv7-a-neon_shared",
2699 }
2700 android.AssertArrayString(t, "variants for llndk stubs", expected, actual)
2701
2702 params := result.ModuleForTests("libllndk", "android_vendor.29_arm_armv7-a-neon_shared").Description("generate stub")
2703 android.AssertSame(t, "use VNDK version for default stubs", "current", params.Args["apiLevel"])
2704
Colin Cross0fb7fcd2021-03-02 11:00:07 -08002705 checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) {
2706 t.Helper()
2707 m := result.ModuleForTests(module, variant).Module()
2708 f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo)
2709 android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]",
2710 expectedDirs, f.IncludeDirs)
2711 }
2712
2713 checkExportedIncludeDirs("libllndk", "android_arm64_armv8-a_shared", "include")
2714 checkExportedIncludeDirs("libllndk", "android_vendor.29_arm64_armv8-a_shared", "include")
2715 checkExportedIncludeDirs("libllndk_with_external_headers", "android_arm64_armv8-a_shared", "include")
2716 checkExportedIncludeDirs("libllndk_with_external_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2717 checkExportedIncludeDirs("libllndk_with_override_headers", "android_arm64_armv8-a_shared", "include")
2718 checkExportedIncludeDirs("libllndk_with_override_headers", "android_vendor.29_arm64_armv8-a_shared", "include_llndk")
2719}
2720
Jiyong Parka46a4d52017-12-14 19:54:34 +09002721func TestLlndkHeaders(t *testing.T) {
2722 ctx := testCc(t, `
Colin Cross627280f2021-04-26 16:53:58 -07002723 cc_library_headers {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002724 name: "libllndk_headers",
2725 export_include_dirs: ["my_include"],
Colin Cross627280f2021-04-26 16:53:58 -07002726 llndk: {
2727 llndk_headers: true,
2728 },
Jiyong Parka46a4d52017-12-14 19:54:34 +09002729 }
2730 cc_library {
Colin Cross0477b422020-10-13 18:43:54 -07002731 name: "libllndk",
Colin Cross627280f2021-04-26 16:53:58 -07002732 llndk: {
2733 symbol_file: "libllndk.map.txt",
2734 export_llndk_headers: ["libllndk_headers"],
2735 }
Colin Cross0477b422020-10-13 18:43:54 -07002736 }
2737
2738 cc_library {
Jiyong Parka46a4d52017-12-14 19:54:34 +09002739 name: "libvendor",
2740 shared_libs: ["libllndk"],
2741 vendor: true,
2742 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002743 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08002744 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09002745 }
2746 `)
2747
2748 // _static variant is used since _shared reuses *.o from the static variant
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002749 cc := ctx.ModuleForTests("libvendor", "android_vendor.29_arm_armv7-a-neon_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09002750 cflags := cc.Args["cFlags"]
2751 if !strings.Contains(cflags, "-Imy_include") {
2752 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
2753 }
2754}
2755
Logan Chien43d34c32017-12-20 01:17:32 +08002756func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
2757 actual := module.Properties.AndroidMkRuntimeLibs
2758 if !reflect.DeepEqual(actual, expected) {
2759 t.Errorf("incorrect runtime_libs for shared libs"+
2760 "\nactual: %v"+
2761 "\nexpected: %v",
2762 actual,
2763 expected,
2764 )
2765 }
2766}
2767
2768const runtimeLibAndroidBp = `
2769 cc_library {
Justin Yun8a2600c2020-12-07 12:44:03 +09002770 name: "liball_available",
2771 vendor_available: true,
2772 product_available: true,
2773 no_libcrt : true,
2774 nocrt : true,
2775 system_shared_libs : [],
2776 }
2777 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002778 name: "libvendor_available1",
2779 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002780 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002781 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002782 nocrt : true,
2783 system_shared_libs : [],
2784 }
2785 cc_library {
2786 name: "libvendor_available2",
2787 vendor_available: true,
Justin Yun8a2600c2020-12-07 12:44:03 +09002788 runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002789 target: {
2790 vendor: {
Justin Yun8a2600c2020-12-07 12:44:03 +09002791 exclude_runtime_libs: ["liball_available"],
Logan Chien43d34c32017-12-20 01:17:32 +08002792 }
2793 },
Yi Konge7fe9912019-06-02 00:53:50 -07002794 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002795 nocrt : true,
2796 system_shared_libs : [],
2797 }
2798 cc_library {
Justin Yuncbca3732021-02-03 19:24:13 +09002799 name: "libproduct_vendor",
2800 product_specific: true,
2801 vendor_available: true,
2802 no_libcrt : true,
2803 nocrt : true,
2804 system_shared_libs : [],
2805 }
2806 cc_library {
Logan Chien43d34c32017-12-20 01:17:32 +08002807 name: "libcore",
Justin Yun8a2600c2020-12-07 12:44:03 +09002808 runtime_libs: ["liball_available"],
Yi Konge7fe9912019-06-02 00:53:50 -07002809 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002810 nocrt : true,
2811 system_shared_libs : [],
2812 }
2813 cc_library {
2814 name: "libvendor1",
2815 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002816 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002817 nocrt : true,
2818 system_shared_libs : [],
2819 }
2820 cc_library {
2821 name: "libvendor2",
2822 vendor: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002823 runtime_libs: ["liball_available", "libvendor1", "libproduct_vendor"],
Justin Yun8a2600c2020-12-07 12:44:03 +09002824 no_libcrt : true,
2825 nocrt : true,
2826 system_shared_libs : [],
2827 }
2828 cc_library {
2829 name: "libproduct_available1",
2830 product_available: true,
2831 runtime_libs: ["liball_available"],
2832 no_libcrt : true,
2833 nocrt : true,
2834 system_shared_libs : [],
2835 }
2836 cc_library {
2837 name: "libproduct1",
2838 product_specific: true,
2839 no_libcrt : true,
2840 nocrt : true,
2841 system_shared_libs : [],
2842 }
2843 cc_library {
2844 name: "libproduct2",
2845 product_specific: true,
Justin Yuncbca3732021-02-03 19:24:13 +09002846 runtime_libs: ["liball_available", "libproduct1", "libproduct_vendor"],
Yi Konge7fe9912019-06-02 00:53:50 -07002847 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002848 nocrt : true,
2849 system_shared_libs : [],
2850 }
2851`
2852
2853func TestRuntimeLibs(t *testing.T) {
2854 ctx := testCc(t, runtimeLibAndroidBp)
2855
2856 // runtime_libs for core variants use the module names without suffixes.
Colin Cross7113d202019-11-20 16:39:12 -08002857 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002858
Justin Yun8a2600c2020-12-07 12:44:03 +09002859 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2860 checkRuntimeLibs(t, []string{"liball_available"}, module)
2861
2862 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2863 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002864
2865 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002866 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002867
2868 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2869 // and vendor variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002870 variant = "android_vendor.29_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002871
Justin Yun8a2600c2020-12-07 12:44:03 +09002872 module = ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2873 checkRuntimeLibs(t, []string{"liball_available.vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002874
2875 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002876 checkRuntimeLibs(t, []string{"liball_available.vendor", "libvendor1", "libproduct_vendor.vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002877
2878 // runtime_libs for product variants have '.product' suffixes if the modules have both core
2879 // and product variants.
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002880 variant = "android_product.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002881
2882 module = ctx.ModuleForTests("libproduct_available1", variant).Module().(*Module)
2883 checkRuntimeLibs(t, []string{"liball_available.product"}, module)
2884
2885 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yund00f5ca2021-02-03 19:43:02 +09002886 checkRuntimeLibs(t, []string{"liball_available.product", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002887}
2888
2889func TestExcludeRuntimeLibs(t *testing.T) {
2890 ctx := testCc(t, runtimeLibAndroidBp)
2891
Colin Cross7113d202019-11-20 16:39:12 -08002892 variant := "android_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002893 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2894 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002895
Jiyong Parkf58c46e2021-04-01 21:35:20 +09002896 variant = "android_vendor.29_arm64_armv8-a_shared"
Justin Yun8a2600c2020-12-07 12:44:03 +09002897 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
Logan Chien43d34c32017-12-20 01:17:32 +08002898 checkRuntimeLibs(t, nil, module)
2899}
2900
2901func TestRuntimeLibsNoVndk(t *testing.T) {
2902 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2903
2904 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2905
Colin Cross7113d202019-11-20 16:39:12 -08002906 variant := "android_arm64_armv8-a_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002907
Justin Yun8a2600c2020-12-07 12:44:03 +09002908 module := ctx.ModuleForTests("libvendor_available1", variant).Module().(*Module)
2909 checkRuntimeLibs(t, []string{"liball_available"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002910
2911 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002912 checkRuntimeLibs(t, []string{"liball_available", "libvendor1", "libproduct_vendor"}, module)
Justin Yun8a2600c2020-12-07 12:44:03 +09002913
2914 module = ctx.ModuleForTests("libproduct2", variant).Module().(*Module)
Justin Yuncbca3732021-02-03 19:24:13 +09002915 checkRuntimeLibs(t, []string{"liball_available", "libproduct1", "libproduct_vendor"}, module)
Logan Chien43d34c32017-12-20 01:17:32 +08002916}
2917
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002918func checkStaticLibs(t *testing.T, expected []string, module *Module) {
Jooyung Han03b51852020-02-26 22:45:42 +09002919 t.Helper()
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002920 actual := module.Properties.AndroidMkStaticLibs
2921 if !reflect.DeepEqual(actual, expected) {
2922 t.Errorf("incorrect static_libs"+
2923 "\nactual: %v"+
2924 "\nexpected: %v",
2925 actual,
2926 expected,
2927 )
2928 }
2929}
2930
2931const staticLibAndroidBp = `
2932 cc_library {
2933 name: "lib1",
2934 }
2935 cc_library {
2936 name: "lib2",
2937 static_libs: ["lib1"],
2938 }
2939`
2940
2941func TestStaticLibDepExport(t *testing.T) {
2942 ctx := testCc(t, staticLibAndroidBp)
2943
2944 // Check the shared version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002945 variant := "android_arm64_armv8-a_shared"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002946 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Ryan Prichardc2018e22021-04-02 20:23:22 -07002947 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002948
2949 // Check the static version of lib2.
Colin Cross7113d202019-11-20 16:39:12 -08002950 variant = "android_arm64_armv8-a_static"
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002951 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2952 // libc++_static is linked additionally.
Ryan Prichardc2018e22021-04-02 20:23:22 -07002953 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002954}
2955
Jiyong Parkd08b6972017-09-26 10:50:54 +09002956var compilerFlagsTestCases = []struct {
2957 in string
2958 out bool
2959}{
2960 {
2961 in: "a",
2962 out: false,
2963 },
2964 {
2965 in: "-a",
2966 out: true,
2967 },
2968 {
2969 in: "-Ipath/to/something",
2970 out: false,
2971 },
2972 {
2973 in: "-isystempath/to/something",
2974 out: false,
2975 },
2976 {
2977 in: "--coverage",
2978 out: false,
2979 },
2980 {
2981 in: "-include a/b",
2982 out: true,
2983 },
2984 {
2985 in: "-include a/b c/d",
2986 out: false,
2987 },
2988 {
2989 in: "-DMACRO",
2990 out: true,
2991 },
2992 {
2993 in: "-DMAC RO",
2994 out: false,
2995 },
2996 {
2997 in: "-a -b",
2998 out: false,
2999 },
3000 {
3001 in: "-DMACRO=definition",
3002 out: true,
3003 },
3004 {
3005 in: "-DMACRO=defi nition",
3006 out: true, // TODO(jiyong): this should be false
3007 },
3008 {
3009 in: "-DMACRO(x)=x + 1",
3010 out: true,
3011 },
3012 {
3013 in: "-DMACRO=\"defi nition\"",
3014 out: true,
3015 },
3016}
3017
3018type mockContext struct {
3019 BaseModuleContext
3020 result bool
3021}
3022
3023func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
3024 // CheckBadCompilerFlags calls this function when the flag should be rejected
3025 ctx.result = false
3026}
3027
3028func TestCompilerFlags(t *testing.T) {
3029 for _, testCase := range compilerFlagsTestCases {
3030 ctx := &mockContext{result: true}
3031 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
3032 if ctx.result != testCase.out {
3033 t.Errorf("incorrect output:")
3034 t.Errorf(" input: %#v", testCase.in)
3035 t.Errorf(" expected: %#v", testCase.out)
3036 t.Errorf(" got: %#v", ctx.result)
3037 }
3038 }
Jeff Gaston294356f2017-09-27 17:05:30 -07003039}
Jiyong Park374510b2018-03-19 18:23:01 +09003040
Jiyong Park37b25202018-07-11 10:49:27 +09003041func TestRecovery(t *testing.T) {
3042 ctx := testCc(t, `
3043 cc_library_shared {
3044 name: "librecovery",
3045 recovery: true,
3046 }
3047 cc_library_shared {
3048 name: "librecovery32",
3049 recovery: true,
3050 compile_multilib:"32",
3051 }
Jiyong Park5baac542018-08-28 09:55:37 +09003052 cc_library_shared {
3053 name: "libHalInRecovery",
3054 recovery_available: true,
3055 vendor: true,
3056 }
Jiyong Park37b25202018-07-11 10:49:27 +09003057 `)
3058
3059 variants := ctx.ModuleVariantsForTests("librecovery")
Colin Crossfb0c16e2019-11-20 17:12:35 -08003060 const arm64 = "android_recovery_arm64_armv8-a_shared"
Jiyong Park37b25202018-07-11 10:49:27 +09003061 if len(variants) != 1 || !android.InList(arm64, variants) {
3062 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
3063 }
3064
3065 variants = ctx.ModuleVariantsForTests("librecovery32")
3066 if android.InList(arm64, variants) {
3067 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
3068 }
Jiyong Park5baac542018-08-28 09:55:37 +09003069
3070 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
3071 if !recoveryModule.Platform() {
3072 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
3073 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09003074}
Jiyong Park5baac542018-08-28 09:55:37 +09003075
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003076func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) {
3077 bp := `
3078 cc_prebuilt_test_library_shared {
3079 name: "test_lib",
3080 relative_install_path: "foo/bar/baz",
3081 srcs: ["srcpath/dontusethispath/baz.so"],
3082 }
3083
3084 cc_test {
3085 name: "main_test",
3086 data_libs: ["test_lib"],
3087 gtest: false,
3088 }
3089 `
3090
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003091 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003092 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
Jiyong Parkf58c46e2021-04-01 21:35:20 +09003093 config.TestProductVariables.Platform_vndk_version = StringPtr("29")
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003094 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
3095
3096 ctx := testCcWithConfig(t, config)
3097 module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
3098 testBinary := module.(*Module).linker.(*testBinary)
3099 outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
3100 if err != nil {
3101 t.Fatalf("Expected cc_test to produce output files, error: %s", err)
3102 }
3103 if len(outputFiles) != 1 {
3104 t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
3105 }
3106 if len(testBinary.dataPaths()) != 1 {
3107 t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
3108 }
3109
3110 outputPath := outputFiles[0].String()
3111
3112 if !strings.HasSuffix(outputPath, "/main_test") {
3113 t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
3114 }
Colin Crossaa255532020-07-03 13:18:24 -07003115 entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
Chris Parsons1f6d90f2020-06-17 16:10:42 -04003116 if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") {
3117 t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+
3118 " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0])
3119 }
3120}
3121
Jiyong Park7ed9de32018-10-15 22:25:07 +09003122func TestVersionedStubs(t *testing.T) {
3123 ctx := testCc(t, `
3124 cc_library_shared {
3125 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003126 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003127 stubs: {
3128 symbol_file: "foo.map.txt",
3129 versions: ["1", "2", "3"],
3130 },
3131 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003132
Jiyong Park7ed9de32018-10-15 22:25:07 +09003133 cc_library_shared {
3134 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09003135 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09003136 shared_libs: ["libFoo#1"],
3137 }`)
3138
3139 variants := ctx.ModuleVariantsForTests("libFoo")
3140 expectedVariants := []string{
Colin Cross7113d202019-11-20 16:39:12 -08003141 "android_arm64_armv8-a_shared",
3142 "android_arm64_armv8-a_shared_1",
3143 "android_arm64_armv8-a_shared_2",
3144 "android_arm64_armv8-a_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003145 "android_arm64_armv8-a_shared_current",
Colin Cross7113d202019-11-20 16:39:12 -08003146 "android_arm_armv7-a-neon_shared",
3147 "android_arm_armv7-a-neon_shared_1",
3148 "android_arm_armv7-a-neon_shared_2",
3149 "android_arm_armv7-a-neon_shared_3",
Jiyong Parkd4a3a132021-03-17 20:21:35 +09003150 "android_arm_armv7-a-neon_shared_current",
Jiyong Park7ed9de32018-10-15 22:25:07 +09003151 }
3152 variantsMismatch := false
3153 if len(variants) != len(expectedVariants) {
3154 variantsMismatch = true
3155 } else {
3156 for _, v := range expectedVariants {
3157 if !inList(v, variants) {
3158 variantsMismatch = false
3159 }
3160 }
3161 }
3162 if variantsMismatch {
3163 t.Errorf("variants of libFoo expected:\n")
3164 for _, v := range expectedVariants {
3165 t.Errorf("%q\n", v)
3166 }
3167 t.Errorf(", but got:\n")
3168 for _, v := range variants {
3169 t.Errorf("%q\n", v)
3170 }
3171 }
3172
Colin Cross7113d202019-11-20 16:39:12 -08003173 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("ld")
Jiyong Park7ed9de32018-10-15 22:25:07 +09003174 libFlags := libBarLinkRule.Args["libFlags"]
Colin Cross7113d202019-11-20 16:39:12 -08003175 libFoo1StubPath := "libFoo/android_arm64_armv8-a_shared_1/libFoo.so"
Jiyong Park7ed9de32018-10-15 22:25:07 +09003176 if !strings.Contains(libFlags, libFoo1StubPath) {
3177 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
3178 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09003179
Colin Cross7113d202019-11-20 16:39:12 -08003180 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_shared").Rule("cc")
Jiyong Parkda732bd2018-11-02 18:23:15 +09003181 cFlags := libBarCompileRule.Args["cFlags"]
3182 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
3183 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
3184 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
3185 }
Jiyong Park37b25202018-07-11 10:49:27 +09003186}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003187
Jooyung Hanb04a4992020-03-13 18:57:35 +09003188func TestVersioningMacro(t *testing.T) {
3189 for _, tc := range []struct{ moduleName, expected string }{
3190 {"libc", "__LIBC_API__"},
3191 {"libfoo", "__LIBFOO_API__"},
3192 {"libfoo@1", "__LIBFOO_1_API__"},
3193 {"libfoo-v1", "__LIBFOO_V1_API__"},
3194 {"libfoo.v1", "__LIBFOO_V1_API__"},
3195 } {
3196 checkEquals(t, tc.moduleName, tc.expected, versioningMacroName(tc.moduleName))
3197 }
3198}
3199
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003200func TestStaticExecutable(t *testing.T) {
3201 ctx := testCc(t, `
3202 cc_binary {
3203 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01003204 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003205 static_executable: true,
3206 }`)
3207
Colin Cross7113d202019-11-20 16:39:12 -08003208 variant := "android_arm64_armv8-a"
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003209 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
3210 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07003211 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08003212 for _, lib := range systemStaticLibs {
3213 if !strings.Contains(libFlags, lib) {
3214 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
3215 }
3216 }
3217 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
3218 for _, lib := range systemSharedLibs {
3219 if strings.Contains(libFlags, lib) {
3220 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
3221 }
3222 }
3223}
Jiyong Parke4bb9862019-02-01 00:31:10 +09003224
3225func TestStaticDepsOrderWithStubs(t *testing.T) {
3226 ctx := testCc(t, `
3227 cc_binary {
3228 name: "mybin",
3229 srcs: ["foo.c"],
Colin Cross0de8a1e2020-09-18 14:15:30 -07003230 static_libs: ["libfooC", "libfooB"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003231 static_executable: true,
3232 stl: "none",
3233 }
3234
3235 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003236 name: "libfooB",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003237 srcs: ["foo.c"],
Colin Crossf9aabd72020-02-15 11:29:50 -08003238 shared_libs: ["libfooC"],
Jiyong Parke4bb9862019-02-01 00:31:10 +09003239 stl: "none",
3240 }
3241
3242 cc_library {
Colin Crossf9aabd72020-02-15 11:29:50 -08003243 name: "libfooC",
Jiyong Parke4bb9862019-02-01 00:31:10 +09003244 srcs: ["foo.c"],
3245 stl: "none",
3246 stubs: {
3247 versions: ["1"],
3248 },
3249 }`)
3250
Colin Cross0de8a1e2020-09-18 14:15:30 -07003251 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
3252 actual := mybin.Implicits[:2]
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003253 expected := GetOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
Jiyong Parke4bb9862019-02-01 00:31:10 +09003254
3255 if !reflect.DeepEqual(actual, expected) {
3256 t.Errorf("staticDeps orderings were not propagated correctly"+
3257 "\nactual: %v"+
3258 "\nexpected: %v",
3259 actual,
3260 expected,
3261 )
3262 }
3263}
Jooyung Han38002912019-05-16 04:01:54 +09003264
Jooyung Hand48f3c32019-08-23 11:18:57 +09003265func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
3266 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
3267 cc_library {
3268 name: "libA",
3269 srcs: ["foo.c"],
3270 shared_libs: ["libB"],
3271 stl: "none",
3272 }
3273
3274 cc_library {
3275 name: "libB",
3276 srcs: ["foo.c"],
3277 enabled: false,
3278 stl: "none",
3279 }
3280 `)
3281}
3282
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003283// Simple smoke test for the cc_fuzz target that ensures the rule compiles
3284// correctly.
3285func TestFuzzTarget(t *testing.T) {
3286 ctx := testCc(t, `
3287 cc_fuzz {
3288 name: "fuzz_smoke_test",
3289 srcs: ["foo.c"],
3290 }`)
3291
Paul Duffin075c4172019-12-19 19:06:13 +00003292 variant := "android_arm64_armv8-a_fuzzer"
Mitch Phillipsda9a4632019-07-15 09:34:09 -07003293 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
3294}
3295
Jiyong Park29074592019-07-07 16:27:47 +09003296func TestAidl(t *testing.T) {
3297}
3298
Jooyung Han38002912019-05-16 04:01:54 +09003299func assertString(t *testing.T, got, expected string) {
3300 t.Helper()
3301 if got != expected {
3302 t.Errorf("expected %q got %q", expected, got)
3303 }
3304}
3305
3306func assertArrayString(t *testing.T, got, expected []string) {
3307 t.Helper()
3308 if len(got) != len(expected) {
3309 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
3310 return
3311 }
3312 for i := range got {
3313 if got[i] != expected[i] {
3314 t.Errorf("expected %d-th %q (%q) got %q (%q)",
3315 i, expected[i], expected, got[i], got)
3316 return
3317 }
3318 }
3319}
Colin Crosse1bb5d02019-09-24 14:55:04 -07003320
Jooyung Han0302a842019-10-30 18:43:49 +09003321func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
3322 t.Helper()
3323 assertArrayString(t, android.SortedStringKeys(m), expected)
3324}
3325
Colin Crosse1bb5d02019-09-24 14:55:04 -07003326func TestDefaults(t *testing.T) {
3327 ctx := testCc(t, `
3328 cc_defaults {
3329 name: "defaults",
3330 srcs: ["foo.c"],
3331 static: {
3332 srcs: ["bar.c"],
3333 },
3334 shared: {
3335 srcs: ["baz.c"],
3336 },
Liz Kammer3cf52112021-03-31 15:42:03 -04003337 bazel_module: {
3338 bp2build_available: true,
3339 },
Colin Crosse1bb5d02019-09-24 14:55:04 -07003340 }
3341
3342 cc_library_static {
3343 name: "libstatic",
3344 defaults: ["defaults"],
3345 }
3346
3347 cc_library_shared {
3348 name: "libshared",
3349 defaults: ["defaults"],
3350 }
3351
3352 cc_library {
3353 name: "libboth",
3354 defaults: ["defaults"],
3355 }
3356
3357 cc_binary {
3358 name: "binary",
3359 defaults: ["defaults"],
3360 }`)
3361
3362 pathsToBase := func(paths android.Paths) []string {
3363 var ret []string
3364 for _, p := range paths {
3365 ret = append(ret, p.Base())
3366 }
3367 return ret
3368 }
3369
Colin Cross7113d202019-11-20 16:39:12 -08003370 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003371 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3372 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
3373 }
Colin Cross7113d202019-11-20 16:39:12 -08003374 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_shared").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003375 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
3376 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
3377 }
Colin Cross7113d202019-11-20 16:39:12 -08003378 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a").Rule("ld")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003379 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
3380 t.Errorf("binary ld rule wanted %q, got %q", w, g)
3381 }
3382
Colin Cross7113d202019-11-20 16:39:12 -08003383 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003384 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3385 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
3386 }
Colin Cross7113d202019-11-20 16:39:12 -08003387 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_static").Rule("ar")
Colin Crosse1bb5d02019-09-24 14:55:04 -07003388 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
3389 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
3390 }
3391}
Colin Crosseabaedd2020-02-06 17:01:55 -08003392
3393func TestProductVariableDefaults(t *testing.T) {
3394 bp := `
3395 cc_defaults {
3396 name: "libfoo_defaults",
3397 srcs: ["foo.c"],
3398 cppflags: ["-DFOO"],
3399 product_variables: {
3400 debuggable: {
3401 cppflags: ["-DBAR"],
3402 },
3403 },
3404 }
3405
3406 cc_library {
3407 name: "libfoo",
3408 defaults: ["libfoo_defaults"],
3409 }
3410 `
3411
Paul Duffin8567f222021-03-23 00:02:06 +00003412 result := android.GroupFixturePreparers(
3413 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003414 android.PrepareForTestWithVariables,
Colin Crosseabaedd2020-02-06 17:01:55 -08003415
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003416 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
3417 variables.Debuggable = BoolPtr(true)
3418 }),
3419 ).RunTestWithBp(t, bp)
Colin Crosseabaedd2020-02-06 17:01:55 -08003420
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003421 libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
Paul Duffine84b1332021-03-12 11:59:43 +00003422 android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
Colin Crosseabaedd2020-02-06 17:01:55 -08003423}
Colin Crosse4f6eba2020-09-22 18:11:25 -07003424
3425func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
3426 t.Parallel()
3427 bp := `
3428 cc_library_static {
3429 name: "libfoo",
3430 srcs: ["foo.c"],
3431 whole_static_libs: ["libbar"],
3432 }
3433
3434 cc_library_static {
3435 name: "libbar",
3436 whole_static_libs: ["libmissing"],
3437 }
3438 `
3439
Paul Duffin8567f222021-03-23 00:02:06 +00003440 result := android.GroupFixturePreparers(
3441 prepareForCcTest,
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003442 android.PrepareForTestWithAllowMissingDependencies,
3443 ).RunTestWithBp(t, bp)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003444
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003445 libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003446 android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
Colin Crosse4f6eba2020-09-22 18:11:25 -07003447
Paul Duffine84b1332021-03-12 11:59:43 +00003448 android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
Colin Crosse4f6eba2020-09-22 18:11:25 -07003449
Paul Duffin7d8a8ad2021-03-07 15:58:39 +00003450 libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
Paul Duffine84b1332021-03-12 11:59:43 +00003451 android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
Colin Crosse4f6eba2020-09-22 18:11:25 -07003452}
Colin Crosse9fe2942020-11-10 18:12:15 -08003453
3454func TestInstallSharedLibs(t *testing.T) {
3455 bp := `
3456 cc_binary {
3457 name: "bin",
3458 host_supported: true,
3459 shared_libs: ["libshared"],
3460 runtime_libs: ["libruntime"],
3461 srcs: [":gen"],
3462 }
3463
3464 cc_library_shared {
3465 name: "libshared",
3466 host_supported: true,
3467 shared_libs: ["libtransitive"],
3468 }
3469
3470 cc_library_shared {
3471 name: "libtransitive",
3472 host_supported: true,
3473 }
3474
3475 cc_library_shared {
3476 name: "libruntime",
3477 host_supported: true,
3478 }
3479
3480 cc_binary_host {
3481 name: "tool",
3482 srcs: ["foo.cpp"],
3483 }
3484
3485 genrule {
3486 name: "gen",
3487 tools: ["tool"],
3488 out: ["gen.cpp"],
3489 cmd: "$(location tool) $(out)",
3490 }
3491 `
3492
Paul Duffinc3e6ce02021-03-22 23:21:32 +00003493 config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
Colin Crosse9fe2942020-11-10 18:12:15 -08003494 ctx := testCcWithConfig(t, config)
3495
3496 hostBin := ctx.ModuleForTests("bin", config.BuildOSTarget.String()).Description("install")
3497 hostShared := ctx.ModuleForTests("libshared", config.BuildOSTarget.String()+"_shared").Description("install")
3498 hostRuntime := ctx.ModuleForTests("libruntime", config.BuildOSTarget.String()+"_shared").Description("install")
3499 hostTransitive := ctx.ModuleForTests("libtransitive", config.BuildOSTarget.String()+"_shared").Description("install")
3500 hostTool := ctx.ModuleForTests("tool", config.BuildOSTarget.String()).Description("install")
3501
3502 if g, w := hostBin.Implicits.Strings(), hostShared.Output.String(); !android.InList(w, g) {
3503 t.Errorf("expected host bin dependency %q, got %q", w, g)
3504 }
3505
3506 if g, w := hostBin.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3507 t.Errorf("expected host bin dependency %q, got %q", w, g)
3508 }
3509
3510 if g, w := hostShared.Implicits.Strings(), hostTransitive.Output.String(); !android.InList(w, g) {
3511 t.Errorf("expected host bin dependency %q, got %q", w, g)
3512 }
3513
3514 if g, w := hostBin.Implicits.Strings(), hostRuntime.Output.String(); !android.InList(w, g) {
3515 t.Errorf("expected host bin dependency %q, got %q", w, g)
3516 }
3517
3518 if g, w := hostBin.Implicits.Strings(), hostTool.Output.String(); android.InList(w, g) {
3519 t.Errorf("expected no host bin dependency %q, got %q", w, g)
3520 }
3521
3522 deviceBin := ctx.ModuleForTests("bin", "android_arm64_armv8-a").Description("install")
3523 deviceShared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_shared").Description("install")
3524 deviceTransitive := ctx.ModuleForTests("libtransitive", "android_arm64_armv8-a_shared").Description("install")
3525 deviceRuntime := ctx.ModuleForTests("libruntime", "android_arm64_armv8-a_shared").Description("install")
3526
3527 if g, w := deviceBin.OrderOnly.Strings(), deviceShared.Output.String(); !android.InList(w, g) {
3528 t.Errorf("expected device bin dependency %q, got %q", w, g)
3529 }
3530
3531 if g, w := deviceBin.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3532 t.Errorf("expected device bin dependency %q, got %q", w, g)
3533 }
3534
3535 if g, w := deviceShared.OrderOnly.Strings(), deviceTransitive.Output.String(); !android.InList(w, g) {
3536 t.Errorf("expected device bin dependency %q, got %q", w, g)
3537 }
3538
3539 if g, w := deviceBin.OrderOnly.Strings(), deviceRuntime.Output.String(); !android.InList(w, g) {
3540 t.Errorf("expected device bin dependency %q, got %q", w, g)
3541 }
3542
3543 if g, w := deviceBin.OrderOnly.Strings(), hostTool.Output.String(); android.InList(w, g) {
3544 t.Errorf("expected no device bin dependency %q, got %q", w, g)
3545 }
3546
3547}
Jiyong Park1ad8e162020-12-01 23:40:09 +09003548
3549func TestStubsLibReexportsHeaders(t *testing.T) {
3550 ctx := testCc(t, `
3551 cc_library_shared {
3552 name: "libclient",
3553 srcs: ["foo.c"],
3554 shared_libs: ["libfoo#1"],
3555 }
3556
3557 cc_library_shared {
3558 name: "libfoo",
3559 srcs: ["foo.c"],
3560 shared_libs: ["libbar"],
3561 export_shared_lib_headers: ["libbar"],
3562 stubs: {
3563 symbol_file: "foo.map.txt",
3564 versions: ["1", "2", "3"],
3565 },
3566 }
3567
3568 cc_library_shared {
3569 name: "libbar",
3570 export_include_dirs: ["include/libbar"],
3571 srcs: ["foo.c"],
3572 }`)
3573
3574 cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3575
3576 if !strings.Contains(cFlags, "-Iinclude/libbar") {
3577 t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
3578 }
3579}
Jooyung Hane197d8b2021-01-05 10:33:16 +09003580
3581func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
3582 ctx := testCc(t, `
3583 cc_library {
3584 name: "libfoo",
3585 srcs: ["a/Foo.aidl"],
3586 aidl: { flags: ["-Werror"], },
3587 }
3588 `)
3589
3590 libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
3591 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3592 aidlCommand := manifest.Commands[0].GetCommand()
3593 expectedAidlFlag := "-Werror"
3594 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3595 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3596 }
3597}
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003598
Jooyung Han07f70c02021-11-06 07:08:45 +09003599func TestAidlFlagsWithMinSdkVersion(t *testing.T) {
3600 for _, tc := range []struct {
3601 name string
3602 sdkVersion string
3603 variant string
3604 expected string
3605 }{
3606 {
3607 name: "default is current",
3608 sdkVersion: "",
3609 variant: "android_arm64_armv8-a_static",
3610 expected: "platform_apis",
3611 },
3612 {
3613 name: "use sdk_version",
3614 sdkVersion: `sdk_version: "29"`,
3615 variant: "android_arm64_armv8-a_static",
3616 expected: "platform_apis",
3617 },
3618 {
3619 name: "use sdk_version(sdk variant)",
3620 sdkVersion: `sdk_version: "29"`,
3621 variant: "android_arm64_armv8-a_sdk_static",
3622 expected: "29",
3623 },
3624 {
3625 name: "use min_sdk_version",
3626 sdkVersion: `min_sdk_version: "29"`,
3627 variant: "android_arm64_armv8-a_static",
3628 expected: "29",
3629 },
3630 } {
3631 t.Run(tc.name, func(t *testing.T) {
3632 ctx := testCc(t, `
3633 cc_library {
3634 name: "libfoo",
3635 stl: "none",
3636 srcs: ["a/Foo.aidl"],
3637 `+tc.sdkVersion+`
3638 }
3639 `)
3640 libfoo := ctx.ModuleForTests("libfoo", tc.variant)
3641 manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
3642 aidlCommand := manifest.Commands[0].GetCommand()
3643 expectedAidlFlag := "--min_sdk_version=" + tc.expected
3644 if !strings.Contains(aidlCommand, expectedAidlFlag) {
3645 t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag)
3646 }
3647 })
3648 }
3649}
3650
Jiyong Parka008fb02021-03-16 17:15:53 +09003651func TestMinSdkVersionInClangTriple(t *testing.T) {
3652 ctx := testCc(t, `
3653 cc_library_shared {
3654 name: "libfoo",
3655 srcs: ["foo.c"],
3656 min_sdk_version: "29",
3657 }`)
3658
3659 cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
3660 android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
3661}
3662
Paul Duffin3cb603e2021-02-19 13:57:10 +00003663func TestIncludeDirsExporting(t *testing.T) {
3664
3665 // Trim spaces from the beginning, end and immediately after any newline characters. Leaves
3666 // embedded newline characters alone.
3667 trimIndentingSpaces := func(s string) string {
3668 return strings.TrimSpace(regexp.MustCompile("(^|\n)\\s+").ReplaceAllString(s, "$1"))
3669 }
3670
3671 checkPaths := func(t *testing.T, message string, expected string, paths android.Paths) {
3672 t.Helper()
3673 expected = trimIndentingSpaces(expected)
3674 actual := trimIndentingSpaces(strings.Join(android.FirstUniqueStrings(android.NormalizePathsForTesting(paths)), "\n"))
3675 if expected != actual {
3676 t.Errorf("%s: expected:\n%s\n actual:\n%s\n", message, expected, actual)
3677 }
3678 }
3679
3680 type exportedChecker func(t *testing.T, name string, exported FlagExporterInfo)
3681
3682 checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
3683 t.Helper()
3684 exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo)
3685 name := module.Name()
3686
3687 for _, checker := range checkers {
3688 checker(t, name, exported)
3689 }
3690 }
3691
3692 expectedIncludeDirs := func(expectedPaths string) exportedChecker {
3693 return func(t *testing.T, name string, exported FlagExporterInfo) {
3694 t.Helper()
3695 checkPaths(t, fmt.Sprintf("%s: include dirs", name), expectedPaths, exported.IncludeDirs)
3696 }
3697 }
3698
3699 expectedSystemIncludeDirs := func(expectedPaths string) exportedChecker {
3700 return func(t *testing.T, name string, exported FlagExporterInfo) {
3701 t.Helper()
3702 checkPaths(t, fmt.Sprintf("%s: system include dirs", name), expectedPaths, exported.SystemIncludeDirs)
3703 }
3704 }
3705
3706 expectedGeneratedHeaders := func(expectedPaths string) exportedChecker {
3707 return func(t *testing.T, name string, exported FlagExporterInfo) {
3708 t.Helper()
3709 checkPaths(t, fmt.Sprintf("%s: generated headers", name), expectedPaths, exported.GeneratedHeaders)
3710 }
3711 }
3712
3713 expectedOrderOnlyDeps := func(expectedPaths string) exportedChecker {
3714 return func(t *testing.T, name string, exported FlagExporterInfo) {
3715 t.Helper()
3716 checkPaths(t, fmt.Sprintf("%s: order only deps", name), expectedPaths, exported.Deps)
3717 }
3718 }
3719
3720 genRuleModules := `
3721 genrule {
3722 name: "genrule_foo",
3723 cmd: "generate-foo",
3724 out: [
3725 "generated_headers/foo/generated_header.h",
3726 ],
3727 export_include_dirs: [
3728 "generated_headers",
3729 ],
3730 }
3731
3732 genrule {
3733 name: "genrule_bar",
3734 cmd: "generate-bar",
3735 out: [
3736 "generated_headers/bar/generated_header.h",
3737 ],
3738 export_include_dirs: [
3739 "generated_headers",
3740 ],
3741 }
3742 `
3743
3744 t.Run("ensure exported include dirs are not automatically re-exported from shared_libs", func(t *testing.T) {
3745 ctx := testCc(t, genRuleModules+`
3746 cc_library {
3747 name: "libfoo",
3748 srcs: ["foo.c"],
3749 export_include_dirs: ["foo/standard"],
3750 export_system_include_dirs: ["foo/system"],
3751 generated_headers: ["genrule_foo"],
3752 export_generated_headers: ["genrule_foo"],
3753 }
3754
3755 cc_library {
3756 name: "libbar",
3757 srcs: ["bar.c"],
3758 shared_libs: ["libfoo"],
3759 export_include_dirs: ["bar/standard"],
3760 export_system_include_dirs: ["bar/system"],
3761 generated_headers: ["genrule_bar"],
3762 export_generated_headers: ["genrule_bar"],
3763 }
3764 `)
3765 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
3766 checkIncludeDirs(t, ctx, foo,
3767 expectedIncludeDirs(`
3768 foo/standard
3769 .intermediates/genrule_foo/gen/generated_headers
3770 `),
3771 expectedSystemIncludeDirs(`foo/system`),
3772 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
3773 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
3774 )
3775
3776 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
3777 checkIncludeDirs(t, ctx, bar,
3778 expectedIncludeDirs(`
3779 bar/standard
3780 .intermediates/genrule_bar/gen/generated_headers
3781 `),
3782 expectedSystemIncludeDirs(`bar/system`),
3783 expectedGeneratedHeaders(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
3784 expectedOrderOnlyDeps(`.intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h`),
3785 )
3786 })
3787
3788 t.Run("ensure exported include dirs are automatically re-exported from whole_static_libs", func(t *testing.T) {
3789 ctx := testCc(t, genRuleModules+`
3790 cc_library {
3791 name: "libfoo",
3792 srcs: ["foo.c"],
3793 export_include_dirs: ["foo/standard"],
3794 export_system_include_dirs: ["foo/system"],
3795 generated_headers: ["genrule_foo"],
3796 export_generated_headers: ["genrule_foo"],
3797 }
3798
3799 cc_library {
3800 name: "libbar",
3801 srcs: ["bar.c"],
3802 whole_static_libs: ["libfoo"],
3803 export_include_dirs: ["bar/standard"],
3804 export_system_include_dirs: ["bar/system"],
3805 generated_headers: ["genrule_bar"],
3806 export_generated_headers: ["genrule_bar"],
3807 }
3808 `)
3809 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
3810 checkIncludeDirs(t, ctx, foo,
3811 expectedIncludeDirs(`
3812 foo/standard
3813 .intermediates/genrule_foo/gen/generated_headers
3814 `),
3815 expectedSystemIncludeDirs(`foo/system`),
3816 expectedGeneratedHeaders(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
3817 expectedOrderOnlyDeps(`.intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h`),
3818 )
3819
3820 bar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module()
3821 checkIncludeDirs(t, ctx, bar,
3822 expectedIncludeDirs(`
3823 bar/standard
3824 foo/standard
3825 .intermediates/genrule_foo/gen/generated_headers
3826 .intermediates/genrule_bar/gen/generated_headers
3827 `),
3828 expectedSystemIncludeDirs(`
3829 bar/system
3830 foo/system
3831 `),
3832 expectedGeneratedHeaders(`
3833 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
3834 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
3835 `),
3836 expectedOrderOnlyDeps(`
3837 .intermediates/genrule_foo/gen/generated_headers/foo/generated_header.h
3838 .intermediates/genrule_bar/gen/generated_headers/bar/generated_header.h
3839 `),
3840 )
3841 })
3842
Paul Duffin3cb603e2021-02-19 13:57:10 +00003843 t.Run("ensure only aidl headers are exported", func(t *testing.T) {
3844 ctx := testCc(t, genRuleModules+`
3845 cc_library_shared {
3846 name: "libfoo",
3847 srcs: [
3848 "foo.c",
3849 "b.aidl",
3850 "a.proto",
3851 ],
3852 aidl: {
3853 export_aidl_headers: true,
3854 }
3855 }
3856 `)
3857 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
3858 checkIncludeDirs(t, ctx, foo,
3859 expectedIncludeDirs(`
3860 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
3861 `),
3862 expectedSystemIncludeDirs(``),
3863 expectedGeneratedHeaders(`
3864 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
3865 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
3866 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00003867 `),
3868 expectedOrderOnlyDeps(`
3869 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
3870 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
3871 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00003872 `),
3873 )
3874 })
3875
Paul Duffin3cb603e2021-02-19 13:57:10 +00003876 t.Run("ensure only proto headers are exported", func(t *testing.T) {
3877 ctx := testCc(t, genRuleModules+`
3878 cc_library_shared {
3879 name: "libfoo",
3880 srcs: [
3881 "foo.c",
3882 "b.aidl",
3883 "a.proto",
3884 ],
3885 proto: {
3886 export_proto_headers: true,
3887 }
3888 }
3889 `)
3890 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
3891 checkIncludeDirs(t, ctx, foo,
3892 expectedIncludeDirs(`
3893 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto
3894 `),
3895 expectedSystemIncludeDirs(``),
3896 expectedGeneratedHeaders(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00003897 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
3898 `),
3899 expectedOrderOnlyDeps(`
Paul Duffin3cb603e2021-02-19 13:57:10 +00003900 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/proto/a.pb.h
3901 `),
3902 )
3903 })
3904
Paul Duffin33056e82021-02-19 13:49:08 +00003905 t.Run("ensure only sysprop headers are exported", func(t *testing.T) {
Paul Duffin3cb603e2021-02-19 13:57:10 +00003906 ctx := testCc(t, genRuleModules+`
3907 cc_library_shared {
3908 name: "libfoo",
3909 srcs: [
3910 "foo.c",
3911 "a.sysprop",
3912 "b.aidl",
3913 "a.proto",
3914 ],
3915 }
3916 `)
3917 foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
3918 checkIncludeDirs(t, ctx, foo,
3919 expectedIncludeDirs(`
3920 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include
3921 `),
3922 expectedSystemIncludeDirs(``),
3923 expectedGeneratedHeaders(`
3924 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00003925 `),
3926 expectedOrderOnlyDeps(`
3927 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/include/a.sysprop.h
3928 .intermediates/libfoo/android_arm64_armv8-a_shared/gen/sysprop/public/include/a.sysprop.h
Paul Duffin3cb603e2021-02-19 13:57:10 +00003929 `),
3930 )
3931 })
3932}
Colin Crossae628182021-06-14 16:52:28 -07003933
3934func TestIncludeDirectoryOrdering(t *testing.T) {
Liz Kammer08572c62021-09-30 10:11:04 -04003935 baseExpectedFlags := []string{
3936 "${config.ArmThumbCflags}",
3937 "${config.ArmCflags}",
3938 "${config.CommonGlobalCflags}",
3939 "${config.DeviceGlobalCflags}",
3940 "${config.ExternalCflags}",
3941 "${config.ArmToolchainCflags}",
3942 "${config.ArmArmv7ANeonCflags}",
3943 "${config.ArmGenericCflags}",
3944 "-target",
3945 "armv7a-linux-androideabi20",
Liz Kammer08572c62021-09-30 10:11:04 -04003946 }
3947
3948 expectedIncludes := []string{
3949 "external/foo/android_arm_export_include_dirs",
3950 "external/foo/lib32_export_include_dirs",
3951 "external/foo/arm_export_include_dirs",
3952 "external/foo/android_export_include_dirs",
3953 "external/foo/linux_export_include_dirs",
3954 "external/foo/export_include_dirs",
3955 "external/foo/android_arm_local_include_dirs",
3956 "external/foo/lib32_local_include_dirs",
3957 "external/foo/arm_local_include_dirs",
3958 "external/foo/android_local_include_dirs",
3959 "external/foo/linux_local_include_dirs",
3960 "external/foo/local_include_dirs",
3961 "external/foo",
3962 "external/foo/libheader1",
3963 "external/foo/libheader2",
3964 "external/foo/libwhole1",
3965 "external/foo/libwhole2",
3966 "external/foo/libstatic1",
3967 "external/foo/libstatic2",
3968 "external/foo/libshared1",
3969 "external/foo/libshared2",
3970 "external/foo/liblinux",
3971 "external/foo/libandroid",
3972 "external/foo/libarm",
3973 "external/foo/lib32",
3974 "external/foo/libandroid_arm",
3975 "defaults/cc/common/ndk_libc++_shared",
3976 "defaults/cc/common/ndk_libandroid_support",
3977 }
3978
3979 conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"}
3980 cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"}
3981
Liz Kammer9dc65772021-12-16 11:38:50 -05003982 cflags := []string{"-Wall", "-Werror", "-std=candcpp"}
3983 cstd := []string{"-std=gnu99", "-std=conly"}
3984 cppstd := []string{"-std=gnu++17", "-std=cpp", "-fno-rtti"}
Liz Kammer08572c62021-09-30 10:11:04 -04003985
3986 lastIncludes := []string{
3987 "out/soong/ndk/sysroot/usr/include",
3988 "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
3989 }
3990
3991 combineSlices := func(slices ...[]string) []string {
3992 var ret []string
3993 for _, s := range slices {
3994 ret = append(ret, s...)
3995 }
3996 return ret
3997 }
3998
3999 testCases := []struct {
4000 name string
4001 src string
4002 expected []string
4003 }{
4004 {
4005 name: "c",
4006 src: "foo.c",
Stephen Hinese24303f2021-12-14 15:07:08 -08004007 expected: combineSlices(baseExpectedFlags, conly, expectedIncludes, cflags, cstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}),
Liz Kammer08572c62021-09-30 10:11:04 -04004008 },
4009 {
4010 name: "cc",
4011 src: "foo.cc",
Stephen Hinese24303f2021-12-14 15:07:08 -08004012 expected: combineSlices(baseExpectedFlags, cppOnly, expectedIncludes, cflags, cppstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}", "${config.NoOverrideExternalGlobalCflags}"}),
Liz Kammer08572c62021-09-30 10:11:04 -04004013 },
4014 {
4015 name: "assemble",
4016 src: "foo.s",
4017 expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__"}, expectedIncludes, lastIncludes),
4018 },
4019 }
4020
4021 for _, tc := range testCases {
4022 t.Run(tc.name, func(t *testing.T) {
4023 bp := fmt.Sprintf(`
Colin Crossae628182021-06-14 16:52:28 -07004024 cc_library {
4025 name: "libfoo",
Liz Kammer08572c62021-09-30 10:11:04 -04004026 srcs: ["%s"],
Liz Kammer9dc65772021-12-16 11:38:50 -05004027 cflags: ["-std=candcpp"],
4028 conlyflags: ["-std=conly"],
4029 cppflags: ["-std=cpp"],
Colin Crossae628182021-06-14 16:52:28 -07004030 local_include_dirs: ["local_include_dirs"],
4031 export_include_dirs: ["export_include_dirs"],
4032 export_system_include_dirs: ["export_system_include_dirs"],
4033 static_libs: ["libstatic1", "libstatic2"],
4034 whole_static_libs: ["libwhole1", "libwhole2"],
4035 shared_libs: ["libshared1", "libshared2"],
4036 header_libs: ["libheader1", "libheader2"],
4037 target: {
4038 android: {
4039 shared_libs: ["libandroid"],
4040 local_include_dirs: ["android_local_include_dirs"],
4041 export_include_dirs: ["android_export_include_dirs"],
4042 },
4043 android_arm: {
4044 shared_libs: ["libandroid_arm"],
4045 local_include_dirs: ["android_arm_local_include_dirs"],
4046 export_include_dirs: ["android_arm_export_include_dirs"],
4047 },
4048 linux: {
4049 shared_libs: ["liblinux"],
4050 local_include_dirs: ["linux_local_include_dirs"],
4051 export_include_dirs: ["linux_export_include_dirs"],
4052 },
4053 },
4054 multilib: {
4055 lib32: {
4056 shared_libs: ["lib32"],
4057 local_include_dirs: ["lib32_local_include_dirs"],
4058 export_include_dirs: ["lib32_export_include_dirs"],
4059 },
4060 },
4061 arch: {
4062 arm: {
4063 shared_libs: ["libarm"],
4064 local_include_dirs: ["arm_local_include_dirs"],
4065 export_include_dirs: ["arm_export_include_dirs"],
4066 },
4067 },
4068 stl: "libc++",
4069 sdk_version: "20",
4070 }
4071
4072 cc_library_headers {
4073 name: "libheader1",
4074 export_include_dirs: ["libheader1"],
4075 sdk_version: "20",
4076 stl: "none",
4077 }
4078
4079 cc_library_headers {
4080 name: "libheader2",
4081 export_include_dirs: ["libheader2"],
4082 sdk_version: "20",
4083 stl: "none",
4084 }
Liz Kammer08572c62021-09-30 10:11:04 -04004085 `, tc.src)
Colin Crossae628182021-06-14 16:52:28 -07004086
Liz Kammer08572c62021-09-30 10:11:04 -04004087 libs := []string{
4088 "libstatic1",
4089 "libstatic2",
4090 "libwhole1",
4091 "libwhole2",
4092 "libshared1",
4093 "libshared2",
4094 "libandroid",
4095 "libandroid_arm",
4096 "liblinux",
4097 "lib32",
4098 "libarm",
4099 }
Colin Crossae628182021-06-14 16:52:28 -07004100
Liz Kammer08572c62021-09-30 10:11:04 -04004101 for _, lib := range libs {
4102 bp += fmt.Sprintf(`
Colin Crossae628182021-06-14 16:52:28 -07004103 cc_library {
4104 name: "%s",
4105 export_include_dirs: ["%s"],
4106 sdk_version: "20",
4107 stl: "none",
4108 }
4109 `, lib, lib)
Liz Kammer08572c62021-09-30 10:11:04 -04004110 }
4111
4112 ctx := android.GroupFixturePreparers(
4113 PrepareForIntegrationTestWithCc,
4114 android.FixtureAddTextFile("external/foo/Android.bp", bp),
4115 ).RunTest(t)
4116 // Use the arm variant instead of the arm64 variant so that it gets headers from
4117 // ndk_libandroid_support to test LateStaticLibs.
4118 cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
4119
4120 var includes []string
4121 flags := strings.Split(cflags, " ")
4122 for _, flag := range flags {
4123 if strings.HasPrefix(flag, "-I") {
4124 includes = append(includes, strings.TrimPrefix(flag, "-I"))
4125 } else if flag == "-isystem" {
4126 // skip isystem, include next
4127 } else if len(flag) > 0 {
4128 includes = append(includes, flag)
4129 }
4130 }
4131
4132 android.AssertArrayString(t, "includes", tc.expected, includes)
4133 })
Colin Crossae628182021-06-14 16:52:28 -07004134 }
4135
Colin Crossae628182021-06-14 16:52:28 -07004136}