1 | /* |
---|
2 | * $Id: test.cpp 88 2008-12-10 18:31:39Z rosiere $ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | * Test |
---|
7 | */ |
---|
8 | |
---|
9 | #define NB_ITERATION 64 |
---|
10 | #define CYCLE_MAX (1024*NB_ITERATION) |
---|
11 | |
---|
12 | #include "Behavioural/Generic/Shifter/SelfTest/include/test.h" |
---|
13 | #include "Common/include/BitManipulation.h" |
---|
14 | #include "Common/include/Test.h" |
---|
15 | |
---|
16 | void test (string name, |
---|
17 | morpheo::behavioural::generic::shifter::Parameters param) |
---|
18 | { |
---|
19 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
20 | |
---|
21 | try |
---|
22 | { |
---|
23 | cout << param.print(1); |
---|
24 | param.test(); |
---|
25 | } |
---|
26 | catch (morpheo::ErrorMorpheo & error) |
---|
27 | { |
---|
28 | cout << "<" << name << "> : " << error.what (); |
---|
29 | return; |
---|
30 | } |
---|
31 | catch (...) |
---|
32 | { |
---|
33 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
34 | exit (EXIT_FAILURE); |
---|
35 | } |
---|
36 | |
---|
37 | #ifdef STATISTICS |
---|
38 | morpheo::behavioural::Parameters_Statistics * param_stat = new morpheo::behavioural::Parameters_Statistics(5,50); |
---|
39 | #endif |
---|
40 | |
---|
41 | Tusage_t _usage = USE_ALL; |
---|
42 | |
---|
43 | // _usage = usage_unset(_usage,USE_SYSTEMC ); |
---|
44 | // _usage = usage_unset(_usage,USE_VHDL ); |
---|
45 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH ); |
---|
46 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT); |
---|
47 | // _usage = usage_unset(_usage,USE_POSITION ); |
---|
48 | _usage = usage_unset(_usage,USE_STATISTICS ); |
---|
49 | // _usage = usage_unset(_usage,USE_INFORMATION ); |
---|
50 | |
---|
51 | Shifter * _Shifter = new Shifter (name.c_str(), |
---|
52 | #ifdef STATISTICS |
---|
53 | param_stat, |
---|
54 | #endif |
---|
55 | ¶m, |
---|
56 | _usage); |
---|
57 | |
---|
58 | #ifdef SYSTEMC |
---|
59 | /********************************************************************* |
---|
60 | * Déclarations des signaux |
---|
61 | *********************************************************************/ |
---|
62 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
63 | sc_signal <Tdirection_t> NRESET("nreset"); |
---|
64 | sc_signal <Tdata_t > SHIFTER_DATA_IN [param._nb_port]; |
---|
65 | sc_signal <Tshift_t > SHIFTER_SHIFT [param._nb_port]; |
---|
66 | sc_signal <Tdirection_t> SHIFTER_DIRECTION [param._nb_port]; |
---|
67 | sc_signal <morpheo::behavioural::generic::shifter::Ttype_t > SHIFTER_TYPE [param._nb_port]; |
---|
68 | sc_signal <Tcarry_t > SHIFTER_CARRY [param._nb_port]; |
---|
69 | sc_signal <Tcontrol_t > SHIFTER_CARRY_IN [param._nb_port]; |
---|
70 | sc_signal <Tdata_t > SHIFTER_COMPLETION[param._nb_port]; |
---|
71 | sc_signal <Tdata_t > SHIFTER_DATA_OUT [param._nb_port]; |
---|
72 | |
---|
73 | /******************************************************** |
---|
74 | * Instanciation |
---|
75 | ********************************************************/ |
---|
76 | |
---|
77 | cout << "<" << name << "> Instanciation of _Shifter" << endl; |
---|
78 | |
---|
79 | #if (defined(STATISTICS) || defined (VHDL_TESTBENCH)) |
---|
80 | (*(_Shifter->in_CLOCK)) (CLOCK); |
---|
81 | (*(_Shifter->in_NRESET)) (NRESET); |
---|
82 | #endif |
---|
83 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
84 | { |
---|
85 | (*(_Shifter-> in_SHIFTER_DATA [i])) (SHIFTER_DATA_IN [i]); |
---|
86 | if (param._shift_value == 0) |
---|
87 | (*(_Shifter-> in_SHIFTER_SHIFT [i])) (SHIFTER_SHIFT [i]); |
---|
88 | if (param._direction == external_direction) |
---|
89 | (*(_Shifter-> in_SHIFTER_DIRECTION [i])) (SHIFTER_DIRECTION [i]); |
---|
90 | if (param._rotate == external_rotate) |
---|
91 | (*(_Shifter-> in_SHIFTER_TYPE [i])) (SHIFTER_TYPE [i]); |
---|
92 | if (param._carry == external_carry) |
---|
93 | (*(_Shifter-> in_SHIFTER_CARRY [i])) (SHIFTER_CARRY [i]); |
---|
94 | if (param._carry == external_completion) |
---|
95 | if (param._type_completion_bool == true) |
---|
96 | (*(_Shifter-> in_SHIFTER_CARRY_IN [i])) (SHIFTER_CARRY_IN [i]); |
---|
97 | else |
---|
98 | (*(_Shifter-> in_SHIFTER_COMPLETION[i])) (SHIFTER_COMPLETION[i]); |
---|
99 | (*(_Shifter->out_SHIFTER_DATA [i])) (SHIFTER_DATA_OUT [i]); |
---|
100 | } |
---|
101 | |
---|
102 | /******************************************************** |
---|
103 | * Simulation - Begin |
---|
104 | ********************************************************/ |
---|
105 | |
---|
106 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
107 | // Initialisation |
---|
108 | |
---|
109 | srand (0); |
---|
110 | //srand (time(NULL)); |
---|
111 | |
---|
112 | const uint32_t iteration = NB_ITERATION; |
---|
113 | |
---|
114 | Tdirection_t direction ; |
---|
115 | morpheo::behavioural::generic::shifter::Ttype_t type ; |
---|
116 | Tcarry_t carry ; |
---|
117 | const Tdata_t data_max = (1<<param._size_data); |
---|
118 | Tdata_t data_in [param._nb_port]; |
---|
119 | Tdata_t data_completion [param._nb_port]; |
---|
120 | Tshift_t shift_min ; |
---|
121 | Tshift_t shift_max ; |
---|
122 | Tdata_t data_out [param._nb_port]; |
---|
123 | string op ; |
---|
124 | |
---|
125 | if (param._shift_value != 0) |
---|
126 | { |
---|
127 | shift_min = param._shift_value; |
---|
128 | shift_max = param._shift_value; |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | shift_min = 0; |
---|
133 | shift_max = param._size_data-1; |
---|
134 | } |
---|
135 | |
---|
136 | sc_start(0); |
---|
137 | |
---|
138 | NRESET.write(1); |
---|
139 | |
---|
140 | for (uint32_t x=0; x<6; x++) |
---|
141 | { |
---|
142 | switch (x) |
---|
143 | { |
---|
144 | case 0 : |
---|
145 | if (param._have_shift_logic_left) |
---|
146 | { |
---|
147 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Left Logic" << endl; |
---|
148 | direction = _left ; |
---|
149 | type = _shift; |
---|
150 | carry = _logic; |
---|
151 | op = " sll " ; |
---|
152 | break; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Left Logic" << endl; |
---|
157 | continue; |
---|
158 | } |
---|
159 | case 1 : |
---|
160 | if (param._have_shift_logic_right) |
---|
161 | { |
---|
162 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Right Logic" << endl; |
---|
163 | direction = _right; |
---|
164 | type = _shift; |
---|
165 | carry = _logic; |
---|
166 | op = " srl " ; |
---|
167 | break; |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Right Logic" << endl; |
---|
172 | continue; |
---|
173 | } |
---|
174 | case 2 : |
---|
175 | if (param._have_shift_arithmetic_left) |
---|
176 | { |
---|
177 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Left Arithmetic" << endl; |
---|
178 | direction = _left ; |
---|
179 | type = _shift ; |
---|
180 | carry = _arithmetic; |
---|
181 | op = " sla " ; |
---|
182 | break; |
---|
183 | } |
---|
184 | else |
---|
185 | { |
---|
186 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Left Arithmetic" << endl; |
---|
187 | continue; |
---|
188 | } |
---|
189 | case 3 : |
---|
190 | if (param._have_shift_arithmetic_right) |
---|
191 | { |
---|
192 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Right Arithmetic" << endl; |
---|
193 | direction = _right; |
---|
194 | type = _shift; |
---|
195 | carry = _arithmetic; |
---|
196 | op = " sra " ; |
---|
197 | break; |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Right Arithmetic" << endl; |
---|
202 | continue; |
---|
203 | } |
---|
204 | case 4 : |
---|
205 | if ( param._have_rotate_left) |
---|
206 | { |
---|
207 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Rotate Left" << endl; |
---|
208 | direction = _left ; |
---|
209 | type = _rotate; |
---|
210 | carry = _logic ; |
---|
211 | op = " rol "; |
---|
212 | break; |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate Left" << endl; |
---|
217 | continue; |
---|
218 | } |
---|
219 | case 5 : |
---|
220 | if (param._have_rotate_right) |
---|
221 | { |
---|
222 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Rotate Right" << endl; |
---|
223 | direction = _right; |
---|
224 | type = _rotate; |
---|
225 | carry = _logic ; |
---|
226 | op = " ror "; |
---|
227 | break; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate Right" << endl; |
---|
232 | continue; |
---|
233 | } |
---|
234 | default : |
---|
235 | continue; |
---|
236 | } |
---|
237 | |
---|
238 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
239 | { |
---|
240 | SHIFTER_DIRECTION [i].write(direction ); |
---|
241 | SHIFTER_TYPE [i].write(type ); |
---|
242 | SHIFTER_CARRY [i].write(carry ); |
---|
243 | } |
---|
244 | |
---|
245 | for (uint32_t it=0; it < iteration; it++) |
---|
246 | { |
---|
247 | for (Tshift_t shift=shift_min; shift<=shift_max; shift++) |
---|
248 | { |
---|
249 | Tdata_t mask_left = 0; |
---|
250 | Tdata_t mask_right = 0; |
---|
251 | |
---|
252 | if (param._size_data_completion > 0) |
---|
253 | { |
---|
254 | mask_left = gen_mask<Tdata_t> (shift); |
---|
255 | mask_right = mask_left << (param._size_data - shift); |
---|
256 | } |
---|
257 | |
---|
258 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
259 | { |
---|
260 | data_in [i] = rand() % data_max; |
---|
261 | data_completion [i] = (rand() % data_max) & gen_mask<Tdata_t>(param._size_data_completion); |
---|
262 | |
---|
263 | switch (x) |
---|
264 | { |
---|
265 | case 0 : data_out [i] =((shift_logic_left <Tdata_t>(param._size_data, data_in[i], shift) & ~mask_left ) | (data_completion [i] & mask_left )); break; |
---|
266 | case 1 : data_out [i] =((shift_logic_right <Tdata_t>(param._size_data, data_in[i], shift) & ~mask_right) | (data_completion [i] & mask_right)); break; |
---|
267 | case 2 : data_out [i] = shift_arithmetic_left <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
268 | case 3 : data_out [i] = shift_arithmetic_right <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
269 | case 4 : data_out [i] = rotate_left <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
270 | case 5 : data_out [i] = rotate_right <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
271 | default : break; |
---|
272 | } |
---|
273 | SHIFTER_DATA_IN [i].write(data_in [i]); |
---|
274 | SHIFTER_SHIFT [i].write(shift ); |
---|
275 | if (param._type_completion_bool == true) |
---|
276 | SHIFTER_CARRY_IN [i].write(data_completion [i]!=0); |
---|
277 | else |
---|
278 | SHIFTER_COMPLETION[i].write(data_completion [i]); |
---|
279 | } |
---|
280 | |
---|
281 | sc_start(0); |
---|
282 | |
---|
283 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "}" << endl; |
---|
284 | |
---|
285 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
286 | { |
---|
287 | cout << "\t[" << i << "] " |
---|
288 | << hex |
---|
289 | << data_in[i] << op |
---|
290 | << std::dec |
---|
291 | << shift << " = " |
---|
292 | << std::hex |
---|
293 | << SHIFTER_DATA_OUT [i].read() |
---|
294 | << " - completion : " |
---|
295 | << data_completion [i] |
---|
296 | << std::dec ; |
---|
297 | |
---|
298 | TEST(Tdata_t,SHIFTER_DATA_OUT [i].read(),data_out[i]); |
---|
299 | } |
---|
300 | sc_start(1); |
---|
301 | } |
---|
302 | } |
---|
303 | } |
---|
304 | |
---|
305 | sc_start(0); |
---|
306 | |
---|
307 | |
---|
308 | /******************************************************** |
---|
309 | * Simulation - End |
---|
310 | ********************************************************/ |
---|
311 | |
---|
312 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
313 | |
---|
314 | #endif |
---|
315 | |
---|
316 | delete _Shifter; |
---|
317 | |
---|
318 | #ifdef STATISTICS |
---|
319 | delete param_stat; |
---|
320 | #endif |
---|
321 | } |
---|