diff --git a/snapshot/win/pe_image_reader_test.cc b/snapshot/win/pe_image_reader_test.cc index 145e8676..3192a446 100644 --- a/snapshot/win/pe_image_reader_test.cc +++ b/snapshot/win/pe_image_reader_test.cc @@ -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), diff --git a/test/test_paths.cc b/test/test_paths.cc index ae1c5baa..ce180a37 100644 --- a/test/test_paths.cc +++ b/test/test_paths.cc @@ -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 = diff --git a/test/test_paths.h b/test/test_paths.h index 2e89ac79..5540f77d 100644 --- a/test/test_paths.h +++ b/test/test_paths.h @@ -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 Crashpad’s standalone build, this returns \a name, with the system’s + //! 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 + //! system’s 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 diff --git a/util/misc/paths_test.cc b/util/misc/paths_test.cc index 1f373029..f0503ddc 100644 --- a/util/misc/paths_test.cc +++ b/util/misc/paths_test.cc @@ -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 diff --git a/util/win/process_info_test.cc b/util/win/process_info_test.cc index 93cf099e..709536b9 100644 --- a/util/win/process_info_test.cc +++ b/util/win/process_info_test.cc @@ -104,10 +104,12 @@ TEST(ProcessInfo, Self) { std::vector 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);