Skip to content

Commit

Permalink
Round-trip client/processor unittests for Windows
Browse files Browse the repository at this point in the history
R=mark at http://breakpad.appspot.com/258001

git-svn-id: http://google-breakpad.googlecode.com/svn@762 4c0a9323-5329-0410-9bdc-e9ce6186880e
  • Loading branch information
ted.mielczarek committed Jan 24, 2011
1 parent 3d17949 commit 0da054a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions trunk/src/client/windows/breakpad_client.gyp
Expand Up @@ -60,6 +60,7 @@
'<(DEPTH)/common/windows/guid_string.h',
'<(DEPTH)/common/windows/http_upload.cc',
'<(DEPTH)/common/windows/http_upload.h',
'<(DEPTH)/common/windows/string_utils.cc',
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/client/windows/handler/exception_handler.cc
Expand Up @@ -560,7 +560,7 @@ void ExceptionHandler::HandleInvalidParameter(const wchar_t* expression,

// static
void ExceptionHandler::HandlePureVirtualCall() {
// This is an pure virtual funciton call, not an exception. It's safe to
// This is an pure virtual function call, not an exception. It's safe to
// play with sprintf here.
AutoExceptionHandler auto_exception_handler;
ExceptionHandler* current_handler = auto_exception_handler.get_handler();
Expand Down
20 changes: 20 additions & 0 deletions trunk/src/client/windows/unittests/client_tests.gyp
Expand Up @@ -50,7 +50,27 @@
'../crash_generation/crash_generation.gyp:crash_generation_server',
'../crash_generation/crash_generation.gyp:crash_generation_client',
'../handler/exception_handler.gyp:exception_handler',
'processor_bits',
]
},
{
'target_name': 'processor_bits',
'type': 'static_library',
'include_dirs': [
'<(DEPTH)',
],
'direct_dependent_settings': {
'include_dirs': [
'<(DEPTH)',
]
},
'sources': [
'<(DEPTH)/common/string_conversion.cc',
'<(DEPTH)/processor/basic_code_modules.cc',
'<(DEPTH)/processor/logging.cc',
'<(DEPTH)/processor/minidump.cc',
'<(DEPTH)/processor/pathname_stripper.cc',
]
}
],
}
58 changes: 55 additions & 3 deletions trunk/src/client/windows/unittests/exception_handler_test.cc
Expand Up @@ -33,12 +33,20 @@
#include <objbase.h>
#include <shellapi.h>

#include <string>

#include "../../../breakpad_googletest_includes.h"
#include "../../../../common/windows/string_utils-inl.h"
#include "../../../../google_breakpad/processor/minidump.h"
#include "../crash_generation/crash_generation_server.h"
#include "../handler/exception_handler.h"
#include "dump_analysis.h" // NOLINT

namespace {

using std::wstring;
using namespace google_breakpad;

const wchar_t kPipeName[] = L"\\\\.\\pipe\\BreakpadCrashTest\\TestCaseServer";
const char kSuccessIndicator[] = "success";
const char kFailureIndicator[] = "failure";
Expand Down Expand Up @@ -72,6 +80,13 @@ class ExceptionHandlerTest : public ::testing::Test {
const google_breakpad::ClientInfo *client_info,
const std::wstring *dump_path);

static bool DumpCallback(const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded);

static std::wstring dump_file;
static std::wstring full_dump_file;
};
Expand Down Expand Up @@ -119,15 +134,30 @@ BOOL ExceptionHandlerTest::DoesPathExist(const TCHAR *path_name) {
return TRUE;
}

// static
void ExceptionHandlerTest::ClientDumpCallback(
void *dump_context,
const google_breakpad::ClientInfo *client_info,
const std::wstring *dump_path) {
const wstring *dump_path) {
dump_file = *dump_path;
// Create the full dump file name from the dump path.
full_dump_file = dump_file.substr(0, dump_file.length() - 4) + L"-full.dmp";
}

// static
bool ExceptionHandlerTest::DumpCallback(const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded) {
dump_file = dump_path;
dump_file += L"\\";
dump_file += minidump_id;
dump_file += L".dmp";
return succeeded;
}

void ExceptionHandlerTest::DoCrashInvalidParameter() {
google_breakpad::ExceptionHandler *exc =
new google_breakpad::ExceptionHandler(
Expand Down Expand Up @@ -188,7 +218,7 @@ TEST_F(ExceptionHandlerTest, InvalidParameterMiniDumpTest) {

// Call with a bad argument
ASSERT_TRUE(DoesPathExist(temp_path_));
std::wstring dump_path(temp_path_);
wstring dump_path(temp_path_);
google_breakpad::CrashGenerationServer server(
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
&dump_path);
Expand Down Expand Up @@ -259,7 +289,7 @@ TEST_F(ExceptionHandlerTest, PureVirtualCallMiniDumpTest) {

// Call with a bad argument
ASSERT_TRUE(DoesPathExist(temp_path_));
std::wstring dump_path(temp_path_);
wstring dump_path(temp_path_);
google_breakpad::CrashGenerationServer server(
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
&dump_path);
Expand Down Expand Up @@ -322,4 +352,26 @@ TEST_F(ExceptionHandlerTest, PureVirtualCallMiniDumpTest) {
EXPECT_FALSE(mini.HasStream(TokenStream));
EXPECT_FALSE(full.HasStream(TokenStream));
}

// Test that writing a minidump produces a valid minidump containing
// some expected structures.
TEST_F(ExceptionHandlerTest, WriteMinidumpTest) {
ExceptionHandler handler(temp_path_,
NULL,
DumpCallback,
NULL,
ExceptionHandler::HANDLER_ALL);
ASSERT_TRUE(handler.WriteMinidump());
ASSERT_FALSE(dump_file.empty());

string minidump_filename;
ASSERT_TRUE(WindowsStringUtils::safe_wcstombs(dump_file,
&minidump_filename));

// Read the minidump and verify some info.
Minidump minidump(minidump_filename);
ASSERT_TRUE(minidump.Read());
//TODO(ted): more comprehensive tests...
}

} // namespace

0 comments on commit 0da054a

Please sign in to comment.