`timescale 1ns/1ps module completion_phase_tb; reg sys=1,fast=1,clear=1,ready=0; reg [15:0] data=0; always #10 sys=~sys; always #5 fast=~fast; wire phase_ready; wire [15:0] phase_data; actual_completion dut(fast,clear,ready,data,phase_ready,phase_data); integer comparisons=0,i; reg observing=0; // Compare the values the original and repaired CPU-side consuming edge sees, // before the coincident positive-fast producer's NBA updates. always @(negedge sys) if(observing && !clear) begin if(phase_ready!==dut.data_ready) $fatal(1,"completion phase changed CPU-visible readiness"); if(phase_ready && phase_data!==dut.hold_data) $fatal(1,"completion flag/data became incoherent"); comparisons=comparisons+1; end initial begin repeat(4) @(negedge sys);#1;clear=0;observing=1; for(i=0;i<20000;i=i+1) begin @(negedge fast);#1;data=$random;ready=$random; if(i%19==0) clear=1; if(i%19==3) clear=0; end clear=1;#1; if(phase_ready!==0 || dut.data_ready!==0) $fatal(1,"completion clear missing"); $display("PASS %0d original/repaired completion flag/data observations at actual CPU phase; no extra CPU sampling cycle, random producer traffic and clears",comparisons); $finish; end initial begin #1000000;$fatal(1,"completion phase timeout");end endmodule