OpenCores
URL https://opencores.org/ocsvn/distributed_intelligence/distributed_intelligence/trunk

Subversion Repositories distributed_intelligence

[/] [distributed_intelligence/] [trunk/] [LIB/] [UnitTest.vhd] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 leoel
--      Package File Template
2
--
3
--      Purpose: This package defines supplemental types, subtypes, 
4
--               constants, and functions 
5
 
6
 
7
library IEEE;
8
use IEEE.STD_LOGIC_1164.all;
9
use IEEE.NUMERIC_STD.all;
10
 
11
package UnitTest is
12
 
13
-- Declare constants
14
 
15
-- Declare functions and procedure
16
 
17
        procedure assertEqual(current, expected: in integer; resultName: in string := "Result");
18
        procedure assertEqual(current, expected: in std_logic; resultName: in string := "Result");
19
        procedure assertEqual(current, expected: in std_logic_vector; resultName: in string := "Result");
20
        procedure assertOperationResult(        actual, expected : in integer; opName: in string:= "operation"; overflowCond: boolean := false; overflowBit: std_logic := '-');
21
        procedure assertOperationResult(        actual, expected : in std_logic_vector; opName: in string:= "operation"; overflowCond: boolean := false; overflowBit: std_logic := '-');
22
end UnitTest;
23
 
24
 
25
package body UnitTest is
26
 
27
                procedure assertEqual(current, expected: in integer; resultName: in string := "Result") is
28
                begin
29
                        assert current = expected
30
                                report resultName &" is incorrect. Expected: " & integer'image(expected) & " Current: " & integer'image(current)
31
                                severity ERROR;
32
                end procedure;
33
 
34
                procedure assertEqual(current, expected: in std_logic; resultName: in string := "Result") is
35
                begin
36
                        assert current = expected
37
                                report resultName &" is incorrect. Expected: " & std_logic'image(expected) & " Current: " & std_logic'image(current)
38
                                severity ERROR;
39
                end procedure;
40
 
41
                procedure assertEqual(current, expected: in std_logic_vector; resultName: in string := "Result") is
42
                begin
43
                        assertEqual(to_integer(unsigned(current)), to_integer(unsigned(expected)), resultName);
44
                end procedure;
45
 
46
 
47
                -- Automaticaly verifies that the result is correct, beeing given the boundaries of the calculator and that
48
                -- overflow bit is correctly set in both cases
49
                -- Arguments:
50
                --      actual, expected: Actual and expected results
51
                --              opName: Name of the operation
52
                --              overflowCond: Condition for an overflow, ignored by default
53
                --              overflowBit: Overflow bit set to 1 in case of overflow, no verification if set to '-' (default)
54
                procedure assertOperationResult(        actual, expected : in integer; opName: in string:= "operation";
55
                                                                                                        overflowCond: boolean := false; overflowBit: std_logic := '-') is
56
                begin
57
                        if overflowCond then
58
                                if overflowBit /= '-' then
59
                                        assertEqual(overflowBit, '1', "Overflow bit for " & opName & " with result " & integer'image(actual));
60
                                end if;
61
                        else
62
                                if overflowBit /= '-' then
63
                                        assertEqual(overflowBit, '0', "Overflow bit for " & opName & " with result " & integer'image(actual));
64
                                end if;
65
                                assertEqual(actual, expected , opName & " result");
66
                        end if;
67
                end procedure;
68
 
69
                procedure assertOperationResult(        actual, expected : in std_logic_vector; opName: in string:= "operation";
70
                                                                                                        overflowCond: boolean := false; overflowBit: std_logic := '-') is
71
                begin
72
                        assertOperationResult(to_integer(unsigned(actual)), to_integer(unsigned(expected)), opName, overflowCond, overflowBit);
73
                end procedure;
74
end UnitTest;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.