crashpad/client/crashpad_client_win_test.cc
Scott Graham 660a5e69d6 win: switch crashpad_handler.exe to /subsystem:windows and add .com
This switches the default behaviour of crashpad_handler.exe to be a
/subsystem:windows app, so that normal usage won't cause a console to be
popped up. At the same time, creates a copy of crashpad_handler.exe in
the output dir named crashpad_handler.com. The .com doesn't affect
normal operation, as the way StartHandler() uses CreateProcess()
requires a real path to a file. However, when run from a command prompt,
.com are found before .exe, so editbin the .com to be to a console app,
which will be run in preference to the exe when run as just
"crashpad_handler", as one tends to do from a command prompt when
debugging. That is:

  d:\src\crashpad\crashpad\out\Debug>where crashpad_handler
  d:\src\crashpad\crashpad\out\Debug\crashpad_handler.com
  d:\src\crashpad\crashpad\out\Debug\crashpad_handler.exe

  d:\src\crashpad\crashpad\out\Debug>crashpad_handler --help
  Usage: crashpad_handler [OPTION]...
  ...

  d:\src\crashpad\crashpad\out\Debug>crashpad_handler.exe --help
  <no output>

  d:\src\crashpad\crashpad\out\Debug>crashpad_handler.com --help
  Usage: crashpad_handler.com [OPTION]...
  ...

We also use the .com file in test invocations so that output streams
will be visible.

R=mark@chromium.org

Change-Id: I1a27f88472d491b2a1d76e63c45e6415d9f679c0
Reviewed-on: https://chromium-review.googlesource.com/371578
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-08-17 20:50:47 +00:00

92 lines
2.8 KiB
C++

// 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"
#include "base/files/file_path.h"
#include "gtest/gtest.h"
#include "test/paths.h"
#include "test/scoped_temp_dir.h"
#include "test/win/win_multiprocess.h"
namespace crashpad {
namespace test {
namespace {
void StartAndUseHandler() {
ScopedTempDir temp_dir;
base::FilePath handler_path = Paths::Executable().DirName().Append(
FILE_PATH_LITERAL("crashpad_handler.com"));
CrashpadClient client;
ASSERT_TRUE(client.StartHandler(handler_path,
temp_dir.path(),
"",
std::map<std::string, std::string>(),
std::vector<std::string>(),
false));
EXPECT_TRUE(client.UseHandler());
}
class StartWithInvalidHandles final : public WinMultiprocess {
public:
StartWithInvalidHandles() : WinMultiprocess() {}
~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);
StartAndUseHandler();
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
SetStdHandle(STD_ERROR_HANDLE, original_stderr);
}
};
TEST(CrashpadClient, StartWithInvalidHandles) {
WinMultiprocess::Run<StartWithInvalidHandles>();
}
class StartWithSameStdoutStderr final : public WinMultiprocess {
public:
StartWithSameStdoutStderr() : WinMultiprocess() {}
~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);
StartAndUseHandler();
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
}
};
TEST(CrashpadClient, StartWithSameStdoutStderr) {
WinMultiprocess::Run<StartWithSameStdoutStderr>();
}
} // namespace
} // namespace test
} // namespace crashpad