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

Last change on this file since 85 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: 3.8 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    1024*NB_ITERATION
11
12#include "Behavioural/Generic/Counter/SelfTest/include/test.h"
13#include "Common/include/Test.h"
14
15void test (string name,
16           morpheo::behavioural::generic::counter::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#ifdef STATISTICS
36  morpheo::behavioural::Parameters_Statistics * param_stat = new morpheo::behavioural::Parameters_Statistics (5,50);
37#endif
38
39  Counter * _Counter = new Counter (name.c_str(),
40#ifdef STATISTICS
41                                    param_stat,
42#endif
43                                    param,
44                                    USE_ALL);
45 
46#ifdef SYSTEMC
47  /*********************************************************************
48   * Déclarations des signaux
49   *********************************************************************/
50  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
51  sc_signal<Tcontrol_t>                    RESET;
52  sc_signal<Tdata_t>                       DATA_IN  [param._nb_port];
53  sc_signal<Tcontrol_t>                    ADDSUB   [param._nb_port];
54  sc_signal<Tdata_t>                       DATA_OUT [param._nb_port];
55
56  /********************************************************
57   * Instanciation
58   ********************************************************/
59 
60  cout << "<" << name << "> Instanciation of _Counter" << endl;
61 
62  (*(_Counter->in_CLOCK))        (CLOCK);
63  (*(_Counter->in_NRESET))       (RESET);
64
65  for (uint32_t i=0; i<param._nb_port; i++)
66    {
67      (*(_Counter-> in_COUNTER_DATA  [i]))        (DATA_IN  [i]);
68      (*(_Counter-> in_COUNTER_ADDSUB[i]))        (ADDSUB   [i]);
69      (*(_Counter->out_COUNTER_DATA  [i]))        (DATA_OUT [i]);
70    }
71
72  /********************************************************
73   * Simulation - Begin
74   ********************************************************/
75
76  cout << "<" << name << "> Start Simulation ............" << endl;
77  // Initialisation
78
79  srand(0);
80  //srand(TIME(NULL));
81
82  Tdata_t    data_in  [param._nb_port];
83  Tdata_t    data_out [param._nb_port];
84  Tcontrol_t addsub   [param._nb_port];
85
86  sc_start(0);
87
88  RESET.write(1);
89
90  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
91
92  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
93
94  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
95    {
96      cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Itération " << iteration << endl;
97      for (uint32_t i=0; i<param._nb_port; i++)
98        {
99          Tdata_t data = rand()%param._data_max;
100          data_in  [i] = data;
101          addsub   [i] = (rand()%2)==1; 
102         
103          DATA_IN  [i].write(data      );
104          ADDSUB   [i].write(addsub [i]);
105
106          data_out [i] = (addsub[i]==1)?((data<param._data_max)?data+1:data):((data>0)?data-1:data);
107        }
108
109      sc_start(0);
110     
111      for (uint32_t i=0; i<param._nb_port; i++)
112        {
113          cout << hex
114               << "    [" << i << "] "
115               << data_in [i];
116
117          if (addsub[i] == 1)
118            cout << " ++";
119          else
120            cout << " --";
121
122          cout << " = " 
123               << DATA_OUT [i].read();
124
125          TEST(Tdata_t,DATA_OUT [i].read(),data_out [i]);
126           
127          cout << std::dec << endl;
128        }
129     
130      sc_start(1);
131    }
132
133  sc_start(1);
134
135  /********************************************************
136   * Simulation - End
137   ********************************************************/
138
139  cout << "<" << name << "> ............ Stop Simulation" << endl;
140
141#endif
142
143  delete _Counter;
144#ifdef STATISTICS
145  delete param_stat;
146#endif
147
148}
Note: See TracBrowser for help on using the repository browser.