【问题标题】:VHDL testbench report errorVHDL测试台报告错误
【发布时间】:2014-03-17 21:59:47
【问题描述】:

在一个带有自检测试台的项目上工作,遇到一个我不明白的问题。

以下代码的问题是模拟中的错误。我将在代码中指出错误的来源:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

ENTITY TestBenchAutomated IS
-- Generics passed in
generic (m: integer := 3; n: integer := 5; h: integer := 4; DATA_SIZE: integer :=5);
END TestBenchAutomated;

ARCHITECTURE behavior OF TestBenchAutomated IS 

     -- Component Declaration for the Unit Under Test (UUT)
     COMPONENT TopLevelM_M
     generic (m: integer := 3; n: integer := 5; h: integer := 4; DATA_SIZE: integer :=5);
     PORT(
            clk : IN  std_logic;
            next_in : IN  std_logic; --User input
            rst_in : IN  std_logic;  --User input
            OUTPUT : OUT  SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0) --Calculated DATA output
          );
     END COMPONENT;


    --Inputs
    signal clk : std_logic := '0';
    signal next_in : std_logic := '0';
    signal rst_in : std_logic := '0';

    --Outputs
    signal OUTPUT : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0);

    -- Clock period definitions
    constant clk_period : time := 10 ns;

    --Variable to be used in assert section
     type Vector is record
            OUTPUT_test : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0);
     end record;

type VectorArray is array (natural range <>) of Vector;

constant Vectors : VectorArray := (
     -- Values to be compaired to calculated output
    (OUTPUT_test =>"000000110000"), -- 48
    (OUTPUT_test =>"000011110110"), -- 246
    (OUTPUT_test =>"000101001000"), -- 382 <--- Purposefully incorrect value, Should be '000100001000' = 264
    (OUTPUT_test =>"111111010011"), -- -45
    (OUTPUT_test =>"111101001100"), -- -180
    (OUTPUT_test =>"111111001111"), -- -49
    (OUTPUT_test =>"000000101011"), -- 43  Purposefully incorrect value, Should be '000010101011' = 171
    (OUTPUT_test =>"000000010011"), -- 19
    (OUTPUT_test =>"111111100101"), -- -27
    (OUTPUT_test =>"111110111011"), -- -69
    (OUTPUT_test =>"111110111011"), -- -69
    (OUTPUT_test =>"000000101101"), -- 45
    (OUTPUT_test =>"111011011110"), -- -290
    (OUTPUT_test =>"000001010110"), -- 86
    (OUTPUT_test =>"000011110010"), -- 242
    (OUTPUT_test =>"00000111110"),  -- 125
    (OUTPUT_test =>"111111001001"), -- -55
    (OUTPUT_test =>"000100010101"), -- 277
    (OUTPUT_test =>"111111100011"), -- -29
    (OUTPUT_test =>"111101111101"));-- -131 



BEGIN

    -- Instantiate the Unit Under Test (UUT)
    uut: TopLevelM_M PORT MAP (
             clk => clk,
             next_in => next_in,
             rst_in => rst_in,
             OUTPUT => OUTPUT
          );

    -- Clock process definitions
  clk_process :process
        begin
            clk <= '0';
            wait for clk_period/2;
            clk <= '1';
            wait for clk_period/2;
        end process;
    -- Process to simulate user input and to check output is correct
Test :process
    variable  i : integer;
        begin
            wait for 100 ns;
            rst_in <= '1';
            wait for clk_period*3;
            rst_in <= '0';

    --Loops through enough times to cover matrix and more to show it freezes in S_Wait state
    for i in 0 to 50 loop 

            for i in Vectors'range loop

                next_in <= '1';
                wait for clk_period*5;
                next_in <= '0';
                wait for clk_period*4; --Appropriate amount of clock cycles needed for calculations to be displayed at output
                --Check the output is the same as expected
                assert OUTPUT = Vectors(i).OUTPUT_test
                report "Incorrect Output on vector line" & integer'image(i) &
                lf & "Expected:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_test))) --& lf &
                --"But got" & integer'image(i)(to_integer(signed(OUTPUT)))
                severity error;

            end loop;
        end loop;

        wait;

    end process;
END;

正如您在向量中看到的,我插入了两个不正确的值以确保代码正常工作。我在那里期待模拟中的错误,告诉我向量的地址 2 上存在错误以及它是什么整数。但是,模拟停止了,我得到了这个:

错误:索引 328 超出界限 1 到 1。 错误:正在进行 TestBenchAutomated.vhd:Test

信息:模拟器已停止。

显然,由向量中的二进制数表示的整数 328 会导致此错误,但我不明白为什么它会导致此错误,而不是我编写的那个错误。什么是超出边界的索引?

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: indexing vhdl simulation


    【解决方案1】:

    这个:

    report "Incorrect Output on vector line" & integer'image(i) &
    lf & "Expected:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_test)))
    

    应该是:

    report "Incorrect Output on vector line" & integer'image(i) &
    lf & "Expected:" & integer'image(to_integer((Vectors(i).OUTPUT_test)))
    

    它抱怨(to_integer((Vectors(i).OUTPUT_test))) 的值超出了一个字符的范围,而它本应用作'IMAGE 的参数,而您已经提供了i

    对于简化的测试用例:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    
    entity foo is
        constant m: integer := 3; 
        constant n: integer := 5; 
        constant h: integer := 4; 
        constant DATA_SIZE: integer :=5;
    end entity;
    
    architecture fum of foo is
        signal OUTPUT : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0) := "000011110110" ;
    
         type Vector is record
                OUTPUT_test : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0);
         end record;
    
        type VectorArray is array (natural range <>) of Vector;
    
        constant Vectors : VectorArray := (
             -- Values to be compaired to calculated output
            (OUTPUT_test =>"000011110110"), -- 246  (CORRECT)
            (OUTPUT_test =>"000101001000")  -- 382  (INCORRECT)        
            );
    
    begin
    TEST:
        process 
        begin
            for i in Vectors'RANGE loop
                assert OUTPUT = Vectors(i).OUTPUT_test
                report "Incorrect Output on vector line " & integer'image(i) &
    --            lf & "Expected:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_test)))
                lf & "Expected:" & integer'image(to_integer((Vectors(i).OUTPUT_test)))
                severity error;
            end loop;
            wait;
        end process;
    
    end architecture;
    

    以及不正确的用法,Nick Gasson 的 nvc 给出:

    david_koontz@Macbook: nvc -a foo.vhdl
    ** 错误:属性 IMAGE 应有 2 个参数,但有 3 个
    文件 foo.vhdl,第 34 行 lf & "预期:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_t ...

                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
    

    使用正确数量的“图像”参数(如示例所示):

    david_koontz@Macbook: nvc -r foo
    ** 致命:0ms+0:断言错误:向量线 1 上的输出不正确
    预计:328
    进程 :foo:test
    文件 foo.vhdl,第 32 行

    发现了一个 ghdl 错误,但它可能没有报告这个问题。它以任何一种方式工作(这应该是一个运行时错误)。整数值 382 不是可以连接的字符。

    附录:

    Tristan Gingold(ghdl 作者)指出,表达式是'IMAGE 函数的字符串输出的元素索引。

    进一步分析揭示了问题原始代码中错误消息的依据:

     & integer'image(i)(to_integer((Vectors(i).OUTPUT_test)))
    

    T'IMAGE(X)
    种类:功能。 前缀:任何标量类型或子类型 T。
    参数:类型为 T 的基类型的表达式。
    结果类型:字符串类型。
    结果:参数值的字符串表示,没有
    前导或尾随空格。

    后面没有连接运算符。

    (to_integer( ( Vectors(i).OUTPUT ) ) ) 返回记录元素 OUTPUT 的整数值,类型有符号。 (多余的括号除外)。

    Vectors(i).OUTPUT 的内容是

    constant Vectors : VectorArray := (
        (OUTPUT_test =>"000011110110"), -- 246  (CORRECT)
        (OUTPUT_test =>"000101001000")  -- 382  (INCORRECT)        
        );
    

    382 应该是 328,它的 0x148。阅读障碍很难拼写。

    并且在这种情况下对于 i = 1 (Vectors'RANGE is (0 to 1), is “000101001000”,to_integer 为 328,超出字符串元素(元素类型字符)的范围。

    整数,值 328 与否不是记录的元素索引类型(而 OUTPUT 是)。

    'IMAGE 的未命名字符串输出的子类型是 i 的字符串长度,其值为 1,长度为 1,范围为 1 到 1。328 超出范围。

    请注意,ISIM 消息在原始模型中准确地说明了这一点:

    错误:索引 328 超出界限 1 到 1。错误:正在进行 TestBenchAutomated.vhd:Test

    这看起来仍然像一个 ghdl 错误。但是,它也确实使 nvc 的错误消息变得可疑。

    【讨论】:

    • 错误的行号有很长的路要走。不得不盯着它看了一会儿才能看到它。
    • Nick Gasson 已经修复了 nvc “** 致命:数组索引 328 超出 1 到 1 的界限” &LF& “文件 foo.vhdl,第 34 行”。 ghdl 会晚一点。
    猜你喜欢
    • 1970-01-01
    • 2013-06-19
    • 2011-03-03
    • 2023-04-07
    • 2015-08-05
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多