[SOLVED] System verilog extended class and constrained random question

Status
Not open for further replies.

vlsiexpert

Newbie
Joined
Feb 9, 2023
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
25
Need help on a simple system verilog code


1. class packet has dynamic array data[] and it's size is constrained between 1 to 250
2. Extending the packet class to small_packet and constraining size to be less than 10
3. casting small_packet to packet class's object

I would expect the size should be always less than 10, but it is not obeying the constraint in extended class

Any help?code link

[ MODERATOR ACTION ] Upload original code here


Code Verilog - [expand]
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
// Code your testbench here
// or browse Examples
class packet;
  rand byte data[];
  rand bit [7:0] length;
  
  constraint payload_size_c { data.size inside { [1 : 250]};}
  
endclass
 
class gen;
  rand packet pkt;
  function exec();
  pkt = new();
  if ( !pkt.randomize()) $fatal("Gen: trans randomization failed");
  endfunction: exec
endclass
 
class small_packet extends packet;
 
  constraint small_c { data.size < 10 ; }
endclass
program test;
  small_packet spkt;
  gen sgen;
  
  initial begin
   spkt = new();
    sgen = new();
    sgen.pkt = spkt;
    sgen.exec();
        
    $display("Size = %d, length = %d",sgen.pkt.data.size,sgen.pkt.length);
    
  end
endprogram

 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…