Tests: Fix various test leaks (#2703).

This commit is contained in:
Wilson Snyder 2020-12-15 22:09:40 -05:00
parent c54360485e
commit 084ba6711b
11 changed files with 33 additions and 9 deletions

View File

@ -27,7 +27,11 @@ public:
, m_free(true) {}
~TestVpiHandle() {
if (m_handle && m_free) {
{ vpi_free_object(m_handle); m_handle = NULL; }
// Below not VL_DO_DANGLING so is portable
{
vpi_free_object(m_handle);
m_handle = NULL;
}
}
}
operator vpiHandle() const { return m_handle; }

View File

@ -124,7 +124,7 @@ void dpii_v_ushort(unsigned short i, unsigned short* o) { *o = ~i; }
void dpii_v_longint(long long i, long long* o) { *o = ~i; }
void dpii_v_ulong(unsigned long long i, unsigned long long* o) { *o = ~i; }
void dpii_v_chandle(void* i, void** o) { *o = i; }
void dpii_v_string(const char* i, const char** o) { *o = strdup(i); } // Leaks
void dpii_v_string(const char* i, const char** o) { *o = i; }
void dpii_v_real(double i, double* o) { *o = i + 1.5; }
void dpii_v_shortreal(float i, float* o) { *o = i + 1.5f; }

View File

@ -61,7 +61,23 @@ Vt_embed1_child* __get_modelp() {
vl_fatal(__FILE__, __LINE__, __FILE__, "svPutUserData failed");
}
}
return (Vt_embed1_child*)(__modelp);
return reinterpret_cast<Vt_embed1_child*>(__modelp);
}
void __delete_modelp() {
svScope scope = svGetScope();
if (!scope) {
vl_fatal(__FILE__, __LINE__, __FILE__, "svGetScope failed");
return;
}
void* __modelp = svGetUserData(scope, &T_Embed_Child_Unique);
if (__modelp) {
delete reinterpret_cast<Vt_embed1_child*>(__modelp);
__modelp = nullptr;
if (svPutUserData(scope, &T_Embed_Child_Unique, __modelp)) {
vl_fatal(__FILE__, __LINE__, __FILE__, "svPutUserData failed");
}
}
}
void t_embed_child_initial() {
@ -74,6 +90,7 @@ void t_embed_child_final() {
VL_DEBUG_IF(VL_PRINTF(" t_embed1_child_final\n"););
Vt_embed1_child* __modelp = __get_modelp();
__modelp->final();
__delete_modelp();
}
void t_embed_child_eval() {

View File

@ -161,6 +161,7 @@ int main(int argc, char** argv, char** env) {
tfp->close();
top->final();
VL_DO_DANGLING(delete tfp, tfp);
VL_DO_DANGLING(delete top, top);
VL_PRINTF("*-* All Finished *-*\n");

View File

@ -12,6 +12,7 @@
#include <cstdio>
#include "svdpi.h"
#include "vpi_user.h"
#include "TestVpi.h"
//======================================================================
@ -53,7 +54,7 @@ void show(vpiHandle obj) {
void dpii_check() {
show(0);
vpiHandle mod = vpi_handle_by_name((PLI_BYTE8*)"top.t", NULL);
TestVpiHandle mod = vpi_handle_by_name((PLI_BYTE8*)"top.t", NULL);
if (!mod) {
vpi_printf(const_cast<char*>("-- Cannot vpi_find module\n"));
} else {

View File

@ -47,6 +47,7 @@ int main(int argc, char** argv, char** env) {
tfp->close();
top->final();
VL_DO_DANGLING(delete top, top);
VL_DO_DANGLING(delete tfp, tfp);
printf("*-* All Finished *-*\n");
return 0;
}

View File

@ -206,7 +206,7 @@ int mon_check() {
#ifdef IS_VPI
static int mon_check_vpi() {
vpiHandle href = vpi_handle(vpiSysTfCall, 0);
TestVpiHandle href = vpi_handle(vpiSysTfCall, 0);
s_vpi_value vpi_value;
vpi_value.format = vpiIntVal;

View File

@ -196,7 +196,7 @@ int mon_check() {
#ifdef IS_VPI
static int mon_check_vpi() {
vpiHandle href = vpi_handle(vpiSysTfCall, 0);
TestVpiHandle href = vpi_handle(vpiSysTfCall, 0);
s_vpi_value vpi_value;
vpi_value.format = vpiIntVal;

View File

@ -99,7 +99,7 @@ int mon_check() {
#ifdef IS_VPI
static int mon_check_vpi() {
vpiHandle href = vpi_handle(vpiSysTfCall, 0);
TestVpiHandle href = vpi_handle(vpiSysTfCall, 0);
s_vpi_value vpi_value;
vpi_value.format = vpiIntVal;

View File

@ -214,7 +214,7 @@ int mon_check() {
#ifdef IS_VPI
static int mon_check_vpi() {
vpiHandle href = vpi_handle(vpiSysTfCall, 0);
TestVpiHandle href = vpi_handle(vpiSysTfCall, 0);
s_vpi_value vpi_value;
vpi_value.format = vpiIntVal;

View File

@ -609,7 +609,7 @@ int mon_check() {
#ifdef IS_VPI
static int mon_check_vpi() {
vpiHandle href = vpi_handle(vpiSysTfCall, 0);
TestVpiHandle href = vpi_handle(vpiSysTfCall, 0);
s_vpi_value vpi_value;
vpi_value.format = vpiIntVal;