03.05.2013 Views

SystemC Verification Library (SCV)

SystemC Verification Library (SCV)

SystemC Verification Library (SCV)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Introduction to<br />

<strong>SystemC</strong> <strong>Verification</strong> <strong>Library</strong> (<strong>SCV</strong>)<br />

Anupam Bakshi<br />

Agnisys, Inc.<br />

April 14 th 2013<br />

ISCUG


What does <strong>SystemC</strong> <strong>Verification</strong> need?<br />

• Test Generation<br />

– Constrained Random<br />

• Connection to HDL<br />

– At various busses in the test bench<br />

• Functional Coverage<br />

– Scoreboard<br />

2


What <strong>SCV</strong> provides?<br />

• Test Generation<br />

– Constrained Randomization<br />

– Weighted Randomization<br />

• Connection to HDL<br />

– API for connection to HDL<br />

• Functional Coverage<br />

– Transaction monitoring & recording ability<br />

– But no built-in coverage<br />

– Requires post processing<br />

3


What <strong>SCV</strong> Provides? (contd.)<br />

• Data Introspection (similar to Verilog PLI but<br />

for C/C++ data structures)<br />

• Randomization and seed management for<br />

reproducibility of simulation runs<br />

• Transaction Monitoring and Recording<br />

• Sparse Array Support<br />

4


How to get started with <strong>SCV</strong>?<br />

• Download <strong>SystemC</strong> and <strong>SCV</strong> : http://www.accellera.org<br />

– Get <strong>SystemC</strong> lib : systemc-2.3.0.tgz<br />

– Get <strong>SCV</strong> lib : scv-1.0p2-sysc2.2.12jun06.tgz<br />

• Compile <strong>SystemC</strong><br />

• Compile <strong>SCV</strong><br />

– On x86_64 linux will need a patch<br />

• http://thawedoutnow.blogspot.tw/2013/02/scv-for-x8664linux-patch.html<br />

• OR use Simulation Vendor Tools<br />

5


Running <strong>SCV</strong> examples<br />

• Copy Makefile.rules.in to Makefile.rules<br />

– Define variables to point to the <strong>SCV</strong> and <strong>SystemC</strong><br />

include and lib directories<br />

includedir=/home/cae/systemc/systemc-2.3.0/include<br />

libdir=/home/cae/systemc/systemc-2.3.0/lib-linux64<br />

SYSC_INC_PREFIX=$includedir<br />

SYSC_LIB_PREFIX=$libdir<br />

• Ensure LD_LIBRARY_PATH is set for dynamic<br />

libraries<br />

• Patch is required : scv_constraint.h.patch<br />

6


• Key to using <strong>SCV</strong><br />

<strong>SCV</strong> Smart Pointer<br />

• No hassles of memory allocation/de-allocation<br />

• Randomization<br />

• Weighted Randomization<br />

• Constrained Randomization<br />

7


scv_smart_ptr and scv_extensions<br />

scv_smart_ptr<br />

Acts like a pointer to the<br />

scv_extensions object<br />

object<br />

This slide © WHDL (Intro to <strong>SystemC</strong> Modeling and <strong>Verification</strong>).<br />

Reproduced with permission.<br />

scv_extensions<br />

object<br />

data_type T<br />

scv_smart_ptr<br />

constructor automatically<br />

creates underlying<br />

scv_extensions object<br />

8


scv_smart_pointer example<br />

scv_smart_pointer sm_int(“sm_int_label”);<br />

sm_int->print();<br />

sm_int->next(); // randomize values<br />

sm_int->keep_out(1, 5);<br />

sm_int->keep_only(-10, 10);<br />

sm_int->write(10);<br />

sm_int->read();<br />

9


Randomization<br />

• Get a new random value set<br />

– Next()<br />

• Initialize the random number generator<br />

– scv_random::set_global_seed(int)<br />

• Pick a different seed each time<br />

– scv_random::pick_random_seed()<br />

• Enable/disable randomization<br />

– enable_randomization()/disable_randomization()<br />

10


• Ranges<br />

– keep_out()<br />

– keep_only()<br />

• Weighted<br />

Distribution<br />

– scv_bag()<br />

Random Distribution<br />

scv_smart_ptr data_p("data");<br />

//create a distribution for generating the state data<br />

//highest probabilty for states 1-4, zero chance for 3<br />

and<br />

//lower probability for 0, 5, and 6.<br />

scv_bag state_dist("state_dist");<br />

state_dist.add(STATE_0, 10);<br />

state_dist.add(STATE_1, 25);<br />

state_dist.add(STATE_2, 25);<br />

state_dist.add(STATE_4, 25);<br />

state_dist.add(STATE_5, 10);<br />

state_dist.add(STATE_6, 5);<br />

//set the distribution for the state variable in data_p<br />

data_p->state.set_mode(state_dist);<br />

11


Constraints<br />

struct addr_constraint : public scv_constraint_base {<br />

//create the objects that will be constrained<br />

scv_smart_ptr row;<br />

scv_smart_ptr col;<br />

<strong>SCV</strong>_CONSTRAINT_CTOR(addr_constraint) {<br />

//constraint row to be between 10 and 50 exclusive or 200 and 250 inclusive<br />

<strong>SCV</strong>_CONSTRAINT ( (row() > 10 && row() < 50) ||<br />

(row() >= 200 && row() ( row() - 5) );<br />

<strong>SCV</strong>_CONSTRAINT ( col() < ( row() + 20) );<br />

}<br />

};<br />

// <strong>SCV</strong>_SOFT_CONSTRAINT : Only warning, if constraint is not met, no error<br />

12


Constraints (contd.)<br />

scv_random::set_global_seed(1023);<br />

//instantiate a constrained object<br />

addr_constraint addr("addr");<br />

//randomize the object five times and print the values<br />

for(int i=0; i


struct reg1_t {<br />

sc_uint field1;<br />

sc_uint field2;<br />

};<br />

struct reg2_t {<br />

sc_uint f1;<br />

sc_uint f2;<br />

sc_uint f3;<br />

};<br />

struct block_t {<br />

reg1_t reg1;<br />

reg2_t reg2;<br />

};<br />

<strong>SCV</strong> Register Example<br />

template<br />

class scv_extensions : public<br />

scv_extensions_base {<br />

public:<br />

scv_extensions reg1;<br />

scv_extensions reg2;<br />

<strong>SCV</strong>_EXTENSIONS_CTOR(block_t) {<br />

<strong>SCV</strong>_FIELD(reg1);<br />

<strong>SCV</strong>_FIELD(reg2);<br />

}<br />

};<br />

14


<strong>SCV</strong> Register Example (contd.)<br />

scv_smart_ptr block_p ("block");<br />

scv_random::set_global_seed(10);<br />

block_p->reg1.field2.keep_only(1, 10);<br />

block_p->next();<br />

block_p->print();<br />

block_p->next();<br />

block_p->print();<br />

15


<strong>SCV</strong> Register example output<br />

Random value for block:<br />

{<br />

reg1 {<br />

field1:2<br />

field2:5 // Note the value has been constrained<br />

}<br />

reg2 {<br />

f1:3<br />

f2:13<br />

f3:0<br />

}<br />

}<br />

{<br />

reg1 {<br />

field1:3<br />

field2:2<br />

}<br />

reg2 {<br />

f1:0<br />

f2:9<br />

f3:1<br />

}<br />

}<br />

16


Summary<br />

• <strong>SCV</strong> promotes advanced verification methodology<br />

• Where to go for more info?<br />

– Go to the source : www.accellera.org<br />

– Join the <strong>SystemC</strong> <strong>Verification</strong> Working Group (VWG)<br />

• Apparently working on the next release<br />

17


Q/A<br />

18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!