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

Last change on this file since 141 was 138, checked in by rosiere, 14 years ago

1) add counters_t type for interface
2) fix in check load in load_store_unit
3) add parameters (but not yet implemented)
4) change environment and add script (distcc_env.sh ...)
5) add warning if an unser change rename flag with l.mtspr instruction
6) ...

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