diff --git a/test/multiprocess.h b/test/multiprocess.h index 1d3ee9b2..aac9288b 100644 --- a/test/multiprocess.h +++ b/test/multiprocess.h @@ -92,6 +92,12 @@ class Multiprocess { //! expected to kill the child. void SetExpectedChildTermination(TerminationReason reason, int code); +#if !defined(OS_WIN) + //! \brief Sets termination reason and code appropriately for a child that + //! terminates via `__builtin_trap()`. + void SetExpectedChildTerminationBuiltinTrap(); +#endif // !OS_WIN + protected: ~Multiprocess(); diff --git a/test/multiprocess_exec_fuchsia.cc b/test/multiprocess_exec_fuchsia.cc index e6306080..7d571f91 100644 --- a/test/multiprocess_exec_fuchsia.cc +++ b/test/multiprocess_exec_fuchsia.cc @@ -86,6 +86,10 @@ void Multiprocess::SetExpectedChildTermination(TerminationReason reason, code_ = code; } +void Multiprocess::SetExpectedChildTerminationBuiltinTrap() { + SetExpectedChildTermination(kTerminationNormal, -1); +} + Multiprocess::~Multiprocess() { delete info_; } diff --git a/test/multiprocess_exec_test.cc b/test/multiprocess_exec_test.cc index 0104b0f3..99a1b01f 100644 --- a/test/multiprocess_exec_test.cc +++ b/test/multiprocess_exec_test.cc @@ -98,6 +98,35 @@ TEST(MultiprocessExec, MultiprocessExecSimpleChildReturnsNonZero) { exec.Run(); }; +#if !defined(OS_WIN) + +CRASHPAD_CHILD_TEST_MAIN(BuiltinTrapChild) { + __builtin_trap(); + return EXIT_SUCCESS; +} + +class TestBuiltinTrapTermination final : public MultiprocessExec { + public: + TestBuiltinTrapTermination() { + SetChildTestMainFunction("BuiltinTrapChild"); + SetExpectedChildTerminationBuiltinTrap(); + } + + ~TestBuiltinTrapTermination() = default; + + private: + void MultiprocessParent() override {} + + DISALLOW_COPY_AND_ASSIGN(TestBuiltinTrapTermination); +}; + +TEST(MultiprocessExec, BuiltinTrapTermination) { + TestBuiltinTrapTermination test; + test.Run(); +} + +#endif // !OS_WIN + } // namespace } // namespace test } // namespace crashpad diff --git a/test/multiprocess_posix.cc b/test/multiprocess_posix.cc index c638b48a..96b8ad26 100644 --- a/test/multiprocess_posix.cc +++ b/test/multiprocess_posix.cc @@ -157,6 +157,14 @@ void Multiprocess::SetExpectedChildTermination(TerminationReason reason, code_ = code; } +void Multiprocess::SetExpectedChildTerminationBuiltinTrap() { +#if defined(ARCH_CPU_ARM64) + SetExpectedChildTermination(kTerminationSignal, SIGTRAP); +#else + SetExpectedChildTermination(kTerminationSignal, SIGILL); +#endif +} + Multiprocess::~Multiprocess() { }