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