aboutsummaryrefslogtreecommitdiff
path: root/src/client/linux/minidump_writer/minidump_writer_unittest.cc
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-08-09 22:59:58 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-08-09 22:59:58 +0000
commit43c933d7f8e490d9dbf3f939f3b2f095a170dc84 (patch)
tree153b8e0393f5e9f9f7edcf7f1d905cfd58571bad /src/client/linux/minidump_writer/minidump_writer_unittest.cc
parentClean up warnings about narrowing conversion (diff)
downloadbreakpad-43c933d7f8e490d9dbf3f939f3b2f095a170dc84.tar.xz
Adding a way to create an ExceptionHandler that takes in a file descriptor
where the minidump should be created, without the need of opening any other file. BUG=None TEST=Run unit-tests. git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1007 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/linux/minidump_writer/minidump_writer_unittest.cc')
-rw-r--r--src/client/linux/minidump_writer/minidump_writer_unittest.cc39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/client/linux/minidump_writer/minidump_writer_unittest.cc b/src/client/linux/minidump_writer/minidump_writer_unittest.cc
index 31e1440d..1fff015f 100644
--- a/src/client/linux/minidump_writer/minidump_writer_unittest.cc
+++ b/src/client/linux/minidump_writer/minidump_writer_unittest.cc
@@ -60,7 +60,7 @@ namespace {
typedef testing::Test MinidumpWriterTest;
}
-TEST(MinidumpWriterTest, Setup) {
+TEST(MinidumpWriterTest, SetupWithPath) {
int fds[2];
ASSERT_NE(-1, pipe(fds));
@@ -89,6 +89,36 @@ TEST(MinidumpWriterTest, Setup) {
close(fds[1]);
}
+TEST(MinidumpWriterTest, SetupWithFD) {
+ int fds[2];
+ ASSERT_NE(-1, pipe(fds));
+
+ const pid_t child = fork();
+ if (child == 0) {
+ close(fds[1]);
+ char b;
+ HANDLE_EINTR(read(fds[0], &b, sizeof(b)));
+ close(fds[0]);
+ syscall(__NR_exit);
+ }
+ close(fds[0]);
+
+ ExceptionHandler::CrashContext context;
+ memset(&context, 0, sizeof(context));
+
+ AutoTempDir temp_dir;
+ string templ = temp_dir.path() + "/minidump-writer-unittest";
+ int fd = open(templ.c_str(), O_CREAT | O_WRONLY, S_IRWXU);
+ // Set a non-zero tid to avoid tripping asserts.
+ context.tid = 1;
+ ASSERT_TRUE(WriteMinidump(fd, child, &context, sizeof(context)));
+ struct stat st;
+ ASSERT_EQ(stat(templ.c_str(), &st), 0);
+ ASSERT_GT(st.st_size, 0u);
+
+ close(fds[1]);
+}
+
// Test that mapping info can be specified when writing a minidump,
// and that it ends up in the module list of the minidump.
TEST(MinidumpWriterTest, MappingInfo) {
@@ -261,9 +291,8 @@ TEST(MinidumpWriterTest, MappingInfoContained) {
mapping.first = info;
memcpy(mapping.second, kModuleGUID, sizeof(MDGUID));
mappings.push_back(mapping);
- ASSERT_TRUE(
- WriteMinidump(dumpfile.c_str(), child, &context, sizeof(context),
- mappings));
+ ASSERT_TRUE(WriteMinidump(dumpfile.c_str(), child, &context, sizeof(context),
+ mappings));
// Read the minidump. Load the module list, and ensure that
// the mmap'ed |memory| is listed with the given module name
@@ -355,8 +384,6 @@ TEST(MinidumpWriterTest, DeletedBinary) {
ASSERT_EQ(stat(templ.c_str(), &st), 0);
ASSERT_GT(st.st_size, 0u);
-
-
Minidump minidump(templ.c_str());
ASSERT_TRUE(minidump.Read());