File: t_tri_gate.cpp

package info (click to toggle)
verilator 3.833-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 10,196 kB
  • sloc: cpp: 49,566; perl: 7,111; yacc: 2,221; lex: 1,702; makefile: 651; sh: 175
file content (66 lines) | stat: -rw-r--r-- 1,370 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
// -*- mode: C++; c-file-style: "cc-mode" -*-
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2008 by Lane Brooks

#ifdef T_COND
# include "Vt_tri_gate_cond.h"
#elif defined(T_BUFIF0)
# include "Vt_tri_gate_bufif0.h"
#elif defined(T_BUFIF1)
# include "Vt_tri_gate_bufif1.h"
#elif defined(T_NOTIF0)
# include "Vt_tri_gate_notif0.h"
#elif defined(T_NOTIF1)
# include "Vt_tri_gate_notif1.h"
#else
# error "Unknown test"
#endif

VM_PREFIX* tb = NULL;

double sc_time_stamp() {
    return 0;
}

bool check() {
    bool pass;
    int c = (tb->A >> tb->SEL) & 0x1;

    if(tb->Z == c && tb->Y == c && tb->X == c && tb->W == c) {
	pass = true;
	printf("PASS: ");
    } else {
	pass = false;
	printf("FAIL: ");
    }
#ifdef TEST_VERBOSE
    printf("SEL=%d A=%d W=%d X=%d Y=%d Z=%d\n", tb->SEL, tb->A, tb->W, tb->X, tb->Y, tb->Z);
#endif
    return pass;
}

int main() {
    bool pass = true;

    Verilated::debug(0);
    tb = new VM_PREFIX ("tb");

    // loop through every possibility and check the result
    for (tb->SEL=0; tb->SEL<2; tb->SEL++) {
	for (tb->A=0; tb->A<4; tb->A++) {
	    tb->eval();
	    if(!check()) {
		pass =false;
	    }
	}
    }

    if(pass) {
	VL_PRINTF("*-* All Finished *-*\n");
	tb->final();
    } else {
	vl_fatal(__FILE__,__LINE__,"top", "Unexpected results from tristate test\n");
    }
    return 0;
}