Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bazel/unit_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@score_baselibs//third_party/itf:py_unittest_qnx_test.bzl", "py_unittest_qnx_test")

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):
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):
"""
This Bazel macro allows to add unit tests on qnx and host with a single macro.

Expand All @@ -31,6 +31,8 @@ def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility
FooTest.Test1 - do not run Test1 from test suite FooTest
FooTest.* - do not run any test from test suite FooTest
*FooTest.* - runs all non FooTest tests.
cc_test_qnx: Optional macro to wrap each cc_test for QNX execution.
The calling project provides its own cc_test_qnx implementation.

Returns:
Test suites for host and QNX
Expand All @@ -54,6 +56,7 @@ def cc_unit_test_suites_for_host_and_qnx(name, cc_unit_tests = None, visibility
testonly = True,
test_cases = cc_unit_tests,
excluded_tests_filter = excluded_tests_filter,
cc_test_qnx = cc_test_qnx,
)

_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 []
Expand Down
46 changes: 44 additions & 2 deletions third_party/itf/py_unittest_qnx_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,47 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

def py_unittest_qnx_test(**kwargs):
pass
"""Convenience macro for creating QNX test suites."""

def py_unittest_qnx_test(
name,
test_cases = [],
test_suites = [],
visibility = None,
tags = [],
excluded_tests_filter = None,
cc_test_qnx = None,
**kwargs):
"""Creates a test suite of QNX tests from cc_test targets.

Args:
name: Name of the test_suite to create
test_cases: List of cc_test targets to wrap with cc_test_qnx
test_suites: Additional test_suite targets to include
visibility: Visibility for the generated test_suite
tags: Tags to apply to the test_suite
cc_test_qnx: Optional macro to wrap each cc_test target for QNX execution.
The calling project provides its own cc_test_qnx implementation.
If None, test_cases are ignored and only test_suites are collected.
**kwargs: Additional arguments passed to test_suite
"""
qnx_test_targets = []

for test_case in test_cases:
if cc_test_qnx != None:
test_name = test_case.split(":")[-1] if ":" in test_case else test_case
qnx_target_name = test_name + "_qnx"

cc_test_qnx(
name = qnx_target_name,
cc_test = test_case,
)

qnx_test_targets.append(":" + qnx_target_name)

native.test_suite(
name = name,
tests = qnx_test_targets + test_suites,
visibility = visibility,
tags = tags,
)
Loading