source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Shifter/SelfTest/src/test.cpp @ 113

Last change on this file since 113 was 113, checked in by rosiere, 15 years ago

1) Add modelsim simulation systemC
2) Modelsim cosimulation systemC / VHDL is not finish !!!! (cf execute_queue and write_unit)
3) Add multi architecture
5) Add template for comparator, multiplier and divider
6) Change Message
Warning) Various test macro have change, many selftest can't compile

  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
1/*
2 * $Id: test.cpp 113 2009-04-14 18:39:12Z 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
16void 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                                    &param,
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  Time * _time = new Time();
103
104  /********************************************************
105   * Simulation - Begin
106   ********************************************************/
107
108  cout << "<" << name << "> Start Simulation ............" << endl;
109  // Initialisation
110
111  srand (0);
112  //srand (time(NULL));
113 
114  const uint32_t iteration        = NB_ITERATION;
115
116  Tdirection_t   direction       ;
117  morpheo::behavioural::generic::shifter::Ttype_t        type            ;
118  Tcarry_t       carry           ; 
119  const Tdata_t  data_max        = (1<<param._size_data);
120  Tdata_t        data_in         [param._nb_port];
121  Tdata_t        data_completion [param._nb_port];
122  Tshift_t       shift_min       ;
123  Tshift_t       shift_max       ;
124  Tdata_t        data_out        [param._nb_port];
125  string         op              ;
126
127  if (param._shift_value != 0)
128    {
129      shift_min = param._shift_value;
130      shift_max = param._shift_value;
131    }
132  else
133    {
134      shift_min = 0;
135      shift_max = param._size_data-1;
136    }
137
138  sc_start(0);
139
140  NRESET.write(1);
141 
142  for (uint32_t x=0; x<6; x++)
143    {
144      switch (x)
145        {
146        case 0 :
147          if (param._have_shift_logic_left)
148            {
149              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Shift   Left  Logic" << endl;
150              direction = _left ;
151              type      = _shift;
152              carry     = _logic;
153              op        = " sll " ;     
154              break;
155            }
156          else
157            {
158              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Shift   Left  Logic" << endl;
159              continue;
160            }
161        case 1 :
162          if (param._have_shift_logic_right)
163            {
164              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Shift   Right Logic" << endl;
165              direction = _right;
166              type      = _shift;
167              carry     = _logic;
168              op        = " srl " ;
169              break;
170            }
171          else
172            {
173              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Shift   Right Logic" << endl;
174              continue;
175            }
176        case 2 :
177          if (param._have_shift_arithmetic_left)
178            {
179              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Shift   Left  Arithmetic" << endl;
180              direction = _left      ;
181              type      = _shift     ;
182              carry     = _arithmetic;
183              op        = " sla "    ;
184              break;
185            }
186          else
187            {
188              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Shift   Left  Arithmetic" << endl;
189              continue;
190            }
191        case 3 :
192          if (param._have_shift_arithmetic_right)
193            {
194              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Shift   Right Arithmetic" << endl;
195              direction = _right;
196              type      = _shift;
197              carry     = _arithmetic;
198              op        = " sra "    ;
199              break;
200            }
201          else
202            {
203              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Shift   Right Arithmetic" << endl;
204              continue;
205            }
206        case 4 :
207          if ( param._have_rotate_left)
208            {
209              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Rotate  Left" << endl;
210              direction = _left  ;
211              type      = _rotate;
212              carry     = _logic ; 
213              op        = " rol "; 
214              break;
215            }
216          else
217            {
218              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Rotate  Left" << endl;
219              continue;
220            }
221        case 5 :
222          if (param._have_rotate_right)
223            {
224              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} Test    Rotate  Right" << endl;
225              direction = _right;
226              type      = _rotate;
227              carry     = _logic ; 
228              op        = " ror "; 
229              break;
230            }
231          else
232            {
233              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "} No Test Rotate  Right" << endl;
234              continue;
235            }
236        default : 
237          continue;
238        }
239
240      for (uint32_t i=0; i<param._nb_port; i++)
241        {
242          SHIFTER_DIRECTION [i].write(direction );
243          SHIFTER_TYPE      [i].write(type      ); 
244          SHIFTER_CARRY     [i].write(carry     );
245        }
246
247      for (uint32_t it=0; it < iteration; it++)
248        {
249          for (Tshift_t shift=shift_min; shift<=shift_max; shift++)
250            {
251              Tdata_t mask_left  = 0;
252              Tdata_t mask_right = 0;
253             
254              if (param._size_data_completion > 0)
255                {
256                  mask_left  = gen_mask<Tdata_t> (shift);
257                  mask_right = mask_left << (param._size_data - shift);
258                }
259             
260              for (uint32_t i=0; i<param._nb_port; i++)
261                {
262                  data_in         [i] = rand() % data_max;
263                  data_completion [i] = (rand() % data_max) & gen_mask<Tdata_t>(param._size_data_completion); 
264
265                  switch (x)
266                    {
267                    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;
268                    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;
269                    case 2  : data_out [i] = shift_arithmetic_left  <Tdata_t>(param._size_data, data_in[i], shift); break;
270                    case 3  : data_out [i] = shift_arithmetic_right <Tdata_t>(param._size_data, data_in[i], shift); break;
271                    case 4  : data_out [i] = rotate_left            <Tdata_t>(param._size_data, data_in[i], shift); break;
272                    case 5  : data_out [i] = rotate_right           <Tdata_t>(param._size_data, data_in[i], shift); break;
273                    default : break;
274                  }
275                  SHIFTER_DATA_IN   [i].write(data_in         [i]);
276                  SHIFTER_SHIFT     [i].write(shift              ); 
277                  if (param._type_completion_bool == true)
278                    SHIFTER_CARRY_IN  [i].write(data_completion [i]!=0);
279                  else
280                    SHIFTER_COMPLETION[i].write(data_completion [i]);
281                }
282             
283              sc_start(0);
284             
285              cout << "{" << static_cast<uint32_t>(simulation_cycle()) << "}" << endl;
286             
287              for (uint32_t i=0; i<param._nb_port; i++)
288                {
289                  cout << "\t[" << i << "] " 
290                       << hex
291                       << data_in[i] << op
292                       << std::dec
293                       << shift      << " = " 
294                       << std::hex
295                       << SHIFTER_DATA_OUT [i].read()
296                       << " - completion : "
297                       << data_completion [i]
298                       << std::dec ;
299                 
300                  TEST(Tdata_t,SHIFTER_DATA_OUT [i].read(),data_out[i]);
301                }
302              sc_start(1);
303            }
304        }
305    }
306 
307  sc_start(0);
308 
309
310  /********************************************************
311   * Simulation - End
312   ********************************************************/
313  delete _time;
314
315  cout << "<" << name << "> ............ Stop Simulation" << endl;
316
317#endif
318
319  delete _Shifter;
320
321#ifdef STATISTICS
322  delete param_stat;
323#endif
324}
Note: See TracBrowser for help on using the repository browser.