cmput 329 - computer organization and architecture ii 1 cmput329 - fall 2003 topic 6: testbenches...

13
CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

Upload: roy-casey

Post on 25-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture

II 1

CMPUT329 - Fall 2003

Topic 6: TestbenchesParas Mehta and José Nelson Amaral

Page 2: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 2

Why Use Testbenches?

● Manually Driven Simulation● specify inputs and observe outputs● advantage

● allows testing without downloading to device● disadvantage

● can only test a few combinations of input

Page 3: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 3

Why Use Testbenches?

● Testbenches● a programmed thorough test of design● advantages

● test design without downloading to board● can program a test of all inputs as well

automatically check expected behaviour● disadvantages

● cannot test all functionality (e.g. keyboard)● cannot determine/resolve timing issues

Page 4: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 4

Testbench Structure

● Testbench is self-contained● Internal signals are directly

manipulated● Elements:

● entity contains no ports● declare, instantiate testing components● process for supplying input● process for checking output

Page 5: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 5

Testbench

Testbench Structure

UnitUnderTest

clkreset

input_1input_2

input_n. . .

output_1output_2

output_n

. . .

Manipulated byTestbench

Checked byTestbench

Page 6: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 6

architecture behaviour of testbench is signal clk, rst : std_logic; signal done : boolean; constant clk_period : time := 5 ns;begin

end architecture;

done <= true when condition else false;

. . .

. . . clk <= '0' when rst = '1' else not clk after clk_period when not done else '0';

. . . rst <= '1', '0' after time;

Condition indicates simulation is over. e.g:

• time period has elapsed• iterations completed• end of input file reached

Testbench Structure

● Basic signals are clock, reset, and termination:

Clk:

• not active during reset• oscillates until done

Reset:

• brief pulse for reset of all signals in the design

Page 7: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 7

Manipulating Input

● Input set as normal signal assignment

ALU

operand1

operand2

alu_result

opcode

input: process()begin

operand1 <= “000”;operand2 <= “101”;opcode <= “100”;

end process;

Page 8: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 8

assert conditionreport debug-stringseverity note | warning | error | failure;

Syntax:

Checking Output

● Output read as a normal signal read● Checking done with assert-report-

severity

Page 9: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 9

Checking Output

● Output read as a normal signal read● Checking done with assert-report-

severityverify: process(output)begin if clk'event and clk = '0' then if (opcode = AND_OP)

assert (alu_result = operand1 and operand2)report “Output is incorrect”severity error;

end if; end if;end process;

Falling edge allows signal to be checked

Page 10: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 10

File Input

● Using assert to check behaviour implies writing correct behaviour twice

● Instead, write expected behaviour in file: Testbench

UnitUnder Test

Assert

Expected Output Output

Page 11: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 11

File Input

● Require file and line variables:InputProcess: process (clk) file input : text is “input.txt”; variable line_in: line; variable op1_in, op2_in : std_logic_vector(3 downto 0);begin if clk'event and clk='1' then if not endfile(input) then

readline(input, line_in);read(line_in, op1_in);read(line_in, op2_in);operand1 <= op1_in;operand2 <= op2_in;

end if; end if;end process;

std.textio.all;ieee.std_logic_textio.all;

read(line, variable)

hread(line, variable)

readline(file, line)

Page 12: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 12

File Input

● Require file and line variables:

CheckProcess: process (clkt) file output1 : text is “output.txt”; variable line_in: line; variable o_exp : std_logic;begin if clk'event and clk='0' then if not endfile(output1) then

readline(output1, line_in);read(line_in, o_exp);assert (o_exp = alu_result)report “Output incorrect”severity error;

end if; end if;end process;

ALU

operand1

operand2

alu_result

opcode

Page 13: CMPUT 329 - Computer Organization and Architecture II 1 CMPUT329 - Fall 2003 Topic 6: Testbenches Paras Mehta and José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II 13

Debug Output

● Lines can also be used to write to std_out:

CheckProcess: process(clk) variable line_out: line;begin if clk'event and clk = '1' then

write(line_out, string'(“At time ”));write(line_out, now);write(line_out, string'(“, output is ”));write(line_out, alu_result;writeline(output, line_out);

end if;end process;

ALU

operand1

operand2

alu_result

opcode