20 #include <test/unit_test/multi_runner.h>
22 #include <ripple/beast/unit_test/amount.hpp>
24 #include <boost/lexical_cast.hpp>
41 fmtdur(
typename clock_type::duration
const& d)
44 auto const ms = duration_cast<milliseconds>(d);
46 return boost::lexical_cast<std::string>(ms.count()) +
"ms";
78 [](
run_time const& t1,
typename clock_type::duration
const& t2) {
79 return t1.second > t2;
82 if (iter !=
top.end())
94 top.resize(
top.size() - 1);
119 boost::container::static_vector<run_time, 2 * max_top> top_result;
120 top_result.resize(
top.size() + r.
top.size());
128 return t1.second > t2.second;
131 if (top_result.size() >
max_top)
145 s <<
"Longest suite times:\n";
146 for (
auto const& [name, dur] :
top)
151 s <<
fmtdur(elapsed) <<
", " << amount{
suites,
"suite"} <<
", "
152 << amount{
cases,
"case"} <<
", " << amount{
total,
"test"} <<
" total, "
158 template <
bool IsParent>
165 template <
bool IsParent>
169 return test_index_++;
172 template <
bool IsParent>
179 template <
bool IsParent>
183 any_failed_ = any_failed_ || v;
186 template <
bool IsParent>
191 return results_.total;
194 template <
bool IsParent>
199 return results_.suites;
202 template <
bool IsParent>
209 template <
bool IsParent>
216 template <
bool IsParent>
224 template <
bool IsParent>
233 template <
bool IsParent>
241 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
242 boost::interprocess::message_queue::remove(message_queue_name_);
245 shared_mem_ = boost::interprocess::shared_memory_object{
248 boost::interprocess::create_only_t,
249 boost::interprocess::open_only_t>{},
251 boost::interprocess::read_write};
255 shared_mem_.truncate(
sizeof(inner));
257 std::make_unique<boost::interprocess::message_queue>(
258 boost::interprocess::create_only,
266 std::make_unique<boost::interprocess::message_queue>(
267 boost::interprocess::open_only, message_queue_name_);
270 region_ = boost::interprocess::mapped_region{
271 shared_mem_, boost::interprocess::read_write};
273 inner_ =
new (region_.get_address()) inner{};
275 inner_ =
reinterpret_cast<inner*
>(region_.get_address());
281 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
282 boost::interprocess::message_queue::remove(message_queue_name_);
288 template <
bool IsParent>
294 boost::interprocess::shared_memory_object::remove(shared_mem_name_);
295 boost::interprocess::message_queue::remove(message_queue_name_);
299 template <
bool IsParent>
303 return inner_->checkout_test_index();
306 template <
bool IsParent>
310 return inner_->checkout_job_index();
313 template <
bool IsParent>
317 return inner_->any_failed();
320 template <
bool IsParent>
324 return inner_->any_failed(v);
327 template <
bool IsParent>
334 template <
bool IsParent>
338 inner_->inc_keep_alive_count();
341 template <
bool IsParent>
345 return inner_->get_keep_alive_count();
348 template <
bool IsParent>
353 inner_->print_results(s);
356 template <
bool IsParent>
364 message_queue_->send(&mt,
sizeof(mt), 0);
365 message_queue_->send(s.
c_str(), s.
size(), 0);
368 template <
bool IsParent>
372 return inner_->tests();
375 template <
bool IsParent>
379 return inner_->suites();
382 template <
bool IsParent>
389 any_failed(failures != 0);
417 unsigned int priority = 0;
419 buf.
data(), buf.
size(), recvd_size, priority);
422 assert(recvd_size == 1);
426 buf.
data(), buf.
size(), recvd_size, priority);
432 case MessageType::log:
436 case MessageType::test_start:
439 case MessageType::test_end:
450 <<
" reading unit test message queue.\n";
455 std::cerr <<
"Unknown error reading unit test message queue.\n";
473 os_ <<
"\nSuite: " << s
474 <<
" failed to complete. The child process may have crashed.\n";
509 , num_jobs_{num_jobs}
511 , print_log_{!quiet || print_log}
520 while (this->continue_keep_alive_)
526 auto cur_count = this->get_keep_alive_count();
527 if (cur_count == last_count)
531 cur_count = this->get_keep_alive_count();
532 if (cur_count == last_count)
535 std::cerr <<
"multi_runner_child " << job_index_
536 <<
": Assuming parent died, exiting.\n";
540 last_count = cur_count;
645 template class multi_runner_base<true>;
646 template class multi_runner_base<false>;