verilator/test_regress/t/t_process_rand.v

51 lines
1.1 KiB
Systemverilog
Raw Normal View History

2023-06-01 16:02:08 +02:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2023 Antmicro Ltd
2023-06-01 16:02:08 +02:00
// SPDX-License-Identifier: CC0-1.0
module t;
2026-03-10 02:38:29 +01:00
process p;
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
integer seed;
string state;
int a;
int b;
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
initial begin
p = process::self();
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
// Test setting RNG state with state string
state = p.get_randstate();
p.set_randstate(state);
a = $random;
p.set_randstate(state);
b = $random;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
// Test the same with $urandom
state = p.get_randstate();
p.set_randstate(state);
a = $urandom;
p.set_randstate(state);
b = $urandom;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
// Test if the results repeat after the state is reset
state = p.get_randstate();
for (int i = 0; i < 10; i++) $random;
a = $random;
// Now reset the state and take 11th result again
p.set_randstate(state);
for (int i = 0; i < 10; i++) $random;
b = $random;
$display("a=%d, b=%d", a, b);
if (a != b) $stop;
2023-06-01 16:02:08 +02:00
2026-03-10 02:38:29 +01:00
$write("*-* All Finished *-*\n");
$finish;
end
2023-06-01 16:02:08 +02:00
endmodule