Skip to content

Commit f1f1ced

Browse files
FrancoGiachettaDiegoCivigabrielbosio
authored
Speedup tests (#1421)
* use cargo-nextest instead of cargo test * parallelize tests run in cairo-native-bin-utils * Update .github/workflows/ci.yml Co-authored-by: DiegoC <90105443+DiegoCivi@users.noreply.github.com> * remove nextest config * fix secp256_get_point_from_x and secp256_new implementation * fix workflow * allow specifying amount of jobs * clippy * Use --cargo-profile ci with nextest to preserve ci build profile * Use cargo llvm-cov nextest for coverage while keeping run for binary --------- Co-authored-by: DiegoC <90105443+DiegoCivi@users.noreply.github.com> Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com> Co-authored-by: gabrielbosio <gabrielbosio95@gmail.com>
1 parent 63a7bc1 commit f1f1ced

7 files changed

Lines changed: 29 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ jobs:
116116
RUST_LOG: cairo_native=debug,cairo_native_test=debug
117117
steps:
118118
- uses: actions/checkout@v4
119+
- name: Install testing tools
120+
uses: taiki-e/install-action@v2
121+
with:
122+
tool: cargo-nextest
119123
- name: check and free hdd space left
120124
run: |
121125
echo "Listing 20 largest packages"
@@ -167,6 +171,10 @@ jobs:
167171
RUST_LOG: cairo_native=debug,cairo_native_test=debug
168172
steps:
169173
- uses: actions/checkout@v4
174+
- name: Install testing tools
175+
uses: taiki-e/install-action@v2
176+
with:
177+
tool: cargo-nextest
170178
- name: Rustup toolchain install
171179
uses: dtolnay/rust-toolchain@1.84.1
172180
with:

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,28 @@ check: check-llvm
6464

6565
.PHONY: test
6666
test: check-llvm
67-
cargo test --profile ci --features=with-cheatcode,with-debug-utils,testing
67+
cargo nextest run --cargo-profile ci --features=with-cheatcode,with-debug-utils,testing
6868

6969
.PHONY: test-cairo
7070
test-cairo: check-llvm
7171
bash ./scripts/test_cairo.sh
7272

7373
.PHONY: proptest
7474
proptest: check-llvm
75-
cargo test --profile ci --features=with-cheatcode,with-debug-utils,testing proptest
75+
cargo nextest run --cargo-profile ci --features=with-cheatcode,with-debug-utils,testing proptest
7676

7777
.PHONY: test-cli
7878
test-ci: check-llvm
79-
cargo test --profile ci --features=with-cheatcode,with-debug-utils,testing
79+
cargo nextest run --cargo-profile ci --features=with-cheatcode,with-debug-utils,testing
8080

8181
.PHONY: proptest-cli
8282
proptest-ci: check-llvm
83-
cargo test --profile ci --features=with-cheatcode,with-debug-utils,testing proptest
83+
cargo nextest run --cargo-profile ci --features=with-cheatcode,with-debug-utils,testing proptest
8484

8585
.PHONY: coverage
8686
coverage: check-llvm
87-
cargo llvm-cov --verbose --profile ci --features=with-cheatcode,with-debug-utils,testing --workspace --lcov --output-path lcov.info
88-
cargo llvm-cov --verbose --profile ci --features=with-cheatcode,with-debug-utils,testing --lcov --output-path lcov-test.info run --package cairo-native-test -- corelib
87+
cargo llvm-cov nextest --verbose --profile ci --features=with-cheatcode,with-debug-utils,testing --workspace --lcov --output-path lcov.info
88+
cargo llvm-cov run --verbose --profile ci --features=with-cheatcode,with-debug-utils,testing --lcov --output-path lcov-test.info --package cairo-native-test -- corelib
8989

9090
.PHONY: doc
9191
doc: check-llvm

binaries/cairo-native-bin-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ num-traits.workspace = true
2222
scarb-metadata.workspace = true
2323
starknet-types-core.workspace = true
2424
tracing.workspace = true
25+
rayon.workspace = true

binaries/cairo-native-bin-utils/src/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use cairo_native::{
2020
use colored::Colorize;
2121
use itertools::Itertools;
2222
use num_traits::ToPrimitive;
23+
use rayon::iter::{IntoParallelIterator, ParallelIterator};
2324
#[cfg(feature = "scarb")]
2425
use scarb_metadata::{PackageMetadata, TargetMetadata};
2526
use starknet_types_core::felt::Felt;
@@ -212,8 +213,9 @@ pub fn run_tests(
212213
failed_run_results: vec![],
213214
mismatch_reason: vec![],
214215
}));
216+
215217
named_tests
216-
.into_iter()
218+
.into_par_iter()
217219
.map(
218220
|(name, test)| -> anyhow::Result<(String, Option<TestResult>)> {
219221
if test.ignored {

binaries/cairo-native-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ cairo-lang-test-plugin.workspace = true
99
cairo-lang-test-runner.workspace = true
1010
cairo-native-bin-utils = { workspace = true, features = ["with-cheatcode"] }
1111
clap = { workspace = true, features = ["derive"] }
12+
rayon = { workspace = true }
1213
tracing-subscriber = { workspace = true, features = ["env-filter"]}
1314
tracing.workspace = true

binaries/cairo-native-test/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct Args {
4141
/// Compares test result with Cairo VM.
4242
#[arg(long, default_value_t = false)]
4343
compare_with_cairo_vm: bool,
44+
#[arg(short = 'j', long)]
45+
jobs: Option<u8>,
4446
}
4547

4648
fn main() -> anyhow::Result<()> {
@@ -54,6 +56,12 @@ fn main() -> anyhow::Result<()> {
5456
.finish(),
5557
)?;
5658

59+
if let Some(num_jobs) = args.jobs {
60+
rayon::ThreadPoolBuilder::new()
61+
.num_threads(num_jobs as usize)
62+
.build_global()?;
63+
}
64+
5765
check_compiler_path(args.single_file, &args.path)?;
5866

5967
let compiler = TestCompiler::try_new(

0 commit comments

Comments
 (0)