1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/client/mac/handler/testcases/DynamicImagesTests.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +// Copyright (c) 2008, Google Inc. 1.5 +// All rights reserved 1.6 +// Redistribution and use in source and binary forms, with or without 1.7 +// modification, are permitted provided that the following conditions are 1.8 +// met: 1.9 +// 1.10 +// * Redistributions of source code must retain the above copyright 1.11 +// notice, this list of conditions and the following disclaimer. 1.12 +// * Redistributions in binary form must reproduce the above 1.13 +// copyright notice, this list of conditions and the following disclaimer 1.14 +// in the documentation and/or other materials provided with the 1.15 +// distribution. 1.16 +// * Neither the name of Google Inc. nor the names of its 1.17 +// contributors may be used to endorse or promote products derived from 1.18 +// this software without specific prior written permission. 1.19 +// 1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 + 1.32 +// 1.33 +// DynamicImagesTests.cpp 1.34 +// minidump_test 1.35 +// 1.36 +// Created by Neal Sidhwaney on 4/17/08. 1.37 +// Copyright 2008 Google Inc. All rights reserved. 1.38 +// 1.39 + 1.40 +#include "client/mac/handler/testcases/DynamicImagesTests.h" 1.41 +#include "client/mac/handler/dynamic_images.h" 1.42 + 1.43 +DynamicImagesTests test2(TEST_INVOCATION(DynamicImagesTests, 1.44 + ReadTaskMemoryTest)); 1.45 +DynamicImagesTests test3(TEST_INVOCATION(DynamicImagesTests, 1.46 + ReadLibrariesFromLocalTaskTest)); 1.47 + 1.48 +DynamicImagesTests::DynamicImagesTests(TestInvocation *invocation) 1.49 + : TestCase(invocation) { 1.50 +} 1.51 + 1.52 +DynamicImagesTests::~DynamicImagesTests() { 1.53 +} 1.54 + 1.55 +void DynamicImagesTests::ReadTaskMemoryTest() { 1.56 + kern_return_t kr; 1.57 + 1.58 + // pick test2 as a symbol we know to be valid to read 1.59 + // anything will work, really 1.60 + void *addr = reinterpret_cast<void*>(&test2); 1.61 + std::vector<uint8_t> buf(getpagesize()); 1.62 + 1.63 + fprintf(stderr, "reading 0x%p\n", addr); 1.64 + kr = google_breakpad::ReadTaskMemory(mach_task_self(), 1.65 + (uint64_t)addr, 1.66 + getpagesize(), 1.67 + buf); 1.68 + 1.69 + CPTAssert(kr == KERN_SUCCESS); 1.70 + 1.71 + CPTAssert(0 == memcmp(&buf[0], (const void*)addr, getpagesize())); 1.72 +} 1.73 + 1.74 +void DynamicImagesTests::ReadLibrariesFromLocalTaskTest() { 1.75 + 1.76 + mach_port_t me = mach_task_self(); 1.77 + google_breakpad::DynamicImages *d = new google_breakpad::DynamicImages(me); 1.78 + 1.79 + fprintf(stderr,"Local task image count: %d\n", d->GetImageCount()); 1.80 + 1.81 + CPTAssert(d->GetImageCount() > 0); 1.82 +}