File: t_tri_select.cpp

package info (click to toggle)
verilator 3.864-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,272 kB
  • ctags: 19,637
  • sloc: cpp: 57,401; perl: 8,764; yacc: 2,559; lex: 1,727; makefile: 658; sh: 175
file content (68 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// -*- mode: C++; c-file-style: "cc-mode" -*-

#include "Vt_tri_select.h"

Vt_tri_select *tb = NULL;

double sc_time_stamp() {
    return 0;
}

bool check() {
    bool pass = true;
#ifdef TEST_VERBOSE
    bool verbose = true;
#else
    bool verbose = false;
#endif

    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 == Y && tb->Y2 == Y && tb->Y3 == Y && tb->W == W) {
	pass = true;
	if (verbose) printf("-  pass: ");
    } else {
	pass = false;
	verbose = true;
	printf("%%E-Fail: ");
    }

    if (verbose) printf("Read: OE1=%d OE2=%d A1=0x%x A2=0x%x Y1=0x%x Y2=0x%x Y3=0x%x W=0x%x  Expected: Y1=Y2=Y3=%d and W=0x%x\n",
			tb->OE1, tb->OE2, tb->A1, tb->A2, tb->Y1, tb->Y2, tb->Y3, tb->W, Y,W);
    return pass;
}

int main() {
    bool pass = true;

    Verilated::debug(0);
    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) {
	VL_PRINTF("*-* All Finished *-*\n");
	tb->final();
    } else {
	vl_fatal(__FILE__,__LINE__,"top", "Unexpected results from t_tri_select\n");
    }
    return 0;
}