2015-11-19 11:25:52 -08:00
|
|
|
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2017-03-24 15:24:11 -04:00
|
|
|
#include <vector>
|
|
|
|
|
2015-11-19 11:25:52 -08:00
|
|
|
#include "base/files/file_path.h"
|
2016-11-03 09:38:14 -07:00
|
|
|
#include "base/macros.h"
|
2017-03-24 15:24:11 -04:00
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
#include "base/logging.h"
|
2015-11-19 11:25:52 -08:00
|
|
|
#include "gtest/gtest.h"
|
2017-04-03 13:53:11 -04:00
|
|
|
#include "test/test_paths.h"
|
2017-04-07 10:46:41 -04:00
|
|
|
#include "test/scoped_temp_dir.h"
|
2015-11-19 11:25:52 -08:00
|
|
|
#include "test/win/win_multiprocess.h"
|
2017-04-07 10:46:41 -04:00
|
|
|
#include "test/win/win_multiprocess_with_temp_dir.h"
|
2017-03-24 15:24:11 -04:00
|
|
|
#include "util/win/scoped_handle.h"
|
2016-11-03 09:38:14 -07:00
|
|
|
#include "util/win/termination_codes.h"
|
2015-11-19 11:25:52 -08:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
2017-03-24 15:24:11 -04:00
|
|
|
void StartAndUseHandler(const base::FilePath& temp_dir) {
|
2017-04-03 13:53:11 -04:00
|
|
|
base::FilePath handler_path = TestPaths::Executable().DirName().Append(
|
2016-08-16 16:30:31 -07:00
|
|
|
FILE_PATH_LITERAL("crashpad_handler.com"));
|
2017-03-24 15:24:11 -04:00
|
|
|
|
2015-11-19 11:25:52 -08:00
|
|
|
CrashpadClient client;
|
|
|
|
ASSERT_TRUE(client.StartHandler(handler_path,
|
2017-03-24 15:24:11 -04:00
|
|
|
temp_dir,
|
2016-09-16 13:21:50 -07:00
|
|
|
base::FilePath(),
|
2015-11-19 11:25:52 -08:00
|
|
|
"",
|
|
|
|
std::map<std::string, std::string>(),
|
|
|
|
std::vector<std::string>(),
|
2016-10-21 13:08:18 -07:00
|
|
|
true,
|
|
|
|
true));
|
2016-12-12 20:57:48 -08:00
|
|
|
ASSERT_TRUE(client.WaitForHandlerStart(INFINITE));
|
2015-11-19 11:25:52 -08:00
|
|
|
}
|
|
|
|
|
2017-03-24 15:24:11 -04:00
|
|
|
class StartWithInvalidHandles final : public WinMultiprocessWithTempDir {
|
2015-11-19 11:25:52 -08:00
|
|
|
public:
|
2017-03-24 15:24:11 -04:00
|
|
|
StartWithInvalidHandles() : WinMultiprocessWithTempDir() {}
|
2015-11-19 11:25:52 -08:00
|
|
|
~StartWithInvalidHandles() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WinMultiprocessParent() override {}
|
|
|
|
|
|
|
|
void WinMultiprocessChild() override {
|
|
|
|
HANDLE original_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
HANDLE original_stderr = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
|
|
|
|
2017-04-07 10:46:41 -04:00
|
|
|
StartAndUseHandler(GetTempDirPath());
|
2015-11-19 11:25:52 -08:00
|
|
|
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE, original_stderr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, StartWithInvalidHandles) {
|
2017-04-07 10:46:41 -04:00
|
|
|
WinMultiprocessWithTempDir::Run<StartWithInvalidHandles>();
|
2015-11-19 11:25:52 -08:00
|
|
|
}
|
|
|
|
|
2017-03-24 15:24:11 -04:00
|
|
|
class StartWithSameStdoutStderr final : public WinMultiprocessWithTempDir {
|
2015-11-19 11:25:52 -08:00
|
|
|
public:
|
2017-03-24 15:24:11 -04:00
|
|
|
StartWithSameStdoutStderr() : WinMultiprocessWithTempDir() {}
|
2015-11-19 11:25:52 -08:00
|
|
|
~StartWithSameStdoutStderr() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WinMultiprocessParent() override {}
|
|
|
|
|
|
|
|
void WinMultiprocessChild() override {
|
|
|
|
HANDLE original_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
HANDLE original_stderr = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, original_stderr);
|
|
|
|
|
2017-04-07 10:46:41 -04:00
|
|
|
StartAndUseHandler(GetTempDirPath());
|
2015-11-19 11:25:52 -08:00
|
|
|
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, StartWithSameStdoutStderr) {
|
2017-04-07 10:46:41 -04:00
|
|
|
WinMultiprocessWithTempDir::Run<StartWithSameStdoutStderr>();
|
2015-11-19 11:25:52 -08:00
|
|
|
}
|
|
|
|
|
2016-11-03 09:38:14 -07:00
|
|
|
void StartAndUseBrokenHandler(CrashpadClient* client) {
|
|
|
|
ScopedTempDir temp_dir;
|
2017-04-03 13:53:11 -04:00
|
|
|
base::FilePath handler_path = TestPaths::Executable().DirName().Append(
|
2016-11-03 09:38:14 -07:00
|
|
|
FILE_PATH_LITERAL("fake_handler_that_crashes_at_startup.exe"));
|
|
|
|
ASSERT_TRUE(client->StartHandler(handler_path,
|
|
|
|
temp_dir.path(),
|
|
|
|
base::FilePath(),
|
|
|
|
"",
|
|
|
|
std::map<std::string, std::string>(),
|
|
|
|
std::vector<std::string>(),
|
|
|
|
false,
|
|
|
|
true));
|
|
|
|
}
|
|
|
|
|
|
|
|
class HandlerLaunchFailureCrash : public WinMultiprocess {
|
|
|
|
public:
|
|
|
|
HandlerLaunchFailureCrash() : WinMultiprocess() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WinMultiprocessParent() override {
|
|
|
|
SetExpectedChildExitCode(crashpad::kTerminationCodeCrashNoDump);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinMultiprocessChild() override {
|
|
|
|
CrashpadClient client;
|
|
|
|
StartAndUseBrokenHandler(&client);
|
|
|
|
__debugbreak();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, HandlerLaunchFailureCrash) {
|
|
|
|
WinMultiprocess::Run<HandlerLaunchFailureCrash>();
|
|
|
|
}
|
|
|
|
|
|
|
|
class HandlerLaunchFailureDumpAndCrash : public WinMultiprocess {
|
|
|
|
public:
|
|
|
|
HandlerLaunchFailureDumpAndCrash() : WinMultiprocess() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WinMultiprocessParent() override {
|
|
|
|
SetExpectedChildExitCode(crashpad::kTerminationCodeCrashNoDump);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinMultiprocessChild() override {
|
|
|
|
CrashpadClient client;
|
|
|
|
StartAndUseBrokenHandler(&client);
|
|
|
|
// We don't need to fill this out as we're only checking that we're
|
|
|
|
// terminated with the correct failure code.
|
|
|
|
EXCEPTION_POINTERS info = {};
|
|
|
|
client.DumpAndCrash(&info);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, HandlerLaunchFailureDumpAndCrash) {
|
|
|
|
WinMultiprocess::Run<HandlerLaunchFailureDumpAndCrash>();
|
|
|
|
}
|
|
|
|
|
|
|
|
class HandlerLaunchFailureDumpWithoutCrash : public WinMultiprocess {
|
|
|
|
public:
|
|
|
|
HandlerLaunchFailureDumpWithoutCrash() : WinMultiprocess() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void WinMultiprocessParent() override {
|
|
|
|
// DumpWithoutCrash() normally blocks indefinitely. There's no return value,
|
|
|
|
// but confirm that it exits cleanly because it'll return right away if the
|
|
|
|
// handler didn't start.
|
|
|
|
SetExpectedChildExitCode(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinMultiprocessChild() override {
|
|
|
|
CrashpadClient client;
|
|
|
|
StartAndUseBrokenHandler(&client);
|
|
|
|
// We don't need to fill this out as we're only checking that we're
|
|
|
|
// terminated with the correct failure code.
|
|
|
|
CONTEXT context = {};
|
|
|
|
client.DumpWithoutCrash(context);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, HandlerLaunchFailureDumpWithoutCrash) {
|
|
|
|
WinMultiprocess::Run<HandlerLaunchFailureDumpWithoutCrash>();
|
|
|
|
}
|
|
|
|
|
2015-11-19 11:25:52 -08:00
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|