From 12f3ecd6f30a0345bf8de5e2483f80c4ba47c200 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Thu, 10 Oct 2024 12:53:33 +0200 Subject: [PATCH] adds test for tracing of sc_fixed datatypes --- .cproject | 6 +- scc | 2 +- tests/CMakeLists.txt | 1 + tests/sc_fixed_tracing/CMakeLists.txt | 3 + tests/sc_fixed_tracing/sc_main.cpp | 82 +++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 tests/sc_fixed_tracing/CMakeLists.txt create mode 100644 tests/sc_fixed_tracing/sc_main.cpp diff --git a/.cproject b/.cproject index f7efdd6..f0cfc10 100644 --- a/.cproject +++ b/.cproject @@ -14,7 +14,7 @@ - + @@ -28,8 +28,8 @@ - - + + diff --git a/scc b/scc index 010aac1..966e575 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit 010aac102a7bfda042debf09c51981ee55c723ac +Subproject commit 966e575aba7f2f4ffc8a422d522f7173c4c7d98c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0d161b8..1e275dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(axi4_pin_level) add_subdirectory(ace_pin_level) add_subdirectory(configuration) add_subdirectory(configurer) +add_subdirectory(sc_fixed_tracing) if(FULL_TEST_SUITE) add_subdirectory(sim_performance) endif() diff --git a/tests/sc_fixed_tracing/CMakeLists.txt b/tests/sc_fixed_tracing/CMakeLists.txt new file mode 100644 index 0000000..8dcb049 --- /dev/null +++ b/tests/sc_fixed_tracing/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable (sc_fixed_tracing sc_main.cpp) +target_link_libraries (sc_fixed_tracing LINK_PUBLIC scc-sysc) +add_test(NAME sc_fixed_tracing_test COMMAND sc_fixed_tracing ) \ No newline at end of file diff --git a/tests/sc_fixed_tracing/sc_main.cpp b/tests/sc_fixed_tracing/sc_main.cpp new file mode 100644 index 0000000..769b18f --- /dev/null +++ b/tests/sc_fixed_tracing/sc_main.cpp @@ -0,0 +1,82 @@ +#define SC_INCLUDE_FX +#include +#include +#include +#include +#include +#include +#include + +using namespace sc_dt; +using namespace std; + +struct testbench : public sc_core::sc_module { + scc::sc_variable> a{"a", sc_dt::sc_fixed<6, 4>()}; + scc::sc_variable> b_sc_sat{"b_sc_sat", 0}; + scc::sc_variable> a_qant{"a_qant", 0}; + scc::sc_variable> b_sc_rnd{"b_sc_rnd", 0}; + scc::sc_variable> b_sc_trn{"b_sc_trn", 0}; + sc_fixed<5, 3> a_fixed; + sc_dt::sc_fix a_fix{5, 3}; + sc_fxtype_params params{5, 4}; + sc_fxtype_context context{params}; + // becase we do not specify in b_fix constructor anything + // the parameters are taken form the latest created context + sc_fix b_fix; + sc_fix c_fix{5, 3}; + + testbench(sc_core::sc_module_name const& nm) + : sc_module(nm) { + SC_HAS_PROCESS(testbench); + SC_THREAD(run); + } + + void trace(sc_core::sc_trace_file* trf) const override { + a.trace(trf); + scc::sc_trace(trf, a_fixed, std::string(name()) + ".a_fixed"); + scc::sc_trace(trf, a_fix, std::string(name()) + ".a_fix"); + scc::sc_trace(trf, b_fix, std::string(name()) + ".b_fix"); + scc::sc_trace(trf, c_fix, std::string(name()) + ".c_fix"); + } + + void run() { + wait(1_ns); + init(); + wait(1_ns); + test_overflow_modes(); + wait(1_ns); + test_quantization_modes(); + wait(1_ns); + this->a = 2; + wait(1_ps); + sc_core::sc_stop(); + } + + void init() { + a_fixed = 1.75; + a_fix = 1.75; + b_fix = 1.75; + c_fix = 1.75; + } + void test_overflow_modes() { + a = -7; + b_sc_sat = *a; + } + + void test_quantization_modes() { + a_qant = -2.3125; + b_sc_rnd = *a_qant; + b_sc_trn = *a_qant; + } +}; + +int sc_main(int sc_argc, char* sc_argv[]) { + scc::init_logging(scc::log::INFO); + scc::configurer cfg(""); + scc::tracer trc("sc_fixed_tracing"); + testbench tb("tb"); + sc_core::sc_start(); + SCCINFO("sc_main") << "End Simulation."; + + return sc_core::sc_report_handler::get_count(sc_core::SC_ERROR) + sc_core::sc_report_handler::get_count(sc_core::SC_WARNING); +} // End of 'sc_main'