verilator/test_regress/t/t_tri_select.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2009-01-06 16:03:57 +00:00
#include "Vt_tri_select.h"
Vt_tri_select *tb = NULL;
double sc_time_stamp() {
return 0;
}
bool check() {
bool pass = true;
int Y = (tb->OE1 & !tb->OE2) ? tb->A1
: (!tb->OE1 & tb->OE2) ? tb->A2
: (tb->OE1 & tb->OE2) ? (tb->A1 | tb->A2)
: 3; // pullup
int W = (((tb->OE2) ? (tb->A2 & 0x1) : 0) << tb->A1)
| (((tb->OE1) ? (tb->A2 >> 1)&0x1 : 0) << tb->A2);
if(tb->Y1 == tb->Y2 && tb->Y1 == Y && tb->W == W) {
pass = true;
printf("Pass: ");
} else {
pass = false;
printf("Fail: ");
}
printf("Read: OE1=%d OE2=%d A1=0x%x A2=0x%x Y1=0x%x Y2=0x%x W=0x%x Expected: Y1=Y2=%d and W=0x%x\n", tb->OE1, tb->OE2, tb->A1, tb->A2, tb->Y1, tb->Y2, tb->W, Y,W);
return pass;
}
int main() {
bool pass = true;
2009-01-06 16:57:25 +00:00
Verilated::debug(0);
2009-01-06 16:03:57 +00:00
tb = new Vt_tri_select("tb");
// loop through every possibility and check the result
for (tb->OE1=0; tb->OE1<2; tb->OE1++) {
for (tb->OE2=0; tb->OE2<2; tb->OE2++) {
for (tb->A1=0; tb->A1<4; tb->A1++) {
for (tb->A2=0; tb->A2<4; tb->A2++) {
tb->eval();
if(!check()) {
pass = false;
}
}
}
}
}
if(pass) {
cout << "*-* All Finished *-*" << endl;
tb->final();
} else {
vl_fatal(__FILE__,__LINE__,"top", "Unexpected results from t_tri_select\n");
}
return 0;
}