From 9f4d474909fc52b4e1abc084b7d59ed4544efb58 Mon Sep 17 00:00:00 2001 From: Trevor Guidry Date: Thu, 24 Oct 2024 15:31:58 -0400 Subject: [PATCH] SERVER-91567 Add jstests to coverage variants (#28370) GitOrigin-RevId: ad2177882ded45effba7f936555dee5532b33bdd --- etc/evergreen_yml_components/definitions.yml | 32 ++++++++- .../tasks/compile_tasks_shared.yml | 66 +++++++++---------- .../variants/codecoverage/test_dev.yml | 38 +++++++++++ .../functions/code_coverage_data_process.py | 24 ++++--- 4 files changed, 118 insertions(+), 42 deletions(-) diff --git a/etc/evergreen_yml_components/definitions.yml b/etc/evergreen_yml_components/definitions.yml index 7bc0487d510..c1ad150831d 100644 --- a/etc/evergreen_yml_components/definitions.yml +++ b/etc/evergreen_yml_components/definitions.yml @@ -129,6 +129,34 @@ functions: args: - "src/evergreen/gen_feature_flags.sh" + "generate github token": &generate_github_token + command: github.generate_token + params: + expansion_name: github_token + permissions: + metadata: read + contents: read + + # this cannot use a script because the codebase is not yet cloned + "conditionally clone repo": &conditionally_clone_repo + command: subprocess.exec + params: + binary: "bash" + args: + - "-c" + - | + if [ -z "${gcov_tool}" ]; then + echo "Not a code coverage repo, skipping git clone." + exit 0 + fi + + git clone --branch=${branch_name} --depth=1500 https://x-access-token:${github_token}@github.com/10gen/mongo.git src + export dir=src + bash src/evergreen/restore_git_history_and_tags.sh + + cd src + git reset --hard ${revision} + "fetch artifacts": &fetch_artifacts command: s3.get display_name: "fetch artifacts" @@ -137,7 +165,7 @@ functions: aws_secret: ${aws_secret} remote_file: ${mongo_artifacts} bucket: mciuploads - extract_to: src + extract_to: "./" "fetch venv": &fetch_venv command: s3.get @@ -717,6 +745,8 @@ functions: "do setup": - *f_expansions_write + - *generate_github_token + - *conditionally_clone_repo - *fetch_artifacts - *kill_processes - *cleanup_environment diff --git a/etc/evergreen_yml_components/tasks/compile_tasks_shared.yml b/etc/evergreen_yml_components/tasks/compile_tasks_shared.yml index 6765a06485d..4969e12bc7f 100644 --- a/etc/evergreen_yml_components/tasks/compile_tasks_shared.yml +++ b/etc/evergreen_yml_components/tasks/compile_tasks_shared.yml @@ -182,41 +182,41 @@ tasks: - command: archive.targz_pack params: target: "artifacts.tgz" - source_dir: "src" + source_dir: "./" include: - - ".resmoke_mongo_version.yml" - - ".resmoke_mongo_release_values.yml" - - "patch_test_tags.tgz" - - "./build/**.gcno" - - "./etc/*san.suppressions" - - "./etc/backports_required_for_multiversion_tests.yml" - - "./etc/evergreen_timeouts.yml" - - "./etc/expansions.default.yml" - - "./etc/evergreen_nightly.yml" - - "./etc/evergreen.yml" - - "./etc/evergreen_yml_components/**" - - "./etc/repo_config.yaml" - - "./etc/scons/**" - - "./etc/macos_dev_entitlements.xml" - - "docker_compose/**" - - "buildscripts/**" - - "jstests/**" - - "patch_files.txt" - - "evergreen/**" - - "src/**.idl" - - "src/mongo/client/sdam/json_tests/sdam_tests/**" - - "src/mongo/client/sdam/json_tests/server_selection_tests/**" - - "src/mongo/db/modules/enterprise/docs/**" - - "src/mongo/db/modules/enterprise/jstests/**" - - "src/mongo/db/modules/subscription/jstests/**" - - "src/mongo/util/options_parser/test_config_files/**" - - "src/third_party/JSON-Schema-Test-Suite/tests/draft4/**" - - "src/third_party/mock_ocsp_responder/**" - - "src/third_party/schemastore.org/**" - - "poetry.lock" - - "pyproject.toml" + - "src/.resmoke_mongo_version.yml" + - "src/.resmoke_mongo_release_values.yml" + - "src/patch_test_tags.tgz" + - "./**.gcno" + - "src/etc/*san.suppressions" + - "src/etc/backports_required_for_multiversion_tests.yml" + - "src/etc/evergreen_timeouts.yml" + - "src/etc/expansions.default.yml" + - "src/etc/evergreen_nightly.yml" + - "src/etc/evergreen.yml" + - "src/etc/evergreen_yml_components/**" + - "src/etc/repo_config.yaml" + - "src/etc/scons/**" + - "src/etc/macos_dev_entitlements.xml" + - "src/docker_compose/**" + - "src/buildscripts/**" + - "src/jstests/**" + - "src/patch_files.txt" + - "src/evergreen/**" + - "src/src/**.idl" + - "src/src/mongo/client/sdam/json_tests/sdam_tests/**" + - "src/src/mongo/client/sdam/json_tests/server_selection_tests/**" + - "src/src/mongo/db/modules/enterprise/docs/**" + - "src/src/mongo/db/modules/enterprise/jstests/**" + - "src/src/mongo/db/modules/subscription/jstests/**" + - "src/src/mongo/util/options_parser/test_config_files/**" + - "src/src/third_party/JSON-Schema-Test-Suite/tests/draft4/**" + - "src/src/third_party/mock_ocsp_responder/**" + - "src/src/third_party/schemastore.org/**" + - "src/poetry.lock" + - "src/pyproject.toml" exclude_files: - - "*_test.pdb" + - "src/*_test.pdb" - command: s3.put params: diff --git a/etc/evergreen_yml_components/variants/codecoverage/test_dev.yml b/etc/evergreen_yml_components/variants/codecoverage/test_dev.yml index 88b7e0f46ca..30b578ac7fa 100644 --- a/etc/evergreen_yml_components/variants/codecoverage/test_dev.yml +++ b/etc/evergreen_yml_components/variants/codecoverage/test_dev.yml @@ -27,9 +27,16 @@ buildvariants: timeout_secs: 18000 # 5 hour idle timeout use_scons_cache: false gcov_tool: /opt/mongodbtoolchain/v4/bin/gcov + # The gcov instrumentation saves the path the .gcno files were created in as the default path + # for the .gcda files. In Evergreen the path will start with /data/mci/[Hashed ID]/src/... where + # the hashed ID is unique per task run. GCOV_PREFIX_STRIP is the number of directory levels to + # strip from the top of the default path before appending to the GCOV_PREFIX (if any). + gcov_environment: GCOV_PREFIX=$(pwd)/.. GCOV_PREFIX_STRIP=3 num_scons_link_jobs_available: 0.99 compile_variant: *AL2023-arm64-coverage tasks: &AL2023-arm64-coverage-tasks + # These are carefully and explicitly curated. Do not add more tests/tasks without consulting with DevProd. + # unittests - name: compile_and_package_serial_no_unittests_TG distros: - amazon2023.3-arm64-large @@ -37,6 +44,18 @@ buildvariants: distros: - amazon2023.3-arm64-large - name: bazel_coverage + # jstests + - name: jsCore + - name: fle2 + - name: aggregation + - name: change_streams + - name: replica_sets_jscore_passthrough_gen + - name: sharding_jscore_passthrough_gen + - name: sharded_collections_jscore_passthrough_gen + - name: aggregation_mongos_passthrough + - name: aggregation_sharded_collections_passthrough + - name: change_streams_mongos_sessions_passthrough + - name: fle2_sharding # Variant to support Code Coverage on amd64/x86_64 - name: &rhel-93-64-bit-coverage rhel-93-64-bit-coverage @@ -64,9 +83,16 @@ buildvariants: timeout_secs: 18000 # 5 hour idle timeout use_scons_cache: false gcov_tool: /opt/mongodbtoolchain/v4/bin/gcov + # The gcov instrumentation saves the path the .gcno files were created in as the default path + # for the .gcda files. In Evergreen the path will start with /data/mci/[Hashed ID]/src/... where + # the hashed ID is unique per task run. GCOV_PREFIX_STRIP is the number of directory levels to + # strip from the top of the default path before appending to the GCOV_PREFIX (if any). + gcov_environment: GCOV_PREFIX=$(pwd)/.. GCOV_PREFIX_STRIP=3 num_scons_link_jobs_available: 0.99 compile_variant: *rhel-93-64-bit-coverage tasks: &rhel-93-64-bit-coverage-tasks + # These are carefully and explicitly curated. Do not add more tests/tasks without consulting with DevProd. + # unittests - name: compile_and_package_serial_no_unittests_TG distros: - rhel93-large @@ -74,3 +100,15 @@ buildvariants: distros: - rhel93-large - name: bazel_coverage + # jstests + - name: jsCore + - name: fle2 + - name: aggregation + - name: change_streams + - name: replica_sets_jscore_passthrough_gen + - name: sharding_jscore_passthrough_gen + - name: sharded_collections_jscore_passthrough_gen + - name: aggregation_mongos_passthrough + - name: aggregation_sharded_collections_passthrough + - name: change_streams_mongos_sessions_passthrough + - name: fle2_sharding diff --git a/evergreen/functions/code_coverage_data_process.py b/evergreen/functions/code_coverage_data_process.py index d43f16e45cf..1fa4a249ff4 100755 --- a/evergreen/functions/code_coverage_data_process.py +++ b/evergreen/functions/code_coverage_data_process.py @@ -88,7 +88,6 @@ def main(): workdir = expansions.get("workdir") bazelisk_path = os.path.join(workdir, "tmp", "bazelisk") - bazel_output_location = None if os.path.exists(bazelisk_path): print("Found bazel, looking for output path") proc = subprocess.run( @@ -133,12 +132,20 @@ def main(): else: has_scons_gcno = False - if bazel_output_location: - has_bazel_gcno = any( - True for _ in glob.iglob("./**/*.gcno", root_dir=bazel_output_location, recursive=True) - ) - else: - has_bazel_gcno = False + # because of bazel symlink shenanigans, the bazel gcda and gcno files are put in different + # directories when the GCOV_PREFIX and GCOV_PREFIX_STRIP env vars are used. We manually + # put the gcno files where the gcda files are generated to fix this. + has_bazel_gcno = False + bazel_output_dir = os.path.join(workdir, "bazel-out") + for file in glob.iglob("./**/bazel-out/**/*.gcno", root_dir=workdir, recursive=True): + has_bazel_gcno = True + parts = file.split("bazel-out/") + assert len(parts) == 2, "Something went wrong, path was not split into 2 parts." + old_path = os.path.join(workdir, file) + new_path = os.path.join(bazel_output_dir, parts[1]) + new_dir = os.path.dirname(new_path) + os.makedirs(new_dir, exist_ok=True) + os.rename(old_path, new_path) if not has_bazel_gcno and not has_bazel_gcno: print("No gcno files were found. Something went wrong.") @@ -198,11 +205,12 @@ def main(): ] if has_bazel_gcno: - args.append(bazel_output_location) + args.append(bazel_output_dir) if has_scons_gcno: args.append(scons_build_dir) + print("Running gcovr command") process = subprocess.run( args, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8" )