From e96cfc5e563fc513ddaf7f7e878688ad0f294133 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Tue, 11 Aug 2026 15:14:01 -0400 Subject: [PATCH] Tests: More VPI simulator support (#8083) --- test_regress/t/TestSimulator.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test_regress/t/TestSimulator.h b/test_regress/t/TestSimulator.h index ea999e2c3..5f6584804 100644 --- a/test_regress/t/TestSimulator.h +++ b/test_regress/t/TestSimulator.h @@ -40,6 +40,8 @@ public: m_simulators.vcs = true; } else if (0 == strcmp(m_info.product, "ModelSim for Questa-64")) { m_simulators.questa = true; + } else if (0 == strncmp(m_info.product, "xmsim", std::strlen("xmsim"))) { + m_simulators.ncsim = true; } else { printf("%%Warning: %s:%d: Unknown simulator in TestSimulator.h: %s\n", __FILE__, __LINE__, m_info.product); @@ -68,11 +70,25 @@ public: static bool has_get_scalar() { return !simulators().icarus; } // return test level scope static const char* top() { - if (simulators().verilator || simulators().icarus || simulators().questa) { - return "t"; - } else { - return "top.t"; + // Tests built with make_top_shell=False have no "top" wrapper module, + // so probe the design rather than assuming one is present + static const char* s_topp = nullptr; + if (!s_topp) { + const char* const defaultTopp + = (simulators().verilator || simulators().icarus || simulators().questa) ? "t" + : "top.t"; + s_topp = defaultTopp; + if (vpiHandle h = vpi_handle_by_name(const_cast(defaultTopp), NULL)) { + vpi_release_handle(h); + } else { + const char* const other = (0 == std::strcmp(defaultTopp, "t")) ? "top.t" : "t"; + if (vpiHandle oh = vpi_handle_by_name(const_cast(other), NULL)) { + vpi_release_handle(oh); + s_topp = other; + } + } } + return s_topp; } // return absolute scope of obj static const char* rooted(const char* obj) {