File: t_randomize_member_select.v

package info (click to toggle)
verilator 5.040-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 164,628 kB
  • sloc: cpp: 145,372; python: 21,412; ansic: 10,559; yacc: 6,085; lex: 1,931; makefile: 1,264; sh: 494; perl: 282; fortran: 22
file content (50 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (2)
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
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Antmicro.
// SPDX-License-Identifier: CC0-1.0

class B;
  rand int insideB;
  constraint i {
    insideB inside {[0:10]};
  };
endclass

class A;
  rand logic[31:0] rdata;
  rand int delay;
  int i = 97;
  rand B b;
  function new();
    b = new;
  endfunction
  constraint delay_bounds {
    delay inside {[0:2]};
  }
endclass

module t;
  A a;
  int i;
  int delay;
  logic[31:0] rdata;
  int b;
  initial begin
    a = new;
    i = 7;
    repeat (120) begin
      a.b.insideB = 3;
      a.delay = 1;
      a.rdata = 3;
      if (a.randomize() with {if (a.delay == 1) a.rdata == i;} == 0) $stop;
      if (a.b.randomize() with {a.b.insideB < 3;} == 0) $stop;
      if (a.delay == 1 && a.rdata != 97) $stop;
      if (a.b.insideB >= 3) $stop;
      if (a.randomize() with {if (a.delay == 1) a.rdata == local::i;} == 0) $stop;
      if (a.delay == 1 && a.rdata != 7) $stop;
    end
    $write("*-* All Finished *-*\n");
    $finish;
  end
endmodule