Introduction to SystemC Verification Library (SCV) · Introduction to SystemC Verification Library...
Transcript of Introduction to SystemC Verification Library (SCV) · Introduction to SystemC Verification Library...
What does SystemC Verification need?
• Test Generation
– Constrained Random
• Connection to HDL
– At various busses in the test bench
• Functional Coverage
– Scoreboard
2
What SCV provides?
• Test Generation– Constrained Randomization
– Weighted Randomization
• Connection to HDL– API for connection to HDL
• Functional Coverage– Transaction monitoring & recording ability
– But no built-in coverage
– Requires post processing
3
What SCV Provides? (contd.)
• Data Introspection (similar to Verilog PLI but for C/C++ data structures)
• Randomization and seed management for reproducibility of simulation runs
• Transaction Monitoring and Recording
• Sparse Array Support
4
How to get started with SCV?
• Download SystemC and SCV : http://www.accellera.org
– Get SystemC lib : systemc-2.3.0.tgz
– Get SCV lib : scv-1.0p2-sysc2.2.12jun06.tgz
• Compile SystemC
• Compile SCV
– On x86_64 linux will need a patch
• http://thawedoutnow.blogspot.tw/2013/02/scv-for-x8664-linux-patch.html
• OR use Simulation Vendor Tools
5
Running SCV examples
• Copy Makefile.rules.in to Makefile.rules– Define variables to point to the SCV and SystemC
include and lib directories
includedir=/home/cae/systemc/systemc-2.3.0/include
libdir=/home/cae/systemc/systemc-2.3.0/lib-linux64
SYSC_INC_PREFIX=$includedir
SYSC_LIB_PREFIX=$libdir
• Ensure LD_LIBRARY_PATH is set for dynamic libraries
• Patch is required : scv_constraint.h.patch
6
SCV Smart Pointer
• Key to using SCV
• No hassles of memory allocation/de-allocation
• Randomization
• Weighted Randomization
• Constrained Randomization
7
scv_smart_ptr<T> and scv_extensionsobject
This slide © WHDL (Intro to SystemC Modeling and Verification).
Reproduced with permission.
8
data_type T
scv_extensions<T>object
scv_smart_ptr<T> constructor automatically creates underlying scv_extensions objectscv_smart_ptr<T>
Acts like a pointer to the scv_extensions object
scv_smart_pointer example
scv_smart_pointer<int> sm_int(“sm_int_label”);
sm_int->print();
sm_int->next(); // randomize values
sm_int->keep_out(1, 5);
sm_int->keep_only(-10, 10);
sm_int->write(10);
sm_int->read();
9
Randomization
• Get a new random value set
– Next()
• Initialize the random number generator
– scv_random::set_global_seed(int)
• Pick a different seed each time
– scv_random::pick_random_seed()
• Enable/disable randomization
– enable_randomization()/disable_randomization()
10
Random Distribution
• Ranges
– keep_out()
– keep_only()
• Weighted
Distribution
– scv_bag()
11
scv_smart_ptr<data_t> data_p("data");
//create a distribution for generating the state data//highest probabilty for states 1-4, zero chance for 3
and//lower probability for 0, 5, and 6.
scv_bag<onehot_t> state_dist("state_dist");state_dist.add(STATE_0, 10);state_dist.add(STATE_1, 25);state_dist.add(STATE_2, 25);state_dist.add(STATE_4, 25);state_dist.add(STATE_5, 10);state_dist.add(STATE_6, 5);
//set the distribution for the state variable in data_pdata_p->state.set_mode(state_dist);
Constraints
struct addr_constraint : public scv_constraint_base {//create the objects that will be constrainedscv_smart_ptr<int> row;scv_smart_ptr<int> col;
SCV_CONSTRAINT_CTOR(addr_constraint) {//constraint row to be between 10 and 50 exclusive or 200 and 250 inclusiveSCV_CONSTRAINT ( (row() > 10 && row() < 50) ||
(row() >= 200 && row() <= 250) );
//constraint col to be less than row+20 and greater than row-5SCV_CONSTRAINT ( col() > ( row() - 5) );SCV_CONSTRAINT ( col() < ( row() + 20) );
}};
// SCV_SOFT_CONSTRAINT : Only warning, if constraint is not met, no error
12
Constraints (contd.)
scv_random::set_global_seed(1023);
//instantiate a constrained objectaddr_constraint addr("addr");
//randomize the object five times and print the valuesfor(int i=0; i<5; ++i) {addr.next();scv_out << "Row: " << *(addr.row) << "; Col: “ << *(addr.col) << endl;
}scv_out << endl;
13
SCV Register Examplestruct reg1_t {sc_uint<2> field1;sc_uint<5> field2;
};
struct reg2_t {sc_uint<3> f1;sc_uint<4> f2;sc_uint<1> f3;
};
struct block_t {reg1_t reg1;reg2_t reg2;
};
14
template<>class scv_extensions<block_t> : public
scv_extensions_base<block_t> {public:
scv_extensions<reg1_t > reg1;scv_extensions<reg2_t > reg2;
SCV_EXTENSIONS_CTOR(block_t) {SCV_FIELD(reg1);SCV_FIELD(reg2);
}};
SCV Register Example (contd.)
scv_smart_ptr<block_t> block_p ("block");
scv_random::set_global_seed(10);
block_p->reg1.field2.keep_only(1, 10);
block_p->next();
block_p->print();
block_p->next();
block_p->print();
15
SCV Register example outputRandom value for block:{
reg1 {field1:2field2:5 // Note the value has been constrained
}reg2 {
f1:3f2:13f3:0
}}
16
{reg1 {field1:3field2:2
}reg2 {f1:0f2:9f3:1
}}
Summary
• SCV promotes advanced verification methodology
• Where to go for more info?
– Go to the source : www.accellera.org
– Join the SystemC Verification Working Group (VWG)
• Apparently working on the next release
17