File: t_constraint_dyn_queue_basic.v

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (113 lines) | stat: -rwxr-xr-x 3,271 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
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
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by PlanV GmbH.
// SPDX-License-Identifier: CC0-1.0

`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d:  got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);

class ConstrainedDynamicQueueArray;
    rand int queue_1d[$];
    rand int queue[$][$];
    rand int dyn[][];
    rand int queue_dyn[$][];
    rand int dyn_queue[][$];
    rand int queue_unp[$][3];
    rand int unp_queue[3][$];
    rand int \array_w[ith_es]cape [3][2];

    // Constraints for the queues and dynamic arrays
    constraint queue_constraints {
        foreach (queue_1d[i]) queue_1d[i] == i + 2;
        foreach (queue[i, j]) queue[i][j] == (2 * i) + j;
    }

    constraint dyn_constraints {
        dyn[0][0] == 10;
        dyn[1][0] inside {20, 30, 40};
        dyn[1][1] > 50;
        dyn[0][1] < 100;
        dyn[0][2] inside {5, 15, 25};
    }

    constraint queue_dyn_constraints {
        foreach (queue_dyn[i, j]) queue_dyn[i][j] == i + j + 3;
    }

    constraint dyn_queue_constraints {
        foreach (dyn_queue[i, j]) dyn_queue[i][j] == (3 * i) + j + 2;
    }

    constraint unp_queue_constraints {
        foreach (unp_queue[i, j]) unp_queue[i][j] == (i * 5) + j + 1;
    }

    constraint array_with_escape_constraints {
        \array_w[ith_es]cape [0][0] == 6;
    }

    // Constructor
    function new();
        queue_1d = {1, 2, 3, 4};
        queue = '{ '{1, 2}, '{3, 4, 5}, '{6}};
        dyn = new[2];
        dyn[0] = new[3];
        dyn[1] = new[4];

        queue_dyn = {};
        queue_dyn[0] = new[3];
        queue_dyn[1] = new[4];

        dyn_queue = new[2];
        dyn_queue[0] = {7, 8, 9};
        dyn_queue[1] = {10};

        queue_unp = {};

        unp_queue[0] = {17, 18};
        unp_queue[1] = {19};
        unp_queue[2] = {20};
    endfunction

    // Self-check function
    function void check();
        foreach (queue_1d[i]) `checkh(queue_1d[i], i + 2)

        foreach (queue[i, j]) `checkh(queue[i][j], (2 * i) + j)

        `checkh(dyn[0][0], 10)
        `checkh(dyn[1][0] inside {20, 30, 40}, 1'b1)
        `checkh(dyn[1][1] > 50, 1'b1)
        `checkh(dyn[0][1] < 100, 1'b1)
        `checkh(dyn[0][2] inside {5, 15, 25}, 1'b1)

        foreach (queue_dyn[i, j]) `checkh(queue_dyn[i][j], i + j + 3)

        foreach (dyn_queue[i, j]) `checkh(dyn_queue[i][j], (3 * i) + j + 2)

        `checkh(unp_queue[0][0], (0 * 5) + 0 + 1)
        `checkh(unp_queue[0][1], (0 * 5) + 1 + 1)
        `checkh(unp_queue[1][0], (1 * 5) + 0 + 1)
        `checkh(unp_queue[2][0], (2 * 5) + 0 + 1)

        `checkh(\array_w[ith_es]cape [0][0], 6)
    endfunction
endclass

module t_constraint_dyn_queue_basic;
    ConstrainedDynamicQueueArray array_test;
    int success;
    initial begin
        $display("Test: Randomization for dynamic and mixed queues and arrays:");
        array_test = new();
        repeat(2) begin
            success = array_test.randomize();
            `checkh(success, 1)
            array_test.check();
        end

        $write("*-* All Finished *-*\n");
        $finish;
    end
endmodule