]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/process/test/async_system_stackless.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / process / test / async_system_stackless.cpp
CommitLineData
b32b8144
FG
1// Copyright (c) 2016 Klemens D. Morgenstern
2//
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)
5
6#define BOOST_TEST_MAIN
7#define BOOST_TEST_IGNORE_SIGCHLD
8#include <boost/test/included/unit_test.hpp>
9
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>
15
16#include <string>
17#include <boost/asio/io_context.hpp>
92f5a8d4 18#include <boost/asio/post.hpp>
b32b8144
FG
19#include <boost/asio/spawn.hpp>
20#include <boost/asio/coroutine.hpp>
21#include <boost/asio/use_future.hpp>
22#include <boost/asio/yield.hpp>
23
24#include <vector>
25#include <array>
92f5a8d4 26BOOST_AUTO_TEST_SUITE( async );
b32b8144
FG
27
28namespace bp = boost::process;
b32b8144
FG
29BOOST_AUTO_TEST_CASE(stackless, *boost::unit_test::timeout(15))
30{
31 using boost::unit_test::framework::master_test_suite;
32
33 boost::asio::io_context ios;
34
35 bool did_something_else = false;
36
37 struct stackless_t : boost::asio::coroutine
38 {
39 boost::asio::io_context & ios;
40 bool & did_something_else;
41
42 stackless_t(boost::asio::io_context & ios_,
43 bool & did_something_else)
44 : ios(ios_), did_something_else(did_something_else) {}
45 void operator()(
46 boost::system::error_code ec = boost::system::error_code(),
47 std::size_t exit_code = 0)
48 {
49 if (!ec) reenter (this)
50 {
51 yield bp::async_system(
52 ios, *this,
53 master_test_suite().argv[1],
54 "test", "--exit-code", "42");
55
20effc67 56 BOOST_CHECK_EQUAL(exit_code, 42u);
b32b8144
FG
57 BOOST_CHECK(did_something_else);
58 }
59 }
60 } stackless{ios, did_something_else};
61
92f5a8d4
TL
62 boost::asio::post(ios.get_executor(), [&]{stackless();});
63 boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});
b32b8144
FG
64
65 ios.run();
66
67 BOOST_CHECK(did_something_else);
68}
92f5a8d4
TL
69
70
20effc67 71BOOST_AUTO_TEST_SUITE_END();