forked from VUnit/vunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use integer_array_t instead of array_t
- Loading branch information
1138-4EB
committed
Nov 26, 2019
1 parent
b13044a
commit 9020d6e
Showing
4 changed files
with
86 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
|
||
vu = VUnit.from_argv() | ||
vu.add_osvvm() | ||
vu.add_array_util() | ||
|
||
src_path = join(dirname(__file__), "src") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,78 +10,92 @@ use ieee.numeric_std.all; | |
|
||
library vunit_lib; | ||
context vunit_lib.vunit_context; | ||
use vunit_lib.array_pkg.all; | ||
|
||
|
||
library osvvm; | ||
use osvvm.RandomPkg.all; | ||
use osvvm.RandomPkg.RandomPType; | ||
|
||
entity tb_sobel_x is | ||
generic ( | ||
runner_cfg : string; | ||
tb_path : string); | ||
tb_path : string | ||
); | ||
end entity; | ||
|
||
architecture tb of tb_sobel_x is | ||
signal clk : std_logic := '0'; | ||
signal input_tvalid : std_logic := '0'; | ||
signal input_tlast : std_logic := '0'; | ||
signal input_tdata : unsigned(14-1 downto 0) := (others => '0'); | ||
|
||
signal clk : std_logic := '0'; | ||
signal input_tvalid : std_logic := '0'; | ||
signal input_tlast : std_logic := '0'; | ||
signal input_tdata : unsigned(13 downto 0) := (others => '0'); | ||
signal output_tvalid : std_logic; | ||
signal output_tlast : std_logic; | ||
signal output_tdata : signed(input_tdata'length downto 0); | ||
signal output_tlast : std_logic; | ||
signal output_tdata : signed(input_tdata'length downto 0); | ||
|
||
shared variable image : array_t; | ||
shared variable reference_image : array_t; | ||
signal image, reference_image : integer_array_t; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eine
Owner
|
||
signal start, data_check_done, stimuli_done : boolean := false; | ||
|
||
begin | ||
|
||
main : process | ||
procedure sobel_x(variable image : inout array_t; | ||
variable result : inout array_t) is | ||
begin | ||
result.init_2d(width => image.width, | ||
height => image.height, | ||
bit_width => image.bit_width+1, | ||
is_signed => true); | ||
procedure sobel_x( | ||
signal image : inout integer_array_t; | ||
signal result : inout integer_array_t | ||
) is begin | ||
result <= new_2d( | ||
width => image.width, | ||
height => image.height, | ||
bit_width => image.bit_width+1, | ||
is_signed => true | ||
); | ||
|
||
for y in 0 to image.height-1 loop | ||
for x in 0 to image.width-1 loop | ||
result.set(x => x, y => y, | ||
value => (image.get(minimum(x+1, image.width-1),y) - | ||
image.get(maximum(x-1, 0), y))); | ||
set( | ||
result, | ||
x => x, | ||
y => y, | ||
value => ( | ||
get(image, minimum(x+1, image.width-1),y) | ||
- get(image, maximum(x-1, 0), y) | ||
) | ||
); | ||
end loop; | ||
end loop; | ||
|
||
end procedure; | ||
|
||
variable rnd : RandomPType; | ||
|
||
procedure randomize(variable arr : inout array_t) is | ||
begin | ||
for idx in 0 to arr.length-1 loop | ||
arr.set(idx, value => rnd.RandInt(arr.lower_limit, arr.upper_limit)); | ||
end loop; | ||
end procedure; | ||
|
||
procedure run_test is | ||
begin | ||
wait until rising_edge(clk); | ||
start <= true; | ||
wait until rising_edge(clk); | ||
start <= false; | ||
|
||
wait until (stimuli_done and | ||
data_check_done and | ||
rising_edge(clk)); | ||
wait until ( | ||
stimuli_done and | ||
data_check_done and | ||
rising_edge(clk) | ||
); | ||
end procedure; | ||
|
||
procedure test_random_image(width, height : natural) is | ||
begin | ||
image.init_2d(width => width, height => height, | ||
bit_width => input_tdata'length, | ||
is_signed => false); | ||
randomize(image); | ||
image <= new_2d( | ||
width => width, height => height, | ||
bit_width => input_tdata'length, | ||
is_signed => false | ||
); | ||
|
||
for idx in 0 to image.length-1 loop | ||
set( | ||
image, | ||
idx, | ||
value => rnd.RandInt(image.lower_limit, image.upper_limit) | ||
); | ||
end loop; | ||
|
||
sobel_x(image, result => reference_image); | ||
run_test; | ||
end procedure; | ||
|
@@ -96,8 +110,8 @@ begin | |
test_random_image(16, 1); | ||
test_random_image(1, 1); | ||
elsif run("test_input_file_against_output_file") then | ||
image.load_csv(tb_path & "input.csv"); | ||
reference_image.load_csv(tb_path & "output.csv"); | ||
image <= load_csv(tb_path & "input.csv"); | ||
reference_image <= load_csv(tb_path & "output.csv"); | ||
run_test; | ||
end if; | ||
end loop; | ||
|
@@ -110,9 +124,11 @@ begin | |
wait until start and rising_edge(clk); | ||
stimuli_done <= false; | ||
|
||
report ("Sending image of size " & | ||
to_string(image.width) & "x" & | ||
to_string(image.height)); | ||
report ( | ||
"Sending image of size " & | ||
to_string(image.width) & "x" & | ||
to_string(image.height) | ||
); | ||
|
||
for y in 0 to image.height-1 loop | ||
for x in 0 to image.width-1 loop | ||
|
@@ -123,7 +139,7 @@ begin | |
else | ||
input_tlast <= '0'; | ||
end if; | ||
input_tdata <= to_unsigned(image.get(x,y), input_tdata'length); | ||
input_tdata <= to_unsigned(get(image, x, y), input_tdata'length); | ||
end loop; | ||
end loop; | ||
|
||
|
@@ -141,28 +157,32 @@ begin | |
for x in 0 to reference_image.width-1 loop | ||
wait until output_tvalid = '1' and rising_edge(clk); | ||
check_equal(output_tlast, x = reference_image.width-1); | ||
check_equal(output_tdata, reference_image.get(x, y), | ||
check_equal(output_tdata, get(reference_image, x, y), | ||
"x=" & to_string(x) & " y=" & to_string(y)); | ||
end loop; | ||
end loop; | ||
report ("Done checking image of size " & | ||
to_string(reference_image.width) & "x" & | ||
to_string(reference_image.height)); | ||
report ( | ||
"Done checking image of size " & | ||
to_string(reference_image.width) & "x" & | ||
to_string(reference_image.height) | ||
); | ||
data_check_done <= true; | ||
end process; | ||
|
||
clk <= not clk after 1 ns; | ||
|
||
dut : entity work.sobel_x | ||
generic map ( | ||
data_width => input_tdata'length) | ||
data_width => input_tdata'length | ||
) | ||
port map ( | ||
clk => clk, | ||
input_tvalid => input_tvalid, | ||
input_tlast => input_tlast, | ||
input_tdata => input_tdata, | ||
output_tvalid => output_tvalid, | ||
output_tlast => output_tlast, | ||
output_tdata => output_tdata); | ||
output_tdata => output_tdata | ||
); | ||
|
||
end architecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can just use a shared variable. It works in all simulators even if is not part of the VHDL-standard