From 46a8e8887cf9a6353c906dedf7126d1d7283ed2d Mon Sep 17 00:00:00 2001 From: std-max <85441682+std-max@users.noreply.github.com> Date: Tue, 10 May 2022 10:19:52 +0200 Subject: [PATCH 1/4] Add a testcase for #795 --- vunit/vhdl/run/test/run_tests.vhd | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vunit/vhdl/run/test/run_tests.vhd b/vunit/vhdl/run/test/run_tests.vhd index 61b3038fb..a65244fde 100644 --- a/vunit/vhdl/run/test/run_tests.vhd +++ b/vunit/vhdl/run/test/run_tests.vhd @@ -467,6 +467,27 @@ begin test_case_cleanup; + --------------------------------------------------------------------------- + banner("Should prevent from running a test from enabled_test_case more than once unless re-initialized."); + test_case_setup; + test_runner_setup(runner, "enabled_test_cases : Should one"); + for i in 0 to 1 loop + case i is + when 0 => + check(c, run("Should one"), "Expected ""Should one"" to run."); + when others => + check_false(c, run("Should one"), "Didn't expected ""Should one"" to run."); + end case; + end loop; + check_false(c, run("Should one"), "Didn't expect ""Should one"" to run."); + test_runner_setup(runner, "enabled_test_cases : Should one"); + while test_suite loop + check(c, run("Should one"), "Expected ""Should one"" to run."); + exit; + end loop; + + test_case_cleanup; + --------------------------------------------------------------------------- --banner("Should be possible to exit a test case or test suite with an error message that can be caught afterwards."); --test_case_setup; From bc9f94ac04f3e10af301dea1bdda272c334ee130 Mon Sep 17 00:00:00 2001 From: std-max <85441682+std-max@users.noreply.github.com> Date: Tue, 10 May 2022 11:55:28 +0200 Subject: [PATCH 2/4] Reset the number of run test cases when test_runner_setup is called --- vunit/vhdl/run/src/run.vhd | 14 ++++++-------- vunit/vhdl/run/src/runner_pkg.vhd | 7 +++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/vunit/vhdl/run/src/run.vhd b/vunit/vhdl/run/src/run.vhd index 4763e737a..aa00da477 100644 --- a/vunit/vhdl/run/src/run.vhd +++ b/vunit/vhdl/run/src/run.vhd @@ -87,6 +87,8 @@ package body run_pkg is end if; end loop; end if; + set_num_of_run_test_cases(runner_state, 0); + exit_gate(runner); set_phase(runner_state, test_suite_setup); notify(runner); @@ -234,7 +236,7 @@ package body run_pkg is if get_test_suite_completed(runner_state) then set_running_test_case(runner_state, ""); return false; - elsif get_run_all(runner_state) then + elsif get_run_all(runner_state) or get_test_case_name(runner_state, get_active_test_case_index(runner_state)) = name then if not has_run(name) then register_run(name); info(runner_trace_logger, "Test case: " & name); @@ -243,14 +245,10 @@ package body run_pkg is end if; set_running_test_case(runner_state, name); return true; + elsif get_test_case_name(runner_state, get_active_test_case_index(runner_state)) = name then + -- error(runner_trace_logger, "Test case: " & name & " cannot be run more than once unless re-initialization"); + return false; end if; - elsif get_test_case_name(runner_state, get_active_test_case_index(runner_state)) = name then - info(runner_trace_logger, "Test case: " & name); - if has_active_python_runner(runner_state) then - core_pkg.test_start(name); - end if; - set_running_test_case(runner_state, name); - return true; end if; set_running_test_case(runner_state, ""); diff --git a/vunit/vhdl/run/src/runner_pkg.vhd b/vunit/vhdl/run/src/runner_pkg.vhd index 7455622ed..3ddb1d6c6 100644 --- a/vunit/vhdl/run/src/runner_pkg.vhd +++ b/vunit/vhdl/run/src/runner_pkg.vhd @@ -84,6 +84,8 @@ package runner_pkg is procedure inc_num_of_run_test_cases(runner : runner_t); + procedure set_num_of_run_test_cases(runner : runner_t; new_value : integer); + procedure set_has_run_since_last_loop_check(runner : runner_t); procedure clear_has_run_since_last_loop_check(runner : runner_t); @@ -425,6 +427,11 @@ package body runner_pkg is set(runner.p_data, n_run_test_cases_idx, get_num_of_run_test_cases(runner) + 1); end; + procedure set_num_of_run_test_cases(runner : runner_t; new_value : integer) is + begin + set(runner.p_data, n_run_test_cases_idx, new_value); + end; + procedure set_has_run_since_last_loop_check(runner : runner_t) is begin set(runner.p_data, has_run_since_last_loop_check_idx, to_integer(true)); From cf1ab91e6faabea3a7440553e56aad8177f38fcc Mon Sep 17 00:00:00 2001 From: std-max <85441682+std-max@users.noreply.github.com> Date: Tue, 10 May 2022 12:58:44 +0200 Subject: [PATCH 3/4] Raise an error when a test case is called twice --- vunit/vhdl/run/src/run.vhd | 2 +- vunit/vhdl/run/test/run_tests.vhd | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/vunit/vhdl/run/src/run.vhd b/vunit/vhdl/run/src/run.vhd index aa00da477..97fef13da 100644 --- a/vunit/vhdl/run/src/run.vhd +++ b/vunit/vhdl/run/src/run.vhd @@ -246,7 +246,7 @@ package body run_pkg is set_running_test_case(runner_state, name); return true; elsif get_test_case_name(runner_state, get_active_test_case_index(runner_state)) = name then - -- error(runner_trace_logger, "Test case: " & name & " cannot be run more than once unless re-initialization"); + error(runner_trace_logger, "Test case: " & name & " cannot be run more than once unless re-initialization."); return false; end if; end if; diff --git a/vunit/vhdl/run/test/run_tests.vhd b/vunit/vhdl/run/test/run_tests.vhd index a65244fde..f9e6fa115 100644 --- a/vunit/vhdl/run/test/run_tests.vhd +++ b/vunit/vhdl/run/test/run_tests.vhd @@ -471,15 +471,17 @@ begin banner("Should prevent from running a test from enabled_test_case more than once unless re-initialized."); test_case_setup; test_runner_setup(runner, "enabled_test_cases : Should one"); - for i in 0 to 1 loop + for i in 0 to 2 loop case i is when 0 => check(c, run("Should one"), "Expected ""Should one"" to run."); when others => + mock(runner_trace_logger); check_false(c, run("Should one"), "Didn't expected ""Should one"" to run."); + check_log(runner_trace_logger, "Test case: Should one cannot be run more than once unless re-initialization.", error); + unmock(runner_trace_logger); end case; end loop; - check_false(c, run("Should one"), "Didn't expect ""Should one"" to run."); test_runner_setup(runner, "enabled_test_cases : Should one"); while test_suite loop check(c, run("Should one"), "Expected ""Should one"" to run."); From 76907f84f80b04e1005484f21a4fd968d725deda Mon Sep 17 00:00:00 2001 From: std-max <85441682+std-max@users.noreply.github.com> Date: Tue, 31 May 2022 18:14:17 +0200 Subject: [PATCH 4/4] Remove tests that check the ability to re-run a test case (as it is not a supported feature) --- vunit/vhdl/run/src/run.vhd | 2 +- vunit/vhdl/run/test/run_tests.vhd | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/vunit/vhdl/run/src/run.vhd b/vunit/vhdl/run/src/run.vhd index 97fef13da..7d7504a94 100644 --- a/vunit/vhdl/run/src/run.vhd +++ b/vunit/vhdl/run/src/run.vhd @@ -246,7 +246,7 @@ package body run_pkg is set_running_test_case(runner_state, name); return true; elsif get_test_case_name(runner_state, get_active_test_case_index(runner_state)) = name then - error(runner_trace_logger, "Test case: " & name & " cannot be run more than once unless re-initialization."); + error(runner_trace_logger, "Test case: " & name & " cannot be run more than once."); return false; end if; end if; diff --git a/vunit/vhdl/run/test/run_tests.vhd b/vunit/vhdl/run/test/run_tests.vhd index f9e6fa115..39bb9cc4b 100644 --- a/vunit/vhdl/run/test/run_tests.vhd +++ b/vunit/vhdl/run/test/run_tests.vhd @@ -468,24 +468,21 @@ begin test_case_cleanup; --------------------------------------------------------------------------- - banner("Should prevent from running a test from enabled_test_case more than once unless re-initialized."); + banner("Should prevent from running a test from enabled_test_case more than once."); test_case_setup; test_runner_setup(runner, "enabled_test_cases : Should one"); - for i in 0 to 2 loop - case i is - when 0 => - check(c, run("Should one"), "Expected ""Should one"" to run."); - when others => - mock(runner_trace_logger); - check_false(c, run("Should one"), "Didn't expected ""Should one"" to run."); - check_log(runner_trace_logger, "Test case: Should one cannot be run more than once unless re-initialization.", error); - unmock(runner_trace_logger); - end case; - end loop; - test_runner_setup(runner, "enabled_test_cases : Should one"); while test_suite loop - check(c, run("Should one"), "Expected ""Should one"" to run."); - exit; + for i in 0 to 2 loop + case i is + when 0 => + check(c, run("Should one"), "Expected ""Should one"" to run."); + when others => + mock(runner_trace_logger); + check_false(c, run("Should one"), "Didn't expected ""Should one"" to run."); + check_log(runner_trace_logger, "Test case: Should one cannot be run more than once.", error); + unmock(runner_trace_logger); + end case; + end loop; end loop; test_case_cleanup;