File: t_mem_slot.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 (56 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (3)
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
// -*- mode: C++; c-file-style: "cc-mode" -*-

#include <cstdlib>
#include <verilated.h>
#include "Vt_mem_slot.h"

unsigned int Array[3];

unsigned int
StepSim (Vt_mem_slot *sim, unsigned int slot, unsigned int bit, unsigned int val, unsigned int rslot) {
#ifdef TEST_VERBOSE
    printf ("StepSim: slot=%d bit=%d val=%d rslot=%d\n", slot, bit, val, rslot);
#endif

    sim->SlotIdx      = slot;
    sim->BitToChange  = bit;
    sim->BitVal       = val;
    sim->SlotToReturn = rslot;
    sim->Clk          = 0;

    sim->eval();

    sim->Clk          = 1;

    sim->eval();


    if (sim->OutputVal != Array[rslot]) {
	printf ("%%Error: got %x - expected %x\n", sim->OutputVal, Array[rslot]);
	exit (1);
    }

    if (val)
	Array[slot] |= (1 << bit);
    else
	Array[slot] &= ~(1 << bit);

    return sim->OutputVal;
}

int main (int argc, char *argv[]) {
    Vt_mem_slot *sim = new Vt_mem_slot;
    int slot, bit, i;

    Verilated::debug(0);

    /* clear all bits in the array */
    for (slot = 0; slot < 3; slot++)
	for (bit = 0; bit < 2; bit++)
	    StepSim (sim, slot, bit, 0, 0);

    printf ("\nTesting\n");
    for (i = 0; i < 100; i++)
	StepSim (sim, random() % 3, random() % 2, random() % 2, random() % 3);
    printf ("*-* All Finished *-*\n");
}