Skip to content

Commit 1c27363

Browse files
committed
chore: dont run valgrind and memory tests at the same time
1 parent 77c736b commit 1c27363

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

src/run/runner/tests.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,38 @@ async fn create_test_setup() -> (SystemInfo, RunData, TempDir) {
130130
(system_info, run_data, temp_dir)
131131
}
132132

133+
// Uprobes set by memtrack, lead to crashes in valgrind because they work by setting breakpoints on the first
134+
// instruction. Valgrind doesn't rethrow those breakpoint exceptions, which makes the test crash.
135+
//
136+
// Therefore, we can only execute either valgrind or memtrack at any time, and not both at the same time.
137+
static BPF_INSTRUMENTATION_LOCK: OnceCell<Semaphore> = OnceCell::const_new();
138+
139+
async fn acquire_bpf_instrumentation_lock() -> SemaphorePermit<'static> {
140+
let semaphore = BPF_INSTRUMENTATION_LOCK
141+
.get_or_init(|| async { Semaphore::new(1) })
142+
.await;
143+
semaphore.acquire().await.unwrap()
144+
}
145+
133146
mod valgrind {
134147
use super::*;
135148

136-
async fn get_valgrind_executor() -> &'static ValgrindExecutor {
149+
async fn get_valgrind_executor() -> (SemaphorePermit<'static>, &'static ValgrindExecutor) {
137150
static VALGRIND_EXECUTOR: OnceCell<ValgrindExecutor> = OnceCell::const_new();
138151

139-
VALGRIND_EXECUTOR
152+
let executor = VALGRIND_EXECUTOR
140153
.get_or_init(|| async {
141154
let executor = ValgrindExecutor;
142155
let system_info = SystemInfo::new().unwrap();
143156
executor.setup(&system_info, None).await.unwrap();
144157
executor
145158
})
146-
.await
159+
.await;
160+
let _lock = acquire_bpf_instrumentation_lock().await;
161+
162+
(_lock, executor)
147163
}
148164

149-
#[cfg(test)]
150165
fn valgrind_config(command: &str) -> Config {
151166
Config {
152167
mode: RunnerMode::Simulation,
@@ -159,7 +174,7 @@ mod valgrind {
159174
#[test_log::test(tokio::test)]
160175
async fn test_valgrind_executor(#[case] cmd: &str) {
161176
let (system_info, run_data, _temp_dir) = create_test_setup().await;
162-
let executor = get_valgrind_executor().await;
177+
let (_lock, executor) = get_valgrind_executor().await;
163178

164179
let config = valgrind_config(cmd);
165180
executor
@@ -172,7 +187,7 @@ mod valgrind {
172187
#[test_log::test(tokio::test)]
173188
async fn test_valgrind_executor_with_env(#[case] env_case: (&str, &str)) {
174189
let (system_info, run_data, _temp_dir) = create_test_setup().await;
175-
let executor = get_valgrind_executor().await;
190+
let (_lock, executor) = get_valgrind_executor().await;
176191

177192
let (env_var, env_value) = env_case;
178193
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {
@@ -304,7 +319,11 @@ fi
304319
mod memory {
305320
use super::*;
306321

307-
async fn get_memory_executor() -> (SemaphorePermit<'static>, MemoryExecutor) {
322+
async fn get_memory_executor() -> (
323+
SemaphorePermit<'static>,
324+
SemaphorePermit<'static>,
325+
MemoryExecutor,
326+
) {
308327
static MEMORY_INIT: OnceCell<()> = OnceCell::const_new();
309328
static MEMORY_SEMAPHORE: OnceCell<Semaphore> = OnceCell::const_new();
310329

@@ -321,10 +340,12 @@ mod memory {
321340
.await;
322341
let permit = semaphore.acquire().await.unwrap();
323342

324-
(permit, MemoryExecutor)
343+
// Memory executor uses heaptrack which uses BPF-based instrumentation, which conflicts with valgrind.
344+
let _lock = acquire_bpf_instrumentation_lock().await;
345+
346+
(permit, _lock, MemoryExecutor)
325347
}
326348

327-
#[cfg(test)]
328349
fn memory_config(command: &str) -> Config {
329350
Config {
330351
mode: RunnerMode::Memory,
@@ -337,7 +358,7 @@ mod memory {
337358
#[test_log::test(tokio::test)]
338359
async fn test_memory_executor(#[case] cmd: &str) {
339360
let (system_info, run_data, _temp_dir) = create_test_setup().await;
340-
let (_permit, executor) = get_memory_executor().await;
361+
let (_permit, _lock, executor) = get_memory_executor().await;
341362

342363
let config = memory_config(cmd);
343364
executor
@@ -350,7 +371,7 @@ mod memory {
350371
#[test_log::test(tokio::test)]
351372
async fn test_memory_executor_with_env(#[case] env_case: (&str, &str)) {
352373
let (system_info, run_data, _temp_dir) = create_test_setup().await;
353-
let (_permit, executor) = get_memory_executor().await;
374+
let (_permit, _lock, executor) = get_memory_executor().await;
354375

355376
let (env_var, env_value) = env_case;
356377
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {

0 commit comments

Comments
 (0)