#include "testbench.h" #include #include #undef CHECK #include #include using namespace sc_core; factory::add> tb8; factory::add> tb9; factory::add> tb10; template unsigned run_scenario(STATE& state) { auto& dut = factory::get>(); dut.rst.write(true); sc_start(state.reset_cycles * dut.clk.period()); dut.rst.write(false); sc_start(dut.clk.period()); auto run1 = sc_spawn([&dut, &state]() { auto burst_cnt{0}; for(auto size:state.packet_sizes) { cxs_pkt_shared_ptr tx_pkt = cxs_pkt_mm::get().allocate(); tx_pkt->get_data().resize(size); auto phase{tlm::nw::REQUEST}; sc_core::sc_time t = sc_core::SC_ZERO_TIME; auto status = dut.isck->nb_transport_fw(*tx_pkt, phase, t); REQUIRE(status == tlm::TLM_UPDATED); REQUIRE(phase == tlm::nw::CONFIRM); if(++burst_cnt==state.granularity) { wait(dut.recv.data_written_event()); while(!dut.recv.empty()) { auto recv_pkt = dut.recv.front(); dut.recv.pop_front(); REQUIRE(tx_pkt==recv_pkt); REQUIRE(recv_pkt->get_data().size()==state.packet_sizes[state.resp_cnt]); state.resp_cnt++; } burst_cnt=0; } } }); unsigned cycles{0}; while(cycles < state.max_cycles && !(run1.terminated())) { // while(cycles<1000 && !(run5.terminated())){ sc_start(10 * dut.clk.period()); cycles += 10; } return cycles; } template unsigned run_scenario(int width, STATE &state) { switch (width) { case 8: case 256: return run_scenario<256>(state); case 9: case 512: return run_scenario<512>(state); case 10: case 1024: return run_scenario<1024>(state); } return 0; } TEST_CASE("single-packet", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; unsigned int max_cycles = 5000; std::vector packet_sizes; unsigned granularity{1}; unsigned resp_cnt{0}; } state; state.packet_sizes.assign({4, 8, 16, 32, 64, 128, 256, 1024}); for(auto width=8; width<11; ++width) { state.resp_cnt = 0; auto cycles = run_scenario(width, state); REQUIRE(cycles < state.max_cycles); REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); REQUIRE(state.resp_cnt == state.packet_sizes.size()); } } /* TEST_CASE("flit-alignment", "[CXS][tlm-level]") { struct { unsigned int reset_cycles{4}; std::vector packet_sizes; unsigned granularity{2}; unsigned resp_cnt{0}; } state; state.packet_sizes.assign({4, 32, 32, 8, 64, 128}); state.resp_cnt = 0; auto cycles = run_scenario(8, state); REQUIRE(cycles < 1000); REQUIRE(sc_report_handler::get_count(SC_ERROR) == 0); REQUIRE(sc_report_handler::get_count(SC_WARNING) == 0); REQUIRE(state.resp_cnt == state.packet_sizes.size()); } */