process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
fork_and_run.h File Reference
#include <core/posix/exit.h>
#include <core/posix/fork.h>
#include <core/posix/visibility.h>
#include <functional>
+ Include dependency graph for fork_and_run.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 core
 
 core::testing
 

Macros

#define TESTP(test_suite, test_name, CODE)
 
#define TESTP_F(test_fixture, test_name, CODE)
 

Enumerations

enum  core::testing::ForkAndRunResult {
  core::testing::ForkAndRunResult::empty = 0,
  core::testing::ForkAndRunResult::client_failed = 1 << 0,
  core::testing::ForkAndRunResult::service_failed = 1 << 1
}
 The ForkAndRunResult enum models the different failure modes of fork_and_run. More...
 

Functions

CORE_POSIX_DLL_PUBLIC ForkAndRunResult core::testing::operator| (ForkAndRunResult lhs, ForkAndRunResult rhs)
 
CORE_POSIX_DLL_PUBLIC ForkAndRunResult core::testing::operator& (ForkAndRunResult lhs, ForkAndRunResult rhs)
 
CORE_POSIX_DLL_PUBLIC ForkAndRunResult core::testing::fork_and_run (const std::function< core::posix::exit::Status()> &service, const std::function< core::posix::exit::Status()> &client)
 Forks two processes for both the service and the client. More...
 

Macro Definition Documentation

#define TESTP (   test_suite,
  test_name,
  CODE 
)
Value:
TEST(test_suite, test_name) { \
auto test = [&]() { \
CODE \
return HasFailure() ? core::posix::exit::Status::failure \
}; \
auto child = core::posix::fork( \
test, \
auto result = child.wait_for(core::posix::wait::Flags::untraced); \
EXPECT_EQ(core::posix::wait::Result::Status::exited, result.status); \
EXPECT_EQ(core::posix::exit::Status::success, result.detail.if_exited.status); \
} \
TEST(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
The process exited normally.
CORE_POSIX_DLL_PUBLIC ChildProcess fork(const std::function< posix::exit::Status()> &main, const StandardStream &flags)
fork forks a new process and executes the provided main function in the newly forked process...
Definition: fork.cpp:57
Also wait for state changes in untraced children.

Test definition macro which runs a TEST in a forked process. Note that you can only use EXPECT_*, not ASSERT_*!

Usage: TESTP(test_suite, test_name, { test code ... EXPECT_* ... })

Definition at line 75 of file fork_and_run.h.

#define TESTP_F (   test_fixture,
  test_name,
  CODE 
)
Value:
TEST_F(test_fixture, test_name) { \
auto test = [&]() { \
CODE \
return HasFailure() ? core::posix::exit::Status::failure \
}; \
auto child = core::posix::fork( \
test, \
auto result = child.wait_for(core::posix::wait::Flags::untraced); \
EXPECT_EQ(core::posix::wait::Result::Status::exited, result.status); \
EXPECT_EQ(core::posix::exit::Status::success, result.detail.if_exited.status); \
} \
The process exited normally.
CORE_POSIX_DLL_PUBLIC ChildProcess fork(const std::function< posix::exit::Status()> &main, const StandardStream &flags)
fork forks a new process and executes the provided main function in the newly forked process...
Definition: fork.cpp:57
TEST_F(ForkedSpinningProcess, throwing_access_to_process_group_id_of_a_forked_process_works)
Also wait for state changes in untraced children.

Test definition macro which runs a TEST_F in a forked process. Note that you can only use EXPECT_*, not ASSERT_*!

Usage: TESTP_F(FixtureName, TestName, { ... test code ... EXPECT_* ... })

Definition at line 100 of file fork_and_run.h.