]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/async_pipe.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)
7 #define BOOST_TEST_MAIN
9 #include <boost/test/included/unit_test.hpp>
13 #include <boost/algorithm/string/predicate.hpp>
15 #include <boost/process/async_pipe.hpp>
16 #include <boost/process/pipe.hpp>
17 #include <boost/asio/read.hpp>
18 #include <boost/asio/read_until.hpp>
19 #include <boost/asio/write.hpp>
20 #include <boost/asio/streambuf.hpp>
23 namespace bp
= boost::process
;
24 namespace asio
= boost::asio
;
26 BOOST_AUTO_TEST_CASE(plain_async
, *boost::unit_test::timeout(5))
29 bp::async_pipe pipe
{ios
};
31 std::string st
= "test-string\n";
35 asio::async_write(pipe
, asio::buffer(st
), [](const boost::system::error_code
&, std::size_t){});
36 asio::async_read_until(pipe
, buf
, '\n', [](const boost::system::error_code
&, std::size_t){});
41 std::istream
istr(&buf
);
42 BOOST_CHECK(std::getline(istr
, line
));
45 BOOST_CHECK_EQUAL(line
, "test-string");
49 BOOST_AUTO_TEST_CASE(closed_transform
)
53 bp::async_pipe ap
{ios
};
55 BOOST_CHECK(ap
.is_open());
56 bp::pipe p2
= static_cast<bp::pipe
>(ap
);
57 BOOST_CHECK(p2
.is_open());
60 BOOST_CHECK(!ap
.is_open());
62 bp::pipe p
= static_cast<bp::pipe
>(ap
);
63 BOOST_CHECK(!p
.is_open());
67 BOOST_AUTO_TEST_CASE(multithreaded_async_pipe
)
71 std::vector
<std::thread
> threads
;
72 for (int i
= 0; i
< std::thread::hardware_concurrency(); i
++)
74 threads
.emplace_back([&ioc
]
76 std::vector
<bp::async_pipe
*> pipes
;
77 for (size_t i
= 0; i
< 100; i
++)
78 pipes
.push_back(new bp::async_pipe(ioc
));
83 for (auto &t
: threads
)