From c589039d2b9f455d32778ff2b97ea91ab22fa2e3 Mon Sep 17 00:00:00 2001 From: sahithinukala Date: Tue, 17 Mar 2026 15:08:40 +0530 Subject: [PATCH] Add py_unittest_qnx_test.bzl macro for QNX test suites --- bazel/unit_tests.bzl | 5 ++- third_party/itf/py_unittest_qnx_test.bzl | 46 ++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/bazel/unit_tests.bzl b/bazel/unit_tests.bzl index cf5ab655..08ae755b 100644 --- a/bazel/unit_tests.bzl +++ b/bazel/unit_tests.bzl @@ -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. @@ -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 @@ -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 [] diff --git a/third_party/itf/py_unittest_qnx_test.bzl b/third_party/itf/py_unittest_qnx_test.bzl index e601d23c..48bc59eb 100644 --- a/third_party/itf/py_unittest_qnx_test.bzl +++ b/third_party/itf/py_unittest_qnx_test.bzl @@ -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, + )