diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-08 15:09:38 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-08 22:02:28 -0600 |
commit | f8d09347a43ddab462d94f716e0a6f249e2e6635 (patch) | |
tree | ce5d447fd0fd88d691b8a22a0b448e20e1bce508 /alu_tb.v | |
parent | 2a67798b81aa3e43e7f3c474acd3b470d942d227 (diff) |
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).
Diffstat (limited to 'alu_tb.v')
-rw-r--r-- | alu_tb.v | 74 |
1 files changed, 28 insertions, 46 deletions
@@ -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 |