mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
Fix bugs
This commit is contained in:
@@ -10,7 +10,7 @@ int two_dimension_array(int n, int nonce) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
for (int j = 0; i < n; ++i) {
|
for (int j = 0; j < n; ++j) {
|
||||||
two_dimension_array_arr[i] += two_dimension_array_arr[j];
|
two_dimension_array_arr[i] += two_dimension_array_arr[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/tests.rs
39
src/tests.rs
@@ -139,16 +139,11 @@ pub fn test_irgen(path: &Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute compiled executable
|
// Execute compiled executable
|
||||||
let mut child = Command::new(fs::canonicalize(bin_path.clone()).unwrap())
|
let mut child = Command::new(fs::canonicalize(bin_path).unwrap())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("failed to execute the compiled executable");
|
.expect("failed to execute the compiled executable");
|
||||||
|
|
||||||
Command::new("rm")
|
|
||||||
.arg(bin_path)
|
|
||||||
.status()
|
|
||||||
.expect("failed to remove compiled executable");
|
|
||||||
|
|
||||||
let status = some_or!(
|
let status = some_or!(
|
||||||
child
|
child
|
||||||
.wait_timeout_ms(500)
|
.wait_timeout_ms(500)
|
||||||
@@ -311,18 +306,22 @@ pub fn test_asmgen(path: &Path) {
|
|||||||
assert_eq!(width, 32);
|
assert_eq!(width, 32);
|
||||||
assert!(is_signed);
|
assert!(is_signed);
|
||||||
|
|
||||||
let asm_path = path.with_extension("S").as_path().display().to_string();
|
let temp_dir = tempdir().expect("temp dir creation failed");
|
||||||
let mut buffer = File::create(Path::new(&asm_path)).expect("need to success creating file");
|
let asm_path = temp_dir.path().join("temp.S");
|
||||||
write(&asm, &mut buffer).unwrap();
|
let asm_path_str = asm_path.as_path().display().to_string();
|
||||||
|
let bin_path_str = asm_path
|
||||||
// Link to an RISC-V executable
|
|
||||||
let bin_path = path
|
|
||||||
.with_extension("asmgen")
|
.with_extension("asmgen")
|
||||||
.as_path()
|
.as_path()
|
||||||
.display()
|
.display()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
|
// Create the assembly code
|
||||||
|
let mut buffer = File::create(asm_path.as_path()).expect("need to success creating file");
|
||||||
|
write(&asm, &mut buffer).unwrap();
|
||||||
|
|
||||||
|
// Compile the assembly code
|
||||||
if !Command::new("riscv64-linux-gnu-gcc-10")
|
if !Command::new("riscv64-linux-gnu-gcc-10")
|
||||||
.args(&["-static", &asm_path, "-o", &bin_path])
|
.args(&["-static", &asm_path_str, "-o", &bin_path_str])
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.status()
|
.status()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -331,23 +330,13 @@ pub fn test_asmgen(path: &Path) {
|
|||||||
::std::process::exit(SKIP_TEST);
|
::std::process::exit(SKIP_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::new("rm")
|
|
||||||
.arg(asm_path)
|
|
||||||
.status()
|
|
||||||
.expect("failed to remove assembly code file");
|
|
||||||
|
|
||||||
// Emulate the executable
|
// Emulate the executable
|
||||||
let mut child = Command::new("qemu-riscv64-static")
|
let mut child = Command::new("qemu-riscv64-static")
|
||||||
.args(&[&bin_path])
|
.args(&[&bin_path_str])
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("failed to execute the compiled executable");
|
.expect("failed to execute the compiled executable");
|
||||||
|
|
||||||
Command::new("rm")
|
|
||||||
.arg(bin_path)
|
|
||||||
.status()
|
|
||||||
.expect("failed to remove compiled executable");
|
|
||||||
|
|
||||||
let status = some_or!(
|
let status = some_or!(
|
||||||
child
|
child
|
||||||
.wait_timeout_ms(500)
|
.wait_timeout_ms(500)
|
||||||
@@ -372,6 +361,8 @@ pub fn test_asmgen(path: &Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let qemu_status = some_or_exit!(status.code(), SKIP_TEST);
|
let qemu_status = some_or_exit!(status.code(), SKIP_TEST);
|
||||||
|
drop(buffer);
|
||||||
|
temp_dir.close().expect("temp dir deletion failed");
|
||||||
|
|
||||||
println!("kecc interp: {}, qemu: {}", value as u8, qemu_status as u8);
|
println!("kecc interp: {}, qemu: {}", value as u8, qemu_status as u8);
|
||||||
assert_eq!(value as u8, qemu_status as u8);
|
assert_eq!(value as u8, qemu_status as u8);
|
||||||
|
|||||||
Reference in New Issue
Block a user