Просмотр исходного кода

Have sh_test directly invoke benchmarks (#4552)

These tests typically take 10-20s, but I'm seeing some timeouts
[here](https://github.com/carbon-language/carbon-lang/actions/runs/11899548036/job/33158400417).
This seemed particularly suspicious due to the _absence_ of output
(copied below). That got me looking, and maybe the subprocessing tickles
a cpu bottleneck, so proposing this approach to remove the exec. Even if
this doesn't solve the flakiness, I think it's a simpler implementation.

Note I believe this is intended to work. The `sh` rules rely on shebangs
(as noted at https://bazel.build/reference/be/shell#sh_test), and are
essentially just subprocessing to the input. Note this could've also had
`args` on a `cc_test` rule, but I'd expect the same args to be passed to
`run` where instead the benchmark behavior should be default (and I'm
assuming you'd rather not have args there). Fundamentally this becomes a
symlink:

```
bazel-bin/common/map_benchmark_test -> .../execroot/_main/bazel-out/k8-fastbuild/bin/common/map_benchmark
```

Copying snippet from timeout below:

```
==================== Test output for //common:map_benchmark_test:
      /private/var/tmp/_bazel_runner/e591f63ed099023de1f206992dfce127/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/common/map_benchmark_test/test.log
-- Test timed out at 2024-11-18 19:32:13 UTC --
INFO: From Testing //common:map_benchmark_test:
================================================================================
```
Jon Ross-Perkins 1 год назад
Родитель
Сommit
493d766a97

+ 19 - 6
common/BUILD

@@ -299,8 +299,13 @@ sh_test(
     size = "enormous",
     # We configure the test to run quickly.
     timeout = "short",
-    srcs = ["map_benchmark_test.sh"],
-    data = [":map_benchmark"],
+    srcs = [":map_benchmark"],
+    args = [
+        "--benchmark_counters_tabular=true",
+        "--benchmark_min_time=1x",
+        # The `$$` is repeated for Bazel escaping of `$`.
+        "--benchmark_filter=^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$$",
+    ],
 )
 
 cc_library(
@@ -349,8 +354,11 @@ cc_binary(
 
 sh_test(
     name = "raw_hashtable_metadata_group_benchmark_test",
-    srcs = ["raw_hashtable_metadata_group_benchmark_test.sh"],
-    data = [":raw_hashtable_metadata_group_benchmark"],
+    srcs = ["raw_hashtable_metadata_group_benchmark"],
+    args = [
+        "--benchmark_counters_tabular=true",
+        "--benchmark_min_time=1x",
+    ],
 )
 
 cc_library(
@@ -428,8 +436,13 @@ sh_test(
     size = "enormous",
     # We configure the test to run quickly.
     timeout = "short",
-    srcs = ["set_benchmark_test.sh"],
-    data = [":set_benchmark"],
+    srcs = [":set_benchmark"],
+    args = [
+        "--benchmark_counters_tabular=true",
+        "--benchmark_min_time=1x",
+        # The `$$` is repeated for Bazel escaping of `$`.
+        "--benchmark_filter=^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$$",
+    ],
 )
 
 cc_library(

+ 0 - 12
common/map_benchmark_test.sh

@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-#
-# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-# Exceptions. See /LICENSE for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-BENCHMARK="$TEST_SRCDIR/$TEST_WORKSPACE/common/map_benchmark"
-
-exec "$BENCHMARK" \
-  --benchmark_counters_tabular=true \
-  --benchmark_min_time=1x \
-  --benchmark_filter='^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$'

+ 0 - 11
common/raw_hashtable_metadata_group_benchmark_test.sh

@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-#
-# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-# Exceptions. See /LICENSE for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-BENCHMARK="$TEST_SRCDIR/$TEST_WORKSPACE/common/raw_hashtable_metadata_group_benchmark"
-
-exec "$BENCHMARK" \
-  --benchmark_counters_tabular=true \
-  --benchmark_min_time=1x

+ 0 - 12
common/set_benchmark_test.sh

@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-#
-# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-# Exceptions. See /LICENSE for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-BENCHMARK="$TEST_SRCDIR/$TEST_WORKSPACE/common/set_benchmark"
-
-exec "$BENCHMARK" \
-  --benchmark_counters_tabular=true \
-  --benchmark_min_time=1x \
-  --benchmark_filter='^[^/]*/[1-9][0-9]{0,3}(/[0-9]+)?$'

+ 6 - 2
toolchain/driver/BUILD

@@ -74,8 +74,12 @@ cc_binary(
 
 sh_test(
     name = "compile_benchmark_test",
-    srcs = ["compile_benchmark_test.sh"],
-    data = [":compile_benchmark"],
+    srcs = [":compile_benchmark"],
+    args = [
+        "--benchmark_min_time=1x",
+        # The `$$` is repeated for Bazel escaping of `$`.
+        "--benchmark_filter=/256$$",
+    ],
 )
 
 cc_library(

+ 0 - 13
toolchain/driver/compile_benchmark_test.sh

@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-#
-# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-# Exceptions. See /LICENSE for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-BENCHMARK="$TEST_SRCDIR/$TEST_WORKSPACE/toolchain/driver/compile_benchmark"
-
-# Run the benchmark with the fastest size and a single iteration to make sure it
-# doesn't hit errors.
-exec "$BENCHMARK" \
-  --benchmark_min_time=1x \
-  --benchmark_filter='/256$'