Browse Source

test(sim): migrate frame_rx_tb to the unified 16-bit protocol

Vectors regenerated by the independent Python codec (hth_platform/python/
hth_protocol.py): fixed contract GET_ALL vector, SET_ALL 32-byte zero and
mixed frames, a declared-34-byte oversized frame with embedded A5 5A and
its bad-CRC twin, then recovery via the KEEPALIVE contract vector.
Covers: trusted oversized extents, payload write gating past MAX_PAYLOAD,
resync after bad CRC, busy accept gating.  Remote execution pending host
return (LAN outage during run).
codex 3 months ago
parent
commit
c0d26e23f9
1 changed files with 55 additions and 44 deletions
  1. 55 44
      tests/sim/frame_rx_tb.v

+ 55 - 44
tests/sim/frame_rx_tb.v

@@ -8,18 +8,18 @@ module frame_rx_tb;
     reg frame_ready = 1'b0;
     reg frame_ready = 1'b0;
     wire frame_valid;
     wire frame_valid;
     wire [7:0] frame_type;
     wire [7:0] frame_type;
-    wire [7:0] frame_length;
-    reg [7:0] payload_read_addr = 8'd0;
+    wire [15:0] frame_length;
+    reg [15:0] payload_read_addr = 16'd0;
     wire [7:0] payload_read_data;
     wire [7:0] payload_read_data;
     wire payload_wr_en;
     wire payload_wr_en;
-    wire [7:0] payload_wr_addr;
+    wire [15:0] payload_wr_addr;
     wire [7:0] payload_wr_data;
     wire [7:0] payload_wr_data;
     integer i;
     integer i;
 
 
     always #1 clk = ~clk;
     always #1 clk = ~clk;
 
 
-    // Production boundary uses 11-byte SET_ALL max payload.
-    frame_rx #(.MAX_PAYLOAD(11), .INTER_BYTE_TIMEOUT_CYCLES(16)) dut (
+    // 6400 SET_ALL is 32 bytes; the request RAM keeps that production size.
+    frame_rx #(.MAX_PAYLOAD(32), .INTER_BYTE_TIMEOUT_CYCLES(16)) dut (
         .clk(clk), .rst_n(rst_n), .byte_valid(byte_valid), .byte_data(byte_data),
         .clk(clk), .rst_n(rst_n), .byte_valid(byte_valid), .byte_data(byte_data),
         .accept_enable(accept_enable), .frame_valid(frame_valid), .frame_ready(frame_ready),
         .accept_enable(accept_enable), .frame_valid(frame_valid), .frame_ready(frame_ready),
         .frame_type(frame_type), .frame_length(frame_length),
         .frame_type(frame_type), .frame_length(frame_length),
@@ -27,7 +27,7 @@ module frame_rx_tb;
         .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr), .payload_wr_data(payload_wr_data)
         .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr), .payload_wr_data(payload_wr_data)
     );
     );
 
 
-    payload_ram #(.DEPTH(11), .ADDR_WIDTH(8)) payload_store (
+    payload_ram #(.DEPTH(32), .ADDR_WIDTH(8)) payload_store (
         .clk(clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr), .wr_data(payload_wr_data),
         .clk(clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr), .wr_data(payload_wr_data),
         .rd_addr(payload_read_addr), .rd_data(payload_read_data)
         .rd_addr(payload_read_addr), .rd_data(payload_read_data)
     );
     );
@@ -40,7 +40,10 @@ module frame_rx_tb;
             byte_valid = 1'b1;
             byte_valid = 1'b1;
             @(negedge clk);
             @(negedge clk);
             byte_valid = 1'b0;
             byte_valid = 1'b0;
+            // Give the serial CRC time to absorb the byte before the next
+            // one arrives (matches production 921600 byte spacing).
             repeat (10) @(posedge clk);
             repeat (10) @(posedge clk);
+            $display("push %02h t=%0t", value, $time);
         end
         end
     endtask
     endtask
 
 
@@ -52,37 +55,42 @@ module frame_rx_tb;
         end
         end
     endtask
     endtask
 
 
-    task get_frame;
+    task expect_frame;
+        input [7:0] etype;
+        input [15:0] elen;
         begin
         begin
-            push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h6D); push(8'h7B);
             repeat (4) @(posedge clk);
             repeat (4) @(posedge clk);
-            if (!frame_valid) $fatal(1, "valid GET frame missing");
-            if (frame_type !== 8'h02 || frame_length !== 8'd0) $fatal(1, "frame metadata mismatch");
-            ack_frame();
+            $display("expect t=%0t valid=%b type=%h len=%0d state=%0d idx=%0d crc=%h",
+                $time, frame_valid, frame_type, frame_length, dut.state, dut.payload_index, dut.crc_value);
+            if (!frame_valid) $fatal(1, "valid frame missing");
+            if (frame_type !== etype || frame_length !== elen)
+                $fatal(1, "frame metadata mismatch type=%h len=%0d", frame_type, frame_length);
         end
         end
     endtask
     endtask
 
 
     initial begin
     initial begin
         repeat (3) @(posedge clk);
         repeat (3) @(posedge clk);
         rst_n = 1'b1;
         rst_n = 1'b1;
-        get_frame();
 
 
-        // Bad CRC must not publish (atomicity of frame accept).
-        push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h6D); push(8'h7A);
+        // Fixed contract vector: GET_ALL A5 5A 02 00 00 FC A2.
+        push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h00);
+        push(8'hFC); push(8'hA2);
+        expect_frame(8'h02, 16'd0);
+        ack_frame();
+
+        // Bad CRC (contract vector with corrupted CRC low byte) stays silent.
+        push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h00);
+        push(8'hFC); push(8'hA3);
         repeat (4) @(posedge clk);
         repeat (4) @(posedge clk);
         if (frame_valid) $fatal(1, "bad CRC published");
         if (frame_valid) $fatal(1, "bad CRC published");
 
 
-        // Golden SET_ALL all-zero 11-byte vector.
-        // A55A010B00000000000000000000005873
-        push(8'hA5); push(8'h5A); push(8'h01); push(8'h0B);
-        for (i = 0; i < 11; i = i + 1) push(8'h00);
-        push(8'h58); push(8'h73);
-        repeat (4) @(posedge clk);
-        if (!frame_valid) $fatal(1, "golden SET_ALL not published");
-        if (frame_type !== 8'h01 || frame_length !== 8'd11)
-            $fatal(1, "SET_ALL metadata mismatch type=%h len=%0d", frame_type, frame_length);
-        for (i = 0; i < 11; i = i + 1) begin
-            payload_read_addr = i[7:0];
+        // SET_ALL, 32 zero bytes (16-bit length header 20 00, CRC 04 5D).
+        push(8'hA5); push(8'h5A); push(8'h01); push(8'h20); push(8'h00);
+        for (i = 0; i < 32; i = i + 1) push(8'h00);
+        push(8'h04); push(8'h5D);
+        expect_frame(8'h01, 16'd32);
+        for (i = 0; i < 32; i = i + 1) begin
+            payload_read_addr = i[15:0];
             @(posedge clk);
             @(posedge clk);
             @(negedge clk);
             @(negedge clk);
             if (payload_read_data !== 8'h00)
             if (payload_read_data !== 8'h00)
@@ -90,46 +98,49 @@ module frame_rx_tb;
         end
         end
         ack_frame();
         ack_frame();
 
 
-        // Mixed golden: A55A010B0A141E280019326401020087D5
-        push(8'hA5); push(8'h5A); push(8'h01); push(8'h0B);
+        // Mixed values: 0A 14 1E 28 / 00 19 32 64 / 01 02 00 + zeros.
+        push(8'hA5); push(8'h5A); push(8'h01); push(8'h20); push(8'h00);
         push(8'h0A); push(8'h14); push(8'h1E); push(8'h28);
         push(8'h0A); push(8'h14); push(8'h1E); push(8'h28);
         push(8'h00); push(8'h19); push(8'h32); push(8'h64);
         push(8'h00); push(8'h19); push(8'h32); push(8'h64);
         push(8'h01); push(8'h02); push(8'h00);
         push(8'h01); push(8'h02); push(8'h00);
-        push(8'h87); push(8'hD5);
-        repeat (4) @(posedge clk);
-        if (!frame_valid) $fatal(1, "mixed golden SET_ALL not published");
-        if (frame_length !== 8'd11) $fatal(1, "mixed golden length");
+        for (i = 11; i < 32; i = i + 1) push(8'h00);
+        push(8'h40); push(8'h33);
+        expect_frame(8'h01, 16'd32);
         ack_frame();
         ack_frame();
 
 
-        // A complete oversized frame remains one trusted request.  Only the
-        // first MAX_PAYLOAD bytes enter RAM; embedded A5 5A cannot resync it.
-        // CRC covers TYPE=01, LENGTH=34 and the complete generated payload.
-        push(8'hA5); push(8'h5A); push(8'h01); push(8'h22);
+        // A complete oversized frame (declared 34 bytes over a 32-byte RAM)
+        // remains one trusted request: consumed in full, CRC checked, with
+        // embedded A5 5A unable to resync.  CRC 42 3B from the independent
+        // Python codec.
+        push(8'hA5); push(8'h5A); push(8'h01); push(8'h22); push(8'h00);
         for (i = 0; i < 34; i = i + 1) begin
         for (i = 0; i < 34; i = i + 1) begin
             if (i == 3) push(8'hA5);
             if (i == 3) push(8'hA5);
             else if (i == 4) push(8'h5A);
             else if (i == 4) push(8'h5A);
             else push(i[7:0]);
             else push(i[7:0]);
         end
         end
-        push(8'hEC); push(8'h69);
-        repeat (4) @(posedge clk);
-        if (!frame_valid) $fatal(1, "trusted oversized frame metadata missing");
-        if (frame_type !== 8'h01 || frame_length !== 8'd34)
-            $fatal(1, "oversized metadata mismatch type=%h len=%0d", frame_type, frame_length);
+        push(8'h42); push(8'h3B);
+        expect_frame(8'h01, 16'd34);
         ack_frame();
         ack_frame();
 
 
-        // The same complete oversized request with a bad CRC is silent.
-        push(8'hA5); push(8'h5A); push(8'h01); push(8'h22);
+        // The same complete oversized request with a bad CRC is silent and
+        // the next real frame still parses (length extent is trusted).
+        push(8'hA5); push(8'h5A); push(8'h01); push(8'h22); push(8'h00);
         for (i = 0; i < 34; i = i + 1) begin
         for (i = 0; i < 34; i = i + 1) begin
             if (i == 3) push(8'hA5);
             if (i == 3) push(8'hA5);
             else if (i == 4) push(8'h5A);
             else if (i == 4) push(8'h5A);
             else push(i[7:0]);
             else push(i[7:0]);
         end
         end
-        push(8'hED); push(8'h69);
+        push(8'h42); push(8'h3C);
         repeat (4) @(posedge clk);
         repeat (4) @(posedge clk);
         if (frame_valid) $fatal(1, "bad-CRC oversized frame published");
         if (frame_valid) $fatal(1, "bad-CRC oversized frame published");
+        push(8'hA5); push(8'h5A); push(8'h05); push(8'h00); push(8'h00);
+        push(8'h6C); push(8'h27);
+        expect_frame(8'h05, 16'd0);
+        ack_frame();
 
 
         accept_enable = 1'b0;
         accept_enable = 1'b0;
-        push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h6D); push(8'h7B);
+        push(8'hA5); push(8'h5A); push(8'h02); push(8'h00); push(8'h00);
+        push(8'hFC); push(8'hA2);
         repeat (4) @(posedge clk);
         repeat (4) @(posedge clk);
         if (frame_valid) $fatal(1, "busy input was accepted");
         if (frame_valid) $fatal(1, "busy input was accepted");
         $display("frame_rx_tb PASS");
         $display("frame_rx_tb PASS");