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