From 6e3b957b30c4f850515ef0a8051f8b487bdef66a Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 31 Jan 2023 19:24:30 -0500 Subject: [PATCH] Tests: Add iterate check (#3919) --- test_regress/t/TestSimulator.h | 3 ++- test_regress/t/t_vpi_var.cpp | 46 +++++++++++++++++++++++++++++++++- test_regress/t/t_vpi_var.v | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/test_regress/t/TestSimulator.h b/test_regress/t/TestSimulator.h index 5c49404f4..0f3659440 100644 --- a/test_regress/t/TestSimulator.h +++ b/test_regress/t/TestSimulator.h @@ -74,7 +74,8 @@ public: static const char* rooted(const char* obj) { static std::string buf; std::ostringstream os; - os << top() << "." << obj; + os << top(); + if (*obj) os << "." << obj; buf = os.str(); return buf.c_str(); } diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index 5f28eb0d5..4a0e1b0f7 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -389,6 +389,8 @@ int _mon_check_varlist() { int _mon_check_getput() { TestVpiHandle vh2 = VPI_HANDLE("onebit"); CHECK_RESULT_NZ(vh2); + const char* p = vpi_get_str(vpiFullName, vh2); + CHECK_RESULT_CSTR(p, "t.onebit"); s_vpi_value v; v.format = vpiIntVal; @@ -399,15 +401,56 @@ int _mon_check_getput() { t.type = vpiSimTime; t.high = 0; t.low = 0; + v.value.integer = 0; + vpi_put_value(vh2, &v, &t, vpiNoDelay); + vpi_get_value(vh2, &v); + CHECK_RESULT(v.value.integer, 0); + v.value.integer = 1; vpi_put_value(vh2, &v, &t, vpiNoDelay); - vpi_get_value(vh2, &v); CHECK_RESULT(v.value.integer, 1); return 0; } +int _mon_check_getput_iter() { + TestVpiHandle vh2 = VPI_HANDLE("sub"); + CHECK_RESULT_NZ(vh2); + TestVpiHandle vh10 = vpi_iterate(vpiReg, vh2); + CHECK_RESULT_NZ(vh10); + CHECK_RESULT(vpi_get(vpiType, vh10), vpiIterator); + + TestVpiHandle vh11; + while (1) { + vh11 = vpi_scan(vh10); + CHECK_RESULT_NZ(vh11); // If get zero we never found the variable + const char* p = vpi_get_str(vpiFullName, vh11); +#ifdef TEST_VERBOSE + printf(" scanned %s\n", p); +#endif + if (0 == strcmp(p, "t.sub.subsig1")) break; + } + CHECK_RESULT(vpi_get(vpiType, vh11), vpiReg); + + s_vpi_time t; + t.type = vpiSimTime; + t.high = 0; + t.low = 0; + s_vpi_value v; + v.format = vpiIntVal; + v.value.integer = 0; + vpi_put_value(vh11, &v, &t, vpiNoDelay); + vpi_get_value(vh11, &v); + CHECK_RESULT(v.value.integer, 0); + + v.value.integer = 1; + vpi_put_value(vh11, &v, &t, vpiNoDelay); + vpi_get_value(vh11, &v); + CHECK_RESULT(v.value.integer, 1); + return 0; +} + int _mon_check_quad() { TestVpiHandle vh2 = VPI_HANDLE("quads"); CHECK_RESULT_NZ(vh2); @@ -651,6 +694,7 @@ extern "C" int mon_check() { if (int status = _mon_check_var()) return status; if (int status = _mon_check_varlist()) return status; if (int status = _mon_check_getput()) return status; + if (int status = _mon_check_getput_iter()) return status; if (int status = _mon_check_quad()) return status; if (int status = _mon_check_string()) return status; if (int status = _mon_check_putget_str(NULL)) return status; diff --git a/test_regress/t/t_vpi_var.v b/test_regress/t/t_vpi_var.v index 672f987fc..b01d6699b 100644 --- a/test_regress/t/t_vpi_var.v +++ b/test_regress/t/t_vpi_var.v @@ -100,7 +100,7 @@ extern "C" int mon_check(); endmodule : t module sub; - reg subsig1 /*verilator public_flat_rd*/; + reg subsig1 /*verilator public_flat_rw*/; reg subsig2 /*verilator public_flat_rd*/; `ifdef IVERILOG // stop icarus optimizing signals away