21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include <boost/mpl/list.hpp>
26 #include "core/thread_pool_sequential.hpp"
27 #include "core/thread_pool_master.hpp"
28 #include "core/thread_pool_workers.hpp"
32 using namespace libjmmcg;
52 const typename priority_queue_t<Db, Sz, Jn, Mdl, PoolSize, GSSk>::
pool_type::
pool_type::
size_type priority_queue_t<Db, Sz, Jn, Mdl, PoolSize, GSSk>::
pool_size;
89 BOOST_AUTO_TEST_SUITE(thread_pool_tests)
91 BOOST_AUTO_TEST_SUITE(joinable)
93 BOOST_AUTO_TEST_SUITE(finite)
95 BOOST_AUTO_TEST_SUITE(nowait)
97 BOOST_AUTO_TEST_CASE_TEMPLATE(n_threads, T, finite_test_types) {
98 typedef typename T::pool_type pool_type;
99 typedef typename pool_type::joinable joinable;
100 typedef typename pool_type::nonjoinable nonjoinable;
102 constexpr unsigned test_size=1000;
104 std::mt19937_64 gen(42);
105 std::uniform_int_distribution<
int> distribution(std::numeric_limits<
int>::min()+1, std::numeric_limits<
int>::max()-1);
106 auto rand=std::bind(distribution, gen);
108 pool_type pool(T::pool_size);
109 for (
unsigned i=0;i<test_size; ++i) {
110 pool<<nonjoinable()<<work_type_simple(rand());
112 BOOST_CHECK_GT(pool.queue_size(), 0U);
115 BOOST_CHECK_EQUAL(pool.pool_size(), T::pool_size);
116 BOOST_CHECK_EQUAL(pool.queue_size(), 0U);
119 BOOST_AUTO_TEST_SUITE_END()
121 BOOST_AUTO_TEST_SUITE(wait_dataflow)
123 BOOST_AUTO_TEST_CASE_TEMPLATE(add_one_work, T, finite_test_types) {
124 typedef typename T::pool_type pool_type;
125 typedef typename pool_type::joinable joinable;
127 constexpr unsigned test_size=10;
129 std::mt19937_64 gen(42);
130 std::uniform_int_distribution<
int> distribution(std::numeric_limits<
int>::min()+1, std::numeric_limits<
int>::max()-1);
131 auto rand=std::bind(distribution, gen);
133 pool_type pool(T::pool_size);
134 for (
unsigned i=0;i<test_size; ++i) {
135 auto const &exec0=pool<<joinable()<<work_type_simple(rand());
136 auto const &exec1=pool<<joinable()<<work_type_simple(rand());
137 auto const &exec2=pool<<joinable()<<work_type_simple(rand());
138 auto const &exec3=pool<<joinable()<<work_type_simple(rand());
139 auto const &exec4=pool<<joinable()<<work_type_simple(rand());
140 auto const &exec5=pool<<joinable()<<work_type_simple(rand());
141 auto const &exec6=pool<<joinable()<<work_type_simple(rand());
142 auto const &exec7=pool<<joinable()<<work_type_simple(rand());
143 auto const &exec8=pool<<joinable()<<work_type_simple(rand());
144 auto const &exec9=pool<<joinable()<<work_type_simple(rand());
156 BOOST_CHECK_EQUAL(pool.pool_size(), T::pool_size);
157 BOOST_CHECK_EQUAL(pool.queue_size(), 0U);
160 BOOST_AUTO_TEST_SUITE_END()
162 BOOST_AUTO_TEST_SUITE_END()
164 BOOST_AUTO_TEST_SUITE(infinite)
166 BOOST_AUTO_TEST_SUITE(wait_dataflow)
168 BOOST_AUTO_TEST_CASE_TEMPLATE(add_one_work, T, infinite_test_types) {
169 typedef typename T::pool_type pool_type;
170 typedef typename pool_type::joinable joinable;
172 constexpr unsigned test_size=100;
174 std::mt19937_64 gen(42);
175 std::uniform_int_distribution<
int> distribution(std::numeric_limits<
int>::min()+1, std::numeric_limits<
int>::max()-1);
176 auto rand=std::bind(distribution, gen);
179 for (
unsigned i=0;i<test_size; ++i) {
180 auto const &exec0=pool<<joinable()<<work_type_simple(rand());
181 auto const &exec1=pool<<joinable()<<work_type_simple(rand());
182 auto const &exec2=pool<<joinable()<<work_type_simple(rand());
183 auto const &exec3=pool<<joinable()<<work_type_simple(rand());
184 auto const &exec4=pool<<joinable()<<work_type_simple(rand());
185 auto const &exec5=pool<<joinable()<<work_type_simple(rand());
186 auto const &exec6=pool<<joinable()<<work_type_simple(rand());
187 auto const &exec7=pool<<joinable()<<work_type_simple(rand());
188 auto const &exec8=pool<<joinable()<<work_type_simple(rand());
189 auto const &exec9=pool<<joinable()<<work_type_simple(rand());
201 BOOST_CHECK_EQUAL(pool.queue_size(), 0U);
204 BOOST_AUTO_TEST_SUITE_END()
206 BOOST_AUTO_TEST_SUITE_END()
208 BOOST_AUTO_TEST_SUITE_END()
210 BOOST_AUTO_TEST_SUITE_END()