applies cklang-tidy fixes

This commit is contained in:
Eyck Jentzsch 2023-12-22 20:42:21 +01:00
parent 288f0577f1
commit b9c9e15166
31 changed files with 607 additions and 537 deletions

View File

@ -1,4 +1,3 @@
---
Language: Cpp
# BasedOnStyle: LLVM
# should be in line with IndentWidth
@ -13,8 +12,8 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
@ -39,8 +38,8 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 140
CommentPragmas: '^( IWYU pragma:| @suppress)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 4
@ -76,13 +75,13 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false

3
.clang-tidy Normal file
View File

@ -0,0 +1,3 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-diagnostic-*,clang-analyzer-*'
WarningsAsErrors: ''

104
.cproject
View File

@ -28,6 +28,42 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule buildDir="build/${ConfigName}" dirtyTs="1703253448607" moduleId="de.marw.cmake4eclipse.mbs.settings">
<options/>
<defs>
<def name="CMAKE_BUILD_TYPE" type="STRING" val="Debug"/>
<def name="BUILD_SCC_DOCUMENTATION" type="BOOL" val="OFF"/>
<def name="ENABLE_CLANG_TIDY" type="STRING" val="ON"/>
</defs>
</storageModule>
</cconfiguration>
<cconfiguration id="cmake4eclipse.mbs.toolchain.cmake.134761605.1785168986">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cmake4eclipse.mbs.toolchain.cmake.134761605.1785168986" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.PE64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cmake4eclipse.mbs.toolchain.cmake.134761605.1785168986" name="Release" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cmake4eclipse.mbs.toolchain.cmake.134761605.1785168986." name="/" resourcePath="">
<toolChain id="cmake4eclipse.mbs.toolchain.cmake.16485475" name="CMake driven" superClass="cmake4eclipse.mbs.toolchain.cmake">
<targetPlatform id="cmake4eclipse.mbs.targetPlatform.cmake.1713261153" name="Any Platform" superClass="cmake4eclipse.mbs.targetPlatform.cmake"/>
<builder buildPath="/SystemC-Components-Test/build/Debug" id="cmake4eclipse.mbs.builder.322228822" keepEnvironmentInBuildfile="false" name="CMake Builder" superClass="cmake4eclipse.mbs.builder"/>
<tool id="cmake4eclipse.mbs.toolchain.tool.dummy.944613359" name="CMake" superClass="cmake4eclipse.mbs.toolchain.tool.dummy">
<inputType id="cmake4eclipse.mbs.inputType.c.1854920030" superClass="cmake4eclipse.mbs.inputType.c"/>
<inputType id="cmake4eclipse.mbs.inputType.cpp.525905746" superClass="cmake4eclipse.mbs.inputType.cpp"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule buildDir="build/${ConfigName}" dirtyTs="1673562408113" moduleId="de.marw.cmake4eclipse.mbs.settings">
<options/>
<defs>
@ -36,26 +72,56 @@
</defs>
</storageModule>
</cconfiguration>
<cconfiguration id="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022" moduleId="org.eclipse.cdt.core.settings" name="ClangTidy">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.PE64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022" name="ClangTidy" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.dockerdpath=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=ssh://eyck@kraftwerk02:22" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022." name="/" resourcePath="">
<toolChain id="cmake4eclipse.mbs.toolchain.cmake.1529597056" name="CMake driven" superClass="cmake4eclipse.mbs.toolchain.cmake">
<targetPlatform id="cmake4eclipse.mbs.targetPlatform.cmake.157305521" name="Any Platform" superClass="cmake4eclipse.mbs.targetPlatform.cmake"/>
<builder buildPath="/SystemC-Components-Test/build/Debug" id="cmake4eclipse.mbs.builder.407860995" keepEnvironmentInBuildfile="false" name="CMake Builder" superClass="cmake4eclipse.mbs.builder"/>
<tool id="cmake4eclipse.mbs.toolchain.tool.dummy.1269675407" name="CMake" superClass="cmake4eclipse.mbs.toolchain.tool.dummy">
<inputType id="cmake4eclipse.mbs.inputType.c.2145364949" superClass="cmake4eclipse.mbs.inputType.c"/>
<inputType id="cmake4eclipse.mbs.inputType.cpp.143816444" superClass="cmake4eclipse.mbs.inputType.cpp"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule buildDir="build/${ConfigName}" dirtyTs="1703253448607" moduleId="de.marw.cmake4eclipse.mbs.settings">
<options/>
<defs>
<def name="CMAKE_BUILD_TYPE" type="STRING" val="Debug"/>
<def name="BUILD_SCC_DOCUMENTATION" type="BOOL" val="OFF"/>
<def name="ENABLE_CLANG_TIDY" type="STRING" val="ON"/>
</defs>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="SystemC-Components-Test.null.276784792" name="SystemC-Components-Test"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="ClangTidy">
<resource resourceType="PROJECT" workspacePath="/SystemC-Components-Test"/>
</configuration>
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/SystemC-Components-Test"/>
</configuration>
<configuration configurationName="Debug"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605;cmake4eclipse.mbs.toolchain.cmake.134761605.1159094612;cmake4eclipse.mbs.toolchain.tool.dummy.326050058;cmake4eclipse.mbs.inputType.cpp.459033018">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605;cmake4eclipse.mbs.toolchain.cmake.134761605.1159094612;cmake4eclipse.mbs.toolchain.tool.dummy.326050058;cmake4eclipse.mbs.inputType.c.1524512146">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
@ -69,4 +135,24 @@
</target>
</buildTargets>
</storageModule>
<storageModule cmakelistsFolder="" moduleId="de.marw.cmake4eclipse.mbs.settings">
<targets>
<target name=""/>
</targets>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605;cmake4eclipse.mbs.toolchain.cmake.134761605.1159094612;cmake4eclipse.mbs.toolchain.tool.dummy.326050058;cmake4eclipse.mbs.inputType.c.1524512146">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022;cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022.;cmake4eclipse.mbs.toolchain.tool.dummy.1269675407;cmake4eclipse.mbs.inputType.c.2145364949">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605;cmake4eclipse.mbs.toolchain.cmake.134761605.1159094612;cmake4eclipse.mbs.toolchain.tool.dummy.326050058;cmake4eclipse.mbs.inputType.cpp.459033018">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022;cmake4eclipse.mbs.toolchain.cmake.134761605.1198783022.;cmake4eclipse.mbs.toolchain.tool.dummy.1269675407;cmake4eclipse.mbs.inputType.cpp.143816444">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
</cproject>

1
.gitignore vendored
View File

@ -43,3 +43,4 @@
/*.fst
/*.gtkw
/.envrc.*
/.direnv/

View File

@ -42,21 +42,21 @@ if(ENABLE_COVERAGE)
set(COVERAGE_EXCLUDES "osci-lib/scc/*" "/engr/dev/tools/*")
endif()
find_program(CLANG_TIDY_EXE NAMES "clang-tidy-9")
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if(ENABLE_CLANG_TIDY)
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CLANG_TIDY_CHECKS "-*,modernize-*,-modernize-use-trailing-return-type,clang-analyzer-core.*,clang-analyzer-cplusplus.*")
set(CMAKE_CXX_CLANG_TIDY
${CLANG_TIDY_EXE};
-checks=${CLANG_TIDY_CHECKS};
-fix;)
else()
message(AUTHOR_WARNING "clang-tidy not found!")
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE) # delete it
endif()
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
#set(CLANG_TIDY_CHECKS "-*,modernize-*,-modernize-use-trailing-return-type,clang-analyzer-core.*,clang-analyzer-cplusplus.*")
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE};-fix)
else()
message(AUTHOR_WARNING "clang-tidy not found!")
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE) # delete it
endif()
endif()
set(CLANG_FORMAT_EXCLUDE_PATTERNS "/third_party/")
find_package(ClangFormat)
set(CONAN_CMAKE_SILENT_OUTPUT ON)
conan_check()
conan_configure(REQUIRES fmt/8.0.1 spdlog/1.9.2 boost/1.75.0 gsl-lite/0.37.0 systemc/2.3.3 catch2/3.1.0 zlib/1.2.11 lz4/1.9.4

2
scc

@ -1 +1 @@
Subproject commit ffa0f2f7ef98790984fa3786c36b8778c5b52237
Subproject commit 6063f8da997247d68aec9422e39c93458f18bba0

View File

@ -7,39 +7,33 @@ auto factory::get_instance() -> factory& {
return instance;
}
factory::factory() :
m_constructors{},
m_objects{}
{ }
factory::factory()
: m_constructors{}
, m_objects{} {}
void factory::create() {
for (const auto& item : m_constructors) {
for(const auto& item : m_constructors) {
m_objects[item.first] = item.second();
}
}
void factory::destroy() {
m_objects.clear();
}
void factory::destroy() { m_objects.clear(); }
void factory::add_object(const std::string& name, constructor create) {
auto it = m_constructors.find(name);
if (it == m_constructors.cend()) {
if(it == m_constructors.cend()) {
m_constructors[name] = create;
}
else {
throw std::runtime_error("factory::add(): "
+ name + " object already exist in factory");
} else {
throw std::runtime_error("factory::add(): " + name + " object already exist in factory");
}
}
auto factory::get_object(const std::string& name) -> void* {
auto it = m_objects.find(name);
if (it == m_objects.cend()) {
throw std::runtime_error("factory::get(): "
+ name + " object doesn't exist in factory");
if(it == m_objects.cend()) {
throw std::runtime_error("factory::get(): " + name + " object doesn't exist in factory");
}
return it->second.get();

View File

@ -9,29 +9,28 @@
#ifndef SRC_FACTORY_H_
#define SRC_FACTORY_H_
#include <map>
#include <string>
#include <memory>
#include <functional>
#include <map>
#include <memory>
#include <string>
class factory {
public:
static factory& get_instance();
template<typename T, typename ...Args>
class add {
template <typename T, typename... Args> class add {
public:
add(Args&&... args);
add(const std::string& name, Args&&... args);
};
template<typename T>
static T& get(const std::string& name = "");
template <typename T> static T& get(const std::string& name = "");
void create();
void destroy();
private:
using destructor = std::function<void(void*)>;
using object = std::unique_ptr<void, destructor>;
@ -51,27 +50,15 @@ private:
std::map<std::string, object> m_objects;
};
template<typename T, typename ...Args>
factory::add<T, Args...>::add(Args&&... args) {
add("", args...);
template <typename T, typename... Args> factory::add<T, Args...>::add(Args&&... args) { add("", args...); }
template <typename T, typename... Args> factory::add<T, Args...>::add(const std::string& name, Args&&... args) {
factory::get_instance().add_object(name, [args...]() -> object {
return object{new T(std::forward<Args>(args)...), [](void* obj) { delete static_cast<T*>(obj); }};
});
}
template<typename T, typename ...Args>
factory::add<T, Args...>::add(const std::string& name, Args&&... args) {
factory::get_instance().add_object(name,
[args...] () -> object {
return object{
new T(std::forward<Args>(args)...),
[] (void* obj) {
delete static_cast<T*>(obj);
}
};
}
);
}
template<typename T> auto
factory::get(const std::string& name) -> T& {
template <typename T> auto factory::get(const std::string& name) -> T& {
return *static_cast<T*>(factory::get_instance().get_object(name));
}

View File

@ -7,26 +7,26 @@
#include "factory.h"
#include <catch2/catch_session.hpp>
#include <cstdlib>
#include <scc/report.h>
#include <scc/trace.h>
#include <scc/tracer.h>
#include <util/ities.h>
#include <cstdlib>
using namespace scc;
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::FATAL).logAsync(false));
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<scc::tracer> tracer;
if(getenv("SCC_TEST_TRACE"))
tracer=std::make_unique<scc::tracer>(my_name, scc::tracer::file_type::TEXT, true);
tracer = std::make_unique<scc::tracer>(my_name, scc::tracer::file_type::TEXT, true);
// instantiate design(s)
factory::get_instance().create();
// run tests
int result = Catch::Session().run( argc, argv );
int result = Catch::Session().run(argc, argv);
// destroy design(s)
sc_stop();
factory::get_instance().destroy();

View File

@ -10,14 +10,14 @@ using namespace sc_core;
factory::add<testbench> tb;
int snoop_id=0;
int snoop_id = 0;
bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload const& b){
bool is_equal(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)
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();
@ -25,11 +25,11 @@ bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload cons
// 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;
// if(!ret) SCCWARN()<<"Comparison failed: "<<a<<" and "<<b;
return ret;
}
template<typename bus_cfg>
template <typename bus_cfg>
tlm::tlm_generic_payload* prepare_trans_ace(uint64_t start_address, unsigned addr_incr, unsigned len, unsigned width, unsigned id) {
auto trans = tlm::scc::tlm_mm<>::get().allocate<axi::ace_extension>(len);
trans->set_address(start_address);
@ -39,54 +39,51 @@ tlm::tlm_generic_payload* prepare_trans_ace(uint64_t start_address, unsigned add
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) / (8*width);
if(width==(bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
auto length = (len * 8 - 1) / (8 * width);
if(width == (bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
length++;
ext->set_length(length);
// ext->set_burst(len * 8 > bus_cfg::buswidth ? axi::burst_e::INCR : axi::burst_e::FIXED);
// here len is CachelineSizeBytes
// here burtst for read/write_trans and snoop_trans are different
ext->set_burst(axi::burst_e::INCR); //TBD???
//ext->set_burst(len*8 > bus_cfg::BUSWIDTH ? axi::burst_e::WRAP : axi::burst_e::INCR);
ext->set_burst(axi::burst_e::INCR); // TBD???
// ext->set_burst(len*8 > bus_cfg::BUSWIDTH ? axi::burst_e::WRAP : axi::burst_e::INCR);
ext->set_id(id);
ext->set_snoop(axi::snoop_e::READ_SHARED); // set it so that is_data_less return true???
return trans;
}
inline void randomize(tlm::tlm_generic_payload& gp) {
static uint8_t req_cnt{0};
auto addr = gp.get_address();
uint8_t const* src = reinterpret_cast<uint8_t const*>(&addr);
static uint8_t req_cnt{0};
for(size_t i = 0; i < gp.get_data_length(); ++i) {
*(gp.get_data_ptr() + i) = i % 2 ? i : req_cnt;
}
req_cnt++;
}
template<typename STATE>
unsigned run_scenario(STATE& state){
template <typename STATE> unsigned run_scenario(STATE& state) {
auto& dut = factory::get<testbench>();
dut.axi_tgt_pe.set_operation_cb([&state](axi::axi_protocol_types::tlm_payload_type& trans) -> unsigned {
auto id = axi::get_axi_id(trans);
if(trans.is_read()) {
for(size_t i = 0; i < trans.get_data_length(); ++i) {
*(trans.get_data_ptr() + i) = i % 2 ? 123 : (state.resp_cnt+128);
*(trans.get_data_ptr() + i) = i % 2 ? 123 : (state.resp_cnt + 128);
}
state.read_tx[id].second.emplace_back(&trans);
}
if(trans.is_write())
state.write_tx[id].second.emplace_back(&trans);
SCCDEBUG(__FUNCTION__)<<"RX: "<<trans;
SCCDEBUG(__FUNCTION__) << "RX: " << trans;
state.resp_cnt++;
return 0;
});
dut.transport_cb = [&state](tlm::tlm_generic_payload& trans) -> unsigned {
SCCDEBUG(__FUNCTION__)<<" update snoop trans, with snoop_id = " << snoop_id;
SCCDEBUG(__FUNCTION__) << " update snoop trans, with snoop_id = " << snoop_id;
// extracting address and snoop_e from ac_trans and pack them into cache data trans
auto ac_address = trans.get_address();
auto ext = trans.get_extension<ace_extension>();
auto ac_snoop=ext->get_snoop();
auto ac_snoop = ext->get_snoop();
for(size_t i = 0; i < trans.get_data_length(); ++i) {
*(trans.get_data_ptr() + i) = i % 2 ? i : 128;
}
@ -95,80 +92,84 @@ unsigned run_scenario(STATE& state){
};
dut.rst.write(false);
sc_start(state.ResetCycles*dut.clk.period());
sc_start(state.ResetCycles * dut.clk.period());
dut.rst.write(true);
sc_start(dut.clk.period());
auto run1 = sc_spawn([&dut, &state](){
auto run1 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x0};
for(int i = 0; i < state.NumberOfIterations; ++i) {
// tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
// tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4,
// state.BurstLengthByte, state.BurstSizeBytes, 1);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.read_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
StartAddr += state.BurstSizeBytes;
}
});
auto run2 = sc_spawn([&dut, &state](){
auto run2 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x2000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 2);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 2);
trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans);
SCCDEBUG(__FUNCTION__) << "run2, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run2, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.write_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
StartAddr += state.BurstSizeBytes;
}
});
auto run3 = sc_spawn([&dut, &state](){
auto run3 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x1000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 3);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 3);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "run3, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run3, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.read_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
StartAddr += state.BurstSizeBytes;
}
});
auto run4 = sc_spawn([&dut, &state](){
auto run4 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x3000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 4);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 4);
trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans);
SCCDEBUG(__FUNCTION__) << "run4, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run4, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.write_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
StartAddr += state.BurstSizeBytes;
}
});
auto run5 = sc_spawn([&dut, &state](){
unsigned int StartAddr{0x0};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.CachelineSizeBytes, state.BurstSizeBytes, 5);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i << "snoop_id = " << snoop_id <<" TX: "<<*trans;
dut.ace_tgt_pe.snoop(*trans);
SCCDEBUG(__FUNCTION__) << "run1, after iteration "<< i ;
state.snoop_tx[snoop_id].first.emplace_back(trans);
snoop_id++;
StartAddr += state.BurstSizeBytes;
}
});
auto run5 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x0};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans_ace<testbench::bus_cfg>(StartAddr, 4, state.CachelineSizeBytes, state.BurstSizeBytes, 5);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i << "snoop_id = " << snoop_id << " TX: " << *trans;
dut.ace_tgt_pe.snoop(*trans);
SCCDEBUG(__FUNCTION__) << "run1, after iteration " << i;
state.snoop_tx[snoop_id].first.emplace_back(trans);
snoop_id++;
StartAddr += state.BurstSizeBytes;
}
});
unsigned cycles{0};
while(cycles<1000 && !(run1.terminated() && run2.terminated() && run3.terminated() && run4.terminated())){
// while(cycles<1000 && !(run5.terminated())){
while(cycles < 1000 && !(run1.terminated() && run2.terminated() && run3.terminated() && run4.terminated())) {
// while(cycles<1000 && !(run5.terminated())){
sc_start(10 * dut.clk.period());
cycles+=10;
cycles += 10;
}
return cycles;
}
@ -179,59 +180,59 @@ TEST_CASE("ace_burst_alignment", "[AXI][pin-level]") {
unsigned int BurstLengthByte{16};
unsigned int BurstSizeBytes{8};
unsigned int NumberOfIterations{2};
unsigned int CachelineSizeBytes={64}; //
unsigned int CachelineSizeBytes = {64}; //
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;
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> snoop_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;
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>>
snoop_tx;
unsigned resp_cnt{0};
} state;
state.resp_cnt=0;
state.resp_cnt = 0;
auto cycles = run_scenario(state);
// REQUIRE(cycles<1000);
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==4*state.NumberOfIterations);
// REQUIRE(state.resp_cnt==1*state.NumberOfIterations);
for(auto& e: state.write_tx) {
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
// REQUIRE(state.resp_cnt==1*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) {
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
CHECK(*send_tx[i] == *recv_tx[i]);
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
for(auto& e: state.read_tx) {
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){
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
SCCDEBUG(__FUNCTION__) << " index = " << i ;
// SCCDEBUG(__FUNCTION__) <<" send value = "<<*send_tx[i];
// SCCDEBUG(__FUNCTION__) <<" received value = "<<*recv_tx[i];
CHECK(*send_tx[i] == *recv_tx[i]);
SCCDEBUG(__FUNCTION__) << " index = " << i;
// SCCDEBUG(__FUNCTION__) <<" send value = "<<*send_tx[i];
// SCCDEBUG(__FUNCTION__) <<" received value = "<<*recv_tx[i];
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
for(auto& e: state.snoop_tx) {
for(auto& e : state.snoop_tx) {
auto const& snoop_tx = e.second.first;
auto const& recv_tx = e.second.second;
REQUIRE(snoop_tx.size() == recv_tx.size());
for(auto i = 0; i<snoop_tx.size(); ++i){
for(auto i = 0; i < snoop_tx.size(); ++i) {
REQUIRE(snoop_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
SCCDEBUG(__FUNCTION__) << " index = " << i ;
SCCDEBUG(__FUNCTION__) <<" send snoop value = "<<*snoop_tx[i];
SCCDEBUG(__FUNCTION__) <<" received value = "<<*recv_tx[i];
// CHECK(*snoop_tx[i] == *recv_tx[i]);
SCCDEBUG(__FUNCTION__) << " index = " << i;
SCCDEBUG(__FUNCTION__) << " send snoop value = " << *snoop_tx[i];
SCCDEBUG(__FUNCTION__) << " received value = " << *recv_tx[i];
// CHECK(*snoop_tx[i] == *recv_tx[i]);
}
}
}
TEST_CASE("ace_narrow_burst", "[AXI][pin-level]") {
@ -240,37 +241,35 @@ TEST_CASE("ace_narrow_burst", "[AXI][pin-level]") {
unsigned int BurstLengthByte{16};
unsigned int BurstSizeBytes{8};
unsigned int NumberOfIterations{2};
unsigned int CachelineSizeBytes={64}; //
unsigned int CachelineSizeBytes = {64}; //
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;
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>> snoop_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;
std::unordered_map<unsigned, std::pair<std::vector<tlm::scc::tlm_gp_shared_ptr>, std::vector<tlm::scc::tlm_gp_shared_ptr>>>
snoop_tx;
unsigned resp_cnt{0};
} state;
state.resp_cnt=0;
state.resp_cnt = 0;
auto cycles = run_scenario(state);
REQUIRE(cycles<1000);
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==4*state.NumberOfIterations);
for(auto& e: state.write_tx) {
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 i = 0; i < send_tx.size(); ++i)
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
for(auto& e: state.read_tx) {
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]);
for(auto i = 0; i < send_tx.size(); ++i)
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}

View File

@ -2,8 +2,8 @@
#define _TESTBENCH_H_
#include <axi/pe/axi_initiator.h>
#include <axi/pe/simple_target.h>
#include <axi/pe/simple_ace_target.h>
#include <axi/pe/simple_target.h>
#include <axi/pin/ace_initiator.h>
#include <axi/pin/ace_target.h>
#include <axi/scv/recorder_modules.h>
@ -13,10 +13,9 @@ using namespace sc_core;
using namespace axi;
using namespace axi::pe;
class testbench : public sc_core::sc_module
,public tlm::scc::pe::intor_bw_b {
class testbench : public sc_core::sc_module, public tlm::scc::pe::intor_bw_b {
public:
using bus_cfg = axi::ace_cfg</*BUSWIDTH=*/64, /*ADDRWIDTH=*/32, /*IDWIDTH=*/4, /*USERWIDTH=*/1,/*CACHELINE*/64>;
using bus_cfg = axi::ace_cfg</*BUSWIDTH=*/64, /*ADDRWIDTH=*/32, /*IDWIDTH=*/4, /*USERWIDTH=*/1, /*CACHELINE*/ 64>;
sc_core::sc_time clk_period{10, sc_core::SC_NS};
sc_core::sc_clock clk{"clk", clk_period, 0.5, sc_core::SC_ZERO_TIME, true};
@ -47,7 +46,8 @@ public:
public:
SC_HAS_PROCESS(testbench);
testbench(): testbench("testbench") {}
testbench()
: testbench("testbench") {}
testbench(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
, intor_pe("ace_intor_pe", intor)
@ -90,10 +90,14 @@ public:
ace_tgt_pe.isckt_axi(tgt_axi);
// for updating snooop transaction
intor_pe.bw_o(bw_i);
}
unsigned transport(tlm::tlm_generic_payload& trans) override { if(transport_cb) return transport_cb(trans); else return 0;}
unsigned transport(tlm::tlm_generic_payload& trans) override {
if(transport_cb)
return transport_cb(trans);
else
return 0;
}
std::function<unsigned(tlm::tlm_generic_payload&)> transport_cb;
};

View File

@ -10,13 +10,12 @@ using namespace sc_core;
using namespace ahb;
factory::add<testbench> tb;
bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload const& b){
bool is_equal(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)
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();
@ -24,12 +23,10 @@ bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload cons
// 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;
// if(!ret) SCCWARN()<<"Comparison failed: "<<a<<" and "<<b;
return ret;
}
template<unsigned BUSWIDTH>
tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned len, unsigned width) {
template <unsigned BUSWIDTH> tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned len, unsigned width) {
static unsigned id{0};
auto trans = tlm::scc::tlm_mm<>::get().allocate<ahb::ahb_extension>(len);
trans->set_address(start_address);
@ -42,47 +39,44 @@ tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned len, un
}
inline void randomize(tlm::tlm_generic_payload& gp) {
static uint8_t req_cnt{0};
auto addr = gp.get_address();
uint8_t const* src = reinterpret_cast<uint8_t const*>(&addr);
static uint8_t req_cnt{0};
for(size_t i = 0; i < gp.get_data_length(); ++i) {
*(gp.get_data_ptr() + i) = i % 2 ? i : req_cnt;
}
req_cnt++;
}
template<typename STATE>
unsigned run_scenario(STATE& state, unsigned wait_states = 0){
template <typename STATE> unsigned run_scenario(STATE& state, unsigned wait_states = 0) {
auto& dut = factory::get<testbench>();
dut.tsck.register_b_transport([&state, wait_states](tlm::tlm_base_protocol_types::tlm_payload_type& trans, sc_core::sc_time& d) {
if(trans.is_read()) {
for(size_t i = 0; i < trans.get_data_length(); ++i) {
*(trans.get_data_ptr() + i) = i % 2 ? i : (state.resp_cnt+128);
*(trans.get_data_ptr() + i) = i % 2 ? i : (state.resp_cnt + 128);
}
state.read_tx.second.emplace_back(&trans);
}
if(trans.is_write())
state.write_tx.second.emplace_back(&trans);
SCCDEBUG(__FUNCTION__)<<"RX: "<<trans;
for(unsigned i=0; i<wait_states; ++i)
SCCDEBUG(__FUNCTION__) << "RX: " << trans;
for(unsigned i = 0; i < wait_states; ++i)
sc_core::wait(factory::get<testbench>().clk.posedge_event());
state.resp_cnt++;
return 0;
});
dut.rst_n.write(false);
sc_start(state.ResetCycles*dut.clk.period());
sc_start(state.ResetCycles * dut.clk.period());
dut.rst_n.write(true);
sc_start(dut.clk.period());
dut.HSEL.write(true);
sc_start(dut.clk.period());
auto run1 = sc_spawn([&dut, &state](){
auto run1 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x0};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::DWIDTH>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "task run1, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "task run1, iteration " << i << " TX: " << *trans;
sc_core::sc_time d;
dut.isck->b_transport(*trans, d);
state.read_tx.first.emplace_back(trans);
@ -90,13 +84,13 @@ unsigned run_scenario(STATE& state, unsigned wait_states = 0){
}
SCCDEBUG(__FUNCTION__) << "task run1 finished";
});
auto run2 = sc_spawn([&dut, &state](){
auto run2 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x2000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::DWIDTH>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes);
trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans);
SCCDEBUG(__FUNCTION__) << "task run2, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "task run2, iteration " << i << " TX: " << *trans;
sc_core::sc_time d;
dut.isck->b_transport(*trans, d);
state.write_tx.first.emplace_back(trans);
@ -104,12 +98,12 @@ unsigned run_scenario(STATE& state, unsigned wait_states = 0){
}
SCCDEBUG(__FUNCTION__) << "task run2 finished";
});
auto run3 = sc_spawn([&dut, &state](){
auto run3 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x1000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::DWIDTH>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "task run3, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "task run3, iteration " << i << " TX: " << *trans;
sc_core::sc_time d;
dut.isck->b_transport(*trans, d);
state.read_tx.first.emplace_back(trans);
@ -117,13 +111,13 @@ unsigned run_scenario(STATE& state, unsigned wait_states = 0){
}
SCCDEBUG(__FUNCTION__) << "task run3 finished";
});
auto run4 = sc_spawn([&dut, &state](){
auto run4 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x3000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::DWIDTH>(StartAddr, state.BurstLengthByte, state.BurstSizeBytes);
trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans);
SCCDEBUG(__FUNCTION__) << "task run4, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "task run4, iteration " << i << " TX: " << *trans;
sc_core::sc_time d;
dut.isck->b_transport(*trans, d);
state.write_tx.first.emplace_back(trans);
@ -133,9 +127,9 @@ unsigned run_scenario(STATE& state, unsigned wait_states = 0){
});
unsigned cycles{0};
while(cycles<1000 && !(run1.terminated() && run2.terminated() && run3.terminated() && run4.terminated())){
while(cycles < 1000 && !(run1.terminated() && run2.terminated() && run3.terminated() && run4.terminated())) {
sc_start(10 * dut.clk.period());
cycles+=10;
cycles += 10;
}
return cycles;
}
@ -153,19 +147,19 @@ TEST_CASE("ahb_read_write", "[AHB][pin-level]") {
auto cycles = run_scenario(state);
REQUIRE(cycles<1000);
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==4*state.NumberOfIterations);
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
{
auto& e = state.write_tx;
auto const& send_tx = e.first;
auto const& recv_tx = e.second;
REQUIRE(send_tx.size() == recv_tx.size());
for(auto i = 0; i<send_tx.size(); ++i) {
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
CHECK(*send_tx[i] == *recv_tx[i]);
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
{
@ -173,9 +167,9 @@ TEST_CASE("ahb_read_write", "[AHB][pin-level]") {
auto const& send_tx = e.first;
auto const& recv_tx = e.second;
REQUIRE(send_tx.size() == recv_tx.size());
for(auto i = 0; i<send_tx.size(); ++i){
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
CHECK(*send_tx[i] == *recv_tx[i]);
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
}
@ -193,28 +187,26 @@ TEST_CASE("ahb_narrow_read_write", "[AHB][pin-level]") {
auto cycles = run_scenario(state);
REQUIRE(cycles<1000);
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==4*state.NumberOfIterations);
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
{
auto& e = state.write_tx;
auto const& send_tx = e.first;
auto const& recv_tx = e.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 i = 0; i < send_tx.size(); ++i)
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
{
auto& e = state.read_tx;
auto const& send_tx = e.first;
auto const& recv_tx = e.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 i = 0; i < send_tx.size(); ++i)
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
@ -231,19 +223,19 @@ TEST_CASE("ahb_delayed_read_write", "[AHB][pin-level]") {
auto cycles = run_scenario(state, 1);
REQUIRE(cycles<1000);
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==4*state.NumberOfIterations);
REQUIRE(state.resp_cnt == 4 * state.NumberOfIterations);
{
auto& e = state.write_tx;
auto const& send_tx = e.first;
auto const& recv_tx = e.second;
REQUIRE(send_tx.size() == recv_tx.size());
for(auto i = 0; i<send_tx.size(); ++i) {
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
CHECK(*send_tx[i] == *recv_tx[i]);
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
{
@ -251,10 +243,9 @@ TEST_CASE("ahb_delayed_read_write", "[AHB][pin-level]") {
auto const& send_tx = e.first;
auto const& recv_tx = e.second;
REQUIRE(send_tx.size() == recv_tx.size());
for(auto i = 0; i<send_tx.size(); ++i){
for(auto i = 0; i < send_tx.size(); ++i) {
REQUIRE(send_tx[i]->get_response_status() == tlm::TLM_OK_RESPONSE);
CHECK(*send_tx[i] == *recv_tx[i]);
CHECK(is_equal(*send_tx[i], *recv_tx[i]));
}
}
}

View File

@ -9,7 +9,7 @@ using namespace sc_core;
class testbench : public sc_core::sc_module {
public:
enum { DWIDTH = 32};
enum { DWIDTH = 32 };
sc_core::sc_time clk_period{10, sc_core::SC_NS};
sc_core::sc_clock clk{"clk", clk_period, 0.5, sc_core::SC_ZERO_TIME, true};
sc_core::sc_signal<bool> rst_n{"rst_n"};
@ -35,7 +35,8 @@ public:
public:
SC_HAS_PROCESS(testbench);
testbench(): testbench("testbench") {}
testbench()
: testbench("testbench") {}
testbench(sc_core::sc_module_name nm)
: sc_core::sc_module(nm) {
intor_bfm.HCLK_i(clk);
@ -71,9 +72,7 @@ public:
tgt_bfm.isckt(tsck);
}
void run1() {
}
void run1() {}
};
#endif // _TESTBENCH_H_

View File

@ -10,12 +10,12 @@ using namespace sc_core;
factory::add<testbench> tb;
bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload const& b){
bool is_equal(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)
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();
@ -23,11 +23,11 @@ bool operator==(tlm::tlm_generic_payload const& a, tlm::tlm_generic_payload cons
// 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;
// if(!ret) SCCWARN()<<"Comparison failed: "<<a<<" and "<<b;
return ret;
}
template<typename bus_cfg>
template <typename bus_cfg>
tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned addr_incr, unsigned len, unsigned width, unsigned id) {
auto trans = tlm::scc::tlm_mm<>::get().allocate<axi::axi4_extension>(len);
trans->set_address(start_address);
@ -37,8 +37,8 @@ tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned addr_in
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) / (8*width);
if(width==(bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
auto length = (len * 8 - 1) / (8 * width);
if(width == (bus_cfg::BUSWIDTH / 8) && start_address % (bus_cfg::BUSWIDTH / 8))
length++;
ext->set_length(length);
// ext->set_burst(len * 8 > bus_cfg::buswidth ? axi::burst_e::INCR : axi::burst_e::FIXED);
@ -48,79 +48,80 @@ tlm::tlm_generic_payload* prepare_trans(uint64_t start_address, unsigned addr_in
}
inline void randomize(tlm::tlm_generic_payload& gp) {
static uint8_t req_cnt{0};
auto addr = gp.get_address();
uint8_t const* src = reinterpret_cast<uint8_t const*>(&addr);
static uint8_t req_cnt{0};
for(size_t i = 0; i < gp.get_data_length(); ++i) {
*(gp.get_data_ptr() + i) = i % 2 ? i : req_cnt;
}
req_cnt++;
}
template<typename STATE>
unsigned run_scenario(STATE& state){
template <typename STATE> unsigned run_scenario(STATE& state) {
auto& dut = factory::get<testbench>();
dut.tgt_pe.set_operation_cb([&state](axi::axi_protocol_types::tlm_payload_type& trans) -> unsigned {
auto id = axi::get_axi_id(trans);
if(trans.is_read()) {
for(size_t i = 0; i < trans.get_data_length(); ++i) {
*(trans.get_data_ptr() + i) = i % 2 ? i : (state.resp_cnt+128);
*(trans.get_data_ptr() + i) = i % 2 ? i : (state.resp_cnt + 128);
}
state.read_tx[id].second.emplace_back(&trans);
}
if(trans.is_write())
state.write_tx[id].second.emplace_back(&trans);
SCCDEBUG(__FUNCTION__)<<"RX: "<<trans;
SCCDEBUG(__FUNCTION__) << "RX: " << trans;
state.resp_cnt++;
return 0;
});
dut.rst.write(false);
sc_start(state.ResetCycles*dut.clk.period());
sc_start(state.ResetCycles * dut.clk.period());
dut.rst.write(true);
sc_start(dut.clk.period());
auto run1 = sc_spawn([&dut, &state](){
auto run1 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x0};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 1);
trans->set_command(tlm::TLM_READ_COMMAND);
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run1, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.read_tx[axi::get_axi_id(*trans)].first.emplace_back(trans);
StartAddr += state.BurstSizeBytes;
}
});
auto run2 = sc_spawn([&dut, &state](){
auto run2 = sc_spawn([&dut, &state]() {
unsigned int StartAddr{0x2000};
for(int i = 0; i < state.NumberOfIterations; ++i) {
tlm::scc::tlm_gp_shared_ptr trans = prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 2);
tlm::scc::tlm_gp_shared_ptr trans =
prepare_trans<testbench::bus_cfg>(StartAddr, 4, state.BurstLengthByte, state.BurstSizeBytes, 2);
trans->set_command(tlm::TLM_WRITE_COMMAND);
randomize(*trans);
SCCDEBUG(__FUNCTION__) << "run2, iteration " << i <<" TX: "<<*trans;
SCCDEBUG(__FUNCTION__) << "run2, iteration " << i << " TX: " << *trans;
dut.intor_pe.transport(*trans, false);
state.write_tx[axi::get_axi_id(*trans)