Crashpad
Public Member Functions | Protected Member Functions | List of all members
crashpad::test::MultiprocessExec Class Reference

Manages an exec()-based multiprocess test. More...

#include "test/multiprocess_exec.h"

Inheritance diagram for crashpad::test::MultiprocessExec:
crashpad::test::Multiprocess

Public Member Functions

void SetChildCommand (const base::FilePath &command, const std::vector< std::string > *arguments)
 Sets the command to exec() in the child. More...
 
void SetChildTestMainFunction (const std::string &function_name)
 Calls SetChildCommand() to run a child test main function registered with CRASHPAD_CHILD_TEST_MAIN(). More...
 
ProcessType ChildProcess ()
 Returns a ProcessType representing the child process. More...
 
- Public Member Functions inherited from crashpad::test::Multiprocess
void Run ()
 Runs the test. More...
 
void SetExpectedChildTermination (TerminationReason reason, ReturnCodeType code)
 Sets the expected termination reason and code. More...
 
void SetExpectedChildTerminationBuiltinTrap ()
 Sets termination reason and code appropriately for a child that terminates via __builtin_trap().
 

Protected Member Functions

void PreFork () override
 Establishes the proper testing environment prior to forking. More...
 
- Protected Member Functions inherited from crashpad::test::Multiprocess
pid_t ChildPID () const
 Returns the child process’ process ID. More...
 
FileHandle ReadPipeHandle () const
 Returns the read pipe’s file handle. More...
 
FileHandle WritePipeHandle () const
 Returns the write pipe’s file handle. More...
 
void CloseReadPipe ()
 Closes the read pipe. More...
 
void CloseWritePipe ()
 Closes the write pipe. More...
 
void set_info (internal::MultiprocessInfo *info)
 
internal::MultiprocessInfoinfo ()
 

Additional Inherited Members

- Public Types inherited from crashpad::test::Multiprocess
enum  TerminationReason : bool
 The termination type for a child process. More...
 

Detailed Description

Manages an exec()-based multiprocess test.

These tests are based on fork() and exec(). The parent process is able to communicate with the child in the same manner as a base-class Multiprocess parent. The read and write pipes appear in the child process on stdin and stdout, respectively.

Subclasses are expected to implement the parent in the same was as a base-class Multiprocess parent. The child must be implemented in an executable to be set by SetChildCommand().

Member Function Documentation

◆ ChildProcess()

ProcessType crashpad::test::MultiprocessExec::ChildProcess ( )

Returns a ProcessType representing the child process.

This method is only valid during the body of MultiprocessParent().

Returns
A platform-specific type representing the child process. This method can fail on macOS because access to a child's task port requires the task_for_pid entitlement.

◆ PreFork()

void crashpad::test::MultiprocessExec::PreFork ( )
overrideprotectedvirtual

Establishes the proper testing environment prior to forking.

Subclasses that solely implement a test should not need to override this method. Subclasses that do not implement tests but instead implement additional testing features on top of this class may override this method provided that they call the superclass’ implementation first as follows:

void PreFork() override {
ASSERT_NO_FATAL_FAILURE(Multiprocess::PreFork());
// Place subclass-specific pre-fork code here.
}

Subclass implementations may signal failure by raising their own fatal gtest assertions.

Reimplemented from crashpad::test::Multiprocess.

◆ SetChildCommand()

void crashpad::test::MultiprocessExec::SetChildCommand ( const base::FilePath &  command,
const std::vector< std::string > *  arguments 
)

Sets the command to exec() in the child.

This method must be called before the test can be Run().

This method is useful when a custom executable is required for the child binary, however, SetChildTestMainFunction() should generally be preferred.

Parameters
[in]commandThe executable’s pathname.
[in]argumentsThe command-line arguments to pass to the child process in its argv[] vector. This vector must begin at argv[1], as command is implicitly used as argv[0]. This argument may be nullptr if no command-line arguments are to be passed.
See also
SetChildTestMainFunction

◆ SetChildTestMainFunction()

void crashpad::test::MultiprocessExec::SetChildTestMainFunction ( const std::string &  function_name)

Calls SetChildCommand() to run a child test main function registered with CRASHPAD_CHILD_TEST_MAIN().

This uses the same launch mechanism as SetChildCommand(), but coordinates with test/gtest_main.cc to allow for simple registration of a child processes' entry point via the helper macro, rather than needing to create a separate build target.

Parameters
[in]function_nameThe name of the function as passed to CRASHPAD_CHILD_TEST_MAIN().

The documentation for this class was generated from the following files:
crashpad::test::Multiprocess::PreFork
virtual void PreFork()
Establishes the proper testing environment prior to forking.
Definition: multiprocess_posix.cc:175
crashpad::test::MultiprocessExec::PreFork
void PreFork() override
Establishes the proper testing environment prior to forking.
Definition: multiprocess_exec_fuchsia.cc:147