Executes a subprocess.
More...
#include <exec_tester.h>
|
| ExecTester (const std::vector< std::string > &args, int fd_to_check=STDOUT_FILENO) |
| Constructs an ExecTester that will monitor an execve call on args . More...
|
|
virtual | ~ExecTester ()=default |
|
bool | Run (const std::string &input, int *status) |
| Forks and execs the subprocess with the configured arguments. More...
|
|
|
static std::string | BuildSiblingPath (const std::string &path, const std::string &file_name) |
| Returns file_name qualified to be in the same directory as the file specified by path . More...
|
|
|
virtual bool | CheckLine (const std::string &line) |
| Checks a line of the subprocess's output to the configured file descriptor for an expected property. More...
|
|
virtual bool | FinalCheck (bool accumulated) |
| Returns the final result given the accumulated CheckLine() results. More...
|
|
Executes a subprocess.
Monitors its output to a given file descriptor (stdout by default) and checks its exit code.
◆ ExecTester()
asylo::experimental::ExecTester::ExecTester |
( |
const std::vector< std::string > & |
args, |
|
|
int |
fd_to_check = STDOUT_FILENO |
|
) |
| |
Constructs an ExecTester
that will monitor an execve
call on args
.
- Parameters
-
args | The command-line arguments to the subprocess. The first argument should be the executable to be run. |
fd_to_check | The file descriptor from which output is sent to CheckLine(). |
◆ ~ExecTester()
virtual asylo::experimental::ExecTester::~ExecTester |
( |
| ) |
|
|
virtualdefault |
◆ BuildSiblingPath()
static std::string asylo::experimental::ExecTester::BuildSiblingPath |
( |
const std::string & |
path, |
|
|
const std::string & |
file_name |
|
) |
| |
|
static |
Returns file_name
qualified to be in the same directory as the file specified by path
.
This utility helps find binaries in common use cases in Asylo.
- Deprecated:
- Use Bazel's runfiles library for file paths.
- Parameters
-
path | A path to a file. |
file_name | A path to a file relative to the directory containing path . |
- Returns
- A path to
file_name
within the same directory as the file at path
. If path
is a relative path, then the returned path is relative to the same directory. If path
is absolute, then so is the returned path.
◆ CheckLine()
virtual bool asylo::experimental::ExecTester::CheckLine |
( |
const std::string & |
line | ) |
|
|
inlineprotectedvirtual |
Checks a line of the subprocess's output to the configured file descriptor for an expected property.
- Parameters
-
- Returns
true
if the property holds and false
otherwise.
◆ FinalCheck()
virtual bool asylo::experimental::ExecTester::FinalCheck |
( |
bool |
accumulated | ) |
|
|
inlineprotectedvirtual |
Returns the final result given the accumulated CheckLine() results.
This is useful e.g., for determining hard bounds that CheckLine() soft-checks.
- Parameters
-
accumulated | The conjunction (logical "and") of the return value of CheckLine() on each line of the subprocess's output to the given file descriptor. |
- Returns
- Whether the test as a whole was successful.
◆ Run()
bool asylo::experimental::ExecTester::Run |
( |
const std::string & |
input, |
|
|
int * |
status |
|
) |
| |
Forks and execs the subprocess with the configured arguments.
Redirects the subprocess's stdin from input
if non-empty. Validates the subprocess's output to fd_to_check
(from the constructor) with CheckLine() and FinalCheck(). Stores the process status in status
after exit or signal termination.
- Parameters
-
| input | The input to give to the subprocess on its stdin. |
[out] | status | An output argument that is set to the subprocess's exit status information, as returned by waitpid() . |
- Returns
- The logical "and" of all CheckLine() results on the subprocess's output to the configured file descriptor.
The documentation for this class was generated from the following file: