summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Tests/Kernel/CMakeLists.txt2
-rw-r--r--Tests/Kernel/crash.cpp (renamed from Userland/Utilities/crash.cpp)49
-rw-r--r--Userland/Utilities/CMakeLists.txt1
3 files changed, 28 insertions, 24 deletions
diff --git a/Tests/Kernel/CMakeLists.txt b/Tests/Kernel/CMakeLists.txt
index 91ecf7338a..746f195593 100644
--- a/Tests/Kernel/CMakeLists.txt
+++ b/Tests/Kernel/CMakeLists.txt
@@ -29,6 +29,8 @@ foreach(source IN LISTS TEST_SOURCES)
install(TARGETS "${test_name}" RUNTIME DESTINATION usr/Tests/Kernel/Legacy)
endforeach()
+serenity_test("crash.cpp" Kernel MAIN_ALREADY_DEFINED)
+
set(LIBTEST_BASED_SOURCES
TestEFault.cpp
TestKernelAlarm.cpp
diff --git a/Userland/Utilities/crash.cpp b/Tests/Kernel/crash.cpp
index 54fcfdd984..02648d3adb 100644
--- a/Userland/Utilities/crash.cpp
+++ b/Tests/Kernel/crash.cpp
@@ -55,7 +55,7 @@ int main(int argc, char** argv)
args_parser.set_general_help(
"Exercise error-handling paths of the execution environment "
"(i.e., Kernel or UE) by crashing in many different ways.");
- args_parser.add_option(do_all_crash_types, "Test that all of the following crash types crash as expected", nullptr, 'A');
+ args_parser.add_option(do_all_crash_types, "Test that all of the following crash types crash as expected (default behavior)", nullptr, 'A');
args_parser.add_option(do_segmentation_violation, "Perform a segmentation violation by dereferencing an invalid pointer", nullptr, 's');
args_parser.add_option(do_division_by_zero, "Perform a division by zero", nullptr, 'd');
args_parser.add_option(do_illegal_instruction, "Execute an illegal CPU instruction", nullptr, 'i');
@@ -77,7 +77,9 @@ int main(int argc, char** argv)
args_parser.add_option(do_failing_assertion, "Perform a failing assertion", nullptr, 'n');
args_parser.add_option(do_deref_null_refptr, "Dereference a null RefPtr", nullptr, 'R');
- if (argc != 2) {
+ if (argc == 1) {
+ do_all_crash_types = true;
+ } else if (argc != 2) {
args_parser.print_usage(stderr, argv[0]);
exit(1);
}
@@ -86,9 +88,10 @@ int main(int argc, char** argv)
Crash::RunType run_type = do_all_crash_types ? Crash::RunType::UsingChildProcess
: Crash::RunType::UsingCurrentProcess;
+ bool any_failures = false;
if (do_segmentation_violation || do_all_crash_types) {
- Crash("Segmentation violation", []() {
+ any_failures |= !Crash("Segmentation violation", []() {
volatile int* crashme = nullptr;
*crashme = 0xbeef;
return Crash::Failure::DidNotCrash;
@@ -96,7 +99,7 @@ int main(int argc, char** argv)
}
if (do_division_by_zero || do_all_crash_types) {
- Crash("Division by zero", []() {
+ any_failures |= !Crash("Division by zero", []() {
volatile int lala = 10;
volatile int zero = 0;
[[maybe_unused]] volatile int test = lala / zero;
@@ -105,21 +108,21 @@ int main(int argc, char** argv)
}
if (do_illegal_instruction || do_all_crash_types) {
- Crash("Illegal instruction", []() {
+ any_failures |= !Crash("Illegal instruction", []() {
asm volatile("ud2");
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
if (do_abort || do_all_crash_types) {
- Crash("Abort", []() {
+ any_failures |= !Crash("Abort", []() {
abort();
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
if (do_read_from_uninitialized_malloc_memory || do_all_crash_types) {
- Crash("Read from uninitialized malloc memory", []() {
+ any_failures |= !Crash("Read from uninitialized malloc memory", []() {
auto* uninitialized_memory = (volatile u32**)malloc(1024);
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;
@@ -130,7 +133,7 @@ int main(int argc, char** argv)
}
if (do_read_from_freed_memory || do_all_crash_types) {
- Crash("Read from freed memory", []() {
+ any_failures |= !Crash("Read from freed memory", []() {
auto* uninitialized_memory = (volatile u32**)malloc(1024);
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;
@@ -142,7 +145,7 @@ int main(int argc, char** argv)
}
if (do_write_to_uninitialized_malloc_memory || do_all_crash_types) {
- Crash("Write to uninitialized malloc memory", []() {
+ any_failures |= !Crash("Write to uninitialized malloc memory", []() {
auto* uninitialized_memory = (volatile u32**)malloc(1024);
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;
@@ -153,7 +156,7 @@ int main(int argc, char** argv)
}
if (do_write_to_freed_memory || do_all_crash_types) {
- Crash("Write to freed memory", []() {
+ any_failures |= !Crash("Write to freed memory", []() {
auto* uninitialized_memory = (volatile u32**)malloc(1024);
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;
@@ -165,7 +168,7 @@ int main(int argc, char** argv)
}
if (do_write_to_read_only_memory || do_all_crash_types) {
- Crash("Write to read only memory", []() {
+ any_failures |= !Crash("Write to read only memory", []() {
auto* ptr = (u8*)mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0);
if (ptr == MAP_FAILED)
return Crash::Failure::UnexpectedError;
@@ -181,7 +184,7 @@ int main(int argc, char** argv)
}
if (do_invalid_stack_pointer_on_syscall || do_all_crash_types) {
- Crash("Invalid stack pointer on syscall", []() {
+ any_failures |= !Crash("Invalid stack pointer on syscall", []() {
u8* makeshift_stack = (u8*)mmap(nullptr, 0, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_STACK, 0, 0);
if (!makeshift_stack)
return Crash::Failure::UnexpectedError;
@@ -203,7 +206,7 @@ int main(int argc, char** argv)
}
if (do_invalid_stack_pointer_on_page_fault || do_all_crash_types) {
- Crash("Invalid stack pointer on page fault", []() {
+ any_failures |= !Crash("Invalid stack pointer on page fault", []() {
u8* bad_stack = (u8*)mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (!bad_stack)
return Crash::Failure::UnexpectedError;
@@ -222,7 +225,7 @@ int main(int argc, char** argv)
}
if (do_syscall_from_writeable_memory || do_all_crash_types) {
- Crash("Syscall from writable memory", []() {
+ any_failures |= !Crash("Syscall from writable memory", []() {
u8 buffer[] = { 0xb8, Syscall::SC_getuid, 0, 0, 0, 0xcd, 0x82 };
((void (*)())buffer)();
return Crash::Failure::DidNotCrash;
@@ -230,7 +233,7 @@ int main(int argc, char** argv)
}
if (do_legitimate_syscall || do_all_crash_types) {
- Crash("Regular syscall from outside msyscall", []() {
+ any_failures |= !Crash("Regular syscall from outside msyscall", []() {
// Since 'crash' is dynamically linked, and DynamicLoader only allows LibSystem to make syscalls, this should kill us:
Syscall::invoke(Syscall::SC_getuid);
return Crash::Failure::DidNotCrash;
@@ -238,7 +241,7 @@ int main(int argc, char** argv)
}
if (do_execute_non_executable_memory || do_all_crash_types) {
- Crash("Execute non executable memory", []() {
+ any_failures |= !Crash("Execute non executable memory", []() {
auto* ptr = (u8*)mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (ptr == MAP_FAILED)
return Crash::Failure::UnexpectedError;
@@ -251,14 +254,14 @@ int main(int argc, char** argv)
}
if (do_trigger_user_mode_instruction_prevention || do_all_crash_types) {
- Crash("Trigger x86 User Mode Instruction Prevention", []() {
+ any_failures |= !Crash("Trigger x86 User Mode Instruction Prevention", []() {
asm volatile("str %eax");
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
if (do_use_io_instruction || do_all_crash_types) {
- Crash("Attempt to use an I/O instruction", [] {
+ any_failures |= !Crash("Attempt to use an I/O instruction", [] {
u8 keyboard_status = IO::in8(0x64);
outln("Keyboard status: {:#02x}", keyboard_status);
return Crash::Failure::DidNotCrash;
@@ -266,14 +269,14 @@ int main(int argc, char** argv)
}
if (do_read_cpu_counter || do_all_crash_types) {
- Crash("Read the CPU timestamp counter", [] {
+ any_failures |= !Crash("Read the CPU timestamp counter", [] {
asm volatile("rdtsc");
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
if (do_pledge_violation || do_all_crash_types) {
- Crash("Violate pledge()'d promises", [] {
+ any_failures |= !Crash("Violate pledge()'d promises", [] {
if (pledge("", nullptr) < 0) {
perror("pledge");
return Crash::Failure::DidNotCrash;
@@ -284,19 +287,19 @@ int main(int argc, char** argv)
}
if (do_failing_assertion || do_all_crash_types) {
- Crash("Perform a failing assertion", [] {
+ any_failures |= !Crash("Perform a failing assertion", [] {
VERIFY(1 == 2);
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
if (do_deref_null_refptr || do_all_crash_types) {
- Crash("Dereference a null RefPtr", [] {
+ any_failures |= !Crash("Dereference a null RefPtr", [] {
RefPtr<Core::Object> p;
*p;
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
- return 0;
+ return any_failures;
}
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 59f0eb38a9..20e7a0b20c 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -59,7 +59,6 @@ target_link_libraries(chres LibGUI)
target_link_libraries(cksum LibCrypto)
target_link_libraries(config LibConfig)
target_link_libraries(copy LibGUI)
-target_link_libraries(crash LibTest)
target_link_libraries(disasm LibX86)
target_link_libraries(expr LibRegex)
target_link_libraries(file LibGfx LibIPC LibCompress)