diff --git a/.github/workflows/coprocessor-cargo-tests.yml b/.github/workflows/coprocessor-cargo-tests.yml index 0947dbd10..4b9c5fef2 100644 --- a/.github/workflows/coprocessor-cargo-tests.yml +++ b/.github/workflows/coprocessor-cargo-tests.yml @@ -53,7 +53,13 @@ jobs: - name: Setup Rust uses: dtolnay/rust-toolchain@a54c7afa936fefeb4456b2dd8068152669aa8203 with: - toolchain: stable + toolchain: "1.91.1" + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@a37010ded18ff788be4440302bd6830b1ae50d8b # v2.68.25 + with: + tool: cargo-llvm-cov - name: Install cargo dependencies run: | @@ -71,8 +77,8 @@ jobs: ~/.cargo/registry ~/.cargo/git target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- + key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-coverage- - name: Login to GitHub Container Registry uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 @@ -101,7 +107,36 @@ jobs: run: | docker run --rm -d -p 4566:4566 --name localstack localstack/localstack:latest - - name: Run tests + - name: Clean previous coverage data + run: cargo llvm-cov clean --workspace --profile coverage + working-directory: coprocessor/fhevm-engine + + - name: Run tests with coverage + run: | + DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor \ + TEST_GLOBAL_LOCALSTACK=1 \ + cargo llvm-cov --no-report --workspace --profile coverage -- --test-threads=1 + working-directory: coprocessor/fhevm-engine + + - name: Generate coverage report + if: always() run: | - DATABASE_URL=postgresql://postgres:postgres@localhost:5432/coprocessor TEST_GLOBAL_LOCALSTACK=1 cargo test --release -- --test-threads=1 + if cargo llvm-cov report --profile coverage > /tmp/cov-report.txt 2>&1; then + REPORT=$(cat /tmp/cov-report.txt) + else + echo "cargo llvm-cov report failed:" + cat /tmp/cov-report.txt + REPORT="" + fi + { + echo '## Coverage: coprocessor/fhevm-engine' + if [ -n "$REPORT" ]; then + echo '```' + echo "$REPORT" + echo '```' + else + echo '*No coverage data available (tests may have failed before producing profiling data).*' + fi + } >> "$GITHUB_STEP_SUMMARY" + echo "$REPORT" working-directory: coprocessor/fhevm-engine diff --git a/coprocessor/fhevm-engine/Cargo.toml b/coprocessor/fhevm-engine/Cargo.toml index 433b56a5a..afa5c0e0b 100644 --- a/coprocessor/fhevm-engine/Cargo.toml +++ b/coprocessor/fhevm-engine/Cargo.toml @@ -111,3 +111,10 @@ inherits = "release" opt-level = 1 lto = false codegen-units = 16 + +[profile.coverage] +inherits = "release" +opt-level = 1 +lto = false +debug = 1 +codegen-units = 16 diff --git a/coprocessor/fhevm-engine/rust-toolchain.toml b/coprocessor/fhevm-engine/rust-toolchain.toml index d6d338197..32d69cb59 100644 --- a/coprocessor/fhevm-engine/rust-toolchain.toml +++ b/coprocessor/fhevm-engine/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "1.91.1" +components = ["llvm-tools-preview"]