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

Last change on this file since 82 was 82, checked in by rosiere, 16 years ago
  • support locale (now must "just" translate)
  • update all component with new test format
  • update all component with usage
  • New component : decod queue and prediction_unit
  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1/*
2 * $Id: test.cpp 82 2008-05-01 16:48:45Z 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  Shifter * _Shifter = new Shifter (name.c_str(),
41#ifdef STATISTICS
42                                    param_stat,
43#endif
44                                    &param,
45                                    USE_ALL);
46 
47#ifdef SYSTEMC
48  /*********************************************************************
49   * Déclarations des signaux
50   *********************************************************************/
51  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
52  sc_signal <Tdirection_t>                 NRESET("nreset");
53  sc_signal <Tdata_t     >                 SHIFTER_DATA_IN   [param._nb_port];
54  sc_signal <Tshift_t    >                 SHIFTER_SHIFT     [param._nb_port];
55  sc_signal <Tdirection_t>                 SHIFTER_DIRECTION [param._nb_port];
56  sc_signal <morpheo::behavioural::generic::shifter::Ttype_t     >                 SHIFTER_TYPE      [param._nb_port];
57  sc_signal <Tcarry_t    >                 SHIFTER_CARRY     [param._nb_port];
58  sc_signal <Tcontrol_t  >                 SHIFTER_CARRY_IN  [param._nb_port];
59  sc_signal <Tdata_t     >                 SHIFTER_COMPLETION[param._nb_port];
60  sc_signal <Tdata_t     >                 SHIFTER_DATA_OUT  [param._nb_port];
61 
62  /********************************************************
63   * Instanciation
64   ********************************************************/
65 
66  cout << "<" << name << "> Instanciation of _Shifter" << endl;
67 
68#if (defined(STATISTICS) || defined (VHDL_TESTBENCH))
69  (*(_Shifter->in_CLOCK))        (CLOCK);
70  (*(_Shifter->in_NRESET))       (NRESET);
71#endif
72  for (uint32_t i=0; i<param._nb_port; i++)
73    {
74      (*(_Shifter-> in_SHIFTER_DATA      [i])) (SHIFTER_DATA_IN   [i]);
75      if (param._shift_value == 0)
76      (*(_Shifter-> in_SHIFTER_SHIFT     [i])) (SHIFTER_SHIFT     [i]);
77      if (param._direction   == external_direction)
78      (*(_Shifter-> in_SHIFTER_DIRECTION [i])) (SHIFTER_DIRECTION [i]);
79      if (param._rotate      == external_rotate)
80      (*(_Shifter-> in_SHIFTER_TYPE      [i])) (SHIFTER_TYPE      [i]);
81      if (param._carry       == external_carry)
82      (*(_Shifter-> in_SHIFTER_CARRY     [i])) (SHIFTER_CARRY     [i]);
83      if (param._carry       == external_completion)
84      if (param._type_completion_bool == true)
85      (*(_Shifter-> in_SHIFTER_CARRY_IN  [i])) (SHIFTER_CARRY_IN  [i]);
86      else
87      (*(_Shifter-> in_SHIFTER_COMPLETION[i])) (SHIFTER_COMPLETION[i]);
88      (*(_Shifter->out_SHIFTER_DATA      [i])) (SHIFTER_DATA_OUT  [i]);
89    }
90
91  /********************************************************
92   * Simulation - Begin
93   ********************************************************/
94
95  cout << "<" << name << "> Start Simulation ............" << endl;
96  // Initialisation
97
98  srand (0);
99  //srand (time(NULL));
100 
101  const uint32_t iteration        = NB_ITERATION;
102
103  Tdirection_t   direction       ;
104  morpheo::behavioural::generic::shifter::Ttype_t        type            ;
105  Tcarry_t       carry           ; 
106  const Tdata_t  data_max        = (1<<param._size_data);
107  Tdata_t        data_in         [param._nb_port];
108  Tdata_t        data_completion [param._nb_port];
109  Tshift_t       shift_min       ;
110  Tshift_t       shift_max       ;
111  Tdata_t        data_out        [param._nb_port];
112  string         op              ;
113
114  if (param._shift_value != 0)
115    {
116      shift_min = param._shift_value;
117      shift_max = param._shift_value;
118    }
119  else
120    {
121      shift_min = 0;
122      shift_max = param._size_data-1;
123    }
124
125  sc_start(0);
126
127  NRESET.write(1);
128 
129  for (uint32_t x=0; x<6; x++)
130    {
131      switch (x)
132        {
133        case 0 :
134          if (param._have_shift_logic_left)
135            {
136              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Shift   Left  Logic" << endl;
137              direction = _left ;
138              type      = _shift;
139              carry     = _logic;
140              op        = " sll " ;     
141              break;
142            }
143          else
144            {
145              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift   Left  Logic" << endl;
146              continue;
147            }
148        case 1 :
149          if (param._have_shift_logic_right)
150            {
151              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Shift   Right Logic" << endl;
152              direction = _right;
153              type      = _shift;
154              carry     = _logic;
155              op        = " srl " ;
156              break;
157            }
158          else
159            {
160              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift   Right Logic" << endl;
161              continue;
162            }
163        case 2 :
164          if (param._have_shift_arithmetic_left)
165            {
166              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Shift   Left  Arithmetic" << endl;
167              direction = _left      ;
168              type      = _shift     ;
169              carry     = _arithmetic;
170              op        = " sla "    ;
171              break;
172            }
173          else
174            {
175              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift   Left  Arithmetic" << endl;
176              continue;
177            }
178        case 3 :
179          if (param._have_shift_arithmetic_right)
180            {
181              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Shift   Right Arithmetic" << endl;
182              direction = _right;
183              type      = _shift;
184              carry     = _arithmetic;
185              op        = " sra "    ;
186              break;
187            }
188          else
189            {
190              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift   Right Arithmetic" << endl;
191              continue;
192            }
193        case 4 :
194          if ( param._have_rotate_left)
195            {
196              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Rotate  Left" << endl;
197              direction = _left  ;
198              type      = _rotate;
199              carry     = _logic ; 
200              op        = " rol "; 
201              break;
202            }
203          else
204            {
205              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate  Left" << endl;
206              continue;
207            }
208        case 5 :
209          if (param._have_rotate_right)
210            {
211              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test    Rotate  Right" << endl;
212              direction = _right;
213              type      = _rotate;
214              carry     = _logic ; 
215              op        = " ror "; 
216              break;
217            }
218          else
219            {
220              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate  Right" << endl;
221              continue;
222            }
223        default : 
224          continue;
225        }
226
227      for (uint32_t i=0; i<param._nb_port; i++)
228        {
229          SHIFTER_DIRECTION [i].write(direction );
230          SHIFTER_TYPE      [i].write(type      ); 
231          SHIFTER_CARRY     [i].write(carry     );
232        }
233
234      for (uint32_t it=0; it < iteration; it++)
235        {
236          for (Tshift_t shift=shift_min; shift<=shift_max; shift++)
237            {
238              Tdata_t mask_left  = 0;
239              Tdata_t mask_right = 0;
240             
241              if (param._size_data_completion > 0)
242                {
243                  mask_left  = gen_mask<Tdata_t> (shift);
244                  mask_right = mask_left << (param._size_data - shift);
245                }
246             
247              for (uint32_t i=0; i<param._nb_port; i++)
248                {
249                  data_in         [i] = rand() % data_max;
250                  data_completion [i] = (rand() % data_max) & gen_mask<Tdata_t>(param._size_data_completion); 
251
252                  switch (x)
253                    {
254                    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;
255                    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;
256                    case 2  : data_out [i] = shift_arithmetic_left  <Tdata_t>(param._size_data, data_in[i], shift); break;
257                    case 3  : data_out [i] = shift_arithmetic_right <Tdata_t>(param._size_data, data_in[i], shift); break;
258                    case 4  : data_out [i] = rotate_left            <Tdata_t>(param._size_data, data_in[i], shift); break;
259                    case 5  : data_out [i] = rotate_right           <Tdata_t>(param._size_data, data_in[i], shift); break;
260                    default : break;
261                  }
262                  SHIFTER_DATA_IN   [i].write(data_in         [i]);
263                  SHIFTER_SHIFT     [i].write(shift              ); 
264                  if (param._type_completion_bool == true)
265                    SHIFTER_CARRY_IN  [i].write(data_completion [i]!=0);
266                  else
267                    SHIFTER_COMPLETION[i].write(data_completion [i]);
268                }
269             
270              sc_start(0);
271             
272              cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "}" << endl;
273             
274              for (uint32_t i=0; i<param._nb_port; i++)
275                {
276                  cout << "\t[" << i << "] " 
277                       << hex
278                       << data_in[i] << op
279                       << std::dec
280                       << shift      << " = " 
281                       << std::hex
282                       << SHIFTER_DATA_OUT [i].read()
283                       << " - completion : "
284                       << data_completion [i]
285                       << std::dec ;
286                 
287                  TEST(Tdata_t,SHIFTER_DATA_OUT [i].read(),data_out[i]);
288                }
289              sc_start(1);
290            }
291        }
292    }
293 
294  sc_start(0);
295 
296
297  /********************************************************
298   * Simulation - End
299   ********************************************************/
300
301  cout << "<" << name << "> ............ Stop Simulation" << endl;
302
303#endif
304
305  delete _Shifter;
306
307#ifdef STATISTICS
308  delete param_stat;
309#endif
310}
Note: See TracBrowser for help on using the repository browser.