Skip to content

Commit

Permalink
[t1rocket] add rtl unexcepted quit check in difftest
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Aug 13, 2024
1 parent e2c1bed commit 7fbe2de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
15 changes: 8 additions & 7 deletions t1rocketemu/online_drive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ fn main() {
let argc = c_args.len() as c_int;
let argv = c_args_ptr.as_ptr() as *mut *mut c_char;

unsafe {
verilator_main_c(argc, argv);
let verilator_ret = unsafe { verilator_main_c(argc, argv) };

if verilator_ret == 0 {
std::fs::write("perf.txt", format!("total_cycles: {}", online_dpi::get_t()))
.expect("fail to write into perf.txt");
} else {
eprintln!("verilator_main_c return unexpectedly");
}

std::fs::write(
"perf.txt",
format!("total_cycles: {}", online_dpi::get_t()),
)
.expect("fail to write into perf.txt");
std::process::exit(verilator_ret);
}

extern "C" {
Expand Down
23 changes: 16 additions & 7 deletions t1rocketemu/online_drive/verilator_shim/verilator_shim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ class VTestBench;
extern "C" int verilator_main_c(int argc, char **argv) {
// Setup context, defaults, and parse command line
Verilated::debug(0);
VerilatedContext* contextp = new VerilatedContext();

// use unique_ptr to ensure deletion of context and model
std::unique_ptr<VerilatedContext> contextp;
std::unique_ptr<VTestBench> topp;

// Construct the Verilated context
contextp = std::make_unique<VerilatedContext>();
// Construct the Verilated model, from Vtop.h generated from Verilating
topp = std::make_unique<VTestBench>(contextp.get());

contextp->fatalOnError(false);
contextp->commandArgs(argc, argv);
#ifdef VM_TRACE
contextp->traceEverOn(true);
#endif

// Construct the Verilated model, from Vtop.h generated from Verilating
VTestBench* topp = new VTestBench(contextp);

// Simulate until $finish
while (!contextp->gotFinish()) {
// Evaluate model
Expand All @@ -28,13 +34,16 @@ extern "C" int verilator_main_c(int argc, char **argv) {

if (!contextp->gotFinish()) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting without $finish; no events left\n"););
return 1;
}

if (contextp->gotError()) {
VL_DEBUG_IF(VL_PRINTF("+ Exiting due to errors\n"););
return 1;
}

// Final model cleanup
topp->final();

delete topp;
delete contextp;

return 0;
}

0 comments on commit 7fbe2de

Please sign in to comment.