20 #include <test/unit_test/multi_runner.h>
22 #include <beast/unit_test/amount.hpp>
24 #include <boost/lexical_cast.hpp>
40 fmtdur(
typename clock_type::duration
const& d)
43 auto const ms = duration_cast<milliseconds>(d);
45 return boost::lexical_cast<std::string>(ms.count()) +
"ms";
77 [](
run_time const& t1,
typename clock_type::duration
const& t2) {
78 return t1.second > t2;
81 if (iter !=
top.end())
93 top.resize(
top.size() - 1);
118 boost::container::static_vector<run_time, 2 * max_top> top_result;
119 top_result.resize(
top.size() + r.
top.size());
127 return t1.second > t2.second;
130 if (top_result.size() >
max_top)
144 s <<
"Longest suite times:\n";
145 for (
auto const& [name, dur] :
top)
150 s <<
fmtdur(elapsed) <<
", " << amount{
suites,
"suite"} <<
", "
151 << amount{
cases,
"case"} <<
", " << amount{
total,
"test"} <<
" total, "
157 template <
bool IsParent>
164 template <
bool IsParent>
168 return test_index_++;
171 template <
bool IsParent>
178 template <
bool IsParent>
182 any_failed_ = any_failed_ || v;
185 template <
bool IsParent>
190 return results_.total;
193 template <
bool IsParent>
198 return results_.suites;
201 template <
bool IsParent>
208 template <
bool IsParent>
215 template <
bool IsParent>
223 template <
bool IsParent>
232 template <
bool IsParent>
240 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
241 boost::interprocess::message_queue::remove(message_queue_name_);
244 shared_mem_ = boost::interprocess::shared_memory_object{
247 boost::interprocess::create_only_t,
248 boost::interprocess::open_only_t>{},
250 boost::interprocess::read_write};
254 shared_mem_.truncate(
sizeof(inner));
256 std::make_unique<boost::interprocess::message_queue>(
257 boost::interprocess::create_only,
265 std::make_unique<boost::interprocess::message_queue>(
266 boost::interprocess::open_only, message_queue_name_);
269 region_ = boost::interprocess::mapped_region{
270 shared_mem_, boost::interprocess::read_write};
272 inner_ =
new (region_.get_address()) inner{};
274 inner_ =
reinterpret_cast<inner*
>(region_.get_address());
280 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
281 boost::interprocess::message_queue::remove(message_queue_name_);
287 template <
bool IsParent>
293 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
294 boost::interprocess::message_queue::remove(message_queue_name_);
298 template <
bool IsParent>
302 return inner_->checkout_test_index();
305 template <
bool IsParent>
309 return inner_->checkout_job_index();
312 template <
bool IsParent>
316 return inner_->any_failed();
319 template <
bool IsParent>
323 return inner_->any_failed(v);
326 template <
bool IsParent>
333 template <
bool IsParent>
337 inner_->inc_keep_alive_count();
340 template <
bool IsParent>
344 return inner_->get_keep_alive_count();
347 template <
bool IsParent>
352 inner_->print_results(s);
355 template <
bool IsParent>
363 message_queue_->send(&mt,
sizeof(mt), 0);
364 message_queue_->send(s.
c_str(), s.
size(), 0);
367 template <
bool IsParent>
371 return inner_->tests();
374 template <
bool IsParent>
378 return inner_->suites();
381 template <
bool IsParent>
388 any_failed(failures != 0);
391 template <
bool IsParent>
393 template <
bool IsParent>
421 unsigned int priority = 0;
423 buf.
data(), buf.
size(), recvd_size, priority);
426 assert(recvd_size == 1);
430 buf.
data(), buf.
size(), recvd_size, priority);
436 case MessageType::log:
440 case MessageType::test_start:
443 case MessageType::test_end:
454 <<
" reading unit test message queue.\n";
459 std::cerr <<
"Unknown error reading unit test message queue.\n";
477 os_ <<
"\nSuite: " << s
478 <<
" failed to complete. The child process may have crashed.\n";
513 , num_jobs_{num_jobs}
515 , print_log_{!quiet || print_log}
524 while (this->continue_keep_alive_)
530 auto cur_count = this->get_keep_alive_count();
531 if (cur_count == last_count)
535 cur_count = this->get_keep_alive_count();
536 if (cur_count == last_count)
539 std::cerr <<
"multi_runner_child " << job_index_
540 <<
": Assuming parent died, exiting.\n";
544 last_count = cur_count;
649 template class multi_runner_base<true>;
650 template class multi_runner_base<false>;