2023-01-27 17:27:20 -05:00
|
|
|
#pragma once
|
2023-01-27 17:58:29 -05:00
|
|
|
#include <verilated.h>
|
2023-01-30 08:07:34 -05:00
|
|
|
#include "util.hpp"
|
2023-01-27 17:27:20 -05:00
|
|
|
|
|
|
|
/* https://zipcpu.com/blog/2017/06/21/looking-at-verilator.html */
|
|
|
|
template <class TOP> class TB {
|
|
|
|
int tick_count;
|
|
|
|
int bailout;
|
|
|
|
|
2023-01-27 17:58:29 -05:00
|
|
|
public:
|
|
|
|
TOP mod;
|
2023-01-30 08:07:34 -05:00
|
|
|
|
2023-01-30 08:54:17 -05:00
|
|
|
TB(int argc, char *argv[], int _bailout = 0) : mod(), bailout(_bailout) {
|
2023-01-27 17:27:20 -05:00
|
|
|
mod.clk = 0;
|
|
|
|
tick_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TB() {
|
|
|
|
mod.final();
|
|
|
|
}
|
|
|
|
|
2023-01-30 08:07:34 -05:00
|
|
|
void run_clock() {
|
2023-01-27 17:27:20 -05:00
|
|
|
mod.clk = !mod.clk;
|
|
|
|
mod.eval();
|
2023-01-30 08:54:17 -05:00
|
|
|
Verilated::timeInc(1);
|
2023-01-30 08:07:34 -05:00
|
|
|
|
2023-01-27 17:27:20 -05:00
|
|
|
mod.clk = !mod.clk;
|
|
|
|
mod.eval();
|
2023-01-30 08:54:17 -05:00
|
|
|
Verilated::timeInc(1);
|
2023-01-27 17:27:20 -05:00
|
|
|
tick_count++;
|
|
|
|
|
|
|
|
if (bailout > 0 && tick_count >= bailout)
|
|
|
|
exit(1);
|
2023-01-30 08:54:17 -05:00
|
|
|
if (Verilated::gotError())
|
|
|
|
exit(1);
|
2023-01-27 17:27:20 -05:00
|
|
|
}
|
|
|
|
};
|