Skip to content

Commit

Permalink
sreg test is now fully passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrf committed Dec 23, 2019
1 parent cbf1cb5 commit 993d985
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/ModuleDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ vector<EntryFunctionContainer *> ModuleDecl::getEntryFunctionContainer() {

int ModuleDecl::getNumInstances() { return instance_list_.size(); }

ModuleDecl::signalMapType ModuleDecl::getSignals() { return signals_; }
const ModuleDecl::signalMapType & ModuleDecl::getSignals() const { return signals_; }

ModuleDecl::processMapType ModuleDecl::getProcessMap() { return process_map_; }

Expand Down
24 changes: 12 additions & 12 deletions src/ModuleDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ using json = nlohmann::json;

class ModuleDecl {
public:
typedef pair<string, Signal *> signalPairType;
typedef map<string, Signal *> signalMapType;
typedef std::pair<std::string, Signal *> signalPairType;
typedef std::map<std::string, Signal *> signalMapType;

// Maps the name of the port with a pointer to a structure that holds
// information about the port.
typedef pair<string, PortDecl *> portPairType;
typedef std::pair<std::string, PortDecl *> portPairType;
// typedef map<string, PortDecl* > portMapType;

typedef pair<string, InterfaceDecl *> interfacePairType;
typedef map<string, InterfaceDecl *> interfaceMapType;
typedef std::pair<std::string, InterfaceDecl *> interfacePairType;
typedef std::map<std::string, InterfaceDecl *> interfaceMapType;

// Maps the name of the process with a pointer to a structure that holds
// information about the process.
typedef pair<string, ProcessDecl *> processPairType;
typedef map<string, ProcessDecl *> processMapType;
typedef std::pair<std::string, ProcessDecl *> processPairType;
typedef std::map<std::string, ProcessDecl *> processMapType;

typedef pair<string, string> moduleProcessPairType;
typedef std::pair<std::string, std::string> moduleProcessPairType;

typedef pair<string, string> portSignalPairType;
typedef map<string, string> portSignalMapType;
typedef std::pair<std::string, std::string> portSignalPairType;
typedef std::map<std::string, std::string> portSignalMapType;

// Why is this a not a Type?
typedef vector<string> instanceName;
typedef std::vector<std::string> instanceName;

// PortType
typedef std::vector<std::tuple<std::string, PortDecl *> > PortType;
Expand Down Expand Up @@ -112,7 +112,7 @@ class ModuleDecl {
vector<string> getInstanceList();
vector<EntryFunctionContainer *> getEntryFunctionContainer();
int getNumInstances();
signalMapType getSignals();
const signalMapType & getSignals() const;

void dumpPorts(raw_ostream &, int);
void dumpInterfaces(raw_ostream &, int);
Expand Down
186 changes: 85 additions & 101 deletions tests/sreg-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,122 +18,106 @@ using namespace clang::tooling;
using namespace clang::ast_matchers;
using namespace scpar;

TEST_CASE("sreg example",
"[llnl-examples]") {
TEST_CASE("sreg example", "[llnl-examples]") {
std::string code{systemc_clang::read_systemc_file(
systemc_clang::test_data_dir, "/llnl-examples/sreg.cpp")};
INFO(systemc_clang::test_data_dir);

auto catch_test_args = systemc_clang::catch_test_args;
catch_test_args.push_back("-I" + systemc_clang::test_data_dir + "/llnl-examples/");
catch_test_args.push_back("-I" + systemc_clang::test_data_dir +
"/llnl-examples/");

ASTUnit *from_ast =
tooling::buildASTFromCodeWithArgs(code, catch_test_args)
.release();
tooling::buildASTFromCodeWithArgs(code, catch_test_args).release();

SystemCConsumer sc{from_ast};
sc.HandleTranslationUnit(from_ast->getASTContext());
auto model{sc.getSystemCModel()};
// These are instances.
auto module_decl{model->getModuleDecl()};

cout << "\n";
for (const auto &decl : module_decl ) {
cout << "[ " << decl.first << " ]" << decl.second << " " << decl.second->getInstanceName() << "\n";
llvm::outs() << "\n";
for (const auto &decl : module_decl) {
llvm::outs() << "[ " << decl.first << " ]" << decl.second << " "
<< decl.second->getInstanceName() << "\n";
}

cout << "MODULE SIZE: " << module_decl.size();
SECTION("Found sc_modules", "[modules]") {
INFO( "ERROR: number of sc_module declarations found: " << module_decl.size() );
CHECK(module_decl.size() == 5);

auto test_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "test"; })};

auto sreg_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
REQUIRE(test_module != module_decl.end() );
REQUIRE(sreg_module != module_decl.end() );
// Testing instances.
auto test_module{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "testing";
})};

auto sreg_bypass{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "sreg_bypass";
})};

auto sreg_fwd{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "sreg_fwd";
})};

auto sreg_fwd_rev{std::find_if(
module_decl.begin(), module_decl.end(), [](const auto &element) {
return element.second->getInstanceName() == "sreg_fwd_rev";
})};

//
// Begin the tests.
//
//
SECTION("sreg instance and port tests", "[instances]") {
INFO("ERROR: number of sc_module declarations found: "
<< module_decl.size());
CHECK(module_decl.size() == 4);

REQUIRE(test_module != module_decl.end());
REQUIRE(sreg_bypass != module_decl.end());
REQUIRE(sreg_fwd != module_decl.end());
REQUIRE(sreg_fwd_rev != module_decl.end());

//
//
//
INFO("Checking sreg_bypass ports.");
auto sreg_bypass_decl{sreg_bypass->second};

REQUIRE(sreg_bypass_decl->getIPorts().size() == 2);
REQUIRE(sreg_bypass_decl->getOPorts().size() == 0);
REQUIRE(sreg_bypass_decl->getIOPorts().size() == 0);
REQUIRE(sreg_bypass_decl->getSignals().size() == 0);
REQUIRE(sreg_bypass_decl->getOtherVars().size() == 0);
REQUIRE(sreg_bypass_decl->getInputStreamPorts().size() == 1);
REQUIRE(sreg_bypass_decl->getOutputStreamPorts().size() == 1);

//
//
//
INFO("Checking sreg_fwd ports.");
auto sreg_fwd_decl{sreg_fwd->second};

REQUIRE(sreg_fwd_decl->getIPorts().size() == 2);
REQUIRE(sreg_fwd_decl->getOPorts().size() == 0);
REQUIRE(sreg_fwd_decl->getIOPorts().size() == 0);
REQUIRE(sreg_fwd_decl->getSignals().size() == 1);
REQUIRE(sreg_fwd_decl->getOtherVars().size() == 0);
REQUIRE(sreg_fwd_decl->getInputStreamPorts().size() == 1);
REQUIRE(sreg_fwd_decl->getOutputStreamPorts().size() == 1);

//
//
//
INFO("Checking sreg_fwd_rev ports.");

auto sreg_fwd_rev_decl{sreg_fwd_rev->second};

REQUIRE(sreg_fwd_rev_decl->getIPorts().size() == 2);
REQUIRE(sreg_fwd_rev_decl->getOPorts().size() == 0);
REQUIRE(sreg_fwd_rev_decl->getIOPorts().size() == 0);
REQUIRE(sreg_fwd_rev_decl->getSignals().size() == 7);
REQUIRE(sreg_fwd_rev_decl->getOtherVars().size() == 0);
REQUIRE(sreg_fwd_rev_decl->getInputStreamPorts().size() == 1);
REQUIRE(sreg_fwd_rev_decl->getOutputStreamPorts().size() == 1);
}

SECTION("Found sreg instances", "[instances]") {
auto module_instances{model->getModuleInstanceMap()};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
REQUIRE(module_instances[p_module->second].size() == 3);
}

SECTION("Checking sreg_bypass ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};

auto sreg_bypass{module_instances[p_module->second][0]};

REQUIRE(sreg_bypass->getIPorts().size() == 2);
REQUIRE(sreg_bypass->getOPorts().size() == 0);
REQUIRE(sreg_bypass->getIOPorts().size() == 0);
REQUIRE(sreg_bypass->getSignals().size() == 0);
REQUIRE(sreg_bypass->getOtherVars().size() == 0);
REQUIRE(sreg_bypass->getInputStreamPorts().size() == 1);
REQUIRE(sreg_bypass->getOutputStreamPorts().size() == 1);
}

SECTION("Checking sreg_fwd ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
auto sreg_fwd{module_instances[p_module->second][1]};

REQUIRE(sreg_fwd->getIPorts().size() == 2);
REQUIRE(sreg_fwd->getOPorts().size() == 0);
REQUIRE(sreg_fwd->getIOPorts().size() == 0);
REQUIRE(sreg_fwd->getSignals().size() == 1);
REQUIRE(sreg_fwd->getOtherVars().size() == 0);
REQUIRE(sreg_fwd->getInputStreamPorts().size() == 1);
REQUIRE(sreg_fwd->getOutputStreamPorts().size() == 1);
}

SECTION("Checking sreg_fwd_rev ports", "[ports]") {
auto module_instances{model->getModuleInstanceMap()};
//auto p_module{module_decl.find("sreg")};
auto p_module{
std::find_if(
module_decl.begin(), module_decl.end(),
[](const auto &element) { return element.first == "sreg"; })};
auto sreg_fwd_rev{module_instances[p_module->second][2]};

REQUIRE(sreg_fwd_rev->getIPorts().size() == 2);
REQUIRE(sreg_fwd_rev->getOPorts().size() == 0);
REQUIRE(sreg_fwd_rev->getIOPorts().size() == 0);
REQUIRE(sreg_fwd_rev->getSignals().size() == 7);
REQUIRE(sreg_fwd_rev->getOtherVars().size() == 0);
REQUIRE(sreg_fwd_rev->getInputStreamPorts().size() == 1);
REQUIRE(sreg_fwd_rev->getOutputStreamPorts().size() == 1);
}

// SECTION("No ports bound", "[ports]") {
// // The module instances have all the information.
// auto module_instances{model->getModuleInstanceMap()};
// auto p_module{module_decl["test"]};
// // There is only one module instance
// auto test_module{module_instances[p_module].front()};

// // Check if the proper number of ports are found.
// INFO("FAIL_TEST: A module must have a port bound for it to be recognized.");
// REQUIRE(test_module != nullptr);
// }
}

0 comments on commit 993d985

Please sign in to comment.