[2] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Generic/Shifter/SelfTest/include/test.h" |
---|
| 10 | #include "Include/BitManipulation.h" |
---|
| 11 | #include "Include/Test.h" |
---|
| 12 | |
---|
| 13 | #define NB_ITERATION 64 |
---|
| 14 | |
---|
| 15 | void test (string name, |
---|
| 16 | morpheo::behavioural::generic::shifter::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 | Shifter * _Shifter = new Shifter (name.c_str(), |
---|
| 36 | #ifdef STATISTICS |
---|
| 37 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
| 38 | #endif |
---|
| 39 | param); |
---|
| 40 | |
---|
| 41 | #ifdef SYSTEMC |
---|
| 42 | /********************************************************************* |
---|
| 43 | * Déclarations des signaux |
---|
| 44 | *********************************************************************/ |
---|
| 45 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
| 46 | sc_signal <Tdata_t > SHIFTER_DATA_IN [param._nb_port]; |
---|
| 47 | sc_signal <Tshift_t > SHIFTER_SHIFT [param._nb_port]; |
---|
| 48 | sc_signal <Tdirection_t> SHIFTER_DIRECTION [param._nb_port]; |
---|
| 49 | sc_signal <Ttype_t > SHIFTER_TYPE [param._nb_port]; |
---|
| 50 | sc_signal <Tcarry_t > SHIFTER_CARRY [param._nb_port]; |
---|
| 51 | sc_signal <Tcontrol_t > SHIFTER_CARRY_IN [param._nb_port]; |
---|
| 52 | sc_signal <Tdata_t > SHIFTER_COMPLETION[param._nb_port]; |
---|
| 53 | sc_signal <Tdata_t > SHIFTER_DATA_OUT [param._nb_port]; |
---|
| 54 | |
---|
| 55 | /******************************************************** |
---|
| 56 | * Instanciation |
---|
| 57 | ********************************************************/ |
---|
| 58 | |
---|
| 59 | cout << "<" << name << "> Instanciation of _Shifter" << endl; |
---|
| 60 | |
---|
| 61 | #if (defined(STATISTICS) || defined (VHDL_TESTBENCH)) |
---|
| 62 | (*(_Shifter->in_CLOCK)) (CLOCK); |
---|
| 63 | #endif |
---|
| 64 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 65 | { |
---|
| 66 | (*(_Shifter-> in_SHIFTER_DATA [i])) (SHIFTER_DATA_IN [i]); |
---|
| 67 | if (param._shift_value == 0) |
---|
| 68 | (*(_Shifter-> in_SHIFTER_SHIFT [i])) (SHIFTER_SHIFT [i]); |
---|
| 69 | if (param._direction == external_direction) |
---|
| 70 | (*(_Shifter-> in_SHIFTER_DIRECTION [i])) (SHIFTER_DIRECTION [i]); |
---|
| 71 | if (param._rotate == external_rotate) |
---|
| 72 | (*(_Shifter-> in_SHIFTER_TYPE [i])) (SHIFTER_TYPE [i]); |
---|
| 73 | if (param._carry == external_carry) |
---|
| 74 | (*(_Shifter-> in_SHIFTER_CARRY [i])) (SHIFTER_CARRY [i]); |
---|
| 75 | if (param._carry == external_completion) |
---|
| 76 | if (param._type_completion_bool == true) |
---|
| 77 | (*(_Shifter-> in_SHIFTER_CARRY_IN [i])) (SHIFTER_CARRY_IN [i]); |
---|
| 78 | else |
---|
| 79 | (*(_Shifter-> in_SHIFTER_COMPLETION[i])) (SHIFTER_COMPLETION[i]); |
---|
| 80 | (*(_Shifter->out_SHIFTER_DATA [i])) (SHIFTER_DATA_OUT [i]); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /******************************************************** |
---|
| 84 | * Simulation - Begin |
---|
| 85 | ********************************************************/ |
---|
| 86 | |
---|
| 87 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 88 | // Initialisation |
---|
| 89 | |
---|
| 90 | srand (0); |
---|
| 91 | //srand (time(NULL)); |
---|
| 92 | |
---|
| 93 | const uint32_t iteration = NB_ITERATION; |
---|
| 94 | |
---|
| 95 | Tdirection_t direction ; |
---|
| 96 | Ttype_t type ; |
---|
| 97 | Tcarry_t carry ; |
---|
| 98 | const Tdata_t data_max = (1<<param._size_data); |
---|
| 99 | Tdata_t data_in [param._nb_port]; |
---|
| 100 | Tdata_t data_completion [param._nb_port]; |
---|
| 101 | Tshift_t shift_min ; |
---|
| 102 | Tshift_t shift_max ; |
---|
| 103 | Tdata_t data_out [param._nb_port]; |
---|
| 104 | string op ; |
---|
| 105 | |
---|
| 106 | if (param._shift_value != 0) |
---|
| 107 | { |
---|
| 108 | shift_min = param._shift_value; |
---|
| 109 | shift_max = param._shift_value; |
---|
| 110 | } |
---|
| 111 | else |
---|
| 112 | { |
---|
| 113 | shift_min = 0; |
---|
| 114 | shift_max = param._size_data-1; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | sc_start(0); |
---|
| 118 | |
---|
| 119 | for (uint32_t x=0; x<6; x++) |
---|
| 120 | { |
---|
| 121 | switch (x) |
---|
| 122 | { |
---|
| 123 | case 0 : |
---|
| 124 | if (param._have_shift_logic_left) |
---|
| 125 | { |
---|
| 126 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Left Logic" << endl; |
---|
| 127 | direction = _left ; |
---|
| 128 | type = _shift; |
---|
| 129 | carry = _logic; |
---|
| 130 | op = " sll " ; |
---|
| 131 | break; |
---|
| 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Left Logic" << endl; |
---|
| 136 | continue; |
---|
| 137 | } |
---|
| 138 | case 1 : |
---|
| 139 | if (param._have_shift_logic_right) |
---|
| 140 | { |
---|
| 141 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Right Logic" << endl; |
---|
| 142 | direction = _right; |
---|
| 143 | type = _shift; |
---|
| 144 | carry = _logic; |
---|
| 145 | op = " srl " ; |
---|
| 146 | break; |
---|
| 147 | } |
---|
| 148 | else |
---|
| 149 | { |
---|
| 150 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Right Logic" << endl; |
---|
| 151 | continue; |
---|
| 152 | } |
---|
| 153 | case 2 : |
---|
| 154 | if (param._have_shift_arithmetic_left) |
---|
| 155 | { |
---|
| 156 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Left Arithmetic" << endl; |
---|
| 157 | direction = _left ; |
---|
| 158 | type = _shift ; |
---|
| 159 | carry = _arithmetic; |
---|
| 160 | op = " sla " ; |
---|
| 161 | break; |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Left Arithmetic" << endl; |
---|
| 166 | continue; |
---|
| 167 | } |
---|
| 168 | case 3 : |
---|
| 169 | if (param._have_shift_arithmetic_right) |
---|
| 170 | { |
---|
| 171 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Shift Right Arithmetic" << endl; |
---|
| 172 | direction = _right; |
---|
| 173 | type = _shift; |
---|
| 174 | carry = _arithmetic; |
---|
| 175 | op = " sra " ; |
---|
| 176 | break; |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | { |
---|
| 180 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Shift Right Arithmetic" << endl; |
---|
| 181 | continue; |
---|
| 182 | } |
---|
| 183 | case 4 : |
---|
| 184 | if ( param._have_rotate_left) |
---|
| 185 | { |
---|
| 186 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Rotate Left" << endl; |
---|
| 187 | direction = _left ; |
---|
| 188 | type = _rotate; |
---|
| 189 | carry = _logic ; |
---|
| 190 | op = " rol "; |
---|
| 191 | break; |
---|
| 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
| 195 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate Left" << endl; |
---|
| 196 | continue; |
---|
| 197 | } |
---|
| 198 | case 5 : |
---|
| 199 | if (param._have_rotate_right) |
---|
| 200 | { |
---|
| 201 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Test Rotate Right" << endl; |
---|
| 202 | direction = _right; |
---|
| 203 | type = _rotate; |
---|
| 204 | carry = _logic ; |
---|
| 205 | op = " ror "; |
---|
| 206 | break; |
---|
| 207 | } |
---|
| 208 | else |
---|
| 209 | { |
---|
| 210 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} No Test Rotate Right" << endl; |
---|
| 211 | continue; |
---|
| 212 | } |
---|
| 213 | default : |
---|
| 214 | continue; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 218 | { |
---|
| 219 | SHIFTER_DIRECTION [i].write(direction ); |
---|
| 220 | SHIFTER_TYPE [i].write(type ); |
---|
| 221 | SHIFTER_CARRY [i].write(carry ); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | for (uint32_t it=0; it < iteration; it++) |
---|
| 225 | { |
---|
| 226 | for (Tshift_t shift=shift_min; shift<=shift_max; shift++) |
---|
| 227 | { |
---|
| 228 | Tdata_t mask_left = 0; |
---|
| 229 | Tdata_t mask_right = 0; |
---|
| 230 | |
---|
| 231 | if (param._size_data_completion > 0) |
---|
| 232 | { |
---|
| 233 | mask_left = gen_mask<Tdata_t> (shift); |
---|
| 234 | mask_right = mask_left << (param._size_data - shift); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 238 | { |
---|
| 239 | data_in [i] = rand() % data_max; |
---|
| 240 | data_completion [i] = (rand() % data_max) & gen_mask<Tdata_t>(param._size_data_completion); |
---|
| 241 | |
---|
| 242 | switch (x) |
---|
| 243 | { |
---|
| 244 | case 0 : data_out [i] =((shift_logic_left <Tdata_t>(param._size_data, data_in[i], shift) & ~mask_left ) | (data_completion [i] & mask_left )); break; |
---|
| 245 | case 1 : data_out [i] =((shift_logic_right <Tdata_t>(param._size_data, data_in[i], shift) & ~mask_right) | (data_completion [i] & mask_right)); break; |
---|
| 246 | case 2 : data_out [i] = shift_arithmetic_left <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
| 247 | case 3 : data_out [i] = shift_arithmetic_right <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
| 248 | case 4 : data_out [i] = rotate_left <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
| 249 | case 5 : data_out [i] = rotate_right <Tdata_t>(param._size_data, data_in[i], shift); break; |
---|
| 250 | default : break; |
---|
| 251 | } |
---|
| 252 | SHIFTER_DATA_IN [i].write(data_in [i]); |
---|
| 253 | SHIFTER_SHIFT [i].write(shift ); |
---|
| 254 | if (param._type_completion_bool == true) |
---|
| 255 | SHIFTER_CARRY_IN [i].write(data_completion [i]!=0); |
---|
| 256 | else |
---|
| 257 | SHIFTER_COMPLETION[i].write(data_completion [i]); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | sc_start(0); |
---|
| 261 | |
---|
| 262 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "}" << endl; |
---|
| 263 | |
---|
| 264 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 265 | { |
---|
| 266 | cout << "\t[" << i << "] " |
---|
| 267 | << hex |
---|
| 268 | << data_in[i] << op |
---|
| 269 | << dec |
---|
| 270 | << shift << " = " |
---|
| 271 | << hex |
---|
| 272 | << SHIFTER_DATA_OUT [i].read() |
---|
| 273 | << " - completion : " |
---|
| 274 | << data_completion [i] |
---|
| 275 | << dec ; |
---|
| 276 | |
---|
| 277 | TEST(Tdata_t,SHIFTER_DATA_OUT [i].read(),data_out[i]); |
---|
| 278 | } |
---|
| 279 | sc_start(1); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | sc_start(0); |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | /******************************************************** |
---|
| 288 | * Simulation - End |
---|
| 289 | ********************************************************/ |
---|
| 290 | |
---|
| 291 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 292 | |
---|
| 293 | #endif |
---|
| 294 | |
---|
| 295 | delete _Shifter; |
---|
| 296 | } |
---|