Skip to content

Commit

Permalink
Merge pull request #1533 from mintlayer/fix/increase_coverage_partitions
Browse files Browse the repository at this point in the history
Increase coverage partitions count
  • Loading branch information
TheQuantumPhysicist authored Feb 5, 2024
2 parents 7dc9999 + cb6b864 commit 0c4f5f7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 56 deletions.
120 changes: 76 additions & 44 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,76 @@
on:
push:
branches:
- "**" # target all branches
pull_request:
branches:
- master

name: Code Coverage

env:
# We partition coverage tests into multiple parts to avoid filling diskspace in a single runner
PARTITIONS_COUNT: 5

jobs:
coverage:
runs-on: ubuntu-latest

strategy:
matrix:
# This range spans from `0` to `PARTITIONS_COUNT - 1`, where `PARTITIONS_COUNT` is the number of partitions (defined in env var above)
partition: [0, 1, 2, 3, 4]

steps:
- name: Install dependencies
run: sudo apt-get install -yqq build-essential libgtk-3-dev python3 python3-toml
- uses: actions/checkout@v1
- name: Install rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2023-11-01
- name: Run cargo clean
run: cargo clean
- name: Install grcov from cargo
run: cargo install grcov

- name: Run coverage tests
run: python3 build-tools/workspace-partition.py ${{ env.PARTITIONS_COUNT }} ${{ matrix.partition }} | xargs -I {} sh -c 'CARGO_INCREMENTAL=0 RUST_BACKTRACE=full RUST_LOG=debug RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off" RUSTDOCFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off" RUSTUP_TOOLCHAIN=nightly-2023-11-01 cargo test'

- name: Collect coverage data with grcov
run: grcov . --source-dir . --output-type lcov --branch --ignore-not-existing --binary-path ./target/debug/ -o grcov-report-${{ matrix.partition }}

- uses: actions/upload-artifact@v2
with:
name: code-coverage-report-${{ matrix.partition }}
path: grcov-report-${{ matrix.partition }}
# on:
# push:
# branches:
# - "**" # target all branches
# pull_request:
# branches:
# - master

# name: Code Coverage

# env:
# # We partition coverage tests into multiple parts to avoid filling diskspace in a single runner
# PARTITIONS_COUNT: 30

# jobs:
# coverage:
# runs-on: ubuntu-latest

# strategy:
# matrix:
# # This range spans from `0` to `PARTITIONS_COUNT - 1`, where `PARTITIONS_COUNT` is the number of partitions (defined in env var above)
# partition:
# [
# 0,
# 1,
# 2,
# 3,
# 4,
# 5,
# 6,
# 7,
# 8,
# 9,
# 10,
# 11,
# 12,
# 13,
# 14,
# 15,
# 16,
# 17,
# 18,
# 19,
# 20,
# 21,
# 22,
# 23,
# 24,
# 25,
# 26,
# 27,
# 28,
# 29,
# ]

# steps:
# - name: Install dependencies
# run: sudo apt-get install -yqq build-essential libgtk-3-dev python3 python3-toml
# - uses: actions/checkout@v1
# - name: Install rust
# run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2023-11-01
# - name: Run cargo clean
# run: cargo clean
# - name: Install grcov from cargo
# run: cargo install grcov

# - name: Run coverage tests
# run: python3 build-tools/workspace-partition.py ${{ env.PARTITIONS_COUNT }} ${{ matrix.partition }} | xargs -I {} sh -c 'CARGO_INCREMENTAL=0 RUST_BACKTRACE=full RUST_LOG=debug RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off" RUSTDOCFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off" RUSTUP_TOOLCHAIN=nightly-2023-11-01 cargo test'

# - name: Collect coverage data with grcov
# run: grcov . --source-dir . --output-type lcov --branch --ignore-not-existing --binary-path ./target/debug/ -o grcov-report-${{ matrix.partition }}

# - uses: actions/upload-artifact@v2
# with:
# name: code-coverage-report-${{ matrix.partition }}
# path: grcov-report-${{ matrix.partition }}
34 changes: 22 additions & 12 deletions build-tools/workspace-partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@ def get_package_name(crate_dir):
else:
raise Exception("Cargo.toml not found for crate {}.".format(crate_dir))

def group_crates_by_first_directory(members):
def group_crates_by_first_directory(members, do_group: bool):
'''
Here we ensure that all crates in the same directory are grouped together, to minimize fracturing of coverage.
We assume here that crates are tested within their directory. This is a fair assumption since we put test-suites
in the same directory as the crate they are testing.
This can be disabled with do_group boolean. In that case, groups will be the same crate dirs.
'''
crate_groups = {}
for crate_dir in members:
# Split the path name with the directory separator
dir_parts = crate_dir.split(os.path.sep)
if dir_parts:
# Group crates by the first element and join them back using the separator
dir_name = os.path.sep.join(dir_parts[:1])
if dir_name not in crate_groups:
crate_groups[dir_name] = []
crate_groups[dir_name].append(crate_dir)

if do_group:
crate_groups = {}
for crate_dir in members:
# Split the path name with the directory separator
dir_parts = crate_dir.split(os.path.sep)
if dir_parts:
# Group crates by the first element and join them back using the separator
dir_name = os.path.sep.join(dir_parts[:1])
if dir_name not in crate_groups:
crate_groups[dir_name] = []
crate_groups[dir_name].append(crate_dir)
else:
crate_groups = {}
for crate_dir in members:
crate_groups[crate_dir] = []
crate_groups[crate_dir].append(crate_dir)
return crate_groups

def partition_workspace(m, n):
Expand All @@ -48,7 +57,8 @@ def partition_workspace(m, n):
raise Exception("No members found in the workspace.")

# Group crates based on directory structure using directory separators
crate_directory_groups = group_crates_by_first_directory(members)
# This was disabled because we still are having disk-space issues
crate_directory_groups = group_crates_by_first_directory(members, False)

# Calculate elements per partition and remainder based on the number of crate directories
total_directories = len(crate_directory_groups)
Expand Down

0 comments on commit 0c4f5f7

Please sign in to comment.