blob: 9639ab98f17d0be101fad47e2e4ab79cd311977f [file] [log] [blame]
Jingwen Chen537242c2022-08-24 11:53:27 +00001// Copyright 2022 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
15package bp2build
16
17import (
18 "fmt"
19 "testing"
20
21 "android/soong/android"
22 "android/soong/cc"
23 "android/soong/genrule"
24)
25
26type ccTestBp2buildTestCase struct {
27 description string
28 blueprint string
Kevin Dagostino32edd1a2022-12-04 11:16:42 +000029 filesystem map[string]string
Jingwen Chen537242c2022-08-24 11:53:27 +000030 targets []testBazelTarget
31}
32
33func registerCcTestModuleTypes(ctx android.RegistrationContext) {
34 cc.RegisterCCBuildComponents(ctx)
35 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
36 ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
37 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
38 ctx.RegisterModuleType("cc_test_library", cc.TestLibraryFactory)
39 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
40}
41
42func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) {
43 t.Helper()
44 moduleTypeUnderTest := "cc_test"
Jingwen Chen537242c2022-08-24 11:53:27 +000045 description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
46 t.Run(description, func(t *testing.T) {
47 t.Helper()
48 RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{
49 ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported),
Kevin Dagostino32edd1a2022-12-04 11:16:42 +000050 Filesystem: testCase.filesystem,
Jingwen Chen537242c2022-08-24 11:53:27 +000051 ModuleTypeUnderTest: moduleTypeUnderTest,
52 ModuleTypeUnderTestFactory: cc.TestFactory,
53 Description: description,
54 Blueprint: testCase.blueprint,
55 })
56 })
57}
58
59func TestBasicCcTest(t *testing.T) {
60 runCcTestTestCase(t, ccTestBp2buildTestCase{
61 description: "basic cc_test with commonly used attributes",
62 blueprint: `
63cc_test {
64 name: "mytest",
65 host_supported: true,
66 srcs: ["test.cpp"],
67 target: {
68 android: {
69 srcs: ["android.cpp"],
70 shared_libs: ["foolib"],
71 },
72 linux: {
73 srcs: ["linux.cpp"],
74 },
75 host: {
76 static_libs: ["hostlib"],
77 },
78 },
Liz Kammerefc51d92023-04-21 15:11:25 -040079 static_libs: ["cc_test_lib1"],
80 shared_libs: ["cc_test_lib2"],
Jingwen Chen537242c2022-08-24 11:53:27 +000081 data: [":data_mod", "file.txt"],
82 data_bins: [":cc_bin"],
83 data_libs: [":cc_lib"],
84 cflags: ["-Wall"],
85}
Liz Kammerefc51d92023-04-21 15:11:25 -040086
87cc_test_library {
88 name: "cc_test_lib1",
89 host_supported: true,
90 include_build_directory: false,
91}
Jingwen Chen537242c2022-08-24 11:53:27 +000092` + simpleModuleDoNotConvertBp2build("cc_library", "foolib") +
93 simpleModuleDoNotConvertBp2build("cc_library_static", "hostlib") +
94 simpleModuleDoNotConvertBp2build("genrule", "data_mod") +
95 simpleModuleDoNotConvertBp2build("cc_binary", "cc_bin") +
Liz Kammerefc51d92023-04-21 15:11:25 -040096 simpleModuleDoNotConvertBp2build("cc_library", "cc_lib") +
Spandan Das651203d2023-07-21 22:55:32 +000097 simpleModuleDoNotConvertBp2build("cc_test_library", "cc_test_lib2") +
98 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
99 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
Jingwen Chen537242c2022-08-24 11:53:27 +0000100 targets: []testBazelTarget{
Liz Kammerefc51d92023-04-21 15:11:25 -0400101 {"cc_library_shared", "cc_test_lib1", AttrNameToString{}},
102 {"cc_library_static", "cc_test_lib1_bp2build_cc_library_static", AttrNameToString{}},
Jingwen Chen537242c2022-08-24 11:53:27 +0000103 {"cc_test", "mytest", AttrNameToString{
104 "copts": `["-Wall"]`,
105 "data": `[
106 ":data_mod",
107 "file.txt",
108 ":cc_bin",
109 ":cc_lib",
110 ]`,
Spandan Das651203d2023-07-21 22:55:32 +0000111 "deps": `[
112 ":cc_test_lib1_bp2build_cc_library_static",
113 ":libgtest_main",
114 ":libgtest",
115 ] + select({
Jingwen Chen537242c2022-08-24 11:53:27 +0000116 "//build/bazel/platforms/os:darwin": [":hostlib"],
Jingwen Chen537242c2022-08-24 11:53:27 +0000117 "//build/bazel/platforms/os:linux_bionic": [":hostlib"],
Colin Cross133782e2022-12-20 15:29:31 -0800118 "//build/bazel/platforms/os:linux_glibc": [":hostlib"],
Jingwen Chen537242c2022-08-24 11:53:27 +0000119 "//build/bazel/platforms/os:linux_musl": [":hostlib"],
120 "//build/bazel/platforms/os:windows": [":hostlib"],
121 "//conditions:default": [],
122 })`,
Jingwen Chen537242c2022-08-24 11:53:27 +0000123 "local_includes": `["."]`,
Liz Kammerefc51d92023-04-21 15:11:25 -0400124 "dynamic_deps": `[":cc_test_lib2"] + select({
Jingwen Chen537242c2022-08-24 11:53:27 +0000125 "//build/bazel/platforms/os:android": [":foolib"],
126 "//conditions:default": [],
127 })`,
128 "srcs": `["test.cpp"] + select({
129 "//build/bazel/platforms/os:android": [
130 "linux.cpp",
131 "android.cpp",
132 ],
Jingwen Chen537242c2022-08-24 11:53:27 +0000133 "//build/bazel/platforms/os:linux_bionic": ["linux.cpp"],
Colin Cross133782e2022-12-20 15:29:31 -0800134 "//build/bazel/platforms/os:linux_glibc": ["linux.cpp"],
Jingwen Chen537242c2022-08-24 11:53:27 +0000135 "//build/bazel/platforms/os:linux_musl": ["linux.cpp"],
136 "//conditions:default": [],
137 })`,
yikefdca7fe2023-08-17 01:03:37 +0000138 "runs_on": `[
139 "host_without_device",
140 "device",
141 ]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700142 "features": `select({
143 "//build/bazel/platforms/os_arch:android_arm64": [
144 "memtag_heap",
145 "diag_memtag_heap",
146 ],
147 "//conditions:default": [],
148 })`,
Jingwen Chen537242c2022-08-24 11:53:27 +0000149 },
150 },
151 },
152 })
153}
154
155func TestBasicCcTestGtestIsolatedDisabled(t *testing.T) {
156 runCcTestTestCase(t, ccTestBp2buildTestCase{
157 description: "cc test with disabled gtest and isolated props",
158 blueprint: `
159cc_test {
160 name: "mytest",
161 host_supported: true,
162 srcs: ["test.cpp"],
163 gtest: false,
164 isolated: false,
165}
166`,
167 targets: []testBazelTarget{
168 {"cc_test", "mytest", AttrNameToString{
169 "gtest": "False",
Jingwen Chen537242c2022-08-24 11:53:27 +0000170 "local_includes": `["."]`,
171 "srcs": `["test.cpp"]`,
yikefdca7fe2023-08-17 01:03:37 +0000172 "runs_on": `[
173 "host_without_device",
174 "device",
175 ]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700176 "features": `select({
177 "//build/bazel/platforms/os_arch:android_arm64": [
178 "memtag_heap",
179 "diag_memtag_heap",
180 ],
181 "//conditions:default": [],
182 })`,
Jingwen Chen537242c2022-08-24 11:53:27 +0000183 },
184 },
185 },
186 })
187}
Jingwen Chenfbff97a2022-09-16 02:32:03 +0000188
189func TestCcTest_TestOptions_Tags(t *testing.T) {
190 runCcTestTestCase(t, ccTestBp2buildTestCase{
191 description: "cc test with test_options.tags converted to tags",
192 blueprint: `
193cc_test {
194 name: "mytest",
195 host_supported: true,
196 srcs: ["test.cpp"],
197 test_options: { tags: ["no-remote"] },
198}
Spandan Das651203d2023-07-21 22:55:32 +0000199` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
200 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
Jingwen Chenfbff97a2022-09-16 02:32:03 +0000201 targets: []testBazelTarget{
202 {"cc_test", "mytest", AttrNameToString{
203 "tags": `["no-remote"]`,
204 "local_includes": `["."]`,
205 "srcs": `["test.cpp"]`,
Spandan Das651203d2023-07-21 22:55:32 +0000206 "deps": `[
207 ":libgtest_main",
208 ":libgtest",
209 ]`,
yikefdca7fe2023-08-17 01:03:37 +0000210 "runs_on": `[
211 "host_without_device",
212 "device",
213 ]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700214 "features": `select({
215 "//build/bazel/platforms/os_arch:android_arm64": [
216 "memtag_heap",
217 "diag_memtag_heap",
218 ],
219 "//conditions:default": [],
220 })`,
Jingwen Chenfbff97a2022-09-16 02:32:03 +0000221 },
222 },
223 },
224 })
225}
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000226
227func TestCcTest_TestConfig(t *testing.T) {
228 runCcTestTestCase(t, ccTestBp2buildTestCase{
229 description: "cc test that sets a test_config",
230 filesystem: map[string]string{
231 "test_config.xml": "",
232 },
233 blueprint: `
234cc_test {
235 name: "mytest",
236 srcs: ["test.cpp"],
237 test_config: "test_config.xml",
238}
Spandan Das651203d2023-07-21 22:55:32 +0000239` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
240 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000241 targets: []testBazelTarget{
242 {"cc_test", "mytest", AttrNameToString{
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000243 "local_includes": `["."]`,
244 "srcs": `["test.cpp"]`,
245 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
246 "test_config": `"test_config.xml"`,
Spandan Das651203d2023-07-21 22:55:32 +0000247 "deps": `[
248 ":libgtest_main",
249 ":libgtest",
250 ]`,
yikefdca7fe2023-08-17 01:03:37 +0000251 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700252 "features": `select({
253 "//build/bazel/platforms/os_arch:android_arm64": [
254 "memtag_heap",
255 "diag_memtag_heap",
256 ],
257 "//conditions:default": [],
258 })`,
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000259 },
260 },
261 },
262 })
263}
264
265func TestCcTest_TestConfigAndroidTestXML(t *testing.T) {
266 runCcTestTestCase(t, ccTestBp2buildTestCase{
267 description: "cc test that defaults to test config AndroidTest.xml",
268 filesystem: map[string]string{
Yu Liud136a6a2023-08-21 21:23:04 +0000269 "AndroidTest.xml": "",
270 "DynamicConfig.xml": "",
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000271 },
272 blueprint: `
273cc_test {
274 name: "mytest",
275 srcs: ["test.cpp"],
276}
Spandan Das651203d2023-07-21 22:55:32 +0000277` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
278 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000279 targets: []testBazelTarget{
280 {"cc_test", "mytest", AttrNameToString{
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000281 "local_includes": `["."]`,
282 "srcs": `["test.cpp"]`,
283 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
284 "test_config": `"AndroidTest.xml"`,
Yu Liud136a6a2023-08-21 21:23:04 +0000285 "dynamic_config": `"DynamicConfig.xml"`,
Spandan Das651203d2023-07-21 22:55:32 +0000286 "deps": `[
287 ":libgtest_main",
288 ":libgtest",
289 ]`,
yikefdca7fe2023-08-17 01:03:37 +0000290 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700291 "features": `select({
292 "//build/bazel/platforms/os_arch:android_arm64": [
293 "memtag_heap",
294 "diag_memtag_heap",
295 ],
296 "//conditions:default": [],
297 })`,
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000298 },
299 },
300 },
301 })
302}
303
304func TestCcTest_TestConfigTemplateOptions(t *testing.T) {
305 runCcTestTestCase(t, ccTestBp2buildTestCase{
306 description: "cc test that sets test config template attributes",
307 filesystem: map[string]string{
308 "test_config_template.xml": "",
309 },
310 blueprint: `
311cc_test {
312 name: "mytest",
313 srcs: ["test.cpp"],
314 test_config_template: "test_config_template.xml",
315 auto_gen_config: true,
Spandan Dasf5a86552023-07-22 03:16:53 +0000316 isolated: true,
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000317}
Spandan Dasd1cd3512023-07-22 02:19:42 +0000318` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
319 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000320 targets: []testBazelTarget{
321 {"cc_test", "mytest", AttrNameToString{
322 "auto_generate_test_config": "True",
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000323 "local_includes": `["."]`,
324 "srcs": `["test.cpp"]`,
325 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
326 "template_configs": `[
327 "'<target_preparer class=\"com.android.tradefed.targetprep.RootTargetPreparer\">\\n <option name=\"force-root\" value=\"false\" />\\n </target_preparer>'",
328 "'<option name=\"not-shardable\" value=\"true\" />'",
329 ]`,
330 "template_install_base": `"/data/local/tmp"`,
331 "template_test_config": `"test_config_template.xml"`,
Spandan Dasd1cd3512023-07-22 02:19:42 +0000332 "deps": `[":libgtest_isolated_main"]`,
333 "dynamic_deps": `[":liblog"]`,
yikefdca7fe2023-08-17 01:03:37 +0000334 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700335 "features": `select({
336 "//build/bazel/platforms/os_arch:android_arm64": [
337 "memtag_heap",
338 "diag_memtag_heap",
339 ],
340 "//conditions:default": [],
341 })`,
Kevin Dagostino32edd1a2022-12-04 11:16:42 +0000342 },
343 },
344 },
345 })
346}
Spandan Das651203d2023-07-21 22:55:32 +0000347
348func TestCcTest_WithExplicitGTestDepInAndroidBp(t *testing.T) {
349 runCcTestTestCase(t, ccTestBp2buildTestCase{
350 description: "cc test that lists libgtest in Android.bp should not have dups of libgtest in BUILD file",
351 blueprint: `
352cc_test {
353 name: "mytest",
354 srcs: ["test.cpp"],
355 static_libs: ["libgtest"],
356}
357` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
358 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
359 targets: []testBazelTarget{
360 {"cc_test", "mytest", AttrNameToString{
Spandan Das651203d2023-07-21 22:55:32 +0000361 "local_includes": `["."]`,
362 "srcs": `["test.cpp"]`,
363 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
364 "deps": `[
365 ":libgtest",
366 ":libgtest_main",
367 ]`,
yikefdca7fe2023-08-17 01:03:37 +0000368 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700369 "features": `select({
370 "//build/bazel/platforms/os_arch:android_arm64": [
371 "memtag_heap",
372 "diag_memtag_heap",
373 ],
374 "//conditions:default": [],
375 })`,
Spandan Das651203d2023-07-21 22:55:32 +0000376 },
377 },
378 },
379 })
380
381}
Spandan Dasd1cd3512023-07-22 02:19:42 +0000382
383func TestCcTest_WithIsolatedTurnedOn(t *testing.T) {
384 runCcTestTestCase(t, ccTestBp2buildTestCase{
385 description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main",
386 blueprint: `
387cc_test {
388 name: "mytest",
389 srcs: ["test.cpp"],
390 isolated: true,
391}
392` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
393 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
394 targets: []testBazelTarget{
395 {"cc_test", "mytest", AttrNameToString{
Spandan Dasd1cd3512023-07-22 02:19:42 +0000396 "local_includes": `["."]`,
397 "srcs": `["test.cpp"]`,
398 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
399 "deps": `[":libgtest_isolated_main"]`,
400 "dynamic_deps": `[":liblog"]`,
yikefdca7fe2023-08-17 01:03:37 +0000401 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700402 "features": `select({
403 "//build/bazel/platforms/os_arch:android_arm64": [
404 "memtag_heap",
405 "diag_memtag_heap",
406 ],
407 "//conditions:default": [],
408 })`,
Spandan Dasd1cd3512023-07-22 02:19:42 +0000409 },
410 },
411 },
412 })
413
414}
Spandan Dase50fd112023-07-26 17:35:20 +0000415
416func TestCcTest_GtestExplicitlySpecifiedInAndroidBp(t *testing.T) {
417 runCcTestTestCase(t, ccTestBp2buildTestCase{
418 description: "If `gtest` is explicit in Android.bp, it should be explicit in BUILD files as well",
419 blueprint: `
420cc_test {
421 name: "mytest_with_gtest",
422 gtest: true,
423}
424cc_test {
425 name: "mytest_with_no_gtest",
426 gtest: false,
427}
428` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
429 simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
430 targets: []testBazelTarget{
431 {"cc_test", "mytest_with_gtest", AttrNameToString{
432 "local_includes": `["."]`,
433 "deps": `[
434 ":libgtest_main",
435 ":libgtest",
436 ]`,
437 "gtest": "True",
438 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
yikefdca7fe2023-08-17 01:03:37 +0000439 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700440 "features": `select({
441 "//build/bazel/platforms/os_arch:android_arm64": [
442 "memtag_heap",
443 "diag_memtag_heap",
444 ],
445 "//conditions:default": [],
446 })`,
Spandan Dase50fd112023-07-26 17:35:20 +0000447 },
448 },
449 {"cc_test", "mytest_with_no_gtest", AttrNameToString{
450 "local_includes": `["."]`,
451 "gtest": "False",
452 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
yikefdca7fe2023-08-17 01:03:37 +0000453 "runs_on": `["device"]`,
Yu Liu7ece4aa2023-08-25 16:56:33 -0700454 "features": `select({
455 "//build/bazel/platforms/os_arch:android_arm64": [
456 "memtag_heap",
457 "diag_memtag_heap",
458 ],
459 "//conditions:default": [],
460 })`,
461 },
462 },
463 },
464 })
465}
466
467func TestCcTest_DisableMemtagHeap(t *testing.T) {
468 runCcTestTestCase(t, ccTestBp2buildTestCase{
469 description: "cc test that disable memtag_heap",
470 blueprint: `
471cc_test {
472 name: "mytest",
473 srcs: ["test.cpp"],
474 isolated: true,
475 sanitize: {
476 cfi: true,
477 memtag_heap: false,
478 },
479}
480` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
481 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
482 targets: []testBazelTarget{
483 {"cc_test", "mytest", AttrNameToString{
484 "local_includes": `["."]`,
485 "srcs": `["test.cpp"]`,
486 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
487 "deps": `[":libgtest_isolated_main"]`,
488 "dynamic_deps": `[":liblog"]`,
489 "runs_on": `["device"]`,
490 "features": `["android_cfi"] + select({
491 "//build/bazel/platforms/os_arch:android_arm64": ["-memtag_heap"],
492 "//conditions:default": [],
493 })`,
494 },
495 },
496 },
497 })
498}
499
500func TestCcTest_RespectArm64MemtagHeap(t *testing.T) {
501 runCcTestTestCase(t, ccTestBp2buildTestCase{
502 description: "cc test that disable memtag_heap",
503 blueprint: `
504cc_test {
505 name: "mytest",
506 srcs: ["test.cpp"],
507 isolated: true,
508 target: {
509 android_arm64: {
510 sanitize: {
511 memtag_heap: false,
512 }
513 }
514 },
515}
516` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
517 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
518 targets: []testBazelTarget{
519 {"cc_test", "mytest", AttrNameToString{
520 "local_includes": `["."]`,
521 "srcs": `["test.cpp"]`,
522 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
523 "deps": `[":libgtest_isolated_main"]`,
524 "dynamic_deps": `[":liblog"]`,
525 "runs_on": `["device"]`,
526 "features": `select({
527 "//build/bazel/platforms/os_arch:android_arm64": ["-memtag_heap"],
528 "//conditions:default": [],
529 })`,
530 },
531 },
532 },
533 })
534}
535
536func TestCcTest_IgnoreNoneArm64MemtagHeap(t *testing.T) {
537 runCcTestTestCase(t, ccTestBp2buildTestCase{
538 description: "cc test that disable memtag_heap",
539 blueprint: `
540cc_test {
541 name: "mytest",
542 srcs: ["test.cpp"],
543 isolated: true,
544 arch: {
545 x86: {
546 sanitize: {
547 memtag_heap: false,
548 }
549 }
550 },
551}
552` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
553 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
554 targets: []testBazelTarget{
555 {"cc_test", "mytest", AttrNameToString{
556 "local_includes": `["."]`,
557 "srcs": `["test.cpp"]`,
558 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
559 "deps": `[":libgtest_isolated_main"]`,
560 "dynamic_deps": `[":liblog"]`,
561 "runs_on": `["device"]`,
562 "features": `select({
563 "//build/bazel/platforms/os_arch:android_arm64": [
564 "memtag_heap",
565 "diag_memtag_heap",
566 ],
567 "//conditions:default": [],
568 })`,
569 },
570 },
571 },
572 })
573}
574
575func TestCcTest_Arm64MemtagHeapOverrideNoConfigOne(t *testing.T) {
576 runCcTestTestCase(t, ccTestBp2buildTestCase{
577 description: "cc test that disable memtag_heap",
578 blueprint: `
579cc_test {
580 name: "mytest",
581 srcs: ["test.cpp"],
582 isolated: true,
583 sanitize: {
584 memtag_heap: true,
585 },
586 target: {
587 android_arm64: {
588 sanitize: {
589 memtag_heap: false,
590 diag: {
591 memtag_heap: false,
592 },
593 }
594 }
595 },
596}
597` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") +
598 simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
599 targets: []testBazelTarget{
600 {"cc_test", "mytest", AttrNameToString{
601 "local_includes": `["."]`,
602 "srcs": `["test.cpp"]`,
603 "target_compatible_with": `["//build/bazel/platforms/os:android"]`,
604 "deps": `[":libgtest_isolated_main"]`,
605 "dynamic_deps": `[":liblog"]`,
606 "runs_on": `["device"]`,
607 "features": `select({
608 "//build/bazel/platforms/os_arch:android_arm64": [
609 "-memtag_heap",
610 "-diag_memtag_heap",
611 ],
612 "//conditions:default": [],
613 })`,
Spandan Dase50fd112023-07-26 17:35:20 +0000614 },
615 },
616 },
617 })
618}