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 class | core::testing::ForkAndRunResult { core::testing::empty = 0 , core::testing::client_failed = 1 << 0 , core::testing::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

## TESTP

#define TESTP | ( |  | test_suite,
|  |  | test_name,
|  |  | CODE
| ) |  |

Value:
TEST(test_suite, test_name) { \
auto test = [&]() { \
CODE \
return HasFailure() ? core::posix::exit::Status::failure \
: core::posix::exit::Status::success; \
}; \
auto child = core::posix::fork( \
test, \
core::posix::StandardStream::empty); \
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
TEST(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
Definition: cross_process_sync_test.cpp:25
core::posix::exit::Status::success
@ success
core::posix::exit::Status::failure
@ failure
core::posix::wait::Flags::untraced
@ untraced
Also wait for state changes in untraced children.
core::posix::fork
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
core::posix::StandardStream::empty
@ empty
core::posix::wait::Result::Status::exited
@ exited
The process exited normally.

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.

## TESTP_F

#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 \
: core::posix::exit::Status::success; \
}; \
auto child = core::posix::fork( \
test, \
core::posix::StandardStream::empty); \
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_F
TEST_F(ForkedSpinningProcess, throwing_access_to_process_group_id_of_a_forked_process_works)
Definition: posix_process_test.cpp:113

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.