@@ -2387,7 +2387,7 @@ EOF
23872387# because the coverage post-processing tool escaped the sandbox to find its own
23882388# runfiles. The error we would see here without the flag would be "Cannot find
23892389# runfiles". See #4685.
2390- function test_rbe_coverage_produces_report () {
2390+ function test_java_rbe_coverage_produces_report () {
23912391 mkdir -p java/factorial
23922392
23932393 JAVA_TOOLCHAIN=" @bazel_tools//tools/jdk:toolchain"
@@ -2477,4 +2477,128 @@ end_of_record"
24772477 assert_equals " $expected_result " " $( cat bazel-testlogs/java/factorial/fact-test/coverage.dat) "
24782478}
24792479
2480+ # Runs coverage with `cc_test` and RE then checks the coverage file is returned.
2481+ # Older versions of gcov are not supported with bazel coverage and so will be skipped.
2482+ # See the above `test_java_rbe_coverage_produces_report` for more information.
2483+ function test_cc_rbe_coverage_produces_report() {
2484+ if [[ " $PLATFORM " == " darwin" ]]; then
2485+ # TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
2486+ # setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
2487+ # action executors in order to select the appropriate Xcode toolchain.
2488+ return 0
2489+ fi
2490+
2491+ # Check to see if intermediate files are supported, otherwise skip.
2492+ gcov --help | grep " \-i," || return 0
2493+
2494+ local test_dir=" a/cc/coverage_test"
2495+ mkdir -p $test_dir
2496+
2497+ cat > " $test_dir " /BUILD << 'EOF '
2498+ package(default_visibility = ["//visibility:public"])
2499+
2500+ cc_library(
2501+ name = "hello-lib",
2502+ srcs = ["hello-lib.cc"],
2503+ hdrs = ["hello-lib.h"],
2504+ )
2505+
2506+ cc_binary(
2507+ name = "hello-world",
2508+ srcs = ["hello-world.cc"],
2509+ deps = [":hello-lib"],
2510+ )
2511+
2512+ cc_test(
2513+ name = "hello-test",
2514+ srcs = ["hello-world.cc"],
2515+ deps = [":hello-lib"],
2516+ )
2517+
2518+ EOF
2519+
2520+ cat > " $test_dir " /hello-lib.cc << 'EOF '
2521+ #include "hello-lib.h"
2522+
2523+ #include <iostream>
2524+
2525+ using std::cout;
2526+ using std::endl;
2527+ using std::string;
2528+
2529+ namespace hello {
2530+
2531+ HelloLib::HelloLib(const string& greeting) : greeting_(new string(greeting)) {
2532+ }
2533+
2534+ void HelloLib::greet(const string& thing) {
2535+ cout << *greeting_ << " " << thing << endl;
2536+ }
2537+
2538+ } // namespace hello
2539+
2540+ EOF
2541+
2542+ cat > " $test_dir " /hello-lib.h << 'EOF '
2543+ #ifndef HELLO_LIB_H_
2544+ #define HELLO_LIB_H_
2545+
2546+ #include <string>
2547+ #include <memory>
2548+
2549+ namespace hello {
2550+
2551+ class HelloLib {
2552+ public:
2553+ explicit HelloLib(const std::string &greeting);
2554+
2555+ void greet(const std::string &thing);
2556+
2557+ private:
2558+ std::unique_ptr<const std::string> greeting_;
2559+ };
2560+
2561+ } // namespace hello
2562+
2563+ #endif // HELLO_LIB_H_
2564+
2565+ EOF
2566+
2567+ cat > " $test_dir " /hello-world.cc << 'EOF '
2568+ #include "hello-lib.h"
2569+
2570+ #include <string>
2571+
2572+ using hello::HelloLib;
2573+ using std::string;
2574+
2575+ int main(int argc, char** argv) {
2576+ HelloLib lib("Hello");
2577+ string thing = "world";
2578+ if (argc > 1) {
2579+ thing = argv[1];
2580+ }
2581+ lib.greet(thing);
2582+ return 0;
2583+ }
2584+
2585+ EOF
2586+
2587+ bazel coverage \
2588+ --test_output=all \
2589+ --experimental_fetch_all_coverage_outputs \
2590+ --experimental_split_coverage_postprocessing \
2591+ --spawn_strategy=remote \
2592+ --remote_executor=grpc://localhost:${worker_port} \
2593+ //" $test_dir " :hello-test >& $TEST_log \
2594+ || fail " Failed to run coverage for cc_test"
2595+
2596+ # Different gcov versions generate different outputs.
2597+ # Simply check if this is empty or not.
2598+ if [[ ! -s bazel-testlogs/a/cc/coverage_test/hello-test/coverage.dat ]]; then
2599+ echo " Coverage is empty. Failing now."
2600+ return 1
2601+ fi
2602+ }
2603+
24802604run_suite " Remote execution and remote cache tests"
0 commit comments