non-win: Add Multiprocess::SetExpectedChildTerminationBuiltinTrap()

Bug: crashpad:30
Change-Id: Ide7ad3d0f8b9938f57d183ff3fc73868ce28c02c
Reviewed-on: https://chromium-review.googlesource.com/932363
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Joshua Peraza 2018-02-22 12:45:42 -08:00 committed by Commit Bot
parent 61f1013ee4
commit c69ba3d527
4 changed files with 47 additions and 0 deletions

View File

@ -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();

View File

@ -86,6 +86,10 @@ void Multiprocess::SetExpectedChildTermination(TerminationReason reason,
code_ = code;
}
void Multiprocess::SetExpectedChildTerminationBuiltinTrap() {
SetExpectedChildTermination(kTerminationNormal, -1);
}
Multiprocess::~Multiprocess() {
delete info_;
}

View File

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

View File

@ -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() {
}