diff options
author | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-01-07 02:25:22 +0000 |
---|---|---|
committer | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-01-07 02:25:22 +0000 |
commit | 07e521c396be01162b4cb8119954401b7eaa510c (patch) | |
tree | 8af73fa62c70581555d2e8e3c1abf0d708e78f3d /src/common/linux/memory_mapped_file_unittest.cc | |
parent | Send crash dumps to Google via HTTPS instead of HTTP, since they might (diff) | |
download | breakpad-07e521c396be01162b4cb8119954401b7eaa510c.tar.xz |
Add utilities for processing Linux core dump files.
This patch is part of a bigger patch that helps merging the breakpad code
with the modified version in Chromium OS.
Specifically, this patch makes the following changes:
1. Add an ElfCoreDump class for processing Linux core dump files, which will
later be used to implement the core dump to minidump conversion.
2. Add a CrashGenerator class for generating a crash with a core dump file
for testing the functionalities of ElfCoreDump.
3. Move some utility functions for reading/writing files to file_utils.h.
BUG=455
TEST=Tested the following:
1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6.
2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock).
3. All unit tests pass.
Review URL: http://breakpad.appspot.com/337001
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@900 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/linux/memory_mapped_file_unittest.cc')
-rw-r--r-- | src/common/linux/memory_mapped_file_unittest.cc | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/src/common/linux/memory_mapped_file_unittest.cc b/src/common/linux/memory_mapped_file_unittest.cc index 8a3129fb..cf89bca9 100644 --- a/src/common/linux/memory_mapped_file_unittest.cc +++ b/src/common/linux/memory_mapped_file_unittest.cc @@ -40,32 +40,15 @@ #include "common/linux/eintr_wrapper.h" #include "common/linux/memory_mapped_file.h" #include "common/tests/auto_tempdir.h" +#include "common/tests/file_utils.h" using google_breakpad::AutoTempDir; using google_breakpad::MemoryMappedFile; +using google_breakpad::WriteFile; using std::string; namespace { -bool WriteFile(const string& path, const void* buffer, size_t buffer_size) { - int fd = - HANDLE_EINTR(open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, S_IRWXU)); - if (fd == -1) { - perror("open"); - return false; - } - - bool ok = true; - if (buffer && buffer_size > 0) { - if (HANDLE_EINTR(write(fd, buffer, buffer_size) != buffer_size)) { - perror("write"); - ok = false; - } - } - close(fd); - return ok; -} - class MemoryMappedFileTest : public testing::Test { protected: void ExpectNoMappedData(const MemoryMappedFile& mapped_file) { @@ -102,7 +85,7 @@ TEST_F(MemoryMappedFileTest, MapNonexistentFile) { TEST_F(MemoryMappedFileTest, MapEmptyFile) { AutoTempDir temp_dir; string test_file = temp_dir.path() + "/empty_file"; - ASSERT_TRUE(WriteFile(test_file, NULL, 0)); + ASSERT_TRUE(WriteFile(test_file.c_str(), NULL, 0)); { MemoryMappedFile mapped_file(test_file.c_str()); @@ -124,7 +107,7 @@ TEST_F(MemoryMappedFileTest, MapNonEmptyFile) { AutoTempDir temp_dir; string test_file = temp_dir.path() + "/test_file"; - ASSERT_TRUE(WriteFile(test_file, data, data_size)); + ASSERT_TRUE(WriteFile(test_file.c_str(), data, data_size)); { MemoryMappedFile mapped_file(test_file.c_str()); @@ -159,8 +142,8 @@ TEST_F(MemoryMappedFileTest, RemapAfterMap) { AutoTempDir temp_dir; string test_file1 = temp_dir.path() + "/test_file1"; string test_file2 = temp_dir.path() + "/test_file2"; - ASSERT_TRUE(WriteFile(test_file1, data1, data1_size)); - ASSERT_TRUE(WriteFile(test_file2, data2, data2_size)); + ASSERT_TRUE(WriteFile(test_file1.c_str(), data1, data1_size)); + ASSERT_TRUE(WriteFile(test_file2.c_str(), data2, data2_size)); { MemoryMappedFile mapped_file(test_file1.c_str()); |