MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / DeathTestImpl

Class DeathTestImpl

tests/gtest/gtest-all.cc:7994–8052  ·  view source on GitHub ↗

Provides cross platform implementation for some death functionality.

Source from the content-addressed store, hash-verified

7992
7993// Provides cross platform implementation for some death functionality.
7994class DeathTestImpl : public DeathTest {
7995 protected:
7996 DeathTestImpl(const char* a_statement, Matcher<const std::string&> matcher)
7997 : statement_(a_statement),
7998 matcher_(std::move(matcher)),
7999 spawned_(false),
8000 status_(-1),
8001 outcome_(IN_PROGRESS),
8002 read_fd_(-1),
8003 write_fd_(-1) {}
8004
8005 // read_fd_ is expected to be closed and cleared by a derived class.
8006 ~DeathTestImpl() override { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
8007
8008 void Abort(AbortReason reason) override;
8009 bool Passed(bool status_ok) override;
8010
8011 const char* statement() const { return statement_; }
8012 bool spawned() const { return spawned_; }
8013 void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
8014 int status() const { return status_; }
8015 void set_status(int a_status) { status_ = a_status; }
8016 DeathTestOutcome outcome() const { return outcome_; }
8017 void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
8018 int read_fd() const { return read_fd_; }
8019 void set_read_fd(int fd) { read_fd_ = fd; }
8020 int write_fd() const { return write_fd_; }
8021 void set_write_fd(int fd) { write_fd_ = fd; }
8022
8023 // Called in the parent process only. Reads the result code of the death
8024 // test child process via a pipe, interprets it to set the outcome_
8025 // member, and closes read_fd_. Outputs diagnostics and terminates in
8026 // case of unexpected codes.
8027 void ReadAndInterpretStatusByte();
8028
8029 // Returns stderr output from the child process.
8030 virtual std::string GetErrorLogs();
8031
8032 private:
8033 // The textual content of the code this object is testing. This class
8034 // doesn't own this string and should not attempt to delete it.
8035 const char* const statement_;
8036 // A matcher that's expected to match the stderr output by the child process.
8037 Matcher<const std::string&> matcher_;
8038 // True if the death test child process has been successfully spawned.
8039 bool spawned_;
8040 // The exit status of the child process.
8041 int status_;
8042 // How the death test concluded.
8043 DeathTestOutcome outcome_;
8044 // Descriptor to the read end of the pipe to the child process. It is
8045 // always -1 in the child process. The child keeps its write end of the
8046 // pipe in write_fd_.
8047 int read_fd_;
8048 // Descriptor to the child's write end of the pipe to the parent process.
8049 // It is always -1 in the parent process. The parent keeps its end of the
8050 // pipe in read_fd_.
8051 int write_fd_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected