Skip to content

Commit 14cb24f

Browse files
feat: skip tests requiring sudo if GITHUB_ACTIONS is not set
Also add a rebuild trigger to make it easier to run GITHUB_ACTIONS=1 cargo test` locally. We could have a better trigger, but this will do for now.
1 parent 3d7bfa1 commit 14cb24f

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

AGENTS.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@ cargo build
1717
# Build in release mode
1818
cargo build --release
1919

20-
# Run tests (prefer nextest if available)
21-
cargo nextest run # preferred if installed
22-
cargo test # fallback if nextest is not available
20+
# Run tests
21+
cargo test
2322

2423
# Run specific test
25-
cargo nextest run <test_name> # with nextest
26-
cargo test <test_name> # with cargo test
24+
cargo test <test_name>
2725

2826
# Run tests with output
29-
cargo nextest run --nocapture # with nextest
30-
cargo test -- --nocapture # with cargo test
27+
cargo test -- -nocapture
3128
```
3229

33-
**Note**: Always check if `cargo nextest` is available first (with `cargo nextest --version` or `which cargo-nextest`). If available, use it instead of `cargo test` as it provides faster and more reliable test execution.
34-
3530
### Running the Application
3631

3732
```bash
@@ -99,7 +94,7 @@ The core functionality for running benchmarks:
9994

10095
The project uses:
10196

102-
- `cargo nextest` (preferred) or standard Rust `cargo test`
97+
- `cargo test`
10398
- `insta` for snapshot testing
10499
- `rstest` for parameterized tests
105100
- `temp-env` for environment variable testing
@@ -108,5 +103,4 @@ Test files include snapshots in `snapshots/` directories for various run environ
108103

109104
**Important**:
110105

111-
- Always prefer `cargo nextest run` over `cargo test` when running tests, as it provides better performance and reliability.
112-
- Some walltime executor tests require `sudo` access and will fail in non-interactive environments (e.g., `test_walltime_executor::*`). These failures are expected if sudo is not available.
106+
- Some tests require `sudo` access. They are skipped by default unless the `GITHUB_ACTIONS` env var is set.

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ This ensures only stable runner releases are marked as "latest" in GitHub.
9696
## Known issue
9797

9898
- If one of the crates is currenlty in beta version, for example the runner is in beta version 4.4.2-beta.1, any alpha release will fail for the any crate, saying that only minor, major or patch releases is supported.
99+
100+
## Testing
101+
102+
- Some tests require `sudo` access. They are skipped by default unless the `GITHUB_ACTIONS` env var is set.

build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
// Force a rebuild of the test target to be able to run the full test suite locally just by
3+
// setting GITHUB_ACTIONS=1 in the environment.
4+
// This is because `test_with` is evaluated at build time
5+
println!("cargo::rerun-if-env-changed=GITHUB_ACTIONS");
6+
}

crates/memtrack/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ use std::{env, path::PathBuf};
33

44
#[cfg(feature = "ebpf")]
55
fn build_ebpf() {
6+
// Force a rebuild of the test target to be able to run the full test suite locally just by
7+
// setting GITHUB_ACTIONS=1 in the environment.
8+
// This is because `test_with` is evaluated at build time
9+
println!("cargo::rerun-if-env-changed=GITHUB_ACTIONS");
10+
611
use libbpf_cargo::SkeletonBuilder;
712

813
println!("cargo:rerun-if-changed=src/ebpf/c");

src/executor/tests.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use super::Config;
22
use crate::executor::ExecutionContext;
33
use crate::executor::Executor;
4-
use crate::executor::memory::executor::MemoryExecutor;
5-
use crate::executor::valgrind::executor::ValgrindExecutor;
6-
use crate::executor::wall_time::executor::WallTimeExecutor;
74
use crate::runner_mode::RunnerMode;
85
use crate::system::SystemInfo;
96
use rstest_reuse::{self, *};
@@ -109,16 +106,6 @@ const ENV_TESTS: [(&str, &str); 8] = [
109106
#[case(TESTS[5])]
110107
fn test_cases(#[case] cmd: &str) {}
111108

112-
// Exec-harness currently does not support the inline multi command scripts
113-
#[template]
114-
#[rstest::rstest]
115-
#[case(TESTS[0])]
116-
#[case(TESTS[1])]
117-
#[case(TESTS[2])]
118-
fn exec_harness_test_cases() -> Vec<&'static str> {
119-
EXEC_HARNESS_COMMANDS.to_vec()
120-
}
121-
122109
#[template]
123110
#[rstest::rstest]
124111
#[case(ENV_TESTS[0])]
@@ -182,6 +169,7 @@ async fn acquire_bpf_instrumentation_lock() -> SemaphorePermit<'static> {
182169

183170
mod valgrind {
184171
use super::*;
172+
use crate::executor::valgrind::executor::ValgrindExecutor;
185173

186174
async fn get_valgrind_executor() -> (SemaphorePermit<'static>, &'static ValgrindExecutor) {
187175
static VALGRIND_EXECUTOR: OnceCell<ValgrindExecutor> = OnceCell::const_new();
@@ -240,8 +228,10 @@ mod valgrind {
240228
}
241229
}
242230

231+
#[test_with::env(GITHUB_ACTIONS)]
243232
mod walltime {
244233
use super::*;
234+
use crate::executor::wall_time::executor::WallTimeExecutor;
245235

246236
async fn get_walltime_executor() -> (SemaphorePermit<'static>, WallTimeExecutor) {
247237
static WALLTIME_INIT: OnceCell<()> = OnceCell::const_new();
@@ -358,6 +348,16 @@ fi
358348
})
359349
.await;
360350
}
351+
//
352+
// Exec-harness currently does not support the inline multi command scripts
353+
#[template]
354+
#[rstest::rstest]
355+
#[case(TESTS[0])]
356+
#[case(TESTS[1])]
357+
#[case(TESTS[2])]
358+
fn exec_harness_test_cases() -> Vec<&'static str> {
359+
EXEC_HARNESS_COMMANDS.to_vec()
360+
}
361361

362362
// Ensure that the walltime executor works with the exec-harness
363363
#[apply(exec_harness_test_cases)]
@@ -391,8 +391,10 @@ fi
391391
}
392392
}
393393

394+
#[test_with::env(GITHUB_ACTIONS)]
394395
mod memory {
395396
use super::*;
397+
use crate::executor::memory::executor::MemoryExecutor;
396398

397399
async fn get_memory_executor() -> (
398400
SemaphorePermit<'static>,

0 commit comments

Comments
 (0)