[10] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Generic/Victim/Pseudo_LRU/SelfTest/include/test.h" |
---|
| 10 | #include "Include/Test.h" |
---|
| 11 | |
---|
| 12 | void test (string name, |
---|
| 13 | morpheo::behavioural::generic::victim::pseudo_lru::Parameters param) |
---|
| 14 | { |
---|
| 15 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 16 | |
---|
| 17 | if (param._nb_update < 1) |
---|
| 18 | { |
---|
| 19 | cerr << "<" << name << "> : To test, need a less one update's port" << endl; |
---|
| 20 | exit (EXIT_FAILURE); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | try |
---|
| 24 | { |
---|
| 25 | cout << param.print(1); |
---|
| 26 | param.test(); |
---|
| 27 | } |
---|
| 28 | catch (morpheo::ErrorMorpheo & error) |
---|
| 29 | { |
---|
| 30 | cout << "<" << name << "> : " << error.what (); |
---|
| 31 | return; |
---|
| 32 | } |
---|
| 33 | catch (...) |
---|
| 34 | { |
---|
| 35 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
| 36 | exit (EXIT_FAILURE); |
---|
| 37 | } |
---|
| 38 | Pseudo_LRU * _Pseudo_LRU = new Pseudo_LRU (name.c_str(), |
---|
| 39 | #ifdef STATISTICS |
---|
| 40 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
| 41 | #endif |
---|
| 42 | param); |
---|
| 43 | |
---|
| 44 | #ifdef SYSTEMC |
---|
| 45 | /********************************************************************* |
---|
| 46 | * Déclarations des signaux |
---|
| 47 | *********************************************************************/ |
---|
| 48 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
| 49 | |
---|
| 50 | sc_signal<Tcontrol_t> ACCESS_VAL [param._nb_access]; |
---|
| 51 | sc_signal<Tcontrol_t> ACCESS_ACK [param._nb_access]; |
---|
| 52 | sc_signal<Taddress_t> ACCESS_ADDRESS [param._nb_access]; |
---|
| 53 | sc_signal<Tentity_t > ACCESS_ENTITY [param._nb_access]; |
---|
| 54 | |
---|
| 55 | sc_signal<Tcontrol_t> UPDATE_VAL [param._nb_update]; |
---|
| 56 | sc_signal<Tcontrol_t> UPDATE_ACK [param._nb_update]; |
---|
| 57 | sc_signal<Taddress_t> UPDATE_ADDRESS [param._nb_update]; |
---|
| 58 | sc_signal<Tentity_t > UPDATE_ENTITY [param._nb_update]; |
---|
| 59 | |
---|
| 60 | /******************************************************** |
---|
| 61 | * Instanciation |
---|
| 62 | ********************************************************/ |
---|
| 63 | |
---|
| 64 | cout << "<" << name << "> Instanciation of _Pseudo_LRU" << endl; |
---|
| 65 | |
---|
| 66 | (*(_Pseudo_LRU->in_CLOCK)) (CLOCK); |
---|
| 67 | |
---|
| 68 | for (uint32_t i=0; i<param._nb_access; i++) |
---|
| 69 | { |
---|
| 70 | (*(_Pseudo_LRU-> in_ACCESS_VAL [i])) (ACCESS_VAL [i]); |
---|
| 71 | (*(_Pseudo_LRU->out_ACCESS_ACK [i])) (ACCESS_ACK [i]); |
---|
| 72 | if (param._size_table>1) |
---|
| 73 | (*(_Pseudo_LRU-> in_ACCESS_ADDRESS [i])) (ACCESS_ADDRESS [i]); |
---|
| 74 | (*(_Pseudo_LRU->out_ACCESS_ENTITY [i])) (ACCESS_ENTITY [i]); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | for (uint32_t i=0; i<param._nb_update; i++) |
---|
| 78 | { |
---|
| 79 | (*(_Pseudo_LRU-> in_UPDATE_VAL [i])) (UPDATE_VAL [i]); |
---|
| 80 | (*(_Pseudo_LRU->out_UPDATE_ACK [i])) (UPDATE_ACK [i]); |
---|
| 81 | if (param._size_table>1) |
---|
| 82 | (*(_Pseudo_LRU-> in_UPDATE_ADDRESS [i])) (UPDATE_ADDRESS [i]); |
---|
| 83 | (*(_Pseudo_LRU-> in_UPDATE_ENTITY [i])) (UPDATE_ENTITY [i]); |
---|
| 84 | } |
---|
| 85 | /******************************************************** |
---|
| 86 | * Simulation - Begin |
---|
| 87 | ********************************************************/ |
---|
| 88 | |
---|
| 89 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 90 | // Initialisation |
---|
| 91 | |
---|
| 92 | sc_start(0); |
---|
| 93 | |
---|
| 94 | bool array [param._nb_access][param._nb_entity]; |
---|
| 95 | |
---|
| 96 | for (uint32_t i=0; i<param._nb_access; i++) |
---|
| 97 | { |
---|
| 98 | ACCESS_VAL[i].write(0); |
---|
| 99 | } |
---|
| 100 | for (uint32_t i=0; i<param._nb_update; i++) |
---|
| 101 | { |
---|
| 102 | UPDATE_VAL[i].write(0); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | sc_start(5); |
---|
| 106 | cout << "-----[ Test Update ]------------------------------" << endl; |
---|
| 107 | for (uint32_t i=0; i<param._nb_update; i++) |
---|
| 108 | { |
---|
| 109 | UPDATE_VAL[i].write(1); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | for (uint32_t j=0; j<param._size_table; j+=param._nb_update) |
---|
| 113 | for (uint32_t k=0; k<param._nb_entity; k++) |
---|
| 114 | { |
---|
| 115 | cout << "time : " << static_cast<uint32_t>(sc_simulation_time()) << endl; |
---|
| 116 | for (uint32_t i=0; i<param._nb_update; i++) |
---|
| 117 | { |
---|
| 118 | |
---|
| 119 | Tcontrol_t val = static_cast<Tcontrol_t>((j+i)<param._size_table); |
---|
| 120 | Taddress_t addr; |
---|
| 121 | if (param._size_table>1) |
---|
| 122 | addr = static_cast<Taddress_t>((j+i)%param._size_table); |
---|
| 123 | else |
---|
| 124 | addr = 0; |
---|
| 125 | Tentity_t entity = (k+1)%param._nb_entity; |
---|
| 126 | UPDATE_VAL [i].write(val ); |
---|
| 127 | if (param._size_table>1) |
---|
| 128 | UPDATE_ADDRESS [i].write(addr); |
---|
| 129 | UPDATE_ENTITY [i].write(entity); |
---|
| 130 | |
---|
| 131 | sc_start(0); |
---|
| 132 | cout << "\t[" << i << "] " << val << " - " << UPDATE_ACK[i].read() << " addr : " << addr << " -> " << entity << endl; |
---|
| 133 | } |
---|
| 134 | sc_start(1); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | for (uint32_t i=0; i<param._nb_update; i++) |
---|
| 139 | { |
---|
| 140 | UPDATE_VAL[i].write(0); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | sc_start(5); |
---|
| 144 | |
---|
| 145 | cout << "-----[ Test Access ]------------------------------" << endl; |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | for (uint32_t j=0; j<param._size_table; j+=param._nb_access) |
---|
| 149 | { |
---|
| 150 | // init |
---|
| 151 | memset(static_cast<void*>(array),0,param._nb_access*param._nb_entity*sizeof(bool)); |
---|
| 152 | |
---|
| 153 | for (uint32_t k=0; k<param._nb_entity; k++) |
---|
| 154 | { |
---|
| 155 | |
---|
| 156 | cout << "time : " << static_cast<uint32_t>(sc_simulation_time()) << endl; |
---|
| 157 | for (uint32_t i=0; i<param._nb_access; i++) |
---|
| 158 | { |
---|
| 159 | Tcontrol_t val = static_cast<Tcontrol_t>((j+i)<param._size_table); |
---|
| 160 | Taddress_t addr ; |
---|
| 161 | if (param._size_table>1) |
---|
| 162 | addr = static_cast<Taddress_t>((j+i)%param._size_table); |
---|
| 163 | else |
---|
| 164 | addr = 0; |
---|
| 165 | ACCESS_VAL [i].write(val ); |
---|
| 166 | if (param._size_table>1) |
---|
| 167 | ACCESS_ADDRESS [i].write(addr); |
---|
| 168 | |
---|
| 169 | sc_start(0); |
---|
| 170 | |
---|
| 171 | Tentity_t entity = ACCESS_ENTITY [i].read(); |
---|
| 172 | |
---|
| 173 | cout << "\t[" << i << "] " << val << " - " << ACCESS_ACK[i].read() << " addr : " << addr << " -> " << entity << endl; |
---|
| 174 | |
---|
| 175 | TEST(bool,false,((val == true) && (array[i][entity] == true))); |
---|
| 176 | |
---|
| 177 | // if ((val == true) && (array[i][entity] == true)) |
---|
| 178 | // { |
---|
| 179 | // cout << "Test KO : Have already give this way" << endl; |
---|
| 180 | // exit (1); |
---|
| 181 | // } |
---|
| 182 | // else |
---|
| 183 | array[i][entity] = true; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | sc_start(1); |
---|
| 187 | |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | for (uint32_t i=0; i<param._nb_access; i++) |
---|
| 192 | { |
---|
| 193 | ACCESS_VAL[i].write(0); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | sc_start(0); |
---|
| 197 | |
---|
| 198 | /******************************************************** |
---|
| 199 | * Simulation - End |
---|
| 200 | ********************************************************/ |
---|
| 201 | |
---|
| 202 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 203 | |
---|
| 204 | #endif |
---|
| 205 | |
---|
| 206 | delete _Pseudo_LRU; |
---|
| 207 | } |
---|