diff --git a/test_c/sim_main.cpp b/test_c/sim_main.cpp index a53851a6a..965bdadcc 100644 --- a/test_c/sim_main.cpp +++ b/test_c/sim_main.cpp @@ -39,7 +39,7 @@ int main(int argc, char **argv, char **env) { top->clk = 0; top->passed = 0; - while (main_time < 60 && !top->passed) { + while (main_time < 60 && !top->passed && !Verilated::gotFinish()) { if ((main_time % 10) == 3) { // Toggle clock top->clk = 1; @@ -55,7 +55,7 @@ int main(int argc, char **argv, char **env) { top->eval(); // Evaluate model #if VM_TRACE - tfp->dump (main_time); // Create waveform trace for this timestamp + if (tfp) tfp->dump (main_time); // Create waveform trace for this timestamp #endif // Read outputs @@ -70,7 +70,7 @@ int main(int argc, char **argv, char **env) { top->final(); #if VM_TRACE - tfp->close(); + if (tfp) tfp->close(); #endif if (!top->passed) { diff --git a/test_regress/driver.pl b/test_regress/driver.pl index ba28eabd4..f87bbd786 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -807,7 +807,7 @@ sub _make_main { if ($self->{trace}) { $fh->print("#if VM_TRACE\n"); - $fh->print(" tfp->close();\n"); + $fh->print(" if (tfp) tfp->close();\n"); $fh->print("#endif //VM_TRACE\n"); } $fh->print("\n"); @@ -840,7 +840,7 @@ sub _print_advance_time { print $fh " ${set}eval();\n"; if ($self->{trace} && !$self->{sp}) { $fh->print("#if VM_TRACE\n"); - $fh->print(" tfp->dump (main_time);\n"); + $fh->print(" if (tfp) tfp->dump (main_time);\n"); $fh->print("#endif //VM_TRACE\n"); } } diff --git a/test_sp/sc_main.cpp b/test_sp/sc_main.cpp index 661a32d56..712e6d01c 100644 --- a/test_sp/sc_main.cpp +++ b/test_sp/sc_main.cpp @@ -134,11 +134,11 @@ int sc_main(int argc, char* argv[]) { cout <<("Test beginning...\n"); reset_l = 1; - while (VL_TIME_Q() < 60 && !passed) { + while (VL_TIME_Q() < 60 && !passed && !Verilated::gotFinish()) { #if WAVES // Flush the wave files each cycle so we can immediately see the output // Don't do this in "real" programs, do it in a abort() handler instead - tfp->flush(); + if (tfp) tfp->flush(); #endif if (VL_TIME_Q() > 10) { reset_l = 1; // Deassert reset @@ -157,7 +157,7 @@ int sc_main(int argc, char* argv[]) { //========== // Close Waves #if WAVES - tfp->close(); + if (tfp) tfp->close(); #endif if (!passed) {