some testing

This commit is contained in:
Janik Schlemminger
2014-03-14 02:49:47 -07:00
parent bf1ae66018
commit 7b64552047
5 changed files with 94 additions and 18 deletions

View File

@@ -32,5 +32,9 @@ int runTests(int argc, char **argv)
int main(int argc, char **argv) {
return runTests(argc,argv);
/*sc_time clk(6, SC_NS);
sc_time time(18, SC_NS);
assert(!((time/clk)-ceil(time/clk)));
std::cout<<"good"<<(time/clk)-ceil(time/clk)<<endl;*/
return runTests(argc,argv);
}

View File

@@ -12,14 +12,16 @@ namespace controller {
void CommandBus::scheduleCommand(const ScheduledCommand& command)
{
if(command.getCommand() == Command::Refresh)
if (command.getCommand() == Command::Refresh)
{
scheduleRefresh(command);
lastCommandsOnBus.at(Command::Activate).at(command.getBank()) = command.getStart();
}
assert(pendingBusCommands.count(command.getStart()) == 0);
assert(!pendingBusCommands.count(command.getStart()));
pendingBusCommands.insert(command.getStart());
lastCommandsOnBus[command.getCommand()][command.getBank()] = command.getStart();
}
void CommandBus::scheduleTrigger(const Trigger command, sc_time time)
@@ -35,10 +37,10 @@ sc_time CommandBus::getLastCommand(Command command, common::Bank bank)
sc_time CommandBus::getLastCommand(Command command)
{
sc_time max;
for(unsigned int i = 0; i < config.numberOfBanks; ++i)
for (unsigned int i = 0; i < config.numberOfBanks; ++i)
{
sc_time current = getLastCommand(command, common::Bank(i));
if(current > max)
if (current > max)
max = current;
}
return max;
@@ -52,11 +54,11 @@ bool CommandBus::notYetScheduled(Command command) const
sc_time CommandBus::getEarliestStartTime(const ScheduledCommand& command) const
{
sc_time newStart = command.getStart();
assert(isClkAligned(newStart, config.Timings.clk));
std::set<sc_time>::iterator it = pendingBusCommands.begin();
while(it != pendingBusCommands.end() && *it <= newStart)
while (it != pendingBusCommands.end() && *it <= newStart)
{
if(*it == newStart)
if (*it == newStart)
newStart += config.Timings.clk;
++it;
}
@@ -65,7 +67,8 @@ sc_time CommandBus::getEarliestStartTime(const ScheduledCommand& command) const
void CommandBus::cleanUpBus(sc_time currentTime)
{
pendingBusCommands.erase(pendingBusCommands.begin(), pendingBusCommands.lower_bound(currentTime));
pendingBusCommands.erase(pendingBusCommands.begin(),
pendingBusCommands.lower_bound(currentTime));
}
void CommandBus::scheduleRefresh(const ScheduledCommand& command)

View File

@@ -18,7 +18,7 @@ sc_time delayByConstraint(sc_time previous, sc_time start, sc_time constraint)
{
assert(start > previous);
sc_time distance = start - previous;
if(distance < constraint)
if (distance < constraint)
return constraint - distance;
else
return SC_ZERO_TIME;
@@ -26,8 +26,13 @@ sc_time delayByConstraint(sc_time previous, sc_time start, sc_time constraint)
sc_time clkAlign(sc_time time, sc_time clk, Alignment alignment)
{
if(alignment == Alignment::UP)
return ceil(time/clk)*clk;
if (alignment == Alignment::UP)
return ceil(time / clk) * clk;
else
return floor(time/clk)*clk;
return floor(time / clk) * clk;
}
bool isClkAligned(sc_time time, sc_time clk)
{
return !((time / clk) - ceil(time / clk));
}

View File

@@ -18,5 +18,6 @@ sc_time delayByConstraint(sc_time previous, sc_time start, sc_time constraint);
enum class Alignment {UP, DOWN};
sc_time clkAlign(sc_time time, sc_time clk, Alignment alignment = Alignment::UP);
bool isClkAligned(sc_time time, sc_time clk);
#endif /* UTILS_H_ */

View File

@@ -20,13 +20,21 @@ using namespace std;
namespace controller {
TEST(CommandBusTest, cleanUpBusWorks)
class CommandBusTest: public Test
{
Configuration config;
ControllerState state(config.numberOfBanks);
CommandBus bus(config, state);
public:
CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state), clk(config.Timings.clk){}
sc_time clk = config.Timings.clk;
Configuration config;
ControllerState state;
CommandBus bus;
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);
@@ -46,6 +54,61 @@ TEST(CommandBusTest, cleanUpBusWorks)
}
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(2*clk, bus.getLastCommand(Command::Read, read0.getBank()));
EXPECT_EQ(3*clk, bus.getLastCommand(Command::Read, read2.getBank()));
EXPECT_EQ(3*clk, bus.getLastCommand(Command::Read));
}
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 */