mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 04:22:15 +00:00
Updated pid test.
This commit is contained in:
committed by
Klemens Morgenstern
parent
8fff7283ed
commit
27a35f452d
@@ -59,11 +59,11 @@ test-suite standalone :
|
||||
[ run utf8.cpp test_impl ]
|
||||
[ run cstring_ref.cpp test_impl ]
|
||||
[ run environment.cpp test_impl ]
|
||||
[ run pid.cpp test_impl : : : <target-os>darwin:<build>no ]
|
||||
[ run shell.cpp test_impl ]
|
||||
;
|
||||
|
||||
test-suite with_target :
|
||||
[ run pid.cpp test_impl : --log_level=all --catch_system_errors=no -- : target ]
|
||||
[ run process.cpp test_impl : --log_level=all --catch_system_errors=no -- : target ]
|
||||
[ run windows.cpp test_impl : --log_level=all --catch_system_errors=no -- : target : <build>no <target-os>windows:<build>yes <target-os>windows:<source>Advapi32 ]
|
||||
[ run ext.cpp test_impl : --log_level=all --catch_system_errors=no -- : target : <target-os>darwin:<build>no ]
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/process/v2/pid.hpp>
|
||||
#include <boost/process/v2/process.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_pid)
|
||||
@@ -22,21 +24,29 @@ BOOST_AUTO_TEST_CASE(test_pid)
|
||||
BOOST_CHECK_GT(all.size(), 0u);
|
||||
BOOST_CHECK(itr != all.end());
|
||||
|
||||
std::vector<bp2::pid_type> children, grand_children;
|
||||
auto grand_child_pids = [](bp2::pid_type pid,
|
||||
std::vector<bp2::pid_type> & children,
|
||||
std::vector<bp2::pid_type> & grand_children)
|
||||
{
|
||||
children = bp2::child_pids(pid);
|
||||
for (unsigned i = 0; i < children.size(); i++)
|
||||
{
|
||||
std::vector<bp2::pid_type> tmp1;
|
||||
std::vector<bp2::pid_type> tmp2 = bp2::child_pids(children[i]);
|
||||
tmp1.insert(std::end(tmp1), std::begin(tmp2), std::end(tmp2));
|
||||
grand_children = tmp1;
|
||||
}
|
||||
return (!children.empty() || !grand_children.empty());
|
||||
};
|
||||
BOOST_CHECK_NE(grand_child_pids(bp2::root_pid, children, grand_children), false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(child_pid)
|
||||
{
|
||||
namespace bp2 = boost::process::v2;
|
||||
|
||||
using boost::unit_test::framework::master_test_suite;
|
||||
const auto pth = bp2::filesystem::absolute(master_test_suite().argv[1]);
|
||||
|
||||
auto cs = bp2::child_pids(bp2::current_pid());
|
||||
boost::asio::io_context ctx;
|
||||
bp2::process proc(ctx, pth, {"sleep", "50000"});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
auto c2 = bp2::child_pids(bp2::current_pid());
|
||||
BOOST_CHECK_LT(cs.size(), c2.size());
|
||||
BOOST_CHECK(std::find(cs.begin(), cs.end(), proc.id()) == cs.end());
|
||||
BOOST_CHECK(std::find(c2.begin(), c2.end(), proc.id()) != c2.end());
|
||||
proc.terminate();
|
||||
proc.wait();
|
||||
|
||||
auto c3 = bp2::child_pids(bp2::current_pid());
|
||||
BOOST_CHECK(std::find(c3.begin(), c3.end(), proc.id()) == c3.end());
|
||||
BOOST_CHECK_LT(c3.size(), c2.size());
|
||||
}
|
||||
Reference in New Issue
Block a user