1 // Copyright (c) 2008, Google Inc. 2 // All rights reserved 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // 30 // DynamicImagesTests.cpp 31 // minidump_test 32 // 33 // Created by Neal Sidhwaney on 4/17/08. 34 // Copyright 2008 Google Inc. All rights reserved. 35 // 36 37 #include "client/mac/handler/testcases/DynamicImagesTests.h" 38 #include "client/mac/handler/dynamic_images.h" 39 40 DynamicImagesTests test2(TEST_INVOCATION(DynamicImagesTests, 41 ReadTaskMemoryTest)); 42 DynamicImagesTests test3(TEST_INVOCATION(DynamicImagesTests, 43 ReadLibrariesFromLocalTaskTest)); 44 45 DynamicImagesTests::DynamicImagesTests(TestInvocation *invocation) 46 : TestCase(invocation) { 47 } 48 49 DynamicImagesTests::~DynamicImagesTests() { 50 } 51 52 void DynamicImagesTests::ReadTaskMemoryTest() { 53 kern_return_t kr; 54 55 // pick test2 as a symbol we know to be valid to read 56 // anything will work, really 57 void *addr = reinterpret_cast<void*>(&test2); 58 std::vector<uint8_t> buf(getpagesize()); 59 60 fprintf(stderr, "reading 0x%p\n", addr); 61 kr = google_breakpad::ReadTaskMemory(mach_task_self(), 62 (uint64_t)addr, 63 getpagesize(), 64 buf); 65 66 CPTAssert(kr == KERN_SUCCESS); 67 68 CPTAssert(0 == memcmp(&buf[0], (const void*)addr, getpagesize())); 69 } 70 71 void DynamicImagesTests::ReadLibrariesFromLocalTaskTest() { 72 73 mach_port_t me = mach_task_self(); 74 google_breakpad::DynamicImages *d = new google_breakpad::DynamicImages(me); 75 76 fprintf(stderr,"Local task image count: %d\n", d->GetImageCount()); 77 78 CPTAssert(d->GetImageCount() > 0); 79 } 80