aboutsummaryrefslogtreecommitdiff
path: root/src/client/linux/minidump_writer/minidump_writer_unittest.cc
diff options
context:
space:
mode:
authorivan.penkov@gmail.com <ivan.penkov@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-07-02 22:55:57 +0000
committerivan.penkov@gmail.com <ivan.penkov@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-07-02 22:55:57 +0000
commit5f6e1f0fe74bc01878d80531a91c39df9dfaa62a (patch)
tree4fe7140f6051191e509807d101d224763d5d6d32 /src/client/linux/minidump_writer/minidump_writer_unittest.cc
parentChange #imports that should have been #includes to #include. (diff)
downloadbreakpad-5f6e1f0fe74bc01878d80531a91c39df9dfaa62a.tar.xz
Fixing various compiler warnings and applying minor tweaks to allow running of
the mojority of breakpad unittests in Google. http://breakpad.appspot.com/399002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@978 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.cc42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/client/linux/minidump_writer/minidump_writer_unittest.cc b/src/client/linux/minidump_writer/minidump_writer_unittest.cc
index b751f50a..4dbbbe86 100644
--- a/src/client/linux/minidump_writer/minidump_writer_unittest.cc
+++ b/src/client/linux/minidump_writer/minidump_writer_unittest.cc
@@ -40,12 +40,14 @@
#include "client/linux/handler/exception_handler.h"
#include "client/linux/minidump_writer/linux_dumper.h"
#include "client/linux/minidump_writer/minidump_writer.h"
+#include "client/linux/minidump_writer/minidump_writer_unittest_utils.h"
#include "common/linux/eintr_wrapper.h"
#include "common/linux/file_id.h"
#include "common/linux/safe_readlink.h"
#include "common/tests/auto_tempdir.h"
#include "common/using_std_string.h"
#include "google_breakpad/processor/minidump.h"
+#include "processor/scoped_ptr.h"
using namespace google_breakpad;
@@ -94,7 +96,7 @@ TEST(MinidumpWriterTest, MappingInfo) {
// These are defined here so the parent can use them to check the
// data from the minidump afterwards.
- const u_int32_t kMemorySize = sysconf(_SC_PAGESIZE);
+ const u_int32_t memory_size = sysconf(_SC_PAGESIZE);
const char* kMemoryName = "a fake module";
const u_int8_t kModuleGUID[sizeof(MDGUID)] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
@@ -117,7 +119,7 @@ TEST(MinidumpWriterTest, MappingInfo) {
// Get some memory.
char* memory =
reinterpret_cast<char*>(mmap(NULL,
- kMemorySize,
+ memory_size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
-1,
@@ -145,7 +147,7 @@ TEST(MinidumpWriterTest, MappingInfo) {
// Add information about the mapped memory.
MappingInfo info;
info.start_addr = kMemoryAddress;
- info.size = kMemorySize;
+ info.size = memory_size;
info.offset = 0;
strcpy(info.name, kMemoryName);
@@ -170,7 +172,7 @@ TEST(MinidumpWriterTest, MappingInfo) {
ASSERT_TRUE(module);
EXPECT_EQ(kMemoryAddress, module->base_address());
- EXPECT_EQ(kMemorySize, module->size());
+ EXPECT_EQ(memory_size, module->size());
EXPECT_EQ(kMemoryName, module->code_file());
EXPECT_EQ(module_identifier, module->debug_identifier());
@@ -186,7 +188,7 @@ TEST(MinidumpWriterTest, MappingInfoContained) {
// These are defined here so the parent can use them to check the
// data from the minidump afterwards.
- const u_int32_t kMemorySize = sysconf(_SC_PAGESIZE);
+ const u_int32_t memory_size = sysconf(_SC_PAGESIZE);
const char* kMemoryName = "a fake module";
const u_int8_t kModuleGUID[sizeof(MDGUID)] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
@@ -213,14 +215,14 @@ TEST(MinidumpWriterTest, MappingInfoContained) {
ASSERT_NE(-1, fd);
unlink(tempfile.c_str());
// fill with zeros
- char buffer[kMemorySize];
- memset(buffer, 0, kMemorySize);
- ASSERT_EQ(kMemorySize, write(fd, buffer, kMemorySize));
+ google_breakpad::scoped_array<char> buffer(new char[memory_size]);
+ memset(buffer.get(), 0, memory_size);
+ ASSERT_EQ(memory_size, write(fd, buffer.get(), memory_size));
lseek(fd, 0, SEEK_SET);
char* memory =
reinterpret_cast<char*>(mmap(NULL,
- kMemorySize,
+ memory_size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE,
fd,
@@ -248,8 +250,8 @@ TEST(MinidumpWriterTest, MappingInfoContained) {
// Add information about the mapped memory. Report it as being larger than
// it actually is.
MappingInfo info;
- info.start_addr = kMemoryAddress - kMemorySize;
- info.size = kMemorySize * 3;
+ info.start_addr = kMemoryAddress - memory_size;
+ info.size = memory_size * 3;
info.offset = 0;
strcpy(info.name, kMemoryName);
@@ -287,20 +289,11 @@ TEST(MinidumpWriterTest, DeletedBinary) {
char kNumberOfThreadsArgument[2];
sprintf(kNumberOfThreadsArgument, "%d", kNumberOfThreadsInHelperProgram);
- // Locate helper binary next to the current binary.
- char self_path[PATH_MAX];
- if (!SafeReadLink("/proc/self/exe", self_path)) {
- FAIL() << "readlink failed";
+ string helper_path(GetHelperBinary());
+ if (helper_path.empty()) {
+ FAIL() << "Couldn't find helper binary";
exit(1);
}
- string helper_path(self_path);
- size_t pos = helper_path.rfind('/');
- if (pos == string::npos) {
- FAIL() << "no trailing slash in path: " << helper_path;
- exit(1);
- }
- helper_path.erase(pos + 1);
- helper_path += "linux_dumper_unittest_helper";
// Copy binary to a temp file.
AutoTempDir temp_dir;
@@ -308,7 +301,7 @@ TEST(MinidumpWriterTest, DeletedBinary) {
char cmdline[2 * PATH_MAX];
sprintf(cmdline, "/bin/cp \"%s\" \"%s\"", helper_path.c_str(),
binpath.c_str());
- ASSERT_EQ(0, system(cmdline));
+ ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline;
ASSERT_EQ(0, chmod(binpath.c_str(), 0755));
int fds[2];
@@ -381,6 +374,7 @@ TEST(MinidumpWriterTest, DeletedBinary) {
kGUIDStringSize);
string module_identifier(identifier_string);
// Strip out dashes
+ size_t pos;
while ((pos = module_identifier.find('-')) != string::npos) {
module_identifier.erase(pos, 1);
}