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

Last change on this file since 42 was 42, checked in by rosiere, 17 years ago

Modification des classes d'encapsulation des interfaces :

  • gère les signaux à écrire dans le vhdl
  • les traces pour le testbench
  • la génération des vhdl structurelles

-> test sur la Pattern History Table

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