| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- `timescale 1ns/1ps
- // Independent 199-byte baseline, literal offsets from objective section 7.1.
- // Expectations intentionally do not use the generated header or generator.
- module thermal_snapshot_contract_tb;
- reg clk=0;always #20 clk=~clk;
- reg rst_n=0,capture=0,generation=0;
- wire ready,locked,bb,cb,ob;
- reg [7:0] address=0;
- wire [7:0] data;
- wire [4:0] bi,ci,oi;
- reg [15:0] braw,craw;
- reg [7:0] requested,applied;
- // Realistic synchronous source ports with one registered read latency.
- always @(posedge clk) begin
- braw<=(generation ? 16'hE000 : 16'hA000)+{7'd0,bb,8'd0}+bi;
- craw<=(generation ? 16'hF000 : 16'hB000)+{7'd0,cb,8'd0}+3*ci;
- requested<=(generation ? 8'd1 : 8'h10)+oi;
- applied<=(generation ? 8'd2 : 8'h40)+oi;
- end
- thermal_snapshot_mux dut(.clk(clk),.rst_n(rst_n),.capture(capture),.ready(ready),.locked(locked),
- .bmc_active_bank(1'b1),.ct_active_bank(1'b0),.output_active_bank(1'b1),
- .bmc_locked_bank(bb),.ct_locked_bank(cb),.output_locked_bank(ob),
- .control_state(3'd3),.fault_flags(16'h1234),.watchdog_active(1'b1),.watchdog_remaining(8'd29),
- .manual_mode(1'b1),.hard_protect(1'b0),.bmc_stale(1'b0),.ct_stale(1'b1),
- .bmc_epoch(16'h4567),.ct_epoch(16'h89AB),.control_epoch(16'hCDEF),
- .bmc_age(16'h0123),.ct_age(16'h4567),.bmc_valid_mask(24'hA1B2C3),.ct_valid_mask(27'h56789AB),
- .safety_override_mask(24'h55AA33),.lane_fault_mask(4'hB),.global_fault(1'b1),
- .unlock(1'b0),.payload_addr(address),.payload_data(data),.bmc_rd_index(bi),.bmc_rd_raw(braw),
- .ct_rd_index(ci),.ct_rd_raw(craw),.output_rd_addr(oi),.requested_data(requested),.applied_data(applied));
- reg [7:0] expected [0:198];
- integer i,n,cycles;
- reg [15:0] word_value;
- initial begin
- expected[0]=3;expected[1]=8'h34;expected[2]=8'h12;expected[3]=1;expected[4]=29;
- expected[5]=1;expected[6]=0;expected[7]=0;expected[8]=0;expected[9]=1;expected[10]=0;
- expected[11]=8'h67;expected[12]=8'h45;expected[13]=8'hAB;expected[14]=8'h89;
- expected[15]=8'hEF;expected[16]=8'hCD;expected[17]=8'h23;expected[18]=8'h01;
- expected[19]=8'h67;expected[20]=8'h45;
- for(i=0;i<24;i=i+1) begin
- word_value=16'hA100+i;expected[21+2*i]=word_value[7:0];expected[22+2*i]=word_value[15:8];
- expected[130+i]=8'h10+i;expected[154+i]=8'h40+i;
- end
- expected[69]=8'hC3;expected[70]=8'hB2;expected[71]=8'hA1;
- for(i=0;i<27;i=i+1) begin
- word_value=16'hB000+3*i;expected[72+2*i]=word_value[7:0];expected[73+2*i]=word_value[15:8];
- end
- expected[126]=8'hAB;expected[127]=8'h89;expected[128]=8'h67;expected[129]=8'h05;
- for(i=0;i<4;i=i+1) begin
- expected[178+i]=8'h28+i;expected[182+i]=8'h58+i;
- expected[186+i]=8'h2C+i;expected[190+i]=8'h5C+i;
- end
- expected[194]=8'h33;expected[195]=8'hAA;expected[196]=8'h55;expected[197]=8'h0B;expected[198]=1;
- repeat(4) @(negedge clk);rst_n=1;repeat(4) @(negedge clk);
- capture=1;@(negedge clk);capture=0;cycles=0;
- while(!ready && cycles<1000) begin @(negedge clk);cycles=cycles+1;end
- if(!ready) $fatal(1,"snapshot copy deadline");
- if(locked) $fatal(1,"source locks retained until Host finishes reading");
- generation=1; // live sources change while Host stalls and reads in chunks
- repeat(50) @(negedge clk);
- for(n=0;n<199;n=n+1) begin
- address=n;repeat(3) @(negedge clk);
- if(data!==expected[n]) $fatal(1,"snapshot byte %0d got %02x expected %02x",n,data,expected[n]);
- end
- $display("thermal_snapshot_contract_tb PASS");$finish;
- end
- initial begin #1000000;$fatal(1,"snapshot test bounded deadline");end
- endmodule
|