Added code for testing Breakpad minidump creation

This commit is contained in:
Asher Baker 2016-07-01 22:43:09 +01:00 committed by Asher Baker
parent 3f79530280
commit 00f5c3d08e
3 changed files with 153 additions and 0 deletions

View File

@ -231,6 +231,7 @@ AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals)
FileList = [
['extension', 'AMBuilder'],
['test', 'AMBuilder'],
['buildbot', 'PackageScript'],
['buildbot', 'BreakpadSymbols']
]

54
test/AMBuilder Normal file
View File

@ -0,0 +1,54 @@
# vim: set ts=2 sw=2 tw=99 noet ft=python:
import os
import ambuild.osutil as osutil
from ambuild.command import SymlinkCommand
from ambuild.command import ShellCommand
from ambuild.command import DirectCommand
def BuildEverything():
if AMBuild.target['platform'] not in ['linux']:
return
compiler = SM.DefaultCompiler()
compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src'))
if AMBuild.target['platform'] in ['linux']:
compiler['POSTLINKFLAGS'].append('-lstdc++')
compiler['POSTLINKFLAGS'].append('-pthread')
name = 'test'
extension = AMBuild.AddJob(name)
binary = Cpp.ExecutableBuilder(name, AMBuild, extension, compiler)
binary.AddSourceFiles('test', [
'test.cpp',
])
if AMBuild.target['platform'] in ['linux']:
link = os.path.join(AMBuild.outputFolder, extension.workFolder, 'libbreakpad_client.a')
target = os.path.join(AMBuild.outputFolder, 'breakpad', 'src', 'client', 'linux', 'libbreakpad_client.a')
try:
os.lstat(link)
except:
extension.AddCommand(SymlinkCommand(link, target))
binary.AddObjectFiles(['libbreakpad_client.a'])
elif AMBuild.target['platform'] in ['windows']:
libs = ['exception_handler', 'common']
for lib in libs:
path = os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'handler', 'Release', 'lib', lib + '.lib')
if os.path.isfile(path):
binary.RelinkIfNewer(path)
binary['POSTLINKFLAGS'].extend([path])
path = os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'crash_generation', 'Release', 'lib', 'crash_generation_client.lib')
if os.path.isfile(path):
binary.RelinkIfNewer(path)
binary['POSTLINKFLAGS'].extend([path])
SM.ExtractDebugInfo(extension, binary)
binary.SendToJob()
BuildEverything()

98
test/test.cpp Normal file
View File

@ -0,0 +1,98 @@
/*
* =============================================================================
* Accelerator Extension
* Copyright (C) 2011 Asher Baker (asherkin). All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined _LINUX
#include "client/linux/handler/exception_handler.h"
#include "common/linux/linux_libc_support.h"
#include "third_party/lss/linux_syscall_support.h"
#include <signal.h>
#include <dirent.h>
#include <unistd.h>
#elif defined _WINDOWS
#define _STDINT // ~.~
#include "client/windows/handler/exception_handler.h"
#else
#error Bad platform.
#endif
char dumpStoragePath[512] = ".";
google_breakpad::ExceptionHandler *handler = NULL;
#if defined _LINUX
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded)
{
if (succeeded) {
sys_write(STDOUT_FILENO, "Wrote minidump to: ", 19);
} else {
sys_write(STDOUT_FILENO, "Failed to write minidump to: ", 29);
}
sys_write(STDOUT_FILENO, descriptor.path(), my_strlen(descriptor.path()));
sys_write(STDOUT_FILENO, "\n", 1);
return succeeded;
}
#elif defined _WINDOWS
static bool dumpCallback(const wchar_t* dump_path,
const wchar_t* minidump_id,
void* context,
EXCEPTION_POINTERS* exinfo,
MDRawAssertionInfo* assertion,
bool succeeded)
{
if (!succeeded) {
printf("Failed to write minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id);
return succeeded;
}
printf("Wrote minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id);
return succeeded;
}
#else
#error Bad platform.
#endif
int main(int argc, char *argv[])
{
#if defined _LINUX
google_breakpad::MinidumpDescriptor descriptor(dumpStoragePath);
handler = new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1);
#elif defined _WINDOWS
wchar_t *buf = new wchar_t[sizeof(dumpStoragePath)];
size_t num_chars = mbstowcs(buf, dumpStoragePath, sizeof(dumpStoragePath));
handler = new google_breakpad::ExceptionHandler(std::wstring(buf, num_chars), NULL, dumpCallback, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL);
delete buf;
#else
#error Bad platform.
#endif
// Test shit here.
int a = *(int *)0x0;
delete handler;
return 0;
}