Skip to content

Commit c4286ea

Browse files
Add py_unittest_qnx_test.bzl macro for QNX test suites
1 parent d2a65da commit c4286ea

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

bazel/unit_tests.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
load("@rules_cc//cc:defs.bzl", "cc_test")
1515
load("@score_baselibs//third_party/itf:py_unittest_qnx_test.bzl", "py_unittest_qnx_test")
1616

17-
def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility = None, test_suites_from_sub_packages = None, excluded_tests_filter = None):
17+
def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility = None, test_suites_from_sub_packages = None, excluded_tests_filter = None, cc_test_qnx = None):
1818
"""
1919
This Bazel macro allows to add unit tests on qnx and host with a single macro.
2020
@@ -31,6 +31,8 @@ def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility
3131
FooTest.Test1 - do not run Test1 from test suite FooTest
3232
FooTest.* - do not run any test from test suite FooTest
3333
*FooTest.* - runs all non FooTest tests.
34+
cc_test_qnx: Optional macro to wrap each cc_test for QNX execution.
35+
The calling project provides its own cc_test_qnx implementation.
3436
3537
Returns:
3638
Test suites for host and QNX
@@ -54,6 +56,7 @@ def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility
5456
testonly = True,
5557
test_cases = cc_unit_tests,
5658
excluded_tests_filter = excluded_tests_filter,
59+
cc_test_qnx = cc_test_qnx,
5760
)
5861

5962
_qnx_test_suites_from_sub_packages = [test_suite + "_qnx" for test_suite in test_suites_from_sub_packages] if test_suites_from_sub_packages else []

third_party/itf/py_unittest_qnx_test.bzl

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,47 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313

14-
def py_unittest_qnx_test(**kwargs):
15-
pass
14+
"""Convenience macro for creating QNX test suites."""
15+
16+
def py_unittest_qnx_test(
17+
name,
18+
test_cases = [],
19+
test_suites = [],
20+
visibility = None,
21+
tags = [],
22+
excluded_tests_filter = None,
23+
cc_test_qnx = None,
24+
**kwargs):
25+
"""Creates a test suite of QNX tests from cc_test targets.
26+
27+
Args:
28+
name: Name of the test_suite to create
29+
test_cases: List of cc_test targets to wrap with cc_test_qnx
30+
test_suites: Additional test_suite targets to include
31+
visibility: Visibility for the generated test_suite
32+
tags: Tags to apply to the test_suite
33+
cc_test_qnx: Optional macro to wrap each cc_test target for QNX execution.
34+
The calling project provides its own cc_test_qnx implementation.
35+
If None, test_cases are ignored and only test_suites are collected.
36+
**kwargs: Additional arguments passed to test_suite
37+
"""
38+
qnx_test_targets = []
39+
40+
for test_case in test_cases:
41+
if cc_test_qnx != None:
42+
test_name = test_case.split(":")[-1] if ":" in test_case else test_case
43+
qnx_target_name = test_name + "_qnx"
44+
45+
cc_test_qnx(
46+
name = qnx_target_name,
47+
cc_test = test_case,
48+
)
49+
50+
qnx_test_targets.append(":" + qnx_target_name)
51+
52+
native.test_suite(
53+
name = name,
54+
tests = qnx_test_targets + test_suites,
55+
visibility = visibility,
56+
tags = tags,
57+
)

0 commit comments

Comments
 (0)