]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/on_exit.cpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #define BOOST_TEST_MAIN
11 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
13 #include <boost/process.hpp>
14 #include <boost/asio.hpp>
18 BOOST_AUTO_TEST_CASE(single_ios
, *boost::unit_test::timeout(6))
20 using boost::unit_test::framework::master_test_suite
;
22 if (master_test_suite().argc
> 2 && strcmp(master_test_suite().argv
[1], "sleep") == 0)
24 auto s
= atoi(master_test_suite().argv
[2]);
25 std::this_thread::sleep_for(std::chrono::seconds(s
));
29 namespace bp
= boost::process
;
30 boost::asio::io_context ios
;
31 std::chrono::steady_clock::time_point p1
, p2
;
33 // launch a child that will sleep for 2s
34 auto c1
= bp::child(master_test_suite().argv
[0], "sleep", "2", ios
,
35 bp::on_exit([&p1
](int, const std::error_code
&)
36 { p1
= std::chrono::steady_clock::now(); }));
38 // wait a bit, make sure the child launch for my test
39 std::this_thread::sleep_for(std::chrono::milliseconds(10));
41 // launch a child that will sleep for 4s
42 auto c2
= bp::child(master_test_suite().argv
[0], "sleep", "4", ios
,
43 bp::on_exit([&p2
](int, const std::error_code
&)
44 { p2
= std::chrono::steady_clock::now(); }));
46 // wait for the notifications
47 while (!ios
.stopped())
50 BOOST_REQUIRE((p2
- p1
) > std::chrono::seconds(1));