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>
14 #include <boost/process/error.hpp>
15 #include <boost/process/async.hpp>
16 #include <boost/process/child.hpp>
18 #include <boost/system/error_code.hpp>
19 #include <boost/asio.hpp>
20 #if defined(BOOST_WINDOWS_API)
22 typedef boost::asio::windows::stream_handle pipe_end
;
23 #elif defined(BOOST_POSIX_API)
24 # include <sys/wait.h>
26 typedef boost::asio::posix::stream_descriptor pipe_end
;
29 namespace bp
= boost::process
;
31 BOOST_AUTO_TEST_CASE(sync_wait
)
33 using boost::unit_test::framework::master_test_suite
;
37 master_test_suite().argv
[1],
38 "test", "--exit-code", "123",
43 int exit_code
= c
.exit_code();
46 BOOST_CHECK_EQUAL(123, exit_code
);
51 #if defined(BOOST_WINDOWS_API)
56 wait_handler(HANDLE handle
) : handle_(handle
) {}
58 void operator()(const boost::system::error_code
&ec
)
62 BOOST_REQUIRE(GetExitCodeProcess(handle_
, &exit_code
));
63 BOOST_CHECK_EQUAL(123, exit_code
);
66 #elif defined(BOOST_POSIX_API)
69 void operator()(const boost::system::error_code
&ec
, int signal
)
72 BOOST_REQUIRE_EQUAL(SIGCHLD
, signal
);
75 BOOST_CHECK_EQUAL(123, WEXITSTATUS(status
));
80 BOOST_AUTO_TEST_CASE(async_wait
)
82 using boost::unit_test::framework::master_test_suite
;
83 using namespace boost::asio
;
85 boost::asio::io_context io_context
;
87 #if defined(BOOST_POSIX_API)
88 signal_set
set(io_context
, SIGCHLD
);
89 set
.async_wait(wait_handler());
94 master_test_suite().argv
[1],
95 "test", "--exit-code", "123",
100 #if defined(BOOST_WINDOWS_API)
101 windows::object_handle
handle(io_context
, c
.native_handle());
102 handle
.async_wait(wait_handler(handle
.native_handle()));
104 std::cout
<< "async_wait 1" << std::endl
;
106 std::cout
<< "async_wait 2" << std::endl
;