Asylo
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
asylo::experimental::ExecTester Class Reference

Executes a subprocess. More...

#include <exec_tester.h>

Public Member Functions

 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 Public Member Functions

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...
 

Protected Member Functions

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...
 

Detailed Description

Executes a subprocess.

Monitors its output to a given file descriptor (stdout by default) and checks its exit code.

Constructor & Destructor Documentation

◆ 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
argsThe command-line arguments to the subprocess. The first argument should be the executable to be run.
fd_to_checkThe file descriptor from which output is sent to CheckLine().

◆ ~ExecTester()

virtual asylo::experimental::ExecTester::~ExecTester ( )
virtualdefault

Member Function Documentation

◆ 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
pathA path to a file.
file_nameA 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
lineThe line to check.
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
accumulatedThe 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
inputThe input to give to the subprocess on its stdin.
[out]statusAn 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: