From f9e500705da74cfbfcedc7c941179dfdbf832435 Mon Sep 17 00:00:00 2001 From: ping-ee Date: Mon, 23 Sep 2024 11:30:22 +0800 Subject: [PATCH 1/2] Wrap `exp` with parentheses in macros This change ensures correct operator precedence in assertions to prevent logical errors caused by missing parentheses. --- svut/svut_h.sv | 4 ++-- svut/template.sv | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/svut/svut_h.sv b/svut/svut_h.sv index edef5e5..ec02883 100644 --- a/svut/svut_h.sv +++ b/svut/svut_h.sv @@ -129,7 +129,7 @@ endfunction `define FAIL_IF_NOT(exp, message="") \ svut_status = 0; \ svut_msg = create_msg("FAIL_IF_NOT", message); \ - if (!exp) begin \ + if (!(exp)) begin \ `ERROR(svut_msg); \ svut_status = 1; \ end @@ -156,7 +156,7 @@ endfunction `define ASSERT(exp, message="") \ svut_status = 0; \ svut_msg = create_msg("ASSERT", message); \ - if (!exp) begin \ + if (!(exp)) begin \ `ERROR(svut_msg); \ svut_status = 1; \ end diff --git a/svut/template.sv b/svut/template.sv index cc4a961..c17e907 100644 --- a/svut/template.sv +++ b/svut/template.sv @@ -51,7 +51,7 @@ ${module_inst} // - `FAIL_IF_EQUAL(aSignal, 23): Increment error counter if evaluation is equal // - `FAIL_IF_NOT_EQUAL(aSignal, 45): Increment error counter if evaluation is not equal // - `ASSERT(aSignal): Increment error counter if evaluation is not true - // - `ASSERT((aSignal == 0)): Increment error counter if evaluation is not true + // - `ASSERT(aSignal == 0): Increment error counter if evaluation is not true // // Available flag: // From 9594a8d585de402e6f0ae736797bb0aadd727c11 Mon Sep 17 00:00:00 2001 From: ping-ee Date: Mon, 23 Sep 2024 12:05:17 +0800 Subject: [PATCH 2/2] Add `ASSERT` to Macro test --- test/Adder_KO_testsuite.sv | 2 ++ test/Adder_OK_testsuite.sv | 2 ++ test/testsuite_run.sh | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Adder_KO_testsuite.sv b/test/Adder_KO_testsuite.sv index d5c732d..1a167b2 100644 --- a/test/Adder_KO_testsuite.sv +++ b/test/Adder_KO_testsuite.sv @@ -95,6 +95,8 @@ module Adder_unit_test_KO; `FAIL_IF_NOT_EQUAL(out, 8'd0); `INFO("Test FAIL_IF_NOT_EQUAL"); `FAIL_IF_EQUAL(out, 8'd1); + `INFO("Test ASSERT"); + `ASSERT(inc === 1'b1); `ERROR("Test finished"); diff --git a/test/Adder_OK_testsuite.sv b/test/Adder_OK_testsuite.sv index 3b8c307..4cc95ae 100644 --- a/test/Adder_OK_testsuite.sv +++ b/test/Adder_OK_testsuite.sv @@ -98,6 +98,8 @@ module Adder_unit_test_OK; `FAIL_IF_EQUAL(out, 8'd0); `INFO("Test FAIL_IF_NOT_EQUAL"); `FAIL_IF_NOT_EQUAL(out, 8'd1); + `INFO("Test ASSERT"); + `ASSERT(inc === 1'b0); `SUCCESS("Test finished"); diff --git a/test/testsuite_run.sh b/test/testsuite_run.sh index 54be071..795a848 100644 --- a/test/testsuite_run.sh +++ b/test/testsuite_run.sh @@ -20,7 +20,7 @@ test_run_ko_testsuite() { #@test test_run_ko_testsuite_error_count() { #@test run exe_ko_to_log - error_num=9 + error_num=10 [ $(grep -c "ERROR:" log) -eq "$error_num" ] }