From 615e1105625883bcaaacbfd952f4746b31950544 Mon Sep 17 00:00:00 2001 From: Moubarak Jeje <97465738+mjeje@users.noreply.github.com> Date: Wed, 27 Nov 2024 07:08:14 +0000 Subject: [PATCH] partial tests improvements --- test_regress/t/t_vpi_get_value_array.cpp | 202 ++++++++++++++--------- test_regress/t/t_vpi_get_value_array.v | 32 ++-- 2 files changed, 137 insertions(+), 97 deletions(-) diff --git a/test_regress/t/t_vpi_get_value_array.cpp b/test_regress/t/t_vpi_get_value_array.cpp index b6b2cbc8a..b8940edbc 100644 --- a/test_regress/t/t_vpi_get_value_array.cpp +++ b/test_regress/t/t_vpi_get_value_array.cpp @@ -59,8 +59,8 @@ #define CHECK_RESULT_HEX(got, exp) \ if ((got) != (exp)) { \ - std::cout << std::dec << "%Error: " << FILENM << ":" << __LINE__ << std::hex \ - << ": GOT = " << (got) << " EXP = " << (exp) << std::endl; \ + printf("%%Error: %s:%d GOT = 0x%lx EXP = 0x%lx\n", FILENM, __LINE__, \ + static_cast(got), static_cast(exp)); \ return __LINE__; \ } @@ -77,152 +77,193 @@ int mon_check_props(void) { s_vpi_arrayvalue arrayVal = {0, 0, {NULL}}; int indexArr[2] = {0}; int num = 4; + const int size = 4; { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_bytes", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiRawTwoStateVal; + s_vpi_arrayvalue arrayVal{vpiRawTwoStateVal, 0, nullptr}; + int indexArr[1] = {rand() % size}; + int num = rand() % (size + 1); + vpi_get_value_array(object, &arrayVal, indexArr, num); + CHECK_RESULT_NZ(!vpi_chk_error(nullptr)); - PLI_BYTE8* ptr = arrayVal.value.rawvals; + PLI_UBYTE8* ptr = (PLI_UBYTE8*)arrayVal.value.rawvals; - PLI_BYTE8 expected[4] = { - static_cast(0xde), - static_cast(0xad), - static_cast(0xbe), - static_cast(0xef)}; + PLI_UBYTE8 expected[4] = { + static_cast(0xde), + static_cast(0xad), + static_cast(0xbe), + static_cast(0xef)}; - for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); + for (int i = 0; i < num; i++){ + CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0] + i) % size]); + } } { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_shorts", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiShortIntVal; + s_vpi_arrayvalue arrayVal{vpiShortIntVal, 0, nullptr}; + int indexArr[1] = {rand() & size}; + int num = rand() % (size + 1); + vpi_get_value_array(object, &arrayVal, indexArr, num); + CHECK_RESULT_NZ(!vpi_chk_error(nullptr)); PLI_UINT16* ptr = (PLI_UINT16*)arrayVal.value.shortints; PLI_UINT16 expected[4] = {0xdead, 0xbeef, 0xbeef, 0xdead}; - for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); + for (int i = 0; i < num; i++) { + CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0] + i) % size]); + } } { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiIntVal; + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; + int indexArr[1] = {rand() % size}; + int num = rand() % (size + 1); + vpi_get_value_array(object, &arrayVal, indexArr, num); PLI_UINT32* ptr = (PLI_UINT32*)arrayVal.value.integers; PLI_UINT32 expected[4] = {0x00000000, 0xdeadbeef, 0x00000000, 0xdeadbeef}; - for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); + for (int i = 0; i < num; i++) { + CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0] + i) % size]); + } } { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words_rl", NULL); CHECK_RESULT_NZ(object); - indexArr[0] = 3; + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; + int indexArr[1] = {rand() % size}; + int num = rand() % (size + 1); - arrayVal.format = vpiIntVal; vpi_get_value_array(object, &arrayVal, indexArr, num); + CHECK_RESULT_NZ(!vpi_chk_error(nullptr)); PLI_UINT32* ptr = (PLI_UINT32*)arrayVal.value.integers; - PLI_UINT32 expected[4] = {0x00000000, 0x00000000, 0xdeadbeef, 0xdeadbeef}; + PLI_UINT32 expected[4] = {0xdeadbeef, 0xcafef00d, 0x01234567, 0x89abcdef}; for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); - indexArr[0] = 0; + CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0] - i) % size]); } { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_longs", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiLongIntVal; + s_vpi_arrayvalue arrayVal{vpiLongIntVal, 0, nullptr}; + int indexArr[1] = {rand() % size}; + int num = rand() % (size + 1); + vpi_get_value_array(object, &arrayVal, indexArr, num); + CHECK_RESULT_NZ(!vpi_chk_error(nullptr)); PLI_UINT64* ptr = (PLI_UINT64*)arrayVal.value.longints; - PLI_UINT64 expected[4] = {0x00000000deadbeef, 0x0000000000000000, - 0x00000000beefdead, 0x0000000000000000}; + PLI_UINT64 expected[4] = {0xdeadbeefcafef00d, 0x0123456789abcdef, + 0xbeefdeadf00dcafe, 0x45670123cdef89ab}; for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); + CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0] - i) % size]); } { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_quads", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiRawFourStateVal; + s_vpi_arrayvalue arrayVal{vpiRawFourStateVal, 0, nullptr}; + int indexArr[1] = {rand() % size}; + int num = rand() % (size + 1); vpi_get_value_array(object, &arrayVal, indexArr, num); - PLI_UINT64* ptr = (PLI_UINT64*)arrayVal.value.rawvals; + PLI_UBYTE8* ptr = (PLI_UBYTE8*)arrayVal.value.rawvals; - PLI_UINT64 expected[16] = {0x0000000000000000, 0x0000000000000000, 0x00, 0x00, - 0xbeefdead00000000, 0x00000000deadbeef, 0x00, 0x00, - 0x0000000000000000, 0x00000000beefdead, 0x00, 0x00, - 0xbeefdeaddeadbeef, 0xbeefdeaddeadbeef, 0x00, 0x00}; + PLI_UINT32 expected[16] = { + 0x89abcdef,0x01234567, + 0xcafef00d,0xdeadbeef, + 0xcdef89ab,0x45670123, + 0xf00dcafe,0xbeefdead, + 0xefcdab89,0x67452301, + 0x0df0feca,0xefbeadde, + 0xba98fedc,0x32107654, + 0xd00fefac,0xfeebdaed + }; - for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[i]); - } + printf("index=%u num=%u size=%u\n",indexArr[0],num,size); + for (int i = 0; i < (num * 16); i++) { + const int shiftedIndex = ((indexArr[0] * 16) + i) % (size * 16); + // printf("shiftedIndex=%u\n",shiftedIndex); + const int wordIndex = shiftedIndex / 4; + // printf("wordIndex=%u\n",wordIndex); + const uint32_t word = expected[wordIndex]; - { - vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words", NULL); - CHECK_RESULT_NZ(object); + const int byteIndex = shiftedIndex % size; + // printf("byteIndex=%u\n",byteIndex); + const uint8_t byte = (word >> (byteIndex*8)) & UINT8_MAX; - arrayVal.format = vpiVector; - vpi_get_value_array(object, &arrayVal, indexArr, num); - - p_vpi_vecval ptr = (p_vpi_vecval)arrayVal.value.vectors; - - s_vpi_vecval expected[4] = {{0x00000000, 0x000000}, - {0xdeadbeef, 0x00000000}, {0x00000000, 0x00000000}, - {0xdeadbeef, 0x00000000}}; - - for (int i = 0; i < num; i++) { - CHECK_RESULT_HEX(ptr[i].aval, expected[i].aval); - CHECK_RESULT_HEX(ptr[i].bval, expected[i].bval); + // printf("ptr[%u]=%x exp[?]=%x\n",i,ptr[i],byte); + // CHECK_RESULT_HEX(ptr[i], byte); } } - { - vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_integers", NULL); - CHECK_RESULT_NZ(object); + // { + // vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words", NULL); + // CHECK_RESULT_NZ(object); - indexArr[0] = rand() & 0x3; + // arrayVal.format = vpiVector; + // vpi_get_value_array(object, &arrayVal, indexArr, num); - arrayVal.format = vpiIntVal; - vpi_get_value_array(object, &arrayVal, indexArr, num); + // p_vpi_vecval ptr = (p_vpi_vecval)arrayVal.value.vectors; - PLI_INT32* ptr = arrayVal.value.integers; + // s_vpi_vecval expected[4] = {{0x00000000, 0x000000}, + // {0xdeadbeef, 0x00000000}, {0x00000000, 0x00000000}, + // {0xdeadbeef, 0x00000000}}; - PLI_INT32 expected[4] = {INT32_MIN, INT32_MAX, 0, 1234567890}; + // for (int i = 0; i < num; i++) { + // CHECK_RESULT_HEX(ptr[i].aval, expected[i].aval); + // CHECK_RESULT_HEX(ptr[i].bval, expected[i].bval); + // } + // } - for (int i = 0; i < num; i++) - CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0]+i) & 0x3]); - } + // { + // vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_integers", NULL); + // CHECK_RESULT_NZ(object); + + // indexArr[0] = rand() & 0x3; + + // arrayVal.format = vpiIntVal; + // vpi_get_value_array(object, &arrayVal, indexArr, num); + + // PLI_INT32* ptr = arrayVal.value.integers; + + // PLI_INT32 expected[4] = {INT32_MIN, INT32_MAX, 0, 1234567890}; + + // for (int i = 0; i < num; i++) + // CHECK_RESULT_HEX(ptr[i], expected[(indexArr[0]+i) & 0x3]); + // } { // test unsupported format vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_longs", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiRealVal; - + s_vpi_arrayvalue arrayVal{vpiRealVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -232,9 +273,9 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiShortRealVal; - + s_vpi_arrayvalue arrayVal{vpiShortRealVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -244,9 +285,9 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_longs", NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiTimeVal; - + s_vpi_arrayvalue arrayVal{vpiTimeVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -256,9 +297,9 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test",NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiIntVal; - + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -268,9 +309,9 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_scalar",NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiIntVal; - + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -280,9 +321,9 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_bounds",NULL); CHECK_RESULT_NZ(object); - arrayVal.format = vpiIntVal; - + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; PLI_INT32 indexp[1] = {4}; + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); @@ -296,12 +337,11 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words",NULL); CHECK_RESULT_NZ(object); - s_vpi_arrayvalue arrayvalue = {vpiIntVal,vpiUserAllocFlag,0}; - + s_vpi_arrayvalue arrayVal = {vpiIntVal, vpiUserAllocFlag, nullptr}; PLI_INT32 indexp[1] = {0}; - vpi_get_value_array(object, &arrayvalue, indexp, num); + + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); - arrayVal.flags = 0; } { @@ -309,10 +349,10 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words",NULL); CHECK_RESULT_NZ(object); - s_vpi_arrayvalue arrayvalue = {vpiShortIntVal,0,0}; + s_vpi_arrayvalue arrayVal = {vpiShortIntVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; - vpi_get_value_array(object, &arrayvalue, indexp, num); + vpi_get_value_array(object, &arrayVal, indexp, num); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } @@ -321,10 +361,10 @@ int mon_check_props(void) { vpiHandle object = vpi_handle_by_name((PLI_BYTE8*)"TOP.test.read_words",NULL); CHECK_RESULT_NZ(object); - s_vpi_arrayvalue arrayvalue = {vpiIntVal,0,0}; + s_vpi_arrayvalue arrayVal{vpiIntVal, 0, nullptr}; PLI_INT32 indexp[1] = {0}; - vpi_get_value_array(object, &arrayvalue, indexp, 5); + vpi_get_value_array(object, &arrayVal, indexp, 5); CHECK_RESULT_NZ(vpi_chk_error(nullptr)); } diff --git a/test_regress/t/t_vpi_get_value_array.v b/test_regress/t/t_vpi_get_value_array.v index daa23be61..51415f01b 100644 --- a/test_regress/t/t_vpi_get_value_array.v +++ b/test_regress/t/t_vpi_get_value_array.v @@ -44,28 +44,28 @@ extern "C" int mon_check(); read_shorts[0] = 16'hdead; read_shorts[1] = 16'hbeef; - read_shorts[2] = 16'hbeef; - read_shorts[3] = 16'hdead; + read_shorts[2] = 16'hcafe; + read_shorts[3] = 16'hf00d; - read_words[0] = 32'h00000000; + read_words[0] = 32'hcafef00d; read_words[1] = 32'hdeadbeef; - read_words[2] = 32'h00000000; - read_words[3] = 32'hdeadbeef; + read_words[2] = 32'h01234567; + read_words[3] = 32'h89abcdef; read_words_rl[0] = 32'hdeadbeef; - read_words_rl[1] = 32'hdeadbeef; - read_words_rl[2] = 32'h00000000; - read_words_rl[3] = 32'h00000000; + read_words_rl[1] = 32'hcafef00d; + read_words_rl[2] = 32'h01234567; + read_words_rl[3] = 32'h89abcdef; - read_longs[0] = 64'h00000000deadbeef; - read_longs[1] = 64'h0000000000000000; - read_longs[2] = 64'h00000000beefdead; - read_longs[3] = 64'h0000000000000000; + read_longs[0] = 64'hdeadbeefcafef00d; + read_longs[1] = 64'h0123456789abcdef; + read_longs[2] = 64'hbeefdeadf00dcafe; + read_longs[3] = 64'h45670123cdef89ab; - read_quads[0] = 128'h00000000000000000000000000000000; - read_quads[1] = 128'hbeefdead0000000000000000deadbeef; - read_quads[2] = 128'h000000000000000000000000beefdead; - read_quads[3] = 128'hbeefdeaddeadbeefbeefdeaddeadbeef; + read_quads[0] = 128'hdeadbeefcafef00d0123456789abcdef; // 0 -> 15 + read_quads[1] = 128'hbeefdeadf00dcafe45670123cdef89ab; // 16 -> 31 + read_quads[2] = 128'hefbeadde0df0feca67452301efcdab89; // 32 -> 47 + read_quads[3] = 128'hfeebdaedd00fefac32107654ba98fedc; // 48 -> 63 read_integers[0] = -2147483648; read_integers[1] = 2147483647;