Lecture4 - VHDL - Simple Testbenches
Short Description
VHDL lecture...
Description
Lecture 4
Simple Testbenches
Testbench Defined • Testbench = VHDL entity that applies stimuli (drives the inputs) t the Desi!n "nder Test (D"T) and (ptinally) verifies e#pected utputs$ • The results can be vie%ed in a %avefrm %ind% r %ritten t a file$ • Since Testbench is %ritten in VHDL& it is nt restricted t a sin!le simulatin tl (prtability)$ • The same Testbench can be easily adapted t test different implementatins (i$e$ different architectures) f the same desi!n$
Testbench Defined • Testbench = VHDL entity that applies stimuli (drives the inputs) t the Desi!n "nder Test (D"T) and (ptinally) verifies e#pected utputs$ • The results can be vie%ed in a %avefrm %ind% r %ritten t a file$ • Since Testbench is %ritten in VHDL& it is nt restricted t a sin!le simulatin tl (prtability)$ • The same Testbench can be easily adapted t test different implementatins (i$e$ different architectures) f the same desi!n$
Testbench
Processes Generating
Design Under Test (DUT)
Stimuli
Observed Outputs
ssible surces f e#pected results used fr cmparisn Testbench VHDL Design
actual results % &
Representative Inputs
Manual Calculations or
Reference Software Implementation (C !ava Matlab "
e#pecte$ results
Testbench The same testbench can be used t test multiple implementatins f the same circuit (multiple architectures) testbench
desi!n entity
*rchitecture + *rchitecture 2
$$$$
*rchitecture ,
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 PORT (
--All Design Under Test component declarations );
END COMPONENT;
----------------------------------------------------BEGIN
DUTTestComp
PORT MAP(
-- !nstantiations o" DUTs
); test#e$%ence
PROCESS
-- !np%t stim%li END PROCESS;
END behavioral;
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 i nut prts f tested entity SI,"AL test3vectr6 STD3L07853V:5T01(2 $O-"#O ;) SI,"AL test3result 6 STD3L0785
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"$ behaviral
VHDL Desi!n Styles &$L $esign St/les
d!t!0lo Concurrent statements
structur!l Components and interconnects
beh!vior!l Sequential statements
• #estbenches
Ghat is a 105:SSI • * prcess is a seAuence f instructins referred t as seAuential statements$ The Bey%rd 105:SS
• * 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
:#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 n i t u c e # e f r e d r 0
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$
r!ram e#ecutin stps here
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 n i t u c e # e f r e d r 0
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$
+
Speci0/ing ti3e in &$L
Time values (physical literals) :#amples . ns + min min +;$- us +;$- fs
,umeric value
Space
"nit f time (dimensin)
"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
secnds
min
minutes (-; secnds)
hr
hurs ('-;; secnds)
Si3ple #estbenches
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 behaviral
7eneratin! all values f ne input S87,*L test3vectr 6 STD3L07853V:5T01(' d%nt ;)1_periodD2 cl>1 9: 1C2 -AI# 'OR cl>1_periodD2 :,D 105:SS cl> 9: not cl> !0ter cl>_periodD2 $$$$$$$ :,D behaviral
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 = 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
Asserts F Reports
*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 simulatin r halt$
*ssert synta# *SS:1T cnditin N1:01T ?messa!e? NS:V:18T severity3level O #he 3ess!ge is ritten hen the condition is 'ALSE. Severity3level can be6 "ote? -!rning? Error 4de0!ult8? or '!ilure.
*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 "ote 4de0!ult8? -!rning? Error? or '!ilure.
1eprt :#amples
reprt ?8nitialiQatin cmplete? reprt ?5urrent time = ? R timeima!e(n%) reprt ?8ncrrect branch? severity errr
View more...
Comments