[67] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Generic/Queue/SelfTest/include/test.h" |
---|
| 10 | #include "Common/include/Test.h" |
---|
| 11 | |
---|
| 12 | #define NB_ITERATION 1 |
---|
| 13 | #define CYCLE_MAX (2048*NB_ITERATION) |
---|
| 14 | |
---|
| 15 | #define LABEL(str) \ |
---|
| 16 | { \ |
---|
| 17 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} " << str << endl; \ |
---|
| 18 | } while(0) |
---|
| 19 | |
---|
| 20 | static uint32_t cycle = 0; |
---|
| 21 | |
---|
| 22 | #define SC_START(cycle_offset) \ |
---|
| 23 | do \ |
---|
| 24 | { \ |
---|
| 25 | /*cout << "SC_START (begin)" << endl;*/ \ |
---|
| 26 | \ |
---|
| 27 | uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \ |
---|
| 28 | if (cycle_current != cycle) \ |
---|
| 29 | { \ |
---|
| 30 | cycle = cycle_current; \ |
---|
| 31 | cout << "##########[ cycle "<< cycle << " ]" << endl; \ |
---|
| 32 | } \ |
---|
| 33 | \ |
---|
| 34 | if (cycle_current > CYCLE_MAX) \ |
---|
| 35 | { \ |
---|
| 36 | TEST_KO("Maximal cycles Reached"); \ |
---|
| 37 | } \ |
---|
| 38 | sc_start(cycle_offset); \ |
---|
| 39 | /*cout << "SC_START (end )" << endl;*/ \ |
---|
| 40 | } while(0) |
---|
| 41 | |
---|
| 42 | void test (string name, |
---|
| 43 | morpheo::behavioural::generic::queue::Parameters * _param) |
---|
| 44 | { |
---|
| 45 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 46 | |
---|
| 47 | #ifdef STATISTICS |
---|
| 48 | morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
| 49 | #endif |
---|
| 50 | |
---|
| 51 | Queue * _Queue = new Queue (name.c_str(), |
---|
| 52 | #ifdef STATISTICS |
---|
| 53 | _parameters_statistics, |
---|
| 54 | #endif |
---|
| 55 | _param); |
---|
| 56 | |
---|
| 57 | #ifdef SYSTEMC |
---|
| 58 | /********************************************************************* |
---|
| 59 | * Déclarations des signaux |
---|
| 60 | *********************************************************************/ |
---|
| 61 | string rename; |
---|
| 62 | |
---|
| 63 | sc_clock * in_CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
| 64 | sc_signal<Tcontrol_t> * in_NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
| 65 | sc_signal<Tcontrol_t> * in_INSERT_VAL = new sc_signal<Tcontrol_t> ( "in_INSERT_VAL" ); |
---|
| 66 | sc_signal<Tcontrol_t> * out_INSERT_ACK = new sc_signal<Tcontrol_t> ("out_INSERT_ACK" ); |
---|
| 67 | sc_signal<Tdata_t > * in_INSERT_DATA = new sc_signal<Tdata_t > ( "in_INSERT_DATA"); |
---|
| 68 | sc_signal<Tcontrol_t> * out_RETIRE_VAL = new sc_signal<Tcontrol_t> ("out_RETIRE_VAL" ); |
---|
| 69 | sc_signal<Tcontrol_t> * in_RETIRE_ACK = new sc_signal<Tcontrol_t> ( "in_RETIRE_ACK" ); |
---|
| 70 | sc_signal<Tdata_t > * out_RETIRE_DATA = new sc_signal<Tdata_t > ("out_RETIRE_DATA"); |
---|
| 71 | |
---|
| 72 | /******************************************************** |
---|
| 73 | * Instanciation |
---|
| 74 | ********************************************************/ |
---|
| 75 | |
---|
| 76 | cout << "<" << name << "> Instanciation of _Queue" << endl; |
---|
| 77 | |
---|
| 78 | (*(_Queue->in_CLOCK)) (*(in_CLOCK)); |
---|
| 79 | (*(_Queue->in_NRESET)) (*(in_NRESET)); |
---|
| 80 | |
---|
| 81 | (*(_Queue-> in_INSERT_VAL )) (*( in_INSERT_VAL )); |
---|
| 82 | (*(_Queue->out_INSERT_ACK )) (*(out_INSERT_ACK )); |
---|
| 83 | (*(_Queue-> in_INSERT_DATA)) (*( in_INSERT_DATA)); |
---|
| 84 | (*(_Queue->out_RETIRE_VAL )) (*(out_RETIRE_VAL )); |
---|
| 85 | (*(_Queue-> in_RETIRE_ACK )) (*( in_RETIRE_ACK )); |
---|
| 86 | (*(_Queue->out_RETIRE_DATA)) (*(out_RETIRE_DATA)); |
---|
| 87 | |
---|
| 88 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 89 | Time * _time = new Time(); |
---|
| 90 | |
---|
| 91 | /******************************************************** |
---|
| 92 | * Simulation - Begin |
---|
| 93 | ********************************************************/ |
---|
| 94 | |
---|
| 95 | // Initialisation |
---|
| 96 | const int32_t percent_insert_transaction = 75; |
---|
| 97 | const int32_t percent_retire_transaction = 75; |
---|
| 98 | const uint32_t nb_request = 3*_param->_size_queue; |
---|
| 99 | |
---|
| 100 | const uint32_t seed = 0; |
---|
| 101 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
| 102 | |
---|
| 103 | srand(seed); |
---|
| 104 | |
---|
| 105 | SC_START(0); |
---|
| 106 | LABEL("Initialisation"); |
---|
| 107 | |
---|
| 108 | in_INSERT_VAL -> write(0); |
---|
| 109 | in_RETIRE_ACK -> write(0); |
---|
| 110 | |
---|
| 111 | LABEL("Reset"); |
---|
| 112 | in_NRESET->write(0); |
---|
| 113 | SC_START(5); |
---|
| 114 | in_NRESET->write(1); |
---|
| 115 | |
---|
| 116 | LABEL("Loop of Test"); |
---|
| 117 | |
---|
| 118 | uint32_t data_in = 0; |
---|
| 119 | uint32_t data_out = 0; |
---|
| 120 | |
---|
| 121 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 122 | { |
---|
| 123 | LABEL("Iteration "+toString(iteration)); |
---|
| 124 | |
---|
| 125 | while (data_out <= nb_request) |
---|
| 126 | { |
---|
| 127 | in_INSERT_VAL -> write((rand()%100)<percent_insert_transaction); |
---|
| 128 | in_INSERT_DATA -> write(data_in); |
---|
| 129 | in_RETIRE_ACK -> write((rand()%100)<percent_retire_transaction); |
---|
| 130 | |
---|
| 131 | SC_START(0); // genMoore |
---|
| 132 | |
---|
| 133 | if ( in_INSERT_VAL->read() and out_INSERT_ACK->read()) |
---|
| 134 | { |
---|
| 135 | LABEL ("Transaction with interface : INSERT"); |
---|
| 136 | data_in ++; |
---|
| 137 | } |
---|
| 138 | if (out_RETIRE_VAL->read() and in_RETIRE_ACK->read()) |
---|
| 139 | { |
---|
| 140 | LABEL ("Transaction with interface : RETIRE"); |
---|
| 141 | TEST(Tdata_t, out_RETIRE_DATA->read(), data_out); |
---|
| 142 | data_out++; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | SC_START(1); |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /******************************************************** |
---|
| 150 | * Simulation - End |
---|
| 151 | ********************************************************/ |
---|
| 152 | |
---|
| 153 | TEST_OK ("End of Simulation"); |
---|
| 154 | delete _time; |
---|
| 155 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 156 | |
---|
| 157 | delete in_CLOCK; |
---|
| 158 | delete in_NRESET; |
---|
| 159 | #endif |
---|
| 160 | |
---|
| 161 | delete _Queue; |
---|
| 162 | #ifdef STATISTICS |
---|
| 163 | delete _parameters_statistics; |
---|
| 164 | #endif |
---|
| 165 | } |
---|