Tests: Use common TEST_ error reporting.

This commit is contained in:
Wilson Snyder 2021-03-12 12:37:26 -05:00
parent 2feb46fc5d
commit b52b063c16
19 changed files with 315 additions and 425 deletions

View File

@ -15,21 +15,55 @@
extern int errors; extern int errors;
#ifdef TEST_VERBOSE #ifdef TEST_VERBOSE
static bool verbose = true; static const bool verbose = true;
#else #else
static bool verbose = false; static const bool verbose = false;
#endif #endif
//====================================================================== //======================================================================
// Use cout to avoid issues with %d/%lx etc // Use cout to avoid issues with %d/%lx etc
#define TEST_CHECK(got, exp, test) \ #define TEST_CHECK(got, exp, test) \
if (!(test)) { \ do { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \ if (!(test)) { \
<< " EXP = " << (exp) << std::endl; \ std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ \
++errors; \ << ": GOT = " << (got) << " EXP = " << (exp) << std::endl; \
} ++errors; \
} \
} while (0)
#define TEST_CHECK_EQ(got, exp) TEST_CHECK(got, exp, ((got) == (exp))); #define TEST_CHECK_EQ(got, exp) TEST_CHECK(got, exp, ((got) == (exp)));
#define TEST_CHECK_NE(got, exp) TEST_CHECK(got, exp, ((got) != (exp)));
#define TEST_CHECK_CSTR(got, exp) TEST_CHECK(got, exp, 0 == strcmp((got), (exp)));
#define TEST_CHECK_HEX_EQ(got, exp) \
do { \
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
<< ": GOT=" << (got) << " EXP=" << (exp) << std::endl; \
++errors; \
} \
} while (0)
#define TEST_CHECK_HEX_NE(got, exp) \
do { \
if ((got) == (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
<< ": GOT=" << (got) << " EXP!=" << (exp) << std::endl; \
++errors; \
} \
} while (0)
#define TEST_CHECK_NZ(got) \
do { \
if (!(got)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
<< ": GOT= NULL EXP!=NULL" << std::endl; \
++errors; \
} \
} while (0)
//======================================================================
#define TEST_VERBOSE_PRINTF(format, ...) \ #define TEST_VERBOSE_PRINTF(format, ...) \
do { \ do { \

View File

@ -1,4 +1,4 @@
# SystemC::Coverage-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.cppl39pagesp_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.cppl40pagesp_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.cppl41pagesp_user/t_cover_lib_colost_threehmain' 220

View File

@ -1,3 +1,3 @@
# SystemC::Coverage-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.cppl39pagesp_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.cppl40pagesp_user/t_cover_lib_cokept_twohmain' 210

View File

@ -1,3 +1,3 @@
# SystemC::Coverage-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.cppl39pagesp_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.cppl40pagesp_user/t_cover_lib_cokept_twohmain' 0

View File

@ -14,22 +14,17 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
#include "verilated_cov.h" #include "verilated_cov.h"
#include VM_PREFIX_INCLUDE #include VM_PREFIX_INCLUDE
#define CHECK_RESULT_CSTR(got, exp) \
if (strcmp((got), (exp))) { \
printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", __FILE__, __LINE__, \
(got) ? (got) : "<null>", (exp) ? (exp) : "<null>"); \
++failure; \
}
//====================================================================== //======================================================================
double sc_time_stamp() { return 0; } double sc_time_stamp() { return 0; }
int failure = 0; int errors = 0;
//====================================================================== //======================================================================
@ -50,7 +45,7 @@ int main() {
coverw[1] = 220; coverw[1] = 220;
#ifdef T_COVER_LIB #ifdef T_COVER_LIB
CHECK_RESULT_CSTR(covContextp->defaultFilename(), "coverage.dat"); TEST_CHECK_CSTR(covContextp->defaultFilename(), "coverage.dat");
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat"); covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat");
covContextp->clearNonMatch("kept_"); covContextp->clearNonMatch("kept_");
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat"); covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat");
@ -59,7 +54,7 @@ int main() {
covContextp->clear(); covContextp->clear();
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat"); covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat");
#elif defined(T_COVER_LIB_LEGACY) #elif defined(T_COVER_LIB_LEGACY)
CHECK_RESULT_CSTR(VerilatedCov::defaultFilename(), "coverage.dat"); TEST_CHECK_CSTR(VerilatedCov::defaultFilename(), "coverage.dat");
VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat"); VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat");
VerilatedCov::clearNonMatch("kept_"); VerilatedCov::clearNonMatch("kept_");
VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat"); VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat");
@ -72,5 +67,5 @@ int main() {
#endif #endif
printf("*-* All Finished *-*\n"); printf("*-* All Finished *-*\n");
return (failure ? 10 : 0); return (errors ? 10 : 0);
} }

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -40,17 +42,8 @@ extern void dpii_check();
//====================================================================== //======================================================================
int failure = 0; int errors = 0;
int dpii_failure() { return failure; } int dpii_failure() { return errors; }
#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)
//====================================================================== //======================================================================
@ -59,49 +52,49 @@ void dpii_lib_bit_check() {
bv[0] = 0xa3a2a1a0; // 31..0 bv[0] = 0xa3a2a1a0; // 31..0
bv[1] = 0xa7a6a5a4; // 63..32 bv[1] = 0xa7a6a5a4; // 63..32
bv[2] = 0xabaaa9a8; // 95..64 bv[2] = 0xabaaa9a8; // 95..64
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 32), 0); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 32), 0);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 33), 0); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 33), 0);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 34), 1); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 34), 1);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 35), 0); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 35), 0);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 36), 0); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 36), 0);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 37), 1); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 37), 1);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 38), 0); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 38), 0);
CHECK_RESULT_HEX((int)svGetBitselBit(bv, 39), 1); TEST_CHECK_HEX_EQ((int)svGetBitselBit(bv, 39), 1);
svPutBitselBit(bv, 32, 1); svPutBitselBit(bv, 32, 1);
svPutBitselBit(bv, 33, 0); svPutBitselBit(bv, 33, 0);
svPutBitselBit(bv, 34, 1); svPutBitselBit(bv, 34, 1);
svPutBitselBit(bv, 35, 1); svPutBitselBit(bv, 35, 1);
CHECK_RESULT_HEX(bv[0], 0xa3a2a1a0); TEST_CHECK_HEX_EQ(bv[0], 0xa3a2a1a0);
CHECK_RESULT_HEX(bv[1], 0xa7a6a5ad); TEST_CHECK_HEX_EQ(bv[1], 0xa7a6a5ad);
CHECK_RESULT_HEX(bv[2], 0xabaaa9a8); TEST_CHECK_HEX_EQ(bv[2], 0xabaaa9a8);
svBitVecVal btmp[2]; svBitVecVal btmp[2];
svGetPartselBit(btmp, bv, 40, 8); svGetPartselBit(btmp, bv, 40, 8);
CHECK_RESULT_HEX(btmp[0], 0xa5); TEST_CHECK_HEX_EQ(btmp[0], 0xa5);
svGetPartselBit(btmp, bv, 32, 32); svGetPartselBit(btmp, bv, 32, 32);
CHECK_RESULT_HEX(btmp[0], 0xa7a6a5ad); TEST_CHECK_HEX_EQ(btmp[0], 0xa7a6a5ad);
svGetPartselBit(btmp, bv, 48, 40); svGetPartselBit(btmp, bv, 48, 40);
CHECK_RESULT_HEX(btmp[0], 0xa9a8a7a6); TEST_CHECK_HEX_EQ(btmp[0], 0xa9a8a7a6);
CHECK_RESULT_HEX(btmp[1], 0xaa); TEST_CHECK_HEX_EQ(btmp[1], 0xaa);
btmp[0] = 0xa5; btmp[0] = 0xa5;
svPutPartselBit(bv, btmp[0], 48, 8); svPutPartselBit(bv, btmp[0], 48, 8);
CHECK_RESULT_HEX(bv[0], 0xa3a2a1a0); TEST_CHECK_HEX_EQ(bv[0], 0xa3a2a1a0);
CHECK_RESULT_HEX(bv[1], 0xa7a5a5ad); TEST_CHECK_HEX_EQ(bv[1], 0xa7a5a5ad);
CHECK_RESULT_HEX(bv[2], 0xabaaa9a8); TEST_CHECK_HEX_EQ(bv[2], 0xabaaa9a8);
btmp[0] = 0x11223344; btmp[0] = 0x11223344;
svPutPartselBit(bv, btmp[0], 32, 32); svPutPartselBit(bv, btmp[0], 32, 32);
CHECK_RESULT_HEX(bv[0], 0xa3a2a1a0); TEST_CHECK_HEX_EQ(bv[0], 0xa3a2a1a0);
CHECK_RESULT_HEX(bv[1], 0x11223344); TEST_CHECK_HEX_EQ(bv[1], 0x11223344);
CHECK_RESULT_HEX(bv[2], 0xabaaa9a8); TEST_CHECK_HEX_EQ(bv[2], 0xabaaa9a8);
btmp[0] = 0x99887766; btmp[0] = 0x99887766;
svPutPartselBit(bv, btmp[0], 24, 24); svPutPartselBit(bv, btmp[0], 24, 24);
CHECK_RESULT_HEX(bv[0], 0x66a2a1a0); TEST_CHECK_HEX_EQ(bv[0], 0x66a2a1a0);
CHECK_RESULT_HEX(bv[1], 0x11228877); TEST_CHECK_HEX_EQ(bv[1], 0x11228877);
CHECK_RESULT_HEX(bv[2], 0xabaaa9a8); TEST_CHECK_HEX_EQ(bv[2], 0xabaaa9a8);
} }
void dpii_lib_logic_check() { void dpii_lib_logic_check() {
@ -112,68 +105,68 @@ void dpii_lib_logic_check() {
lv[0].bval = 0xc3c2c1c0; // 31..0 lv[0].bval = 0xc3c2c1c0; // 31..0
lv[1].bval = 0xc7c6c5c4; // 63..32 lv[1].bval = 0xc7c6c5c4; // 63..32
lv[2].bval = 0xcbcac9c8; // 95..64 lv[2].bval = 0xcbcac9c8; // 95..64
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 32), 0); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 32), 0);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 33), 0); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 33), 0);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 34), 3); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 34), 3);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 35), 0); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 35), 0);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 36), 1); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 36), 1);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 37), 1); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 37), 1);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 38), 2); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 38), 2);
CHECK_RESULT_HEX((int)svGetBitselLogic(lv, 39), 3); TEST_CHECK_HEX_EQ((int)svGetBitselLogic(lv, 39), 3);
svPutBitselLogic(lv, 32, 1); svPutBitselLogic(lv, 32, 1);
svPutBitselLogic(lv, 33, 0); svPutBitselLogic(lv, 33, 0);
svPutBitselLogic(lv, 34, 1); svPutBitselLogic(lv, 34, 1);
svPutBitselLogic(lv, 35, 3); svPutBitselLogic(lv, 35, 3);
CHECK_RESULT_HEX(lv[0].aval, 0xb3b2b1b0); TEST_CHECK_HEX_EQ(lv[0].aval, 0xb3b2b1b0);
CHECK_RESULT_HEX(lv[1].aval, 0xb7b6b5bd); TEST_CHECK_HEX_EQ(lv[1].aval, 0xb7b6b5bd);
CHECK_RESULT_HEX(lv[2].aval, 0xbbbab9b8); TEST_CHECK_HEX_EQ(lv[2].aval, 0xbbbab9b8);
CHECK_RESULT_HEX(lv[0].bval, 0xc3c2c1c0); TEST_CHECK_HEX_EQ(lv[0].bval, 0xc3c2c1c0);
CHECK_RESULT_HEX(lv[1].bval, 0xc7c6c5c8); TEST_CHECK_HEX_EQ(lv[1].bval, 0xc7c6c5c8);
CHECK_RESULT_HEX(lv[2].bval, 0xcbcac9c8); TEST_CHECK_HEX_EQ(lv[2].bval, 0xcbcac9c8);
svLogicVecVal ltmp[2]; svLogicVecVal ltmp[2];
svGetPartselLogic(ltmp, lv, 40, 8); svGetPartselLogic(ltmp, lv, 40, 8);
CHECK_RESULT_HEX(ltmp[0].aval, 0xb5); TEST_CHECK_HEX_EQ(ltmp[0].aval, 0xb5);
CHECK_RESULT_HEX(ltmp[0].bval, 0xc5); TEST_CHECK_HEX_EQ(ltmp[0].bval, 0xc5);
svGetPartselLogic(ltmp, lv, 32, 32); svGetPartselLogic(ltmp, lv, 32, 32);
CHECK_RESULT_HEX(ltmp[0].aval, 0xb7b6b5bd); TEST_CHECK_HEX_EQ(ltmp[0].aval, 0xb7b6b5bd);
CHECK_RESULT_HEX(ltmp[0].bval, 0xc7c6c5c8); TEST_CHECK_HEX_EQ(ltmp[0].bval, 0xc7c6c5c8);
svGetPartselLogic(ltmp, lv, 48, 40); svGetPartselLogic(ltmp, lv, 48, 40);
CHECK_RESULT_HEX(ltmp[0].aval, 0xb9b8b7b6); TEST_CHECK_HEX_EQ(ltmp[0].aval, 0xb9b8b7b6);
CHECK_RESULT_HEX(ltmp[0].bval, 0xc9c8c7c6); TEST_CHECK_HEX_EQ(ltmp[0].bval, 0xc9c8c7c6);
CHECK_RESULT_HEX(ltmp[1].aval, 0xba); TEST_CHECK_HEX_EQ(ltmp[1].aval, 0xba);
CHECK_RESULT_HEX(ltmp[1].bval, 0xca); TEST_CHECK_HEX_EQ(ltmp[1].bval, 0xca);
ltmp[0].aval = 0xb5; ltmp[0].aval = 0xb5;
ltmp[0].bval = 0xc5; ltmp[0].bval = 0xc5;
svPutPartselLogic(lv, ltmp[0], 48, 8); svPutPartselLogic(lv, ltmp[0], 48, 8);
CHECK_RESULT_HEX(lv[0].aval, 0xb3b2b1b0); TEST_CHECK_HEX_EQ(lv[0].aval, 0xb3b2b1b0);
CHECK_RESULT_HEX(lv[1].aval, 0xb7b5b5bd); TEST_CHECK_HEX_EQ(lv[1].aval, 0xb7b5b5bd);
CHECK_RESULT_HEX(lv[2].aval, 0xbbbab9b8); TEST_CHECK_HEX_EQ(lv[2].aval, 0xbbbab9b8);
CHECK_RESULT_HEX(lv[0].bval, 0xc3c2c1c0); TEST_CHECK_HEX_EQ(lv[0].bval, 0xc3c2c1c0);
CHECK_RESULT_HEX(lv[1].bval, 0xc7c5c5c8); TEST_CHECK_HEX_EQ(lv[1].bval, 0xc7c5c5c8);
CHECK_RESULT_HEX(lv[2].bval, 0xcbcac9c8); TEST_CHECK_HEX_EQ(lv[2].bval, 0xcbcac9c8);
ltmp[0].aval = 0x11223344; ltmp[0].aval = 0x11223344;
ltmp[0].bval = 0x81828384; ltmp[0].bval = 0x81828384;
svPutPartselLogic(lv, ltmp[0], 32, 32); svPutPartselLogic(lv, ltmp[0], 32, 32);
CHECK_RESULT_HEX(lv[0].aval, 0xb3b2b1b0); TEST_CHECK_HEX_EQ(lv[0].aval, 0xb3b2b1b0);
CHECK_RESULT_HEX(lv[1].aval, 0x11223344); TEST_CHECK_HEX_EQ(lv[1].aval, 0x11223344);
CHECK_RESULT_HEX(lv[2].aval, 0xbbbab9b8); TEST_CHECK_HEX_EQ(lv[2].aval, 0xbbbab9b8);
CHECK_RESULT_HEX(lv[0].bval, 0xc3c2c1c0); TEST_CHECK_HEX_EQ(lv[0].bval, 0xc3c2c1c0);
CHECK_RESULT_HEX(lv[1].bval, 0x81828384); TEST_CHECK_HEX_EQ(lv[1].bval, 0x81828384);
CHECK_RESULT_HEX(lv[2].bval, 0xcbcac9c8); TEST_CHECK_HEX_EQ(lv[2].bval, 0xcbcac9c8);
ltmp[0].aval = 0x99887766; ltmp[0].aval = 0x99887766;
ltmp[0].bval = 0x89888786; ltmp[0].bval = 0x89888786;
svPutPartselLogic(lv, ltmp[0], 24, 24); svPutPartselLogic(lv, ltmp[0], 24, 24);
CHECK_RESULT_HEX(lv[0].aval, 0x66b2b1b0); TEST_CHECK_HEX_EQ(lv[0].aval, 0x66b2b1b0);
CHECK_RESULT_HEX(lv[1].aval, 0x11228877); TEST_CHECK_HEX_EQ(lv[1].aval, 0x11228877);
CHECK_RESULT_HEX(lv[2].aval, 0xbbbab9b8); TEST_CHECK_HEX_EQ(lv[2].aval, 0xbbbab9b8);
CHECK_RESULT_HEX(lv[0].bval, 0x86c2c1c0); TEST_CHECK_HEX_EQ(lv[0].bval, 0x86c2c1c0);
CHECK_RESULT_HEX(lv[1].bval, 0x81828887); TEST_CHECK_HEX_EQ(lv[1].bval, 0x81828887);
CHECK_RESULT_HEX(lv[2].bval, 0xcbcac9c8); TEST_CHECK_HEX_EQ(lv[2].bval, 0xcbcac9c8);
} }
//====================================================================== //======================================================================

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -70,26 +72,8 @@ extern int dpii_failure();
} }
#endif #endif
int failure = 0; int errors = 0;
int dpii_failure() { return failure; } int dpii_failure() { return errors; }
#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)
#define CHECK_RESULT_HEX_NE(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)
void dpii_unused(const svOpenArrayHandle u) {} void dpii_unused(const svOpenArrayHandle u) {}
@ -107,58 +91,58 @@ void _dpii_all(int c, int p, int u, const svOpenArrayHandle i, const svOpenArray
if (p) { if (p) {
int d = 0; int d = 0;
if (c == 0 || c == 1) { if (c == 0 || c == 1) {
CHECK_RESULT_HEX(svLeft(i, d), 1); TEST_CHECK_HEX_EQ(svLeft(i, d), 1);
CHECK_RESULT_HEX(svRight(i, d), -1); TEST_CHECK_HEX_EQ(svRight(i, d), -1);
CHECK_RESULT_HEX(svLow(i, d), -1); TEST_CHECK_HEX_EQ(svLow(i, d), -1);
CHECK_RESULT_HEX(svHigh(i, d), 1); TEST_CHECK_HEX_EQ(svHigh(i, d), 1);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 3); TEST_CHECK_HEX_EQ(svSize(i, d), 3);
} else if (c == 2) { } else if (c == 2) {
CHECK_RESULT_HEX(svLeft(i, d), 95); TEST_CHECK_HEX_EQ(svLeft(i, d), 95);
CHECK_RESULT_HEX(svRight(i, d), 1); TEST_CHECK_HEX_EQ(svRight(i, d), 1);
CHECK_RESULT_HEX(svLow(i, d), 1); TEST_CHECK_HEX_EQ(svLow(i, d), 1);
CHECK_RESULT_HEX(svHigh(i, d), 95); TEST_CHECK_HEX_EQ(svHigh(i, d), 95);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 95); TEST_CHECK_HEX_EQ(svSize(i, d), 95);
} else { } else {
CHECK_RESULT_HEX(0, 1); TEST_CHECK_HEX_EQ(0, 1);
} }
} }
#endif #endif
if (u >= 1) { if (u >= 1) {
int d = 1; int d = 1;
if (c == 0) { if (c == 0) {
CHECK_RESULT_HEX(svLeft(i, d), -2); TEST_CHECK_HEX_EQ(svLeft(i, d), -2);
CHECK_RESULT_HEX(svRight(i, d), 2); TEST_CHECK_HEX_EQ(svRight(i, d), 2);
CHECK_RESULT_HEX(svLow(i, d), -2); TEST_CHECK_HEX_EQ(svLow(i, d), -2);
CHECK_RESULT_HEX(svHigh(i, d), 2); TEST_CHECK_HEX_EQ(svHigh(i, d), 2);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 5); TEST_CHECK_HEX_EQ(svSize(i, d), 5);
} else if (c == 1) { } else if (c == 1) {
CHECK_RESULT_HEX(svLeft(i, d), 2); TEST_CHECK_HEX_EQ(svLeft(i, d), 2);
CHECK_RESULT_HEX(svRight(i, d), -2); TEST_CHECK_HEX_EQ(svRight(i, d), -2);
CHECK_RESULT_HEX(svLow(i, d), -2); TEST_CHECK_HEX_EQ(svLow(i, d), -2);
CHECK_RESULT_HEX(svHigh(i, d), 2); TEST_CHECK_HEX_EQ(svHigh(i, d), 2);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 5); TEST_CHECK_HEX_EQ(svSize(i, d), 5);
} }
} }
if (u >= 2) { if (u >= 2) {
int d = 2; int d = 2;
if (c == 0) { if (c == 0) {
CHECK_RESULT_HEX(svLeft(i, d), -3); TEST_CHECK_HEX_EQ(svLeft(i, d), -3);
CHECK_RESULT_HEX(svRight(i, d), 3); TEST_CHECK_HEX_EQ(svRight(i, d), 3);
CHECK_RESULT_HEX(svLow(i, d), -3); TEST_CHECK_HEX_EQ(svLow(i, d), -3);
CHECK_RESULT_HEX(svHigh(i, d), 3); TEST_CHECK_HEX_EQ(svHigh(i, d), 3);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 7); TEST_CHECK_HEX_EQ(svSize(i, d), 7);
} else if (c == 1) { } else if (c == 1) {
CHECK_RESULT_HEX(svLeft(i, d), 3); TEST_CHECK_HEX_EQ(svLeft(i, d), 3);
CHECK_RESULT_HEX(svRight(i, d), -3); TEST_CHECK_HEX_EQ(svRight(i, d), -3);
CHECK_RESULT_HEX(svLow(i, d), -3); TEST_CHECK_HEX_EQ(svLow(i, d), -3);
CHECK_RESULT_HEX(svHigh(i, d), 3); TEST_CHECK_HEX_EQ(svHigh(i, d), 3);
// CHECK_RESULT_HEX(svIncrement(i, d), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
CHECK_RESULT_HEX(svSize(i, d), 7); TEST_CHECK_HEX_EQ(svSize(i, d), 7);
} }
} }
#ifdef VERILATOR #ifdef VERILATOR
@ -240,12 +224,12 @@ void dpii_open_bit(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o) { void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i); intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
CHECK_RESULT_HEX_NE(arrPtr, 0); // All the arrays should actually exist TEST_CHECK_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i); int sizeInputOfArray = svSizeOfArray(i);
CHECK_RESULT_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size TEST_CHECK_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
CHECK_RESULT_HEX_NE(svDimensions(i), 0); // All the test cases are unpacked arrays TEST_CHECK_HEX_NE(svDimensions(i), 0); // All the test cases are unpacked arrays
#endif #endif
} }
@ -254,12 +238,12 @@ void dpii_open_logic(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
static void _dpii_open_int_ux(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) { static void _dpii_open_int_ux(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i); intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
CHECK_RESULT_HEX_NE(arrPtr, 0); // All the arrays should actually exist TEST_CHECK_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i); int sizeInputOfArray = svSizeOfArray(i);
CHECK_RESULT_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size TEST_CHECK_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
CHECK_RESULT_HEX(svDimensions(i), u); TEST_CHECK_HEX_EQ(svDimensions(i), u);
#endif #endif
int dim = svDimensions(i); int dim = svDimensions(i);
@ -268,30 +252,30 @@ static void _dpii_open_int_ux(int u, const svOpenArrayHandle i, const svOpenArra
if (dim == 1) { if (dim == 1) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a); intptr_t ip = (intptr_t)svGetArrElemPtr(i, a);
intptr_t i2p = (intptr_t)svGetArrElemPtr1(i, a); intptr_t i2p = (intptr_t)svGetArrElemPtr1(i, a);
CHECK_RESULT_HEX(ip, i2p); TEST_CHECK_HEX_EQ(ip, i2p);
CHECK_RESULT_HEX_NE(ip, 0); TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a); intptr_t op = (intptr_t)svGetArrElemPtr(o, a);
CHECK_RESULT_HEX_NE(op, 0); TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip); *reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
} else { } else {
for (int b = svLow(i, 2); b <= svHigh(i, 2); ++b) { for (int b = svLow(i, 2); b <= svHigh(i, 2); ++b) {
if (dim == 2) { if (dim == 2) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b); intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b);
intptr_t i2p = (intptr_t)svGetArrElemPtr2(i, a, b); intptr_t i2p = (intptr_t)svGetArrElemPtr2(i, a, b);
CHECK_RESULT_HEX(ip, i2p); TEST_CHECK_HEX_EQ(ip, i2p);
CHECK_RESULT_HEX_NE(ip, 0); TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b); intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b);
CHECK_RESULT_HEX_NE(op, 0); TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip); *reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
} else { } else {
for (int c = svLow(i, 3); c <= svHigh(i, 3); ++c) { for (int c = svLow(i, 3); c <= svHigh(i, 3); ++c) {
if (dim == 3) { if (dim == 3) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b, c); intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b, c);
intptr_t i2p = (intptr_t)svGetArrElemPtr3(i, a, b, c); intptr_t i2p = (intptr_t)svGetArrElemPtr3(i, a, b, c);
CHECK_RESULT_HEX(ip, i2p); TEST_CHECK_HEX_EQ(ip, i2p);
CHECK_RESULT_HEX_NE(ip, 0); TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b, c); intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b, c);
CHECK_RESULT_HEX_NE(op, 0); TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip); *reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
} }
} }

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -52,26 +54,8 @@ extern int dpii_failure();
} }
#endif #endif
int failure = 0; int errors = 0;
int dpii_failure() { return failure; } int dpii_failure() { return errors; }
#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)
#define CHECK_RESULT_HEX_NE(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)
void dpii_unused(const svOpenArrayHandle u) {} void dpii_unused(const svOpenArrayHandle u) {}
@ -82,7 +66,7 @@ static void _dpii_bit_elem_ux(int p, int u, const svOpenArrayHandle i, const svO
int dim = svDimensions(i); int dim = svDimensions(i);
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
CHECK_RESULT_HEX(dim, u); TEST_CHECK_HEX_EQ(dim, u);
#endif #endif
for (int a = svLow(i, 1); a <= svHigh(i, 1); ++a) { for (int a = svLow(i, 1); a <= svHigh(i, 1); ++a) {
@ -90,7 +74,7 @@ static void _dpii_bit_elem_ux(int p, int u, const svOpenArrayHandle i, const svO
if (dim == 1) { if (dim == 1) {
svBit v = svGetBitArrElem(i, a); svBit v = svGetBitArrElem(i, a);
svBit v2 = svGetBitArrElem1(i, a); svBit v2 = svGetBitArrElem1(i, a);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutBitArrElem(o, v ? 0 : 1, a); svPutBitArrElem(o, v ? 0 : 1, a);
svPutBitArrElem1(q, v ? 0 : 1, a); svPutBitArrElem1(q, v ? 0 : 1, a);
} else { } else {
@ -98,7 +82,7 @@ static void _dpii_bit_elem_ux(int p, int u, const svOpenArrayHandle i, const svO
if (dim == 2) { if (dim == 2) {
svBit v = svGetBitArrElem(i, a, b); svBit v = svGetBitArrElem(i, a, b);
svBit v2 = svGetBitArrElem2(i, a, b); svBit v2 = svGetBitArrElem2(i, a, b);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutBitArrElem(o, v ? 0 : 1, a, b); svPutBitArrElem(o, v ? 0 : 1, a, b);
svPutBitArrElem2(q, v ? 0 : 1, a, b); svPutBitArrElem2(q, v ? 0 : 1, a, b);
} else { } else {
@ -106,7 +90,7 @@ static void _dpii_bit_elem_ux(int p, int u, const svOpenArrayHandle i, const svO
if (dim == 3) { if (dim == 3) {
svBit v = svGetBitArrElem(i, a, b, c); svBit v = svGetBitArrElem(i, a, b, c);
svBit v2 = svGetBitArrElem3(i, a, b, c); svBit v2 = svGetBitArrElem3(i, a, b, c);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutBitArrElem(o, v ? 0 : 1, a, b, c); svPutBitArrElem(o, v ? 0 : 1, a, b, c);
svPutBitArrElem3(q, v ? 0 : 1, a, b, c); svPutBitArrElem3(q, v ? 0 : 1, a, b, c);
} }
@ -137,7 +121,7 @@ static void _dpii_logic_elem_ux(int p, int u, const svOpenArrayHandle i, const s
int dim = svDimensions(i); int dim = svDimensions(i);
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
CHECK_RESULT_HEX(dim, u); TEST_CHECK_HEX_EQ(dim, u);
#endif #endif
int sizeInputOfArray = svSizeOfArray(i); int sizeInputOfArray = svSizeOfArray(i);
// svSizeOfArray(i) undeterministic as not in C representation // svSizeOfArray(i) undeterministic as not in C representation
@ -147,7 +131,7 @@ static void _dpii_logic_elem_ux(int p, int u, const svOpenArrayHandle i, const s
if (dim == 1) { if (dim == 1) {
svLogic v = svGetLogicArrElem(i, a); svLogic v = svGetLogicArrElem(i, a);
svLogic v2 = svGetLogicArrElem1(i, a); svLogic v2 = svGetLogicArrElem1(i, a);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutLogicArrElem(o, v ? 0 : 1, a); svPutLogicArrElem(o, v ? 0 : 1, a);
svPutLogicArrElem1(q, v ? 0 : 1, a); svPutLogicArrElem1(q, v ? 0 : 1, a);
} else { } else {
@ -155,7 +139,7 @@ static void _dpii_logic_elem_ux(int p, int u, const svOpenArrayHandle i, const s
if (dim == 2) { if (dim == 2) {
svLogic v = svGetLogicArrElem(i, a, b); svLogic v = svGetLogicArrElem(i, a, b);
svLogic v2 = svGetLogicArrElem2(i, a, b); svLogic v2 = svGetLogicArrElem2(i, a, b);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutLogicArrElem(o, v ? 0 : 1, a, b); svPutLogicArrElem(o, v ? 0 : 1, a, b);
svPutLogicArrElem2(q, v ? 0 : 1, a, b); svPutLogicArrElem2(q, v ? 0 : 1, a, b);
} else { } else {
@ -163,7 +147,7 @@ static void _dpii_logic_elem_ux(int p, int u, const svOpenArrayHandle i, const s
if (dim == 3) { if (dim == 3) {
svLogic v = svGetLogicArrElem(i, a, b, c); svLogic v = svGetLogicArrElem(i, a, b, c);
svLogic v2 = svGetLogicArrElem3(i, a, b, c); svLogic v2 = svGetLogicArrElem3(i, a, b, c);
CHECK_RESULT_HEX(v, v2); TEST_CHECK_HEX_EQ(v, v2);
svPutLogicArrElem(o, v ? 0 : 1, a, b, c); svPutLogicArrElem(o, v ? 0 : 1, a, b, c);
svPutLogicArrElem3(q, v ? 0 : 1, a, b, c); svPutLogicArrElem3(q, v ? 0 : 1, a, b, c);
} }

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -24,27 +26,9 @@
#endif #endif
// clang-format on // clang-format on
#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)
#define CHECK_RESULT_HEX_NE(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)
//====================================================================== //======================================================================
int failure = 0; int errors = 0;
void dpii_nullptr() { void dpii_nullptr() {
printf("%s:\n", __func__); printf("%s:\n", __func__);
@ -104,16 +88,16 @@ void dpii_int_u3(const svOpenArrayHandle i) {
printf("%s:\n", __func__); printf("%s:\n", __func__);
// Correct usage // Correct usage
intptr_t ip = (intptr_t)svGetArrElemPtr3(i, 1, 2, 3); intptr_t ip = (intptr_t)svGetArrElemPtr3(i, 1, 2, 3);
CHECK_RESULT_HEX_NE(ip, 0); TEST_CHECK_HEX_NE(ip, 0);
// Out of bounds // Out of bounds
ip = (intptr_t)svGetArrElemPtr3(i, 1, 2, 30); ip = (intptr_t)svGetArrElemPtr3(i, 1, 2, 30);
CHECK_RESULT_HEX(ip, 0); TEST_CHECK_HEX_EQ(ip, 0);
ip = (intptr_t)svGetArrElemPtr3(i, 1, 20, 3); ip = (intptr_t)svGetArrElemPtr3(i, 1, 20, 3);
CHECK_RESULT_HEX(ip, 0); TEST_CHECK_HEX_EQ(ip, 0);
ip = (intptr_t)svGetArrElemPtr3(i, 10, 2, 3); ip = (intptr_t)svGetArrElemPtr3(i, 10, 2, 3);
CHECK_RESULT_HEX(ip, 0); TEST_CHECK_HEX_EQ(ip, 0);
ip = (intptr_t)svGetArrElemPtr1(i, 30); ip = (intptr_t)svGetArrElemPtr1(i, 30);
CHECK_RESULT_HEX(ip, 0); TEST_CHECK_HEX_EQ(ip, 0);
} }
void dpii_real_u1(const svOpenArrayHandle i) { void dpii_real_u1(const svOpenArrayHandle i) {

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -39,26 +41,8 @@ extern int dpii_failure();
} }
#endif #endif
int failure = 0; int errors = 0;
int dpii_failure() { return failure; } int dpii_failure() { return errors; }
#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)
#define CHECK_RESULT_HEX_NE(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)
static void _invert(int bits, svBitVecVal o[], const svBitVecVal i[]) { static void _invert(int bits, svBitVecVal o[], const svBitVecVal i[]) {
for (int w = 0; w < SV_PACKED_DATA_NELEMS(bits); ++w) o[w] = ~i[w]; for (int w = 0; w < SV_PACKED_DATA_NELEMS(bits); ++w) o[w] = ~i[w];
@ -102,7 +86,7 @@ static void _dpii_bit_vecval_ux(int bits, int p, int u, const svOpenArrayHandle
int dim = svDimensions(i); int dim = svDimensions(i);
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
CHECK_RESULT_HEX(dim, u); TEST_CHECK_HEX_EQ(dim, u);
#endif #endif
svBitVecVal vv[SV_PACKED_DATA_NELEMS(bits)]; svBitVecVal vv[SV_PACKED_DATA_NELEMS(bits)];
@ -113,7 +97,7 @@ static void _dpii_bit_vecval_ux(int bits, int p, int u, const svOpenArrayHandle
if (dim == 1) { if (dim == 1) {
svGetBitArrElemVecVal(vv, i, a); svGetBitArrElemVecVal(vv, i, a);
svGetBitArrElem1VecVal(vv2, i, a); svGetBitArrElem1VecVal(vv2, i, a);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutBitArrElemVecVal(o, vo, a); svPutBitArrElemVecVal(o, vo, a);
svPutBitArrElem1VecVal(q, vo, a); svPutBitArrElem1VecVal(q, vo, a);
@ -122,7 +106,7 @@ static void _dpii_bit_vecval_ux(int bits, int p, int u, const svOpenArrayHandle
if (dim == 2) { if (dim == 2) {
svGetBitArrElemVecVal(vv, i, a, b); svGetBitArrElemVecVal(vv, i, a, b);
svGetBitArrElem2VecVal(vv2, i, a, b); svGetBitArrElem2VecVal(vv2, i, a, b);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutBitArrElemVecVal(o, vo, a, b); svPutBitArrElemVecVal(o, vo, a, b);
svPutBitArrElem2VecVal(q, vo, a, b); svPutBitArrElem2VecVal(q, vo, a, b);
@ -131,7 +115,7 @@ static void _dpii_bit_vecval_ux(int bits, int p, int u, const svOpenArrayHandle
if (dim == 3) { if (dim == 3) {
svGetBitArrElemVecVal(vv, i, a, b, c); svGetBitArrElemVecVal(vv, i, a, b, c);
svGetBitArrElem3VecVal(vv2, i, a, b, c); svGetBitArrElem3VecVal(vv2, i, a, b, c);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutBitArrElemVecVal(o, vo, a, b, c); svPutBitArrElemVecVal(o, vo, a, b, c);
svPutBitArrElem3VecVal(q, vo, a, b, c); svPutBitArrElem3VecVal(q, vo, a, b, c);
@ -173,7 +157,7 @@ static void _dpii_logic_vecval_ux(int bits, int p, int u, const svOpenArrayHandl
int dim = svDimensions(i); int dim = svDimensions(i);
#ifndef NC #ifndef NC
// NC always returns zero and warns // NC always returns zero and warns
CHECK_RESULT_HEX(dim, u); TEST_CHECK_HEX_EQ(dim, u);
#endif #endif
svLogicVecVal vv[SV_PACKED_DATA_NELEMS(bits)]; svLogicVecVal vv[SV_PACKED_DATA_NELEMS(bits)];
@ -184,7 +168,7 @@ static void _dpii_logic_vecval_ux(int bits, int p, int u, const svOpenArrayHandl
if (dim == 1) { if (dim == 1) {
svGetLogicArrElemVecVal(vv, i, a); svGetLogicArrElemVecVal(vv, i, a);
svGetLogicArrElem1VecVal(vv2, i, a); svGetLogicArrElem1VecVal(vv2, i, a);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutLogicArrElemVecVal(o, vo, a); svPutLogicArrElemVecVal(o, vo, a);
svPutLogicArrElem1VecVal(q, vo, a); svPutLogicArrElem1VecVal(q, vo, a);
@ -193,7 +177,7 @@ static void _dpii_logic_vecval_ux(int bits, int p, int u, const svOpenArrayHandl
if (dim == 2) { if (dim == 2) {
svGetLogicArrElemVecVal(vv, i, a, b); svGetLogicArrElemVecVal(vv, i, a, b);
svGetLogicArrElem2VecVal(vv2, i, a, b); svGetLogicArrElem2VecVal(vv2, i, a, b);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutLogicArrElemVecVal(o, vo, a, b); svPutLogicArrElemVecVal(o, vo, a, b);
svPutLogicArrElem2VecVal(q, vo, a, b); svPutLogicArrElem2VecVal(q, vo, a, b);
@ -202,7 +186,7 @@ static void _dpii_logic_vecval_ux(int bits, int p, int u, const svOpenArrayHandl
if (dim == 3) { if (dim == 3) {
svGetLogicArrElemVecVal(vv, i, a, b, c); svGetLogicArrElemVecVal(vv, i, a, b, c);
svGetLogicArrElem3VecVal(vv2, i, a, b, c); svGetLogicArrElem3VecVal(vv2, i, a, b, c);
CHECK_RESULT_HEX(_same(bits, vv, vv2), true); TEST_CHECK_HEX_EQ(_same(bits, vv, vv2), true);
_invert(bits, vo, vv); _invert(bits, vo, vv);
svPutLogicArrElemVecVal(o, vo, a, b, c); svPutLogicArrElemVecVal(o, vo, a, b, c);
svPutLogicArrElem3VecVal(q, vo, a, b, c); svPutLogicArrElem3VecVal(q, vo, a, b, c);

View File

@ -14,6 +14,8 @@
#include <iostream> #include <iostream>
#include "svdpi.h" #include "svdpi.h"
#include "TestCheck.h"
//====================================================================== //======================================================================
// clang-format off // clang-format off
@ -40,34 +42,25 @@ extern void dpii_open_i(const svOpenArrayHandle i, const svOpenArrayHandle o);
//====================================================================== //======================================================================
int failure = 0; int errors = 0;
int dpii_failure() { return failure; } int dpii_failure() { return errors; }
#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)
//====================================================================== //======================================================================
void dpii_open_i(const svOpenArrayHandle i, const svOpenArrayHandle o) { void dpii_open_i(const svOpenArrayHandle i, const svOpenArrayHandle o) {
// Illegal in VCS: // Illegal in VCS:
// CHECK_RESULT_HEX(svLeft(i, 0), 2); // TEST_CHECK_HEX_EQ(svLeft(i, 0), 2);
// CHECK_RESULT_HEX(svRight(i, 0), 0); // TEST_CHECK_HEX_EQ(svRight(i, 0), 0);
// CHECK_RESULT_HEX(svLow(i, 0), 0); // TEST_CHECK_HEX_EQ(svLow(i, 0), 0);
// CHECK_RESULT_HEX(svHigh(i, 0), 2); // TEST_CHECK_HEX_EQ(svHigh(i, 0), 2);
// //
CHECK_RESULT_HEX(svDimensions(i), 1); TEST_CHECK_HEX_EQ(svDimensions(i), 1);
CHECK_RESULT_HEX(svLeft(i, 1), 2); TEST_CHECK_HEX_EQ(svLeft(i, 1), 2);
CHECK_RESULT_HEX(svRight(i, 1), 0); TEST_CHECK_HEX_EQ(svRight(i, 1), 0);
CHECK_RESULT_HEX(svLow(i, 1), 0); TEST_CHECK_HEX_EQ(svLow(i, 1), 0);
CHECK_RESULT_HEX(svHigh(i, 1), 2); TEST_CHECK_HEX_EQ(svHigh(i, 1), 2);
// CHECK_RESULT_HEX(svIncrement(i, 1), 0); // TEST_CHECK_HEX_EQ(svIncrement(i, 1), 0);
CHECK_RESULT_HEX(svSize(i, 1), 3); TEST_CHECK_HEX_EQ(svSize(i, 1), 3);
for (int a = 0; a < 3; ++a) { for (int a = 0; a < 3; ++a) {
svBitVecVal vec[1]; svBitVecVal vec[1];
svGetBitArrElemVecVal(vec, i, a); svGetBitArrElemVecVal(vec, i, a);

View File

@ -10,15 +10,11 @@
#include <verilated.h> #include <verilated.h>
#include "Vt_multitop_sig.h" #include "Vt_multitop_sig.h"
#include "TestCheck.h"
double sc_time_stamp() { return 0; } double sc_time_stamp() { return 0; }
// Use cout to avoid issues with %d/%lx etc int errors = 0;
#define CHECK_RESULT(got, exp) \
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = " << (exp) << std::endl; \
return __LINE__; \
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
Vt_multitop_sig* topp = new Vt_multitop_sig(""); Vt_multitop_sig* topp = new Vt_multitop_sig("");
@ -30,20 +26,21 @@ int main(int argc, char* argv[]) {
topp->b__02Ein = 0; topp->b__02Ein = 0;
topp->uniq_in = 0; topp->uniq_in = 0;
topp->eval(); topp->eval();
CHECK_RESULT(topp->a__02Eout, 1); TEST_CHECK_EQ(topp->a__02Eout, 1);
CHECK_RESULT(topp->b__02Eout, 0); TEST_CHECK_EQ(topp->b__02Eout, 0);
CHECK_RESULT(topp->uniq_out, 1); TEST_CHECK_EQ(topp->uniq_out, 1);
topp->a__02Ein = 1; topp->a__02Ein = 1;
topp->b__02Ein = 1; topp->b__02Ein = 1;
topp->uniq_in = 1; topp->uniq_in = 1;
topp->eval(); topp->eval();
CHECK_RESULT(topp->a__02Eout, 0); TEST_CHECK_EQ(topp->a__02Eout, 0);
CHECK_RESULT(topp->b__02Eout, 1); TEST_CHECK_EQ(topp->b__02Eout, 1);
CHECK_RESULT(topp->uniq_out, 0); TEST_CHECK_EQ(topp->uniq_out, 0);
} }
topp->final(); topp->final();
VL_DO_DANGLING(delete topp, topp); VL_DO_DANGLING(delete topp, topp);
printf("*-* All Finished *-*\n"); printf("*-* All Finished *-*\n");
return errors ? 10 : 0;
} }

View File

@ -12,20 +12,12 @@
#include <verilated_save.h> #include <verilated_save.h>
#include VM_PREFIX_INCLUDE #include VM_PREFIX_INCLUDE
//====================================================================== #include "TestCheck.h"
#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; \
exit(10); \
} \
} while (0)
//====================================================================== //======================================================================
unsigned int main_time = 0; unsigned int main_time = 0;
int errors = 0;
double sc_time_stamp() { return main_time; } double sc_time_stamp() { return main_time; }
@ -36,13 +28,13 @@ int main(int argc, char* argv[]) {
{ {
VerilatedSave os; VerilatedSave os;
os.open("/No_such_file_as_this"); os.open("/No_such_file_as_this");
CHECK_RESULT_HEX(os.isOpen(), false); TEST_CHECK_EQ(os.isOpen(), false);
} }
{ {
VerilatedRestore os; VerilatedRestore os;
os.open("/No_such_file_as_this"); os.open("/No_such_file_as_this");
CHECK_RESULT_HEX(os.isOpen(), false); TEST_CHECK_EQ(os.isOpen(), false);
} }
return 0; return errors ? 10 : 0;
} }

View File

@ -5,6 +5,8 @@
#include <verilated.h> #include <verilated.h>
#include "TestCheck.h"
#include VM_PREFIX_INCLUDE #include VM_PREFIX_INCLUDE
unsigned long long main_time = 0; unsigned long long main_time = 0;
@ -14,43 +16,39 @@ double sc_time_stamp() { return (double)main_time; }
#define FILENM "t_timescale.cpp" #define FILENM "t_timescale.cpp"
#define CHECK_RESULT(got, exp) \ int errors = 0;
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << FILENM << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = " << (exp) << std::endl; \
return __LINE__; \
}
int main(int argc, char** argv, char** env) { int main(int argc, char** argv, char** env) {
VM_PREFIX* top = new VM_PREFIX("top"); VM_PREFIX* top = new VM_PREFIX("top");
CHECK_RESULT(VL_TIME_STR_CONVERT("100s"), 2); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100s"), 2);
CHECK_RESULT(VL_TIME_STR_CONVERT("10s"), 1); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10s"), 1);
CHECK_RESULT(VL_TIME_STR_CONVERT("1s"), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1s"), 0);
CHECK_RESULT(VL_TIME_STR_CONVERT("100ms"), -1); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100ms"), -1);
CHECK_RESULT(VL_TIME_STR_CONVERT("10ms"), -2); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10ms"), -2);
CHECK_RESULT(VL_TIME_STR_CONVERT("1ms"), -3); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1ms"), -3);
CHECK_RESULT(VL_TIME_STR_CONVERT("100us"), -4); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100us"), -4);
CHECK_RESULT(VL_TIME_STR_CONVERT("10us"), -5); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10us"), -5);
CHECK_RESULT(VL_TIME_STR_CONVERT("1us"), -6); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1us"), -6);
CHECK_RESULT(VL_TIME_STR_CONVERT("100ns"), -7); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100ns"), -7);
CHECK_RESULT(VL_TIME_STR_CONVERT("10ns"), -8); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10ns"), -8);
CHECK_RESULT(VL_TIME_STR_CONVERT("1ns"), -9); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1ns"), -9);
CHECK_RESULT(VL_TIME_STR_CONVERT("100ps"), -10); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100ps"), -10);
CHECK_RESULT(VL_TIME_STR_CONVERT("10ps"), -11); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10ps"), -11);
CHECK_RESULT(VL_TIME_STR_CONVERT("1ps"), -12); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1ps"), -12);
CHECK_RESULT(VL_TIME_STR_CONVERT("100fs"), -13); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("100fs"), -13);
CHECK_RESULT(VL_TIME_STR_CONVERT("10fs"), -14); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("10fs"), -14);
CHECK_RESULT(VL_TIME_STR_CONVERT("1fs"), -15); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1fs"), -15);
CHECK_RESULT(VL_TIME_STR_CONVERT("1.5s"), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1.5s"), 0);
CHECK_RESULT(VL_TIME_STR_CONVERT("1s "), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1s "), 0);
CHECK_RESULT(VL_TIME_STR_CONVERT("1ss"), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("1ss"), 0);
CHECK_RESULT(VL_TIME_STR_CONVERT("s"), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT("s"), 0);
CHECK_RESULT(VL_TIME_STR_CONVERT(0), 0); TEST_CHECK_EQ(VL_TIME_STR_CONVERT(0), 0);
top->final(); top->final();
VL_DO_DANGLING(delete top, top); VL_DO_DANGLING(delete top, top);
printf("*-* All Finished *-*\n"); printf("*-* All Finished *-*\n");
return 0;
return errors ? 10 : 0;
} }

View File

@ -19,12 +19,13 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "TestCheck.h"
#include "TestSimulator.h" #include "TestSimulator.h"
#include "TestVpi.h" #include "TestVpi.h"
#include "vpi_user.h" #include "vpi_user.h"
bool got_error = false; int errors = 0;
TestVpiHandle vh_value_cb; TestVpiHandle vh_value_cb;
TestVpiHandle vh_rw_cb; TestVpiHandle vh_rw_cb;
@ -34,33 +35,6 @@ unsigned int last_rw_cb_time = 0;
unsigned int main_time = 0; unsigned int main_time = 0;
#ifdef TEST_VERBOSE
bool verbose = true;
#else
bool verbose = false;
#endif
#define CHECK_RESULT_NZ(got) \
if (!(got)) { \
printf("%%Error: %s:%d: GOT = NULL EXP = !NULL\n", __FILE__, __LINE__); \
got_error = true; \
}
// Use cout to avoid issues with %d/%lx etc
#define CHECK_RESULT_NE(got, exp) \
if ((got) == (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = !" << (exp) << std::endl; \
got_error = true; \
}
// Use cout to avoid issues with %d/%lx etc
#define CHECK_RESULT(got, exp) \
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = " << (exp) << std::endl; \
got_error = true; \
}
static void reregister_value_cb(); static void reregister_value_cb();
static void reregister_rw_cb(); static void reregister_rw_cb();
@ -79,13 +53,13 @@ static void reregister_value_cb() {
if (verbose) vpi_printf(const_cast<char*>("- Removing cbValueChange callback\n")); if (verbose) vpi_printf(const_cast<char*>("- Removing cbValueChange callback\n"));
int ret = vpi_remove_cb(vh_value_cb); int ret = vpi_remove_cb(vh_value_cb);
vh_value_cb.freed(); vh_value_cb.freed();
CHECK_RESULT(ret, 1); TEST_CHECK_EQ(ret, 1);
if (verbose) { if (verbose) {
vpi_printf(const_cast<char*>("- last_value_cb_time %d , main_time %d\n"), vpi_printf(const_cast<char*>("- last_value_cb_time %d , main_time %d\n"),
last_value_cb_time, main_time); last_value_cb_time, main_time);
} }
CHECK_RESULT_NE(main_time, last_value_cb_time); TEST_CHECK_NE(main_time, last_value_cb_time);
last_value_cb_time = main_time; last_value_cb_time = main_time;
} }
if (verbose) vpi_printf(const_cast<char*>("- Registering cbValueChange callback\n")); if (verbose) vpi_printf(const_cast<char*>("- Registering cbValueChange callback\n"));
@ -95,7 +69,7 @@ static void reregister_value_cb() {
cb_data_testcase.reason = cbValueChange; cb_data_testcase.reason = cbValueChange;
TestVpiHandle vh1 = VPI_HANDLE("count"); TestVpiHandle vh1 = VPI_HANDLE("count");
CHECK_RESULT_NZ(vh1); TEST_CHECK_NZ(vh1);
s_vpi_value v; s_vpi_value v;
v.format = vpiSuppressVal; v.format = vpiSuppressVal;
@ -104,7 +78,7 @@ static void reregister_value_cb() {
cb_data_testcase.value = &v; cb_data_testcase.value = &v;
vh_value_cb = vpi_register_cb(&cb_data_testcase); vh_value_cb = vpi_register_cb(&cb_data_testcase);
CHECK_RESULT_NZ(vh_value_cb); TEST_CHECK_NZ(vh_value_cb);
} }
static void reregister_rw_cb() { static void reregister_rw_cb() {
@ -112,13 +86,13 @@ static void reregister_rw_cb() {
if (verbose) vpi_printf(const_cast<char*>("- Removing cbReadWriteSynch callback\n")); if (verbose) vpi_printf(const_cast<char*>("- Removing cbReadWriteSynch callback\n"));
int ret = vpi_remove_cb(vh_rw_cb); int ret = vpi_remove_cb(vh_rw_cb);
vh_rw_cb.freed(); vh_rw_cb.freed();
CHECK_RESULT(ret, 1); TEST_CHECK_EQ(ret, 1);
if (verbose) { if (verbose) {
vpi_printf(const_cast<char*>("- last_rw_cb_time %d , main_time %d\n"), last_rw_cb_time, vpi_printf(const_cast<char*>("- last_rw_cb_time %d , main_time %d\n"), last_rw_cb_time,
main_time); main_time);
} }
CHECK_RESULT_NE(main_time, last_rw_cb_time); TEST_CHECK_NE(main_time, last_rw_cb_time);
last_rw_cb_time = main_time; last_rw_cb_time = main_time;
} }
if (verbose) vpi_printf(const_cast<char*>("- Registering cbReadWriteSynch callback\n")); if (verbose) vpi_printf(const_cast<char*>("- Registering cbReadWriteSynch callback\n"));
@ -128,7 +102,7 @@ static void reregister_rw_cb() {
cb_data_testcase.reason = cbReadWriteSynch; cb_data_testcase.reason = cbReadWriteSynch;
vh_rw_cb = vpi_register_cb(&cb_data_testcase); vh_rw_cb = vpi_register_cb(&cb_data_testcase);
CHECK_RESULT_NZ(vh_rw_cb); TEST_CHECK_NZ(vh_rw_cb);
} }
static int the_filler_callback(p_cb_data cb_data) { return 0; } static int the_filler_callback(p_cb_data cb_data) { return 0; }
@ -143,7 +117,7 @@ static void register_filler_cb() {
cb_data_1.reason = cbReadWriteSynch; cb_data_1.reason = cbReadWriteSynch;
TestVpiHandle cb_data_1_h = vpi_register_cb(&cb_data_1); TestVpiHandle cb_data_1_h = vpi_register_cb(&cb_data_1);
CHECK_RESULT_NZ(cb_data_1_h); TEST_CHECK_NZ(cb_data_1_h);
if (verbose) { if (verbose) {
vpi_printf(const_cast<char*>("- Registering filler cbValueChange callback\n")); vpi_printf(const_cast<char*>("- Registering filler cbValueChange callback\n"));
@ -154,7 +128,7 @@ static void register_filler_cb() {
cb_data_2.reason = cbValueChange; cb_data_2.reason = cbValueChange;
TestVpiHandle vh2 = VPI_HANDLE("count"); TestVpiHandle vh2 = VPI_HANDLE("count");
CHECK_RESULT_NZ(vh2); TEST_CHECK_NZ(vh2);
s_vpi_value v; s_vpi_value v;
v.format = vpiSuppressVal; v.format = vpiSuppressVal;
@ -163,7 +137,7 @@ static void register_filler_cb() {
cb_data_2.value = &v; cb_data_2.value = &v;
TestVpiHandle cb_data_2_h = vpi_register_cb(&cb_data_2); TestVpiHandle cb_data_2_h = vpi_register_cb(&cb_data_2);
CHECK_RESULT_NZ(cb_data_2_h); TEST_CHECK_NZ(cb_data_2_h);
} }
double sc_time_stamp() { return main_time; } double sc_time_stamp() { return main_time; }
@ -176,9 +150,9 @@ int main(int argc, char** argv, char** env) {
VM_PREFIX* topp = new VM_PREFIX(""); // Note null name - we're flattening it out VM_PREFIX* topp = new VM_PREFIX(""); // Note null name - we're flattening it out
reregister_value_cb(); reregister_value_cb();
CHECK_RESULT_NZ(vh_value_cb); TEST_CHECK_NZ(vh_value_cb);
reregister_rw_cb(); reregister_rw_cb();
CHECK_RESULT_NZ(vh_rw_cb); TEST_CHECK_NZ(vh_rw_cb);
register_filler_cb(); register_filler_cb();
topp->eval(); topp->eval();
@ -186,12 +160,12 @@ int main(int argc, char** argv, char** env) {
while (vl_time_stamp64() < sim_time && !Verilated::gotFinish()) { while (vl_time_stamp64() < sim_time && !Verilated::gotFinish()) {
main_time += 1; main_time += 1;
if (verbose) VL_PRINTF("Sim Time %d got_error %d\n", main_time, got_error); if (verbose) VL_PRINTF("Sim Time %d got_error %d\n", main_time, errors);
topp->clk = !topp->clk; topp->clk = !topp->clk;
topp->eval(); topp->eval();
VerilatedVpi::callValueCbs(); VerilatedVpi::callValueCbs();
VerilatedVpi::callCbs(cbReadWriteSynch); VerilatedVpi::callCbs(cbReadWriteSynch);
if (got_error) vl_stop(__FILE__, __LINE__, "TOP-cpp"); if (errors) vl_stop(__FILE__, __LINE__, "TOP-cpp");
} }
if (!Verilated::gotFinish()) { if (!Verilated::gotFinish()) {
@ -200,5 +174,5 @@ int main(int argc, char** argv, char** env) {
topp->final(); topp->final();
VL_DO_DANGLING(delete topp, topp); VL_DO_DANGLING(delete topp, topp);
return 0; return errors ? 10 : 0;
} }

View File

@ -63,7 +63,7 @@ int main(int argc, char** argv, char** env) {
TEST_CHECK_EQ(VerilatedVpi::cbNextDeadline(), main_time + 1); TEST_CHECK_EQ(VerilatedVpi::cbNextDeadline(), main_time + 1);
} }
if ((main_time % 5) == 0) topp->clk = !topp->clk; if ((main_time % 5) == 0) topp->clk = !topp->clk;
// mon_do(); // mon_do();
#if VM_TRACE #if VM_TRACE
if (tfp) tfp->dump(main_time); if (tfp) tfp->dump(main_time);
#endif #endif

View File

@ -41,7 +41,7 @@ static int _time_cb1(p_cb_data cb_data) {
TEST_VERBOSE_PRINTF("time_cb1: %d\n", t.low); TEST_VERBOSE_PRINTF("time_cb1: %d\n", t.low);
++callback_count1; ++callback_count1;
if (callback_time1) TEST_CHECK_EQ(callback_time1, t.low); if (callback_time1) TEST_CHECK_EQ(callback_time1, t.low);
callback_time1 = t.low + 1; // Next call callback_time1 = t.low + 1; // Next call
t_cb_data cb_data_n; t_cb_data cb_data_n;
bzero(&cb_data_n, sizeof(cb_data_n)); bzero(&cb_data_n, sizeof(cb_data_n));
@ -123,10 +123,8 @@ extern "C" void dpii_final() {
TEST_VERBOSE_PRINTF("-dpii_final()\n"); TEST_VERBOSE_PRINTF("-dpii_final()\n");
// Allow some slop as cb might be before/after this call // Allow some slop as cb might be before/after this call
TEST_CHECK(callback_count1, 1010, TEST_CHECK(callback_count1, 1010, (callback_count1 >= 1000 && callback_count1 <= 1020));
(callback_count1 >= 1000 && callback_count1 <= 1020)); TEST_CHECK(callback_count2, 1010, (callback_count2 >= 1000 && callback_count2 <= 1020));
TEST_CHECK(callback_count2, 1010,
(callback_count2 >= 1000 && callback_count2 <= 1020));
if (errors) { if (errors) {
vpi_control(vpiStop); vpi_control(vpiStop);

View File

@ -32,25 +32,17 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "TestCheck.h"
#include "TestSimulator.h" #include "TestSimulator.h"
#include "TestVpi.h" #include "TestVpi.h"
int errors = 0;
unsigned int main_time = 0; unsigned int main_time = 0;
unsigned int callback_count_zero_time = 0; unsigned int callback_count_zero_time = 0;
unsigned int callback_count_start_of_sim = 0; unsigned int callback_count_start_of_sim = 0;
//====================================================================== //======================================================================
// Use cout to avoid issues with %d/%lx etc
#define CHECK_RESULT(got, exp) \
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = " << (exp) << std::endl; \
return __LINE__; \
}
//======================================================================
#ifdef IS_VPI #ifdef IS_VPI
static int _zero_time_cb(p_cb_data cb_data) { static int _zero_time_cb(p_cb_data cb_data) {
@ -79,9 +71,9 @@ static int _start_of_sim_cb(p_cb_data cb_data) {
} }
static int _end_of_sim_cb(p_cb_data cb_data) { static int _end_of_sim_cb(p_cb_data cb_data) {
CHECK_RESULT(callback_count_start_of_sim, 1); TEST_CHECK_EQ(callback_count_start_of_sim, 1);
CHECK_RESULT(callback_count_zero_time, 1); TEST_CHECK_EQ(callback_count_zero_time, 1);
fprintf(stdout, "*-* All Finished *-*\n"); if (!errors) fprintf(stdout, "*-* All Finished *-*\n");
return 0; return 0;
} }

View File

@ -16,21 +16,9 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
bool got_error = false; #include "TestCheck.h"
// Use cout to avoid issues with %d/%lx etc int errors = 0;
#define CHECK_RESULT(got, exp) \
if ((got) != (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << ": GOT = " << (got) \
<< " EXP = " << (exp) << std::endl; \
got_error = true; \
}
#define CHECK_RESULT_CSTR(got, exp) \
if (strcmp((got), (exp))) { \
printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", __FILE__, __LINE__, \
(got) ? (got) : "<null>", (exp) ? (exp) : "<null>"); \
return __LINE__; \
}
vluint64_t main_time = 0; vluint64_t main_time = 0;
#ifdef T_WRAPPER_LEGACY #ifdef T_WRAPPER_LEGACY
@ -47,52 +35,52 @@ int main(int argc, char** argv, char** env) {
// Many used only by git@github.com:djg/verilated-rs.git // Many used only by git@github.com:djg/verilated-rs.git
Verilated::commandArgs(argc, argv); // Commonly used Verilated::commandArgs(argc, argv); // Commonly used
CHECK_RESULT_CSTR(Verilated::commandArgsPlusMatch("not-matching"), ""); TEST_CHECK_CSTR(Verilated::commandArgsPlusMatch("not-matching"), "");
const char* argadd[] = {"+testingPlusAdd+2", nullptr}; const char* argadd[] = {"+testingPlusAdd+2", nullptr};
Verilated::commandArgsAdd(1, argadd); Verilated::commandArgsAdd(1, argadd);
CHECK_RESULT_CSTR(Verilated::commandArgsPlusMatch("testingPlusAdd"), "+testingPlusAdd+2"); TEST_CHECK_CSTR(Verilated::commandArgsPlusMatch("testingPlusAdd"), "+testingPlusAdd+2");
Verilated::assertOn(true); Verilated::assertOn(true);
CHECK_RESULT(Verilated::assertOn(), true); TEST_CHECK_EQ(Verilated::assertOn(), true);
Verilated::calcUnusedSigs(true); Verilated::calcUnusedSigs(true);
CHECK_RESULT(Verilated::calcUnusedSigs(), true); TEST_CHECK_EQ(Verilated::calcUnusedSigs(), true);
Verilated::debug(9); // Commonly used Verilated::debug(9); // Commonly used
CHECK_RESULT(Verilated::debug(), 9); TEST_CHECK_EQ(Verilated::debug(), 9);
Verilated::debug(0); Verilated::debug(0);
Verilated::errorLimit(2); Verilated::errorLimit(2);
CHECK_RESULT(Verilated::errorLimit(), 2); TEST_CHECK_EQ(Verilated::errorLimit(), 2);
Verilated::fatalOnError(true); Verilated::fatalOnError(true);
CHECK_RESULT(Verilated::fatalOnError(), true); TEST_CHECK_EQ(Verilated::fatalOnError(), true);
Verilated::fatalOnVpiError(true); Verilated::fatalOnVpiError(true);
CHECK_RESULT(Verilated::fatalOnVpiError(), true); TEST_CHECK_EQ(Verilated::fatalOnVpiError(), true);
Verilated::gotError(false); Verilated::gotError(false);
CHECK_RESULT(Verilated::gotError(), false); TEST_CHECK_EQ(Verilated::gotError(), false);
Verilated::gotFinish(false); Verilated::gotFinish(false);
CHECK_RESULT(Verilated::gotFinish(), false); // Commonly used TEST_CHECK_EQ(Verilated::gotFinish(), false); // Commonly used
Verilated::mkdir(VL_STRINGIFY(TEST_OBJ_DIR) "/mkdired"); Verilated::mkdir(VL_STRINGIFY(TEST_OBJ_DIR) "/mkdired");
Verilated::randReset(0); Verilated::randReset(0);
CHECK_RESULT(Verilated::randReset(), 0); TEST_CHECK_EQ(Verilated::randReset(), 0);
Verilated::randSeed(1234); Verilated::randSeed(1234);
CHECK_RESULT(Verilated::randSeed(), 1234); TEST_CHECK_EQ(Verilated::randSeed(), 1234);
Verilated::traceEverOn(true); // Commonly used Verilated::traceEverOn(true); // Commonly used
CHECK_RESULT_CSTR(Verilated::productName(), Verilated::productName()); TEST_CHECK_CSTR(Verilated::productName(), Verilated::productName());
CHECK_RESULT_CSTR(Verilated::productVersion(), Verilated::productVersion()); TEST_CHECK_CSTR(Verilated::productVersion(), Verilated::productVersion());
CHECK_RESULT(Verilated::timeunit(), 12); TEST_CHECK_EQ(Verilated::timeunit(), 12);
CHECK_RESULT(Verilated::timeprecision(), 12); TEST_CHECK_EQ(Verilated::timeprecision(), 12);
VM_PREFIX* topp = new VM_PREFIX(); VM_PREFIX* topp = new VM_PREFIX();
@ -110,8 +98,8 @@ int main(int argc, char** argv, char** env) {
#endif #endif
< sim_time < sim_time
&& !Verilated::gotFinish()) { && !Verilated::gotFinish()) {
CHECK_RESULT(VL_TIME_Q(), main_time); TEST_CHECK_EQ(VL_TIME_Q(), main_time);
CHECK_RESULT(VL_TIME_D(), main_time); TEST_CHECK_EQ(VL_TIME_D(), main_time);
main_time += 1; main_time += 1;
#ifdef T_WRAPPER_LEGACY #ifdef T_WRAPPER_LEGACY
@ -133,5 +121,5 @@ int main(int argc, char** argv, char** env) {
VL_DO_DANGLING(delete topp, topp); VL_DO_DANGLING(delete topp, topp);
Verilated::runExitCallbacks(); Verilated::runExitCallbacks();
return got_error ? 10 : 0; return errors ? 10 : 0;
} }