From c6167118d54a294eb1349283e4f7138fa7de2f08 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 5 Apr 2024 08:42:10 +0200 Subject: [PATCH] adds additional tests --- src/sc_main.cpp | 2 +- tests/cci_param_restricted/test.cpp | 60 ++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/sc_main.cpp b/src/sc_main.cpp index 6a26589..7ad3209 100644 --- a/src/sc_main.cpp +++ b/src/sc_main.cpp @@ -18,7 +18,7 @@ using namespace sc_core; int sc_main(int argc, char* argv[]) { auto my_name = util::split(argv[0], '/').back(); - scc::init_logging(LogConfig().logLevel(getenv("SCC_TEST_VERBOSE") ? log::DEBUG : log::FATAL).logAsync(false)); + scc::init_logging(LogConfig().logLevel(getenv("SCC_TEST_VERBOSE") ? log::DEBUG : log::FATAL).logAsync(false).msgTypeFieldWidth(35)); // create tracer if environment variable SCC_TEST_TRACE is defined std::unique_ptr tracer; if(getenv("SCC_TEST_TRACE")) diff --git a/tests/cci_param_restricted/test.cpp b/tests/cci_param_restricted/test.cpp index 0ffa6b5..3fb0f4c 100644 --- a/tests/cci_param_restricted/test.cpp +++ b/tests/cci_param_restricted/test.cpp @@ -17,24 +17,72 @@ struct top : public sc_core::sc_module { : sc_core::sc_module(nm) {} scc::cci_param_restricted param1{"param1", 1, scc::min_max_restriction(0, 10), "This is parameter 1"}; - scc::cci_param_restricted param2{"param2", 1, scc::min_restriction(0), "This is parameter 2"}; - scc::cci_param_restricted param3{"param3", 1, scc::min_max_excl_restriction(0, 10), "This is parameter 3"}; + scc::cci_param_restricted param2{"param2", 1, scc::min_max_excl_restriction(0, 10), "This is parameter 3"}; + scc::cci_param_restricted param3{"param3", 1, scc::min_restriction(0), "This is parameter 2"}; scc::cci_param_restricted param4{"param4", 1, scc::min_excl_restriction(0), "This is parameter 4"}; scc::cci_param_restricted param5{"param5", 4, scc::discrete_restriction({1, 2, 4, 8, 16}), "This is parameter 5"}; }; factory::add tb; -TEST_CASE("simple cci_param_restricted test", "[SCC][cci_param_restricted]") { - +TEST_CASE("simple cci_param_restricted min_max test", "[SCC][cci_param_restricted]") { + sc_report_handler::set_actions(SC_ERROR, SC_LOG | SC_CACHE_REPORT | SC_DISPLAY | SC_DO_NOTHING); auto& dut = factory::get(); auto run1 = sc_spawn([&dut]() { sc_core::wait(1_ns); - sc_core::sc_stop(); + for(auto i : {0, 5, 10, -1, 11}) { + dut.param1.set_value(i); + sc_core::wait(1_ns); + } }); sc_start(10_ns); REQUIRE(run1.terminated()); - REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 2); REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + sc_report_handler::initialize(); + auto run2 = sc_spawn([&dut]() { + sc_core::wait(1_ns); + for(auto i : {0, 5, 10, -1, 11}) { + dut.param2.set_value(i); + sc_core::wait(1_ns); + } + }); + + sc_start(10_ns); + REQUIRE(run2.terminated()); + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 4); + REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + sc_report_handler::initialize(); +} + +TEST_CASE("simple cci_param_restricted min test", "[SCC][cci_param_restricted]") { + sc_report_handler::set_actions(SC_ERROR, SC_LOG | SC_CACHE_REPORT | SC_DISPLAY | SC_DO_NOTHING); + auto& dut = factory::get(); + auto run1 = sc_spawn([&dut]() { + sc_core::wait(1_ns); + for(auto i : {0, 5, -1}) { + dut.param3.set_value(i); + sc_core::wait(1_ns); + } + }); + + sc_start(10_ns); + REQUIRE(run1.terminated()); + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 1); + REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + sc_report_handler::initialize(); + auto run2 = sc_spawn([&dut]() { + sc_core::wait(1_ns); + for(auto i : {0, 5, -1}) { + dut.param4.set_value(i); + sc_core::wait(1_ns); + } + }); + + sc_start(10_ns); + REQUIRE(run2.terminated()); + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 2); + REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + sc_report_handler::initialize(); }