Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables regression testing in bazel. #246

Merged
merged 10 commits into from
Jan 5, 2024
58 changes: 27 additions & 31 deletions bazel/testing.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def camel_to_snake(camel_case_name):
# The size = medium hammer is overkill for some tests too (bazel
# test grumbles about this). If re-inventing, make sure to re-invent
# the CMake test too.
#
#
def generate_integration_tests(sources, xodr_files):
for xodr_file in xodr_files:
camel_case_name = xodr_file[:-len(".xodr")]
Expand All @@ -47,33 +47,29 @@ def generate_integration_tests(sources, xodr_files):
],
)

# TODO(stonier): Reneable once a solution to #585 (see below) is found.
#
# # Not very bazel style (prefer individual test definitions)
# def generate_unit_tests(sources):
# for source in sources:
# name = source[:-len(".cc")]
# native.cc_test(
# name = name,
# srcs = [source],
# size = "small",
# copts = COPTS,
# linkopts = ["-lpthread"],
# defines = [
# "DEF_MALIDRIVE_RESOURCES=\\\"resources/\\\""
# ],
# data = ["//resources:all"], # sledge hammer
# deps = [
# "//:maliput_malidrive",
# "//:utility",
# "@googletest//:gtest",
# "@maliput//:api",
# "@maliput//:base",
# "@maliput//:common",
# "@maliput//:geometry_base",
# "@maliput//:math",
# # TODO(stonier): Can't ship test_utilities without infecting maliput with gtest
# # https://github.com/maliput/maliput/issues/585
# "@maliput//:test_utilities",
# ],
# )
# Not very bazel style (prefer individual test definitions)
def generate_unit_tests(sources):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you also allow to pass a list of target dependencies.
That will allow to select in each library the target link dependencies and pair it to what we do in cmake.
I also prefer to have the for loop in each BUILD.bazel file and only pass here the src list with just one file instead of the entire list. It is a matter of composability.
Note you also have the ability to pass in kwargs and default values --> https://bazel.build/rules/macro-tutorial . That could help with target customization. For instance, if we have at some point a test that deserves promotion to size="medium" we could use default values and override the default "small".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you also allow to pass a list of target dependencies.
That will allow to select in each library the target link dependencies and pair it to what we do in cmake.

I understand that this is solution is actually better.

However I tried to replicate the current CMake setup, and in the current CMake setup we link to all the targets: https://github.com/maliput/maliput_malidrive/blob/eb547917ac19c1d56efdc5ab09665e49e9571e97/test/CMakeLists.txt

for source in sources:
name = source[:-len(".cc")]
native.cc_test(
name = name,
srcs = [source],
size = "small",
copts = COPTS,
linkopts = ["-lpthread"],
defines = [
"DEF_MALIDRIVE_RESOURCES=\\\"resources/\\\""
],
data = ["//resources:all"], # sledge hammer
deps = [
"//:maliput_malidrive",
"//:utility",
"@googletest//:gtest",
"@maliput//:api",
"@maliput//:base",
"@maliput//:common",
"@maliput//:geometry_base",
"@maliput//:math",
"@maliput//:test_utilities",
],
)
18 changes: 5 additions & 13 deletions test/regression/base/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
###############################################################################
# TODO(stonier):
# Reenable once a solution to #585 [1] is found. See also comments in
# generate_unit_tests.
#
# [1] https://github.com/maliput/maliput/issues/585
###############################################################################

###############################################################################
# Loaders
###############################################################################

# load("//:bazel/variables.bzl", "COPTS")
# load("//:bazel/testing.bzl", "generate_unit_tests")
load("//:bazel/variables.bzl", "COPTS")
load("//:bazel/testing.bzl", "generate_unit_tests")

###############################################################################
# Test
###############################################################################

# generate_unit_tests(
# sources = glob(["*.cc"]),
# )
generate_unit_tests(
sources = glob(["*.cc"]),
)
Loading