test: Fix paths for crashpad_tests monolith in Chromium

Instead of individual per-directory test executables like
crashpad_util_test, all Crashpad tests in Chromium will be run from a
single crashpad_tests executable.

Test: crashpad_util_test Paths.Executable, ProcessInfo.Self; crashpad_snapshot_test PEImageReader.DebugDirectory
Bug: chromium:779790
Change-Id: If95272fd641734fbdb8e231fbcdc4e7ccb2cb822
Reviewed-on: https://chromium-review.googlesource.com/749303
Reviewed-by: Scott Graham <scottmg@chromium.org>
This commit is contained in:
Mark Mentovai 2017-11-01 10:46:35 -04:00
parent c542a5ae03
commit 43b798b492
5 changed files with 52 additions and 12 deletions

View File

@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "snapshot/win/process_reader_win.h"
#include "test/errors.h"
#include "test/test_paths.h"
#include "util/misc/from_pointer_cast.h"
#include "util/win/get_module_information.h"
#include "util/win/module_version.h"
@ -52,7 +53,11 @@ TEST(PEImageReader, DebugDirectory) {
DWORD age;
std::string pdbname;
EXPECT_TRUE(pe_image_reader.DebugDirectoryInformation(&uuid, &age, &pdbname));
EXPECT_NE(pdbname.find("crashpad_snapshot_test"), std::string::npos);
std::string self_name = base::UTF16ToUTF8(
TestPaths::ExpectedExecutableBasename(L"crashpad_snapshot_test")
.RemoveFinalExtension()
.value());
EXPECT_NE(pdbname.find(self_name), std::string::npos);
const std::string suffix(".pdb");
EXPECT_EQ(
pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix),

View File

@ -116,6 +116,23 @@ base::FilePath TestPaths::Executable() {
return executable_path;
}
// static
base::FilePath TestPaths::ExpectedExecutableBasename(
const base::FilePath::StringType& name) {
#if defined(CRASHPAD_IN_CHROMIUM)
base::FilePath::StringType executable_name(
FILE_PATH_LITERAL("crashpad_tests"));
#else // CRASHPAD_IN_CHROMIUM
base::FilePath::StringType executable_name(name);
#endif // CRASHPAD_IN_CHROMIUM
#if defined(OS_WIN)
executable_name += FILE_PATH_LITERAL(".exe");
#endif // OS_WIN
return base::FilePath(executable_name);
}
// static
base::FilePath TestPaths::TestDataRoot() {
static base::FilePath* test_data_root =

View File

@ -62,6 +62,24 @@ class TestPaths {
//! On failure, aborts execution.
static base::FilePath Executable();
//! \brief Returns the expected basename of the currently-running test
//! executable.
//!
//! In Crashpads standalone build, this returns \a name, with the systems
//! extension for executables (`.exe`) appended if appropriate.
//!
//! When building in Chromium, \a name is ignored, and the name of the
//! monolithic test executable (`crashpad_tests`) is returned, with the
//! systems extension for executables appended if appropriate.
//!
//! Only use this function to determine test expectations.
//!
//! Do not use this function to obtain the name of the currently running test
//! executable, use Executable() instead. Do not use this function to locate
//! other build artifacts, use BuildArtifact() instead.
static base::FilePath ExpectedExecutableBasename(
const base::FilePath::StringType& name);
//! \brief Returns the pathname of the test data root.
//!
//! If the `CRASHPAD_TEST_DATA_ROOT` environment variable is set, its value

View File

@ -15,8 +15,8 @@
#include "util/misc/paths.h"
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "test/test_paths.h"
namespace crashpad {
namespace test {
@ -26,12 +26,10 @@ TEST(Paths, Executable) {
base::FilePath executable_path;
ASSERT_TRUE(Paths::Executable(&executable_path));
const base::FilePath executable_name(executable_path.BaseName());
#if defined(OS_WIN)
EXPECT_EQ(executable_name.value(),
FILE_PATH_LITERAL("crashpad_util_test.exe"));
#else
EXPECT_EQ(executable_name.value(), "crashpad_util_test");
#endif // OS_WIN
const base::FilePath expected_name(TestPaths::ExpectedExecutableBasename(
FILE_PATH_LITERAL("crashpad_util_test")));
EXPECT_EQ(executable_name.value(), expected_name.value());
}
} // namespace

View File

@ -104,10 +104,12 @@ TEST(ProcessInfo, Self) {
std::vector<ProcessInfo::Module> modules;
EXPECT_TRUE(process_info.Modules(&modules));
ASSERT_GE(modules.size(), 2u);
static constexpr wchar_t kSelfName[] = L"\\crashpad_util_test.exe";
ASSERT_GE(modules[0].name.size(), wcslen(kSelfName));
EXPECT_EQ(modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName)),
kSelfName);
std::wstring self_name =
std::wstring(1, '\\') +
TestPaths::ExpectedExecutableBasename(L"crashpad_util_test").value();
ASSERT_GE(modules[0].name.size(), self_name.size());
EXPECT_EQ(modules[0].name.substr(modules[0].name.size() - self_name.size()),
self_name);
ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName));
EXPECT_EQ(modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName)),
kNtdllName);