[2] | 1 | /* |
---|
| 2 | * $Id: test.cpp 88 2008-12-10 18:31:39Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define NB_ITERATION 1024 |
---|
[82] | 10 | #define CYCLE_MAX 1024*NB_ITERATION |
---|
[2] | 11 | |
---|
| 12 | #include "Behavioural/Generic/Counter/SelfTest/include/test.h" |
---|
[44] | 13 | #include "Common/include/Test.h" |
---|
[2] | 14 | |
---|
| 15 | void test (string name, |
---|
| 16 | morpheo::behavioural::generic::counter::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 | } |
---|
[71] | 35 | #ifdef STATISTICS |
---|
| 36 | morpheo::behavioural::Parameters_Statistics * param_stat = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
| 37 | #endif |
---|
| 38 | |
---|
[88] | 39 | Tusage_t _usage = USE_ALL; |
---|
| 40 | |
---|
| 41 | // _usage = usage_unset(_usage,USE_SYSTEMC ); |
---|
| 42 | // _usage = usage_unset(_usage,USE_VHDL ); |
---|
| 43 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH ); |
---|
| 44 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT); |
---|
| 45 | // _usage = usage_unset(_usage,USE_POSITION ); |
---|
| 46 | // _usage = usage_unset(_usage,USE_STATISTICS ); |
---|
| 47 | // _usage = usage_unset(_usage,USE_INFORMATION ); |
---|
| 48 | |
---|
[2] | 49 | Counter * _Counter = new Counter (name.c_str(), |
---|
| 50 | #ifdef STATISTICS |
---|
[71] | 51 | param_stat, |
---|
[2] | 52 | #endif |
---|
[82] | 53 | param, |
---|
[88] | 54 | _usage); |
---|
[2] | 55 | |
---|
| 56 | #ifdef SYSTEMC |
---|
| 57 | /********************************************************************* |
---|
| 58 | * Déclarations des signaux |
---|
| 59 | *********************************************************************/ |
---|
| 60 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
[42] | 61 | sc_signal<Tcontrol_t> RESET; |
---|
[2] | 62 | sc_signal<Tdata_t> DATA_IN [param._nb_port]; |
---|
| 63 | sc_signal<Tcontrol_t> ADDSUB [param._nb_port]; |
---|
| 64 | sc_signal<Tdata_t> DATA_OUT [param._nb_port]; |
---|
| 65 | |
---|
| 66 | /******************************************************** |
---|
| 67 | * Instanciation |
---|
| 68 | ********************************************************/ |
---|
| 69 | |
---|
| 70 | cout << "<" << name << "> Instanciation of _Counter" << endl; |
---|
| 71 | |
---|
| 72 | (*(_Counter->in_CLOCK)) (CLOCK); |
---|
[42] | 73 | (*(_Counter->in_NRESET)) (RESET); |
---|
[2] | 74 | |
---|
| 75 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 76 | { |
---|
| 77 | (*(_Counter-> in_COUNTER_DATA [i])) (DATA_IN [i]); |
---|
| 78 | (*(_Counter-> in_COUNTER_ADDSUB[i])) (ADDSUB [i]); |
---|
| 79 | (*(_Counter->out_COUNTER_DATA [i])) (DATA_OUT [i]); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | /******************************************************** |
---|
| 83 | * Simulation - Begin |
---|
| 84 | ********************************************************/ |
---|
| 85 | |
---|
| 86 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 87 | // Initialisation |
---|
| 88 | |
---|
| 89 | srand(0); |
---|
| 90 | //srand(TIME(NULL)); |
---|
| 91 | |
---|
| 92 | Tdata_t data_in [param._nb_port]; |
---|
| 93 | Tdata_t data_out [param._nb_port]; |
---|
| 94 | Tcontrol_t addsub [param._nb_port]; |
---|
| 95 | |
---|
| 96 | sc_start(0); |
---|
[42] | 97 | |
---|
| 98 | RESET.write(1); |
---|
| 99 | |
---|
[2] | 100 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 101 | |
---|
| 102 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
| 103 | |
---|
| 104 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 105 | { |
---|
| 106 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Itération " << iteration << endl; |
---|
| 107 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 108 | { |
---|
| 109 | Tdata_t data = rand()%param._data_max; |
---|
| 110 | data_in [i] = data; |
---|
| 111 | addsub [i] = (rand()%2)==1; |
---|
| 112 | |
---|
| 113 | DATA_IN [i].write(data ); |
---|
| 114 | ADDSUB [i].write(addsub [i]); |
---|
| 115 | |
---|
| 116 | data_out [i] = (addsub[i]==1)?((data<param._data_max)?data+1:data):((data>0)?data-1:data); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | sc_start(0); |
---|
| 120 | |
---|
| 121 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
| 122 | { |
---|
| 123 | cout << hex |
---|
| 124 | << " [" << i << "] " |
---|
| 125 | << data_in [i]; |
---|
| 126 | |
---|
| 127 | if (addsub[i] == 1) |
---|
| 128 | cout << " ++"; |
---|
| 129 | else |
---|
| 130 | cout << " --"; |
---|
| 131 | |
---|
| 132 | cout << " = " |
---|
| 133 | << DATA_OUT [i].read(); |
---|
| 134 | |
---|
| 135 | TEST(Tdata_t,DATA_OUT [i].read(),data_out [i]); |
---|
| 136 | |
---|
[71] | 137 | cout << std::dec << endl; |
---|
[2] | 138 | } |
---|
| 139 | |
---|
| 140 | sc_start(1); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | sc_start(1); |
---|
| 144 | |
---|
| 145 | /******************************************************** |
---|
| 146 | * Simulation - End |
---|
| 147 | ********************************************************/ |
---|
| 148 | |
---|
| 149 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 150 | |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | delete _Counter; |
---|
[71] | 154 | #ifdef STATISTICS |
---|
| 155 | delete param_stat; |
---|
| 156 | #endif |
---|
| 157 | |
---|
[2] | 158 | } |
---|