Reputation: 11
Signal x is a one hot signal of bits 'n' I would like to cover only one hot values of the signal and not interested in other values.
Ex: if a signal x is of 3 bits then I would like does x is reaching below values are not.
x == 3'b001
x == 3'b010
x == 3'b100
I tried below to achieve goal.
struct ABC {
x :uint(bits:n);
event pqrs;
cover pqrs is {
item x using ranges={
range([1]);
range([2]);
range([4]);
};
};
But above code is not elegant since 'n' `define value which can be varied based on environment. Please help me how to write coverage for above case.
Thanking all in advance for your help. Regards, Srikanth
Upvotes: 1
Views: 707
Reputation: 331
you cam write a simple 'define as computed' macro to do so. i have written a short example below.
the macro should look like this :
define <RANGE1'struct_member> "COVER_ITEM_WITH_DEFAULT_RANGES <struct_member>" as computed {
var x:uint(bits:NBITS) = 1;
var str := append( "cover covT_e is also {",
"item ", <1>," using ranges = {");
while(x!=0){
str =append(str,"range([",x,"]);");
x=x<<1;
};
str=append(str, "};",
"}"
);
return str;
};
and the you can use that in your code like so :
<'
define NBITS 4;
import cover0;
extend sys {
field1 : uint(bits:NBITS);
event covT_e;
cover covT_e is empty;
COVER_ITEM_WITH_DEFAULT_RANGES field1;
run() is also {
for i from 1 to 20 {
gen field1;
emit covT_e;
print field1;
}; // for i from 1 to...
}; // run() is also
finalize() is also{
specman("show cover");
};
}; // extend sys
'>
hope this helps!
Upvotes: 1
Reputation:
you can write yourself a define-as-computed macro that creates the covergroup. Note that the macro must expand to the full syntactic element, you cannot just create a macro that creates the range expressions. (I have such a macro but cannot disclose it).
Thorsten.
Upvotes: 0