just a sc_time. pointer to transaction is invalidated as soon as the transaction is sent to the wrapper.
117 lines
3.3 KiB
C++
117 lines
3.3 KiB
C++
/*
|
|
* CommandBus_test.cpp
|
|
*
|
|
* Created on: Mar 13, 2014
|
|
* Author: jonny
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
#include <gmock/gmock.h>
|
|
#include "testUtils.h"
|
|
#include "core/scheduling/ScheduledCommand.h"
|
|
#include "core/Configuration.h"
|
|
#include "core/ControllerState.h"
|
|
#include "core/scheduling/CommandBus.h"
|
|
|
|
using ::testing::_;
|
|
using ::testing::AtLeast;
|
|
using ::testing::Expectation;
|
|
using namespace testing;
|
|
using namespace std;
|
|
|
|
namespace controller {
|
|
|
|
class CommandBusTest: public Test
|
|
{
|
|
public:
|
|
CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state, checker), clk(config.Timings.clk){}
|
|
|
|
Configuration config;
|
|
ControllerState state;
|
|
CommandBus bus;
|
|
|
|
std::vector<ICommandChecker*> checker;
|
|
sc_time clk;
|
|
};
|
|
|
|
TEST_F(CommandBusTest, cleanUpBusWorks)
|
|
{
|
|
shared_ptr<tlm::tlm_generic_payload> dummy = createDummyPayload();
|
|
ScheduledCommand cmd1(*dummy.get(), Command::Read, 2*clk, clk);
|
|
ScheduledCommand cmd2(*dummy.get(), Command::Read, 3*clk, clk);
|
|
ScheduledCommand cmd3(*dummy.get(), Command::Read, 5*clk, clk);
|
|
ScheduledCommand cmd4(*dummy.get(), Command::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<tlm::tlm_generic_payload> dummy = createDummyPayload();
|
|
ScheduledCommand cmd1(*dummy.get(), Command::Read, 2*clk, clk);
|
|
ScheduledCommand cmd2(*dummy.get(), Command::Read, 3*clk, clk);
|
|
ScheduledCommand cmd3(*dummy.get(), Command::Read, 5*clk, clk);
|
|
ScheduledCommand cmd4(*dummy.get(), Command::Read, 7*clk, clk);
|
|
|
|
ScheduledCommand collision(*dummy.get(), Command::Read, 3*clk, clk);
|
|
ScheduledCommand noCollision(*dummy.get(), Command::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<tlm::tlm_generic_payload> dummy = createDummyPayload();
|
|
ScheduledCommand notAligned(*dummy.get(), Command::Read, 2.5*clk, clk);
|
|
|
|
EXPECT_DEATH(bus.getEarliestStartTime(notAligned), ".*");
|
|
}
|
|
|
|
TEST_F(CommandBusTest, getLastCommandWorks)
|
|
{
|
|
shared_ptr<tlm::tlm_generic_payload> dummy0 = createDummyPayload(common::Thread(0), common::Bank(0));
|
|
shared_ptr<tlm::tlm_generic_payload> dummy2 = createDummyPayload(common::Thread(0), common::Bank(2));
|
|
|
|
ScheduledCommand read0(*dummy0.get(), Command::Read, 2*clk, clk);
|
|
ScheduledCommand read2(*dummy2.get(), Command::Read, 3*clk, clk);
|
|
bus.scheduleCommand(read0);
|
|
bus.scheduleCommand(read2);
|
|
|
|
EXPECT_EQ(read0, bus.getLastCommand(Command::Read, read0.getBank()));
|
|
EXPECT_EQ(read2, bus.getLastCommand(Command::Read, read2.getBank()));
|
|
EXPECT_EQ(read2.getStart(), bus.getLastCommand(Command::Read).getStart());
|
|
}
|
|
|
|
TEST_F(CommandBusTest, notYetScheduledWorks)
|
|
{
|
|
shared_ptr<tlm::tlm_generic_payload> dummy = createDummyPayload(common::Thread(0), common::Bank(0));
|
|
ScheduledCommand read(*dummy.get(), Command::Read, 2*clk, clk);
|
|
|
|
EXPECT_TRUE(bus.notYetScheduled(Command::Read));
|
|
bus.scheduleCommand(read);
|
|
EXPECT_FALSE(bus.notYetScheduled(Command::Read));
|
|
}
|
|
|
|
|
|
} /* namespace controller */
|
|
|
|
|
|
|
|
|