Simple Testbenches
Simple Testbenches
Lecture 4
Testbench Defined
Testbench Defined
•• TestbenchTestbench = = VHDL VHDL entity that applies stimulientity that applies stimuli (drives the inputs) t the Desi!n "nder Test
(drives the inputs) t the Desi!n "nder Test
(D"T) and (ptinally) verifies e#pected utputs$
(D"T) and (ptinally) verifies e#pected utputs$
•• The results can be vie%ed in a %avefrm %ind%The results can be vie%ed in a %avefrm %ind%
r %ritten t a file$
r %ritten t a file$
•• SinceSince TestbenchTestbench is %ritten in VHDL& it is ntis %ritten in VHDL& it is nt
restricted t a sin!le simulatin tl (prtability)$
restricted t a sin!le simulatin tl (prtability)$
•• The sameThe same Testbench Testbench can be easily adapted tcan be easily adapted t
test different implementatins (i$e$
test different implementatins (i$e$ differentdifferent
architectures
Testbench Defined
Testbench Defined
•• TestbenchTestbench = = VHDL VHDL entity that applies stimulientity that applies stimuli (drives the inputs) t the Desi!n "nder Test
(drives the inputs) t the Desi!n "nder Test
(D"T) and (ptinally) verifies e#pected utputs$
(D"T) and (ptinally) verifies e#pected utputs$
•• The results can be vie%ed in a %avefrm %ind%The results can be vie%ed in a %avefrm %ind%
r %ritten t a file$
r %ritten t a file$
•• SinceSince TestbenchTestbench is %ritten in VHDL& it is ntis %ritten in VHDL& it is nt
restricted t a sin!le simulatin tl (prtability)$
restricted t a sin!le simulatin tl (prtability)$
•• The sameThe same Testbench Testbench can be easily adapted tcan be easily adapted t
test different implementatins (i$e$
test different implementatins (i$e$ differentdifferent
architectures
Testbench
Testbench
Processes Processes Generating Generating Stimuli Stimuli DesignDesign UnderUnder
Test (DUT)
Test (DUT)
Observed Outputs
Representative Inputs VHDL Design Manual Calculations or Reference Software Implementation (C !ava Matlab " e#pecte$ results Testbench actual results % &
ssible surces f e#pected results
used fr cmparisn
Testbench
testbench
desi!n entity
*rchitecture + *rchitecture 2 $ $ $ $ *rchitecture , The same testbench can be used t
test multiple implementatins f the same circuit (multiple architectures)
Testbench *natmy
ENTITY my_entity_tb IS
--TB entity has no ports
END my_entity_tb;
ARCHITECTURE behavioral OF tb IS
--Local signals and constants
COMPONENT TestComp --All Design Under Test component declarations
PORT ( );
END COMPONENT;
---BEGIN
DUTTestComp PORT MAP( -- !nstantiations o" DUTs
);
test#e$%ence PROCESS
-- !np%t stim%li
END PROCESS;
Testbench fr /01' (+)
LIBRARY ieee USE ieee.std_logic_116.!ll E"#I#Y #r'3tb IS E"$ #r'3tb AR%&I#E%#URE behaviral O' #r'3tb IS 5mpnent declaratin f the tested unit %O()O"E"# *or+ )OR#( * 6 I" STD3L0785 9 6 I" STD3L0785 5 6 I" STD3L0785 1esult 6 OU# STD3L0785 ) E"$ %O()O"E"# Stimulus si!nals si!nals mapped t the input and inut prts f tested entity SI,"AL test3vectr6 STD3L07853V:5T01(2 $O-"#O ;)
Testbench fr /01' (2)
BE,I" ""T 6 #r' )OR# (A) ( * = test3vectr(2)& 9 = test3vectr(+)& 5 = test3vectr(;)& 1esult = test3result) ) Testin!6 )RO%ESS BE,I" test3vectr >= ?;;;? -AI# 'OR +; ns test3vectr >= ?;;+? -AI# 'OR +; ns test3vectr >= ?;+;? -AI# 'OR +; ns test3vectr >= ?;++? -AI# 'OR +; ns test3vectr >= ?+;;? -AI# 'OR +; ns test3vectr >= ?+;+? -AI# 'OR +; ns test3vectr >= ?++;? -AI# 'OR +; ns test3vectr >= ?+++? -AI# 'OR +; ns E"$ )RO%ESS E"$ behaviralVHDL Desi!n Styles
Components and interconnects structur!l &$L $esign St/les d!t!0lo Concurrent statements beh!vior!l • #estbenches Sequential statements• * prcess can be !iven a uniAue name usin! an ptinal L*9:L
• This is fll%ed by the Bey%rd 105:SS
• The Bey%rd 9:78, is used t indicate the start f the prcess
• *ll statements %ithin the prcess are e#ecuted S:C":,T8*LL$ Hence& rder f statements is imprtant$
• * prcess must end %ith the Bey%rds :,D 105:SS$ Testin!6 105:SS 9:78, test3vectr>=E;;F G*8T 01 +; ns test3vectr>=E;+F G*8T 01 +; ns test3vectr>=E+;F G*8T 01 +; ns test3vectr>=E++F G*8T 01 +; ns :,D 105:SS
• * prcess is a seAuence f instructins referred t as seAuential statements$
Ghat is a 105:SSI
:#ecutin f statements in a 105:SS
• The e#ecutin f statements cntinues seAuentially till the last statement in the prcess$ • *fter e#ecutin f the last
statement& the cntrl is a!ain passed t the be!innin! f the prcess$ Testin!6 105:SS 9:78, test3vectr>=E;;F G*8T 01 +; ns test3vectr>=E;+F G*8T 01 +; ns test3vectr>=E+;F G*8T 01 +; ns test3vectr>=E++F G*8T 01 +; ns :,D 105:SS 0 r d e r f e # e c u t i n
r!ram cntrl is passed t the first statement after 9:78,
105:SS %ith a G*8T Statement
• The last statement in the
105:SS is a G*8T instead f G*8T 01 +; ns$
• This %ill cause the 105:SS t suspend indefinitely %hen the G*8T statement is
e#ecuted$
• This frm f G*8T can be used in a prcess included in a
testbench %hen all pssible cmbinatins f inputs have been tested r a nnperidical si!nal has t be !enerated$
Testin!6 105:SS 9:78, test3vectr>=E;;F G*8T 01 +; ns test3vectr>=E;+F G*8T 01 +; ns test3vectr>=E+;F G*8T 01 +; ns test3vectr>=E++F -AI#2 :,D 105:SS
r!ram e#ecutin stps here
0 r d e r f e # e c u t i n
G*8T 01 vs$ G*8T
G*8T 016 %avefrm %ill Beep repeatin! itself frever
G*8T 6 %avefrm %ill Beep its state after the last %ait instructin$
' ) *
+
Time values (physical literals) :#amples
. ns
+ min
min
+;$- us
+;$- fs
"nit f time (dimensin) Space ,umeric value"nits f time
Unit $e0inition B!se Unit fs femtsecnds (+;4+) secnds) $erived Units ps picsecnds (+;4+2 secnds) ns n!noseconds 41567 seconds8 us micrsecnds (+;4- secnds) ms milisecnds (+;4' secnds) sec secndsmin minutes (-; secnds)
7eneratin! selected values f ne input
S87,*L test3vectr 6 STD3L07853V:5T01(2 d%nt ;) 9:78, $$$$$$$ testin!6 105:SS 9:78, test_vector 9: ;555;2 -AI# 'OR 15 ns2 test_vector 9: ;551;2 -AI# 'OR 15 ns2 test_vector 9: ;515;2 -AI# 'OR 15 ns2 test_vector 9: ;511;2 -AI# 'OR 15 ns2 test_vector 9: ;155;2 -AI# 'OR 15 ns2 :,D 105:SS $$$$$$$$ :,D behaviral7eneratin! all values f ne input
S87,*L test3vectr 6 STD3L07853V:5T01(' d%nt ;)<:;5555;2 9:78, $$$$$$$ testin!6 105:SS 9:78, -AI# 'OR 15 ns2 test_vector 9: test_vector = 12 end prcess T:ST8,7 $$$$$$$$ :,D behaviral*rithmetic 0peratrs in VHDL (+)
#o use b!sic !rith3etic oper!tions involving std_logic_vectors /ou need to include the 0olloing libr!r/ p!c>!ges<
LIBRARY ieee
USE ieee$std3l!ic3++-4$all
USE ieee.std_logic_unsigned.!ll2 or
*rithmetic 0peratrs in VHDL (2)
You c!n use st!nd!rd =? oper!tors to per0or3 !ddition !nd subtr!ction<
sign!l A < S#$_LO,I%_E%#OR4+ donto 582 sign!l B < S#$_LO,I%_E%#OR4+ donto 582 sign!l % < S#$_LO,I%_E%#OR4+ donto 582 @@
Different %ays f perfrmin! the same peratin
si!nal cunt6 std3l!ic3vectr(. d%nt ;) u can use6
cunt >= cunt J E;;;;;;;+F
or
cunt >= cunt J +
or
Different declaratins fr the same peratr
$ecl!r!tions in the p!c>!ge ieee.std_logic_unsigned< functin EJF ( L6 std3l!ic3vectr
16std3l!ic3vectr)
return std3l!ic3vectr functin EJF ( L6 std3l!ic3vectr
16 inte!er)
return std3l!ic3vectr functin EJF ( L6 std3l!ic3vectr
16std3l!ic)
0peratr verladin!
• 0peratr verladin! all%s different
ar!ument types fr a !iven peratin
(functin)
• The VHDL tls reslve %hich f these
functins t select based n the types f the
inputs
• This selectin is transparent t the user as
ln! as the functin has been defined fr
the !iven ar!ument types$
S87,*L test3ab 6 STD3L07853V:5T01(+ d%nt ;) S87,*L test3sel 6 STD3L07853V:5T01(+ d%nt ;) 9:78, $$$$$$$ duble3lp6 105:SS 9:78, test_!b 9:;55;2 test_sel 9:;55;2 0or I in 5 to + loop 0or in 5 to + loop !it 0or 15 ns2 test_!b 9: test_!b = 12 end loop2 test_sel 9: test_sel = 12 end loop2 :,D 105:SS $$$$$$$$ :,D behaviral
7eneratin! peridical si!nals& such as clcBs
50,ST*,T clB+3perid 6 T8M: 6= 2; ns 50,ST*,T clB23perid 6 T8M: 6= 2;; ns S87,*L clB+ 6 STD3L0785 S87,*L clB2 6 STD3L0785 <: 5C2 9:78, $$$$$$$ clB+3!eneratr6 105:SS cl>1 9: 5C2-AI# 'OR cl>1_periodD2 cl>1 9: 1C2
-AI# 'OR cl>1_periodD2 :,D 105:SS
cl> 9: not cl> !0ter cl>_periodD2 $$$$$$$
7eneratin! netime si!nals& such as resets
50,ST*,T reset+3%idth 6 T8M: 6= +;; ns 50,ST*,T reset23%idth 6 T8M: 6= +; ns S87,*L reset+ 6 STD3L0785 S87,*L reset2 6 STD3L0785 <: 1C2 9:78, $$$$$$$ reset1_gener!tor< )RO%ESS reset1 9: 1C2-AI# 'OR reset_idth2 reset1 9: 5C2
-AI#2 E"$ )RO%ESS2
reset23!eneratr6 105:SS -AI# 'OR reset_idth2 reset 9: 5C2
-AI#2 :,D 105:SS $$$$$$$
Typical errr
S87,*L test3vectr 6 STD3L07853V:5T01(2 d%nt ;) S87,*L reset 6 STD3L0785 9:78, $$$$$$$ !eneratr+6 105:SS reset >= K+ G*8T 01 +;; ns reset >= K; test_vector 9:;555;2 G*8T :,D 105:SS !eneratr26 105:SS G*8T 01 2;; ns test_vector 9:;551;2 G*8T 01 -;; ns test_vector 9:;511;2 :,D 105:SS $$$$$$$ :,D behaviral*ssert
*ssert is a nons/nthesiG!ble statement
%hse purpse is t %rite ut messa!es
n the screen %hen prblems are fund
durin! simulatin$
Dependin! n the severit/ o0 the proble3&
The simulatr is instructed t cntinue
*ssert synta#
*SS:1T cnditinN1:01T ?messa!e?
NS:V:18T severity3level O
#he 3ess!ge is ritten hen the condition is 'ALSE.
Severity3level can be6
*ssert :#amples
assert initial3value >= ma#3value reprt ?initial value t lar!e? severity errr
assert pacBet3len!th P= ;
reprt ?empty net%rB pacBet received? severity %arnin!
assert false
reprt ?8nitialiQatin cmplete? severity nte
1eprt synta#
1:01T ?messa!e?
NS:V:18T severity3level O
#he 3ess!ge is !l!/s ritten.
Severity3level can be6
1eprt :#amples
reprt ?8nitialiQatin cmplete?
reprt ?5urrent time = ? R timeima!e(n%)