From f8d09347a43ddab462d94f716e0a6f249e2e6635 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sun, 8 Jan 2017 15:09:38 -0600 Subject: Move ALU test cases to external testcase file This makes is a little easier to create new ALU testcases and to quickly read and understand the existing testcases. Additionally, the test bench itself can now report when a test fails, rather than requiring inspection on the waveform (though the waveform is still available). --- alu_tb.v | 74 ++++++++++++++++++++++++---------------------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) (limited to 'alu_tb.v') diff --git a/alu_tb.v b/alu_tb.v index 6afafbc..8342e6c 100644 --- a/alu_tb.v +++ b/alu_tb.v @@ -1,3 +1,4 @@ +`include "testbench.vh" `timescale 1 ns / 100 ps module alu_tb (); @@ -11,58 +12,39 @@ module alu_tb (); wire carry; reg expected_carry; + reg [3*8:0] opstr; + integer file, r; + initial begin $dumpfile("alu_tb.vcd"); $dumpvars(0, alu_tb); - x = 16'h0123; - y = 16'h1234; - - op = 4'h0; // add - expected_result = 16'h1357; - expected_zero = 1'b0; - expected_carry = 1'b0; - - #2 - op = 4'h1; // subtract - expected_result = 16'hEEEF; - expected_carry = 1'b1; - expected_zero = 1'b0; - - #2 - y = 16'h0123; - expected_result = 16'h0; - expected_zero = 1'b1; - expected_carry = 1'b0; - - #2 - y = 16'h1234; - op = 4'h2; // multiply - expected_result = 16'hB11C; - expected_zero = 1'b0; - expected_carry = 1'b0; + file = $fopenr("tests/alu"); + + skip_comments(file); + while (!$feof(file)) begin + r = $fscanf(file, " 0x%x %3s 0x%x = 0x%x Z=%x C=%x\n", x, opstr, y, expected_result, expected_zero, expected_carry); + + case (opstr) + "+" : op = 0; + "-" : op = 1; + "*" : op = 2; + "/" : op = 3; + "&" : op = 4; + "|" : op = 5; + "^" : op = 6; + default : op = 0; + endcase + + #2 + if (result != expected_result || zero != expected_zero || carry != expected_carry) begin + $display("TEST FAILED: 0x%04x %3s 0x%04x = 0x%04x Z=%x C=%x (expected 0x%04x Z=%x C=%x)", x, opstr, y, result, zero, carry, expected_result, expected_zero, expected_carry); + end + skip_comments(file); + end #2 - x = 16'h3E58; - y = 16'h0078; - op = 4'h3; // divide - expected_result = 16'h0085; - - #2 - x = 16'hAF74; - y = 16'h7CC7; - op = 4'h4; // and - expected_result = 16'h2C44; - - #2 - op = 4'h5; // or - expected_result = 16'hFFF7; - - #2 - op = 4'h6; // xor - expected_result = 16'hD3B3; - - #5 + $fclose(file); $finish; end -- cgit v1.2.3