Skip to content

Commit 609ad98

Browse files
committed
fix: cmd with system env var
1 parent 332c5f9 commit 609ad98

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/run/runner/tests.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ const BENCHMARK_COMMANDS: [&str; 5] = [
2828
DIRECTORY_CHECK_SCRIPT,
2929
];
3030

31+
const ENV_VAR_VALIDATION_SCRIPT: &str = "
32+
output=$(echo \"$MY_ENV_VAR\")
33+
if [ \"$output\" != \"Hello\" ]; then
34+
echo \"Assertion failed: Expected 'Hello' but got '$output'\"
35+
exit 1
36+
fi";
37+
38+
const ENV_COMMANDS: [(&str, &str, &str); 1] = [("MY_ENV_VAR", "Hello", ENV_VAR_VALIDATION_SCRIPT)];
39+
3140
async fn create_test_setup() -> (SystemInfo, RunData, TempDir) {
3241
let temp_dir = TempDir::new().unwrap();
3342

@@ -93,3 +102,55 @@ async fn test_walltime_executor() {
93102
}
94103
}
95104
}
105+
106+
#[tokio::test]
107+
async fn test_valgrind_executor_with_env() {
108+
let (system_info, run_data, _temp_dir) = create_test_setup().await;
109+
110+
let executor = ValgrindExecutor;
111+
executor.setup(&system_info).await.unwrap();
112+
113+
let config = Config {
114+
mode: RunnerMode::Instrumentation,
115+
..Config::test()
116+
};
117+
test_executor_with_env(&executor, config, &system_info, &run_data).await;
118+
}
119+
120+
#[tokio::test]
121+
async fn test_walltime_executor_with_env() {
122+
let (system_info, run_data, _temp_dir) = create_test_setup().await;
123+
124+
let executor = WallTimeExecutor::new();
125+
executor.setup(&system_info).await.unwrap();
126+
127+
for enable_perf in [false, true] {
128+
let config = Config {
129+
mode: RunnerMode::Walltime,
130+
enable_perf,
131+
..Config::test()
132+
};
133+
134+
test_executor_with_env(&executor, config, &system_info, &run_data).await;
135+
}
136+
}
137+
138+
async fn test_executor_with_env(
139+
executor: &dyn Executor,
140+
mut config: Config,
141+
system_info: &SystemInfo,
142+
run_data: &RunData,
143+
) {
144+
for (env_var, env_value, cmd) in ENV_COMMANDS {
145+
eprintln!("Running command: {cmd}");
146+
config.command = cmd.to_string();
147+
148+
temp_env::async_with_vars(&[(env_var, Some(env_value))], async {
149+
executor
150+
.run(&config, system_info, run_data, &None)
151+
.await
152+
.unwrap();
153+
})
154+
.await;
155+
}
156+
}

src/run/runner/wall_time/executor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ impl WallTimeExecutor {
2626
fn walltime_bench_cmd(config: &Config, run_data: &RunData) -> Result<String> {
2727
let bench_cmd = get_bench_command(config)?;
2828

29+
// We have to forward all the environment variables.
30+
let system_env = std::env::vars()
31+
.map(|(env, value)| format!("--setenv={env}=\'{}\'", value.replace("'", "\"")))
32+
.join(" ");
33+
2934
let setenv = get_base_injected_env(RunnerMode::Walltime, &run_data.profile_folder)
3035
.into_iter()
3136
.map(|(env, value)| format!("--setenv={env}={value}"))

0 commit comments

Comments
 (0)