adds AXI4 pin level test and moves all tests to automatic discovery

This commit is contained in:
Eyck Jentzsch 2022-10-03 11:08:39 +02:00
parent b68b8c3045
commit e0c3e3d898
6 changed files with 62 additions and 31 deletions

View File

@ -18,14 +18,17 @@ using namespace sc_core;
int sc_main(int argc, char* argv[]) { int sc_main(int argc, char* argv[]) {
auto my_name = util::split(argv[0], '/').back(); auto my_name = util::split(argv[0], '/').back();
scc::init_logging(LogConfig().logLevel(getenv("SCC_TEST_VERBOSE")?log::DEBUG:log::INFO).logAsync(false)); scc::init_logging(LogConfig().logLevel(getenv("SCC_TEST_VERBOSE")?log::DEBUG:log::FATAL).logAsync(false));
// create tracer // create tracer if environment variable SCC_TEST_TRACE is defined
scc::tracer trace(my_name, scc::tracer::file_type::TEXT, true); std::unique_ptr<scc::tracer> tracer;
if(getenv("SCC_TEST_TRACE"))
tracer=std::make_unique<scc::tracer>(my_name, scc::tracer::file_type::TEXT, true);
// instantiate design(s) // instantiate design(s)
factory::get_instance().create(); factory::get_instance().create();
// run tests // run tests
int result = Catch::Session().run( argc, argv ); int result = Catch::Session().run( argc, argv );
// destroy design(s) // destroy design(s)
sc_stop();
factory::get_instance().destroy(); factory::get_instance().destroy();
return result; return result;
} }

View File

@ -6,5 +6,4 @@ add_executable(${PROJECT_NAME}
) )
target_link_libraries (${PROJECT_NAME} PUBLIC test_util) 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})

View File

@ -29,7 +29,7 @@ bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload cons
} }
template<typename bus_cfg> template<typename bus_cfg>
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}; static uint8_t id{0};
auto trans = tlm::scc::tlm_mm<>::get().allocate<axi::axi4_extension>(len); auto trans = tlm::scc::tlm_mm<>::get().allocate<axi::axi4_extension>(len);
trans->set_address(start_address); 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); trans->set_streaming_width(len);
ext->set_size(scc::ilog2(width)); ext->set_size(scc::ilog2(width));
sc_assert(len < (bus_cfg::BUSWIDTH / 8) || len % (bus_cfg::BUSWIDTH / 8) == 0); 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)) if(width==(bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
length++; length++;
ext->set_length(length); ext->set_length(length);
@ -88,7 +88,7 @@ void run_scenario(STATE& state){
for(int i = 0; i < state.NumberOfIterations; ++i) { for(int i = 0; i < state.NumberOfIterations; ++i) {
SCCDEBUG(__FUNCTION__) << "run0 executing transactions in iteration " << i; SCCDEBUG(__FUNCTION__) << "run0 executing transactions in iteration " << i;
{ // 1 { // 1
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0); tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0);
randomize(*trans); randomize(*trans);
trans->set_command(tlm::TLM_READ_COMMAND); trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans;
@ -99,7 +99,7 @@ void run_scenario(STATE& state){
SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string(); SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string();
} }
{ // 2 { // 2
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0); tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0);
trans->set_command(tlm::TLM_WRITE_COMMAND); trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans); randomize(*trans);
SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans;
@ -118,7 +118,7 @@ void run_scenario(STATE& state){
for(int i = 0; i < state.NumberOfIterations; ++i) { for(int i = 0; i < state.NumberOfIterations; ++i) {
SCCDEBUG(__FUNCTION__) << "run1 executing transactions in iteration " << i; SCCDEBUG(__FUNCTION__) << "run1 executing transactions in iteration " << i;
{ // 1 { // 1
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0x8); tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0x8);
randomize(*trans); randomize(*trans);
trans->set_command(tlm::TLM_READ_COMMAND); trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans;
@ -129,7 +129,7 @@ void run_scenario(STATE& state){
SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string(); SCCERR(__FUNCTION__) << "Invalid response status" << trans->get_response_string();
} }
{ // 2 { // 2
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes, 0x8); tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 0x8);
trans->set_command(tlm::TLM_WRITE_COMMAND); trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans); randomize(*trans);
SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans; SCCDEBUG(__FUNCTION__)<<"TX: "<<*trans;
@ -143,11 +143,47 @@ void run_scenario(STATE& state){
} }
}); });
sc_start(120 * dut.clk.period()); sc_start(120 * dut.clk.period());
REQUIRE(run1.terminated()); REQUIRE(run1.terminated());
REQUIRE(run2.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<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> read_tx;
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> 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<send_tx.size(); ++i)
CHECK(*send_tx[i] == *recv_tx[i]);
}
for(auto& e: state.read_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<send_tx.size(); ++i)
CHECK(*send_tx[i] == *recv_tx[i]);
}
}
TEST_CASE("axi4_narrow_burst", "[AXI][pin-level]") {
struct { struct {
unsigned int ResetCycles{4}; unsigned int ResetCycles{4};
unsigned int BurstLengthByte{16}; unsigned int BurstLengthByte{16};

View File

@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.12) project (io_redirector)
add_executable (io_redirector add_executable (${PROJECT_NAME} test.cpp)
main.cpp target_link_libraries (io_redirector LINK_PUBLIC scc-util Catch2::Catch2)
)
target_link_libraries (io_redirector LINK_PUBLIC scc)
add_test(NAME io_redirector_test COMMAND io_redirector) #add_test(NAME io_redirector_test COMMAND io_redirector)
catch_discover_tests(${PROJECT_NAME})

View File

@ -1,22 +1,17 @@
/* #define CATCH_CONFIG_MAIN
* main.cpp #include <catch2/catch_all.hpp>
*
* Created on: 01.01.2019
* Author: eyck
*/
#include <util/io-redirector.h> #include <util/io-redirector.h>
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#include <cassert>
int main(int arcg, char* argv[]){ TEST_CASE( "io-redirector", "[io-redirector]" ) {
util::IoRedirector::get().start(); util::IoRedirector::get().start();
auto result1 = util::IoRedirector::get().get_output(); auto result1 = util::IoRedirector::get().get_output();
assert(result1=="");
printf("Some output"); printf("Some output");
std::cout<<"Some other output"<<std::endl; std::cout<<"Some other output"<<std::endl;
auto result2 = util::IoRedirector::get().get_output(); auto result2 = util::IoRedirector::get().get_output();
assert(result2=="Some outputSome other output\n");
util::IoRedirector::get().stop(); util::IoRedirector::get().stop();
REQUIRE( result1=="" );
REQUIRE( result2=="Some outputSome other output\n" );
} }

View File

@ -6,5 +6,4 @@ add_executable(${PROJECT_NAME}
) )
target_link_libraries (${PROJECT_NAME} PUBLIC test_util) target_link_libraries (${PROJECT_NAME} PUBLIC test_util)
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) catch_discover_tests(${PROJECT_NAME})
#catch_discover_tests(${PROJECT_NAME})