crashpad/handler/win/wer/crashpad_wer_module_unittest.cc
Mark Mentovai 6278690abe Update copyright boilerplate, 2022 edition (Crashpad)
sed -i '' -E -e 's/Copyright (.+) The Crashpad Authors\. All rights reserved\.$/Copyright \1 The Crashpad Authors/' $(git grep -El 'Copyright (.+) The Crashpad Authors\. All rights reserved\.$')

Bug: chromium:1098010
Change-Id: I8d6138469ddbe3d281a5d83f64cf918ec2491611
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3878262
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-09-06 23:54:07 +00:00

87 lines
2.8 KiB
C++

// Copyright 2022 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "client/crashpad_client.h"
#include "base/files/file_path.h"
#include "gtest/gtest.h"
#include "test/test_paths.h"
#include "util/win/registration_protocol_win.h"
#include <Windows.h>
#include <werapi.h>
namespace crashpad {
namespace test {
namespace {
base::FilePath ModulePath() {
auto dir = TestPaths::Executable().DirName();
return dir.Append(FILE_PATH_LITERAL("crashpad_wer.dll"));
}
// Quick sanity check of the module, can't really test dumping etc. outside of
// WerFault.exe loading it.
TEST(CrashpadWerModule, Basic) {
HRESULT res = 0;
// Module loads.
HMODULE hMod = LoadLibraryW(ModulePath().value().c_str());
ASSERT_TRUE(hMod);
// Required functions exist.
auto wref = reinterpret_cast<PFN_WER_RUNTIME_EXCEPTION_EVENT>(
GetProcAddress(hMod, WER_RUNTIME_EXCEPTION_EVENT_FUNCTION));
ASSERT_TRUE(wref);
auto wrees = reinterpret_cast<PFN_WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE>(
GetProcAddress(hMod, WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE_FUNCTION));
ASSERT_TRUE(wrees);
auto wredl = reinterpret_cast<PFN_WER_RUNTIME_EXCEPTION_DEBUGGER_LAUNCH>(
GetProcAddress(hMod, WER_RUNTIME_EXCEPTION_DEBUGGER_LAUNCH));
ASSERT_TRUE(wredl);
// Not-implemented functions return E_FAIL as expected.
res = wrees(nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr);
ASSERT_EQ(res, E_FAIL);
res = wredl(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
ASSERT_EQ(res, E_FAIL);
// Dummy args for OutOfProcessExceptionEventCallback.
crashpad::WerRegistration registration;
WER_RUNTIME_EXCEPTION_INFORMATION wer_ex;
BOOL bClaimed = FALSE;
// No context => skip.
res = wref(nullptr, &wer_ex, &bClaimed, nullptr, nullptr, nullptr);
ASSERT_EQ(res, S_OK);
ASSERT_EQ(bClaimed, FALSE);
// Non-fatal exceptions are skipped.
wer_ex.bIsFatal = FALSE;
res = wref(&registration, &wer_ex, &bClaimed, nullptr, nullptr, nullptr);
ASSERT_EQ(res, S_OK);
ASSERT_EQ(bClaimed, FALSE);
// Fatal exception with unhandled code is skipped.
wer_ex.bIsFatal = TRUE;
wer_ex.exceptionRecord.ExceptionCode = 0xc0000005;
res = wref(&registration, &wer_ex, &bClaimed, nullptr, nullptr, nullptr);
ASSERT_EQ(res, S_OK);
ASSERT_EQ(bClaimed, FALSE);
FreeLibrary(hMod);
}
} // namespace
} // namespace test
} // namespace crashpad