toolkit/crashreporter/google-breakpad/src/client/mac/handler/testcases/DynamicImagesTests.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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.
    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 //
    37 #include "client/mac/handler/testcases/DynamicImagesTests.h"
    38 #include "client/mac/handler/dynamic_images.h"
    40 DynamicImagesTests test2(TEST_INVOCATION(DynamicImagesTests,
    41                                          ReadTaskMemoryTest));
    42 DynamicImagesTests test3(TEST_INVOCATION(DynamicImagesTests,
    43                                          ReadLibrariesFromLocalTaskTest));
    45 DynamicImagesTests::DynamicImagesTests(TestInvocation *invocation)
    46     : TestCase(invocation) {
    47 }
    49 DynamicImagesTests::~DynamicImagesTests() {
    50 }
    52 void DynamicImagesTests::ReadTaskMemoryTest() {
    53   kern_return_t kr;
    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());
    60   fprintf(stderr, "reading 0x%p\n", addr);
    61   kr = google_breakpad::ReadTaskMemory(mach_task_self(),
    62                                        (uint64_t)addr,
    63                                        getpagesize(),
    64                                        buf);
    66   CPTAssert(kr == KERN_SUCCESS);
    68   CPTAssert(0 == memcmp(&buf[0], (const void*)addr, getpagesize()));
    69 }
    71 void DynamicImagesTests::ReadLibrariesFromLocalTaskTest() {
    73   mach_port_t me = mach_task_self();
    74   google_breakpad::DynamicImages *d = new google_breakpad::DynamicImages(me);
    76   fprintf(stderr,"Local task image count: %d\n", d->GetImageCount());
    78   CPTAssert(d->GetImageCount() > 0);
    79 }

mercurial