source: trunk/IPs/systemC/Environment/Queue/selftest/main.cpp @ 108

Last change on this file since 108 was 81, checked in by rosiere, 17 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1#include "../include/Sort_Queue.h"
2#include "../include/Sort_Queue_Dynamic.h"
3#include <iostream>
4
5using namespace std;
6using namespace environment;
7using namespace environment::queue;
8
9
10#define TEST(x,y)                               \
11  {                                             \
12    cout << "Line " << __LINE__ << " : ";       \
13    if (x==y)                                   \
14      {                                         \
15        cout << "Test OK" << endl;              \
16      }                                         \
17    else                                        \
18      {                                         \
19        cout << "Test KO" << endl;              \
20        exit (EXIT_FAILURE);                    \
21      }                                         \
22  } while (0)
23
24class Entry
25{
26public : uint32_t _trdid;  // number of thread
27public : uint32_t _pktid;  // number of packet
28public : uint64_t _data;
29
30  Entry (void)
31  {
32    _trdid = 0;
33    _pktid = 0;
34    _data  = 0;
35  };
36 
37  Entry (uint32_t trdid ,
38         uint32_t pktid ,
39         uint64_t data  )
40  {
41    _trdid = trdid;
42    _pktid = pktid;
43    _data  = data ;
44  };
45 
46  friend std::ostream& operator<< (std::ostream& output, Entry x)
47  {
48    output << x._trdid << " " << x._pktid << " " << std::hex << x._data << std::dec;
49    return output;
50  }
51};
52
53
54#ifdef SYSTEMC
55int sc_main (int argc, char * argv[])
56#else
57int    main (int argc, char * argv[])
58#endif
59{
60  cout << "<main> Begin" << endl;
61
62  {
63    cout << "<main> * create and print a slot_t" << endl;
64    slot_t<uint32_t> * my_slot = new slot_t<uint32_t> (12, 0xdeadbeef);
65    cout << *my_slot << endl;
66   
67    delete my_slot;
68  }
69 
70  {
71    cout << "==================================" << endl; 
72    cout << "=====[ Sort_Queue ]===============" << endl;
73    cout << "==================================" << endl;     
74    cout << "<main>  * create a queue, size = 5" << endl;
75    Parameters * param = new Parameters (5);
76   
77    Sort_Queue <Entry> * my_Sort_Queue = new Sort_Queue <Entry> ("my_queue",param);
78   
79    cout << " * must be empty ..." << endl;
80    TEST(my_Sort_Queue->empty(),true );
81    TEST(my_Sort_Queue->full (),false);
82   
83    cout << " * insert 6 elements" << endl;
84   
85    TEST(my_Sort_Queue->push((uint32_t)5,Entry(1,1,0x33333333)),true ); cout << *my_Sort_Queue << endl;
86    TEST(my_Sort_Queue->push((uint32_t)6,Entry(2,2,0x55555555)),true ); cout << *my_Sort_Queue << endl;
87    TEST(my_Sort_Queue->push((uint32_t)3,Entry(3,3,0x22222222)),true ); cout << *my_Sort_Queue << endl;
88    TEST(my_Sort_Queue->push((uint32_t)5,Entry(4,4,0x44444444)),true ); cout << *my_Sort_Queue << endl;
89    TEST(my_Sort_Queue->push((uint32_t)1,Entry(5,5,0x11111111)),true ); cout << *my_Sort_Queue << endl;
90    TEST(my_Sort_Queue->push((uint32_t)4,Entry(6,6,0x00000BAD)),false); cout << *my_Sort_Queue << endl;
91   
92    cout << " * extract 6 elements" << endl;
93    TEST(my_Sort_Queue->pop()._data,0x11111111); cout << *my_Sort_Queue << endl;
94    TEST(my_Sort_Queue->empty(),false);
95    TEST(my_Sort_Queue->pop()._data,0x22222222); cout << *my_Sort_Queue << endl;
96    TEST(my_Sort_Queue->empty(),false);
97    TEST(my_Sort_Queue->pop()._data,0x33333333); cout << *my_Sort_Queue << endl;
98    TEST(my_Sort_Queue->empty(),false);
99    TEST(my_Sort_Queue->pop()._data,0x44444444); cout << *my_Sort_Queue << endl;
100    TEST(my_Sort_Queue->empty(),false);
101    TEST(my_Sort_Queue->pop()._data,0x55555555); cout << *my_Sort_Queue << endl;
102    TEST(my_Sort_Queue->empty(),true );
103   
104    cout << " * ajout de 8 elements (reset apres le deuxieme)" << endl;
105   
106    TEST(my_Sort_Queue->push((uint32_t)5,Entry(1,1,0x44444444)),true ); cout << *my_Sort_Queue << endl;
107    TEST(my_Sort_Queue->push((uint32_t)6,Entry(2,2,0x55555555)),true ); cout << *my_Sort_Queue << endl;
108    my_Sort_Queue->reset();                                               
109    TEST(my_Sort_Queue->push((uint32_t)3,Entry(3,3,0x22222222)),true ); cout << *my_Sort_Queue << endl;
110    TEST(my_Sort_Queue->push((uint32_t)5,Entry(4,4,0x33333333)),true ); cout << *my_Sort_Queue << endl;
111    TEST(my_Sort_Queue->push((uint32_t)5,Entry(1,1,0x44444444)),true ); cout << *my_Sort_Queue << endl;
112    TEST(my_Sort_Queue->push((uint32_t)7,Entry(2,2,0x55555555)),true ); cout << *my_Sort_Queue << endl;
113    TEST(my_Sort_Queue->push((uint32_t)1,Entry(5,5,0x11111111)),true ); cout << *my_Sort_Queue << endl;
114    TEST(my_Sort_Queue->push((uint32_t)4,Entry(6,6,0x00000BAD)),false); cout << *my_Sort_Queue << endl;
115   
116    cout << " * 3 transitions" << endl;
117   
118    my_Sort_Queue->transition(); cout << *my_Sort_Queue << endl;
119    my_Sort_Queue->transition(); cout << *my_Sort_Queue << endl;
120    my_Sort_Queue->transition(); cout << *my_Sort_Queue << endl;
121   
122    cout << " * extract 1 element" << endl;
123   
124    TEST(my_Sort_Queue->pop()._data,0x11111111);
125   
126    cout << *my_Sort_Queue << endl;
127   
128    for (uint32_t it = 0; it < my_Sort_Queue->nb_slot_use(); it ++)
129      {
130        slot_t<Entry> val = my_Sort_Queue->read(it);
131        cout << val._delay << " " << val._data << endl;
132      }
133   
134    cout << " * Test pop(n)" << endl;
135   
136    TEST(my_Sort_Queue->pop(1)._data, 0x33333333);
137    TEST(my_Sort_Queue->pop(2)._data, 0x55555555);
138    TEST(my_Sort_Queue->pop(0)._data, 0x22222222);
139    TEST(my_Sort_Queue->pop(0)._data, 0x44444444);
140   
141    delete my_Sort_Queue;
142    delete param;
143  }
144
145  {
146    cout << "==================================" << endl; 
147    cout << "=====[ Sort_Queue_Dynamic ]=======" << endl;
148    cout << "==================================" << endl;     
149    cout << "<main>  * create a queue, size = 5" << endl;
150    Parameters * param = new Parameters (5);
151   
152    Sort_Queue_Dynamic <Entry> * my_Sort_Queue_Dynamic = new Sort_Queue_Dynamic <Entry> ("my_queue",param);
153
154    cout << " * must be empty ..." << endl;
155   
156    TEST(my_Sort_Queue_Dynamic->empty(),true);
157    TEST(my_Sort_Queue_Dynamic->full (),false);
158
159    TEST(my_Sort_Queue_Dynamic->push(5,Entry(1,1, 4)),true ); cout << *my_Sort_Queue_Dynamic << endl;
160    TEST(my_Sort_Queue_Dynamic->push(6,Entry(2,2, 6)),true ); cout << *my_Sort_Queue_Dynamic << endl;
161    TEST(my_Sort_Queue_Dynamic->push(3,Entry(3,3, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
162    TEST(my_Sort_Queue_Dynamic->push(5,Entry(4,4, 5)),true ); cout << *my_Sort_Queue_Dynamic << endl;
163    TEST(my_Sort_Queue_Dynamic->push(1,Entry(5,5, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
164    TEST(my_Sort_Queue_Dynamic->push(4,Entry(6,6, 3)),true ); cout << *my_Sort_Queue_Dynamic << endl;
165    TEST(my_Sort_Queue_Dynamic->push(9,Entry(1,1,12)),true ); cout << *my_Sort_Queue_Dynamic << endl;
166    TEST(my_Sort_Queue_Dynamic->push(6,Entry(2,2, 7)),true ); cout << *my_Sort_Queue_Dynamic << endl;
167    TEST(my_Sort_Queue_Dynamic->push(7,Entry(3,3, 8)),true ); cout << *my_Sort_Queue_Dynamic << endl;
168    TEST(my_Sort_Queue_Dynamic->push(7,Entry(4,4, 9)),true ); cout << *my_Sort_Queue_Dynamic << endl;
169    TEST(my_Sort_Queue_Dynamic->push(8,Entry(5,5,11)),true ); cout << *my_Sort_Queue_Dynamic << endl;
170    TEST(my_Sort_Queue_Dynamic->push(7,Entry(6,6,10)),true ); cout << *my_Sort_Queue_Dynamic << endl;
171
172    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 ); cout << *my_Sort_Queue_Dynamic << endl;
173    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 ); cout << *my_Sort_Queue_Dynamic << endl;
174    TEST(my_Sort_Queue_Dynamic->pop()._data, 3 ); cout << *my_Sort_Queue_Dynamic << endl;
175    TEST(my_Sort_Queue_Dynamic->pop()._data, 4 ); cout << *my_Sort_Queue_Dynamic << endl;
176    TEST(my_Sort_Queue_Dynamic->pop()._data, 5 ); cout << *my_Sort_Queue_Dynamic << endl;
177    TEST(my_Sort_Queue_Dynamic->pop()._data, 6 ); cout << *my_Sort_Queue_Dynamic << endl;
178    TEST(my_Sort_Queue_Dynamic->pop()._data, 7 ); cout << *my_Sort_Queue_Dynamic << endl;
179    TEST(my_Sort_Queue_Dynamic->pop()._data, 8 ); cout << *my_Sort_Queue_Dynamic << endl;
180    TEST(my_Sort_Queue_Dynamic->pop()._data, 9 ); cout << *my_Sort_Queue_Dynamic << endl;
181    TEST(my_Sort_Queue_Dynamic->pop()._data,10 ); cout << *my_Sort_Queue_Dynamic << endl;
182    TEST(my_Sort_Queue_Dynamic->pop()._data,11 ); cout << *my_Sort_Queue_Dynamic << endl;
183    TEST(my_Sort_Queue_Dynamic->pop()._data,12 ); cout << *my_Sort_Queue_Dynamic << endl;
184
185
186    TEST(my_Sort_Queue_Dynamic->push(5,Entry(1,1, 4)),true ); cout << *my_Sort_Queue_Dynamic << endl;
187    TEST(my_Sort_Queue_Dynamic->push(6,Entry(2,2, 6)),true ); cout << *my_Sort_Queue_Dynamic << endl;
188    TEST(my_Sort_Queue_Dynamic->push(3,Entry(3,3, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
189    TEST(my_Sort_Queue_Dynamic->push(5,Entry(4,4, 5)),true ); cout << *my_Sort_Queue_Dynamic << endl;
190    TEST(my_Sort_Queue_Dynamic->push(1,Entry(5,5, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
191    TEST(my_Sort_Queue_Dynamic->push(4,Entry(6,6, 3)),true ); cout << *my_Sort_Queue_Dynamic << endl;
192    TEST(my_Sort_Queue_Dynamic->push(9,Entry(1,1,12)),true ); cout << *my_Sort_Queue_Dynamic << endl;
193    TEST(my_Sort_Queue_Dynamic->push(6,Entry(2,2, 7)),true ); cout << *my_Sort_Queue_Dynamic << endl;
194    TEST(my_Sort_Queue_Dynamic->push(7,Entry(3,3, 8)),true ); cout << *my_Sort_Queue_Dynamic << endl;
195    TEST(my_Sort_Queue_Dynamic->push(7,Entry(4,4, 9)),true ); cout << *my_Sort_Queue_Dynamic << endl;
196    TEST(my_Sort_Queue_Dynamic->push(8,Entry(5,5,11)),true ); cout << *my_Sort_Queue_Dynamic << endl;
197    TEST(my_Sort_Queue_Dynamic->push(7,Entry(6,6,10)),true ); cout << *my_Sort_Queue_Dynamic << endl;
198
199    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 )            ; cout << *my_Sort_Queue_Dynamic << endl;
200    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 )            ; cout << *my_Sort_Queue_Dynamic << endl;
201
202    TEST(my_Sort_Queue_Dynamic->push(0,Entry(1,1, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
203    TEST(my_Sort_Queue_Dynamic->push(0,Entry(2,2, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
204    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 )            ; cout << *my_Sort_Queue_Dynamic << endl;
205    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 )            ; cout << *my_Sort_Queue_Dynamic << endl;
206    TEST(my_Sort_Queue_Dynamic->push(0,Entry(1,1, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
207    TEST(my_Sort_Queue_Dynamic->push(0,Entry(2,2, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
208    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 )            ; cout << *my_Sort_Queue_Dynamic << endl;
209    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 )            ; cout << *my_Sort_Queue_Dynamic << endl;
210    TEST(my_Sort_Queue_Dynamic->push(0,Entry(1,1, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
211    TEST(my_Sort_Queue_Dynamic->push(0,Entry(2,2, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
212    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 )            ; cout << *my_Sort_Queue_Dynamic << endl;
213    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 )            ; cout << *my_Sort_Queue_Dynamic << endl;
214    TEST(my_Sort_Queue_Dynamic->push(0,Entry(1,1, 1)),true ); cout << *my_Sort_Queue_Dynamic << endl;
215    TEST(my_Sort_Queue_Dynamic->push(0,Entry(2,2, 2)),true ); cout << *my_Sort_Queue_Dynamic << endl;
216    TEST(my_Sort_Queue_Dynamic->pop()._data, 1 )            ; cout << *my_Sort_Queue_Dynamic << endl;
217    TEST(my_Sort_Queue_Dynamic->pop()._data, 2 )            ; cout << *my_Sort_Queue_Dynamic << endl;
218    TEST(my_Sort_Queue_Dynamic->pop()._data, 3 )            ; cout << *my_Sort_Queue_Dynamic << endl;
219    TEST(my_Sort_Queue_Dynamic->pop(2)._data, 6 )           ; cout << *my_Sort_Queue_Dynamic << endl;
220
221    delete my_Sort_Queue_Dynamic;
222    delete param;
223  }
224
225  cout << "<main> End" << endl;
226
227  return EXIT_SUCCESS;
228}
Note: See TracBrowser for help on using the repository browser.