You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.7 KiB

2 months ago
  1. load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
  2. platform(
  3. name = "windows",
  4. constraint_values = [
  5. "@platforms//os:windows",
  6. ],
  7. )
  8. TEST_COPTS = [
  9. "-pedantic",
  10. "-pedantic-errors",
  11. "-std=c++11",
  12. "-Wall",
  13. "-Wconversion",
  14. "-Wextra",
  15. "-Wshadow",
  16. # "-Wshorten-64-to-32",
  17. "-Wfloat-equal",
  18. "-fstrict-aliasing",
  19. ]
  20. # Some of the issues with DoNotOptimize only occur when optimization is enabled
  21. PER_SRC_COPTS = {
  22. "donotoptimize_test.cc": ["-O3"],
  23. }
  24. TEST_ARGS = ["--benchmark_min_time=0.01s"]
  25. PER_SRC_TEST_ARGS = {
  26. "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"],
  27. "repetitions_test.cc": [" --benchmark_repetitions=3"],
  28. "spec_arg_test.cc": ["--benchmark_filter=BM_NotChosen"],
  29. "spec_arg_verbosity_test.cc": ["--v=42"],
  30. }
  31. cc_library(
  32. name = "output_test_helper",
  33. testonly = 1,
  34. srcs = ["output_test_helper.cc"],
  35. hdrs = ["output_test.h"],
  36. copts = select({
  37. "//:windows": [],
  38. "//conditions:default": TEST_COPTS,
  39. }),
  40. deps = [
  41. "//:benchmark",
  42. "//:benchmark_internal_headers",
  43. ],
  44. )
  45. [
  46. cc_test(
  47. name = test_src[:-len(".cc")],
  48. size = "small",
  49. srcs = [test_src],
  50. args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []),
  51. copts = select({
  52. "//:windows": [],
  53. "//conditions:default": TEST_COPTS,
  54. }) + PER_SRC_COPTS.get(test_src, []),
  55. deps = [
  56. ":output_test_helper",
  57. "//:benchmark",
  58. "//:benchmark_internal_headers",
  59. "@com_google_googletest//:gtest",
  60. "@com_google_googletest//:gtest_main",
  61. ],
  62. # FIXME: Add support for assembly tests to bazel.
  63. # See Issue #556
  64. # https://github.com/google/benchmark/issues/556
  65. )
  66. for test_src in glob(
  67. ["*test.cc"],
  68. exclude = [
  69. "*_assembly_test.cc",
  70. "cxx03_test.cc",
  71. "link_main_test.cc",
  72. ],
  73. )
  74. ]
  75. cc_test(
  76. name = "cxx03_test",
  77. size = "small",
  78. srcs = ["cxx03_test.cc"],
  79. copts = TEST_COPTS + ["-std=c++03"],
  80. target_compatible_with = select({
  81. "//:windows": ["@platforms//:incompatible"],
  82. "//conditions:default": [],
  83. }),
  84. deps = [
  85. ":output_test_helper",
  86. "//:benchmark",
  87. "//:benchmark_internal_headers",
  88. "@com_google_googletest//:gtest",
  89. "@com_google_googletest//:gtest_main",
  90. ],
  91. )
  92. cc_test(
  93. name = "link_main_test",
  94. size = "small",
  95. srcs = ["link_main_test.cc"],
  96. copts = select({
  97. "//:windows": [],
  98. "//conditions:default": TEST_COPTS,
  99. }),
  100. deps = ["//:benchmark_main"],
  101. )