@@ -2343,7 +2343,7 @@ EOF
2343
2343
# because the coverage post-processing tool escaped the sandbox to find its own
2344
2344
# runfiles. The error we would see here without the flag would be "Cannot find
2345
2345
# runfiles". See #4685.
2346
- function test_rbe_coverage_produces_report () {
2346
+ function test_java_rbe_coverage_produces_report () {
2347
2347
mkdir -p java/factorial
2348
2348
2349
2349
JAVA_TOOLS_ZIP=" released"
@@ -2426,4 +2426,130 @@ end_of_record"
2426
2426
assert_equals " $expected_result " " $( cat bazel-testlogs/java/factorial/fact-test/coverage.dat) "
2427
2427
}
2428
2428
2429
+ # Runs coverage with `cc_test` and RE then checks the coverage file is returned.
2430
+ # Older versions of gcov are not supported with bazel coverage and so will be skipped.
2431
+ # See the above `test_java_rbe_coverage_produces_report` for more information.
2432
+ function test_cc_rbe_coverage_produces_report() {
2433
+ if [[ " $PLATFORM " == " darwin" ]]; then
2434
+ # TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
2435
+ # setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
2436
+ # action executors in order to select the appropriate Xcode toolchain.
2437
+ return 0
2438
+ fi
2439
+
2440
+ gcov --help | grep " \-i,"
2441
+ if [[ $? -eq 1 ]]; then
2442
+ echo " gcov does not support intermediate files."
2443
+ return 0
2444
+ fi
2445
+ local test_dir=" a/cc/coverage_test"
2446
+ mkdir -p $test_dir
2447
+
2448
+ cat > " $test_dir " /BUILD << 'EOF '
2449
+ package(default_visibility = ["//visibility:public"])
2450
+
2451
+ cc_library(
2452
+ name = "hello-lib",
2453
+ srcs = ["hello-lib.cc"],
2454
+ hdrs = ["hello-lib.h"],
2455
+ )
2456
+
2457
+ cc_binary(
2458
+ name = "hello-world",
2459
+ srcs = ["hello-world.cc"],
2460
+ deps = [":hello-lib"],
2461
+ )
2462
+
2463
+ cc_test(
2464
+ name = "hello-test",
2465
+ srcs = ["hello-world.cc"],
2466
+ deps = [":hello-lib"],
2467
+ )
2468
+
2469
+ EOF
2470
+
2471
+ cat > " $test_dir " /hello-lib.cc << 'EOF '
2472
+ #include "hello-lib.h"
2473
+
2474
+ #include <iostream>
2475
+
2476
+ using std::cout;
2477
+ using std::endl;
2478
+ using std::string;
2479
+
2480
+ namespace hello {
2481
+
2482
+ HelloLib::HelloLib(const string& greeting) : greeting_(new string(greeting)) {
2483
+ }
2484
+
2485
+ void HelloLib::greet(const string& thing) {
2486
+ cout << *greeting_ << " " << thing << endl;
2487
+ }
2488
+
2489
+ } // namespace hello
2490
+
2491
+ EOF
2492
+
2493
+ cat > " $test_dir " /hello-lib.h << 'EOF '
2494
+ #ifndef HELLO_LIB_H_
2495
+ #define HELLO_LIB_H_
2496
+
2497
+ #include <string>
2498
+ #include <memory>
2499
+
2500
+ namespace hello {
2501
+
2502
+ class HelloLib {
2503
+ public:
2504
+ explicit HelloLib(const std::string &greeting);
2505
+
2506
+ void greet(const std::string &thing);
2507
+
2508
+ private:
2509
+ std::unique_ptr<const std::string> greeting_;
2510
+ };
2511
+
2512
+ } // namespace hello
2513
+
2514
+ #endif // HELLO_LIB_H_
2515
+
2516
+ EOF
2517
+
2518
+ cat > " $test_dir " /hello-world.cc << 'EOF '
2519
+ #include "hello-lib.h"
2520
+
2521
+ #include <string>
2522
+
2523
+ using hello::HelloLib;
2524
+ using std::string;
2525
+
2526
+ int main(int argc, char** argv) {
2527
+ HelloLib lib("Hello");
2528
+ string thing = "world";
2529
+ if (argc > 1) {
2530
+ thing = argv[1];
2531
+ }
2532
+ lib.greet(thing);
2533
+ return 0;
2534
+ }
2535
+
2536
+ EOF
2537
+
2538
+ bazel coverage \
2539
+ --test_output=all \
2540
+ --experimental_fetch_all_coverage_outputs \
2541
+ --experimental_split_coverage_postprocessing \
2542
+ --spawn_strategy=remote \
2543
+ --remote_executor=grpc://localhost:${worker_port} \
2544
+ //" $test_dir " :hello-test >& $TEST_log \
2545
+ || fail " Failed to run coverage for cc_test"
2546
+
2547
+ # Different gcov versions generate different outputs.
2548
+ # Simply check if this is empty or not.
2549
+ if [[ ! -s bazel-testlogs/a/cc/coverage_test/hello-test/coverage.dat ]]; then
2550
+ echo " Coverage is empty. Failing now."
2551
+ return 1
2552
+ fi
2553
+ }
2554
+
2429
2555
run_suite " Remote execution and remote cache tests"
0 commit comments