2014-09-12 19:15:04 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2016-06-08 10:39:40 +02:00
|
|
|
#include "verilated.h"
|
|
|
|
#if VM_TRACE
|
|
|
|
#include "verilated_vcd_c.h"
|
|
|
|
#endif
|
2016-06-23 09:17:29 +02:00
|
|
|
#include <fesvr/dtm.h>
|
2016-06-08 10:39:40 +02:00
|
|
|
#include <iostream>
|
2013-01-25 08:56:45 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-03-26 01:01:13 +01:00
|
|
|
#include <unistd.h>
|
2012-10-02 04:30:11 +02:00
|
|
|
|
2016-08-16 07:03:03 +02:00
|
|
|
extern dtm_t* dtm;
|
2016-06-23 21:17:26 +02:00
|
|
|
static uint64_t trace_count = 0;
|
2016-06-18 06:09:08 +02:00
|
|
|
bool verbose;
|
2016-09-09 19:57:10 +02:00
|
|
|
bool done_reset;
|
2016-06-18 06:09:08 +02:00
|
|
|
|
2013-01-25 08:56:45 +01:00
|
|
|
void handle_sigterm(int sig)
|
2012-11-20 14:40:44 +01:00
|
|
|
{
|
2016-06-23 09:17:29 +02:00
|
|
|
dtm->stop();
|
2012-11-20 14:40:44 +01:00
|
|
|
}
|
|
|
|
|
2016-06-23 21:17:26 +02:00
|
|
|
double sc_time_stamp()
|
|
|
|
{
|
|
|
|
return trace_count;
|
|
|
|
}
|
|
|
|
|
2016-08-16 07:03:03 +02:00
|
|
|
extern "C" int vpi_get_vlog_info(void* arg)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-02 04:30:11 +02:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
unsigned random_seed = (unsigned)time(NULL) ^ (unsigned)getpid();
|
2013-10-29 21:24:09 +01:00
|
|
|
uint64_t max_cycles = -1;
|
2015-09-19 03:02:03 +02:00
|
|
|
uint64_t start = 0;
|
2013-10-29 21:24:09 +01:00
|
|
|
int ret = 0;
|
2013-06-13 19:53:23 +02:00
|
|
|
FILE *vcdfile = NULL;
|
2015-12-04 21:04:13 +01:00
|
|
|
bool print_cycles = false;
|
2012-11-20 14:40:44 +01:00
|
|
|
|
2012-10-02 04:30:11 +02:00
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
std::string arg = argv[i];
|
2016-07-09 11:37:39 +02:00
|
|
|
if (arg.substr(0, 2) == "-v") {
|
|
|
|
const char* filename = argv[i]+2;
|
|
|
|
vcdfile = strcmp(filename, "-") == 0 ? stdout : fopen(filename, "w");
|
|
|
|
if (!vcdfile)
|
|
|
|
abort();
|
2016-08-16 07:03:03 +02:00
|
|
|
} else if (arg.substr(0, 2) == "-s")
|
2012-10-02 04:30:11 +02:00
|
|
|
random_seed = atoi(argv[i]+2);
|
2013-01-25 08:56:45 +01:00
|
|
|
else if (arg == "+verbose")
|
2016-06-18 06:09:08 +02:00
|
|
|
verbose = true;
|
2013-01-25 08:56:45 +01:00
|
|
|
else if (arg.substr(0, 12) == "+max-cycles=")
|
|
|
|
max_cycles = atoll(argv[i]+12);
|
2015-09-19 03:02:03 +02:00
|
|
|
else if (arg.substr(0, 7) == "+start=")
|
|
|
|
start = atoll(argv[i]+7);
|
2015-12-04 21:04:13 +01:00
|
|
|
else if (arg.substr(0, 12) == "+cycle-count")
|
|
|
|
print_cycles = true;
|
2013-01-25 08:56:45 +01:00
|
|
|
}
|
2012-10-02 04:30:11 +02:00
|
|
|
|
2016-07-09 11:37:39 +02:00
|
|
|
srand(random_seed);
|
|
|
|
srand48(random_seed);
|
2016-06-08 10:39:40 +02:00
|
|
|
|
2016-07-09 11:37:39 +02:00
|
|
|
Verilated::randReset(2);
|
2016-09-15 20:53:05 +02:00
|
|
|
VTestHarness *tile = new VTestHarness;
|
2016-07-09 11:37:39 +02:00
|
|
|
|
2016-06-08 10:39:40 +02:00
|
|
|
#if VM_TRACE
|
2016-07-09 11:37:39 +02:00
|
|
|
Verilated::traceEverOn(true); // Verilator must compute traced signals
|
|
|
|
std::unique_ptr<VerilatedVcdFILE> vcdfd(new VerilatedVcdFILE(vcdfile));
|
|
|
|
std::unique_ptr<VerilatedVcdC> tfp(new VerilatedVcdC(vcdfd.get()));
|
|
|
|
if (vcdfile) {
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->trace(tfp.get(), 99); // Trace 99 levels of hierarchy
|
2016-07-09 11:37:39 +02:00
|
|
|
tfp->open("");
|
2016-06-08 10:39:40 +02:00
|
|
|
}
|
|
|
|
#endif
|
2013-05-02 13:58:43 +02:00
|
|
|
|
2016-06-23 09:17:29 +02:00
|
|
|
dtm = new dtm_t(std::vector<std::string>(argv + 1, argv + argc));
|
2013-01-25 08:56:45 +01:00
|
|
|
|
|
|
|
signal(SIGTERM, handle_sigterm);
|
|
|
|
|
2016-06-23 09:17:29 +02:00
|
|
|
// reset for several cycles to handle pipelined reset
|
|
|
|
for (int i = 0; i < 10; i++) {
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->reset = 1;
|
2016-09-22 01:16:47 +02:00
|
|
|
tile->clock = 0;
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->eval();
|
2016-09-22 01:16:47 +02:00
|
|
|
tile->clock = 1;
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->eval();
|
|
|
|
tile->reset = 0;
|
2016-06-23 09:17:29 +02:00
|
|
|
}
|
2016-09-09 19:57:10 +02:00
|
|
|
done_reset = true;
|
2016-06-08 10:39:40 +02:00
|
|
|
|
2016-08-16 23:50:40 +02:00
|
|
|
while (!dtm->done() && !tile->io_success && trace_count < max_cycles) {
|
2016-09-22 01:16:47 +02:00
|
|
|
tile->clock = 0;
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->eval();
|
2016-06-08 10:39:40 +02:00
|
|
|
#if VM_TRACE
|
2016-08-16 07:03:03 +02:00
|
|
|
bool dump = tfp && trace_count >= start;
|
|
|
|
if (dump)
|
2016-09-14 20:36:47 +02:00
|
|
|
tfp->dump(static_cast<vluint64_t>(trace_count * 2));
|
2016-06-08 10:39:40 +02:00
|
|
|
#endif
|
2016-06-23 09:17:29 +02:00
|
|
|
|
2016-09-22 01:16:47 +02:00
|
|
|
tile->clock = 1;
|
2016-08-16 23:50:40 +02:00
|
|
|
tile->eval();
|
2016-06-08 10:39:40 +02:00
|
|
|
#if VM_TRACE
|
2016-08-16 07:03:03 +02:00
|
|
|
if (dump)
|
2016-09-14 20:36:47 +02:00
|
|
|
tfp->dump(static_cast<vluint64_t>(trace_count * 2 + 1));
|
2016-06-08 10:39:40 +02:00
|
|
|
#endif
|
2012-10-02 04:30:11 +02:00
|
|
|
trace_count++;
|
|
|
|
}
|
|
|
|
|
2016-06-08 10:39:40 +02:00
|
|
|
#if VM_TRACE
|
2016-07-09 11:37:39 +02:00
|
|
|
if (tfp)
|
|
|
|
tfp->close();
|
2016-06-08 10:39:40 +02:00
|
|
|
#endif
|
2012-10-02 04:30:11 +02:00
|
|
|
|
2016-07-09 11:37:39 +02:00
|
|
|
if (vcdfile)
|
|
|
|
fclose(vcdfile);
|
|
|
|
|
2016-06-23 09:17:29 +02:00
|
|
|
if (dtm->exit_code())
|
2012-10-02 04:30:11 +02:00
|
|
|
{
|
2016-06-23 21:17:26 +02:00
|
|
|
fprintf(stderr, "*** FAILED *** (code = %d, seed %d) after %ld cycles\n", dtm->exit_code(), random_seed, trace_count);
|
2016-06-23 09:17:29 +02:00
|
|
|
ret = dtm->exit_code();
|
2012-10-02 04:30:11 +02:00
|
|
|
}
|
2016-06-23 21:17:26 +02:00
|
|
|
else if (trace_count == max_cycles)
|
2013-10-29 21:24:09 +01:00
|
|
|
{
|
2016-06-23 21:17:26 +02:00
|
|
|
fprintf(stderr, "*** FAILED *** (timeout, seed %d) after %ld cycles\n", random_seed, trace_count);
|
2013-10-29 21:24:09 +01:00
|
|
|
ret = 2;
|
|
|
|
}
|
2016-06-18 06:09:08 +02:00
|
|
|
else if (verbose || print_cycles)
|
2015-09-19 03:02:03 +02:00
|
|
|
{
|
2016-06-23 21:17:26 +02:00
|
|
|
fprintf(stderr, "Completed after %ld cycles\n", trace_count);
|
2015-09-19 03:02:03 +02:00
|
|
|
}
|
2013-10-29 21:24:09 +01:00
|
|
|
|
2016-06-23 09:17:29 +02:00
|
|
|
delete dtm;
|
2016-08-16 23:50:40 +02:00
|
|
|
delete tile;
|
2012-10-02 04:30:11 +02:00
|
|
|
|
2013-10-29 21:24:09 +01:00
|
|
|
return ret;
|
2012-10-02 04:30:11 +02:00
|
|
|
}
|