reworkes test infrastructure and tests
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
project (axi4_pin_level)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
sc_main.cpp
|
||||
narrow_burst_test.cpp
|
||||
${test_util_SOURCE_DIR}/sc_main.cpp
|
||||
)
|
||||
target_link_libraries (${PROJECT_NAME} PUBLIC scc test_util Catch2::Catch2)
|
||||
target_link_libraries (${PROJECT_NAME} PUBLIC test_util)
|
||||
|
||||
add_test(NAME narrow_burst COMMAND ${PROJECT_NAME})
|
@ -1,12 +1,31 @@
|
||||
|
||||
#define SC_INCLUDE_DYNAMIC_PROCESSES
|
||||
#include "../axi4_pin_level/testbench.h"
|
||||
#include "testbench.h"
|
||||
#include <factory.h>
|
||||
|
||||
#include <tlm/scc/tlm_gp_shared.h>
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
using namespace sc_core;
|
||||
|
||||
factory::add<testbench> tb;
|
||||
|
||||
bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload const& b){
|
||||
auto ret = true;
|
||||
ret &= a.get_command() == b.get_command();
|
||||
ret &= a.get_address() == b.get_address();
|
||||
ret &= a.get_data_length() == b.get_data_length();
|
||||
for(auto i=0u; i<a.get_data_length(); ++i)
|
||||
ret &= a.get_data_ptr()[i] == b.get_data_ptr()[i];
|
||||
if(a.get_byte_enable_ptr() && b.get_byte_enable_ptr()) {
|
||||
ret &= a.get_byte_enable_length() == b.get_byte_enable_length();
|
||||
for(auto i=0u; i<a.get_byte_enable_length(); ++i)
|
||||
ret &= a.get_byte_enable_ptr()[i] == b.get_byte_enable_ptr()[i];
|
||||
}
|
||||
ret &= a.get_command() == b.get_command();
|
||||
if(!ret) SCCWARN()<<"Comparison failed: "<<a<<" and "<<b;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename bus_cfg>
|
||||
tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, size_t len, unsigned id_offs = 0,
|
||||
unsigned addr_offs = 0) {
|
||||
@ -40,22 +59,26 @@ inline void randomize(tlm::tlm_generic_payload& gp) {
|
||||
req_cnt++;
|
||||
}
|
||||
|
||||
TEST_CASE("AXI", "[axi]") {
|
||||
TEST_CASE("pin level narrow burst", "[AXI][pin-level]") {
|
||||
struct {
|
||||
unsigned int ResetCycles{10};
|
||||
unsigned int BurstLengthByte{16};
|
||||
unsigned int NumberOfIterations{10};
|
||||
std::vector<tlm::scc::tlm_gp_shared_ptr> sent_read_tx, sent_write_tx;
|
||||
std::vector<tlm::scc::tlm_gp_shared_ptr> rcv_read_tx, rcv_write_tx;
|
||||
unsigned resp_cnt{0};
|
||||
} setup;
|
||||
} state;
|
||||
|
||||
auto& dut = factory::get<testbench>();
|
||||
dut.tgt_pe.set_operation_cb([&setup](axi::axi_protocol_types::tlm_payload_type& trans) -> unsigned {
|
||||
dut.tgt_pe.set_operation_cb([&state](axi::axi_protocol_types::tlm_payload_type& trans) -> unsigned {
|
||||
auto addr = trans.get_address();
|
||||
uint8_t const* src = reinterpret_cast<uint8_t const*>(&addr);
|
||||
for(size_t i = 0; i < trans.get_data_length(); ++i) {
|
||||
*(trans.get_data_ptr() + i) = i % 2 ? i : setup.resp_cnt;
|
||||
*(trans.get_data_ptr() + i) = i % 2 ? i : state.resp_cnt;
|
||||
}
|
||||
setup.resp_cnt++;
|
||||
if(trans.is_read()) state.rcv_read_tx.emplace_back(&trans);
|
||||
if(trans.is_write()) state.rcv_write_tx.emplace_back(&trans);
|
||||
state.resp_cnt++;
|
||||
return 0;
|
||||
});
|
||||
|
||||
@ -64,56 +87,66 @@ TEST_CASE("AXI", "[axi]") {
|
||||
dut.rst.write(true);
|
||||
sc_start(3*dut.clk.period());
|
||||
|
||||
auto run1 = sc_spawn([&dut, &setup](){
|
||||
auto run1 = sc_spawn([&dut, &state](){
|
||||
unsigned int StartAddr{0x20};
|
||||
for(int i = 0; i < setup.NumberOfIterations; ++i) {
|
||||
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
||||
SCCDEBUG("test") << "run0 executing transactions in iteration " << i;
|
||||
{ // 1
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, setup.BurstLengthByte);
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte);
|
||||
randomize(*trans);
|
||||
trans->set_command(tlm::TLM_READ_COMMAND);
|
||||
dut.intor_pe.transport(*trans, false);
|
||||
state.sent_read_tx.emplace_back(trans);
|
||||
if(trans->get_response_status() != tlm::TLM_OK_RESPONSE)
|
||||
SCCERR() << "Invalid response status" << trans->get_response_string();
|
||||
}
|
||||
StartAddr += setup.BurstLengthByte;
|
||||
StartAddr += state.BurstLengthByte;
|
||||
{ // 2
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, setup.BurstLengthByte);
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte);
|
||||
trans->set_command(tlm::TLM_WRITE_COMMAND);
|
||||
randomize(*trans);
|
||||
dut.intor_pe.transport(*trans, false);
|
||||
state.sent_read_tx.emplace_back(trans);
|
||||
if(trans->get_response_status() != tlm::TLM_OK_RESPONSE)
|
||||
SCCERR() << "Invalid response status" << trans->get_response_string();
|
||||
}
|
||||
StartAddr += setup.BurstLengthByte;
|
||||
StartAddr += state.BurstLengthByte;
|
||||
}
|
||||
});
|
||||
auto run2 = sc_spawn([&dut, &setup](){
|
||||
auto run2 = sc_spawn([&dut, &state](){
|
||||
unsigned int StartAddr{0x1020};
|
||||
for(int i = 0; i < setup.NumberOfIterations; ++i) {
|
||||
for(int i = 0; i < state.NumberOfIterations; ++i) {
|
||||
SCCDEBUG("test") << "run1 executing transactions in iteration " << i;
|
||||
{ // 1
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, setup.BurstLengthByte, 0x8);
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, 0x8);
|
||||
randomize(*trans);
|
||||
trans->set_command(tlm::TLM_READ_COMMAND);
|
||||
dut.intor_pe.transport(*trans, false);
|
||||
state.sent_write_tx.emplace_back(trans);
|
||||
if(trans->get_response_status() != tlm::TLM_OK_RESPONSE)
|
||||
SCCERR() << "Invalid response status" << trans->get_response_string();
|
||||
}
|
||||
StartAddr += setup.BurstLengthByte;
|
||||
StartAddr += state.BurstLengthByte;
|
||||
{ // 2
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, setup.BurstLengthByte, 0x8);
|
||||
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, state.BurstLengthByte, 0x8);
|
||||
trans->set_command(tlm::TLM_WRITE_COMMAND);
|
||||
randomize(*trans);
|
||||
dut.intor_pe.transport(*trans, false);
|
||||
state.sent_write_tx.emplace_back(trans);
|
||||
if(trans->get_response_status() != tlm::TLM_OK_RESPONSE)
|
||||
SCCERR() << "Invalid response status" << trans->get_response_string();
|
||||
}
|
||||
StartAddr += setup.BurstLengthByte;
|
||||
StartAddr += state.BurstLengthByte;
|
||||
}
|
||||
});
|
||||
sc_start(1000 * dut.clk.period());
|
||||
REQUIRE(run1.terminated());
|
||||
REQUIRE(run2.terminated());
|
||||
REQUIRE(setup.resp_cnt==40);
|
||||
REQUIRE(state.resp_cnt==40);
|
||||
REQUIRE(state.sent_write_tx.size() == state.rcv_write_tx.size());
|
||||
for(auto i = 0; i<state.sent_write_tx.size(); ++i)
|
||||
CHECK(*state.sent_write_tx[i] == *state.rcv_write_tx[i]);
|
||||
REQUIRE(state.sent_read_tx.size() == state.rcv_read_tx.size());
|
||||
for(auto i = 0; i<state.sent_write_tx.size(); ++i)
|
||||
CHECK(*state.sent_read_tx[i] == *state.rcv_read_tx[i]);
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* sc_main.cpp
|
||||
*
|
||||
* Created on:
|
||||
* Author:
|
||||
*/
|
||||
|
||||
#include "factory.h"
|
||||
#include <catch2/catch_session.hpp>
|
||||
#include "../axi4_pin_level/testbench.h"
|
||||
|
||||
using namespace scc;
|
||||
int sc_main(int argc, char* argv[]) {
|
||||
sc_report_handler::set_actions(SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_, SC_DO_NOTHING);
|
||||
scc::init_logging(LogConfig().logLevel(log::INFO).logAsync(false));
|
||||
scc::tracer trace("axi4_tlm_pin_tlm", scc::tracer::file_type::NONE, true);
|
||||
|
||||
factory::add<testbench> tb;
|
||||
|
||||
factory::get_instance().create();
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
factory::get_instance().destroy();
|
||||
|
||||
return result + sc_report_handler::get_count(SC_ERROR) + sc_report_handler::get_count(SC_WARNING);
|
||||
}
|
Reference in New Issue
Block a user