Skip to content

Commit 94af1da

Browse files
karthiknadigCopilot
andcommitted
test: preserve native server coverage profiles (Refs #529)
Keep LLVM_PROFILE_FILE in isolated PET subprocess environments so normal EOF shutdown writes profiles into the coverage collector instead of untracked default files. Preserve fixture overrides and minimal environment isolation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d9ee6aa commit 94af1da

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

‎crates/pet/tests/jsonrpc_client.rs‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ static REQUEST_ID: AtomicU32 = AtomicU32::new(1);
2020

2121
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
2222

23+
pub(crate) fn configure_isolated_pet_environment(command: &mut Command) {
24+
command.env_clear().env("PATH", "");
25+
26+
if let Some(value) = std::env::var_os("LLVM_PROFILE_FILE") {
27+
command.env("LLVM_PROFILE_FILE", value);
28+
}
29+
30+
#[cfg(windows)]
31+
for name in ["SYSTEMROOT", "SYSTEMDRIVE"] {
32+
if let Some(value) = std::env::var_os(name) {
33+
command.env(name, value);
34+
}
35+
}
36+
}
37+
2338
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
2439
#[serde(rename_all = "camelCase")]
2540
pub struct RefreshResult {
@@ -121,19 +136,11 @@ impl PetJsonRpcClient {
121136
cmd.arg("server")
122137
.stdin(Stdio::piped())
123138
.stdout(Stdio::piped())
124-
.stderr(Stdio::piped())
125-
// Clear all inherited env vars to prevent host-specific tool
126-
// configuration from leaking into the test environment, then
127-
// restore only the minimum required for the OS to function.
128-
.env_clear()
129-
.env("PATH", "")
130-
.envs(environment.iter().copied());
131-
#[cfg(windows)]
132-
for name in ["SYSTEMROOT", "SYSTEMDRIVE"] {
133-
if let Some(value) = std::env::var_os(name) {
134-
cmd.env(name, value);
135-
}
136-
}
139+
.stderr(Stdio::piped());
140+
configure_isolated_pet_environment(&mut cmd);
141+
// Explicit fixture variables take precedence over the runner values
142+
// retained by the isolated environment.
143+
cmd.envs(environment.iter().copied());
137144
let mut process = cmd
138145
.spawn()
139146
.map_err(|e| format!("Failed to spawn pet server: {e}"))?;

‎crates/pet/tests/jsonrpc_server_test.rs‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@ impl RawRpcClient {
3030
.arg("server")
3131
.stdin(Stdio::piped())
3232
.stdout(Stdio::piped())
33-
.stderr(Stdio::inherit())
34-
.env_clear()
35-
.env("PATH", "");
36-
#[cfg(windows)]
37-
for name in ["SYSTEMROOT", "SYSTEMDRIVE"] {
38-
if let Some(value) = std::env::var_os(name) {
39-
command.env(name, value);
40-
}
41-
}
33+
.stderr(Stdio::inherit());
34+
jsonrpc_client::configure_isolated_pet_environment(&mut command);
4235
let mut child = command.spawn().expect("raw fixture must spawn PET");
4336
let stdout = child.stdout.take().expect("PET stdout must be piped");
4437
let (sender, responses) = mpsc::channel();
@@ -516,15 +509,8 @@ impl ShutdownFixture {
516509
.arg("server")
517510
.stdin(Stdio::piped())
518511
.stdout(Stdio::piped())
519-
.stderr(Stdio::piped())
520-
.env_clear()
521-
.env("PATH", "");
522-
#[cfg(windows)]
523-
for name in ["SYSTEMROOT", "SYSTEMDRIVE"] {
524-
if let Some(value) = std::env::var_os(name) {
525-
command.env(name, value);
526-
}
527-
}
512+
.stderr(Stdio::piped());
513+
jsonrpc_client::configure_isolated_pet_environment(&mut command);
528514
Self {
529515
child: command.spawn().expect("shutdown fixture must spawn PET"),
530516
}

0 commit comments

Comments
 (0)