Skip to content

Commit

Permalink
debug windows test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
anisse committed Jun 16, 2024
1 parent e769ebc commit ad3c217
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/fusetests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ fn parse_cpu_regs(input: Vec<&str>, r: &mut cpu::Regs, halted: &mut bool) -> Res
}
}
fn parse_memory_values(input: Vec<&str>, memory_values: &mut Vec<MemValues>) -> Result<(), String> {
println!("parsing {} memory lines", input.len());
for l in input.iter().filter(|l| **l != "-1") {
println!("test line: '{l}'");
let mem: Vec<&str> = l.split_ascii_whitespace().collect();
//parse address and all value
let base_addr = match u16::from_str_radix(mem[0], 16) {
Expand All @@ -154,20 +156,49 @@ fn parse_memory_values(input: Vec<&str>, memory_values: &mut Vec<MemValues>) ->
Ok(())
}

fn hexdump(s: &str) {
let b: Vec<_> = s.bytes().collect();
for line in b.chunks(16) {
for c in line {
print!("{:02x} ", c);
}
for c in line {
let c: char = char::from(*c);
print!("{}", if c.is_alphanumeric() { c } else { '.' });
}
println!();
}
}

fn parse_tests(input: &str, expected: &str) -> Option<Vec<Test>> {
let mut tests = Vec::new();

let inputs: Vec<&str> = input.trim().split("\n\n").collect();
println!("Input: ");
hexdump(&input[..256]);
println!("Input: on disk");
hexdump(&std::fs::read_to_string("tests/fusetests/tests.in").unwrap()[..256]);
let results: Vec<&str> = expected.trim().split("\n\n").collect();
//println!("Expected: ");
//hexdump(expected);
if inputs.len() != results.len() {
panic!(
"Inconsistent test len in {} vs res {}",
inputs.len(),
results.len()
)
}
println!(
"Number of tests: {} (out of {} chars / {} lines)",
inputs.len(),
input.len(),
input.lines().count()
);
for (i, l) in inputs.iter().enumerate() {
let lines: Vec<&str> = l.lines().collect();
println!("Lines in current input test: {}: {lines:?}", lines.len());
let res: Vec<&str> = results[i].lines().collect();
println!("Lines in current result test: {}: {res:?}", res.len());
let mut t = Test::default();
if lines.len() < 5 {
panic!("Not enough lines {:?}", lines)
Expand Down Expand Up @@ -242,9 +273,10 @@ fn parse_tests(input: &str, expected: &str) -> Option<Vec<Test>> {
let memval = res
.into_iter()
.skip(1)
.filter(|l| !l.starts_with(" "))
.filter(|l| !l.starts_with(" ") && !l.is_empty())
.skip(2)
.collect();
println!("Result memval: {memval:?}");
parse_memory_values(memval, &mut t.changed_mem_values)
.unwrap_or_else(|e| panic!("test res {} ({}): {}", t.desc, i, e));
tests.push(t)
Expand Down

0 comments on commit ad3c217

Please sign in to comment.