gary/lib/Testing.bsv

42 lines
928 B
Plaintext
Raw Normal View History

package Testing;
import Assert::*;
import StmtFSM::*;
interface TestCycleLimiter;
method Bit#(32) cycles();
method Bit#(32) count();
method Action reset_count();
endinterface
module mkTestCycleLimiter#(Integer max_cycles)(TestCycleLimiter);
Bit#(32) max = fromInteger(max_cycles);
Reg#(Bit#(32)) cnt <- mkReg(0);
Reg#(Bit#(32)) lastReset <- mkReg(0);
(* no_implicit_conditions, fire_when_enabled *)
rule count_up;
dynamicAssert(cnt < max, "FAIL: test timed out");
cnt <= cnt+1;
endrule
method cycles = cnt._read;
method Bit#(32) count();
return cnt - lastReset;
endmethod
method Action reset_count();
lastReset <= cnt;
endmethod
endmodule
module mkTest#(String name, RStmt#(Bit#(0)) test)();
mkAutoFSM(seq
$display("RUN ", name);
test;
$display("OK ", name);
endseq);
endmodule
endpackage