summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibTest/CrashTest.cpp
diff options
context:
space:
mode:
authorMichel Hermier <michel.hermier@gmail.com>2021-12-17 18:12:47 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-12-19 14:22:06 -0800
commit4c6e826c055e23493a8b3d72f5f9e5af7a5432ad (patch)
tree35ab5b7cdfcfa8a85d66f7d658b6cdd163d285b4 /Userland/Libraries/LibTest/CrashTest.cpp
parentb1b94692e69c6c4f22f0fbace1b9a80d5d3bd304 (diff)
downloadserenity-4c6e826c055e23493a8b3d72f5f9e5af7a5432ad.zip
LibTest: Add `EXPECT_CRASH_WITH_SIGNAL`
Diffstat (limited to 'Userland/Libraries/LibTest/CrashTest.cpp')
-rw-r--r--Userland/Libraries/LibTest/CrashTest.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/Userland/Libraries/LibTest/CrashTest.cpp b/Userland/Libraries/LibTest/CrashTest.cpp
index c002bec148..ac8433d9be 100644
--- a/Userland/Libraries/LibTest/CrashTest.cpp
+++ b/Userland/Libraries/LibTest/CrashTest.cpp
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Assertions.h>
#include <AK/Platform.h>
#include <LibTest/CrashTest.h>
#include <sys/wait.h>
@@ -17,9 +18,10 @@
namespace Test {
-Crash::Crash(String test_type, Function<Crash::Failure()> crash_function)
+Crash::Crash(String test_type, Function<Crash::Failure()> crash_function, int crash_signal)
: m_type(move(test_type))
, m_crash_function(move(crash_function))
+ , m_crash_signal(crash_signal)
{
}
@@ -49,7 +51,9 @@ bool Crash::run(RunType run_type)
return do_report(Failure(WEXITSTATUS(status)));
}
if (WIFSIGNALED(status)) {
- return do_report(WTERMSIG(status));
+ int signal = WTERMSIG(status);
+ VERIFY(signal > 0);
+ return do_report(signal);
}
VERIFY_NOT_REACHED();
}
@@ -57,7 +61,14 @@ bool Crash::run(RunType run_type)
bool Crash::do_report(Report report)
{
- const bool pass = report.has<int>();
+ bool pass = false;
+ if (m_crash_signal == ANY_SIGNAL) {
+ pass = report.has<int>();
+ } else if (m_crash_signal > 0) {
+ pass = report.has<int>() && report.get<int>() == m_crash_signal;
+ } else {
+ VERIFY_NOT_REACHED();
+ }
if (pass)
out("\x1B[32mPASS\x1B[0m: ");
@@ -68,19 +79,28 @@ bool Crash::do_report(Report report)
[&](const Failure& failure) {
switch (failure) {
case Failure::DidNotCrash:
- outln("Did not crash!");
+ out("Did not crash");
break;
case Failure::UnexpectedError:
- outln("Unexpected error!");
+ out("Unexpected error");
break;
default:
VERIFY_NOT_REACHED();
}
},
[&](const int& signal) {
- outln("Terminated with signal {}", signal);
+ out("Terminated with signal {}", signal);
});
+ if (!pass) {
+ if (m_crash_signal == ANY_SIGNAL) {
+ out(" while expecting any signal");
+ } else if (m_crash_signal > 0) {
+ out(" while expecting signal {}", m_crash_signal);
+ }
+ }
+ outln();
+
return pass;
}