1 #include <boost/test/unit_test.hpp>
5 #include "dsp_thread_queue/dsp_thread.hpp"
6 #include "server/memory_pool.hpp"
19 void operator()(uint dummy
)
23 for (int j
= 0; j
!= 1000; ++j
)
37 template <typename Alloc
>
40 nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> t(1);
43 BOOST_AUTO_TEST_CASE( dsp_thread_test_1
)
45 nova::rt_pool
.init(1024*1024*128);
46 run_test_1
<std::allocator
<void*> >();
47 run_test_1
<nova::rt_pool_allocator
<void*> >();
50 template <typename Alloc
>
53 nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> t(5);
55 t
.terminate_threads();
59 BOOST_AUTO_TEST_CASE( dsp_thread_test_2
)
61 run_test_2
<std::allocator
<void*> >();
62 run_test_2
<nova::rt_pool_allocator
<void*> >();
65 template <typename Alloc
>
68 nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> t(2);
71 t
.terminate_threads();
74 BOOST_AUTO_TEST_CASE( dsp_thread_test_3
)
76 run_test_3
<std::allocator
<void*> >();
77 run_test_3
<nova::rt_pool_allocator
<void*> >();
80 template <typename Alloc
>
83 typedef typename
nova::dsp_thread_queue_item
<dummy_runnable
, Alloc
> dsp_thread_queue_item
;
84 typedef typename
nova::dsp_thread_queue
<dummy_runnable
, Alloc
> dsp_thread_queue
;
86 typedef typename
nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> dsp_threads
;
87 typedef std::unique_ptr
<dsp_thread_queue
> dsp_thread_queue_ptr
;
92 dsp_thread_queue_ptr
q (new dsp_thread_queue(2));
94 dsp_thread_queue_item
* item1
= q
->allocate_queue_item(dummy
, typename
dsp_thread_queue_item::successor_list(), 1);
96 typename
dsp_thread_queue_item::successor_list
sl(1);
99 dsp_thread_queue_item
* item2
= q
->allocate_queue_item(dummy
, sl
, 0);
100 q
->add_initially_runnable(item2
);
102 t
.reset_queue(std::move(q
));
106 t
.terminate_threads();
108 BOOST_REQUIRE_EQUAL(item1
->get_job().i
, 1);
109 BOOST_REQUIRE_EQUAL(item2
->get_job().i
, 1);
114 BOOST_AUTO_TEST_CASE( dsp_thread_test_4
)
116 run_test_4
<std::allocator
<void*> >();
117 run_test_4
<nova::rt_pool_allocator
<void*> >();
120 template <typename Alloc
>
121 void run_test_5(void)
123 typedef nova::dsp_thread_queue_item
<dummy_runnable
, Alloc
> dsp_thread_queue_item
;
124 typedef nova::dsp_thread_queue
<dummy_runnable
, Alloc
> dsp_thread_queue
;
125 typedef nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> dsp_threads
;
127 typedef std::unique_ptr
<dsp_thread_queue
> dsp_thread_queue_ptr
;
132 dsp_thread_queue_ptr
q (new dsp_thread_queue(5));
134 dsp_thread_queue_item
* item1
= q
->allocate_queue_item(dummy
, typename
dsp_thread_queue_item::successor_list(), 4);
136 typename
dsp_thread_queue_item::successor_list
sl(1);
139 dsp_thread_queue_item
* item2
= q
->allocate_queue_item(dummy
, sl
, 0);
140 q
->add_initially_runnable(item2
);
142 dsp_thread_queue_item
* item3
= q
->allocate_queue_item(dummy
, sl
, 0);
143 q
->add_initially_runnable(item3
);
145 dsp_thread_queue_item
* item4
= q
->allocate_queue_item(dummy
, sl
, 0);
146 q
->add_initially_runnable(item4
);
148 dsp_thread_queue_item
* item5
= q
->allocate_queue_item(dummy
, sl
, 0);
149 q
->add_initially_runnable(item5
);
151 t
.reset_queue(std::move(q
));
155 t
.terminate_threads();
157 BOOST_REQUIRE_EQUAL(item1
->get_job().i
, 1);
158 BOOST_REQUIRE_EQUAL(item2
->get_job().i
, 1);
159 BOOST_REQUIRE_EQUAL(item3
->get_job().i
, 1);
160 BOOST_REQUIRE_EQUAL(item4
->get_job().i
, 1);
161 BOOST_REQUIRE_EQUAL(item5
->get_job().i
, 1);
166 BOOST_AUTO_TEST_CASE( dsp_thread_test_5
)
168 run_test_5
<std::allocator
<void*> >();
169 run_test_5
<nova::rt_pool_allocator
<void*> >();
172 template <typename Alloc
>
173 void run_test_6(void)
175 typedef nova::dsp_thread_queue_item
<dummy_runnable
, Alloc
> dsp_thread_queue_item
;
176 typedef nova::dsp_thread_queue
<dummy_runnable
, Alloc
> dsp_thread_queue
;
177 typedef nova::dsp_threads
<dummy_runnable
, nova::nop_thread_init
, Alloc
> dsp_threads
;
179 typedef std::unique_ptr
<dsp_thread_queue
> dsp_thread_queue_ptr
;
184 dsp_thread_queue_ptr
q (new dsp_thread_queue(20));
186 std::vector
<dsp_thread_queue_item
*> items
;
188 for (int i
= 0; i
!= 20; ++i
)
190 items
.push_back(q
->allocate_queue_item(dummy
, typename
dsp_thread_queue_item::successor_list(), 0));
191 q
->add_initially_runnable(items
.back());
194 t
.reset_queue(std::move(q
));
196 const int iterations
= 10000;
198 for (int i
= 0; i
!= iterations
; ++i
)
200 for (int item
= 0; item
!= 20; ++item
)
201 BOOST_REQUIRE_EQUAL(items
[item
]->get_job().i
, i
);
205 t
.terminate_threads();
207 for (int i
= 0; i
!= 20; ++i
)
208 BOOST_REQUIRE_EQUAL(items
[i
]->get_job().i
, iterations
);
211 BOOST_AUTO_TEST_CASE( dsp_thread_test_6
)
213 run_test_6
<std::allocator
<void*> >();
214 run_test_6
<nova::rt_pool_allocator
<void*> >();