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

Last change on this file since 75 was 75, checked in by rosiere, 16 years ago

Update all component (except front_end) to :

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