source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Sort/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: 5.2 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  1024
10#define CYCLE_MAX     (128*NB_ITERATION)
11
12#include "Behavioural/Generic/Sort/SelfTest/include/test.h"
13#include "Common/include/Test.h"
14#include "Common/include/BitManipulation.h"
15#include "Behavioural/include/Allocation.h"
16
17class entry_t
18{
19public : Tcontrol_t _val ;
20public : Tdata_t    _data;
21};
22
23
24void test (string name,
25           morpheo::behavioural::generic::sort::Parameters * _param)
26{
27  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
28
29#ifdef STATISTICS
30  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50);
31#endif
32
33  Sort * _Sort = new Sort (name.c_str(),
34#ifdef STATISTICS
35                           _parameters_statistics,
36#endif
37                           _param,
38                           USE_ALL);
39 
40#ifdef SYSTEMC
41  /*********************************************************************
42   * Déclarations des signaux
43   *********************************************************************/
44  string rename;
45
46  sc_clock              *  in_CLOCK  = new sc_clock ("clock", 1.0, 0.5);         
47  sc_signal<Tcontrol_t> *  in_NRESET = new sc_signal<Tcontrol_t> ("NRESET");
48
49  ALLOC1_SC_SIGNAL( in_INPUT_VAL   ," in_INPUT_VAL   ",Tcontrol_t,_param->_nb_input );
50  ALLOC1_SC_SIGNAL( in_INPUT_DATA  ," in_INPUT_DATA  ",Tdata_t   ,_param->_nb_input );
51  ALLOC1_SC_SIGNAL(out_OUTPUT_VAL  ,"out_OUTPUT_VAL  ",Tcontrol_t,_param->_nb_output);
52  ALLOC1_SC_SIGNAL(out_OUTPUT_INDEX,"out_OUTPUT_INDEX",Taddress_t,_param->_nb_output);
53  ALLOC1_SC_SIGNAL(out_OUTPUT_DATA ,"out_OUTPUT_DATA ",Tdata_t   ,_param->_nb_output);
54 
55  /********************************************************
56   * Instanciation
57   ********************************************************/
58 
59  msg(_("<%s> : Instanciation of _Sort.\n"),name.c_str());
60
61  (*(_Sort->in_CLOCK))        (*(in_CLOCK));
62  (*(_Sort->in_NRESET))       (*(in_NRESET));
63
64  INSTANCE1_SC_SIGNAL(_Sort, in_INPUT_VAL   ,_param->_nb_input );
65  INSTANCE1_SC_SIGNAL(_Sort, in_INPUT_DATA  ,_param->_nb_input );
66  INSTANCE1_SC_SIGNAL(_Sort,out_OUTPUT_VAL  ,_param->_nb_output);
67  if (_param->_have_port_index_out)
68  INSTANCE1_SC_SIGNAL(_Sort,out_OUTPUT_INDEX,_param->_nb_output);
69  if (_param->_have_port_data_out)
70  INSTANCE1_SC_SIGNAL(_Sort,out_OUTPUT_DATA ,_param->_nb_output);
71
72  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
73   
74  Time * _time = new Time();
75
76  /********************************************************
77   * Simulation - Begin
78   ********************************************************/
79
80  // Initialisation
81
82  const uint32_t seed = 0;
83//const uint32_t seed = static_cast<uint32_t>(time(NULL));
84
85  srand(seed);
86
87  entry_t tab [_param->_nb_input];
88
89  SC_START(0);
90  LABEL("Initialisation");
91
92  LABEL("Reset");
93  in_NRESET->write(0);
94  SC_START(5);
95  in_NRESET->write(1); 
96  SC_START(1);
97
98  LABEL("Loop of Test");
99
100  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
101    {
102      LABEL("Iteration %d",iteration);
103
104      for (uint32_t i=0; i<_param->_nb_input; i++)
105        {
106          tab [i]._val  = rand ()%2;
107          tab [i]._data = range<Tdata_t>(rand(),_param->_size_data);
108
109          in_INPUT_VAL  [i]->write(tab [i]._val );
110          in_INPUT_DATA [i]->write(tab [i]._data);
111
112          LABEL("INPUT  [%d] %d - %d",i, tab [i]._val, tab [i]._data);
113        }
114
115      SC_START(1);
116
117      if (_param->_ascending)
118        {
119          Tdata_t data_min = 0;
120          for (uint32_t i=0; i<_param->_nb_output; i++)
121            {
122              bool     find = false;
123              Tdata_t  data = range<Tdata_t>(static_cast<Tdata_t>(-1),_param->_size_data);
124              uint32_t ptr  = 0;
125              // find max
126//            LABEL(" * data_min  : %d",data_min);
127
128              for (uint32_t j=0; j<_param->_nb_input; j++)
129                {
130//                LABEL("tab[%d]._val  : %d",j,tab [j]._val );
131//                LABEL("tab[%d]._data : %d",j,tab [j]._data);
132//                LABEL(" * find      : %d",find);
133//                LABEL(" * data      : %d",data);
134//                LABEL(" * ptr       : %d",ptr );
135
136                if ((tab [j]._val  == 1) and
137                    (tab [j]._data >= data_min) and
138                    (tab [j]._data <= data))
139                  {
140                    if (not (find and (data == tab [j]._data)))
141                      ptr  = j;
142
143                    data = tab [j]._data;
144                    find = true;
145                  }
146                }
147
148//            LABEL("-------------");
149//            LABEL(" * find      : %d",find);
150//            LABEL(" * data      : %d",data);
151//            LABEL(" * ptr       : %d",ptr );
152
153              data_min = data;
154              tab [ptr]._val = false;
155
156              LABEL("OUTPUT [%d] %d - %d",i, out_OUTPUT_VAL [i]->read(), out_OUTPUT_DATA [i]->read(), out_OUTPUT_INDEX [i]->read());
157
158              TEST(Tcontrol_t,out_OUTPUT_VAL   [i]->read(),find);
159
160              if (find)
161                {
162              if (_param->_have_port_index_out)
163              TEST(Taddress_t,out_OUTPUT_INDEX [i]->read(),ptr );
164              if (_param->_have_port_data_out)
165              TEST(Tdata_t   ,out_OUTPUT_DATA  [i]->read(),data);
166                }
167            }
168        }
169    }
170
171  /********************************************************
172   * Simulation - End
173   ********************************************************/
174
175  TEST_OK ("End of Simulation");
176  delete _time;
177
178  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
179
180  delete in_CLOCK;
181  delete in_NRESET;
182
183  delete []  in_INPUT_VAL   ;
184  delete []  in_INPUT_DATA  ;
185  delete [] out_OUTPUT_VAL  ;
186  delete [] out_OUTPUT_INDEX;
187  delete [] out_OUTPUT_DATA ;
188#endif
189
190  delete _Sort;
191#ifdef STATISTICS
192  delete _parameters_statistics;
193#endif
194}
Note: See TracBrowser for help on using the repository browser.