1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
class Foo;
rand int zero;
int two;
endclass
class Bar extends Foo;
rand int one;
static int three;
function void test;
logic[1:0] ok = '0;
zero = 100;
one = 200;
two = 300;
three = 400;
for (int i = 0; i < 20; i++) begin
void'(randomize(one));
if (zero != 100) $stop;
if (one != 200) ok[0] = 1;
if (two != 300) $stop;
if (three != 400) $stop;
end
if (!ok[0]) $stop;
ok = '0;
if (zero.rand_mode() != 1) $stop;
if (one.rand_mode() != 1) $stop;
zero = 500;
one = 600;
two = 700;
three = 800;
one.rand_mode(0);
for (int i = 0; i < 20; i++) begin
void'(randomize(one, two));
if (zero != 500) $stop;
if (one != 600) ok[0] = 1;
if (two != 700) ok[1] = 1;
if (three != 800) $stop;
end
if (one.rand_mode() != 0) $stop;
one.rand_mode(1);
if (ok != 'b11) $stop;
endfunction
endclass
class Baz;
int four;
Bar bar;
function new;
bar = new;
endfunction
endclass
class Qux;
Baz baz;
function new;
baz = new;
endfunction
endclass
class Boo extends Bar;
rand int five;
endclass
module t;
initial begin
Boo boo = new;
Bar bar = boo;
Qux qux = new;
logic[2:0] ok = '0;
bar.test;
bar.zero = 1000;
bar.one = 2000;
bar.two = 3000;
bar.three = 4000;
boo.five = 999999;
for (int i = 0; i < 20; i++) begin
int res = bar.randomize(two);
if (boo.five != 999999) $stop;
end
bar.zero = 1000;
bar.one = 2000;
bar.two = 3000;
bar.three = 4000;
boo.five = 999999;
for (int i = 0; i < 20; i++) begin
int res = bar.randomize(two) with { two > 3000 && two < 4000; };
if (bar.zero != 1000) $stop;
if (bar.one != 2000) $stop;
if (!(bar.two > 3000 && bar.two < 4000)) $stop;
if (bar.three != 4000) $stop;
if (boo.five != 999999) $stop;
end
qux.baz.bar.zero = 5000;
qux.baz.bar.one = 6000;
qux.baz.bar.two = 7000;
qux.baz.bar.three = 8000;
qux.baz.four = 9000;
for (int i = 0; i < 20; i++) begin
void'(qux.randomize(baz));
if (qux.baz.bar.zero != 5000) $stop;
if (qux.baz.bar.one != 6000) $stop;
if (qux.baz.bar.two != 7000) $stop;
if (qux.baz.bar.three != 8000) $stop;
if (qux.baz.four != 9000) $stop;
end
for (int i = 0; i < 20; i++) begin
void'(qux.randomize(baz.bar));
if (qux.baz.bar.zero != 5000) ok[0] = 1;
if (qux.baz.bar.one != 6000) ok[1] = 1;
if (qux.baz.bar.two != 7000) $stop;
if (qux.baz.bar.three != 8000) $stop;
if (qux.baz.four != 9000) $stop;
end
if (!ok[0]) $stop;
if (!ok[1]) $stop;
ok = '0;
qux.baz.bar.zero = 10000;
qux.baz.bar.one = 20000;
for (int i = 0; i < 20; i++) begin
void'(qux.randomize(baz.four));
if (qux.baz.bar.zero != 10000) $stop;
if (qux.baz.bar.one != 20000) $stop;
if (qux.baz.bar.two != 7000) $stop;
if (qux.baz.bar.three != 8000) $stop;
if (qux.baz.four != 9000) ok[0] = 1;
end
if (!ok[0]) $stop;
ok = '0;
qux.baz.four = 30000;
for (int i = 0; i < 20; i++) begin
void'(qux.randomize(baz.bar, qux.baz.bar.one, baz.four));
if (qux.baz.bar.zero != 10000) ok[0] = 1;
if (qux.baz.bar.one != 20000) ok[1] = 1;
if (qux.baz.bar.two != 7000) $stop;
if (qux.baz.bar.three != 8000) $stop;
if (qux.baz.four != 30000) ok[2] = 1;
end
if (ok != 'b111) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule
|