2024-08-14 05:53:47 +02:00
|
|
|
package Testing;
|
|
|
|
|
|
|
|
import Assert::*;
|
|
|
|
import StmtFSM::*;
|
|
|
|
|
2024-08-14 05:53:47 +02:00
|
|
|
interface TestCycleLimiter;
|
|
|
|
method Bit#(32) cycles();
|
2024-08-14 05:53:47 +02:00
|
|
|
|
2024-08-14 05:53:47 +02:00
|
|
|
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;
|
2024-08-14 05:53:47 +02:00
|
|
|
endrule
|
2024-08-14 05:53:47 +02:00
|
|
|
|
|
|
|
method cycles = cnt._read;
|
|
|
|
method Bit#(32) count();
|
|
|
|
return cnt - lastReset;
|
|
|
|
endmethod
|
|
|
|
method Action reset_count();
|
|
|
|
lastReset <= cnt;
|
|
|
|
endmethod
|
2024-08-14 05:53:47 +02:00
|
|
|
endmodule
|
|
|
|
|
|
|
|
module mkTest#(String name, RStmt#(Bit#(0)) test)();
|
|
|
|
mkAutoFSM(seq
|
|
|
|
$display("RUN ", name);
|
|
|
|
test;
|
|
|
|
$display("OK ", name);
|
|
|
|
endseq);
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
endpackage
|