-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsm_tb.vhd.bak
More file actions
146 lines (125 loc) · 5.08 KB
/
fsm_tb.vhd.bak
File metadata and controls
146 lines (125 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
LIBRARY ieee;
USE ieee.STD_LOGIC_1164.all;
ENTITY fsm_tb IS
END fsm_tb;
ARCHITECTURE behaviour OF fsm_tb IS
COMPONENT comments_fsm IS
PORT (clk : in std_logic;
reset : in std_logic;
input : in std_logic_vector(7 downto 0);
output : out std_logic
);
END COMPONENT;
--The input signals with their initial values
SIGNAL clk, s_reset, s_output: STD_LOGIC := '0';
SIGNAL s_input: std_logic_vector(7 downto 0) := (others => '0');
CONSTANT clk_period : time := 1 ns;
-- The ASCII value for the '/', '*' and end-of-line characters
CONSTANT SLASH_CHARACTER : std_logic_vector(7 downto 0) := "00101111";
CONSTANT STAR_CHARACTER : std_logic_vector(7 downto 0) := "00101010";
CONSTANT NEW_LINE_CHARACTER : std_logic_vector(7 downto 0) := "00001010";
-- Two random ASCII values that are not slash/star/new_line
CONSTANT test_char1 : std_logic_vector(7 downto 0) := "00111011";
CONSTANT test_char2 : std_logic_vector(7 downto 0) := "01011101";
-- input array of size 10 to allow for test vectors
type input_array is array (9 downto 0) of std_logic_vector(7 downto 0);
-- test case that is no comment that does not include any slash or star
signal test_case_nocomment : input_array := (test_char1,test_char1,test_char1,test_char1,
test_char1,test_char2,test_char2,test_char2,test_char2,test_char2);
-- test case that is no comment with a slash inside
signal test_case_nocomment_slash : input_array := (test_char1,SLASH_CHARACTER,test_char1,test_char1,
test_char1,test_char2,test_char2,test_char2,test_char2,test_char2);
-- test case that contains a single line comment
signal test_case_doubleslash : input_array := (test_char2,test_char2,SLASH_CHARACTER,SLASH_CHARACTER,
test_char1,SLASH_CHARACTER,SLASH_CHARACTER,NEW_LINE_CHARACTER,test_char2,test_char2);
-- test case that contains a block comment
signal test_case_slashstar : input_array := (test_char2,test_char2,SLASH_CHARACTER,STAR_CHARACTER,
NEW_LINE_CHARACTER,SLASH_CHARACTER,SLASH_CHARACTER,STAR_CHARACTER,SLASH_CHARACTER,test_char2);
BEGIN
dut: comments_fsm
PORT MAP(clk, s_reset, s_input, s_output);
--clock process
clk_process : PROCESS
BEGIN
clk <= '0';
WAIT FOR clk_period/2;
clk <= '1';
WAIT FOR clk_period/2;
END PROCESS;
stim_process: PROCESS
BEGIN
-- test case for double slash comment test case
REPORT "begin test case with double slash comment";
for i in 9 downto 6 loop
s_input <= test_case_doubleslash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment, and input backslash should be output = '0'" SEVERITY ERROR;
end loop;
for i in 5 downto 2 loop
s_input <= test_case_doubleslash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '1') REPORT "comment section should be output = '1'" SEVERITY ERROR;
end loop;
for i in 1 downto 0 loop
s_input <= test_case_doubleslash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment should be output = '0'" SEVERITY ERROR;
end loop;
-- perform reset to verify
s_reset <= '1';
WAIT FOR 1 * clk_period;
s_reset <= '0';
WAIT FOR 1 * clk_period;
ASSERT (s_output = '0') REPORT "reset unsuccessful" SEVERITY ERROR;
-- test block case but reset mid comment to verify reset works
REPORT "begin test case with double slash comment (to test reset mid comment)";
for i in 9 downto 6 loop
s_input <= test_case_doubleslash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "error: no comment, and input backslashcstar should be output = '0'" SEVERITY ERROR;
end loop;
for i in 5 downto 3 loop
s_input <= test_case_doubleslash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '1') REPORT "error: comment section should be output = '1'" SEVERITY ERROR;
end loop;
-- enable reset mid comment to verify it works
s_reset <= '1';
WAIT FOR 1 * clk_period;
s_reset <= '0';
WAIT FOR 1 * clk_period;
ASSERT (s_output = '0') REPORT "reset unsuccessful" SEVERITY ERROR;
--test case for block comment to verify FSM
REPORT "begin test case with block comment";
for i in 9 downto 6 loop
s_input <= test_case_slashstar(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment, and input backslash should be output = '0'" SEVERITY ERROR;
end loop;
for i in 5 downto 1 loop
s_input <= test_case_slashstar(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '1') REPORT "comment section should be output = '1'" SEVERITY ERROR;
end loop;
s_input <= test_case_slashstar(0);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment should be output = '0'" SEVERITY ERROR;
s_reset <= '1';
WAIT FOR 1 * clk_period;
s_reset <= '0';
WAIT FOR 1 * clk_period;
ASSERT (s_output = '0') REPORT "reset unsuccessful" SEVERITY ERROR;
REPORT "begin test case with NO COMMENTS";
for i in 9 downto 0 loop
s_input <= test_case_nocomment_slash(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment, and input backslash should be output = '0'" SEVERITY ERROR;
end loop;
for i in 9 downto 0 loop
s_input <= test_case_nocomment(i);
WAIT FOR 1 * clk_period;
ASSERT(s_output = '0') REPORT "no comment, and input backslash should be output = '0'" SEVERITY ERROR;
end loop;
WAIT;
END PROCESS stim_process;
END;