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