/* * CommandBus_test.cpp * * Created on: Mar 13, 2014 * Author: jonny */ #include #include #include "testUtils.h" #include "core/scheduling/ScheduledCommand.h" #include "core/Configuration.h" #include "core/ControllerState.h" #include "core/CommandBus.h" using ::testing::_; using ::testing::AtLeast; using ::testing::Expectation; using namespace testing; using namespace std; namespace core { class MockWrapper: public IControllerWrapper { public: MOCK_METHOD3(sendCommand, void (sc_time time, tlm::tlm_generic_payload& payload, Command command)); MOCK_METHOD2(sendTrigger, void (sc_time time, Trigger trigger)); }; class CommandBusTest: public Test { public: CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state, checker, mockControllerWrapper), clk(config.Timings.clk){} Configuration config; ControllerState state; MockWrapper mockControllerWrapper; CommandBus bus; std::vector checker; sc_time clk; }; TEST_F(CommandBusTest, cleanUpBusWorks) { shared_ptr dummy = createDummyPayload(); ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); bus.scheduleCommand(cmd1); bus.scheduleCommand(cmd2); bus.scheduleCommand(cmd3); bus.scheduleCommand(cmd4); EXPECT_EQ(4, bus.getPendingBusCommands().size()); bus.cleanUpBus(5*clk); EXPECT_EQ(2, bus.getPendingBusCommands().size()); } TEST_F(CommandBusTest, getEarliestStartTimeWorks) { shared_ptr dummy = createDummyPayload(); ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); ScheduledCommand collision(*dummy.get(), Read, 3*clk, clk); ScheduledCommand noCollision(*dummy.get(), Read, 6*clk, clk); bus.scheduleCommand(cmd1); bus.scheduleCommand(cmd2); bus.scheduleCommand(cmd3); bus.scheduleCommand(cmd4); EXPECT_EQ(4*clk, bus.getEarliestStartTime(collision)); EXPECT_EQ(6*clk, bus.getEarliestStartTime(noCollision)); } TEST_F(CommandBusTest, getESTDiesWithNotClkAligned) { shared_ptr dummy = createDummyPayload(); ScheduledCommand notAligned(*dummy.get(), Read, 2.5*clk, clk); EXPECT_DEATH(bus.getEarliestStartTime(notAligned), ".*"); } TEST_F(CommandBusTest, getLastCommandWorks) { shared_ptr dummy0 = createDummyPayload(Thread(0), Bank(0)); shared_ptr dummy2 = createDummyPayload(Thread(0), Bank(2)); ScheduledCommand read0(*dummy0.get(), Read, 2*clk, clk); ScheduledCommand read2(*dummy2.get(), Read, 3*clk, clk); bus.scheduleCommand(read0); bus.scheduleCommand(read2); EXPECT_EQ(read0, bus.getLastCommand(Read, read0.getBank())); EXPECT_EQ(read2, bus.getLastCommand(Read, read2.getBank())); EXPECT_EQ(read2.getStart(), bus.getLastCommand(Read).getStart()); } TEST_F(CommandBusTest, notYetScheduledWorks) { shared_ptr dummy = createDummyPayload(Thread(0), Bank(0)); ScheduledCommand read(*dummy.get(), Read, 2*clk, clk); EXPECT_TRUE(bus.notYetScheduled(Read)); bus.scheduleCommand(read); EXPECT_FALSE(bus.notYetScheduled(Read)); } } /* namespace controller */