tests/test.sh exit code (0 → resolved); the classification below is post-hoc and cannot change it.// UART receiver.
//
// Line idles high. A byte is: one low start bit, eight data bits (LSB first),
// one high stop bit, each BITLEN clock cycles.
//
// - rx_i is synchronized through two flops; all logic uses that line.
// - A start is accepted the exact cycle a fresh low run (from the high->low
// edge) reaches floor(BITLEN/2). Data bits are sampled at bit-period
// centers, then the stop bit; sampling the stop bit pulses valid_o with the
// byte on data_o (frame_err_o that cycle if the stop bit was low).
// - break_o is a level: high once the line completes six continuous low bit
// periods, until the line is high again. A break preempts any in-progress
// frame (dropped, no valid). After break_o falls, no start is accepted until
// the line holds high for six bit periods (any low restarts the count).
// - d = data bits sampled by the interrupted byte (0 if none); the next d
// delivered bytes are forced frame_err_o high. A further break replaces any
// pending count with its own d.
module TopModule #(
parameter int BITLEN = 16
)(
input logic clk,
input logic rst,
input logic rx_i,
output logic [7:0] data_o,
output logic valid_o,
output logic frame_err_o,
output logic break_o
);
localparam int HALF = BITLEN/2; // floored half bit period
localparam int BREAKLEN = 6*BITLEN; // six continuous bit periods
localparam logic [1:0] NORMAL = 2'd0,
BRK = 2'd1,
RECOVER = 2'd2;
logic sync0, sync1; // two-flop synchronizer
logic [1:0] mode;
logic [31:0] low_run_r, high_run_r; // consecutive low/high run lengths
logic receiving;
logic [31:0] cnt; // cycles until next sample
logic [3:0] bit_no; // data bits sampled so far (0..8)
logic [7:0] shiftreg;
logic [3:0] forced_remaining; // pending frame_err-forced bytes
// Combinational temporaries used only inside the clocked block.
logic rx;
logic [31:0] run, hrun;
always @(posedge clk) begin
if (rst) begin
sync0 <= 1'b1;
sync1 <= 1'b1;
mode <= NORMAL;
low_run_r <= '0;
high_run_r <= '0;
receiving <= 1'b0;
cnt <= '0;
bit_no <= '0;
shiftreg <= '0;
forced_remaining <= '0;
data_o <= '0;
valid_o <= 1'b0;
frame_err_o <= 1'b0;
break_o <= 1'b0;
end else begin
// Two-flop synchronizer; act on the stable (previous) sync1 value.
sync0 <= rx_i;
sync1 <= sync0;
rx = sync1;
// Consecutive low / high run lengths, including this cycle.
run = rx ? 32'd0 : (low_run_r + 32'd1);
hrun = rx ? (high_run_r + 32'd1) : 32'd0;
low_run_r <= run;
high_run_r <= hrun;
// Pulse outputs default low each cycle.
valid_o <= 1'b0;
frame_err_o <= 1'b0;
case (mode)
NORMAL: begin
if (run >= BREAKLEN) begin
// Break preempts everything, including any live frame.
mode <= BRK;
break_o <= 1'b1;
forced_remaining <= receiving ? bit_no : 4'd0;
receiving <= 1'b0;
end else if (receiving) begin
if (cnt == 0) begin
if (bit_no < 8) begin
// Sample a data bit at its center.
shiftreg[bit_no] <= rx;
bit_no <= bit_no + 4'd1;
cnt <= BITLEN-1;
end else begin
// Sample the stop bit -> deliver the byte.
valid_o <= 1'b1;
data_o <= shiftreg;
if (!rx || forced_remaining != 0)
frame_err_o <= 1'b1;
if (forced_remaining != 0)
forced_remaining <= forced_remaining - 4'd1;
receiving <= 1'b0;
end
end else begin
cnt <= cnt - 32'd1;
end
end else begin
// Idle: accept a start once the low run reaches HALF.
if (run == HALF) begin
receiving <= 1'b1;
cnt <= BITLEN-1;
bit_no <= '0;
shiftreg <= '0;
end
end
end
BRK: begin
// Hold break_o high until the line returns high.
if (rx) begin
break_o <= 1'b0;
mode <= RECOVER;
end
end
RECOVER: begin
// No start accepted until six continuous high bit periods;
// any low restarts the count (hrun), break_o stays low.
if (hrun >= BREAKLEN)
mode <= NORMAL;
end
default: mode <= NORMAL;
endcase
end
end
endmodule
Lint/compile the SystemVerilog module
(iverilog -g2012 -o /tmp/dut_test dut.sv 2>&1 && echo "IVERILOG OK") || (verilator --lint-only -Wall dut.sv 2>&1 && echo "VERILATOR OK") || echo "no simulator available"
IVERILOG OK [stdout] IVERILOG OK
Run a functional testbench
cat > /tmp/tb.sv <<'EOF'
module tb;
localparam BL = 8;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BL)) d(.clk(clk),.rst(rst),.rx_i(rx),
.data_o(data),.valid_o(valid),.frame_err_o(ferr),.break_o(brk));
always #5 clk=~clk;
task tick; begin @(posedge clk); #1; end endtask
// send one bit: level held for BL cycles
task sendbit(input b); integer i; begin rx=b; for(i=0;i<BL;i=i+1) tick; end endtask
task sendbyte(input [7:0] v); integer i; begin
sendbit(0); for(i=0;i<8;i=i+1) sendbit(v[i]); sendbit(1); end endtask
integer j;
initial begin
rst=1; tick; tick; rst=0; rx=1;
repeat(4) tick;
// normal byte 0xA5, stop high
fork
begin sendbyte(8'hA5); repeat(3) tick; end
join
// break: hold low for 6+ bit periods
rx=0; for(j=0;j<7*BL;j=j+1) tick;
rx=1; for(j=0;j<8*BL;j=j+1) tick; // recover (>6 bit periods high)
// after recovery, d bytes forced frame_err. send a normal byte
sendbyte(8'h3C); repeat(3) tick;
sendbyte(8'h3C); repeat(3) tick;
$finish;
end
// monitor events
always @(posedge clk) begin
if(valid) $display("t=%0t VALID data=%02h ferr=%b", $time, data, ferr);
if(brk) $display("t=%0t BREAK", $time);
end
endmodule
EOF
iverilog -g2012 -o /tmp/sim /app/dut.sv /tmp/tb.sv && vvp /tmp/sim 2>&1 | head -40t=845 VALID data=a5 ferr=0 t=1395 BREAK t=1405 BREAK t=1415 BREAK t=1425 BREAK t=1435 BREAK t=1445 BREAK t=1455 BREAK t=1465 BREAK t=1475 BREAK t=2875 VALID data=3c ferr=1 t=3705 VALID data=3c ferr=1 /tmp/tb.sv:27: $finish called at 3746 (1s) [stdout] t=845 VALID data=a5 ferr=0 t=1395 BREAK t=1405 BREAK t=1415 BREAK t=1425 BREAK t=1435 BREAK t=1445 BREAK t=1455 BREAK t=1465 BREAK t=1475 BREAK t=2875 VALID data=3c ferr=1 t=3705 VALID data=3c ferr=1 /tmp/tb.sv:27: $finish called at 3746 (1s)
No file changes, the agent left the workspace untouched.
TEST dut_present: PASS (/app/dut.sv exists)
TEST dut_forbidden: PASS (no forbidden constructs)
TEST dut_compiles: PASS (compiled with held-back reference/testbench)
TEST simulation_completed: PASS (Mismatches: 292 in 8633 samples)
TEST reference_equivalence: FAIL (292 mismatches in 8633 samples)
{"score": 0.000000, "results_file": "/tmp/h2t-grader-home.w8ewEV/runtime/cb_verifier_314-25111-7731-15373_314/results.jsonl"}Reproduce this trial: git checkout 2f94510 && PYTHONPATH=src python3 scripts/build_site.py , then open trial/trial_8e2f4529e9e9476f. Re-running the agent live requires EVAL_PLATFORM_ENABLE_OAUTH_SMOKE=1 and is non-deterministic.
Trial trial_8e2f4529e9e9476f · verifier authoritative; classifier explanatory.