Add HW 7
This commit is contained in:
1 parent
0bf71ed374
commit
8963ac82d5
13 files changed
+5206
No files matched your search
@@ -0,0 +1,33 @@
|
||||
//! Set Python's hash seed before the interpreter (including the validator) starts.
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn configure(seed: u64) {
|
||||
// Python accepts only 32-bit hash seeds; the simulator keeps the full u64 seed.
|
||||
let hash_seed = (seed as u32).to_string();
|
||||
if env::var("PYTHONHASHSEED").as_deref() == Ok(hash_seed.as_str()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Restart with an inherited environment instead of changing it at runtime:
|
||||
// on Windows, Rust and CPython can use different copies of the environment.
|
||||
let mut command = Command::new(env::current_exe().expect("cannot locate test executable"));
|
||||
command
|
||||
.args(env::args_os().skip(1))
|
||||
.env("PYTHONHASHSEED", hash_seed);
|
||||
|
||||
// Preserve the PID so timeout/signals still reach the test process directly.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
let error = command.exec();
|
||||
panic!("cannot restart tests with PYTHONHASHSEED: {error}");
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let status = command
|
||||
.status()
|
||||
.expect("cannot restart tests with PYTHONHASHSEED");
|
||||
std::process::exit(status.code().unwrap_or(1));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user