Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 32 additions & 34 deletions .github/workflows/rust-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name: rust-tests
# TODO:
# - Split tests from coverage so I can use nightly :'(
# A test matrix should do.
# - Fix coverage creation, doesn't seem to work.
# - Find out where the compilation slowness lies. Maybe just don't optimize, but let's see.

on:
merge_group:
Expand Down Expand Up @@ -99,6 +104,7 @@ jobs:
RPC_ENDPOINT_MAINNET: ${{ secrets.JUNO_ENDPOINT_MAINNET }}
MLIR_SYS_170_PREFIX: /usr/lib/llvm-17/
TABLEGEN_170_PREFIX: /usr/lib/llvm-17/
TEST_COLLECT_COVERAGE: 1
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -162,55 +168,47 @@ jobs:
- name: Run tests (${{ matrix.target }})
run: make ${{ matrix.target }}

- name: Save coverage report
if: ${{ matrix.target != 'test-doctest' }}
uses: actions/cache/save@v3
with:
path: lcov-${{ matrix.target }}.info
key: coverage-cache-${{ github.sha }}-${{ matrix.target }}

coverage:
name: Generate and upload coverage report
name: Upload coverage report
needs: tests
runs-on: ubuntu-latest
env:
TEST_COLLECT_COVERAGE: 1
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Rust nightly
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly

- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Cache coverage report
id: restore-report
- name: Fetch coverage report for test-cairo-1
uses: actions/cache/restore@v3
with:
path: lcov.info
key: coverage-cache-${{ github.sha }}
path: lcov-test-cairo-1.info
key: coverage-cache-${{ github.sha }}-test-cairo-1
fail-on-cache-miss: true

- name: Python3 Build
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- uses: Swatinem/rust-cache@v2
- name: Fetch coverage report for test-cairo-2
uses: actions/cache/restore@v3
with:
cache-on-failure: true
path: lcov-test-cairo-2.info
key: coverage-cache-${{ github.sha }}-test-cairo-2
fail-on-cache-miss: true

- name: Install deps
run: make deps

- name: Generate coverage report
if: steps.restore-report.outputs.cache-hit != 'true'
run: make coverage-report

- name: Save coverage report
if: steps.restore-report.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
- name: Fetch coverage report for test-cairo-native
uses: actions/cache/restore@v3
with:
path: lcov.info
key: coverage-cache-${{ github.sha }}
path: lcov-test-cairo-native.info
key: coverage-cache-${{ github.sha }}-test-cairo-native
fail-on-cache-miss: true

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
files: lcov-test-cairo-1.info lcov-test-cairo-2.info lcov-test-cairo-native.info
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ harness = false
[profile.release]
codegen-units = 1
lto = "fat"

[profile.test]
opt-level = 3
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,30 @@ clean:
clippy: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
cargo clippy --workspace --all-targets --all-features -- -D warnings

TEST_COMMAND:=cargo nextest run
ifdef TEST_COLLECT_COVERAGE
#TEST_COMMAND=cargo +nightly llvm-cov nextest --ignore-filename-regex 'main.rs' --lcov --output-path lcov-$@.info
TEST_COMMAND=cargo llvm-cov nextest --lcov --output-path lcov-$@.info
endif

test: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
echo "Cairo1 tests"
$(MAKE) test-cairo-1
echo "Cairo2 tests"
$(MAKE) test-cairo-2

test-cairo-1: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
cargo nextest run --workspace --all-targets --features=cairo_1_tests,metrics,cairo-native
$(TEST_COMMAND) --workspace --all-targets --features=cairo_1_tests,metrics,cairo-native

test-cairo-2: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
cargo nextest run --workspace --all-targets --features=metrics,cairo-native
$(TEST_COMMAND) --workspace --all-targets --features=metrics,cairo-native

test-cairo-native: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
cargo nextest run --workspace --test cairo_native --features=cairo-native
$(TEST_COMMAND) --workspace --test cairo_native --features=cairo-native

test-doctests:
cargo test --workspace --doc

coverage: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-2-casm
$(MAKE) coverage-report

coverage-report: compile-cairo compile-starknet compile-cairo-1-casm compile-cairo-1-sierra compile-cairo-2-casm compile-cairo-2-sierra
cargo +nightly llvm-cov nextest --lcov --ignore-filename-regex 'main.rs' --output-path lcov.info --release

heaptrack:
./scripts/heaptrack.sh

Expand Down