tests/test.sh exit code (0 → resolved); the classification below is post-hoc and cannot change it.// UART receiver. Recovers bytes from a line idling high:
// one low start bit, 8 data bits LSB-first, one high stop bit,
// each BITLEN clock cycles. All outputs registered.
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 SIX = 6*BITLEN; // break threshold (six low bit periods)
localparam int HALF = BITLEN/2; // half a bit period, floored
localparam int CW = $clog2(SIX+1);
localparam int BW = $clog2(BITLEN+1);
localparam logic [1:0] S_IDLE = 2'd0,
S_DATA = 2'd1,
S_BREAK = 2'd2, // break asserted, waiting for line high
S_RECOV = 2'd3; // waiting for six continuous high periods
logic rx_meta, rx_sync; // two-flop synchronizer
logic [1:0] state;
logic [CW-1:0] low_cnt, high_cnt;
logic [BW-1:0] cnt; // cycles since last sample point
logic [3:0] data_idx; // data bits sampled so far (0..8; 8 => stop)
logic [3:0] d_pending; // bytes still forced to frame_err
logic [7:0] shiftreg;
logic [CW-1:0] nlow; // this cycle's consecutive-low count
always_ff @(posedge clk) begin
// synchronizer (default)
rx_meta <= rx_i;
rx_sync <= rx_meta;
// one-cycle pulses default low
valid_o <= 1'b0;
frame_err_o <= 1'b0;
if (rst) begin
rx_meta <= 1'b1;
rx_sync <= 1'b1;
state <= S_IDLE;
low_cnt <= '0;
high_cnt <= '0;
cnt <= '0;
data_idx <= '0;
d_pending <= '0;
shiftreg <= '0;
data_o <= '0;
valid_o <= 1'b0;
frame_err_o <= 1'b0;
break_o <= 1'b0;
end else begin
// consecutive-low counter, measured from the high->low edge
nlow = (rx_sync == 1'b0)
? ((low_cnt >= CW'(SIX)) ? CW'(SIX) : low_cnt + 1'b1)
: '0;
low_cnt <= nlow;
if ((state == S_IDLE || state == S_DATA) && (nlow >= CW'(SIX))) begin
// Break preempts any in-progress frame: byte dropped, no valid.
break_o <= 1'b1;
d_pending <= (state == S_DATA) ? data_idx : 4'd0; // d, zero if none
state <= S_BREAK;
end else begin
case (state)
S_IDLE: begin
// Accept a start the exact cycle a fresh low reaches HALF.
if (rx_sync == 1'b0 && nlow == CW'(HALF)) begin
state <= S_DATA;
cnt <= '0;
data_idx <= '0;
shiftreg <= '0;
end
end
S_DATA: begin
if (cnt == BW'(BITLEN-1)) begin
cnt <= '0;
if (data_idx < 4'd8) begin
shiftreg[data_idx] <= rx_sync; // LSB first
data_idx <= data_idx + 1'b1;
end else begin
// stop bit sampled -> deliver byte
valid_o <= 1'b1;
data_o <= shiftreg;
frame_err_o <= (d_pending != 4'd0) || (rx_sync == 1'b0);
if (d_pending != 4'd0)
d_pending <= d_pending - 1'b1;
state <= S_IDLE;
end
end else begin
cnt <= cnt + 1'b1;
end
end
S_BREAK: begin
if (rx_sync == 1'b1) begin
break_o <= 1'b0; // break falls when line high again
high_cnt <= CW'(1); // this high cycle counts
state <= S_RECOV;
end
end
S_RECOV: begin
// Re-arm only after six continuous high periods; any low
// restarts the count, break stays low.
if (rx_sync == 1'b1) begin
if (high_cnt + 1'b1 >= CW'(SIX))
state <= S_IDLE;
else
high_cnt <= high_cnt + 1'b1;
end else begin
high_cnt <= '0;
end
end
default: state <= S_IDLE;
endcase
end
end
end
endmodule
Lint/compile the SystemVerilog
(iverilog -g2012 -o /tmp/dut.out 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 behavioral testbench
cat > /tmp/tb.sv << 'EOF'
`timescale 1ns/1ps
module tb;
localparam int BITLEN=8;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) dut(.clk,.rst,.rx_i(rx),.data_o(data),
.valid_o(valid),.frame_err_o(ferr),.break_o(brk));
always #5 clk=~clk;
task cyc(int n); repeat(n) @(posedge clk); endtask
// send one bit-period at level v
task bit_p(logic v); rx=v; cyc(BITLEN); endtask
// send a byte (start=0, 8 data LSB first, stop=stopv)
task send(input [7:0] b, input logic stopv);
bit_p(0);
for(int i=0;i<8;i++) bit_p(b[i]);
bit_p(stopv);
endtask
int vcount=0;
always @(posedge clk) if(valid) begin
$display("t=%0t VALID data=%02x ferr=%b brk=%b", $time, data, ferr, brk);
vcount++;
end
always @(posedge clk) if(brk) $display("t=%0t BREAK", $time);
initial begin
cyc(3); rst=0; rx=1; cyc(3*BITLEN); // idle high, let sync settle
$display("--- normal byte 0xA5, good stop ---");
send(8'hA5,1'b1); cyc(2);
$display("--- byte 0x3C, bad stop (framing err) ---");
send(8'h3C,1'b0); cyc(2);
// recover: line high a while
rx=1; cyc(BITLEN*2);
$display("--- all-low break (should self-break, no valid, d=5) ---");
rx=0; cyc(BITLEN*7); // hold low > 6 periods -> break
rx=1; cyc(BITLEN*7); // high >=6 periods -> re-arm
$display("--- next byte should be FORCED frame_err (good stop) ---");
send(8'h5A,1'b1); cyc(2);
rx=1; cyc(BITLEN*3);
$finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/tb.out /tmp/dut.out.dummy 2>/dev/null; iverilog -g2012 -o /tmp/tb.out dut.sv /tmp/tb.sv && vvp /tmp/tb.out--- normal byte 0xA5, good stop --- t=1055000 VALID data=a5 ferr=0 brk=0 --- byte 0x3C, bad stop (framing err) --- t=1875000 VALID data=3c ferr=1 brk=0 --- all-low break (should self-break, no valid, d=5) --- t=2575000 BREAK t=2585000 BREAK t=2595000 BREAK t=2605000 BREAK t=2615000 BREAK t=2625000 BREAK t=2635000 BREAK t=2645000 BREAK t=2655000 BREAK --- next byte should be FORCED frame_err (good stop) --- t=3975000 VALID data=5a ferr=1 brk=0 /tmp/tb.sv:41: $finish called at 4245000 (1ps) [stdout] --- normal byte 0xA5, good stop --- t=1055000 VALID data=a5 ferr=0 brk=0 --- byte 0x3C, bad stop (framing err) --- t=1875000 VALID data=3c ferr=1 brk=0 --- all-low break (should self-break, no valid, d=5) --- t=2575000 BREAK t=2585000 BREAK t=2595000 BREAK t=2605000 BREAK t=2615000 BREAK t=2625000 BREAK t=2635000 BREAK t=2645000 BREAK t=2655000 BREAK --- next byte should be FORCED frame_err (good stop) --- t=3975000 VALID data=5a ferr=1 brk=0 /tmp/tb.sv:41: $finish called at 4245000 (1ps)
Confirm exactly 5 forced frame errors
cat > /tmp/tb2.sv << 'EOF'
`timescale 1ns/1ps
module tb;
localparam int BITLEN=8;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) dut(.clk,.rst,.rx_i(rx),.data_o(data),
.valid_o(valid),.frame_err_o(ferr),.break_o(brk));
always #5 clk=~clk;
task cyc(int n); repeat(n) @(posedge clk); endtask
task bit_p(logic v); rx=v; cyc(BITLEN); endtask
task send(input [7:0] b, input logic stopv);
bit_p(0); for(int i=0;i<8;i++) bit_p(b[i]); bit_p(stopv);
endtask
always @(posedge clk) if(valid)
$display("VALID data=%02x ferr=%b", data, ferr);
initial begin
cyc(3); rst=0; rx=1; cyc(3*BITLEN);
rx=0; cyc(BITLEN*7); rx=1; cyc(BITLEN*7); // self-break (d=5), then re-arm
for(int k=0;k<7;k++) begin send(k[7:0],1'b1); cyc(2); end // 7 good-stop bytes
rx=1; cyc(BITLEN*3); $finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/tb2.out dut.sv /tmp/tb2.sv && vvp /tmp/tb2.out/tmp/tb2.sv:20: $finish called at 7365000 (1ps) [stdout] /tmp/tb2.sv:20: $finish called at 7365000 (1ps)
Debug with break edges and byte count
cat > /tmp/tb3.sv << 'EOF'
`timescale 1ns/1ps
module tb;
localparam int BITLEN=8;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) dut(.clk,.rst,.rx_i(rx),.data_o(data),
.valid_o(valid),.frame_err_o(ferr),.break_o(brk));
always #5 clk=~clk;
task cyc(int n); repeat(n) @(posedge clk); endtask
task bit_p(logic v); rx=v; cyc(BITLEN); endtask
task send(input [7:0] b, input logic stopv);
bit_p(0); for(int i=0;i<8;i++) bit_p(b[i]); bit_p(stopv);
endtask
int nb=0;
always @(posedge clk) if(valid) begin
$display("t=%0t VALID data=%02x ferr=%b", $time, data, ferr); nb++; end
logic brkp=0;
always @(posedge clk) begin
if(brk & ~brkp) $display("t=%0t BREAK rise",$time);
if(~brk & brkp) $display("t=%0t BREAK fall",$time);
brkp<=brk;
end
initial begin
cyc(3); rst=0; rx=1; cyc(3*BITLEN);
rx=0; cyc(BITLEN*7); rx=1; cyc(BITLEN*7);
for(int k=0;k<7;k++) begin send(k[7:0],1'b1); cyc(2); end
rx=1; cyc(BITLEN*3);
$display("total bytes=%0d",nb);
$finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/tb3.out dut.sv /tmp/tb3.sv && vvp /tmp/tb3.outt=775000 BREAK rise t=865000 BREAK fall t=1895000 BREAK rise t=2145000 BREAK fall total bytes=0 /tmp/tb3.sv:29: $finish called at 7365000 (1ps) [stdout] t=775000 BREAK rise t=865000 BREAK fall t=1895000 BREAK rise t=2145000 BREAK fall total bytes=0 /tmp/tb3.sv:29: $finish called at 7365000 (1ps)
Verify exactly 5 forced frame errors after self-break
cat > /tmp/tb4.sv << 'EOF'
`timescale 1ns/1ps
module tb;
localparam int BITLEN=8;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) dut(.clk,.rst,.rx_i(rx),.data_o(data),
.valid_o(valid),.frame_err_o(ferr),.break_o(brk));
always #5 clk=~clk;
task cyc(int n); repeat(n) @(posedge clk); endtask
task bit_p(logic v); rx=v; cyc(BITLEN); endtask
task send(input [7:0] b, input logic stopv);
bit_p(0); for(int i=0;i<8;i++) bit_p(b[i]); bit_p(stopv);
endtask
always @(posedge clk) if(valid)
$display("VALID data=%02x ferr=%b", data, ferr);
initial begin
cyc(3); rst=0; rx=1; cyc(3*BITLEN);
rx=0; cyc(BITLEN*7); rx=1; cyc(BITLEN*7); // self-break (d=5) then re-arm
// send 7 non-breaking bytes (0x5A), all good stop
for(int k=0;k<7;k++) begin send(8'h5A,1'b1); cyc(2); end
rx=1; cyc(BITLEN*3); $finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/tb4.out dut.sv /tmp/tb4.sv && vvp /tmp/tb4.outVALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=0 VALID data=5a ferr=0 /tmp/tb4.sv:21: $finish called at 7365000 (1ps) [stdout] VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=1 VALID data=5a ferr=0 VALID data=5a ferr=0 /tmp/tb4.sv:21: $finish called at 7365000 (1ps)
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.DarNhQ/runtime/cb_verifier_339-20398-30361-15969_339/results.jsonl"}Reproduce this trial: git checkout 2f94510 && PYTHONPATH=src python3 scripts/build_site.py , then open trial/trial_69fcc49e9ae24413. Re-running the agent live requires EVAL_PLATFORM_ENABLE_OAUTH_SMOKE=1 and is non-deterministic.
Trial trial_69fcc49e9ae24413 · verifier authoritative; classifier explanatory.