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> 18 #include <boost/asio/post.hpp> 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> 26 BOOST_AUTO_TEST_SUITE( async ); 27 28 namespace bp = boost::process; 29 BOOST_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 stackless_tstackless_t42 stackless_t(boost::asio::io_context & ios_, 43 bool & did_something_else) 44 : ios(ios_), did_something_else(did_something_else) {} operator ()stackless_t45 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 56 BOOST_CHECK_EQUAL(exit_code, 42u); 57 BOOST_CHECK(did_something_else); 58 } 59 } 60 } stackless{ios, did_something_else}; 61 __anon8e4d07af0102null62 boost::asio::post(ios.get_executor(), [&]{stackless();}); __anon8e4d07af0202null63 boost::asio::post(ios.get_executor(), [&]{did_something_else = true;}); 64 65 ios.run(); 66 67 BOOST_CHECK(did_something_else); 68 } 69 70 71 BOOST_AUTO_TEST_SUITE_END(); 72