Included first test for CommandMux.
This commit is contained in:
72
DRAMSys/unitTests/CommandMuxTests.cpp
Normal file
72
DRAMSys/unitTests/CommandMuxTests.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <tlm.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "../library/src/controller/CommandMux.h"
|
||||
#include "../library/src/controller/Command.h"
|
||||
|
||||
class CommandMuxState
|
||||
{
|
||||
public:
|
||||
Command firstCommand;
|
||||
Command secondCommand;
|
||||
Command resultCommand;
|
||||
};
|
||||
|
||||
class CommandMuxTestBase : public testing::Test
|
||||
{
|
||||
public:
|
||||
CommandMux *commandMux;
|
||||
|
||||
tlm_generic_payload *firstPayload;
|
||||
tlm_generic_payload *secondPayload;
|
||||
|
||||
std::pair<Command, tlm_generic_payload *> firstPair;
|
||||
std::pair<Command, tlm_generic_payload *> secondPair;
|
||||
|
||||
std::vector<std::pair<Command, tlm_generic_payload *>> readyCommands;
|
||||
|
||||
std::pair<Command, tlm_generic_payload *> result;
|
||||
|
||||
CommandMuxTestBase()
|
||||
{
|
||||
commandMux = new CommandMux();
|
||||
firstPayload = new tlm_generic_payload();
|
||||
secondPayload = new tlm_generic_payload();
|
||||
}
|
||||
|
||||
~CommandMuxTestBase()
|
||||
{
|
||||
delete commandMux;
|
||||
delete firstPayload;
|
||||
delete secondPayload;
|
||||
}
|
||||
};
|
||||
|
||||
class CommandMuxTestParam : public CommandMuxTestBase, public testing::WithParamInterface<CommandMuxState>
|
||||
{
|
||||
public:
|
||||
CommandMuxTestParam()
|
||||
{
|
||||
commandMux->insertPayload(firstPayload);
|
||||
commandMux->insertPayload(secondPayload);
|
||||
|
||||
firstPair.first = GetParam().firstCommand;
|
||||
firstPair.second = firstPayload;
|
||||
secondPair.first = GetParam().secondCommand;
|
||||
secondPair.second = secondPayload;
|
||||
|
||||
readyCommands.push_back(secondPair);
|
||||
readyCommands.push_back(firstPair);
|
||||
result = commandMux->selectCommand(readyCommands);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(CommandMuxTestParam, satisfiesCommandOrder)
|
||||
{
|
||||
EXPECT_EQ(result.first, GetParam().resultCommand);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Default, CommandMuxTestParam, testing::Values(
|
||||
CommandMuxState{Command::RD, Command::WR, Command::RD},
|
||||
CommandMuxState{Command::RD, Command::ACT, Command::ACT}));
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
TEST(testsuite, test)
|
||||
{
|
||||
EXPECT_EQ(commandToString(Command::Activate), "ACT");
|
||||
EXPECT_EQ(commandToString(Command::ACT), "ACT");
|
||||
}
|
||||
|
||||
@@ -64,11 +64,15 @@ SOURCEHOME = ../library/src/
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
CommandMuxTests.cpp \
|
||||
$${SOURCEHOME}/controller/CommandMux.cpp \
|
||||
$${SOURCEHOME}/controller/Command.cpp
|
||||
|
||||
|
||||
|
||||
HEADERS += \
|
||||
Testfile.h \
|
||||
$${SOURCEHOME}/controller/CommandMux.h \
|
||||
$${SOURCEHOME}/controller/Command.h
|
||||
|
||||
DISTFILES += ../DRAMSys.astylerc
|
||||
|
||||
Reference in New Issue
Block a user