diff options
author | dcaiafa <dcaiafa@chromium.org> | 2015-07-16 17:09:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-17 00:11:02 +0000 |
commit | 4306386450441c312f0e94af12074ae1534b4117 (patch) | |
tree | 3dbf14c87caf8163af08b9642ab4685536248a00 /chromecast/crash/linux/dummy_minidump_generator_unittest.cc | |
parent | abc0faae61c7b13c9e98a28f183b688d09142795 (diff) | |
download | chromium_src-4306386450441c312f0e94af12074ae1534b4117.zip chromium_src-4306386450441c312f0e94af12074ae1534b4117.tar.gz chromium_src-4306386450441c312f0e94af12074ae1534b4117.tar.bz2 |
Revert of Replace system IO calls in chromecast/crash with Chrome utilities. (patchset #9 id:160001 of https://codereview.chromium.org/1227963002/)
Reason for revert:
Breaks CastCrashReporterClientTest.EndToEndTestOnIORestrictedThread:
https://build.chromium.org/p/chromium.linux/builders/Cast%20Linux/builds/2709
Original issue's description:
> Replace system IO calls in chromecast/crash with Chrome utilities.
>
> System IO calls had been used to avoid thread IO restrictions in the
> crash handler. This change replaces each of these calls with the more
> platform-independent, stable Chrome IO utilities from ::base. Thread
> restrictions are disabled in crash_util.cc.
>
> BUG= b/22329428
>
> Committed: https://crrev.com/4927df40d0342522fc268f884835b43f9004549e
> Cr-Commit-Position: refs/heads/master@{#339161}
TBR=wzhong@chromium.org,bcf@google.com,gunsch@chromium.org,gfhuang@chromium.org,slan@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG= b/22329428
Review URL: https://codereview.chromium.org/1239083005
Cr-Commit-Position: refs/heads/master@{#339183}
Diffstat (limited to 'chromecast/crash/linux/dummy_minidump_generator_unittest.cc')
-rw-r--r-- | chromecast/crash/linux/dummy_minidump_generator_unittest.cc | 90 |
1 files changed, 85 insertions, 5 deletions
diff --git a/chromecast/crash/linux/dummy_minidump_generator_unittest.cc b/chromecast/crash/linux/dummy_minidump_generator_unittest.cc index d70ea76..c38304f 100644 --- a/chromecast/crash/linux/dummy_minidump_generator_unittest.cc +++ b/chromecast/crash/linux/dummy_minidump_generator_unittest.cc @@ -11,6 +11,12 @@ namespace chromecast { +namespace { +// This value should stay in sync with the internal buffer size used in +// CopyAndDelete(). +const int kInternalBufferSize = 32768; +} // namespace + TEST(DummyMinidumpGeneratorTest, GenerateFailsWithInvalidPath) { // Create directory in which to put minidump. base::FilePath minidump_dir; @@ -21,7 +27,7 @@ TEST(DummyMinidumpGeneratorTest, GenerateFailsWithInvalidPath) { ASSERT_FALSE(generator.Generate(minidump_dir.Append("minidump.dmp").value())); } -TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithSmallSource) { +TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithValidPath) { // Create directory in which to put minidump. base::FilePath minidump_dir; ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir)); @@ -46,24 +52,98 @@ TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithSmallSource) { EXPECT_EQ(data, copied_data); } -TEST(DummyMinidumpGeneratorTest, GenerateSucceedsWithLargeSource) { +TEST(DummyMinidumpGeneratorTest, CopyAndDeleteFailsWithInvalidSource) { + // Create directory in which to put minidump. + base::FilePath minidump_dir; + ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir)); + + // Attempt to copy from an invalid path. + DummyMinidumpGenerator generator("/path/does/not/exist/minidump.dmp"); + ASSERT_FALSE(generator.CopyAndDeleteForTest( + minidump_dir.Append("minidump.dmp").value())); +} + +TEST(DummyMinidumpGeneratorTest, CopyAndDeleteSucceedsWithSmallSource) { + // Create directory in which to put minidump. + base::FilePath minidump_dir; + ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir)); + + // Create a fake minidump file. + base::FilePath fake_minidump; + ASSERT_TRUE(base::CreateTemporaryFile(&fake_minidump)); + const std::string data("Test contents of the minidump file.\n"); + ASSERT_EQ(static_cast<int>(data.size()), + base::WriteFile(fake_minidump, data.c_str(), data.size())); + + base::FilePath new_minidump = minidump_dir.Append("minidump.dmp"); + DummyMinidumpGenerator generator(fake_minidump.value()); + ASSERT_TRUE(generator.CopyAndDeleteForTest(new_minidump.value())); + + // Original file should not exist, and new file should contain original + // contents. + std::string copied_data; + EXPECT_FALSE(base::PathExists(fake_minidump)); + ASSERT_TRUE(base::PathExists(new_minidump)); + EXPECT_TRUE(base::ReadFileToString(new_minidump, &copied_data)); + EXPECT_EQ(data, copied_data); +} + +TEST(DummyMinidumpGeneratorTest, CopyAndDeleteSucceedsWithLargeSource) { + // Create directory in which to put minidump. + base::FilePath minidump_dir; + ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir)); + + // Create a large fake minidump file. + // Note: The file must be greater than the size of the buffer used to copy the + // file in CopyAndDelete(). Create a big string in memory. + base::FilePath fake_minidump; + ASSERT_TRUE(base::CreateTemporaryFile(&fake_minidump)); + size_t str_len = kInternalBufferSize * 10 + 1; + const std::string data = base::RandBytesAsString(str_len); + + // Write the string to the file and verify that the file is big enough. + ASSERT_EQ(static_cast<int>(data.size()), + base::WriteFile(fake_minidump, data.c_str(), data.size())); + int64_t filesize = 0; + ASSERT_TRUE(base::GetFileSize(fake_minidump, &filesize)); + ASSERT_GT(filesize, kInternalBufferSize); + + base::FilePath new_minidump = minidump_dir.Append("minidump.dmp"); + DummyMinidumpGenerator generator(fake_minidump.value()); + ASSERT_TRUE(generator.CopyAndDeleteForTest(new_minidump.value())); + + // Original file should not exist, and new file should contain original + // contents. + std::string copied_data; + EXPECT_FALSE(base::PathExists(fake_minidump)); + ASSERT_TRUE(base::PathExists(new_minidump)); + EXPECT_TRUE(base::ReadFileToString(new_minidump, &copied_data)); + EXPECT_EQ(data, copied_data); +} + +TEST(DummyMinidumpGeneratorTest, CopyAndDeleteSucceedsWhenEOFAlignsWithBuffer) { // Create directory in which to put minidump. base::FilePath minidump_dir; ASSERT_TRUE(base::CreateNewTempDirectory("", &minidump_dir)); // Create a large fake minidump file. + // Note: The file must be greater than the size of the buffer used to copy the + // file in CopyAndDelete(). Create a big string in memory. base::FilePath fake_minidump; ASSERT_TRUE(base::CreateTemporaryFile(&fake_minidump)); - size_t str_len = 32768 * 10 + 1; + size_t str_len = kInternalBufferSize; const std::string data = base::RandBytesAsString(str_len); - // Write the string to the file. + // Write the string to the file and verify that the file is big enough. ASSERT_EQ(static_cast<int>(data.size()), base::WriteFile(fake_minidump, data.c_str(), data.size())); + int64_t filesize = 0; + ASSERT_TRUE(base::GetFileSize(fake_minidump, &filesize)); + ASSERT_EQ(kInternalBufferSize, filesize); base::FilePath new_minidump = minidump_dir.Append("minidump.dmp"); DummyMinidumpGenerator generator(fake_minidump.value()); - ASSERT_TRUE(generator.Generate(new_minidump.value())); + ASSERT_TRUE(generator.CopyAndDeleteForTest(new_minidump.value())); // Original file should not exist, and new file should contain original // contents. |