use std::io::Write as _;
use std::path::PathBuf;
use std::sync::Once;
static INIT: Once = Once::new();
pub fn setup() {
INIT.call_once(|| {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("error"))
.format(|buf, record| writeln!(buf, "{}", record.args()))
.init();
});
}
pub fn test_data_path(rel: &str) -> String {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../test")
.join(rel)
.to_string_lossy()
.into_owned()
}
pub fn win32_maps_folder() -> String {
let mut s = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../maps/windows/x86")
.to_string_lossy()
.into_owned();
if !s.ends_with('/') {
s.push('/');
}
s
}
pub fn win64_maps_folder() -> String {
let mut s = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../maps/windows/x86_64")
.to_string_lossy()
.into_owned();
if !s.ends_with('/') {
s.push('/');
}
s
}
pub fn critical_values(bits: u32) -> Vec<u64> {
let max = match bits {
8 => u8::MAX as u64,
16 => u16::MAX as u64,
32 => u32::MAX as u64,
64 => u64::MAX,
_ => panic!("Unsupported size"),
};
let sign_bit = 1u64 << (bits - 1);
vec![
0,
1,
max,
sign_bit,
sign_bit - 1,
sign_bit + 1,
0x55, 0xAA, 0xFFFFFFFFFFFFFFFFu64 >> (64 - bits), ]
}
pub fn shift_counts(bits: u32) -> Vec<u64> {
vec![
0,
1,
bits as u64 - 1,
bits as u64,
bits as u64 + 1,
63,
64,
127,
]
}