在一个有自我检查测试平台的项目上工作,有一个我不明白的问题。
以下代码的问题是仿真中的一个错误。我将指出代码中的错误来自何处:
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会导致这个错误,但我不明白为什么它会导致这个错误,而不是我编码的那个错误。这个指数超出界限是什么?
任何帮助都将不胜感激。
谢谢
发布于 2014-03-17 23:08:05
这是:
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;尼克·加森的nvc给出了错误的用法:
david_koontz@Macbook: nvc -a foo.vhdl **错误:属性图像的预期2个参数,但有3个 文件foo.vhdl,第34行lf &“预期:”& ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .
使用“图像”的正确参数数(如示例所示):
david_koontz@Macbook: nvc -r foo **致命: 0ms+0:断言错误:向量行1的输出不正确 预期:328 过程:foo:测试 文件foo.vhdl,第32行
发现了一个ghdl错误,当它可能应该报告的时候,它没有报告这个错误。它以任何方式工作(这应该是一个运行时错误)。整数值382不是一个符合级联条件的字符。
增编:
Tristan (ghdl作者)指出,表达式是'IMAGE函数字符串输出的元素索引。
进一步的分析揭示了问题原始代码中错误信息的基础:
& integer'image(i)(to_integer((Vectors(i).OUTPUT_test)))T‘象(X) 功能。前缀:任何标量类型或子类型T。 参数:其类型为T的基类型的表达式。 结果类型:类型字符串。 结果:参数值的字符串表示形式,没有 引导或尾随空格。
以下没有级联操作符。
(to_integer( ( Vectors(i).OUTPUT )))返回记录元素输出的整数值,输入已签名。(多余的括号除外)。
向量的内容(I).OUTPUT是
constant Vectors : VectorArray := (
(OUTPUT_test =>"000011110110"), -- 246 (CORRECT)
(OUTPUT_test =>"000101001000") -- 382 (INCORRECT)
);382应该是328,它的0x148。诵读困难很难拼写。
在这种情况下,i=1(向量的range是(0到1) ),是"000101001000“,to_integer是328,超出了字符串元素(元素类型字符)的范围。
整数值328或not不是记录的元素索引类型(而输出是)。
“映像”的未命名字符串输出的子类型是i的字符串长度,其值为1,长度为1,范围为1到1.328超出范围。
请注意,ISIM消息中准确地指出,在原始模型中:
错误:索引328超出绑定1到1。错误:进程TestBenchAutomated.vhd:Test
这看起来仍然是个ghdl错误。然而,它也使nvc的错误信息受到怀疑。
https://stackoverflow.com/questions/22466369
复制相似问题