2024-12-13 15:32:47 +01:00
|
|
|
// DESCRIPTION: Verilator: Verilog Test module
|
|
|
|
|
//
|
2026-01-27 02:24:34 +01:00
|
|
|
// This file ONLY is placed under the Creative Commons Public Domain.
|
|
|
|
|
// SPDX-FileCopyrightText: 2024 Antmicro Ltd
|
2024-12-13 15:32:47 +01:00
|
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
|
|
|
|
|
`define check_rand(cl, field, constr, cond) \
|
|
|
|
|
begin \
|
2026-03-10 02:38:29 +01:00
|
|
|
automatic longint prev_result; \
|
|
|
|
|
automatic int ok; \
|
|
|
|
|
if (!bit'(cl.randomize() with { constr; })) $stop; \
|
|
|
|
|
prev_result = longint'(field); \
|
|
|
|
|
if (!(cond)) $stop; \
|
|
|
|
|
repeat(9) begin \
|
|
|
|
|
longint result; \
|
|
|
|
|
if (!bit'(cl.randomize() with { constr; })) $stop; \
|
|
|
|
|
result = longint'(field); \
|
|
|
|
|
if (!(cond)) $stop; \
|
|
|
|
|
if (result != prev_result) ok = 1; \
|
|
|
|
|
prev_result = result; \
|
|
|
|
|
end \
|
|
|
|
|
if (ok != 1) $stop; \
|
2024-12-13 15:32:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class Cls #(int LIMIT = 3);
|
2026-03-10 02:38:29 +01:00
|
|
|
rand int x;
|
|
|
|
|
int y = -100;
|
|
|
|
|
constraint x_limit { x <= LIMIT; };
|
2024-12-13 15:32:47 +01:00
|
|
|
endclass
|
|
|
|
|
|
|
|
|
|
module t;
|
2026-03-10 02:38:29 +01:00
|
|
|
initial begin
|
|
|
|
|
automatic Cls#() cd = new;
|
|
|
|
|
automatic Cls#(5) c5 = new;
|
2024-12-13 15:32:47 +01:00
|
|
|
|
2026-03-10 02:38:29 +01:00
|
|
|
`check_rand(cd, cd.x, x > 0, cd.x > 0 && cd.x <= 3);
|
|
|
|
|
`check_rand(cd, cd.x, x > y, cd.x > -100 && cd.x <= 3);
|
|
|
|
|
if (cd.randomize() with {x > 3;} == 1) $stop;
|
2024-12-13 15:32:47 +01:00
|
|
|
|
2026-03-10 02:38:29 +01:00
|
|
|
`check_rand(c5, c5.x, x > 0, c5.x > 0 && c5.x <= 5);
|
|
|
|
|
`check_rand(c5, c5.x, x > y, c5.x > -100 && c5.x <= 5);
|
|
|
|
|
if (c5.randomize() with {x >= 5;} == 0) $stop;
|
|
|
|
|
if (c5.x != 5) $stop;
|
2024-12-13 15:32:47 +01:00
|
|
|
|
2026-03-10 02:38:29 +01:00
|
|
|
$write("*-* All Finished *-*\n");
|
|
|
|
|
$finish;
|
|
|
|
|
end
|
2024-12-13 15:32:47 +01:00
|
|
|
endmodule
|