From cbd1bd5dad5cfce22dd4c1632d181f9b86cde5e8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 23 Dec 2020 19:15:00 -0500 Subject: [PATCH] Tests: Fix some VPI coverage holes --- test_regress/t/t_cover_lib_1.out | 6 +-- test_regress/t/t_cover_lib_2.out | 4 +- test_regress/t/t_cover_lib_3.out | 4 +- test_regress/t/t_cover_lib_c.cpp | 9 ----- test_regress/t/t_vpi_module.cpp | 9 +++++ test_regress/t/t_vpi_time_cb.cpp | 69 +++++++++++++++++++++++--------- test_regress/t/t_vpi_unimpl.cpp | 21 ++++++++++ test_regress/t/t_vpi_var.cpp | 1 + 8 files changed, 88 insertions(+), 35 deletions(-) diff --git a/test_regress/t/t_cover_lib_1.out b/test_regress/t/t_cover_lib_1.out index d757bf25a..71fdbee4b 100644 --- a/test_regress/t/t_cover_lib_1.out +++ b/test_regress/t/t_cover_lib_1.out @@ -1,4 +1,4 @@ # SystemC::Coverage-3 -C 'f../../t/t_cover_lib_c.cppl44pagesp_user/t_cover_lib_cokept_onehmain' 100 -C 'f../../t/t_cover_lib_c.cppl45pagesp_user/t_cover_lib_cokept_twohmain' 210 -C 'f../../t/t_cover_lib_c.cppl46pagesp_user/t_cover_lib_colost_threehmain' 220 +C 'f../../t/t_cover_lib_c.cppl35pagesp_user/t_cover_lib_cokept_onehmain' 100 +C 'f../../t/t_cover_lib_c.cppl36pagesp_user/t_cover_lib_cokept_twohmain' 210 +C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_colost_threehmain' 220 diff --git a/test_regress/t/t_cover_lib_2.out b/test_regress/t/t_cover_lib_2.out index 42ec9a18e..445668d78 100644 --- a/test_regress/t/t_cover_lib_2.out +++ b/test_regress/t/t_cover_lib_2.out @@ -1,3 +1,3 @@ # SystemC::Coverage-3 -C 'f../../t/t_cover_lib_c.cppl44pagesp_user/t_cover_lib_cokept_onehmain' 100 -C 'f../../t/t_cover_lib_c.cppl45pagesp_user/t_cover_lib_cokept_twohmain' 210 +C 'f../../t/t_cover_lib_c.cppl35pagesp_user/t_cover_lib_cokept_onehmain' 100 +C 'f../../t/t_cover_lib_c.cppl36pagesp_user/t_cover_lib_cokept_twohmain' 210 diff --git a/test_regress/t/t_cover_lib_3.out b/test_regress/t/t_cover_lib_3.out index 78bddf206..e04cf5d1c 100644 --- a/test_regress/t/t_cover_lib_3.out +++ b/test_regress/t/t_cover_lib_3.out @@ -1,3 +1,3 @@ # SystemC::Coverage-3 -C 'f../../t/t_cover_lib_c.cppl44pagesp_user/t_cover_lib_cokept_onehmain' 0 -C 'f../../t/t_cover_lib_c.cppl45pagesp_user/t_cover_lib_cokept_twohmain' 0 +C 'f../../t/t_cover_lib_c.cppl35pagesp_user/t_cover_lib_cokept_onehmain' 0 +C 'f../../t/t_cover_lib_c.cppl36pagesp_user/t_cover_lib_cokept_twohmain' 0 diff --git a/test_regress/t/t_cover_lib_c.cpp b/test_regress/t/t_cover_lib_c.cpp index 8b288fad9..a9168e483 100644 --- a/test_regress/t/t_cover_lib_c.cpp +++ b/test_regress/t/t_cover_lib_c.cpp @@ -24,15 +24,6 @@ double sc_time_stamp() { return 0; } int failure = 0; -#define CHECK_RESULT_HEX(got, exp) \ - do { \ - if ((got) != (exp)) { \ - std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \ - << ": GOT=" << (got) << " EXP=" << (exp) << std::endl; \ - failure = __LINE__; \ - } \ - } while (0) - //====================================================================== const char* name() { return "main"; } diff --git a/test_regress/t/t_vpi_module.cpp b/test_regress/t/t_vpi_module.cpp index b6c5aa40b..0d9922f51 100644 --- a/test_regress/t/t_vpi_module.cpp +++ b/test_regress/t/t_vpi_module.cpp @@ -54,6 +54,13 @@ unsigned int main_time = 0; return __LINE__; \ } +#define CHECK_RESULT(got, exp) \ + if ((got) != (exp)) { \ + std::cout << std::dec << "%Error: " << FILENM << ":" << __LINE__ << ": GOT = " << (got) \ + << " EXP = " << (exp) << std::endl; \ + return __LINE__; \ + } + #define CHECK_RESULT_CSTR(got, exp) \ if (strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ @@ -81,6 +88,7 @@ int mon_check() { TestVpiHandle topmod = vpi_scan(it); CHECK_RESULT_NZ(topmod); + CHECK_RESULT(vpi_get(vpiType, topmod), vpiModule); const char* t_name = vpi_get_str(vpiName, topmod); CHECK_RESULT_NZ(t_name); @@ -89,6 +97,7 @@ int mon_check() { if (strcmp(t_name, "top") == 0) { it = vpi_iterate(vpiModule, topmod); CHECK_RESULT_NZ(it); + CHECK_RESULT(vpi_get(vpiType, it), vpiModule); topmod = vpi_scan(it); t_name = vpi_get_str(vpiName, topmod); CHECK_RESULT_NZ(t_name); diff --git a/test_regress/t/t_vpi_time_cb.cpp b/test_regress/t/t_vpi_time_cb.cpp index e5e16e0d4..54d61a4a1 100644 --- a/test_regress/t/t_vpi_time_cb.cpp +++ b/test_regress/t/t_vpi_time_cb.cpp @@ -89,6 +89,10 @@ unsigned int callback_count_start_of_sim = 0; #ifdef IS_VPI +static int _never_cb(p_cb_data cb_data) { + CHECK_RESULT(0, 1); // Should never get called +} + static int _time_cb1(p_cb_data cb_data) { s_vpi_time t; t.type = vpiSimTime; @@ -99,14 +103,28 @@ static int _time_cb1(p_cb_data cb_data) { t_cb_data cb_data_n; bzero(&cb_data_n, sizeof(cb_data_n)); - - cb_data_n.reason = cbAfterDelay; - t.type = vpiSimTime; - t.high = 0; - t.low = 1; - cb_data_n.time = &t; - cb_data_n.cb_rtn = _time_cb1; - TestVpiHandle cb_data_n1_h = vpi_register_cb(&cb_data_n); + { + cb_data_n.reason = cbAfterDelay; + t.type = vpiSimTime; + t.high = 0; + t.low = 1; + cb_data_n.time = &t; + cb_data_n.cb_rtn = _time_cb1; + TestVpiHandle cb_data_n1_h = vpi_register_cb(&cb_data_n); + CHECK_RESULT(vpi_get(vpiType, cb_data_n1_h), vpiCallback); + } + { + // Test cancelling a callback + cb_data_n.reason = cbAfterDelay; + t.type = vpiSimTime; + t.high = 0; + t.low = 1; + cb_data_n.time = &t; + cb_data_n.cb_rtn = _never_cb; + TestVpiHandle cb_h = vpi_register_cb(&cb_data_n); + vpi_remove_cb(cb_h); + cb_h.freed(); + } return 0; } @@ -128,6 +146,7 @@ static int _time_cb2(p_cb_data cb_data) { cb_data_n.time = &t; cb_data_n.cb_rtn = _time_cb2; TestVpiHandle cb_data_n2_h = vpi_register_cb(&cb_data_n); + CHECK_RESULT(vpi_get(vpiType, cb_data_n2_h), vpiCallback); return 0; } @@ -144,6 +163,7 @@ static int _start_of_sim_cb(p_cb_data cb_data) { cb_data_n1.time = &t1; cb_data_n1.cb_rtn = _time_cb1; TestVpiHandle cb_data_n1_h = vpi_register_cb(&cb_data_n1); + CHECK_RESULT(vpi_get(vpiType, cb_data_n1_h), vpiCallback); cb_data_n2.reason = cbAfterDelay; t2.type = vpiSimTime; @@ -172,17 +192,28 @@ void vpi_compat_bootstrap(void) { // clang-format on t_cb_data cb_data; bzero(&cb_data, sizeof(cb_data)); - - // VL_PRINTF("register start-of-sim callback\n"); - cb_data.reason = cbStartOfSimulation; - cb_data.time = 0; - cb_data.cb_rtn = _start_of_sim_cb; - TestVpiHandle _start_of_sim_cb_h = vpi_register_cb(&cb_data); - - cb_data.reason = cbEndOfSimulation; - cb_data.time = 0; - cb_data.cb_rtn = _end_of_sim_cb; - TestVpiHandle _end_of_sim_cb_h = vpi_register_cb(&cb_data); + { + // VL_PRINTF("register start-of-sim callback\n"); + cb_data.reason = cbStartOfSimulation; + cb_data.time = 0; + cb_data.cb_rtn = _start_of_sim_cb; + TestVpiHandle _start_of_sim_cb_h = vpi_register_cb(&cb_data); + } + { + cb_data.reason = cbEndOfSimulation; + cb_data.time = 0; + cb_data.cb_rtn = _end_of_sim_cb; + TestVpiHandle _end_of_sim_cb_h = vpi_register_cb(&cb_data); + } + { + // Test cancelling a callback + cb_data.reason = cbStartOfSimulation; + cb_data.time = 0; + cb_data.cb_rtn = _never_cb; + TestVpiHandle cb_h = vpi_register_cb(&cb_data); + vpi_remove_cb(cb_h); + cb_h.freed(); + } } // icarus entry diff --git a/test_regress/t/t_vpi_unimpl.cpp b/test_regress/t/t_vpi_unimpl.cpp index 53cdde2c5..9c7e1ec3a 100644 --- a/test_regress/t/t_vpi_unimpl.cpp +++ b/test_regress/t/t_vpi_unimpl.cpp @@ -45,6 +45,12 @@ unsigned int callback_count = 0; return __LINE__; \ } +#define CHECK_RESULT_Z(got) \ + if (got) { \ + printf("%%Error: %s:%d: GOT = !NULL EXP = NULL\n", FILENM, __LINE__); \ + return __LINE__; \ + } + // Use cout to avoid issues with %d/%lx etc #define CHECK_RESULT(got, exp) \ if ((got) != (exp)) { \ @@ -72,6 +78,7 @@ unsigned int callback_count = 0; int _mon_check_unimpl(p_cb_data cb_data) { static TestVpiHandle cb, clk_h; vpiHandle handle; + const char* cp = nullptr; if (cb_data) { // this is the callback s_vpi_error_info info; @@ -151,6 +158,20 @@ int _mon_check_unimpl(p_cb_data cb_data) { handle = vpi_register_cb(&cb_data_s); CHECK_RESULT(callback_count, 24); CHECK_RESULT(handle, 0); + + (void)vpi_get_str(vpiRange, clk_h); // Bad type + CHECK_RESULT(callback_count, 25); + + // Supported but illegal tests: + // Various checks that guarded passing NULL handles + handle = vpi_scan(NULL); + CHECK_RESULT(handle, 0); + (void)vpi_get(vpiType, NULL); + (void)vpi_get(vpiDirection, NULL); + (void)vpi_get(vpiVector, NULL); + cp = vpi_get_str(vpiType, NULL); + CHECK_RESULT_Z(cp); + vpi_release_handle(NULL); } return 0; // Ok } diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index b09f9b3dd..cf948643b 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -338,6 +338,7 @@ int _mon_check_varlist() { TestVpiHandle vh10 = vpi_iterate(vpiReg, vh2); CHECK_RESULT_NZ(vh10); + CHECK_RESULT(vpi_get(vpiType, vh10), vpiIterator); { TestVpiHandle vh11 = vpi_scan(vh10);