]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/async_system_stackless.cpp
1 // Copyright (c) 2016 Klemens D. Morgenstern
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #define BOOST_TEST_MAIN
7 #define BOOST_TEST_IGNORE_SIGCHLD
8 #include <boost/test/included/unit_test.hpp>
10 #include <boost/process/error.hpp>
11 #include <boost/process/io.hpp>
12 #include <boost/process/async.hpp>
13 #include <boost/process/child.hpp>
14 #include <boost/process/async_system.hpp>
17 #include <boost/asio/io_context.hpp>
18 #include <boost/asio/spawn.hpp>
19 #include <boost/asio/coroutine.hpp>
20 #include <boost/asio/use_future.hpp>
21 #include <boost/asio/yield.hpp>
26 namespace bp
= boost::process
;
27 BOOST_AUTO_TEST_CASE(stackless
, *boost::unit_test::timeout(15))
29 using boost::unit_test::framework::master_test_suite
;
31 boost::asio::io_context ios
;
33 bool did_something_else
= false;
35 struct stackless_t
: boost::asio::coroutine
37 boost::asio::io_context
& ios
;
38 bool & did_something_else
;
40 stackless_t(boost::asio::io_context
& ios_
,
41 bool & did_something_else
)
42 : ios(ios_
), did_something_else(did_something_else
) {}
44 boost::system::error_code ec
= boost::system::error_code(),
45 std::size_t exit_code
= 0)
47 if (!ec
) reenter (this)
49 yield
bp::async_system(
51 master_test_suite().argv
[1],
52 "test", "--exit-code", "42");
54 BOOST_CHECK_EQUAL(exit_code
, 42);
55 BOOST_CHECK(did_something_else
);
58 } stackless
{ios
, did_something_else
};
60 ios
.post([&]{stackless();});
61 ios
.post([&]{did_something_else
= true;});
65 BOOST_CHECK(did_something_else
);