tests/test.sh exit code (0 → resolved); the classification below is post-hoc and cannot change it.// UART-style receiver with break detection.
//
// A byte : 1 low start bit, 8 data bits (LSB first), 1 high stop bit,
// each BITLEN clock cycles. Line idles high.
// Start : accepted the cycle a fresh continuous low (measured from the
// high->low edge) reaches floor(BITLEN/2); a shorter low is ignored.
// Sampling: 8 data bits then the stop bit at bit-period centers.
// break_o : level, high once the synchronized line has been continuously low
// for six bit periods, until the line is high again. A break is
// shorter than a byte and preempts any frame in progress (dropped).
// After break falls, no start is accepted until the line holds high
// for six bit periods (any low restarts the wait).
// Let d be the number of data bits the interrupted byte sampled (0 if none):
// the next d delivered bytes force frame_err_o high; a further break
// replaces any pending count with its own d.
module TopModule #(
parameter 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; // floor(BITLEN/2)
localparam int BREAKLEN = 6 * BITLEN; // six bit periods
localparam int CW = $clog2(6 * BITLEN + 2);
// two-flop synchronizer for rx_i
logic sync1, sync2;
logic [CW:0] low_run, high_run; // continuous low / high run lengths
logic armed; // start acceptance enabled
logic active; // a frame is being received
logic [CW:0] phase_cnt; // cycles since last sample point
logic [3:0] data_idx; // number of data bits sampled (0..8)
logic [7:0] shreg; // received data (LSB first)
logic [3:0] pending_err; // remaining bytes forced to frame error
always_ff @(posedge clk) begin
if (rst) begin
sync1 <= 1'b1;
sync2 <= 1'b1;
low_run <= '0;
high_run <= '0;
armed <= 1'b1;
active <= 1'b0;
phase_cnt <= '0;
data_idx <= '0;
shreg <= '0;
pending_err <= '0;
data_o <= '0;
valid_o <= 1'b0;
frame_err_o <= 1'b0;
break_o <= 1'b0;
end else begin
logic cur;
logic [CW:0] nlow, nhigh;
logic brk;
logic newly_break;
// synchronizer
sync1 <= rx_i;
sync2 <= sync1;
cur = sync2; // the synchronized line
// continuous low / high run counters (saturating)
if (cur == 1'b0) begin
nlow = (low_run >= BREAKLEN) ? BREAKLEN[CW:0] : low_run + 1'b1;
nhigh = '0;
end else begin
nlow = '0;
nhigh = (high_run >= BREAKLEN) ? BREAKLEN[CW:0] : high_run + 1'b1;
end
low_run <= nlow;
high_run <= nhigh;
// break level
if (cur == 1'b1)
brk = 1'b0;
else if (nlow >= BREAKLEN)
brk = 1'b1;
else
brk = break_o;
break_o <= brk;
newly_break = brk & ~break_o; // rising edge of break
// arm / recover
if (newly_break)
armed <= 1'b0;
else if (!armed && nhigh >= BREAKLEN)
armed <= 1'b1;
// pulse outputs default low
valid_o <= 1'b0;
frame_err_o <= 1'b0;
if (newly_break) begin
// break preempts any frame; record how many data bits it sampled
active <= 1'b0;
pending_err <= active ? data_idx : 4'd0;
end else if (active) begin
if (phase_cnt + 1 == BITLEN) begin
phase_cnt <= '0;
if (data_idx < 8) begin
shreg <= {cur, shreg[7:1]}; // LSB first
data_idx <= data_idx + 1'b1;
end else begin
// stop bit sampled -> deliver the byte
valid_o <= 1'b1;
data_o <= shreg;
frame_err_o <= (cur == 1'b0) || (pending_err != 0);
if (pending_err != 0)
pending_err <= pending_err - 1'b1;
active <= 1'b0;
end
end else begin
phase_cnt <= phase_cnt + 1'b1;
end
end else begin
// idle: accept a fresh start at half a bit period of low
if (armed && cur == 1'b0 && nlow == HALF) begin
active <= 1'b1;
phase_cnt <= '0;
data_idx <= '0;
end
end
end
end
endmodule
Compile/lint the module
(iverilog -g2012 -o /tmp/dut.out dut.sv 2>&1 && echo "ICARUS_OK") || (verilator --lint-only -Wno-lint dut.sv 2>&1 && echo "VERILATOR_OK") || echo "no simulator available"
ICARUS_OK [stdout] ICARUS_OK
Run functional sanity testbench
cat > /tmp/tb.sv <<'EOF'
module tb;
localparam BITLEN=4;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) 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 send_bit(input logic b); repeat(BITLEN) @(posedge clk) rx<=b; endtask
task send_byte(input [7:0] x, input logic stop);
send_bit(0); // start
for(int i=0;i<8;i++) send_bit(x[i]);
send_bit(stop); // stop
endtask
always @(posedge clk) if(valid) $display("t=%0t VALID data=%02x ferr=%b",$time,data,ferr);
always @(posedge clk) if(brk) $display("t=%0t BREAK",$time);
initial begin
repeat(3) @(posedge clk); rst<=0; rx<=1;
repeat(6) @(posedge clk);
send_byte(8'hA5,1); // normal, good stop
repeat(4) @(posedge clk);
send_byte(8'h3C,0); // bad stop -> ferr
repeat(4) @(posedge clk);
// all-low break: hold low long
repeat(BITLEN*8) @(posedge clk) rx<=0;
rx<=1; repeat(BITLEN*8) @(posedge clk); // recover (6 high periods)
// after break d=5 -> next 5 good bytes forced ferr
send_byte(8'h11,1);
send_byte(8'h22,1);
repeat(4) @(posedge clk);
$finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/t.out /tmp/dut.check dut.sv /tmp/tb.sv 2>/dev/null; iverilog -g2012 -o /tmp/t.out dut.sv /tmp/tb.sv && vvp /tmp/t.outt=505 VALID data=a5 ferr=0 t=945 VALID data=3c ferr=1 t=1085 BREAK t=1095 BREAK t=1105 BREAK t=1115 BREAK t=1125 BREAK t=1135 BREAK t=1145 BREAK t=1155 BREAK t=1165 BREAK t=1175 BREAK t=1185 BREAK t=1195 BREAK t=1205 BREAK t=1215 BREAK t=1225 BREAK t=1235 BREAK t=1245 BREAK t=1255 BREAK t=1265 BREAK t=1275 BREAK t=1285 BREAK t=1295 BREAK t=1305 BREAK t=1315 BREAK t=2025 VALID data=11 ferr=0 t=2425 VALID data=22 ferr=0 /tmp/tb.sv:30: $finish called at 2445 (1s) [stdout] t=505 VALID data=a5 ferr=0 t=945 VALID data=3c ferr=1 t=1085 BREAK t=1095 BREAK t=1105 BREAK t=1115 BREAK t=1125 BREAK t=1135 BREAK t=1145 BREAK t=1155 BREAK t=1165 BREAK t=1175 BREAK t=1185 BREAK t=1195 BREAK t=1205 BREAK t=1215 BREAK t=1225 BREAK t=1235 BREAK t=1245 BREAK t=1255 BREAK t=1265 BREAK t=1275 BREAK t=1285 BREAK t=1295 BREAK t=1305 BREAK t=1315 BREAK t=2025 VALID data=11 ferr=0 t=2425 VALID data=22 ferr=0 /tmp/tb.sv:30: $finish called at 2445 (1s)
Clean forced-frame-error test after break
cat > /tmp/tb2.sv <<'EOF'
module tb;
localparam BITLEN=4;
logic clk=0, rst=1, rx=1;
logic [7:0] data; logic valid, ferr, brk;
TopModule #(.BITLEN(BITLEN)) 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 send_bit(input logic b); repeat(BITLEN) @(posedge clk) rx<=b; endtask
task send_byte(input [7:0] x, input logic stop);
send_bit(0); for(int i=0;i<8;i++) send_bit(x[i]); send_bit(stop);
endtask
int nvalid=0;
always @(posedge clk) if(valid) begin nvalid++; $display("VALID#%0d data=%02x ferr=%b",nvalid,data,ferr); end
logic pb=0;
always @(posedge clk) begin if(brk&&!pb)$display(">> BREAK rises"); if(!brk&&pb)$display(">> BREAK falls"); pb<=brk; end
initial begin
repeat(3) @(posedge clk); rst<=0; rx<=1;
repeat(10) @(posedge clk);
// clean break from idle: drive low >=6 bit periods
repeat(BITLEN*7) @(posedge clk) rx<=0;
rx<=1; repeat(BITLEN*7) @(posedge clk); // recover: hold high 6+ periods
// now send 6 clean good-stop bytes; first 5 must be forced ferr=1 (d=5)
for(int k=0;k<6;k++) begin send_byte(8'h55,1); repeat(2) @(posedge clk); end
repeat(6) @(posedge clk); $finish;
end
endmodule
EOF
iverilog -g2012 -o /tmp/t2.out dut.sv /tmp/tb2.sv && vvp /tmp/t2.out>> BREAK rises >> BREAK falls VALID#1 data=55 ferr=1 VALID#2 data=55 ferr=1 VALID#3 data=55 ferr=1 VALID#4 data=55 ferr=1 VALID#5 data=55 ferr=1 VALID#6 data=55 ferr=0 /tmp/tb2.sv:24: $finish called at 3265 (1s) [stdout] >> BREAK rises >> BREAK falls VALID#1 data=55 ferr=1 VALID#2 data=55 ferr=1 VALID#3 data=55 ferr=1 VALID#4 data=55 ferr=1 VALID#5 data=55 ferr=1 VALID#6 data=55 ferr=0 /tmp/tb2.sv:24: $finish called at 3265 (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.7QyhVD/runtime/cb_verifier_324-14632-25116-21816_324/results.jsonl"}Reproduce this trial: git checkout 2f94510 && PYTHONPATH=src python3 scripts/build_site.py , then open trial/trial_52f4d9b07c2e4921. Re-running the agent live requires EVAL_PLATFORM_ENABLE_OAUTH_SMOKE=1 and is non-deterministic.
Trial trial_52f4d9b07c2e4921 · verifier authoritative; classifier explanatory.