3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-08-18 10:52:18 +00:00

tests: Add long running cancellation

Actually exercise the database cancellation working on an already running task.
This appears to work even with `make -j1`.
This commit is contained in:
Krystine Sherwin 2025-07-09 10:04:58 +12:00
parent 1f3b418018
commit 63b43c7e66
No known key found for this signature in database
2 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,92 @@
[tasks]
bmc
prove
[cancelledby]
bmc: prove
[options]
bmc:
mode bmc
depth 20000
expect cancelled
prove:
mode prove
expect pass
--
[engines]
smtbmc boolector
[script]
read -sv autotune_div.sv
prep -top top
[file autotune_div.sv]
module top #(
parameter WIDTH = 4 // Reduce this if it takes too long on CI
) (
input clk,
input load,
input [WIDTH-1:0] a,
input [WIDTH-1:0] b,
output reg [WIDTH-1:0] q,
output reg [WIDTH-1:0] r,
output reg done
);
reg [WIDTH-1:0] a_reg = 0;
reg [WIDTH-1:0] b_reg = 1;
initial begin
q <= 0;
r <= 0;
done <= 1;
end
reg [WIDTH-1:0] q_step = 1;
reg [WIDTH-1:0] r_step = 1;
// This is not how you design a good divider circuit!
always @(posedge clk) begin
if (load) begin
a_reg <= a;
b_reg <= b;
q <= 0;
r <= a;
q_step <= 1;
r_step <= b;
done <= b == 0;
end else begin
if (r_step <= r) begin
q <= q + q_step;
r <= r - r_step;
if (!r_step[WIDTH-1]) begin
r_step <= r_step << 1;
q_step <= q_step << 1;
end
end else begin
if (!q_step[0]) begin
r_step <= r_step >> 1;
q_step <= q_step >> 1;
end else begin
done <= 1;
end
end
end
end
always @(posedge clk) begin
assert (r_step == b_reg * q_step); // Helper invariant
assert (q * b_reg + r == a_reg); // Main invariant & correct output relationship
if (done) assert (r <= b_reg - 1); // Output range
cover (done);
cover (done && b_reg == 0);
cover (r != a_reg);
cover (r == a_reg);
end
endmodule

View file

@ -0,0 +1,14 @@
#!/bin/bash
set -e
if [[ $TASK == bmc ]]; then
python3 $SBY_MAIN --prefix $WORKDIR -f $SBY_FILE prove bmc
else
python3 $SBY_MAIN --prefix $WORKDIR -f $SBY_FILE --statusreset || true
python3 $SBY_MAIN --prefix $WORKDIR -f $SBY_FILE bmc --statuscancels & bmc_pid="$!"
# make sure we don't leave the background task running
trap 'kill "$bmc_pid" 2>/dev/null || true' EXIT
python3 $SBY_MAIN --prefix $WORKDIR -f $SBY_FILE prove
sleep 10
test -e ${WORKDIR}_bmc/CANCELLED
fi