Your Ad Here

Tuesday, March 31, 2009

specman e-language supports constraint random generation

specman e-language supports the concept of constrained random generation.

. Constraints are applied on struct members e.g Fields and methods.

· Constraints are Boolean equations

· Constraints are declarative statements

Specman e-language categories the constrained mechansim as follows :

1) Random Generation without any constraints parameters
2) Directed Random constrained Generation [ e.g from .. to ]
3) Directed constrained Generation

For constraining a Field use the following syntax :
keep Boolean-expression

Ex: struct packet_s {

Length : uint(bits:6);

Address : uint(bits:2);

// application of Directed Constraints Parameter for Length field

keep Length = = 10;

// application of Directed Random Constraints Parameter for Address field

keep Address in [0..2];
};




For constraining elements in a list (array):

keep for each (item) in list_name {

Boolean-expression; };


Ex: Struct packet_driver_s {

Packets : list of packet_s;

// Constraints list for the individual fields

keep for each (pkt) in packets {

pkt.len < 10; }; };



The syntax for implication constraints are given below:

keep Boolean-expr1 => Boolean-expr2;

Ex:

keep size = = SHORT => length < 10;

keep size = = LONG => length > 20;

Or, suppose if we want to constraint using lists:

Ex:

keep for each (pkt) in packet {

index = = 0 => pkt.addr = = 1 and pkt.kind = = GOOD;

index = = 1 => pkt.addr = = 2 and pkt.kind = = BAD; };


Weighted Constraints:

Weighted constraints are used on a specific application. It allows selection weight for value or range of values. In order to achieve a weighted constraint we need to apply a soft control on the distribution of generated values.

syntax: keep soft gen-item = = select {weight: value ;};

Ex: <’

keep soft length = = select {

20:14;

25:10;

10:20; };

‘>

Thursday, March 19, 2009

specman e-language usage examples for extending methods

Here i am listing examples of extending methods using specman e-language concept.

Ex : extending using is_also

---> Filename packet.e
<’

struct packet_s {

my_method () is {

out (“I am here”);
};
};

‘>

-------> new file packet_extend.e

<’

import packet.e;

extend packet_s {

my_method () is also {

out("to learn e-language”);
};
};

‘>

when we execute the packet_extend.e we can see finally the output appearing as "I am here to learn e-language".


Ex : extend using is first

---> Filename packet.e

<’

struct packet_s {

my_method () is {

out (“I am here”);
};
};

'>

---> New file : packet_extend.e
<’

import packet_extend.e;

extend packet_s {

my_method () is first {

out (“to learn e-language”);
};
};

'>

when we execute the packet_extend.e we can see finally the output appearing as "to learn e-language i am here".


Ex: extend using is only

---> Filename packet.e

<’

struct packet_s {

my_method () is {

out (“I am here”); }; };

'>

---> New file packet_extend.e

<’

import packet.e;

extend transaction_s {

my_method () is only {

out (“to learn e-language”);
};
};

'>

when we execute the packet_extend.e we can see finally the output appearing as "to learn e-language ", this extend method operator overrules the previous contents of the same method defined.

Wednesday, March 18, 2009

How to extend methods in e-language

Specman e-language has the built in features to extend the predefined and
user-defined methods in order to have new contents.
The extension can be done in the same file where the original method is declared or in another new file.
Specman e-language supports the following features for extending the methods

a) is first => which means add before the existing e code
b) is also => which means add after the existing e code
c) is only => which means override/replace the existing e code

Sunday, March 15, 2009

what are different output actions in e-language

e-language supports both formatted and non-formatted print statements, this is similar to any other high-level programming language.

print -> print data, useful at the command line and for struct printing.

Outf() -> it is a predefined method available in Specman e-language. This helps in printing the statements in a formatted manner.

Out() -> it is predefined method available in Specman e-language. This helps in printing the statements without formatted manner.

How to use methods using return values

The below code describes how to use methods using the return values
Ex: file_name : packet.e

<’

struct packet_s {

length: uint;

legal: bool;

legal_value (len: uint): bool is {

If (length >= len) then {

Result = TRUE;
};

If (result = FALSE) then {

legal = FALSE;
};
};

length_calc() is {

var length_incr : uint := 0;

if (length == 0) then {

length_incr = length_incr + 1;
};

// call the Legal_value method

legal_value(length_incr);
};

run() is also {

length_calc() ; // Need to call this method as it is calling other method

};
};

‘>

How to use methods using local struct fields

The below example shows how to use local struct fields for writing method using e-language.

Ex : file_name : packet.e

<’

struct packet_s {

length: uint (bits; 6);

legal_value(): bool is {

if (length >= 64) then {

return (TRUE);
};
}; // end of method

// extend the pre-defined method to call the local method

run() is also {

// call the method declared

legal_value();

}; // end of run() method
};

‘>

Saturday, March 14, 2009

Procedural Control statements in e-language

e-language is high-level programming language, it supports all Procedural flow control statements. The defined flow control statements are:

· If-else statement

· Case statement

· For loop

· While loop

· Repeat-Until loop

Ex: If statement execution

<’

struct packet_s {

Flag: bool;

Check_flag (): bool is {

If (flag = TRUE) {
Out (“flag is true”);
}
else {
Out (“flag is false”);
}; // end of if cond
}; // end of method

run() is also {

Check_flag(); // calling the method declared
};
}; // end of declared struct

‘>


Ex: Case Statement Execution

<’
struct packet_s {

Flag: bool;

Check_flag (): bool is {

Case flag {

TRUE: {out (“flag is true”)};

FALSE: {out (“flag is false”)};
}; // end of case statement
}; // end of method

run() is also {

Check_flag();
};

}; // end of struct

‘>

Ex: For loop condition execution
<’

struct packet_d {

! Pkt: Packet_s; // on-the fly generation

No_of_Pkt: uint (bits: 4);

Keep No_of_Pkt in [1.. 10];

Packet_gen () is {

For i from 0 to (no_of_Pkt-1) {

gen Pkt; }; // on_the_fly gen (gen is specman keyword)

}; // end of method


run() is also {

Packet_gen();
};
}; // end of struct

‘>