From e0c3e3d898e9bbc0e40e502fc9215276b38acedb Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Mon, 3 Oct 2022 11:08:39 +0200 Subject: [PATCH] adds AXI4 pin level test and moves all tests to automatic discovery --- src/sc_main.cpp | 9 ++-- tests/axi4_pin_level/CMakeLists.txt | 3 +- tests/axi4_pin_level/narrow_burst_test.cpp | 50 +++++++++++++++++++--- tests/io-redirector/CMakeLists.txt | 11 +++-- tests/io-redirector/{main.cpp => test.cpp} | 17 +++----- tests/ordered_semaphore/CMakeLists.txt | 3 +- 6 files changed, 62 insertions(+), 31 deletions(-) rename tests/io-redirector/{main.cpp => test.cpp} (62%) diff --git a/src/sc_main.cpp b/src/sc_main.cpp index 7f7ca07..8f3b71c 100644 --- a/src/sc_main.cpp +++ b/src/sc_main.cpp @@ -18,14 +18,17 @@ 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::INFO).logAsync(false)); - // create tracer - scc::tracer trace(my_name, scc::tracer::file_type::TEXT, true); + scc::init_logging(LogConfig().logLevel(getenv("SCC_TEST_VERBOSE")?log::DEBUG:log::FATAL).logAsync(false)); + // create tracer if environment variable SCC_TEST_TRACE is defined + std::unique_ptr tracer; + if(getenv("SCC_TEST_TRACE")) + tracer=std::make_unique(my_name, scc::tracer::file_type::TEXT, true); // instantiate design(s) factory::get_instance().create(); // run tests int result = Catch::Session().run( argc, argv ); // destroy design(s) + sc_stop(); factory::get_instance().destroy(); return result; } diff --git a/tests/axi4_pin_level/CMakeLists.txt b/tests/axi4_pin_level/CMakeLists.txt index 936623f..ffcfa7b 100644 --- a/tests/axi4_pin_level/CMakeLists.txt +++ b/tests/axi4_pin_level/CMakeLists.txt @@ -6,5 +6,4 @@ add_executable(${PROJECT_NAME} ) target_link_libraries (${PROJECT_NAME} PUBLIC test_util) -add_test(NAME narrow_burst COMMAND ${PROJECT_NAME}) -#catch_discover_tests(${PROJECT_NAME}) +catch_discover_tests(${PROJECT_NAME}) diff --git a/tests/axi4_pin_level/narrow_burst_test.cpp b/tests/axi4_pin_level/narrow_burst_test.cpp index 14282c1..7faae16 100644 --- a/tests/axi4_pin_level/narrow_burst_test.cpp +++ b/tests/axi4_pin_level/narrow_burst_test.cpp @@ -29,7 +29,7 @@ bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload cons } template -tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned len, unsigned width, unsigned id_offs) { +tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned addr_incr, unsigned len, unsigned width, unsigned id_offs) { static uint8_t id{0}; auto trans = tlm::scc::tlm_mm<>::get().allocate(len); trans->set_address(start_address); @@ -39,7 +39,7 @@ tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned len, un trans->set_streaming_width(len); ext->set_size(scc::ilog2(width)); sc_assert(len < (bus_cfg::BUSWIDTH / 8) || len % (bus_cfg::BUSWIDTH / 8) == 0); - auto length = (len * 8 - 1) / 32; + auto length = (len * 8 - 1) / (8*width); if(width==(bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8)) length++; ext->set_length(length); @@ -88,7 +88,7 @@ void run_scenario(STATE& state){ for(int i = 0; i < state.NumberOfIterations; ++i) { SCCDEBUG(__FUNCTION__) << "run0 executing transactions in iteration " << i; { // 1 - tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0); + tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0); randomize(*trans); trans->set_command(tlm::TLM_READ_COMMAND); SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; @@ -99,7 +99,7 @@ void run_scenario(STATE& state){ SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string(); } { // 2 - tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0); + tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0); trans->set_command(tlm::TLM_WRITE_COMMAND); randomize(*trans); SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; @@ -118,7 +118,7 @@ void run_scenario(STATE& state){ for(int i = 0; i < state.NumberOfIterations; ++i) { SCCDEBUG(__FUNCTION__) << "run1 executing transactions in iteration " << i; { // 1 - tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0x8); + tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0x8); randomize(*trans); trans->set_command(tlm::TLM_READ_COMMAND); SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; @@ -129,7 +129,7 @@ void run_scenario(STATE& state){ SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string(); } { // 2 - tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0x8); + tlm::scc::tlm_gp_shared_ptr trans = prepare_trans(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0x8); trans->set_command(tlm::TLM_WRITE_COMMAND); randomize(*trans); SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; @@ -143,11 +143,47 @@ void run_scenario(STATE& state){ } }); sc_start(120 * dut.clk.period()); + REQUIRE(run1.terminated()); REQUIRE(run2.terminated()); } -TEST_CASE("pin level narrow burst", "[AXI][pin-level]") { +TEST_CASE("axi4_burst_alignment", "[AXI][pin-level]") { + struct { + unsigned int ResetCycles{4}; + unsigned int BurstLengthByte{16}; + unsigned int BurstSizeBytes{8}; + unsigned int NumberOfIterations{8}; + std::unordered_map, std::vector>> read_tx; + std::unordered_map, std::vector>> write_tx; + unsigned resp_cnt{0}; + } state; + + run_scenario(state); + + REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); + REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); + + REQUIRE(state.resp_cnt==4*state.NumberOfIterations); + for(auto& e: state.write_tx) { + auto const& send_tx = e.second.first; + auto const& recv_tx = e.second.second; + REQUIRE(send_tx.size() == recv_tx.size()); + for(auto i = 0; i #include #include #include -#include -int main(int arcg, char* argv[]){ +TEST_CASE( "io-redirector", "[io-redirector]" ) { util::IoRedirector::get().start(); auto result1 = util::IoRedirector::get().get_output(); - assert(result1==""); printf("Some output"); std::cout<<"Some other output"<