source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/RegisterFile/RegisterFile_Internal_Banked/SelfTest/src/test.cpp @ 145

Last change on this file since 145 was 145, checked in by rosiere, 14 years ago

1) add test with SPECINT2K
2) new config of Selftest
3) modif RAT to support multiple depth_save ... but not finish (need fix Update Prediction Table)
4) add Function_pointer but need fix

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1/*
2 * $Id: test.cpp 145 2010-10-13 18:15:51Z rosiere $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 1
10#define CYCLE_MAX    100000*NB_ITERATION
11#include "Behavioural/Generic/RegisterFile/RegisterFile_Internal_Banked/SelfTest/include/test.h"
12#include "Common/include/Test.h"
13
14void test (string name,
15           morpheo::behavioural::generic::registerfile::registerfile_internal_banked::Parameters * _param)
16{
17  cout << "<" << name << "> : Simulation SystemC" << endl;
18
19  try 
20    {
21      cout << _param->print(1);
22      _param->test();
23    }
24  catch (morpheo::ErrorMorpheo & error)
25    {
26      cout << "<" << name << "> : " <<  error.what ();
27      return;
28    }
29  catch (...)
30    {
31      cerr << "<" << name << "> : This test must generate a error" << endl;
32      exit (EXIT_FAILURE);
33    }
34
35  _model.set_model(MODEL_SYSTEMC,true);
36
37  Tusage_t _usage = USE_ALL;
38
39//   _usage = usage_unset(_usage,USE_SYSTEMC              );
40//   _usage = usage_unset(_usage,USE_VHDL                 );
41//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
42//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
43//   _usage = usage_unset(_usage,USE_POSITION             );
44//   _usage = usage_unset(_usage,USE_STATISTICS           );
45//   _usage = usage_unset(_usage,USE_INFORMATION          );
46
47#ifdef STATISTICS
48  morpheo::behavioural::Parameters_Statistics * _param_stat = new morpheo::behavioural::Parameters_Statistics (5,100);
49#endif
50  RegisterFile_Internal_Banked * registerfile = new RegisterFile_Internal_Banked
51    (name.c_str()
52#ifdef STATISTICS
53     ,_param_stat
54#endif
55     ,_param
56     ,_usage);
57 
58#ifdef SYSTEMC
59  /*********************************************************************
60   * Déclarations des signaux
61   *********************************************************************/
62  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
63  sc_signal<Tcontrol_t>                    NRESET;
64 
65  sc_signal<Tcontrol_t>                    READ_VAL      [_param->_nb_port_read];
66  sc_signal<Tcontrol_t>                    READ_ACK      [_param->_nb_port_read];
67  sc_signal<Taddress_t>                    READ_ADDRESS  [_param->_nb_port_read];
68  sc_signal<Tdata_t>                       READ_DATA     [_param->_nb_port_read];
69
70  sc_signal<Tcontrol_t>                    WRITE_VAL     [_param->_nb_port_write];
71  sc_signal<Tcontrol_t>                    WRITE_ACK     [_param->_nb_port_write];
72  sc_signal<Taddress_t>                    WRITE_ADDRESS [_param->_nb_port_write];
73  sc_signal<Tdata_t>                       WRITE_DATA    [_param->_nb_port_write];
74
75  /********************************************************
76   * Instanciation
77   ********************************************************/
78 
79  cout << "<" << name << "> Instanciation of registerfile" << endl;
80 
81  (*(registerfile->in_CLOCK))        (CLOCK);
82  (*(registerfile->in_NRESET))       (NRESET);
83
84  for (uint32_t i=0; i<_param->_nb_port_read; i++)
85    {
86      (*(registerfile-> in_READ_VAL      [i]))        (READ_VAL      [i]);
87      (*(registerfile->out_READ_ACK      [i]))        (READ_ACK      [i]);
88      if (_param->_have_port_address)
89      (*(registerfile-> in_READ_ADDRESS  [i]))        (READ_ADDRESS  [i]);
90      (*(registerfile->out_READ_DATA     [i]))        (READ_DATA     [i]);
91    }
92  for (uint32_t i=0; i<_param->_nb_port_write; i++)
93    {
94      (*(registerfile-> in_WRITE_VAL     [i]))        (WRITE_VAL     [i]);
95      (*(registerfile->out_WRITE_ACK     [i]))        (WRITE_ACK     [i]);
96      if (_param->_have_port_address)
97      (*(registerfile-> in_WRITE_ADDRESS [i]))        (WRITE_ADDRESS [i]);
98      (*(registerfile-> in_WRITE_DATA    [i]))        (WRITE_DATA    [i]);
99    }
100 
101  cout << "<" << name << "> Start Simulation ............" << endl;
102  Time * _time = new Time();
103
104  /********************************************************
105   * Simulation - Begin
106   ********************************************************/
107
108  // Initialisation
109
110  SC_START(0);
111 
112  for (uint32_t i=0; i<_param->_nb_port_write; i++)
113    WRITE_VAL [i] .write (0);
114  for (uint32_t i=0; i<_param->_nb_port_read; i++)
115    READ_VAL  [i] .write (0);
116
117  NRESET.write(0);
118
119  SC_START(5);
120
121  NRESET.write(1);
122
123  for (uint32_t i=0; i<_param->_nb_port_write; i++)
124    TEST(Tcontrol_t,WRITE_ACK [i],1);
125  for (uint32_t i=0; i<_param->_nb_port_read; i++)
126    TEST(Tcontrol_t,READ_ACK  [i],1);
127
128  for (uint32_t nb_iteration=0; nb_iteration < NB_ITERATION; nb_iteration ++)
129    {
130      cout << "<" << name << "> 1) Write the RegisterFile (no read)" << endl;
131
132      // random init
133      uint32_t grain = 0;
134      //uint32_t grain = static_cast<uint32_t>(time(NULL));
135     
136      srand(grain);
137
138      Tdata_t tab [_param->_nb_word];
139     
140      for (uint32_t i=0; i<_param->_nb_word; i++)
141        tab[i]= rand()%(1<<(_param->_size_word-1));
142     
143      Taddress_t address_next = 0;
144      Taddress_t nb_ack = 0;
145     
146      while (nb_ack < _param->_nb_word)
147        {
148         
149          cout << "cycle : " << static_cast<uint32_t> (simulation_cycle()) << endl;
150
151          for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++)
152            {
153              if ((address_next < _param->_nb_word) and
154                  (WRITE_VAL [num_port].read() == 0))
155                {
156                  cout << "(" << num_port << ") [" << address_next << "] <= " << tab[address_next] << endl;
157                 
158                  WRITE_VAL     [num_port] .write(1);
159                  WRITE_DATA    [num_port] .write(tab[address_next]);
160                  WRITE_ADDRESS [num_port] .write(address_next++);
161                 
162                  // Address can be not a multiple of nb_port_write
163                  if (address_next >= _param->_nb_word)
164                    break;
165                }
166            }
167
168 
169          SC_START(1);
170
171          // reset write_val port
172          for (uint32_t num_port=0; num_port < _param->_nb_port_write; num_port ++)
173            {
174              if ((WRITE_ACK [num_port].read() == 1) and
175                  (WRITE_VAL [num_port].read() == 1))
176                {
177                  WRITE_VAL  [num_port] .write(0);
178                  nb_ack ++;
179                }
180            }
181
182//        SC_START(0);
183        }
184     
185      address_next = 0;
186      nb_ack       = 0;
187
188      cout << "<" << name << "> 2) Read the RegisterFile (no write)" << endl;
189     
190      Tdata_t read_address       [_param->_nb_port_read];
191
192      while (nb_ack < _param->_nb_word)
193        {
194          cout << "cycle : " << static_cast<uint32_t> (simulation_cycle()) << endl;
195         
196          for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++)
197            {
198              if ((address_next < _param->_nb_word) and
199                  (READ_VAL [num_port].read() == 0))
200                {
201                  read_address [num_port] = address_next++;
202
203                  READ_VAL     [num_port].write(1);
204                  READ_ADDRESS [num_port].write(read_address [num_port]);
205
206                  if (address_next >= _param->_nb_word)
207                    break;
208                }
209            }
210
211
212          SC_START(1);
213
214          // reset write_val port
215          for (uint32_t num_port=0; num_port < _param->_nb_port_read; num_port ++)
216            {
217              if ((READ_ACK [num_port].read() == 1) and
218                  (READ_VAL [num_port].read() == 1))
219                {
220                  READ_VAL  [num_port] .write(0);
221
222                  cout << "(" << num_port << ") [" << read_address [num_port] << "] => " << READ_DATA [num_port].read() << endl;
223
224                  TEST(Tdata_t,READ_DATA [num_port].read(), tab[read_address [num_port]]);
225                  nb_ack ++;
226                }
227            }
228
229//        SC_START(0);
230        }
231    }
232
233  /********************************************************
234   * Simulation - End
235   ********************************************************/
236
237  TEST_STR(bool,true,true, "End of Simulation");
238  delete _time;
239  cout << "<" << name << "> ............ Stop Simulation" << endl;
240
241#endif
242
243  delete registerfile;
244}
Note: See TracBrowser for help on using the repository browser.