diff --git a/src/test/shell/bazel/bazel_cc_code_coverage_test.sh b/src/test/shell/bazel/bazel_cc_code_coverage_test.sh index 6177856d1d9dcd..effea640848884 100755 --- a/src/test/shell/bazel/bazel_cc_code_coverage_test.sh +++ b/src/test/shell/bazel/bazel_cc_code_coverage_test.sh @@ -376,6 +376,11 @@ function test_cc_test_coverage_gcov() { output_file_json="output_file.json" zcat $agcda $tgcda $dagcda > $output_file_json + # Remove all branch information from the json. + # We disable branch coverage for gcov 7 and it is easier to remove it + # than it is to put it back. + # Replace "branch": [..] with "branch": [] - (non-empty [..]) + sed -E -i 's/"branches": \[[^]]+]/"branches": \[\]/g' "$output_file_json" assert_gcov_coverage_srcs_a_cc_json "$output_file_json" assert_gcov_coverage_srcs_t_cc_json "$output_file_json" assert_gcov_coverage_srcs_b_h_json "$output_file_json" diff --git a/src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh b/src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh index ec3d9201b09440..7f0cc79e0c0316 100755 --- a/src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh +++ b/src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh @@ -110,6 +110,24 @@ was not found in actual coverage report: <$( cat "$output_file" )>" } +# Asserts if the given expected coverage result is included in the given output +# file, accounting for the fact that branch coverage is disabled for gcov v7 +# +# - expected coverage The expected result that must be included in the output. +# - output_file The location of the coverage output file. +function assert_cc_coverage_result() { + local expected_coverage="${1}"; shift + local output_file="${1}"; shift + + # we disable branch coverage when using gcov 7 so we should strip all branch + # information from the "expected" result before checking. + local gcov_version="$(gcov -v | grep "gcov" | cut -d " " -f 4 | cut -d "." -f 1)" + if [[ "$gcov_version" -le 7 ]]; then + expected_coverage=$(echo "$expected_coverage" | grep -v "^BR") + fi + assert_coverage_result "$expected_coverage" "$output_file" +} + # Returns the path of the code coverage report that was generated by Bazel by # looking at the current $TEST_log. The method fails if TEST_log does not # contain any coverage report for a passed test. @@ -139,6 +157,10 @@ FN:3,_Z1ab FNDA:1,_Z1ab FNF:1 FNH:1 +BRDA:4,0,0,1 +BRDA:4,0,1,0 +BRF:2 +BRH:1 DA:3,1 DA:4,1 DA:5,1 @@ -146,7 +168,7 @@ DA:7,0 LH:3 LF:4 end_of_record" - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" # t.cc is not included in the coverage report because test targets are not # instrumented by default. assert_not_contains "SF:t\.cc" "$coverage_file_path" @@ -277,7 +299,7 @@ DA:10,1 LH:5 LF:5 end_of_record" - assert_coverage_result "$expected_result_num_lib" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_num_lib" "$coverage_file_path" local expected_result_a_header="SF:examples/cpp/foo/bar/baz/a_header.h FN:3,_ZNK1A12num_whateverEv @@ -289,7 +311,7 @@ DA:4,1 LH:2 LF:2 end_of_record" - assert_coverage_result "$expected_result_a_header" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_header" "$coverage_file_path" local coverage_result_num_lib_header="SF:examples/cpp/num-lib.h FN:14,_ZN3num6NumLib18add_number_inlinedEi @@ -301,7 +323,7 @@ DA:15,1 LH:2 LF:2 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" } function test_cc_test_gcov_multiple_headers() { @@ -371,6 +393,10 @@ FN:4,_Z1ab FNDA:1,_Z1ab FNF:1 FNH:1 +BRDA:5,0,0,1 +BRDA:5,0,1,0 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,1 @@ -383,6 +409,10 @@ FN:1,_Z1bi FNDA:1,_Z1bi FNF:1 FNH:1 +BRDA:2,0,0,1 +BRDA:2,0,1,0 +BRF:2 +BRH:1 DA:1,1 DA:2,1 DA:3,1 @@ -393,8 +423,8 @@ end_of_record" local expected_result_t_cc="SF:coverage_srcs/t.cc" ############## Asserting the coverage results ############## - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" - assert_coverage_result "$expected_result_b_h" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_h" "$coverage_file_path" # coverage_srcs/t.cc is not included in the coverage report because the test # targets are not instrumented by default. assert_not_contains "SF:coverage_srcs/t\.cc" "$coverage_file_path" @@ -469,6 +499,10 @@ FN:4,_Z1ab FNDA:1,_Z1ab FNF:1 FNH:1 +BRDA:5,0,0,1 +BRDA:5,0,1,0 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,1 @@ -481,6 +515,10 @@ FN:1,_Z1bi FNDA:1,_Z1bi FNF:1 FNH:1 +BRDA:2,0,0,1 +BRDA:2,0,1,0 +BRF:2 +BRH:1 DA:1,1 DA:2,1 DA:3,1 @@ -491,14 +529,14 @@ end_of_record" local expected_result_t_cc="SF:coverage_srcs/t.cc" ############## Asserting the coverage results ############## - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" - assert_coverage_result "$expected_result_b_h" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_h" "$coverage_file_path" # iostream should not be in the final coverage report because it is a syslib. assert_not_contains "iostream" "$coverage_file_path" # coverage_srcs/t.cc should be included in the coverage report. We don't check # for the full contents of the t.cc report because it might vary from system # to system depending on the system headers. - assert_coverage_result "$expected_result_t_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_t_cc" "$coverage_file_path" } function test_cc_test_gcov_same_header_different_libs() { @@ -602,6 +640,10 @@ FN:4,_Z1ab FNDA:1,_Z1ab FNF:1 FNH:1 +BRDA:5,0,0,1 +BRDA:5,0,1,0 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,1 @@ -616,6 +658,12 @@ FNDA:1,_Z7b_for_ai FNDA:1,_Z7b_for_ci FNF:2 FNH:2 +BRDA:3,0,0,1 +BRDA:3,0,1,0 +BRDA:12,0,0,0 +BRDA:12,0,1,1 +BRF:4 +BRH:2 DA:2,1 DA:3,1 DA:4,1 @@ -632,6 +680,10 @@ FN:4,_Z1cb FNDA:1,_Z1cb FNF:1 FNH:1 +BRDA:5,0,0,0 +BRDA:5,0,1,1 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,0 @@ -641,9 +693,9 @@ LF:4 end_of_record" ############## Asserting the coverage results ############## - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" - assert_coverage_result "$expected_result_b_h" "$coverage_file_path" - assert_coverage_result "$expected_result_c_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_h" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_c_cc" "$coverage_file_path" # coverage_srcs/t.cc is not included in the coverage report because the test # targets are not instrumented by default. assert_not_contains "SF:coverage_srcs/t\.cc" "$coverage_file_path" @@ -769,6 +821,10 @@ FNDA:2,_Z10a_redirectv FNDA:1,_Z1ab FNF:2 FNH:2 +BRDA:5,0,0,1 +BRDA:5,0,1,0 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,1 @@ -787,6 +843,12 @@ FNDA:1,_Z7b_for_ci FNDA:3,_Z9b_for_allv FNF:3 FNH:3 +BRDA:3,0,0,1 +BRDA:3,0,1,0 +BRDA:12,0,0,0 +BRDA:12,0,1,1 +BRF:4 +BRH:2 DA:2,1 DA:3,1 DA:4,1 @@ -807,6 +869,10 @@ FNDA:1,_Z10c_redirectv FNDA:1,_Z1cb FNF:2 FNH:2 +BRDA:5,0,0,0 +BRDA:5,0,1,1 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,0 @@ -818,9 +884,9 @@ LF:6 end_of_record" ############## Asserting the coverage results ############## - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" - assert_coverage_result "$expected_result_b_h" "$coverage_file_path" - assert_coverage_result "$expected_result_c_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_h" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_c_cc" "$coverage_file_path" # coverage_srcs/t.cc is not included in the coverage report because the test # targets are not instrumented by default. assert_not_contains "SF:coverage_srcs/t\.cc" "$coverage_file_path" @@ -1017,6 +1083,10 @@ FN:4,_Z1ab FNDA:1,_Z1ab FNF:1 FNH:1 +BRDA:5,0,0,1 +BRDA:5,0,1,0 +BRF:2 +BRH:1 DA:4,1 DA:5,1 DA:6,1 @@ -1029,6 +1099,10 @@ FN:1,_Z1bb FNDA:1,_Z1bb FNF:1 FNH:1 +BRDA:2,0,0,1 +BRDA:2,0,1,0 +BRF:2 +BRH:1 DA:1,1 DA:2,1 DA:3,1 @@ -1037,8 +1111,8 @@ LH:3 LF:4 end_of_record' - assert_coverage_result "$expected_result_a_cc" "$coverage_file_path" - assert_coverage_result "$expected_result_b_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_a_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_cc" "$coverage_file_path" } function test_external_cc_target_coverage_not_collected_by_default() { @@ -1057,6 +1131,10 @@ FN:1,_Z1bb FNDA:1,_Z1bb FNF:1 FNH:1 +BRDA:2,0,0,1 +BRDA:2,0,1,0 +BRF:2 +BRH:1 DA:1,1 DA:2,1 DA:3,1 @@ -1065,7 +1143,7 @@ LH:3 LF:4 end_of_record' - assert_coverage_result "$expected_result_b_cc" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_b_cc" "$coverage_file_path" assert_not_contains "SF:external/other_repo/a.cc" "$coverage_file_path" } diff --git a/src/test/shell/bazel/bazel_coverage_java_test.sh b/src/test/shell/bazel/bazel_coverage_java_test.sh index 1b3826542533cf..d262f94d542ba9 100755 --- a/src/test/shell/bazel/bazel_coverage_java_test.sh +++ b/src/test/shell/bazel/bazel_coverage_java_test.sh @@ -132,6 +132,24 @@ was not found in actual coverage report: <$( cat "$output_file" )>" } +# Asserts if the given expected coverage result is included in the given output +# file, accounting for the fact that branch coverage is disabled for gcov v7 +# +# - expected coverage The expected result that must be included in the output. +# - output_file The location of the coverage output file. +function assert_cc_coverage_result() { + local expected_coverage="${1}"; shift + local output_file="${1}"; shift + + # we disable branch coverage when using gcov 7 so we should strip all branch + # information from the "expected" result before checking. + local gcov_version="$(gcov -v | grep "gcov" | cut -d " " -f 4 | cut -d "." -f 1)" + if [[ "$gcov_version" -le 7 ]]; then + expected_coverage=$(echo "$expected_coverage" | grep -v "^BR") + fi + assert_coverage_result "$expected_coverage" "$output_file" +} + # Returns the path of the code coverage report that was generated by Bazel by # looking at the current $TEST_log. The method fails if TEST_log does not # contain any coverage report for a passed test. @@ -1133,6 +1151,14 @@ FN:5,main FNDA:1,main FNF:1 FNH:1 +BRDA:6,0,0,1 +BRDA:6,0,1,0 +BRDA:8,0,0,0 +BRDA:8,0,1,1 +BRDA:11,0,0,1 +BRDA:11,0,1,0 +BRF:6 +BRH:3 DA:5,1 DA:6,1 DA:7,1 @@ -1143,7 +1169,7 @@ DA:12,1 LH:6 LF:7 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" } function setup_external_java_target() { diff --git a/src/test/shell/bazel/bazel_coverage_py_test.sh b/src/test/shell/bazel/bazel_coverage_py_test.sh index f514c46568b983..89fae77ffe9579 100755 --- a/src/test/shell/bazel/bazel_coverage_py_test.sh +++ b/src/test/shell/bazel/bazel_coverage_py_test.sh @@ -61,6 +61,24 @@ was not found in actual coverage report: <$( cat "$output_file" )>" } +# Asserts if the given expected coverage result is included in the given output +# file, accounting for the fact that branch coverage is disabled for gcov v7 +# +# - expected coverage The expected result that must be included in the output. +# - output_file The location of the coverage output file. +function assert_cc_coverage_result() { + local expected_coverage="${1}"; shift + local output_file="${1}"; shift + + # we disable branch coverage when using gcov 7 so we should strip all branch + # information from the "expected" result before checking. + local gcov_version="$(gcov -v | grep "gcov" | cut -d " " -f 4 | cut -d "." -f 1)" + if [[ "$gcov_version" -le 7 ]]; then + expected_coverage=$(echo "$expected_coverage" | grep -v "^BR") + fi + assert_coverage_result "$expected_coverage" "$output_file" +} + # Returns the path of the code coverage report that was generated by Bazel by # looking at the current $TEST_log. The method fails if TEST_log does not # contain any coverage report for a passed test. @@ -298,6 +316,14 @@ FN:5,main FNDA:1,main FNF:1 FNH:1 +BRDA:6,0,0,1 +BRDA:6,0,1,0 +BRDA:8,0,0,0 +BRDA:8,0,1,1 +BRDA:11,0,0,1 +BRDA:11,0,1,0 +BRF:6 +BRH:3 DA:5,1 DA:6,1 DA:7,1 @@ -308,7 +334,7 @@ DA:12,1 LH:6 LF:7 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" } function test_py_test_coverage_cc_binary_and_java_binary() { @@ -459,13 +485,21 @@ DA:9,1 LH:4 LF:4 end_of_record" - assert_coverage_result "$expected_result_num_lib" "$coverage_file_path" + assert_cc_coverage_result "$expected_result_num_lib" "$coverage_file_path" local coverage_result_num_lib_header="SF:examples/cpp/num-world.cc FN:5,main FNDA:1,main FNF:1 FNH:1 +BRDA:6,0,0,1 +BRDA:6,0,1,0 +BRDA:8,0,0,0 +BRDA:8,0,1,1 +BRDA:11,0,0,1 +BRDA:11,0,1,0 +BRF:6 +BRH:3 DA:5,1 DA:6,1 DA:7,1 @@ -476,7 +510,7 @@ DA:12,1 LH:6 LF:7 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" ############# Assert Java code coverage results diff --git a/src/test/shell/bazel/bazel_coverage_sh_test.sh b/src/test/shell/bazel/bazel_coverage_sh_test.sh index a42db04b57075d..2221ce59c3b6ef 100755 --- a/src/test/shell/bazel/bazel_coverage_sh_test.sh +++ b/src/test/shell/bazel/bazel_coverage_sh_test.sh @@ -61,6 +61,24 @@ was not found in actual coverage report: <$( cat "$output_file" )>" } +# Asserts if the given expected coverage result is included in the given output +# file, accounting for the fact that branch coverage is disabled for gcov v7 +# +# - expected coverage The expected result that must be included in the output. +# - output_file The location of the coverage output file. +function assert_cc_coverage_result() { + local expected_coverage="${1}"; shift + local output_file="${1}"; shift + + # we disable branch coverage when using gcov 7 so we should strip all branch + # information from the "expected" result before checking. + local gcov_version="$(gcov -v | grep "gcov" | cut -d " " -f 4 | cut -d "." -f 1)" + if [[ "$gcov_version" -le 7 ]]; then + expected_coverage=$(echo "$expected_coverage" | grep -v "^BR") + fi + assert_coverage_result "$expected_coverage" "$output_file" +} + # Returns the path of the code coverage report that was generated by Bazel by # looking at the current $TEST_log. The method fails if TEST_log does not # contain any coverage report for a passed test. @@ -304,6 +322,14 @@ FN:5,main FNDA:1,main FNF:1 FNH:1 +BRDA:6,0,0,1 +BRDA:6,0,1,0 +BRDA:8,0,0,0 +BRDA:8,0,1,1 +BRDA:11,0,0,1 +BRDA:11,0,1,0 +BRF:6 +BRH:3 DA:5,1 DA:6,1 DA:7,1 @@ -314,7 +340,7 @@ DA:12,1 LH:6 LF:7 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" } function test_sh_test_coverage_cc_binary_and_java_binary() { @@ -474,6 +500,14 @@ FN:5,main FNDA:1,main FNF:1 FNH:1 +BRDA:6,0,0,1 +BRDA:6,0,1,0 +BRDA:8,0,0,0 +BRDA:8,0,1,1 +BRDA:11,0,0,1 +BRDA:11,0,1,0 +BRF:6 +BRH:3 DA:5,1 DA:6,1 DA:7,1 @@ -484,7 +518,7 @@ DA:12,1 LH:6 LF:7 end_of_record" - assert_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" + assert_cc_coverage_result "$coverage_result_num_lib_header" "$coverage_file_path" ############# Assert Java code coverage results