From f2ab2fe3ee43a276588a9680749c86e3eacdf31e Mon Sep 17 00:00:00 2001 From: "Lukas Steiner (2)" Date: Thu, 25 Jul 2019 16:40:03 +0200 Subject: [PATCH] Included first test for CommandMux. --- DRAMSys/unitTests/CommandMuxTests.cpp | 72 +++++++++++++++++++++++++++ DRAMSys/unitTests/Testfile.h | 2 +- DRAMSys/unitTests/unitTests.pro | 4 ++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 DRAMSys/unitTests/CommandMuxTests.cpp diff --git a/DRAMSys/unitTests/CommandMuxTests.cpp b/DRAMSys/unitTests/CommandMuxTests.cpp new file mode 100644 index 00000000..6fc2736c --- /dev/null +++ b/DRAMSys/unitTests/CommandMuxTests.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#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 firstPair; + std::pair secondPair; + + std::vector> readyCommands; + + std::pair 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 +{ +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})); diff --git a/DRAMSys/unitTests/Testfile.h b/DRAMSys/unitTests/Testfile.h index 50726e5c..da025ef2 100644 --- a/DRAMSys/unitTests/Testfile.h +++ b/DRAMSys/unitTests/Testfile.h @@ -3,5 +3,5 @@ TEST(testsuite, test) { - EXPECT_EQ(commandToString(Command::Activate), "ACT"); + EXPECT_EQ(commandToString(Command::ACT), "ACT"); } diff --git a/DRAMSys/unitTests/unitTests.pro b/DRAMSys/unitTests/unitTests.pro index 375411e7..a39ed9a7 100644 --- a/DRAMSys/unitTests/unitTests.pro +++ b/DRAMSys/unitTests/unitTests.pro @@ -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