gary/lib/PinSync_Test.bsv

51 lines
1.3 KiB
Plaintext

package PinSync_Test;
import Assert::*;
import StmtFSM::*;
import PinSync::*;
import Testing::*;
module mkTB();
let testflags <- mkTestFlags();
let cycles <- mkCycleCounter();
Reg#(UInt#(2)) dut <- mkPinSync(0);
function Action check_dut_val(UInt#(2) want_val);
return action
if (testflags.verbose)
$display("%0d: PinSync = %0d, want %0d", cycles.all, dut, want_val);
dynamicAssert(dut == want_val, "wrong value");
endaction;
endfunction
function Stmt check_sync(UInt#(2) starting_val, UInt#(2) want_val);
return seq
action
check_dut_val(starting_val);
dut <= want_val;
cycles.reset();
if (testflags.verbose)
$display("%0d: write(%0d)", cycles.all, want_val);
endaction
check_dut_val(starting_val);
action
check_dut_val(want_val);
dynamicAssert(cycles == 2, "synchronizer didn't sync at the right time");
endaction
endseq;
endfunction
runTest(100,
mkTest("PinSync", seq
check_sync(0, 2);
check_sync(2, 3);
check_sync(3, 1);
endseq));
endmodule
endpackage