From 5b3717b369355fa931a962e58fdbfae08f0ac969 Mon Sep 17 00:00:00 2001 From: Tomasz Gorochowik Date: Tue, 17 Nov 2020 12:37:55 +0100 Subject: [PATCH] Tests: Memory clean up in tests (#2645) This patch normalizes what the tests do before exiting. After this change each test should call final on the top module and explicitly free the top module object before exiting. --- test_regress/t/t_clk_2in.cpp | 3 +++ test_regress/t/t_dpi_accessors.cpp | 1 + test_regress/t/t_dpi_export_context2_bad.cpp | 1 + test_regress/t/t_dpi_export_context_bad.cpp | 3 +++ test_regress/t/t_dpi_vams.cpp | 3 +++ test_regress/t/t_enum_public.cpp | 3 +++ test_regress/t/t_flag_fi.cpp | 1 + test_regress/t/t_func_rand.cpp | 2 ++ test_regress/t/t_math_imm2.cpp | 3 +++ test_regress/t/t_mem_multi_io2.cpp | 3 +++ test_regress/t/t_mem_multi_io3.cpp | 3 +++ test_regress/t/t_mem_slot.cpp | 3 +++ test_regress/t/t_multitop_sig.cpp | 4 ++++ test_regress/t/t_order_multidriven.cpp | 4 ++++ test_regress/t/t_order_quad.cpp | 3 ++- test_regress/t/t_param_public.cpp | 3 +++ test_regress/t/t_sc_names.cpp | 1 + test_regress/t/t_scope_map.cpp | 2 ++ test_regress/t/t_timescale.cpp | 1 + test_regress/t/t_timescale_parse.cpp | 1 + test_regress/t/t_trace_cat.cpp | 1 + test_regress/t/t_trace_public_func.cpp | 1 + test_regress/t/t_trace_public_sig.cpp | 1 + test_regress/t/t_tri_gate.cpp | 1 + test_regress/t/t_tri_inout.cpp | 1 + test_regress/t/t_tri_inz.cpp | 1 + test_regress/t/t_tri_pullup.cpp | 1 + test_regress/t/t_tri_select.cpp | 1 + test_regress/t/t_var_pinsizes.cpp | 2 ++ test_regress/t/t_vpi_sc.cpp | 1 + test_regress/t/t_x_assign.cpp | 1 + 31 files changed, 59 insertions(+), 1 deletion(-) diff --git a/test_regress/t/t_clk_2in.cpp b/test_regress/t/t_clk_2in.cpp index ba601f846..fc5a0233f 100644 --- a/test_regress/t/t_clk_2in.cpp +++ b/test_regress/t/t_clk_2in.cpp @@ -50,4 +50,7 @@ int main(int argc, char* argv[]) { } topp->check = 1; clockit(0, 0); + + topp->final(); + VL_DO_DANGLING(delete topp, topp); } diff --git a/test_regress/t/t_dpi_accessors.cpp b/test_regress/t/t_dpi_accessors.cpp index e3f227ab1..c5d7152d9 100644 --- a/test_regress/t/t_dpi_accessors.cpp +++ b/test_regress/t/t_dpi_accessors.cpp @@ -673,6 +673,7 @@ int main() { // Tidy up dut->final(); + VL_DO_DANGLING(delete dut, dut); cout << "*-* All Finished *-*" << endl; } diff --git a/test_regress/t/t_dpi_export_context2_bad.cpp b/test_regress/t/t_dpi_export_context2_bad.cpp index 77ce4668c..ec2b10216 100644 --- a/test_regress/t/t_dpi_export_context2_bad.cpp +++ b/test_regress/t/t_dpi_export_context2_bad.cpp @@ -27,6 +27,7 @@ int main(int argc, char* argv[]) { Verilated::debug(0); topp->eval(); + VL_DO_DANGLING(delete topp, topp); return 1; } int dpii_task() { diff --git a/test_regress/t/t_dpi_export_context_bad.cpp b/test_regress/t/t_dpi_export_context_bad.cpp index a42ceff51..407c8b5b4 100644 --- a/test_regress/t/t_dpi_export_context_bad.cpp +++ b/test_regress/t/t_dpi_export_context_bad.cpp @@ -44,5 +44,8 @@ int main(int argc, char* argv[]) { topp->eval(); dpix_task(); // Missing svSetScope + + topp->final(); + VL_DO_DANGLING(delete topp, topp); return 1; } diff --git a/test_regress/t/t_dpi_vams.cpp b/test_regress/t/t_dpi_vams.cpp index 4722f8636..264eb18cd 100644 --- a/test_regress/t/t_dpi_vams.cpp +++ b/test_regress/t/t_dpi_vams.cpp @@ -51,5 +51,8 @@ int main(int argc, char* argv[]) { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results\n"); } + + topp->final(); + VL_DO_DANGLING(delete topp, topp); return 0; } diff --git a/test_regress/t/t_enum_public.cpp b/test_regress/t/t_enum_public.cpp index 598275ffc..328140331 100644 --- a/test_regress/t/t_enum_public.cpp +++ b/test_regress/t/t_enum_public.cpp @@ -24,4 +24,7 @@ int main(int argc, char* argv[]) { for (int i = 0; i < 10; i++) { // topp->eval(); } + + topp->final(); + VL_DO_DANGLING(delete topp, topp); } diff --git a/test_regress/t/t_flag_fi.cpp b/test_regress/t/t_flag_fi.cpp index 4c0a89ed1..c977decf8 100644 --- a/test_regress/t/t_flag_fi.cpp +++ b/test_regress/t/t_flag_fi.cpp @@ -29,6 +29,7 @@ int main(int argc, char* argv[]) { if (!gotit) { vl_fatal(__FILE__, __LINE__, "dut", "Never got call to myfunction"); } topp->final(); + VL_DO_DANGLING(delete topp, topp); return 0; } diff --git a/test_regress/t/t_func_rand.cpp b/test_regress/t/t_func_rand.cpp index f69fd7243..6a93db0ff 100644 --- a/test_regress/t/t_func_rand.cpp +++ b/test_regress/t/t_func_rand.cpp @@ -24,5 +24,7 @@ int main(int argc, char* argv[]) { if (topp->Rand != 0xfeed0fad) { vl_fatal(__FILE__, __LINE__, "top", "Unexpected value for Rand output\n"); } + topp->final(); + VL_DO_DANGLING(delete topp, topp); printf("*-* All Finished *-*\n"); } diff --git a/test_regress/t/t_math_imm2.cpp b/test_regress/t/t_math_imm2.cpp index 999ef1157..163e797b7 100644 --- a/test_regress/t/t_math_imm2.cpp +++ b/test_regress/t/t_math_imm2.cpp @@ -44,6 +44,9 @@ int main(int argc, char* argv[]) { } } + sim->final(); + VL_DO_DANGLING(delete sim, sim); + if (errs) { vl_stop(__FILE__, __LINE__, "TOP-cpp"); exit(10); diff --git a/test_regress/t/t_mem_multi_io2.cpp b/test_regress/t/t_mem_multi_io2.cpp index 145b02ba3..7c18d04e3 100644 --- a/test_regress/t/t_mem_multi_io2.cpp +++ b/test_regress/t/t_mem_multi_io2.cpp @@ -78,6 +78,9 @@ int main() for (int j = 0; j < 5; j++) check("o345", READ(o345[i][j]), i * 8 + j); } + tb->final(); + VL_DO_DANGLING(delete tb, tb); + if (pass) { VL_PRINTF("*-* All Finished *-*\n"); } else { diff --git a/test_regress/t/t_mem_multi_io3.cpp b/test_regress/t/t_mem_multi_io3.cpp index 9068af3f9..9db98b288 100644 --- a/test_regress/t/t_mem_multi_io3.cpp +++ b/test_regress/t/t_mem_multi_io3.cpp @@ -20,6 +20,9 @@ int main() Verilated::debug(0); tb = new VM_PREFIX("tb"); + tb->final(); + VL_DO_DANGLING(delete tb, tb); + // Just a constructor test VL_PRINTF("*-* All Finished *-*\n"); return 0; diff --git a/test_regress/t/t_mem_slot.cpp b/test_regress/t/t_mem_slot.cpp index 86d3b984e..501c9113f 100644 --- a/test_regress/t/t_mem_slot.cpp +++ b/test_regress/t/t_mem_slot.cpp @@ -55,5 +55,8 @@ int main(int argc, char* argv[]) { for (i = 0; i < 100; i++) // StepSim(sim, random() % 3, random() % 2, random() % 2, random() % 3); + sim->final(); + VL_DO_DANGLING(delete sim, sim); + printf("*-* All Finished *-*\n"); } diff --git a/test_regress/t/t_multitop_sig.cpp b/test_regress/t/t_multitop_sig.cpp index e548d25ad..e89b40853 100644 --- a/test_regress/t/t_multitop_sig.cpp +++ b/test_regress/t/t_multitop_sig.cpp @@ -39,5 +39,9 @@ int main(int argc, char* argv[]) { CHECK_RESULT(topp->b__02Eout, 1); CHECK_RESULT(topp->uniq_out, 0); } + + topp->final(); + VL_DO_DANGLING(delete topp, topp); + printf("*-* All Finished *-*\n"); } diff --git a/test_regress/t/t_order_multidriven.cpp b/test_regress/t/t_order_multidriven.cpp index 8679cdca3..5f6003e4b 100644 --- a/test_regress/t/t_order_multidriven.cpp +++ b/test_regress/t/t_order_multidriven.cpp @@ -56,5 +56,9 @@ int main() { } vcd->close(); + + vcore->final(); + VL_DO_DANGLING(delete vcore, vcore); + printf("*-* All Finished *-*\n"); } diff --git a/test_regress/t/t_order_quad.cpp b/test_regress/t/t_order_quad.cpp index 89773b790..9f6bd98d8 100644 --- a/test_regress/t/t_order_quad.cpp +++ b/test_regress/t/t_order_quad.cpp @@ -38,12 +38,13 @@ int main(int argc, char* argv[]) { topp->eval(); check(topp->y, 0x3c00000000ULL); - topp->final(); if (!fail) { VL_PRINTF("*-* All Finished *-*\n"); topp->final(); } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results\n"); } + + VL_DO_DANGLING(delete topp, topp); return 0; } diff --git a/test_regress/t/t_param_public.cpp b/test_regress/t/t_param_public.cpp index 093d5acb6..f2e158a78 100644 --- a/test_regress/t/t_param_public.cpp +++ b/test_regress/t/t_param_public.cpp @@ -26,4 +26,7 @@ int main(int argc, char* argv[]) { for (int i = 0; i < 10; i++) { // topp->eval(); } + + topp->final(); + VL_DO_DANGLING(delete topp, topp); } diff --git a/test_regress/t/t_sc_names.cpp b/test_regress/t/t_sc_names.cpp index 163916db5..ba71d8c14 100644 --- a/test_regress/t/t_sc_names.cpp +++ b/test_regress/t/t_sc_names.cpp @@ -24,5 +24,6 @@ int sc_main(int argc, char* argv[]) { } else { vl_fatal(__FILE__, __LINE__, "tb", "Unexpected results\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_scope_map.cpp b/test_regress/t/t_scope_map.cpp index 39d28c3d0..020bee9d4 100644 --- a/test_regress/t/t_scope_map.cpp +++ b/test_regress/t/t_scope_map.cpp @@ -161,6 +161,8 @@ int main(int argc, char** argv, char** env) { tfp->close(); top->final(); + VL_DO_DANGLING(delete top, top); + VL_PRINTF("*-* All Finished *-*\n"); return 0; diff --git a/test_regress/t/t_timescale.cpp b/test_regress/t/t_timescale.cpp index 1471cc2d3..f4a673912 100644 --- a/test_regress/t/t_timescale.cpp +++ b/test_regress/t/t_timescale.cpp @@ -50,6 +50,7 @@ int main(int argc, char** argv, char** env) { CHECK_RESULT(VL_TIME_STR_CONVERT(0), 0); top->final(); + VL_DO_DANGLING(delete top, top); printf("*-* All Finished *-*\n"); return 0; } diff --git a/test_regress/t/t_timescale_parse.cpp b/test_regress/t/t_timescale_parse.cpp index eb9fcc18a..c1464fe97 100644 --- a/test_regress/t/t_timescale_parse.cpp +++ b/test_regress/t/t_timescale_parse.cpp @@ -19,4 +19,5 @@ int main() { tb->eval(); tb->final(); + VL_DO_DANGLING(delete tb, tb); } diff --git a/test_regress/t/t_trace_cat.cpp b/test_regress/t/t_trace_cat.cpp index b4a9c6125..c0374121d 100644 --- a/test_regress/t/t_trace_cat.cpp +++ b/test_regress/t/t_trace_cat.cpp @@ -58,6 +58,7 @@ int main(int argc, char** argv, char** env) { } tfp->close(); top->final(); + VL_DO_DANGLING(delete top, top); printf("*-* All Finished *-*\n"); return 0; } diff --git a/test_regress/t/t_trace_public_func.cpp b/test_regress/t/t_trace_public_func.cpp index c43a13dbc..b77045813 100644 --- a/test_regress/t/t_trace_public_func.cpp +++ b/test_regress/t/t_trace_public_func.cpp @@ -46,6 +46,7 @@ int main(int argc, char** argv, char** env) { } tfp->close(); top->final(); + VL_DO_DANGLING(delete top, top); printf("*-* All Finished *-*\n"); return 0; } diff --git a/test_regress/t/t_trace_public_sig.cpp b/test_regress/t/t_trace_public_sig.cpp index 2c996203f..c77db8584 100644 --- a/test_regress/t/t_trace_public_sig.cpp +++ b/test_regress/t/t_trace_public_sig.cpp @@ -46,6 +46,7 @@ int main(int argc, char** argv, char** env) { } tfp->close(); top->final(); + VL_DO_DANGLING(delete top, top); printf("*-* All Finished *-*\n"); return 0; } diff --git a/test_regress/t/t_tri_gate.cpp b/test_regress/t/t_tri_gate.cpp index 6b1c881a6..89810bce7 100644 --- a/test_regress/t/t_tri_gate.cpp +++ b/test_regress/t/t_tri_gate.cpp @@ -54,5 +54,6 @@ int main() { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from tristate test\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_tri_inout.cpp b/test_regress/t/t_tri_inout.cpp index bd0cb1426..6156bfdbf 100644 --- a/test_regress/t/t_tri_inout.cpp +++ b/test_regress/t/t_tri_inout.cpp @@ -54,5 +54,6 @@ int main() { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from inout test\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_tri_inz.cpp b/test_regress/t/t_tri_inz.cpp index 0e47c3b8d..c9393b5f3 100644 --- a/test_regress/t/t_tri_inz.cpp +++ b/test_regress/t/t_tri_inz.cpp @@ -44,5 +44,6 @@ int main() { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from t_tri_inz\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_tri_pullup.cpp b/test_regress/t/t_tri_pullup.cpp index 7885093fd..a85093968 100644 --- a/test_regress/t/t_tri_pullup.cpp +++ b/test_regress/t/t_tri_pullup.cpp @@ -63,5 +63,6 @@ int main() { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from pullup test\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_tri_select.cpp b/test_regress/t/t_tri_select.cpp index d034b85f9..b2efad8fa 100644 --- a/test_regress/t/t_tri_select.cpp +++ b/test_regress/t/t_tri_select.cpp @@ -66,5 +66,6 @@ int main() { } else { vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from t_tri_select\n"); } + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_var_pinsizes.cpp b/test_regress/t/t_var_pinsizes.cpp index 32624893c..a5c75e363 100644 --- a/test_regress/t/t_var_pinsizes.cpp +++ b/test_regress/t/t_var_pinsizes.cpp @@ -15,6 +15,7 @@ int main() { VL_PRINTF("*-* All Finished *-*\n"); tb->final(); + VL_DO_DANGLING(delete tb, tb); return 0; } @@ -23,5 +24,6 @@ int sc_main(int argc, char* argv[]) { VL_PRINTF("*-* All Finished *-*\n"); tb->final(); + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_vpi_sc.cpp b/test_regress/t/t_vpi_sc.cpp index 6cdf5adf9..85c7b9078 100644 --- a/test_regress/t/t_vpi_sc.cpp +++ b/test_regress/t/t_vpi_sc.cpp @@ -12,5 +12,6 @@ int sc_main(int argc, char* argv[]) { VL_PRINTF("*-* All Finished *-*\n"); tb->final(); + VL_DO_DANGLING(delete tb, tb); return 0; } diff --git a/test_regress/t/t_x_assign.cpp b/test_regress/t/t_x_assign.cpp index 760b6f7ec..502301c7c 100644 --- a/test_regress/t/t_x_assign.cpp +++ b/test_regress/t/t_x_assign.cpp @@ -48,6 +48,7 @@ int main(int argc, const char** argv) { exit(1); } + VL_DO_DANGLING(delete top, top); std::cout << "*-* All Finished *-*" << std::endl; return 0; }