use crate::spec::types::ParityFailure;
use std::fs;
use std::io::{self, Write};
use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(loom)]
use loom::sync::Mutex as LoomMutex;
use super::hex::*;
fn load_from_dir(dir: &std::path::Path, tag: &str) -> Vec<(String, Vec<u8>)> {
let Ok(entries) = fs::read_dir(dir) else {
return Vec::new();
};
let mut out = Vec::new();
for entry in entries.flatten() {
let path = entry.path();
let label = match path.file_stem().and_then(|stem| stem.to_str()) {
Some(stem) => stem.to_string(),
None => "regression".to_string(),
};
match path.extension().and_then(|ext| ext.to_str()) {
Some("json") => {
if let Ok(text) = fs::read_to_string(&path) {
if let Ok(failure) = serde_json::from_str::<PersistedFailure>(&text) {
out.push((format!("regression:{tag}:{label}"), failure.input));
}
}
}
Some("hex") => {
if let Ok(text) = fs::read_to_string(&path) {
if let Ok(bytes) = decode_hex(text.trim()) {
out.push((format!("regression:{tag}:{label}"), bytes));
}
}
}
Some("bin") => {
if let Ok(bytes) = fs::read(&path) {
out.push((format!("regression:{tag}:{label}"), bytes));
}
}
_ => continue,
}
}
out.sort_by(|a, b| a.0.cmp(&b.0));
out
}