mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-10 06:36:02 +00:00
Rather than having the 64-bit build assume that it lives in out\{Debug,Release}_x64 and that it can find 32-bit build output in out\{Debug,Release}, require the location of 32-bit build output to be provided explicitly via the CRASHPAD_TEST_32_BIT_OUTPUT environment variable. If this variable is not set, 64-bit tests that require 32-bit test build output will dynamically disable themselves at runtime. In order for this to work, a new DISABLED_TEST() macro is added to support dynamically disabled tests. gtest does not have its own first-class support for this (https://groups.google.com/d/topic/googletestframework/Nwh3u7YFuN4, https://github.com/google/googletest/issues/490) so this local solution is used instead. For tests via Crashpad’s own build\run_tests.py, which is how Crashpad’s own buildbots and trybots invoke tests, CRASHPAD_TEST_32_BIT_OUTPUT is set to a locaton compatible with the paths expected for the GYP-based build. No test coverage is lost on Crashpad’s own buildbots and trybots. For Crashpad tests in Chromium’s buildbots and trybots, this environment variable will not be set, causing these tests to be dynamically disabled. Bug: crashpad:203, chromium:743139, chromium:777924 Change-Id: I3c0de2bf4f835e13ed5a4adda5760d6fed508126 Reviewed-on: https://chromium-review.googlesource.com/739795 Commit-Queue: Mark Mentovai <mark@chromium.org> Reviewed-by: Scott Graham <scottmg@chromium.org>
133 lines
4.6 KiB
C++
133 lines
4.6 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 "snapshot/win/process_snapshot_win.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
#include "build/build_config.h"
|
|
#include "gtest/gtest.h"
|
|
#include "snapshot/win/pe_image_reader.h"
|
|
#include "snapshot/win/process_reader_win.h"
|
|
#include "test/errors.h"
|
|
#include "test/gtest_disabled.h"
|
|
#include "test/test_paths.h"
|
|
#include "test/win/child_launcher.h"
|
|
#include "util/file/file_io.h"
|
|
#include "util/win/scoped_handle.h"
|
|
#include "util/win/scoped_process_suspend.h"
|
|
|
|
namespace crashpad {
|
|
namespace test {
|
|
namespace {
|
|
|
|
void TestImageReaderChild(const base::FilePath& directory) {
|
|
UUID done_uuid;
|
|
done_uuid.InitializeWithNew();
|
|
ScopedKernelHANDLE done(
|
|
CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str()));
|
|
ASSERT_TRUE(done.is_valid()) << ErrorMessage("CreateEvent");
|
|
|
|
std::wstring child_test_executable = directory
|
|
.Append(TestPaths::Executable()
|
|
.BaseName()
|
|
.RemoveFinalExtension()
|
|
.value() +
|
|
L"_image_reader.exe")
|
|
.value();
|
|
ChildLauncher child(child_test_executable, done_uuid.ToString16());
|
|
ASSERT_NO_FATAL_FAILURE(child.Start());
|
|
|
|
char c;
|
|
ASSERT_TRUE(
|
|
LoggingReadFileExactly(child.stdout_read_handle(), &c, sizeof(c)));
|
|
ASSERT_EQ(c, ' ');
|
|
|
|
{
|
|
ScopedProcessSuspend suspend(child.process_handle());
|
|
|
|
ProcessSnapshotWin process_snapshot;
|
|
ASSERT_TRUE(process_snapshot.Initialize(
|
|
child.process_handle(), ProcessSuspensionState::kSuspended, 0, 0));
|
|
|
|
ASSERT_GE(process_snapshot.Modules().size(), 2u);
|
|
|
|
UUID uuid;
|
|
DWORD age;
|
|
std::string pdbname;
|
|
const std::string suffix(".pdb");
|
|
|
|
// Check the main .exe to see that we can retrieve its sections.
|
|
auto module = reinterpret_cast<const internal::ModuleSnapshotWin*>(
|
|
process_snapshot.Modules()[0]);
|
|
ASSERT_TRUE(module->pe_image_reader().DebugDirectoryInformation(
|
|
&uuid, &age, &pdbname));
|
|
EXPECT_NE(pdbname.find("crashpad_snapshot_test_image_reader"),
|
|
std::string::npos);
|
|
EXPECT_EQ(
|
|
pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix),
|
|
0);
|
|
|
|
// Check the dll it loads too.
|
|
module = reinterpret_cast<const internal::ModuleSnapshotWin*>(
|
|
process_snapshot.Modules().back());
|
|
ASSERT_TRUE(module->pe_image_reader().DebugDirectoryInformation(
|
|
&uuid, &age, &pdbname));
|
|
EXPECT_NE(pdbname.find("crashpad_snapshot_test_image_reader_module"),
|
|
std::string::npos);
|
|
EXPECT_EQ(
|
|
pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix),
|
|
0);
|
|
|
|
// Sum the size of the extra memory in all the threads and confirm it's near
|
|
// the limit that the child process set in its CrashpadInfo.
|
|
EXPECT_GE(process_snapshot.Threads().size(), 100u);
|
|
|
|
size_t extra_memory_total = 0;
|
|
for (const auto* thread : process_snapshot.Threads()) {
|
|
for (const auto* extra_memory : thread->ExtraMemory()) {
|
|
extra_memory_total += extra_memory->Size();
|
|
}
|
|
}
|
|
|
|
// Confirm that less than 1M of extra data was gathered. The cap is set to
|
|
// only 100K, but there are other "extra memory" regions that aren't
|
|
// included in the cap. (Completely uncapped it would be > 10M.)
|
|
EXPECT_LT(extra_memory_total, 1000000u);
|
|
}
|
|
|
|
// Tell the child it can terminate.
|
|
EXPECT_TRUE(SetEvent(done.get())) << ErrorMessage("SetEvent");
|
|
|
|
EXPECT_EQ(child.WaitForExit(), 0);
|
|
}
|
|
|
|
TEST(ProcessSnapshotTest, CrashpadInfoChild) {
|
|
TestImageReaderChild(TestPaths::Executable().DirName());
|
|
}
|
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
|
TEST(ProcessSnapshotTest, CrashpadInfoChildWOW64) {
|
|
base::FilePath output_32_bit_directory = TestPaths::Output32BitDirectory();
|
|
if (output_32_bit_directory.empty()) {
|
|
DISABLED_TEST();
|
|
}
|
|
|
|
TestImageReaderChild(output_32_bit_directory);
|
|
}
|
|
#endif
|
|
|
|
} // namespace
|
|
} // namespace test
|
|
} // namespace crashpad
|