Skip to content

Commit

Permalink
Make XLA C++ tests fail if no test case is linked in. This prevents t…
Browse files Browse the repository at this point in the history
…he mistake of linking the test wrong.

PiperOrigin-RevId: 730635331
  • Loading branch information
Google-ML-Automation committed Feb 25, 2025
1 parent 2efc815 commit 008a495
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xla/backends/cpu/benchmarks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ cc_library(
xla_cc_test(
name = "dag_execution_benchmark_test",
srcs = ["dag_execution_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand All @@ -64,6 +65,7 @@ xla_cc_test(
xla_cc_test(
name = "dot_benchmark_test",
srcs = ["dot_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand All @@ -82,6 +84,7 @@ xla_cc_test(
xla_cc_test(
name = "dynamic_update_slice_benchmark_test",
srcs = ["dynamic_update_slice_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand All @@ -100,6 +103,7 @@ xla_cc_test(
xla_cc_test(
name = "elementwise_benchmark_test",
srcs = ["elementwise_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand All @@ -118,6 +122,7 @@ xla_cc_test(
xla_cc_test(
name = "exp_benchmark_test",
srcs = ["exp_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand Down Expand Up @@ -209,6 +214,7 @@ xla_cc_test(
xla_cc_test(
name = "convolution_benchmark_test",
srcs = ["convolution_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand All @@ -225,6 +231,7 @@ xla_cc_test(
xla_cc_test(
name = "custom_call_benchmark_test",
srcs = ["custom_call_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand Down Expand Up @@ -283,6 +290,7 @@ xla_cc_test(
xla_cc_test(
name = "concatenate_benchmark_test",
srcs = ["concatenate_benchmark_test.cc"],
fail_if_no_tests_linked = False,
deps = [
":hlo_benchmark_runner",
"//xla:literal",
Expand Down
2 changes: 2 additions & 0 deletions xla/python/ifrt_proxy/common/ifrt_proxy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ load("//xla:xla.bzl", "xla_cc_test")

def ifrt_proxy_cc_test(
shuffle_tests = True,
fail_if_no_tests_linked = True,
**kwargs):
xla_cc_test(
shuffle_tests = shuffle_tests,
fail_if_no_tests_linked = fail_if_no_tests_linked,
**kwargs
)

Expand Down
3 changes: 3 additions & 0 deletions xla/tests/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def xla_test(
# Therefore we use dynamic linking outside Google.
linkstatic = False,
shuffle_tests = True,
fail_if_no_tests_linked = True,
**kwargs):
"""Generates cc_test targets for the given XLA backends.
Expand Down Expand Up @@ -267,6 +268,7 @@ def xla_test(
dedicated argument, like setting per-backend flaky or timeout attributes.
linkstatic: Whether to link the test statically.
shuffle_tests: Whether to shuffle the test cases.
fail_if_no_tests_linked: Whether to fail if no tests are linked.
**kwargs: Additional keyword arguments to pass to native.cc_test.
"""

Expand Down Expand Up @@ -348,6 +350,7 @@ def xla_test(
data = data + this_backend_data,
linkstatic = linkstatic,
shuffle_tests = shuffle_tests,
fail_if_no_tests_linked = fail_if_no_tests_linked,
**this_backend_kwargs
)

Expand Down
2 changes: 2 additions & 0 deletions xla/tsl/mkl/graph.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def onednn_graph_cc_test(
srcs = [],
deps = [],
shuffle_tests = True,
fail_if_no_tests_linked = True,
**kwargs):
"""xla_cc_test rule that has empty src and deps if not building with Graph API."""
xla_cc_test(
srcs = if_graph_api(srcs),
deps = if_graph_api(deps) + ["@com_google_googletest//:gtest_main"],
shuffle_tests = shuffle_tests,
fail_if_no_tests_linked = fail_if_no_tests_linked,
**kwargs
)
4 changes: 4 additions & 0 deletions xla/xla.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def xla_cc_test(
linkstatic = True,
args = None,
shuffle_tests = True,
fail_if_no_tests_linked = True,
**kwargs):
"""A wrapper around cc_test that adds XLA-specific dependencies.
Expand All @@ -92,9 +93,12 @@ def xla_cc_test(
linkstatic: Whether to link statically.
args: The arguments to pass to the test.
shuffle_tests: Whether to shuffle the test cases.
fail_if_no_tests_linked: Whether to fail if no tests are linked. Currently unused.
**kwargs: Other arguments to pass to the test.
"""

_ = fail_if_no_tests_linked # buildifier: disable=unused-variable

if args == None:
args = []

Expand Down

0 comments on commit 008a495

Please sign in to comment.