Fix testing code

This commit is contained in:
Janggun Lee
2025-02-25 16:20:11 +09:00
parent 7047e17e10
commit 0b01588b6d
3 changed files with 29 additions and 22 deletions

View File

@@ -192,7 +192,11 @@ pub struct Block {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Instruction {
Nop,
// TODO: Explain what this is, why this is needed.
/// A value, used for "simple copy".
///
/// This is only used during phi elimination for Asmgen. You can ignore this before that. In
/// particular, you will need this instruction to properly generate assembly for `lost_copy.c`
/// and `swap.c`.
Value {
value: Operand,
},

View File

@@ -1,5 +1,5 @@
use std::fs::{self, File};
use std::io::{Read, Write, stderr};
use std::io::{self, Read, Write};
use std::path::Path;
use std::process::{Command, Stdio};
use std::time::Duration;
@@ -193,10 +193,13 @@ pub fn test_irgen(path: &Path) {
// be nullified. So, we truncate the result value to byte size one more time here.
println!("clang (expected): {}, kecc: {}", status as u8, value as u8);
if status as u8 != value as u8 {
stderr().lock().write_fmt(format_args!(
let mut stderr = io::stderr().lock();
stderr.write_fmt(format_args!(
"[irgen] Failed to correctly generate {path:?}.\n\n [incorrect ir]"
));
write(&ir, &mut stderr()).unwrap();
write(&ir, &mut stderr).unwrap();
drop(stderr);
panic!("[irgen]");
}
}
@@ -277,23 +280,20 @@ pub fn test_opt<P1: AsRef<Path>, P2: AsRef<Path>, O: Optimize<ir::TranslationUni
let _ = opt.optimize(&mut ir);
if !ir.is_equiv(&to) {
stderr()
.lock()
let mut stderr = io::stderr().lock();
stderr
.write_fmt(format_args!(
"[test_opt] actual outcome mismatches with the expected outcome.\n\n[before opt]"
))
.unwrap();
write(&from, &mut stderr()).unwrap();
stderr()
.lock()
.write_fmt(format_args!("\n[after opt]"))
.unwrap();
write(&ir, &mut stderr()).unwrap();
stderr()
.lock()
write(&from, &mut stderr).unwrap();
stderr.write_fmt(format_args!("\n[after opt]")).unwrap();
write(&ir, &mut stderr).unwrap();
stderr
.write_fmt(format_args!("\n[after opt (expected)]"))
.unwrap();
write(&to, &mut stderr()).unwrap();
write(&to, &mut stderr).unwrap();
drop(stderr);
panic!("[test_opt]");
}
}

View File

@@ -90,7 +90,7 @@ fn test_examples_write_c() {
test_dir(Path::new("examples/c"), OsStr::new("c"), |path| {
if !path.to_str().unwrap().contains(HELLO_MAIN) {
println!("[testing write_c for {path:?}]");
test_write_c(path)
test_write_c(path);
}
});
}
@@ -103,7 +103,7 @@ fn test_examples_irgen_small() {
let path_str = &path.to_str().expect("`path` must be transformed to `&str`");
if !IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) && !path_str.contains(HELLO_MAIN) {
println!("[testing irgen for {path:?}]");
test_irgen(path)
test_irgen(path);
}
});
}
@@ -114,7 +114,7 @@ fn test_examples_irgen_large() {
let path_str = &path.to_str().expect("`path` must be transformed to `&str`");
if IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) && !path_str.contains(HELLO_MAIN) {
println!("[testing irgen for {path:?}]");
test_irgen(path)
test_irgen(path);
}
});
}
@@ -217,7 +217,7 @@ fn test_examples_asmgen_small() {
test_dir(Path::new(dir), OsStr::new("ir"), |path| {
if path.to_str().unwrap().contains(HELLO_MAIN) {
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
test_asmgen(path);
}
});
}
@@ -231,7 +231,7 @@ fn test_examples_asmgen_small() {
if !ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) && !file_name.contains(HELLO_MAIN)
{
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
test_asmgen(path);
}
});
}
@@ -249,7 +249,7 @@ fn test_examples_asmgen_large() {
if ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) && !file_name.contains(HELLO_MAIN)
{
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
test_asmgen(path);
}
});
}
@@ -257,5 +257,8 @@ fn test_examples_asmgen_large() {
#[test]
fn test_examples_end_to_end() {
test_dir(Path::new("examples/c"), OsStr::new("c"), test_end_to_end);
test_dir(Path::new("examples/c"), OsStr::new("c"), |path| {
println!("[testing end-to-end for {path:?}]");
test_end_to_end(path);
});
}