From bbfc334c9358337bb6ad484b2964fb0214e01596 Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Sat, 28 Oct 2017 13:04:01 +0200 Subject: [PATCH] split up the async_system test --- test/Jamfile.jam | 6 ++- test/async_system.cpp | 80 +-------------------------------- test/async_system_future.cpp | 61 +++++++++++++++++++++++++ test/async_system_stackless.cpp | 69 ++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 81 deletions(-) create mode 100644 test/async_system_future.cpp create mode 100644 test/async_system_stackless.cpp diff --git a/test/Jamfile.jam b/test/Jamfile.jam index d659b517..546a7170 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -96,8 +96,10 @@ test-suite with-valgrind : : bare ; test-suite without-valgrind : - [ run async_system.cpp filesystem system coroutine : : sparring_partner : static ] - [ run vfork.cpp system filesystem : : sparring_partner : no linux:yes ] + [ run async_system.cpp filesystem system coroutine : : sparring_partner : static ] + [ run async_system_future.cpp filesystem system coroutine : : sparring_partner : static ] + [ run async_system_stackless.cpp filesystem system coroutine : : sparring_partner : static ] + [ run vfork.cpp system filesystem : : sparring_partner : no linux:yes ] ; diff --git a/test/async_system.cpp b/test/async_system.cpp index 967fa93a..78d614dc 100644 --- a/test/async_system.cpp +++ b/test/async_system.cpp @@ -104,82 +104,4 @@ BOOST_AUTO_TEST_CASE(stackful_error, *boost::unit_test::timeout(15)) ios.run(); BOOST_CHECK(did_something_else); -} - - -BOOST_AUTO_TEST_CASE(stackless, *boost::unit_test::timeout(15)) -{ - using boost::unit_test::framework::master_test_suite; - - boost::asio::io_context ios; - - bool did_something_else = false; - - struct stackless_t : boost::asio::coroutine - { - boost::asio::io_context & ios; - bool & did_something_else; - - stackless_t(boost::asio::io_context & ios_, - bool & did_something_else) - : ios(ios_), did_something_else(did_something_else) {} - void operator()( - boost::system::error_code ec = boost::system::error_code(), - std::size_t exit_code = 0) - { - if (!ec) reenter (this) - { - yield bp::async_system( - ios, *this, - master_test_suite().argv[1], - "test", "--exit-code", "42"); - - BOOST_CHECK_EQUAL(exit_code, 42); - BOOST_CHECK(did_something_else); - } - } - } stackless{ios, did_something_else}; - - ios.post([&]{stackless();}); - ios.post([&]{did_something_else = true;}); - - ios.run(); - - BOOST_CHECK(did_something_else); -} - - -BOOST_AUTO_TEST_CASE(future, *boost::unit_test::timeout(15)) -{ - using boost::unit_test::framework::master_test_suite; - - boost::asio::io_context ios; - - std::future fut = bp::async_system( - ios, boost::asio::use_future, - master_test_suite().argv[1], - "test", "--exit-code", "42"); - - ios.run(); - - int exit_code = 0; - BOOST_CHECK_NO_THROW(exit_code = fut.get()); - - BOOST_CHECK_EQUAL(exit_code, 42); -} - -BOOST_AUTO_TEST_CASE(future_error, *boost::unit_test::timeout(15)) -{ - using boost::unit_test::framework::master_test_suite; - - boost::asio::io_context ios; - - std::future fut = bp::async_system( - ios, boost::asio::use_future, - "invalid-command"); - - ios.run(); - - int exit_code = 0; - BOOST_CHECK_THROW(exit_code = fut.get(), boost::system::system_error); -} +} \ No newline at end of file diff --git a/test/async_system_future.cpp b/test/async_system_future.cpp new file mode 100644 index 00000000..8e04ccb7 --- /dev/null +++ b/test/async_system_future.cpp @@ -0,0 +1,61 @@ +// Copyright (c) 2016 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MAIN +#define BOOST_TEST_IGNORE_SIGCHLD +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace bp = boost::process; + +BOOST_AUTO_TEST_CASE(future, *boost::unit_test::timeout(15)) +{ + using boost::unit_test::framework::master_test_suite; + + boost::asio::io_context ios; + + std::future fut = bp::async_system( + ios, boost::asio::use_future, + master_test_suite().argv[1], + "test", "--exit-code", "42"); + + ios.run(); + + int exit_code = 0; + BOOST_CHECK_NO_THROW(exit_code = fut.get()); + + BOOST_CHECK_EQUAL(exit_code, 42); +} + +BOOST_AUTO_TEST_CASE(future_error, *boost::unit_test::timeout(15)) +{ + using boost::unit_test::framework::master_test_suite; + + boost::asio::io_context ios; + + std::future fut = bp::async_system( + ios, boost::asio::use_future, + "invalid-command"); + + ios.run(); + + int exit_code = 0; + BOOST_CHECK_THROW(exit_code = fut.get(), boost::system::system_error); +} diff --git a/test/async_system_stackless.cpp b/test/async_system_stackless.cpp new file mode 100644 index 00000000..4a0c7d01 --- /dev/null +++ b/test/async_system_stackless.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2016 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MAIN +#define BOOST_TEST_IGNORE_SIGCHLD +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace bp = boost::process; + +BOOST_AUTO_TEST_CASE(stackless, *boost::unit_test::timeout(15)) +{ + using boost::unit_test::framework::master_test_suite; + + boost::asio::io_context ios; + + bool did_something_else = false; + + struct stackless_t : boost::asio::coroutine + { + boost::asio::io_context & ios; + bool & did_something_else; + + stackless_t(boost::asio::io_context & ios_, + bool & did_something_else) + : ios(ios_), did_something_else(did_something_else) {} + void operator()( + boost::system::error_code ec = boost::system::error_code(), + std::size_t exit_code = 0) + { + if (!ec) reenter (this) + { + yield bp::async_system( + ios, *this, + master_test_suite().argv[1], + "test", "--exit-code", "42"); + + BOOST_CHECK_EQUAL(exit_code, 42); + BOOST_CHECK(did_something_else); + } + } + } stackless{ios, did_something_else}; + + ios.post([&]{stackless();}); + ios.post([&]{did_something_else = true;}); + + ios.run(); + + BOOST_CHECK(did_something_else); +} + +