Skip to content

Commit

Permalink
TestBench: rename 'nextStep' as 'step'
Browse files Browse the repository at this point in the history
  • Loading branch information
JimKnowler committed Dec 29, 2020
1 parent c8df5ae commit 5263b2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
12 changes: 5 additions & 7 deletions gtestverilog/lib/TestBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ namespace gtestverilog {
for (size_t i=0; i<numTicks; i++) {
// rising edge
assert(m_core->i_clk == m_clockPolarity);
nextStep();
step();

// falling edge
assert(m_core->i_clk != m_clockPolarity);
nextStep();
step();
}
}

/// @brief simulate a single half clock step
/// @note This will invert the current value on port 'i_clk'
void nextStep() {
void step() {
m_core->i_clk = (m_core->i_clk) ? 0 : 1;
m_core->eval();

m_stepCount += 1;

onNextStep();
onStep();
}

MODULE& core() {
Expand All @@ -77,9 +77,7 @@ namespace gtestverilog {
}

protected:
virtual void onNextStep() {

}
virtual void onStep() {}

private:
std::unique_ptr<MODULE> m_core;
Expand Down
22 changes: 11 additions & 11 deletions gtestverilog/test/TestBench.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ TEST(TestBench, ShouldTickMultipleTimes) {
testBench.tick(10);
}

TEST(TestBench, ShouldNextStep) {
TEST(TestBench, ShouldStep) {
TestBench<TestCore> testBench;
testBench.nextStep();
testBench.step();
}

TEST(TestBench, ShouldInvokeOnStep) {
class MyTestBench : public TestBench<TestCore> {
public:
int counter = 0;

virtual void onNextStep() {
virtual void onStep() {
counter += 1;
}
};

MyTestBench testBench;

testBench.nextStep();
testBench.step();
ASSERT_EQ(1, testBench.counter);

testBench.nextStep();
testBench.step();
ASSERT_EQ(2, testBench.counter);
}

Expand All @@ -71,10 +71,10 @@ TEST(TestBench, ShouldGetStepCount) {
TestBench<TestCore> testBench;
ASSERT_EQ(0, testBench.stepCount());

testBench.nextStep();
testBench.step();
ASSERT_EQ(1, testBench.stepCount());

testBench.nextStep();
testBench.step();
ASSERT_EQ(2, testBench.stepCount());

testBench.tick(3);
Expand All @@ -88,10 +88,10 @@ TEST(TestBench, ShouldSetClockPolarity0) {
testBench.setClockPolarity(0);
ASSERT_EQ(0, core.i_clk);

testBench.nextStep();
testBench.step();
ASSERT_EQ(1, core.i_clk);

testBench.nextStep();
testBench.step();
ASSERT_EQ(0, core.i_clk);

testBench.tick();
Expand All @@ -105,10 +105,10 @@ TEST(TestBench, ShouldSetClockPolarity1) {
testBench.setClockPolarity(1);
ASSERT_EQ(1, core.i_clk);

testBench.nextStep();
testBench.step();
ASSERT_EQ(0, core.i_clk);

testBench.nextStep();
testBench.step();
ASSERT_EQ(1, core.i_clk);

testBench.tick();
Expand Down
4 changes: 2 additions & 2 deletions gtestverilog/tools/generate_testbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def write_source_file():

source_middle = """
void {name}::onNextStep() {{
void {name}::onStep() {{
using namespace gtestverilog;
Step step;
Expand Down Expand Up @@ -127,7 +127,7 @@ def write_header_file():
class {name} : public ::gtestverilog::TestBench<{verilated_name}> {{
public:
virtual void onNextStep() override;
virtual void onStep() override;
::gtestverilog::Trace trace;
Expand Down

0 comments on commit 5263b2b

Please sign in to comment.