Bläddra i källkod

test(prod2u): define minimal independent actuator contract

Codex Resource Selftest 4 månader sedan
förälder
incheckning
d673682080

+ 288 - 0
tests/sim/prod2u_p4_axis_jog_limit_resume_tb.v

@@ -0,0 +1,288 @@
+`timescale 1ns/1ps
+
+module prod2u_p4_axis_jog_limit_resume_tb;
+    reg clk;
+    reg rst_n;
+    reg force_stop;
+    reg limit_fast;
+    reg limit_active;
+    reg jog_start;
+    reg jog_dir;
+    reg [15:0] jog_steps;
+
+    wire step_out;
+    wire dir_out;
+    wire busy;
+    wire drive_active;
+    wire position_valid;
+    wire [7:0] current_aperture;
+    wire [7:0] target_aperture;
+    wire [15:0] remaining_steps;
+    wire terminal_pending;
+
+    integer failures;
+    integer guard;
+    integer rises;
+    integer completed;
+    integer paused_rises;
+    integer after_rises;
+    integer confirm_ticks;
+    reg previous_step;
+
+    prod2u_p4_axis_executor #(
+        .HAS_LIMIT(1),
+        .STANDARD_STEPS(3200),
+        .LIMIT_CONFIRM_US(1000),
+        .DIR_SETUP_US(4),
+        .SPEED0_HALF_US(2),
+        .SPEED1_HALF_US(2),
+        .SPEED2_HALF_US(2),
+        .SPEED3_HALF_US(2)
+    ) dut (
+        .clk(clk),
+        .rst_n(rst_n),
+        .tick_1us(1'b1),
+        .force_stop(force_stop),
+        .force_stop_reason(4'd4),
+        .cancel_late_learning(1'b0),
+        .limit_guard(limit_fast),
+        .limit_fast(limit_fast),
+        .limit_active(limit_active),
+        .limit_ready(1'b1),
+        .jog_start(jog_start),
+        .jog_dir(jog_dir),
+        .jog_speed_code(2'd3),
+        .jog_steps(jog_steps),
+        .standard_start(1'b0),
+        .standard_target_open(1'b0),
+        .mark_closed(1'b0),
+        .mark_close_dir(1'b0),
+        .terminal_ready(1'b1),
+        .step_out(step_out),
+        .dir_out(dir_out),
+        .busy(busy),
+        .drive_active(drive_active),
+        .position_valid(position_valid),
+        .current_aperture(current_aperture),
+        .target_aperture(target_aperture),
+        .close_dir(),
+        .close_dir_valid(),
+        .fault(),
+        .move_kind(),
+        .remaining_steps(remaining_steps),
+        .axis_state(),
+        .jog_can_accept(),
+        .standard_can_accept(),
+        .standard_policy_can_accept(),
+        .terminal_pending(terminal_pending),
+        .terminal_valid(),
+        .terminal_meta(),
+        .terminal_data()
+    );
+
+    initial begin
+        clk = 1'b0;
+        forever #5 clk = ~clk;
+    end
+
+    task reset_axis;
+        input limit_level;
+        begin
+            rst_n = 1'b0;
+            force_stop = 1'b0;
+            limit_fast = limit_level;
+            limit_active = limit_level;
+            jog_start = 1'b0;
+            jog_dir = 1'b0;
+            jog_steps = 16'd1;
+            repeat (4) @(negedge clk);
+            rst_n = 1'b1;
+            repeat (2) @(posedge clk);
+        end
+    endtask
+
+    task pulse_jog;
+        input direction;
+        input [15:0] steps;
+        input integer case_id;
+        begin
+            @(negedge clk);
+            jog_dir = direction;
+            jog_steps = steps;
+            jog_start = 1'b1;
+            @(posedge clk);
+            #1;
+            if (!busy || remaining_steps !== steps) begin
+                failures = failures + 1;
+                $display("RED case %0d: JOG load busy=%0d remaining=%0d expected=%0d",
+                    case_id, busy, remaining_steps, steps);
+            end
+            if (busy && dir_out !== direction) begin
+                failures = failures + 1;
+                $display("RED case %0d: JOG DIR=%0d expected=%0d",
+                    case_id, dir_out, direction);
+            end
+            @(negedge clk);
+            jog_start = 1'b0;
+        end
+    endtask
+
+    task count_to_idle;
+        input integer maximum_cycles;
+        output integer rise_count;
+        begin
+            rise_count = 0;
+            guard = 0;
+            previous_step = step_out;
+            while ((busy || terminal_pending) && guard < maximum_cycles) begin
+                @(posedge clk);
+                #1;
+                if (!previous_step && step_out) rise_count = rise_count + 1;
+                previous_step = step_out;
+                guard = guard + 1;
+            end
+            if (busy || terminal_pending || drive_active || step_out ||
+                guard >= maximum_cycles) begin
+                failures = failures + 1;
+                $display("RED: JOG did not settle within %0d cycles", maximum_cycles);
+            end
+        end
+    endtask
+
+    initial begin
+        failures = 0;
+        rst_n = 1'b0;
+        force_stop = 1'b0;
+        limit_fast = 1'b0;
+        limit_active = 1'b0;
+        jog_start = 1'b0;
+        jog_dir = 1'b0;
+        jog_steps = 16'd1;
+
+        // DIR=0 ignores the close limit completely.
+        reset_axis(1'b1);
+        pulse_jog(1'b0, 16'd8, 1);
+        count_to_idle(200, rises);
+        if (rises != 8) begin
+            failures = failures + 1;
+            $display("RED case 1: DIR0 high-limit rises=%0d expected=8", rises);
+        end
+
+        // A DIR=1 limit pulse shorter than 1000 us pauses motion. Once the
+        // pulse disappears, the same command resumes with all remaining steps.
+        reset_axis(1'b0);
+        pulse_jog(1'b1, 16'd8, 2);
+        rises = 0;
+        completed = 0;
+        guard = 0;
+        previous_step = step_out;
+        while (completed < 2 && busy && guard < 100) begin
+            @(posedge clk);
+            #1;
+            if (!previous_step && step_out) rises = rises + 1;
+            if (previous_step && !step_out) completed = completed + 1;
+            previous_step = step_out;
+            guard = guard + 1;
+        end
+        if (completed != 2) begin
+            failures = failures + 1;
+            $display("RED case 2: did not complete two setup steps completed=%0d", completed);
+        end
+
+        @(negedge clk);
+        limit_fast = 1'b1;
+        limit_active = 1'b1;
+        paused_rises = 0;
+        previous_step = step_out;
+        repeat (100) begin
+            @(posedge clk);
+            #1;
+            if (!previous_step && step_out) paused_rises = paused_rises + 1;
+            previous_step = step_out;
+        end
+        if (!busy || drive_active || paused_rises != 0 || step_out) begin
+            failures = failures + 1;
+            $display("RED case 2: short high pause busy=%0d drive=%0d rises=%0d step=%0d",
+                busy, drive_active, paused_rises, step_out);
+        end
+
+        @(negedge clk);
+        limit_fast = 1'b0;
+        limit_active = 1'b0;
+        count_to_idle(300, after_rises);
+        if ((rises + paused_rises + after_rises) != 8) begin
+            failures = failures + 1;
+            $display("RED case 2: resumed total rises=%0d expected=8 remaining=%0d",
+                rises + paused_rises + after_rises, remaining_steps);
+        end
+        if (position_valid || current_aperture !== 8'hff ||
+            target_aperture !== 8'hff) begin
+            failures = failures + 1;
+            $display("RED case 2: JOG retained position valid=%0d current=%0h target=%0h",
+                position_valid, current_aperture, target_aperture);
+        end
+
+        // A continuously asserted close limit is not accepted early. The
+        // axis stays BUSY and STEP-low through the first 999 one-us samples,
+        // then terminates without learning or retaining a position.
+        reset_axis(1'b0);
+        pulse_jog(1'b1, 16'd8, 3);
+        rises = 0;
+        completed = 0;
+        guard = 0;
+        previous_step = step_out;
+        while (completed < 2 && busy && guard < 100) begin
+            @(posedge clk);
+            #1;
+            if (!previous_step && step_out) rises = rises + 1;
+            if (previous_step && !step_out) completed = completed + 1;
+            previous_step = step_out;
+            guard = guard + 1;
+        end
+        @(negedge clk);
+        limit_fast = 1'b1;
+        limit_active = 1'b1;
+        paused_rises = 0;
+        previous_step = step_out;
+        for (confirm_ticks = 0; confirm_ticks < 999; confirm_ticks = confirm_ticks + 1) begin
+            @(posedge clk);
+            #1;
+            if (!previous_step && step_out) paused_rises = paused_rises + 1;
+            previous_step = step_out;
+            if (!busy) begin
+                failures = failures + 1;
+                $display("RED case 3: confirmed before 1000 us at tick=%0d", confirm_ticks + 1);
+                confirm_ticks = 999;
+            end
+        end
+        if (drive_active || paused_rises != 0 || step_out) begin
+            failures = failures + 1;
+            $display("RED case 3: confirmation drive=%0d rises=%0d step=%0d",
+                drive_active, paused_rises, step_out);
+        end
+        guard = 0;
+        while ((busy || terminal_pending) && guard < 12) begin
+            @(posedge clk);
+            #1;
+            guard = guard + 1;
+        end
+        if (busy || terminal_pending || drive_active || step_out) begin
+            failures = failures + 1;
+            $display("RED case 3: stable limit did not terminate after 1000 us");
+        end
+        if (position_valid || current_aperture !== 8'hff ||
+            target_aperture !== 8'hff) begin
+            failures = failures + 1;
+            $display("RED case 3: confirmed limit retained valid=%0d current=%0h target=%0h",
+                position_valid, current_aperture, target_aperture);
+        end
+
+        if (failures != 0) begin
+            $display("AXIS_JOG_LIMIT_RESUME_RED failures=%0d", failures);
+            $fatal(1);
+        end
+
+        $display("PASS: prod2u_p4_axis_jog_limit_resume_tb");
+        $finish;
+    end
+endmodule

+ 220 - 0
tests/sim/prod2u_p4_axis_minimal_standard_tb.v

@@ -0,0 +1,220 @@
+`timescale 1ns/1ps
+
+module prod2u_p4_axis_minimal_standard_tb;
+    localparam integer STANDARD_STEPS = 3200;
+
+    reg clk;
+    reg rst_n;
+    reg force_stop;
+    reg standard_start;
+    reg standard_target_open;
+    reg limit_fast;
+    reg limit_active;
+
+    wire step_out;
+    wire dir_out;
+    wire busy;
+    wire drive_active;
+    wire position_valid;
+    wire [7:0] current_aperture;
+    wire [7:0] target_aperture;
+    wire terminal_pending;
+
+    integer failures;
+    integer guard;
+    integer rises;
+    reg previous_step;
+
+    prod2u_p4_axis_executor #(
+        .HAS_LIMIT(1),
+        .STANDARD_STEPS(STANDARD_STEPS),
+        .LIMIT_CONFIRM_US(1000),
+        .DIR_SETUP_US(4),
+        .SPEED0_HALF_US(1),
+        .SPEED1_HALF_US(1),
+        .SPEED2_HALF_US(1),
+        .SPEED3_HALF_US(1)
+    ) dut (
+        .clk(clk),
+        .rst_n(rst_n),
+        .tick_1us(1'b1),
+        .force_stop(force_stop),
+        .force_stop_reason(4'd0),
+        .cancel_late_learning(1'b0),
+        .limit_guard(limit_fast),
+        .limit_fast(limit_fast),
+        .limit_active(limit_active),
+        .limit_ready(1'b1),
+        .jog_start(1'b0),
+        .jog_dir(1'b0),
+        .jog_speed_code(2'd3),
+        .jog_steps(16'd1),
+        .standard_start(standard_start),
+        .standard_target_open(standard_target_open),
+        .mark_closed(1'b0),
+        .mark_close_dir(1'b0),
+        .terminal_ready(1'b1),
+        .step_out(step_out),
+        .dir_out(dir_out),
+        .busy(busy),
+        .drive_active(drive_active),
+        .position_valid(position_valid),
+        .current_aperture(current_aperture),
+        .target_aperture(target_aperture),
+        .close_dir(),
+        .close_dir_valid(),
+        .fault(),
+        .move_kind(),
+        .remaining_steps(),
+        .axis_state(),
+        .jog_can_accept(),
+        .standard_can_accept(),
+        .standard_policy_can_accept(),
+        .terminal_pending(terminal_pending),
+        .terminal_valid(),
+        .terminal_meta(),
+        .terminal_data()
+    );
+
+    initial begin
+        clk = 1'b0;
+        forever #5 clk = ~clk;
+    end
+
+    task reset_axis_with_limit_high;
+        begin
+            rst_n = 1'b0;
+            force_stop = 1'b0;
+            standard_start = 1'b0;
+            standard_target_open = 1'b0;
+            limit_fast = 1'b1;
+            limit_active = 1'b1;
+            repeat (4) @(negedge clk);
+            rst_n = 1'b1;
+            repeat (2) @(posedge clk);
+        end
+    endtask
+
+    task run_standard;
+        input target_open;
+        input expected_dir;
+        input [7:0] expected_aperture;
+        input integer case_id;
+        begin
+            @(negedge clk);
+            standard_target_open = target_open;
+            standard_start = 1'b1;
+            @(posedge clk);
+            #1;
+            if (!busy) begin
+                failures = failures + 1;
+                $display("RED case %0d: standard command was not accepted", case_id);
+            end
+            if (busy && dir_out !== expected_dir) begin
+                failures = failures + 1;
+                $display("RED case %0d: DIR=%0d expected=%0d", case_id,
+                    dir_out, expected_dir);
+            end
+            @(negedge clk);
+            standard_start = 1'b0;
+
+            rises = 0;
+            guard = 0;
+            previous_step = step_out;
+            while ((busy || terminal_pending) && guard < 12000) begin
+                @(posedge clk);
+                #1;
+                if (!previous_step && step_out) rises = rises + 1;
+                previous_step = step_out;
+                guard = guard + 1;
+            end
+            if (busy || terminal_pending || drive_active || step_out ||
+                guard >= 12000) begin
+                failures = failures + 1;
+                $display("RED case %0d: standard command did not settle", case_id);
+            end
+            if (rises != STANDARD_STEPS) begin
+                failures = failures + 1;
+                $display("RED case %0d: standard rises=%0d expected=%0d",
+                    case_id, rises, STANDARD_STEPS);
+            end
+            if (!position_valid || current_aperture !== expected_aperture ||
+                target_aperture !== expected_aperture) begin
+                failures = failures + 1;
+                $display("RED case %0d: completion status valid=%0d current=%0h target=%0h",
+                    case_id, position_valid, current_aperture, target_aperture);
+            end
+        end
+    endtask
+
+    initial begin
+        failures = 0;
+        rst_n = 1'b0;
+        force_stop = 1'b0;
+        standard_start = 1'b0;
+        standard_target_open = 1'b0;
+        limit_fast = 1'b0;
+        limit_active = 1'b0;
+
+        // Standard motion is a fixed mechanical command. A high close-limit
+        // input must not shorten or reject either direction.
+        reset_axis_with_limit_high();
+        run_standard(1'b1, 1'b0, 8'd100, 1);
+
+        // Repeating the same target is another complete 3200-step command.
+        run_standard(1'b1, 1'b0, 8'd100, 2);
+
+        reset_axis_with_limit_high();
+        run_standard(1'b0, 1'b1, 8'd0, 3);
+
+        // A hard stop is the exceptional path that may truncate STEP. It must
+        // immediately gate the pins and invalidate a previously completed
+        // command position on the next active clock edge.
+        reset_axis_with_limit_high();
+        run_standard(1'b1, 1'b0, 8'd100, 4);
+        if (!position_valid) begin
+            failures = failures + 1;
+            $display("RED case 5: hard-stop setup has no valid position");
+        end
+        @(negedge clk);
+        standard_target_open = 1'b0;
+        standard_start = 1'b1;
+        @(negedge clk);
+        standard_start = 1'b0;
+        guard = 0;
+        while (!step_out && busy && guard < 5000) begin
+            @(posedge clk);
+            #1;
+            guard = guard + 1;
+        end
+        if (!step_out) begin
+            failures = failures + 1;
+            $display("RED case 5: hard-stop setup emitted no STEP");
+        end else begin
+            #1 force_stop = 1'b1;
+            #1;
+            if (step_out || drive_active) begin
+                failures = failures + 1;
+                $display("RED case 5: hard stop did not gate STEP/drive immediately");
+            end
+            @(posedge clk);
+            #1;
+            if (busy || drive_active || step_out || position_valid ||
+                current_aperture !== 8'hff ||
+                target_aperture !== 8'hff) begin
+                failures = failures + 1;
+                $display("RED case 5: hard stop retained busy=%0d drive=%0d valid=%0d current=%0h target=%0h",
+                    busy, drive_active, position_valid, current_aperture,
+                    target_aperture);
+            end
+        end
+
+        if (failures != 0) begin
+            $display("AXIS_MINIMAL_STANDARD_RED failures=%0d", failures);
+            $fatal(1);
+        end
+
+        $display("PASS: prod2u_p4_axis_minimal_standard_tb");
+        $finish;
+    end
+endmodule

+ 357 - 0
tests/sim/prod2u_p4_minimal_snapshot_contract_tb.v

@@ -0,0 +1,357 @@
+`timescale 1ns/1ps
+
+module prod2u_p4_minimal_snapshot_contract_tb;
+    localparam [7:0] FT_HOST_BATCH_CMD = 8'h07;
+    localparam [7:0] FT_MOTION_CMD = 8'h11;
+    localparam [7:0] CMD_SET_SNAPSHOT = 8'h2a;
+    localparam [7:0] MOTION_JOG = 8'h35;
+    localparam [7:0] STATUS_OK = 8'h00;
+    localparam [7:0] STATUS_PARTIAL = 8'h16;
+    localparam integer STANDARD_STEPS = 8;
+
+    reg clk = 1'b0;
+    reg rst_n = 1'b0;
+    reg request_valid = 1'b0;
+    wire request_ready;
+    reg [7:0] request_type = 8'd0;
+    reg [5:0] request_length = 6'd0;
+    reg [271:0] request_payload = 272'd0;
+    reg [15:0] request_crc16 = 16'd0;
+    wire frame_valid;
+    wire [7:0] frame_type;
+    wire [7:0] frame_payload_len;
+    wire [143:0] frame_payload;
+    wire [191:0] ptc_percent;
+    wire [31:0] fan_percent;
+    wire [7:0] solenoid_percent;
+    wire [2:0] step_out;
+    wire [2:0] dir_out;
+
+    integer errors = 0;
+    integer guard;
+    integer x_step_edges = 0;
+    integer y_step_edges = 0;
+    integer x_before;
+    integer y_before;
+    integer x_after;
+    integer y_after;
+    reg simultaneous_step_seen = 1'b0;
+
+    always #5 clk = ~clk;
+    always @(posedge step_out[0]) x_step_edges = x_step_edges + 1;
+    always @(posedge step_out[1]) y_step_edges = y_step_edges + 1;
+    always @(posedge clk) begin
+        #1;
+        if (rst_n && step_out[0] && step_out[1]) simultaneous_step_seen = 1'b1;
+    end
+
+    prod2u_p4_normal_v3_core #(
+        .CLK_HZ(1000),
+        .WATCHDOG_SECONDS(5),
+        .STANDARD_STEPS(STANDARD_STEPS),
+        .LIMIT_CONFIRM_US(8),
+        .DIR_SETUP_US(2),
+        .SPEED0_HALF_US(2),
+        .SPEED1_HALF_US(2),
+        .SPEED2_HALF_US(2),
+        .SPEED3_HALF_US(2)
+    ) dut (
+        .clk(clk),
+        .rst_n(rst_n),
+        .tick_1us(1'b1),
+        .request_valid(request_valid),
+        .request_ready(request_ready),
+        .request_type(request_type),
+        .request_length(request_length),
+        .request_payload(request_payload),
+        .request_crc16(request_crc16),
+        .emergency_disable_valid(1'b0),
+        .emergency_disable_crc16(16'd0),
+        .frame_valid(frame_valid),
+        .frame_ready(1'b1),
+        .frame_type(frame_type),
+        .frame_payload_len(frame_payload_len),
+        .frame_payload(frame_payload),
+        .x_limit_fast(1'b0),
+        .y_limit_fast(1'b0),
+        .x_limit_guard(1'b0),
+        .y_limit_guard(1'b0),
+        .x_limit_active(1'b0),
+        .y_limit_active(1'b0),
+        .x_limit_ready(1'b1),
+        .y_limit_ready(1'b1),
+        .ptc_percent(ptc_percent),
+        .fan_percent(fan_percent),
+        .solenoid_percent(solenoid_percent),
+        .state_hash16(),
+        .step_out(step_out),
+        .dir_out(dir_out),
+        .en_n(),
+        .disabled(),
+        .watchdog_timeout()
+    );
+
+    task fail;
+        input [8*120-1:0] message;
+        begin
+            errors = errors + 1;
+            $display("MINIMAL_SNAPSHOT_FAIL: %0s", message);
+        end
+    endtask
+
+    task reset_core;
+        begin
+            rst_n = 1'b0;
+            request_valid = 1'b0;
+            request_type = 8'd0;
+            request_length = 6'd0;
+            request_payload = 272'd0;
+            request_crc16 = 16'd0;
+            simultaneous_step_seen = 1'b0;
+            repeat (4) @(negedge clk);
+            rst_n = 1'b1;
+            repeat (4) @(negedge clk);
+        end
+    endtask
+
+    task wait_ready;
+        input [8*64-1:0] label_text;
+        begin
+            guard = 0;
+            while (!request_ready && guard < 512) begin
+                @(negedge clk);
+                guard = guard + 1;
+            end
+            if (!request_ready) fail(label_text);
+        end
+    endtask
+
+    task wait_ack;
+        input [7:0] expected_command;
+        input [7:0] expected_status;
+        input [7:0] expected_detail;
+        input [7:0] expected_flags;
+        input [8*64-1:0] label_text;
+        reg [63:0] observed_ack;
+        begin
+            guard = 0;
+            while (!dut.command_response_valid && guard < 512) begin
+                @(negedge clk);
+                guard = guard + 1;
+            end
+            if (!dut.command_response_valid) begin
+                fail(label_text);
+            end else begin
+                observed_ack = dut.command_ack_payload;
+                if (observed_ack[7:0] !== 8'h01 ||
+                    observed_ack[15:8] !== expected_command ||
+                    observed_ack[23:16] !== expected_status ||
+                    observed_ack[31:24] !== expected_detail ||
+                    observed_ack[63:56] !== expected_flags) begin
+                    $display("ACK_MISMATCH label=%0s ack=%016h expected_cmd=%02h status=%02h detail=%02h flags=%02h",
+                        label_text, observed_ack, expected_command,
+                        expected_status, expected_detail, expected_flags);
+                    fail(label_text);
+                end
+            end
+            wait_ready("response did not retire");
+        end
+    endtask
+
+    task send_jog;
+        input [1:0] axis;
+        input direction;
+        input [15:0] steps;
+        input [15:0] crc;
+        input [8*64-1:0] label_text;
+        begin
+            wait_ready(label_text);
+            @(negedge clk);
+            request_type = FT_MOTION_CMD;
+            request_length = 6'd8;
+            request_payload = 272'd0;
+            request_payload[7:0] = MOTION_JOG;
+            request_payload[15:8] = {6'd0, axis};
+            request_payload[23:16] = {7'd0, direction};
+            request_payload[31:24] = 8'd3;
+            request_payload[47:32] = steps;
+            request_crc16 = crc;
+            request_valid = 1'b1;
+            @(posedge clk);
+            #1;
+            @(negedge clk);
+            request_valid = 1'b0;
+            wait_ack(MOTION_JOG, STATUS_OK, 8'd0, 8'd0, label_text);
+        end
+    endtask
+
+    task fill_snapshot;
+        input [7:0] ptc0;
+        input [7:0] ptc23;
+        input [7:0] fan0;
+        input [7:0] fan1;
+        input [7:0] fan2;
+        input [7:0] fan3;
+        input [7:0] solenoid;
+        input [7:0] x_target;
+        input [7:0] y_target;
+        input [7:0] z_target;
+        integer index;
+        begin
+            request_payload = 272'd0;
+            request_payload[7:0] = CMD_SET_SNAPSHOT;
+            request_payload[15:8] = 8'd0;
+            for (index = 0; index < 24; index = index + 1) begin
+                request_payload[(index + 2) * 8 +: 8] = 8'd0;
+            end
+            request_payload[2 * 8 +: 8] = ptc0;
+            request_payload[25 * 8 +: 8] = ptc23;
+            request_payload[26 * 8 +: 8] = fan0;
+            request_payload[27 * 8 +: 8] = fan1;
+            request_payload[28 * 8 +: 8] = fan2;
+            request_payload[29 * 8 +: 8] = fan3;
+            request_payload[30 * 8 +: 8] = solenoid;
+            request_payload[31 * 8 +: 8] = x_target;
+            request_payload[32 * 8 +: 8] = y_target;
+            request_payload[33 * 8 +: 8] = z_target;
+        end
+    endtask
+
+    task send_snapshot;
+        input [7:0] ptc0;
+        input [7:0] ptc23;
+        input [7:0] fan0;
+        input [7:0] fan1;
+        input [7:0] fan2;
+        input [7:0] fan3;
+        input [7:0] solenoid;
+        input [7:0] x_target;
+        input [7:0] y_target;
+        input [7:0] z_target;
+        input [7:0] expected_status;
+        input [7:0] expected_detail;
+        input [7:0] expected_flags;
+        input [15:0] crc;
+        input [8*64-1:0] label_text;
+        begin
+            wait_ready(label_text);
+            @(negedge clk);
+            request_type = FT_HOST_BATCH_CMD;
+            request_length = 6'd34;
+            fill_snapshot(ptc0, ptc23, fan0, fan1, fan2, fan3,
+                solenoid, x_target, y_target, z_target);
+            request_crc16 = crc;
+            request_valid = 1'b1;
+            @(posedge clk);
+            #1;
+            @(negedge clk);
+            request_valid = 1'b0;
+            wait_ack(CMD_SET_SNAPSHOT, expected_status, expected_detail,
+                expected_flags, label_text);
+        end
+    endtask
+
+    task wait_edge_count;
+        input integer expected_x;
+        input integer expected_y;
+        input [8*64-1:0] label_text;
+        begin
+            guard = 0;
+            while (((x_step_edges < expected_x) || (y_step_edges < expected_y)) &&
+                   guard < 2048) begin
+                @(negedge clk);
+                guard = guard + 1;
+            end
+            if ((x_step_edges < expected_x) || (y_step_edges < expected_y)) begin
+                $display("STEP_TIMEOUT label=%0s x=%0d/%0d y=%0d/%0d",
+                    label_text, x_step_edges, expected_x,
+                    y_step_edges, expected_y);
+                fail(label_text);
+            end
+        end
+    endtask
+
+    initial begin
+        // One command may start both independent standard-motion executors.
+        reset_core();
+        x_before = x_step_edges;
+        y_before = y_step_edges;
+        send_snapshot(8'd0, 8'd0, 8'd30, 8'd30, 8'd30, 8'd30,
+            8'd0, 8'd100, 8'd100, 8'd0,
+            STATUS_OK, 8'h00, 8'h0f, 16'h1101,
+            "same snapshot did not accept both axes");
+        wait_edge_count(x_before + STANDARD_STEPS,
+            y_before + STANDARD_STEPS,
+            "same snapshot did not execute both axes");
+        repeat (24) @(negedge clk);
+        if ((x_step_edges - x_before) != STANDARD_STEPS ||
+            (y_step_edges - y_before) != STANDARD_STEPS ||
+            !simultaneous_step_seen || dir_out[1:0] !== 2'b00) begin
+            $display("DUAL_STANDARD x=%0d y=%0d overlap=%0d dir=%02b",
+                x_step_edges - x_before, y_step_edges - y_before,
+                simultaneous_step_seen, dir_out[1:0]);
+            fail("same snapshot did not run two independent 3200-step equivalents");
+        end
+
+        // A busy X must not create a global movement lock for an idle Y JOG.
+        reset_core();
+        x_before = x_step_edges;
+        y_before = y_step_edges;
+        send_jog(2'd0, 1'b0, 16'd64, 16'h1201,
+            "X long JOG was rejected");
+        wait_edge_count(x_before + 2, y_before,
+            "X long JOG did not begin");
+        send_jog(2'd1, 1'b0, 16'd5, 16'h1202,
+            "busy X incorrectly blocked idle Y JOG");
+        wait_edge_count(x_before + 2, y_before + 5,
+            "Y JOG did not run beside busy X");
+        repeat (24) @(negedge clk);
+        if ((y_step_edges - y_before) != 5) begin
+            fail("Y JOG step count changed because X was busy");
+        end
+
+        // Busy X is ignored, idle Y starts, invalid Z is isolated, PTC/FAN
+        // still commit, and a solenoid change is held while either axis moves.
+        reset_core();
+        x_before = x_step_edges;
+        y_before = y_step_edges;
+        send_jog(2'd0, 1'b0, 16'd64, 16'h1301,
+            "X setup JOG was rejected");
+        wait_edge_count(x_before + 2, y_before,
+            "X setup JOG did not begin");
+        send_snapshot(8'd17, 8'd99, 8'd11, 8'd22, 8'd33, 8'd44,
+            8'd100, 8'd100, 8'd100, 8'd50,
+            STATUS_PARTIAL, 8'h61, 8'h05, 16'h1302,
+            "snapshot did not return approved PARTIAL masks");
+
+        if (ptc_percent[7:0] !== 8'd17 ||
+            ptc_percent[23 * 8 +: 8] !== 8'd99 ||
+            fan_percent[7:0] !== 8'd11 ||
+            fan_percent[15:8] !== 8'd22 ||
+            fan_percent[23:16] !== 8'd33 ||
+            fan_percent[31:24] !== 8'd44) begin
+            fail("PTC/FAN did not commit when one motor target was busy");
+        end
+        if (solenoid_percent !== 8'd0) begin
+            fail("solenoid changed while an axis was busy");
+        end
+
+        wait_edge_count(x_before + 64, y_before + STANDARD_STEPS,
+            "busy-X/idle-Y snapshot motion did not retire");
+        x_after = x_step_edges;
+        y_after = y_step_edges;
+        repeat (40) @(negedge clk);
+        if ((x_after - x_before) != 64 || x_step_edges != x_after) begin
+            fail("ignored busy-X target was deferred or restarted");
+        end
+        if ((y_after - y_before) != STANDARD_STEPS || y_step_edges != y_after) begin
+            fail("idle Y did not execute exactly one standard motion");
+        end
+
+        if (errors != 0) begin
+            $fatal(1, "prod2u_p4_minimal_snapshot_contract_tb RED failures=%0d", errors);
+        end
+        $display("PASS: prod2u_p4_minimal_snapshot_contract_tb");
+        $finish;
+    end
+endmodule

+ 97 - 115
tests/unit/test_prod2u_p4_ack_only_host_contract.py

@@ -1,30 +1,50 @@
 #!/usr/bin/env python3
 #!/usr/bin/env python3
-"""RED contract tests for the temporary ACK-only Normal-v3 host path."""
+"""RED contract tests for the minimal ACK-only Normal-v3 wire path."""
 
 
 from __future__ import annotations
 from __future__ import annotations
 
 
 import importlib.util
 import importlib.util
-import json
 import sys
 import sys
 import unittest
 import unittest
 from pathlib import Path
 from pathlib import Path
-from unittest import mock
 
 
 
 
 ROOT = Path(__file__).resolve().parents[2]
 ROOT = Path(__file__).resolve().parents[2]
 TOOLS = ROOT / "tools"
 TOOLS = ROOT / "tools"
 sys.path.insert(0, str(TOOLS))
 sys.path.insert(0, str(TOOLS))
 
 
+import prod2u_p4_normal_v3_model as model_v3  # noqa: E402
 import prod2u_p4_protocol as protocol  # noqa: E402
 import prod2u_p4_protocol as protocol  # noqa: E402
 
 
 
 
-ACK_ONLY_CAPABILITY = 0x00001F8F
+GOLDEN_REQUEST_HEX = {
+    "enable": (
+        "a55a0204070000000000000000222a00"
+        "000000000000000000000000000000000000000000000000"
+        "1e1e1e1e00000000d6df"
+    ),
+    "jog_x": "a55a020411000000000000000008350001000100000086c3",
+    "jog_y": "a55a0204110000000000000000083501000001000000473e",
+    "mark_x": "a55a0204110000000000000000083600010000000000477d",
+    "mark_y": "a55a02041100000000000000000836010000000000008680",
+    "open": (
+        "a55a0204070000000000000000222a00"
+        "0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a"
+        "46464646646464642c75"
+    ),
+    "close": (
+        "a55a0204070000000000000000222a00"
+        "0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a"
+        "4646464600000000684a"
+    ),
+    "disable": "a55a02040500000000000000000426000000c4ae",
+}
 
 
 
 
 def load_cli():
 def load_cli():
     path = TOOLS / "prod2u_p4_cli.py"
     path = TOOLS / "prod2u_p4_cli.py"
     spec = importlib.util.spec_from_file_location(
     spec = importlib.util.spec_from_file_location(
-        "test_prod2u_p4_ack_only_host_contract_owned",
+        "test_prod2u_p4_minimal_ack_only_cli",
         path,
         path,
     )
     )
     if spec is None or spec.loader is None:
     if spec is None or spec.loader is None:
@@ -36,7 +56,7 @@ def load_cli():
 
 
 
 
 class ScriptedEndpoint:
 class ScriptedEndpoint:
-    """Expose one response only after the first command write."""
+    """Expose scripted response bytes only after the request is written."""
 
 
     def __init__(self, response: bytes) -> None:
     def __init__(self, response: bytes) -> None:
         self._response = bytearray(response)
         self._response = bytearray(response)
@@ -55,99 +75,23 @@ class ScriptedEndpoint:
         return result
         return result
 
 
 
 
-def build_legacy_command_result(request: bytes, ack: bytes) -> bytes:
-    """Build a CRC-valid legacy 0x0F frame that ACK-only hosts must reject."""
-
-    ack_payload = ack[protocol.HEADER_LEN : -protocol.CRC_LEN]
-    payload = (1).to_bytes(4, "little")
-    payload += bytes((0x02, request[4]))
-    payload += int.from_bytes(request[-2:], "little").to_bytes(2, "little")
-    payload += int.from_bytes(ack_payload, "little").to_bytes(8, "little")
-    payload += int.from_bytes(ack_payload[4:6], "little").to_bytes(2, "little")
+def legacy_temperature_request() -> bytes:
     return protocol.encode_frame(
     return protocol.encode_frame(
-        frame_type=0x0F,
+        frame_type=protocol.FrameType.HOST_CMD,
         seq=0,
         seq=0,
         timestamp_tick=0,
         timestamp_tick=0,
-        payload=payload,
+        payload=b"\x29\x00\x00\x00",
     )
     )
 
 
 
 
-class Prod2UP4AckOnlyHostContractTests(unittest.TestCase):
-    def test_capability_clears_trace_bit_and_boot_wire_uses_1f8f(self) -> None:
-        self.assertEqual(protocol.CAPABILITY_FLAGS, ACK_ONLY_CAPABILITY)
-        self.assertEqual(protocol.CAPABILITY_FLAGS & (1 << 4), 0)
-
-        boot = protocol.build_boot_build_id(build_id=0x6A5DB6D3)
-        self.assertEqual(boot[18:22], bytes.fromhex("8F 1F 00 00"))
-
-    def test_host_contract_requires_boot_without_epoch(self) -> None:
-        contract = json.loads(
-            (ROOT / "config" / "prod2u_p4_normal_host_contract_v4.json").read_text(
-                encoding="utf-8"
-            )
-        )
-        self.assertEqual(contract["boot_build_id"]["capability"], ACK_ONLY_CAPABILITY)
-        self.assertEqual(contract["boot_build_id"]["capability_wire_le"], "8F 1F 00 00")
-        self.assertFalse(contract["capability_registry"]["TRACE_EVENT_V1"]["enabled"])
-
-        startup = contract["boot_build_id"].get("startup_order")
-        if startup is None:
-            startup = contract["boot_build_id"].get("startup_epoch_order")
-        self.assertIsNotNone(startup, "host contract must define startup ordering")
-        self.assertEqual(startup["required_prefix"], ["BOOT_BUILD_ID"])
-        self.assertEqual(startup.get("epoch_count", 0), 0)
-
-    def test_session_never_constructs_trace_host_policy(self) -> None:
-        cli = load_cli()
-        endpoint = ScriptedEndpoint(b"")
-
-        with mock.patch.object(
-            cli,
-            "TraceHostPolicy",
-            create=True,
-            side_effect=AssertionError("ACK-only CLI must not instantiate TraceHostPolicy"),
-        ) as constructor:
-            session = cli.NormalSession(endpoint)
-
-        constructor.assert_not_called()
-        self.assertFalse(hasattr(session, "_trace_policy"))
-
-    def test_startup_accepts_boot_then_host_ack_without_epoch(self) -> None:
-        cli = load_cli()
-        request = protocol.build_host_command(command=protocol.CommandId.GET_STATUS)
-        boot = protocol.build_boot_build_id(
-            build_id=0x6A5DB6D3,
-            capability_flags=ACK_ONLY_CAPABILITY,
-        )
-        ack = protocol.build_host_ack(
-            ok=True,
-            command=protocol.CommandId.GET_STATUS,
-            status=protocol.StatusCode.OK,
-            state_hash16=0x1234,
-        )
-        endpoint = ScriptedEndpoint(boot + ack)
-        session = cli.NormalSession(
-            endpoint,
-            timeout_seconds=0.05,
-            expected_build_id=0x6A5DB6D3,
-            expected_capability_flags=ACK_ONLY_CAPABILITY,
-        )
-
-        result = session.command(
-            request,
-            expected_command=protocol.CommandId.GET_STATUS,
-            allow_boot_preamble=True,
-        )
-
+class Prod2UP4MinimalAckOnlyContractTests(unittest.TestCase):
+    def test_existing_input_request_hex_vectors_remain_byte_exact(self) -> None:
         self.assertEqual(
         self.assertEqual(
-            [frame.frame_type for frame in result.frames],
-            [protocol.FrameType.BOOT_BUILD_ID, protocol.FrameType.HOST_ACK],
+            {name: value.hex() for name, value in model_v3.GOLDEN_VECTORS.items()},
+            GOLDEN_REQUEST_HEX,
         )
         )
-        self.assertEqual(session.startup_boot_identity.build_id, 0x6A5DB6D3)
-        self.assertIsNone(getattr(session, "startup_epoch", None))
-        self.assertEqual(endpoint.writes, [request])
 
 
-    def test_transaction_accepts_host_ack_without_command_result_trace(self) -> None:
+    def test_ordinary_command_accepts_ack_as_first_and_only_response(self) -> None:
         cli = load_cli()
         cli = load_cli()
         request = protocol.build_host_command(command=protocol.CommandId.GET_STATUS)
         request = protocol.build_host_command(command=protocol.CommandId.GET_STATUS)
         ack = protocol.build_host_ack(
         ack = protocol.build_host_ack(
@@ -162,11 +106,16 @@ class Prod2UP4AckOnlyHostContractTests(unittest.TestCase):
         result = session.command(request, expected_command=protocol.CommandId.GET_STATUS)
         result = session.command(request, expected_command=protocol.CommandId.GET_STATUS)
 
 
         self.assertEqual(result.raw_response, ack)
         self.assertEqual(result.raw_response, ack)
-        self.assertEqual([frame.frame_type for frame in result.frames], [protocol.FrameType.HOST_ACK])
+        self.assertEqual(
+            [frame.frame_type for frame in result.frames],
+            [protocol.FrameType.HOST_ACK],
+        )
         self.assertEqual(result.ack.state_hash16, 0xBEEF)
         self.assertEqual(result.ack.state_hash16, 0xBEEF)
         self.assertEqual(endpoint.writes, [request])
         self.assertEqual(endpoint.writes, [request])
+        self.assertFalse(hasattr(session, "_trace_policy"))
+        self.assertFalse(hasattr(result, "command_result_trace"))
 
 
-    def test_motor_status_accepts_host_ack_then_optional_followup(self) -> None:
+    def test_motor_status_response_is_ack_then_one_ten_byte_status(self) -> None:
         cli = load_cli()
         cli = load_cli()
         request = protocol.build_get_motor_status()
         request = protocol.build_get_motor_status()
         ack = protocol.build_host_ack(
         ack = protocol.build_host_ack(
@@ -176,7 +125,7 @@ class Prod2UP4AckOnlyHostContractTests(unittest.TestCase):
             response_type=protocol.FrameType.MOTION_STATUS,
             response_type=protocol.FrameType.MOTION_STATUS,
             result_flags=0x08,
             result_flags=0x08,
         )
         )
-        status = protocol.build_motion_status(
+        status_wire = protocol.build_motion_status(
             flags=0,
             flags=0,
             position_valid_mask=0,
             position_valid_mask=0,
             busy_mask=0,
             busy_mask=0,
@@ -184,42 +133,75 @@ class Prod2UP4AckOnlyHostContractTests(unittest.TestCase):
             target_xyz=(0xFF, 0xFF, 0xFF),
             target_xyz=(0xFF, 0xFF, 0xFF),
             fault_mask=0,
             fault_mask=0,
         )
         )
-        endpoint = ScriptedEndpoint(ack + status)
+        endpoint = ScriptedEndpoint(ack + status_wire)
         session = cli.NormalSession(endpoint, timeout_seconds=0.05)
         session = cli.NormalSession(endpoint, timeout_seconds=0.05)
 
 
         result = session.motor_status()
         result = session.motor_status()
+        frames, remainder = protocol.decode_stream(result.raw_response)
 
 
-        self.assertEqual(result.status.current_xyz, (0xFF, 0xFF, 0xFF))
+        self.assertEqual(remainder, b"")
         self.assertEqual(
         self.assertEqual(
-            [frame.frame_type for frame in result.command.frames],
+            [frame.frame_type for frame in frames],
             [protocol.FrameType.HOST_ACK, protocol.FrameType.MOTION_STATUS],
             [protocol.FrameType.HOST_ACK, protocol.FrameType.MOTION_STATUS],
         )
         )
+        self.assertEqual(len(frames[1].payload), protocol.MOTION_STATUS_PAYLOAD_LEN)
+        self.assertEqual(result.status.current_xyz, (0xFF, 0xFF, 0xFF))
         self.assertEqual(endpoint.writes, [request])
         self.assertEqual(endpoint.writes, [request])
 
 
-    def test_legacy_0x0f_frame_is_unexpected_not_a_compatibility_prefix(self) -> None:
-        cli = load_cli()
-        request = protocol.build_host_command(command=protocol.CommandId.GET_STATUS)
-        ack = protocol.build_host_ack(
-            ok=True,
-            command=protocol.CommandId.GET_STATUS,
-            status=protocol.StatusCode.OK,
-            state_hash16=0x1234,
+    def test_mark_closed_is_unsupported_and_has_no_model_side_effect(self) -> None:
+        subject = model_v3.NormalV3Model()
+        before = subject.state_fingerprint()
+
+        result = subject.apply_frame(bytes.fromhex(GOLDEN_REQUEST_HEX["mark_x"]))
+
+        self.assertFalse(result.accepted)
+        self.assertEqual(result.command, 0x36)
+        self.assertEqual(result.status, protocol.StatusCode.UNSUPPORTED_IN_PROFILE)
+        self.assertEqual(subject.state_fingerprint(), before)
+
+    def test_legacy_temperature_request_is_unsupported_and_has_no_side_effect(self) -> None:
+        subject = model_v3.NormalV3Model()
+        before = subject.state_fingerprint()
+
+        result = subject.apply_frame(legacy_temperature_request())
+
+        self.assertFalse(result.accepted)
+        self.assertEqual(result.command, 0x29)
+        self.assertEqual(result.status, protocol.StatusCode.UNSUPPORTED_IN_PROFILE)
+        self.assertEqual(subject.state_fingerprint(), before)
+
+    def test_jog_step_field_keeps_zero_invalid_and_65535_valid(self) -> None:
+        with self.assertRaisesRegex(ValueError, "steps must be from 1 to 65535"):
+            protocol.build_motor_jog(axis=0, raw_dir=1, speed_code=3, steps=0)
+
+        maximum = protocol.build_motor_jog(
+            axis=1,
+            raw_dir=1,
+            speed_code=3,
+            steps=65535,
         )
         )
-        legacy_trace = build_legacy_command_result(request, ack)
-        endpoint = ScriptedEndpoint(legacy_trace + ack)
-        session = cli.NormalSession(endpoint, timeout_seconds=0.05)
+        decoded = protocol.decode_motion_command(protocol.decode_frame(maximum))
 
 
-        with self.assertRaisesRegex(
-            RuntimeError,
-            r"(?i)(0x0f|trace_event|trace frame|unsupported|unexpected)",
-        ):
-            session.command(request, expected_command=protocol.CommandId.GET_STATUS)
+        self.assertEqual(decoded.steps, 65535)
+        self.assertEqual(protocol.decode_frame(maximum).payload[4:6], b"\xFF\xFF")
 
 
-        self.assertEqual(
-            endpoint.writes,
-            [request, protocol.build_host_command(command=protocol.CommandId.DISABLE)],
+    def test_partial_ack_preserves_solenoid_skip_bit_and_actual_state_hash(self) -> None:
+        wire = protocol.build_host_ack(
+            ok=True,
+            command=protocol.CommandId.SET_OUTPUT_SNAPSHOT,
+            status=protocol.StatusCode.PARTIAL,
+            detail=0x41,
+            state_hash16=0xE177,
+            result_flags=0x0D,
         )
         )
 
 
+        ack = protocol.decode_host_ack(protocol.decode_frame(wire))
+
+        self.assertEqual(ack.detail & 0x40, 0x40)
+        self.assertEqual(ack.detail & 0x07, 0x01)
+        self.assertEqual(ack.state_hash16, 0xE177)
+        self.assertEqual(ack.result_flags, 0x0D)
+
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     unittest.main()
     unittest.main()

+ 247 - 0
tests/unit/test_prod2u_p4_minimal_delivery_contract.py

@@ -0,0 +1,247 @@
+#!/usr/bin/env python3
+"""RED contracts for the minimal ACK-only Normal v3 delivery."""
+
+from __future__ import annotations
+
+import hashlib
+import json
+import re
+import shutil
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parents[2]
+STEM = "prod2u_p4_normal_v3"
+DISABLE_HEX = "A55A02040500000000000000000426000000C4AE"
+
+TD_INPUTS = (
+    ROOT / "td" / f"{STEM}.prj",
+    ROOT / "td" / "syn" / f"{STEM}.tcl",
+    ROOT / "td" / "phy" / f"{STEM}.tcl",
+    ROOT / "td" / "bitgen" / f"{STEM}.tcl",
+)
+PACKAGE_TEMPLATE_ROOT = ROOT / "tools" / "package_templates"
+PACKAGE_CONTRACT_INPUTS = (
+    ROOT / "tools" / f"package_{STEM}.ps1",
+    ROOT / "config" / "prod2u_p4_normal_host_contract_v4.json",
+    ROOT / "schemas" / "prod2u_p4_normal_host_contract_v4.schema.json",
+) + tuple(sorted(PACKAGE_TEMPLATE_ROOT.glob("*.ps1")))
+TRACE_ASSETS = (
+    ROOT / "tools" / "prod2u_p4_trace.py",
+    ROOT / "schemas" / f"{STEM}_trace_events.schema.json",
+    ROOT / "schemas" / f"{STEM}_actuator_trace_hardware_session.schema.json",
+)
+ACTIVE_BOOT_OR_BUILD_ID = re.compile(
+    r"(?i)(?:\bBUILD_ID\b|\bbuild[_-]identity\b|\bboot_build_id\b|"
+    r"\bboot_(?:valid|ready|payload)\b|\bOWNER_BOOT\b|\bchoose_boot\b)"
+)
+ACTIVE_TEMPERATURE_RTL = re.compile(
+    r"(?i)(?:temperature|ct7428|temp_(?:scl|sda)|u_temp(?:erature|_scan)?)"
+)
+
+
+def _git(repo: Path, *arguments: str) -> str:
+    return subprocess.run(
+        ["git", *arguments],
+        cwd=repo,
+        capture_output=True,
+        text=True,
+        check=True,
+    ).stdout.strip()
+
+
+def _copy_active_source(destination: Path) -> None:
+    ignored_names = {
+        ".git",
+        ".planning",
+        "__pycache__",
+        ".pytest_cache",
+        "build",
+        "tmp",
+    }
+
+    def ignore(_directory: str, names: list[str]) -> set[str]:
+        return {name for name in names if name in ignored_names or name.endswith((".pyc", ".pyo"))}
+
+    for relative in ("src", "tools", "td", "config", "constraints", "schemas", "docs"):
+        source = ROOT / relative
+        if source.exists():
+            shutil.copytree(source, destination / relative, ignore=ignore)
+    for relative in ("AGENTS.md", "README.zh-CN.md", ".gitignore"):
+        source = ROOT / relative
+        if source.is_file():
+            shutil.copy2(source, destination / relative)
+
+
+def _create_clean_package_fixture(root: Path) -> tuple[Path, str]:
+    source = root / "source"
+    source.mkdir()
+    _copy_active_source(source)
+    _git(source, "init")
+    _git(source, "config", "user.email", "tests@example.invalid")
+    _git(source, "config", "user.name", "Minimal delivery contract")
+    _git(source, "add", ".")
+    _git(source, "commit", "-m", "fixture")
+    return source, _git(source, "rev-parse", "HEAD")
+
+
+def _build_package(root: Path) -> tuple[Path, str, str]:
+    source, commit = _create_clean_package_fixture(root)
+    bitstream = root / "normal.bit"
+    bitstream.write_bytes(b"minimal-normal-v3-package-contract")
+    bitstream_sha256 = hashlib.sha256(bitstream.read_bytes()).hexdigest()
+    td_receipt = root / "td-build-receipt.json"
+    td_receipt.write_text(
+        json.dumps(
+            {
+                "schema": "prod2u-p4-normal-v3-td-build-receipt-v2",
+                "status": "pass",
+                "commit": commit,
+                "bitstream_sha256": bitstream_sha256,
+            }
+        ),
+        encoding="utf-8",
+    )
+    wheelhouse = root / "wheelhouse"
+    wheelhouse.mkdir()
+    (wheelhouse / "pyserial-3.5-py2.py3-none-any.whl").write_bytes(b"fixture")
+    output = root / "out"
+    completed = subprocess.run(
+        [
+            "powershell.exe",
+            "-NoProfile",
+            "-ExecutionPolicy",
+            "Bypass",
+            "-File",
+            str(source / "tools" / f"package_{STEM}.ps1"),
+            "-OutputDir",
+            str(output),
+            "-NormalBitstream",
+            str(bitstream),
+            "-TdReceipt",
+            str(td_receipt),
+            "-WheelhouseRoot",
+            str(wheelhouse),
+        ],
+        cwd=source,
+        capture_output=True,
+        text=True,
+        check=False,
+    )
+    if completed.returncode != 0:
+        raise AssertionError(completed.stdout + completed.stderr)
+    packages = [path for path in output.iterdir() if path.is_dir()]
+    if len(packages) != 1:
+        raise AssertionError(f"expected exactly one package directory, observed {packages}")
+    return packages[0], commit, bitstream_sha256
+
+
+class Prod2UP4MinimalDeliveryContractTests(unittest.TestCase):
+    def test_production_rtl_and_td_have_no_trace_boot_build_id_or_temperature_logic(self) -> None:
+        rtl_files = sorted((ROOT / "src" / "rtl").glob("*.v"))
+        rtl_files += sorted((ROOT / "src" / "top").glob("*.v"))
+        offenders: dict[str, list[str]] = {}
+        for path in rtl_files + list(TD_INPUTS):
+            text = path.read_text(encoding="utf-8", errors="replace")
+            found: list[str] = []
+            if "trace" in text.casefold() or "trace" in path.name.casefold():
+                found.append("trace")
+            if ACTIVE_BOOT_OR_BUILD_ID.search(text):
+                found.append("boot/build-id")
+            if path.suffix.casefold() == ".v" and (
+                ACTIVE_TEMPERATURE_RTL.search(path.name) or ACTIVE_TEMPERATURE_RTL.search(text)
+            ):
+                found.append("temperature-rtl")
+            if found:
+                offenders[path.relative_to(ROOT).as_posix()] = found
+
+        self.assertEqual(offenders, {})
+
+    def test_trace_tools_and_schemas_are_deleted_and_not_packaged_or_contracted(self) -> None:
+        existing = [path.relative_to(ROOT).as_posix() for path in TRACE_ASSETS if path.exists()]
+        existing += [
+            path.relative_to(ROOT).as_posix()
+            for root in (ROOT / "tools", ROOT / "schemas")
+            for path in root.glob("*trace*")
+            if path.is_file() and path not in TRACE_ASSETS
+        ]
+        self.assertEqual(sorted(existing), [])
+
+        offenders = {}
+        for path in PACKAGE_CONTRACT_INPUTS:
+            text = path.read_text(encoding="utf-8", errors="replace")
+            found = []
+            if "trace" in text.casefold():
+                found.append("trace")
+            if ACTIVE_BOOT_OR_BUILD_ID.search(text):
+                found.append("boot/build-id")
+            if found:
+                offenders[path.relative_to(ROOT).as_posix()] = found
+        self.assertEqual(offenders, {})
+
+    def test_limit_inputs_are_bound_to_verified_b9_and_a11_balls_only(self) -> None:
+        adc = (ROOT / "constraints" / f"{STEM}.adc").read_text(encoding="ascii")
+        rows = re.findall(
+            r"^set_pin_assignment\s+\{\s*([^}]+?)\s*\}\s+\{\s*LOCATION\s*=\s*([^;\s]+)",
+            adc,
+            flags=re.MULTILINE,
+        )
+        assignments = {signal.strip(): ball.strip() for signal, ball in rows}
+
+        self.assertEqual(assignments.get("x_limit_raw"), "B9")
+        self.assertEqual(assignments.get("y_limit_raw"), "A11")
+        self.assertNotIn("A5", assignments.values())
+
+    def test_ack_only_send_and_initialize_disable_scripts_are_explicit(self) -> None:
+        send_hex = ROOT / "tools" / "package_templates" / "SEND_HEX.ps1"
+        initialize = ROOT / "tools" / "package_templates" / "INITIALIZE_DISABLE.ps1"
+        self.assertTrue(send_hex.is_file(), send_hex)
+        self.assertTrue(initialize.is_file(), initialize)
+
+        send_text = send_hex.read_text(encoding="utf-8", errors="replace")
+        initialize_text = initialize.read_text(encoding="utf-8", errors="replace")
+        self.assertRegex(send_text, r"(?i)(?:HOST[_ -]?ACK|0x06)")
+        self.assertNotRegex(send_text, r"(?i)(?:trace|0x0f|boot_build_id|build_id)")
+        self.assertIn("SEND_HEX.ps1", initialize_text)
+        self.assertIn(DISABLE_HEX, re.sub(r"\s+", "", initialize_text).upper())
+        self.assertNotRegex(initialize_text, r"(?i)(?:trace|0x0f|boot_build_id|build_id)")
+
+    def test_package_name_and_manifest_use_full_commit_and_bitstream_hash(self) -> None:
+        with tempfile.TemporaryDirectory(dir=ROOT.parent) as temporary:
+            package, commit, bitstream_sha256 = _build_package(Path(temporary))
+            package_info = json.loads((package / "package-info.json").read_text(encoding="utf-8"))
+            observed_files = {
+                path.relative_to(package).as_posix()
+                for path in package.rglob("*")
+                if path.is_file()
+            }
+            text_offenders = {}
+            for relative in sorted(observed_files):
+                path = package / relative
+                if path.suffix.casefold() not in {".json", ".md", ".ps1", ".py"}:
+                    continue
+                text = path.read_text(encoding="utf-8", errors="replace")
+                found = []
+                if "trace" in text.casefold():
+                    found.append("trace")
+                if ACTIVE_BOOT_OR_BUILD_ID.search(text):
+                    found.append("boot/build-id")
+                if found:
+                    text_offenders[relative] = found
+
+        expected_name = f"prod2u-p4-normal-{commit}-{bitstream_sha256[:16]}"
+        self.assertEqual(package.name, expected_name)
+        self.assertEqual(package_info["commit"], commit)
+        self.assertEqual(package_info["bitstream_sha256"], bitstream_sha256)
+        self.assertNotIn("build_id", package_info)
+        self.assertIn("SEND_HEX.ps1", observed_files)
+        self.assertIn("INITIALIZE_DISABLE.ps1", observed_files)
+        self.assertFalse(any("trace" in relative.casefold() for relative in observed_files))
+        self.assertEqual(text_offenders, {})
+
+
+if __name__ == "__main__":
+    unittest.main()

+ 67 - 0
tests/unit/test_prod2u_p4_minimal_snapshot_contract_rtl.py

@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+"""Run the minimal independent-axis snapshot contract directly with Icarus."""
+
+from __future__ import annotations
+
+import subprocess
+import tempfile
+from pathlib import Path
+
+from tools import prod2u_p4_harness as harness
+
+
+ROOT = Path(__file__).resolve().parents[2]
+TESTBENCH = ROOT / "tests/sim/prod2u_p4_minimal_snapshot_contract_tb.v"
+SOURCES = (
+    ROOT / "src/rtl/binary921_crc16.v",
+    ROOT / "src/rtl/prod2u_p4_normal_v3_output_state.v",
+    ROOT / "src/rtl/prod2u_p4_normal_v3_watchdog.v",
+    ROOT / "src/rtl/prod2u_p4_axis_executor.v",
+    ROOT / "src/rtl/prod2u_p4_motor_hub.v",
+    ROOT / "src/rtl/prod2u_p4_response_scheduler.v",
+    ROOT / "src/rtl/prod2u_p4_normal_v3_core.v",
+    TESTBENCH,
+)
+
+
+def test_minimal_snapshot_contract_rtl() -> None:
+    iverilog = harness.resolve_tool("iverilog")
+    vvp = harness.resolve_tool("vvp")
+    assert iverilog is not None, "Icarus Verilog is required"
+    assert vvp is not None, "vvp is required"
+
+    with tempfile.TemporaryDirectory(prefix="p4-minimal-snapshot-") as temporary:
+        executable = Path(temporary) / "minimal_snapshot.vvp"
+        compile_result = subprocess.run(
+            [
+                str(iverilog),
+                "-g2005-sv",
+                "-s",
+                "prod2u_p4_minimal_snapshot_contract_tb",
+                "-o",
+                str(executable),
+                *(str(path) for path in SOURCES),
+            ],
+            cwd=ROOT,
+            env=harness.tool_env(),
+            capture_output=True,
+            text=True,
+            timeout=60,
+            check=False,
+        )
+        assert compile_result.returncode == 0, (
+            compile_result.stdout + compile_result.stderr
+        )
+
+        run_result = subprocess.run(
+            [str(vvp), str(executable)],
+            cwd=ROOT,
+            env=harness.tool_env(),
+            capture_output=True,
+            text=True,
+            timeout=60,
+            check=False,
+        )
+        output = run_result.stdout + run_result.stderr
+        assert run_result.returncode == 0, output
+        assert "PASS: prod2u_p4_minimal_snapshot_contract_tb" in output