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