source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Write_unit/Write_unit/SelfTest/src/top_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: 15.7 KB
Line 
1/*
2 * $Id: top_test.cpp 113 2009-04-14 18:39:12Z rosiere $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#include "Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Write_unit/Write_unit/SelfTest/include/top.h"
10#include "Behavioural/include/Allocation.h"
11#include "Common/include/BitManipulation.h"
12
13  class entry_t
14  {
15  public  : Tcontext_t         _context_id   ;
16  public  : Tcontext_t         _front_end_id ;
17  public  : Tcontext_t         _ooo_engine_id;
18  public  : Tpacket_t          _packet_id    ;
19//public  : Toperation_t       _operation    ;
20//public  : Ttype_t            _type         ;
21  public  : Tcontrol_t         _write_rd     ;
22  public  : Tgeneral_address_t _num_reg_rd   ;
23  public  : Tgeneral_data_t    _data_rd      ;
24  public  : Tcontrol_t         _write_re     ;
25  public  : Tspecial_address_t _num_reg_re   ;
26  public  : Tspecial_data_t    _data_re      ;
27  public  : Texception_t       _exception    ;
28  public  : Tcontrol_t         _no_sequence  ;
29  public  : Tgeneral_data_t    _address      ;
30   
31  public  : entry_t (Tcontext_t         context_id   ,
32                     Tcontext_t         front_end_id ,
33                     Tcontext_t         ooo_engine_id,
34                     Tpacket_t          packet_id    ,
35//                   Toperation_t       operation    ,
36//                   Ttype_t            type         ,
37                     Tcontrol_t         write_rd     ,
38                     Tgeneral_address_t num_reg_rd   ,
39                     Tgeneral_data_t    data_rd      ,
40                     Tcontrol_t         write_re     ,
41                     Tspecial_address_t num_reg_re   ,
42                     Tspecial_data_t    data_re      ,
43                     Texception_t       exception    ,
44                     Tcontrol_t         no_sequence  ,
45                     Tgeneral_data_t    address      )
46    {
47      _context_id    = context_id   ;
48      _front_end_id  = front_end_id ;
49      _ooo_engine_id = ooo_engine_id;
50      _packet_id     = packet_id    ;
51//    _operation     = operation    ;
52//    _type          = type         ;
53      _write_rd      = write_rd     ;
54      _num_reg_rd    = num_reg_rd   ;
55      _data_rd       = data_rd      ;
56      _write_re      = write_re     ;
57      _num_reg_re    = num_reg_re   ;
58      _data_re       = data_re      ;
59      _exception     = exception    ;
60      _no_sequence   = no_sequence  ;
61      _address       = address      ;
62    };
63
64    friend std::ostream& operator<< (std::ostream& output_stream,
65                                     entry_t & x)
66    {
67      output_stream << " * _context_id    : " << toString(x._context_id   ) << std::endl
68                    << " * _front_end_id  : " << toString(x._front_end_id ) << std::endl
69                    << " * _ooo_engine_id : " << toString(x._ooo_engine_id) << std::endl
70                    << " * _packet_id     : " << toString(x._packet_id    ) << std::endl
71                  //<< " * _operation     : " << toString(x._operation    ) << std::endl
72                  //<< " * _type          : " << toString(x._type         ) << std::endl
73                    << " * _write_rd      : " << toString(x._write_rd     ) << std::endl
74                    << " * _num_reg_rd    : " << toString(x._num_reg_rd   ) << std::endl
75                    << " * _data_rd       : " << toString(x._data_rd      ) << std::endl
76                    << " * _write_re      : " << toString(x._write_re     ) << std::endl
77                    << " * _num_reg_re    : " << toString(x._num_reg_re   ) << std::endl
78                    << " * _data_re       : " << toString(x._data_re      ) << std::endl
79                    << " * _exception     : " << toString(x._exception    ) << std::endl
80                    << " * _no_sequence   : " << toString(x._no_sequence  ) << std::endl
81                    << " * _address       : " << toString(x._address      ) << std::endl;
82
83      return output_stream;
84    }
85  };
86
87void top::test (void)
88{
89#ifdef SYSTEMC
90  if (usage_is_set(_usage,USE_SYSTEMC))
91    {
92      msgInformation(_("<%s> : Start Simulation ............\n"),name.c_str());
93     
94      Time * _time = new Time();
95     
96      /********************************************************
97       * Simulation - Begin
98       ********************************************************/
99     
100  // Initialisation
101
102  const uint32_t seed = 0;
103//const uint32_t seed = static_cast<uint32_t>(time(NULL));
104
105  srand(seed);
106 
107  const  int32_t percent_transaction_write_unit_in  = 75;
108  const  int32_t percent_transaction_write_unit_out = 75;
109  const  int32_t percent_transaction_gpr             = 75;
110  const  int32_t percent_transaction_spr             = 75;
111
112  bool            gpr_val [_param->_nb_ooo_engine][_param->_nb_general_register];
113  bool            gpr_use [_param->_nb_ooo_engine][_param->_nb_general_register];
114  Tgeneral_data_t gpr     [_param->_nb_ooo_engine][_param->_nb_general_register];
115  bool            spr_val [_param->_nb_ooo_engine][_param->_nb_special_register];
116  bool            spr_use [_param->_nb_ooo_engine][_param->_nb_special_register];
117  Tgeneral_data_t spr     [_param->_nb_ooo_engine][_param->_nb_special_register];
118
119  entry_t *       request [_param->_nb_packet];
120
121  for (uint32_t i=0; i<_param->_nb_packet; ++i)
122    request [i] = NULL;
123 
124  SC_CYCLE(0);
125  LABEL("Initialisation");
126
127  LABEL("Reset");
128  in_NRESET->write(0);
129  SC_CYCLE(5);
130  in_NRESET->write(1); 
131
132  LABEL("Loop of Test");
133
134  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
135    {
136      LABEL("Iteration %d",iteration);
137
138      for (uint32_t i=0; i<_param->_nb_ooo_engine; i++)
139        {
140          for (uint32_t j=0; j<_param->_nb_general_register; j++)
141            {
142              gpr_val [i][j] = 0;
143              gpr_use [i][j] = 0;
144              gpr     [i][j] = rand();
145            }
146          for (uint32_t j=0; j<_param->_nb_special_register; j++)
147            {
148              spr_val [i][j] = 0;
149              spr_use [i][j] = 0;
150              spr     [i][j] = rand();
151            }
152        }
153
154      for (uint32_t i=0; i<_param->_nb_packet; i++)
155        {
156          if (request [i] == NULL)
157            delete request [i];
158
159          request [i] = new entry_t (range<Tcontext_t        >(rand(),_param->_size_context_id      ),
160                                     range<Tcontext_t        >(rand(),_param->_size_front_end_id    ),
161                                     range<Tcontext_t        >(rand(),_param->_size_ooo_engine_id   ),
162                                     i,
163                                   //range<Toperation_t      >(rand(),_param->_size_operation       ),
164                                   //range<Ttype_t           >(rand(),_param->_size_type            ),
165                                     range<Tcontrol_t        >(rand(),1                             ),
166                                     range<Tgeneral_address_t>(rand(),_param->_size_general_register),
167                                     range<Tgeneral_data_t   >(rand(),_param->_size_general_data    ),
168                                     range<Tcontrol_t        >(rand(),1                             ),
169                                     range<Tspecial_address_t>(rand(),_param->_size_special_register),
170                                     range<Tspecial_data_t   >(rand(),_param->_size_special_data    ),
171                                     range<Texception_t      >(rand(),0                             ),
172                                     range<Tcontrol_t        >(rand(),1                             ),
173                                     range<Tgeneral_data_t   >(rand(),_param->_size_general_data    ));
174        }
175
176      uint32_t nb_request_in  = 0;
177      uint32_t nb_request_out = 0;
178
179      while (nb_request_out < _param->_nb_packet)
180      {
181        bool val = (((rand()%100)<percent_transaction_write_unit_in) and
182                    (nb_request_in < _param->_nb_packet) and
183                    not (request [nb_request_in]->_write_rd and
184                         gpr_use [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_rd]) and
185                    not (request [nb_request_in]->_write_re and
186                         spr_use [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_re]));
187       
188        in_WRITE_UNIT_IN_VAL          ->write(val);
189        if (val)
190          {
191            in_WRITE_UNIT_IN_CONTEXT_ID   ->write(request [nb_request_in]->_context_id   );
192            in_WRITE_UNIT_IN_FRONT_END_ID ->write(request [nb_request_in]->_front_end_id );
193            in_WRITE_UNIT_IN_OOO_ENGINE_ID->write(request [nb_request_in]->_ooo_engine_id);
194            in_WRITE_UNIT_IN_PACKET_ID    ->write(request [nb_request_in]->_packet_id    );
195          //in_WRITE_UNIT_IN_OPERATION    ->write(request [nb_request_in]->_operation    );
196          //in_WRITE_UNIT_IN_TYPE         ->write(request [nb_request_in]->_type         );
197            in_WRITE_UNIT_IN_WRITE_RD     ->write(request [nb_request_in]->_write_rd     );
198            in_WRITE_UNIT_IN_NUM_REG_RD   ->write(request [nb_request_in]->_num_reg_rd   );
199            in_WRITE_UNIT_IN_DATA_RD      ->write(request [nb_request_in]->_data_rd      );
200            in_WRITE_UNIT_IN_WRITE_RE     ->write(request [nb_request_in]->_write_re     );
201            in_WRITE_UNIT_IN_NUM_REG_RE   ->write(request [nb_request_in]->_num_reg_re   );
202            in_WRITE_UNIT_IN_DATA_RE      ->write(request [nb_request_in]->_data_re      );
203            in_WRITE_UNIT_IN_EXCEPTION    ->write(request [nb_request_in]->_exception    );
204            in_WRITE_UNIT_IN_NO_SEQUENCE  ->write(request [nb_request_in]->_no_sequence  );
205            in_WRITE_UNIT_IN_ADDRESS      ->write(request [nb_request_in]->_address      );
206          }
207        in_WRITE_UNIT_OUT_ACK         ->write((rand()%100)<percent_transaction_write_unit_out);
208        in_GPR_WRITE_ACK [0]           ->write((rand()%100)<percent_transaction_gpr);
209        in_SPR_WRITE_ACK [0]           ->write((rand()%100)<percent_transaction_spr);
210           
211        SC_CYCLE(0);
212
213        // ======================================================================
214        // ======================================================================
215        // ======================================================================
216        if (out_GPR_WRITE_VAL [0]->read() and
217             in_GPR_WRITE_ACK [0]->read())
218          {
219            Tcontext_t         ooo_engine_id = (_param->_have_port_ooo_engine_id)?out_GPR_WRITE_OOO_ENGINE_ID[0]->read():0;
220            Tgeneral_address_t num_reg       = out_GPR_WRITE_NUM_REG      [0]->read();
221            Tgeneral_data_t    data          = out_GPR_WRITE_DATA         [0]->read();
222           
223            LABEL(" * Accepted GPR_WRITE     in register [%d][%d]", ooo_engine_id,num_reg);
224
225            TEST(bool           , gpr_val [ooo_engine_id][num_reg], 0);
226            TEST(bool           , gpr_use [ooo_engine_id][num_reg], 1);
227            TEST(Tgeneral_data_t, gpr     [ooo_engine_id][num_reg], data);
228           
229            gpr_val [ooo_engine_id][num_reg] = 1;
230          }
231
232        // ======================================================================
233        // ======================================================================
234        // ======================================================================
235        if (out_SPR_WRITE_VAL [0]->read() and
236             in_SPR_WRITE_ACK [0]->read())
237          {
238            Tcontext_t         ooo_engine_id = (_param->_have_port_ooo_engine_id)?out_SPR_WRITE_OOO_ENGINE_ID[0]->read():0;
239            Tspecial_address_t num_reg       = out_SPR_WRITE_NUM_REG      [0]->read();
240            Tspecial_data_t    data          = out_SPR_WRITE_DATA         [0]->read();
241           
242            LABEL(" * Accepted SPR_WRITE     in register [%d][%d]", ooo_engine_id,num_reg);
243
244            TEST(bool           , spr_val [ooo_engine_id][num_reg], 0);
245            TEST(bool           , spr_use [ooo_engine_id][num_reg], 1);
246            TEST(Tgeneral_data_t, spr     [ooo_engine_id][num_reg], data);
247           
248            spr_val [ooo_engine_id][num_reg] = 1;
249          }
250
251        // ======================================================================
252        // ======================================================================
253        // ======================================================================
254        for (uint32_t i=0; i<_param->_nb_bypass_write; i++)
255          {
256            Tcontext_t         ooo_engine_id  = (_param->_have_port_ooo_engine_id)?out_BYPASS_WRITE_OOO_ENGINE_ID[i]->read():0;
257           
258            if (out_BYPASS_WRITE_GPR_VAL      [i]->read())
259              {
260                Tgeneral_address_t num_reg    = out_BYPASS_WRITE_GPR_NUM_REG  [i]->read(); // RD
261                Tgeneral_data_t    data       = out_BYPASS_WRITE_GPR_DATA     [i]->read();
262
263                LABEL(" * Accepted BYPASS_WRITE  in register [%d][%d] (GPR)", ooo_engine_id,num_reg);
264                           
265
266                TEST(bool           , gpr_use [ooo_engine_id][num_reg], 1);
267                TEST(Tgeneral_data_t, gpr     [ooo_engine_id][num_reg], data);
268              }
269            if (out_BYPASS_WRITE_SPR_VAL      [i]->read())
270              {
271                Tspecial_address_t num_reg    = out_BYPASS_WRITE_SPR_NUM_REG  [i]->read(); // RE
272                Tspecial_data_t    data       = out_BYPASS_WRITE_SPR_DATA     [i]->read();
273
274                LABEL(" * Accepted BYPASS_WRITE  in register [%d][%d] (SPR)", ooo_engine_id,num_reg);
275
276                TEST(bool           , spr_use [ooo_engine_id][num_reg], 1);
277                TEST(Tspecial_data_t, spr     [ooo_engine_id][num_reg], data);
278              }
279          }
280       
281        // ======================================================================
282        // ======================================================================
283        // ======================================================================
284        if ( in_WRITE_UNIT_IN_VAL->read() and
285            out_WRITE_UNIT_IN_ACK->read())
286          {
287            LABEL(" * Accepted WRITE_UNIT_IN  [%d]",nb_request_in);
288//          std::cout << *request [nb_request_in] << std::endl;
289
290            if (request [nb_request_in]->_write_rd)
291              {
292                gpr_val [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_rd] = 0;
293                gpr_use [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_rd] = 1;
294                gpr     [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_rd] = request [nb_request_in]->_data_rd;
295              }
296            if (request [nb_request_in]->_write_re)
297              {
298                spr_val [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_re] = 0;
299                spr_use [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_re] = 1;
300                spr     [request [nb_request_in]->_ooo_engine_id][request [nb_request_in]->_num_reg_re] = request [nb_request_in]->_data_re;
301              }
302            nb_request_in ++;
303          }
304       
305        // ======================================================================
306        // ======================================================================
307        // ======================================================================
308        if (out_WRITE_UNIT_OUT_VAL->read() and
309             in_WRITE_UNIT_OUT_ACK->read())
310          {
311            Tcontext_t packet;
312            if (_param->_have_port_rob_ptr)
313              packet = out_WRITE_UNIT_OUT_PACKET_ID->read();
314            else
315              packet = 0;
316
317            LABEL(" * Accepted WRITE_UNIT_OUT [%d]",packet);
318//          std::cout << *request [packet] << std::endl;
319
320            if (request [packet]->_write_rd)
321              {
322                TEST(bool, gpr_val [request [packet]->_ooo_engine_id][request [packet]->_num_reg_rd], 1);
323                TEST(bool, gpr_use [request [packet]->_ooo_engine_id][request [packet]->_num_reg_rd], 1);
324                gpr_use [request [packet]->_ooo_engine_id][request [packet]->_num_reg_rd] = 0;
325              }
326            if (request [packet]->_write_re)
327              {
328                TEST(bool, spr_val [request [packet]->_ooo_engine_id][request [packet]->_num_reg_re], 1);
329                TEST(bool, spr_use [request [packet]->_ooo_engine_id][request [packet]->_num_reg_re], 1);
330                spr_use [request [packet]->_ooo_engine_id][request [packet]->_num_reg_re] = 0;
331              }
332
333            if (_param->_have_port_context_id)
334            TEST(Tcontext_t     , out_WRITE_UNIT_OUT_CONTEXT_ID   ->read(), request [packet]->_context_id   );
335            if (_param->_have_port_front_end_id)
336            TEST(Tcontext_t     , out_WRITE_UNIT_OUT_FRONT_END_ID ->read(), request [packet]->_front_end_id );
337            if (_param->_have_port_ooo_engine_id)
338            TEST(Tcontext_t     , out_WRITE_UNIT_OUT_OOO_ENGINE_ID->read(), request [packet]->_ooo_engine_id);
339           
340          //TEST(Toperation_t   , out_WRITE_UNIT_OUT_OPERATION    ->read(), request [packet]->_operation    );
341          //TEST(Ttype_t        , out_WRITE_UNIT_OUT_TYPE         ->read(), request [packet]->_type         );
342            TEST(Tcontrol_t     , out_WRITE_UNIT_OUT_FLAGS        ->read(), request [packet]->_data_re      );
343            TEST(Texception_t   , out_WRITE_UNIT_OUT_EXCEPTION    ->read(), request [packet]->_exception    );
344            TEST(Tcontrol_t     , out_WRITE_UNIT_OUT_NO_SEQUENCE  ->read(), request [packet]->_no_sequence  );
345            TEST(Tgeneral_data_t, out_WRITE_UNIT_OUT_ADDRESS      ->read(), request [packet]->_address      );
346            TEST(Tgeneral_data_t, out_WRITE_UNIT_OUT_DATA         ->read(), request [packet]->_data_rd      );
347
348            nb_request_out ++;
349          }
350
351        SC_CYCLE(1);
352      }
353
354      for (uint32_t i=0; i<_param->_nb_packet; i++)
355        if (request [i] == NULL)
356          delete request [i];
357    }
358     
359      /********************************************************
360       * Simulation - End
361       ********************************************************/
362     
363      TEST_OK ("");
364     
365      sc_stop();
366      delete _time;
367     
368      msgInformation(_("<%s> : ............ Stop Simulation\n"),name.c_str());
369    }
370#endif
371}
Note: See TracBrowser for help on using the repository browser.