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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testAlu.vhd] - Blame information for rev 12

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

Line No. Rev Author Line
1 9 leonardoar
--! @file
2
--! @brief Testbench for Alu
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5
library IEEE;
6
use ieee.std_logic_1164.all;
7
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9
 
10
--! Use CPU Definitions package
11
use work.pkgOpenCPU32.all;
12
 
13
ENTITY testAlu IS
14
END testAlu;
15
 
16
--! @brief Alu Testbench file
17
--! @details Exercise each Alu operation to verify if the description work as planned 
18
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
19
ARCHITECTURE behavior OF testAlu IS
20
 
21
 
22
         --! Component declaration to instantiate the Alu circuit
23
    COMPONENT Alu
24
    generic (n : integer := nBits - 1);                                 --! Generic value (Used to easily change the size of the Alu on the package)
25
         Port ( A : in  STD_LOGIC_VECTOR (n downto 0);           --! Alu Operand 1
26
           B : in  STD_LOGIC_VECTOR (n downto 0);                --! Alu Operand 2
27
           S : out  STD_LOGIC_VECTOR (n downto 0);               --! Alu Output
28
           sel : in  aluOps);                                                                   --! Select operation
29
    END COMPONENT;
30
 
31
 
32
   --Inputs
33 12 leonardoar
   signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0');  --! Wire to connect Test signal to component
34
   signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0');  --! Wire to connect Test signal to component
35
   signal sel : aluOps := alu_sum;                                                                                                              --! Wire to connect Test signal to component
36 9 leonardoar
 
37
        --Outputs
38 12 leonardoar
   signal S : std_logic_vector((nBits - 1) downto 0);                                                            --! Wire to connect Test signal to component
39 9 leonardoar
 
40
BEGIN
41
 
42 12 leonardoar
        --! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
43 9 leonardoar
   uut: Alu PORT MAP (
44
          A => A,
45
          B => B,
46
          S => S,
47
          sel => sel
48
        );
49
 
50
   --! Process that will stimulate all of the Alu operations
51
   stim_proc: process
52
   begin
53
      -- AND ---------------------------------------------------------------------------
54
                wait for 1 ps;
55
                REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
56
                sel <= alu_and;
57
                A <= conv_std_logic_vector(2, nBits);
58
                B <= conv_std_logic_vector(3, nBits);
59
                wait for 1 ns;  -- Wait to stabilize the response
60
                assert S = (A and B) report "Invalid AND output" severity FAILURE;
61
 
62
                -- OR ---------------------------------------------------------------------------
63
                wait for 1 ns;
64
                REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
65
                sel <= alu_or;
66
                A <= conv_std_logic_vector(5, nBits);
67
                B <= conv_std_logic_vector(7, nBits);
68
                wait for 1 ns;  -- Wait to stabilize the response
69
                assert S = (A or B) report "Invalid OR output" severity FAILURE;
70
 
71
                -- XOR ---------------------------------------------------------------------------
72
                wait for 1 ns;
73
                REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
74
                sel <= alu_xor;
75
                A <= conv_std_logic_vector(11, nBits);
76
                B <= conv_std_logic_vector(9, nBits);
77
                wait for 1 ns;  -- Wait to stabilize the response
78
                assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
79
 
80
                -- NOT ---------------------------------------------------------------------------
81
                wait for 1 ns;
82
                REPORT "NOT 10" SEVERITY NOTE;
83
                sel <= alu_not;
84
                A <= conv_std_logic_vector(10, nBits);
85
                B <= (others => 'X');
86
                wait for 1 ns;  -- Wait to stabilize the response
87
                assert S = (not A) report "Invalid NOT output" severity FAILURE;
88
 
89
      wait;
90
   end process;
91
 
92
END;

powered by: WebSVN 2.1.0

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