|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



CONSTRAINT BLOCK

Constraint Block



Constraint block contains declarative state ments which restrict the range of varable or defines the relation between variables.Constraint programming is a pwerful mehod that lets users build generic ,resuble objects that can be extended or more constrained later.Constraint solver can only support 2 stet variables.Constraint solver fails only if there is no solution which satisfies all the constraints.constraint block can also have nonrandom variables,but atleast one random variable is needed for randomization.
Constraints are tied to objects.This allows inheritance,hirarchical constraints,controlling the constraints of specific object.


EXAMPLE:
class Base{
rand integer Var;
constraint range { Var < 100 ; Var > 0 ;}
}

class Extended extends Base{
constraint range { Var < 100 ; Var > 50 ;} // Overrighting the Base class constraints.
}

program inhe{
Extended obj;
integer i;
obj = new();
for(i=0 ; i < 100 ; i++)
if(obj.randomize())
printf(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
printf("Randomization failed");
}

RESULTS:

Randomization sucsessfull : Var = 57
Randomization sucsessfull : Var = 82
Randomization sucsessfull : Var = 68
Randomization sucsessfull : Var = 81
Randomization sucsessfull : Var = 90


Inline Constraints



Inline constraints allows to add extra constraints to allready existing conrtints which are declared inside class.If you have constraints already defined for variavle var, solver solves those constraints wlong with the inline constraints.


EXAMPLE

class inline{
rand integer Var;
constraint default_c { Var > 0 ; Var < 100;}
}

program inline_p{
inline obj;
obj = new();
void = obj.randomize() with { Var == 50;} ;
printf(" Randodmize sucessful Var %d ",obj.Var);
}
RESULTS:

Randomization sucsessfull : Var = 50


Disabling Constraint Block



openvera supports to change the status of constraint block dynamically.To change the staus of a Constraint block,built in constraint_mode() method is used.By default all the constraint blocks are active.
When it is called as task,the arguments to the task determines the operation to be performed.


0  OFF  Sets the specified constraint block to inactive 
        so that it is not enforced by subsequent calls 
        to the randomize() method.
1  ON   Sets the specified constraint block to active so 
        that it is considered on subsequent calls to the 
        randomize() method.



When it is called as function,it returns the active status of the specified constrant block.



EXAMPLE:
class rand_mo{
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}
}

program rand_mo_p{
rand_mo obj = new();
void = obj.randomize();
printf(" Var1 : %d Var2 : %d \n",obj.Var1,obj.Var2);
void = obj.constraint_mode(0,"Var_1");
void = obj.randomize();
printf(" Var1 : %d Var2 : %d \n",obj.Var1,obj.Var2);
void = obj.constraint_mode(0,"Var_2");
void = obj.randomize();
printf(" Var1 : %d Var2 : %d \n",obj.Var1,obj.Var2);
}
RESULTS:

Var1 : 20 Var2 : 10
Var1 : 1923838927 Var2 : 10
Var1 : 1447386075 Var2 : -875228050

Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer