Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/testbench.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ macro(add_testbench)

get_all_sources_recursive(lib${TARGET} ${TARGET}_SOURCES)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Create the test executable
add_executable(${TARGET} ${ARG_BENCH_DIR}/${ARG_MODULE}/${TARGET}.cpp)
if(ARG_DEPENDS)
Expand Down
21 changes: 18 additions & 3 deletions include/testbench.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* along with ECAP5-DTESTLIB. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cstdlib>

#ifndef TESTBENCH_H
#define TESTBENCH_H

Expand Down Expand Up @@ -50,6 +52,7 @@ template<class Module> class Testbench {
int * err_cycles;
int cycle;

uint8_t * clk_ptr;
uint64_t clk_period_in_ps;

Testbench() {
Expand All @@ -63,6 +66,13 @@ template<class Module> class Testbench {
this->conditions = NULL;
this->err_cycles = NULL;
this->cycle = 0;

// Only configure the clk pointer if clk_i exists
if constexpr(requires {this->core->clk_i;}) {
this->clk_ptr = &this->core->clk_i;
} else {
this->clk_ptr = NULL;
}
}

~Testbench() {
Expand Down Expand Up @@ -106,13 +116,18 @@ template<class Module> class Testbench {
}

void tick() {
core->clk_i = 1;
if(this->clk_ptr == NULL) {
printf("ERROR: clk_i not found. If the clk signal is named differently, define clk_ptr\n");
std::exit(-1);
}

*this->clk_ptr = 1;
core->eval();
if(this->trace) {
this->trace->dump(this->clk_period_in_ps * this->tickcount + (this->clk_period_in_ps / 10));
}

core->clk_i = 0;
*this->clk_ptr = 0;
core->eval();
if(this->trace) {
this->trace->dump(this->clk_period_in_ps * this->tickcount + (this->clk_period_in_ps / 2));
Expand All @@ -122,7 +137,7 @@ template<class Module> class Testbench {
this->tickcount += 1;
this->cycle += 1;

core->clk_i = 1;
*this->clk_ptr = 1;
core->eval();
if(this->trace) {
this->trace->dump(this->clk_period_in_ps * this->tickcount);
Expand Down