mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00

A challenge for getting LibTest working on Windows has always been CrashTest. It implements death tests similar to Google Test where a child process is cloned to invoke the expression that should abort/terminate the program. Then the exit code of the child is used by the parent test process to verify if the application correctly aborted/terminated due to invoking the expression. The problem was that finding an equivalent way to port Crash::run() to Windows was not looking very likely as publicly exposed Win32/ Native APIs have no equivalent to fork(); however, Windows actually does have native support for process cloning via undocumented NT APIs that clever people reverse engineered and published, see `NtCreateUserProcess()`. All that being said, this `EXPECT_DEATH()` implementation avoids needing to use a child process in general, allowing us to remove CrashTest in favour of a single cross-platform solution for death tests.
27 lines
527 B
C++
27 lines
527 B
C++
/*
|
|
* Copyright (c) 2025, ayeteadoe <ayeteadoe@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Platform.h>
|
|
#include <LibTest/Export.h>
|
|
#include <setjmp.h>
|
|
|
|
#ifndef AK_OS_WINDOWS
|
|
# define LIBTEST_SETJMP(env) sigsetjmp(env, 1)
|
|
# define LIBTEST_LONGJMP siglongjmp
|
|
#else
|
|
# define LIBTEST_SETJMP(env) setjmp(env)
|
|
# define LIBTEST_LONGJMP longjmp
|
|
#endif
|
|
|
|
namespace Test {
|
|
|
|
jmp_buf& assertion_jump_buffer();
|
|
void set_assertion_jump_validity(bool);
|
|
bool assertion_jump_validity();
|
|
|
|
}
|