77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
/*
|
|
* Utils_test.cpp
|
|
*
|
|
* Created on: Mar 14, 2014
|
|
* Author: jonny
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include "core/utils/Utils.h"
|
|
#include "core/utils/RingBuffer.h"
|
|
|
|
//using namespace testing;
|
|
|
|
namespace core {
|
|
|
|
TEST(UtilsTest, clkAlignWorks)
|
|
{
|
|
sc_time clk(6, SC_NS);
|
|
sc_time aligned = 2* clk;
|
|
sc_time not_aligned = 2.5*clk;
|
|
|
|
EXPECT_EQ(aligned, clkAlign(aligned, clk, Alignment::UP));
|
|
EXPECT_EQ(aligned, clkAlign(aligned, clk, Alignment::DOWN));
|
|
EXPECT_EQ(aligned+clk, clkAlign(not_aligned, clk, Alignment::UP));
|
|
EXPECT_EQ(aligned+clk, clkAlign(not_aligned, clk));
|
|
EXPECT_EQ(aligned, clkAlign(not_aligned, clk, Alignment::DOWN));
|
|
}
|
|
|
|
TEST(UtilsTest, isClkAlignedWorks)
|
|
{
|
|
sc_time clk(6, SC_NS);
|
|
sc_time aligned = 2*clk;
|
|
sc_time not_aligned = 2.5 * clk;
|
|
|
|
EXPECT_TRUE(isClkAligned(aligned, clk));
|
|
EXPECT_FALSE(isClkAligned(not_aligned, clk));
|
|
}
|
|
|
|
TEST(UtilsTest, delayByConstraintWorks)
|
|
{
|
|
sc_time start(10, SC_NS);
|
|
sc_time previous(8, SC_NS);
|
|
sc_time constraint(4, SC_NS);
|
|
|
|
EXPECT_EQ(sc_time(2, SC_NS), delayByConstraint(previous, start, constraint));
|
|
EXPECT_EQ(sc_time(4, SC_NS), delayByConstraint(previous, sc_time(8, SC_NS), constraint));
|
|
EXPECT_EQ(sc_time(6, SC_NS), delayByConstraint(previous, sc_time(6, SC_NS), constraint));
|
|
EXPECT_EQ(sc_time(0, SC_NS), delayByConstraint(previous, sc_time(12, SC_NS), constraint));
|
|
EXPECT_EQ(sc_time(0, SC_NS), delayByConstraint(previous, sc_time(14, SC_NS), constraint));
|
|
}
|
|
|
|
TEST(UtilsTest, RingBufferWorks)
|
|
{
|
|
RingBuffer<int> buffer(4);
|
|
EXPECT_TRUE(buffer.isEmpty());
|
|
EXPECT_EQ(0, buffer.getSize());
|
|
EXPECT_DEATH(buffer.get(0), ".*");
|
|
EXPECT_FALSE(buffer.isFull());
|
|
buffer.put(3);
|
|
EXPECT_EQ(1, buffer.getSize());
|
|
EXPECT_FALSE(buffer.isFull());
|
|
buffer.put(5);
|
|
buffer.put(4);
|
|
EXPECT_EQ(4, buffer.getNewest());
|
|
EXPECT_EQ(3, buffer.getOldest());
|
|
EXPECT_FALSE(buffer.isFull());
|
|
buffer.put(9);
|
|
buffer.put(10);
|
|
EXPECT_EQ(10, buffer.getNewest());
|
|
EXPECT_EQ(5, buffer.getOldest());
|
|
EXPECT_EQ(9, buffer.get(2));
|
|
EXPECT_TRUE(buffer.isFull());
|
|
}
|
|
|
|
} /* namespace controller */
|
|
|