2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-09-04 11:45:40 -04:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2014-10-17 13:41:45 -04:00
|
|
|
|
#include "snapshot/mac/mach_o_image_reader.h"
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
mac: Switch from <AvailabilityMacros.h> to <Availability.h>
The macOS 11.0 SDK, as of Xcode 12b6 12A8189n, has not updated
<AvailabilityMacros.h> with a MAC_OS_X_VERSION_11_0 or
MAC_OS_X_VERSION_10_16 constant. However, the <Availability.h> interface
has been updated to provide both __MAC_11_0 and __MAC_10_16.
<AvailabilityMacros.h>’s MAC_OS_X_VERSION_MAX_ALLOWED, which is supposed
to identify the SDK version, is broken in the 11.0 SDK in that whenever
the deployment target is set to 10.15 or earlier, the SDK will be
mis-identified through this interface as 10.15. When using the
<Availability.h> equivalent, __MAC_OS_X_VERSION_MAX_ALLOWED, the 11.0
SDK is identified as 10.16 (arguably it should be internally versioned
as 11.0, but at least this interface allows it to be detected
unambiguously.) It’s clear that the <AvailabilityMacros.h> interface
provides no meaningful support for the macOS 11.0 SDK at all, but
<Availability.h> does.
<Availability.h> was introduced in the Mac OS X 10.5 SDK, so there is no
relevant SDK version compatibility problem with this interface.
Key differences between these interfaces for the purposes used by
Crashpad:
- <AvailabilityMacros.h> → <Availability.h>
- MAC_OS_X_VERSION_MIN_REQUIRED (DT) → __MAC_OS_X_VERSION_MIN_REQUIRED
- MAC_OS_X_VERSION_MAX_ALLOWED (SDK) → __MAC_OS_X_VERSION_MAX_ALLOWED
- MAC_OS_X_VERSION_x_y → __MAC_x_y
- <Availability.h> __MAC_OS_X_VERSION_* SDK/DT macros are only
available when targeting macOS, while <AvailabilityMacros.h>
MAC_OS_X_VERSION_* SDK/DT macros are available on all Apple platforms,
which may be a source of confusion. (<Availability.h> __MAC_* macros
do remain available on all Apple platforms.)
This change was made mostly mechanically by:
sed -i '' -Ee 's/<AvailabilityMacros.h>/<Availability.h>/g' \
$(git grep -E -l '<AvailabilityMacros.h>' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED))/__\1/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED)' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(10_[0-9]+))/__MAC_\2/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(10_[0-9]+)' |
grep -v AvailabilityMacros.h)
Bug: crashpad:347
Change-Id: Ibdcd7a6215a82f7060b7b67d98691f88454085fc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2382421
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-08-28 20:00:15 -04:00
|
|
|
|
#include <Availability.h>
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include <dlfcn.h>
|
2014-09-05 16:53:18 -04:00
|
|
|
|
#include <mach-o/dyld.h>
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include <mach-o/dyld_images.h>
|
|
|
|
|
#include <mach-o/getsect.h>
|
2014-09-05 16:53:18 -04:00
|
|
|
|
#include <mach-o/ldsyms.h>
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include <mach-o/loader.h>
|
2014-09-05 16:53:18 -04:00
|
|
|
|
#include <mach-o/nlist.h>
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
|
#include "build/build_config.h"
|
2015-03-11 17:07:11 -04:00
|
|
|
|
#include "client/crashpad_info.h"
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include "gtest/gtest.h"
|
2014-10-17 13:41:45 -04:00
|
|
|
|
#include "snapshot/mac/mach_o_image_segment_reader.h"
|
2018-02-22 12:12:26 -08:00
|
|
|
|
#include "snapshot/mac/process_reader_mac.h"
|
2014-10-17 13:41:45 -04:00
|
|
|
|
#include "snapshot/mac/process_types.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/mac/dyld.h"
|
2017-04-28 10:08:35 -04:00
|
|
|
|
#include "util/misc/from_pointer_cast.h"
|
2015-09-14 11:09:46 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#include "util/misc/uuid.h"
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// This file is responsible for testing MachOImageReader,
|
|
|
|
|
// MachOImageSegmentReader, and MachOImageSymbolTableReader.
|
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
2014-09-04 11:45:40 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// Native types and constants, in cases where the 32-bit and 64-bit versions
|
|
|
|
|
// are different.
|
|
|
|
|
#if defined(ARCH_CPU_64_BITS)
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using MachHeader = mach_header_64;
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr uint32_t kMachMagic = MH_MAGIC_64;
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using SegmentCommand = segment_command_64;
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr uint32_t kSegmentCommand = LC_SEGMENT_64;
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using Section = section_64;
|
|
|
|
|
using Nlist = nlist_64;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#else
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using MachHeader = mach_header;
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr uint32_t kMachMagic = MH_MAGIC;
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using SegmentCommand = segment_command;
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr uint32_t kSegmentCommand = LC_SEGMENT;
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using Section = section;
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
|
|
|
|
// This needs to be called “struct nlist” because “nlist” without the struct
|
|
|
|
|
// refers to the nlist() function.
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using Nlist = struct nlist;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_X86_64)
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr int kCPUType = CPU_TYPE_X86_64;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#elif defined(ARCH_CPU_X86)
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr int kCPUType = CPU_TYPE_X86;
|
2020-07-07 23:43:46 -04:00
|
|
|
|
#elif defined(ARCH_CPU_ARM64)
|
|
|
|
|
constexpr int kCPUType = CPU_TYPE_ARM64;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Verifies that |expect_section| and |actual_section| agree.
|
|
|
|
|
void ExpectSection(const Section* expect_section,
|
|
|
|
|
const process_types::section* actual_section) {
|
|
|
|
|
ASSERT_TRUE(expect_section);
|
|
|
|
|
ASSERT_TRUE(actual_section);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
MachOImageSegmentReader::SectionNameString(actual_section->sectname),
|
|
|
|
|
MachOImageSegmentReader::SectionNameString(expect_section->sectname));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
EXPECT_EQ(
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
MachOImageSegmentReader::SegmentNameString(actual_section->segname),
|
|
|
|
|
MachOImageSegmentReader::SegmentNameString(expect_section->segname));
|
|
|
|
|
EXPECT_EQ(actual_section->addr, expect_section->addr);
|
|
|
|
|
EXPECT_EQ(actual_section->size, expect_section->size);
|
|
|
|
|
EXPECT_EQ(actual_section->offset, expect_section->offset);
|
|
|
|
|
EXPECT_EQ(actual_section->align, expect_section->align);
|
|
|
|
|
EXPECT_EQ(actual_section->reloff, expect_section->reloff);
|
|
|
|
|
EXPECT_EQ(actual_section->nreloc, expect_section->nreloc);
|
|
|
|
|
EXPECT_EQ(actual_section->flags, expect_section->flags);
|
|
|
|
|
EXPECT_EQ(actual_section->reserved1, expect_section->reserved1);
|
|
|
|
|
EXPECT_EQ(actual_section->reserved2, expect_section->reserved2);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verifies that |expect_segment| is a valid Mach-O segment load command for the
|
|
|
|
|
// current system by checking its |cmd| field. Then, verifies that the
|
|
|
|
|
// information in |actual_segment| matches that in |expect_segment|. The
|
|
|
|
|
// |segname|, |vmaddr|, |vmsize|, and |fileoff| fields are examined. Each
|
|
|
|
|
// section within the segment is also examined by calling ExpectSection().
|
|
|
|
|
// Access to each section via both MachOImageSegmentReader::GetSectionByName()
|
|
|
|
|
// and MachOImageReader::GetSectionByName() is verified, expecting that each
|
|
|
|
|
// call produces the same section. Segment and section data addresses are
|
|
|
|
|
// verified against data obtained by calling getsegmentdata() and
|
|
|
|
|
// getsectiondata(). The segment is checked to make sure that it behaves
|
|
|
|
|
// correctly when attempting to look up a nonexistent section by name.
|
|
|
|
|
// |section_index| is used to track the last-used section index in an image on
|
|
|
|
|
// entry, and is reset to the last-used section index on return after the
|
|
|
|
|
// sections are processed. This is used to test that
|
|
|
|
|
// MachOImageReader::GetSectionAtIndex() returns the correct result.
|
|
|
|
|
void ExpectSegmentCommand(const SegmentCommand* expect_segment,
|
|
|
|
|
const MachHeader* expect_image,
|
|
|
|
|
const MachOImageSegmentReader* actual_segment,
|
|
|
|
|
const MachOImageReader* actual_image,
|
|
|
|
|
size_t* section_index) {
|
|
|
|
|
ASSERT_TRUE(expect_segment);
|
|
|
|
|
ASSERT_TRUE(actual_segment);
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(expect_segment->cmd, kSegmentCommand);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
std::string segment_name = actual_segment->Name();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
segment_name,
|
|
|
|
|
MachOImageSegmentReader::SegmentNameString(expect_segment->segname));
|
|
|
|
|
EXPECT_EQ(actual_segment->vmaddr(), expect_segment->vmaddr);
|
|
|
|
|
EXPECT_EQ(actual_segment->vmsize(), expect_segment->vmsize);
|
|
|
|
|
EXPECT_EQ(actual_segment->fileoff(), expect_segment->fileoff);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
if (actual_segment->SegmentSlides()) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_segment->vmaddr() + actual_image->Slide(),
|
|
|
|
|
actual_segment->Address());
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
unsigned long expect_segment_size;
|
|
|
|
|
const uint8_t* expect_segment_data = getsegmentdata(
|
|
|
|
|
expect_image, segment_name.c_str(), &expect_segment_size);
|
|
|
|
|
mach_vm_address_t expect_segment_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(expect_segment_data);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_segment->Address(), expect_segment_address);
|
|
|
|
|
EXPECT_EQ(actual_segment->vmsize(), expect_segment_size);
|
|
|
|
|
EXPECT_EQ(actual_segment->Size(), actual_segment->vmsize());
|
2014-09-04 11:45:40 -04:00
|
|
|
|
} else {
|
|
|
|
|
// getsegmentdata() doesn’t return appropriate data for the __PAGEZERO
|
|
|
|
|
// segment because getsegmentdata() always adjusts for slide, but the
|
|
|
|
|
// __PAGEZERO segment never slides, it just grows. Skip the getsegmentdata()
|
|
|
|
|
// check for that segment according to the same rules that the kernel uses
|
|
|
|
|
// to identify __PAGEZERO. See 10.9.4 xnu-2422.110.17/bsd/kern/mach_loader.c
|
|
|
|
|
// load_segment().
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_segment->vmaddr(), actual_segment->Address());
|
|
|
|
|
EXPECT_EQ(actual_segment->Size(),
|
|
|
|
|
actual_segment->vmsize() + actual_image->Slide());
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(actual_segment->nsects(), expect_segment->nsects);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// Make sure that the expected load command is big enough for the number of
|
|
|
|
|
// sections that it claims to have, and set up a pointer to its first section
|
|
|
|
|
// structure.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(expect_segment->cmdsize,
|
|
|
|
|
sizeof(*expect_segment) + expect_segment->nsects * sizeof(Section));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
const Section* expect_sections =
|
|
|
|
|
reinterpret_cast<const Section*>(&expect_segment[1]);
|
|
|
|
|
|
|
|
|
|
for (size_t index = 0; index < actual_segment->nsects(); ++index) {
|
|
|
|
|
const Section* expect_section = &expect_sections[index];
|
|
|
|
|
const process_types::section* actual_section =
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_segment->GetSectionAtIndex(index, nullptr);
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
|
|
|
|
ExpectSection(&expect_sections[index], actual_section));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// Make sure that the section is accessible by GetSectionByName as well.
|
|
|
|
|
std::string section_name =
|
|
|
|
|
MachOImageSegmentReader::SectionNameString(expect_section->sectname);
|
|
|
|
|
const process_types::section* actual_section_by_name =
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_segment->GetSectionByName(section_name, nullptr);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section_by_name, actual_section);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// Make sure that the section is accessible by the parent MachOImageReader’s
|
|
|
|
|
// GetSectionByName.
|
|
|
|
|
mach_vm_address_t actual_section_address;
|
|
|
|
|
const process_types::section* actual_section_from_image_by_name =
|
|
|
|
|
actual_image->GetSectionByName(
|
|
|
|
|
segment_name, section_name, &actual_section_address);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section_from_image_by_name, actual_section);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
if (actual_segment->SegmentSlides()) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section->addr + actual_image->Slide(),
|
|
|
|
|
actual_section_address);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
unsigned long expect_section_size;
|
|
|
|
|
const uint8_t* expect_section_data = getsectiondata(expect_image,
|
|
|
|
|
segment_name.c_str(),
|
|
|
|
|
section_name.c_str(),
|
|
|
|
|
&expect_section_size);
|
|
|
|
|
mach_vm_address_t expect_section_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(expect_section_data);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section_address, expect_section_address);
|
|
|
|
|
EXPECT_EQ(actual_section->size, expect_section_size);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
} else {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section->addr, actual_section_address);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test the parent MachOImageReader’s GetSectionAtIndex as well.
|
2014-09-05 16:53:18 -04:00
|
|
|
|
const MachOImageSegmentReader* containing_segment;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
mach_vm_address_t actual_section_address_at_index;
|
|
|
|
|
const process_types::section* actual_section_from_image_at_index =
|
|
|
|
|
actual_image->GetSectionAtIndex(++(*section_index),
|
2014-09-05 16:53:18 -04:00
|
|
|
|
&containing_segment,
|
2014-09-04 11:45:40 -04:00
|
|
|
|
&actual_section_address_at_index);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_section_from_image_at_index, actual_section);
|
|
|
|
|
EXPECT_EQ(containing_segment, actual_segment);
|
|
|
|
|
EXPECT_EQ(actual_section_address_at_index, actual_section_address);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_segment->GetSectionByName("NoSuchSection", nullptr),
|
|
|
|
|
nullptr);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Walks through the load commands of |expect_image|, finding all of the
|
|
|
|
|
// expected segment commands. For each expected segment command, calls
|
|
|
|
|
// actual_image->GetSegmentByName() to obtain an actual segment command, and
|
|
|
|
|
// calls ExpectSegmentCommand() to compare the expected and actual segments. A
|
|
|
|
|
// series of by-name lookups is also performed on the segment to ensure that it
|
|
|
|
|
// behaves correctly when attempting to look up segment and section names that
|
|
|
|
|
// are not present. |test_section_indices| should be true to test
|
|
|
|
|
// MachOImageReader::GetSectionAtIndex() using out-of-range section indices.
|
|
|
|
|
// This should be tested for at least one module, but it’s very noisy in terms
|
|
|
|
|
// of logging output, so this knob is provided to suppress this portion of the
|
|
|
|
|
// test when looping over all modules.
|
|
|
|
|
void ExpectSegmentCommands(const MachHeader* expect_image,
|
|
|
|
|
const MachOImageReader* actual_image,
|
|
|
|
|
bool test_section_index_bounds) {
|
|
|
|
|
ASSERT_TRUE(expect_image);
|
|
|
|
|
ASSERT_TRUE(actual_image);
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// &expect_image[1] points right past the end of the mach_header[_64], to the
|
|
|
|
|
// start of the load commands.
|
2014-09-04 11:45:40 -04:00
|
|
|
|
const char* commands_base = reinterpret_cast<const char*>(&expect_image[1]);
|
|
|
|
|
uint32_t position = 0;
|
|
|
|
|
size_t section_index = 0;
|
|
|
|
|
for (uint32_t index = 0; index < expect_image->ncmds; ++index) {
|
|
|
|
|
ASSERT_LT(position, expect_image->sizeofcmds);
|
|
|
|
|
const load_command* command =
|
|
|
|
|
reinterpret_cast<const load_command*>(&commands_base[position]);
|
|
|
|
|
ASSERT_LE(position + command->cmdsize, expect_image->sizeofcmds);
|
|
|
|
|
if (command->cmd == kSegmentCommand) {
|
2014-09-05 16:53:18 -04:00
|
|
|
|
ASSERT_GE(command->cmdsize, sizeof(SegmentCommand));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
const SegmentCommand* expect_segment =
|
|
|
|
|
reinterpret_cast<const SegmentCommand*>(command);
|
|
|
|
|
std::string segment_name =
|
|
|
|
|
MachOImageSegmentReader::SegmentNameString(expect_segment->segname);
|
|
|
|
|
const MachOImageSegmentReader* actual_segment =
|
2014-09-05 16:53:18 -04:00
|
|
|
|
actual_image->GetSegmentByName(segment_name);
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSegmentCommand(expect_segment,
|
|
|
|
|
expect_image,
|
|
|
|
|
actual_segment,
|
|
|
|
|
actual_image,
|
|
|
|
|
§ion_index));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
position += command->cmdsize;
|
|
|
|
|
}
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(position, expect_image->sizeofcmds);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
if (test_section_index_bounds) {
|
|
|
|
|
// GetSectionAtIndex uses a 1-based index. Make sure that the range is
|
|
|
|
|
// correct.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_image->GetSectionAtIndex(0, nullptr, nullptr), nullptr);
|
2014-10-14 11:10:45 -04:00
|
|
|
|
EXPECT_EQ(
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
actual_image->GetSectionAtIndex(section_index + 1, nullptr, nullptr),
|
|
|
|
|
nullptr);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure that by-name lookups for names that don’t exist work properly:
|
2014-10-14 11:10:45 -04:00
|
|
|
|
// they should return nullptr.
|
2014-09-05 16:53:18 -04:00
|
|
|
|
EXPECT_FALSE(actual_image->GetSegmentByName("NoSuchSegment"));
|
2014-10-14 11:10:45 -04:00
|
|
|
|
EXPECT_FALSE(actual_image->GetSectionByName(
|
|
|
|
|
"NoSuchSegment", "NoSuchSection", nullptr));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// Make sure that there’s a __TEXT segment so that this can do a valid test of
|
|
|
|
|
// a section that doesn’t exist within a segment that does.
|
2014-09-05 16:53:18 -04:00
|
|
|
|
EXPECT_TRUE(actual_image->GetSegmentByName(SEG_TEXT));
|
2014-10-14 11:10:45 -04:00
|
|
|
|
EXPECT_FALSE(
|
|
|
|
|
actual_image->GetSectionByName(SEG_TEXT, "NoSuchSection", nullptr));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// Similarly, make sure that a section name that exists in one segment isn’t
|
|
|
|
|
// accidentally found during a lookup for that section in a different segment.
|
2014-09-22 13:10:14 -04:00
|
|
|
|
//
|
|
|
|
|
// If the image has no sections (unexpected), then any section lookup should
|
|
|
|
|
// fail, and these initial values of test_segment and test_section are fine
|
|
|
|
|
// for the EXPECT_FALSE checks on GetSectionByName() below.
|
|
|
|
|
std::string test_segment = SEG_DATA;
|
|
|
|
|
std::string test_section = SECT_TEXT;
|
|
|
|
|
|
|
|
|
|
const process_types::section* section =
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_image->GetSectionAtIndex(1, nullptr, nullptr);
|
2014-09-22 13:10:14 -04:00
|
|
|
|
if (section) {
|
|
|
|
|
// Use the name of the first section in the image as the section that
|
|
|
|
|
// shouldn’t appear in a different segment. If the first section is in the
|
|
|
|
|
// __TEXT segment (as it is normally), then a section by the same name
|
|
|
|
|
// wouldn’t be expected in the __DATA segment. But if the first section is
|
|
|
|
|
// in any other segment, then it wouldn’t be expected in the __TEXT segment.
|
|
|
|
|
if (MachOImageSegmentReader::SegmentNameString(section->segname) ==
|
|
|
|
|
SEG_TEXT) {
|
|
|
|
|
test_segment = SEG_DATA;
|
|
|
|
|
} else {
|
|
|
|
|
test_segment = SEG_TEXT;
|
|
|
|
|
}
|
|
|
|
|
test_section =
|
|
|
|
|
MachOImageSegmentReader::SectionNameString(section->sectname);
|
|
|
|
|
|
|
|
|
|
// It should be possible to look up the first section by name.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_image->GetSectionByName(
|
|
|
|
|
section->segname, section->sectname, nullptr),
|
|
|
|
|
section);
|
2014-09-22 13:10:14 -04:00
|
|
|
|
}
|
2014-09-04 11:45:40 -04:00
|
|
|
|
EXPECT_FALSE(
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_image->GetSectionByName("NoSuchSegment", test_section, nullptr));
|
2014-09-22 13:10:14 -04:00
|
|
|
|
EXPECT_FALSE(
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_image->GetSectionByName(test_segment, test_section, nullptr));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
// The __LINKEDIT segment normally does exist but doesn’t have any sections.
|
|
|
|
|
EXPECT_FALSE(
|
2014-10-14 11:10:45 -04:00
|
|
|
|
actual_image->GetSectionByName(SEG_LINKEDIT, "NoSuchSection", nullptr));
|
|
|
|
|
EXPECT_FALSE(
|
|
|
|
|
actual_image->GetSectionByName(SEG_LINKEDIT, SECT_TEXT, nullptr));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// In some cases, the expected slide value for an image is unknown, because no
|
|
|
|
|
// reasonable API to return it is provided. When this happens, use kSlideUnknown
|
|
|
|
|
// to avoid checking the actual slide value against anything.
|
2017-07-25 14:31:27 -04:00
|
|
|
|
constexpr mach_vm_size_t kSlideUnknown =
|
|
|
|
|
std::numeric_limits<mach_vm_size_t>::max();
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
2014-09-04 11:45:40 -04:00
|
|
|
|
// Verifies that |expect_image| is a vaild Mach-O header for the current system
|
|
|
|
|
// by checking its |magic| and |cputype| fields. Then, verifies that the
|
|
|
|
|
// information in |actual_image| matches that in |expect_image|. The |filetype|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// field is examined, actual_image->Address() is compared to
|
|
|
|
|
// |expect_image_address|, and actual_image->Slide() is compared to
|
|
|
|
|
// |expect_image_slide|, unless |expect_image_slide| is kSlideUnknown. Various
|
|
|
|
|
// other attributes of |actual_image| are sanity-checked depending on the Mach-O
|
|
|
|
|
// file type. Finally, ExpectSegmentCommands() is called to verify all that all
|
|
|
|
|
// of the segments match; |test_section_index_bounds| is used as an argument to
|
|
|
|
|
// that function.
|
2014-09-04 11:45:40 -04:00
|
|
|
|
void ExpectMachImage(const MachHeader* expect_image,
|
|
|
|
|
mach_vm_address_t expect_image_address,
|
2014-09-05 16:53:18 -04:00
|
|
|
|
mach_vm_size_t expect_image_slide,
|
2014-09-04 11:45:40 -04:00
|
|
|
|
const MachOImageReader* actual_image,
|
|
|
|
|
bool test_section_index_bounds) {
|
|
|
|
|
ASSERT_TRUE(expect_image);
|
|
|
|
|
ASSERT_TRUE(actual_image);
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(expect_image->magic, kMachMagic);
|
|
|
|
|
EXPECT_EQ(expect_image->cputype, kCPUType);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_image->FileType(), expect_image->filetype);
|
|
|
|
|
EXPECT_EQ(actual_image->Address(), expect_image_address);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
if (expect_image_slide != kSlideUnknown) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_image->Slide(), expect_image_slide);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
}
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
const MachOImageSegmentReader* actual_text_segment =
|
2014-09-05 16:53:18 -04:00
|
|
|
|
actual_image->GetSegmentByName(SEG_TEXT);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
ASSERT_TRUE(actual_text_segment);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_text_segment->Address(), expect_image_address);
|
|
|
|
|
EXPECT_EQ(actual_text_segment->Size(), actual_image->Size());
|
|
|
|
|
EXPECT_EQ(actual_image->Slide(),
|
|
|
|
|
expect_image_address - actual_text_segment->vmaddr());
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
uint32_t file_type = actual_image->FileType();
|
|
|
|
|
EXPECT_TRUE(file_type == MH_EXECUTE || file_type == MH_DYLIB ||
|
|
|
|
|
file_type == MH_DYLINKER || file_type == MH_BUNDLE);
|
|
|
|
|
|
|
|
|
|
if (file_type == MH_EXECUTE || file_type == MH_DYLINKER) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_image->DylinkerName(), "/usr/lib/dyld");
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For these, just don’t crash or anything.
|
|
|
|
|
if (file_type == MH_DYLIB) {
|
|
|
|
|
actual_image->DylibVersion();
|
|
|
|
|
}
|
|
|
|
|
actual_image->SourceVersion();
|
|
|
|
|
UUID uuid;
|
|
|
|
|
actual_image->UUID(&uuid);
|
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSegmentCommands(
|
|
|
|
|
expect_image, actual_image, test_section_index_bounds));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verifies the symbol whose Nlist structure is |entry| and whose name is |name|
|
|
|
|
|
// matches the value of a symbol by the same name looked up in |actual_image|.
|
|
|
|
|
// MachOImageReader::LookUpExternalDefinedSymbol() is used for this purpose.
|
|
|
|
|
// Only external defined symbols are considered, other types of symbols are
|
|
|
|
|
// excluded because LookUpExternalDefinedSymbol() only deals with external
|
|
|
|
|
// defined symbols.
|
|
|
|
|
void ExpectSymbol(const Nlist* entry,
|
|
|
|
|
const char* name,
|
|
|
|
|
const MachOImageReader* actual_image) {
|
|
|
|
|
SCOPED_TRACE(name);
|
|
|
|
|
|
|
|
|
|
uint32_t entry_type = entry->n_type & N_TYPE;
|
|
|
|
|
if ((entry->n_type & N_STAB) == 0 && (entry->n_type & N_PEXT) == 0 &&
|
2015-02-05 13:39:20 -05:00
|
|
|
|
(entry_type == N_ABS || entry_type == N_SECT) &&
|
2014-09-05 16:53:18 -04:00
|
|
|
|
(entry->n_type & N_EXT) == 1) {
|
|
|
|
|
mach_vm_address_t actual_address;
|
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
actual_image->LookUpExternalDefinedSymbol(name, &actual_address));
|
|
|
|
|
|
|
|
|
|
// Since the nlist interface was used to read the symbol, use it to compute
|
|
|
|
|
// the symbol address too. This isn’t perfect, and it should be possible in
|
|
|
|
|
// theory to use dlsym() to get the expected address of a symbol. In
|
|
|
|
|
// practice, dlsym() is difficult to use when only a MachHeader* is
|
|
|
|
|
// available as in this function, as opposed to a void* opaque handle. It is
|
|
|
|
|
// possible to get a void* handle by using dladdr() to find the file name
|
|
|
|
|
// corresponding to the MachHeader*, and using dlopen() again on that name,
|
|
|
|
|
// assuming it hasn’t changed on disk since being loaded. However, even with
|
|
|
|
|
// that being done, dlsym() can only deal with symbols whose names begin
|
|
|
|
|
// with an underscore (and requires that the leading underscore be trimmed).
|
|
|
|
|
// dlsym() will also return different addresses for symbols that are
|
|
|
|
|
// resolved via symbol resolver.
|
|
|
|
|
mach_vm_address_t expect_address = entry->n_value;
|
|
|
|
|
if (entry_type == N_SECT) {
|
|
|
|
|
EXPECT_GE(entry->n_sect, 1u);
|
|
|
|
|
expect_address += actual_image->Slide();
|
|
|
|
|
} else {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(entry->n_sect, NO_SECT);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_address, expect_address);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// You’d think that it might be a good idea to verify that if the conditions
|
|
|
|
|
// above weren’t met, that the symbol didn’t show up in actual_image’s symbol
|
|
|
|
|
// table at all. Unfortunately, it’s possible for the same name to show up as
|
|
|
|
|
// both an external defined symbol and as something else, so it’s not possible
|
|
|
|
|
// to verify this reliably.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Locates the symbol table in |expect_image| and verifies that all of the
|
|
|
|
|
// external defined symbols found there are also present and have the same
|
|
|
|
|
// values in |actual_image|. ExpectSymbol() is used to verify the actual symbol.
|
|
|
|
|
void ExpectSymbolTable(const MachHeader* expect_image,
|
|
|
|
|
const MachOImageReader* actual_image) {
|
|
|
|
|
// This intentionally consults only LC_SYMTAB and not LC_DYSYMTAB so that it
|
|
|
|
|
// can look at the larger set of all symbols. The actual implementation being
|
|
|
|
|
// tested is free to consult LC_DYSYMTAB, but that’s considered an
|
|
|
|
|
// optimization. It’s not necessary for the test, and it’s better for the test
|
|
|
|
|
// to expose bugs in that optimization rather than duplicate them.
|
|
|
|
|
const char* commands_base = reinterpret_cast<const char*>(&expect_image[1]);
|
|
|
|
|
uint32_t position = 0;
|
2014-10-14 11:10:45 -04:00
|
|
|
|
const symtab_command* symtab = nullptr;
|
|
|
|
|
const SegmentCommand* linkedit = nullptr;
|
2014-09-05 16:53:18 -04:00
|
|
|
|
for (uint32_t index = 0; index < expect_image->ncmds; ++index) {
|
|
|
|
|
ASSERT_LT(position, expect_image->sizeofcmds);
|
|
|
|
|
const load_command* command =
|
|
|
|
|
reinterpret_cast<const load_command*>(&commands_base[position]);
|
|
|
|
|
ASSERT_LE(position + command->cmdsize, expect_image->sizeofcmds);
|
|
|
|
|
if (command->cmd == LC_SYMTAB) {
|
|
|
|
|
ASSERT_FALSE(symtab);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(command->cmdsize, sizeof(symtab_command));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
symtab = reinterpret_cast<const symtab_command*>(command);
|
|
|
|
|
} else if (command->cmd == kSegmentCommand) {
|
|
|
|
|
ASSERT_GE(command->cmdsize, sizeof(SegmentCommand));
|
|
|
|
|
const SegmentCommand* segment =
|
|
|
|
|
reinterpret_cast<const SegmentCommand*>(command);
|
|
|
|
|
std::string segment_name =
|
|
|
|
|
MachOImageSegmentReader::SegmentNameString(segment->segname);
|
|
|
|
|
if (segment_name == SEG_LINKEDIT) {
|
|
|
|
|
ASSERT_FALSE(linkedit);
|
|
|
|
|
linkedit = segment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
position += command->cmdsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (symtab) {
|
|
|
|
|
ASSERT_TRUE(linkedit);
|
|
|
|
|
|
|
|
|
|
const char* linkedit_base =
|
|
|
|
|
reinterpret_cast<const char*>(linkedit->vmaddr + actual_image->Slide());
|
|
|
|
|
const Nlist* nlist = reinterpret_cast<const Nlist*>(
|
|
|
|
|
linkedit_base + symtab->symoff - linkedit->fileoff);
|
|
|
|
|
const char* strtab = linkedit_base + symtab->stroff - linkedit->fileoff;
|
|
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < symtab->nsyms; ++index) {
|
|
|
|
|
const Nlist* entry = nlist + index;
|
|
|
|
|
const char* name = strtab + entry->n_un.n_strx;
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSymbol(entry, name, actual_image));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mach_vm_address_t ignore;
|
|
|
|
|
EXPECT_FALSE(actual_image->LookUpExternalDefinedSymbol("", &ignore));
|
|
|
|
|
EXPECT_FALSE(
|
|
|
|
|
actual_image->LookUpExternalDefinedSymbol("NoSuchSymbolName", &ignore));
|
|
|
|
|
EXPECT_FALSE(
|
|
|
|
|
actual_image->LookUpExternalDefinedSymbol("_NoSuchSymbolName", &ignore));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MachOImageReader, Self_MainExecutable) {
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
|
|
|
|
|
|
2014-09-22 13:10:14 -04:00
|
|
|
|
const MachHeader* mh_execute_header =
|
|
|
|
|
reinterpret_cast<MachHeader*>(dlsym(RTLD_MAIN_ONLY, MH_EXECUTE_SYM));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(mh_execute_header, nullptr);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
mach_vm_address_t mh_execute_header_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(mh_execute_header);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
MachOImageReader image_reader;
|
|
|
|
|
ASSERT_TRUE(image_reader.Initialize(
|
2014-09-05 16:53:18 -04:00
|
|
|
|
&process_reader, mh_execute_header_address, "executable"));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(image_reader.FileType(), implicit_cast<uint32_t>(MH_EXECUTE));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// The main executable has image index 0.
|
|
|
|
|
intptr_t image_slide = _dyld_get_image_vmaddr_slide(0);
|
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(mh_execute_header,
|
|
|
|
|
mh_execute_header_address,
|
|
|
|
|
image_slide,
|
|
|
|
|
&image_reader,
|
|
|
|
|
true));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
|
|
|
|
// This symbol, __mh_execute_header, is known to exist in all MH_EXECUTE
|
|
|
|
|
// Mach-O files.
|
|
|
|
|
mach_vm_address_t symbol_address;
|
|
|
|
|
ASSERT_TRUE(image_reader.LookUpExternalDefinedSymbol(_MH_EXECUTE_SYM,
|
|
|
|
|
&symbol_address));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(symbol_address, mh_execute_header_address);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mh_execute_header, &image_reader));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MachOImageReader, Self_DyldImages) {
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader;
|
2014-09-04 11:45:40 -04:00
|
|
|
|
ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
uint32_t count = _dyld_image_count();
|
|
|
|
|
ASSERT_GE(count, 1u);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
2015-03-11 17:07:11 -04:00
|
|
|
|
size_t modules_with_crashpad_info = 0;
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
for (uint32_t index = 0; index < count; ++index) {
|
|
|
|
|
const char* image_name = _dyld_get_image_name(index);
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf("index %u, image %s", index, image_name));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// _dyld_get_image_header() is poorly-declared: it’s declared as returning
|
2014-09-04 11:45:40 -04:00
|
|
|
|
// const mach_header* in both 32-bit and 64-bit environments, but in the
|
|
|
|
|
// 64-bit environment, it should be const mach_header_64*.
|
|
|
|
|
const MachHeader* mach_header =
|
2014-09-05 16:53:18 -04:00
|
|
|
|
reinterpret_cast<const MachHeader*>(_dyld_get_image_header(index));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
mach_vm_address_t image_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(mach_header);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
MachOImageReader image_reader;
|
2014-09-22 13:10:14 -04:00
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
image_reader.Initialize(&process_reader, image_address, image_name));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
uint32_t file_type = image_reader.FileType();
|
|
|
|
|
if (index == 0) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(file_type, implicit_cast<uint32_t>(MH_EXECUTE));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
} else {
|
|
|
|
|
EXPECT_TRUE(file_type == MH_DYLIB || file_type == MH_BUNDLE);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
intptr_t image_slide = _dyld_get_image_vmaddr_slide(index);
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
|
|
|
|
|
mach_header, image_address, image_slide, &image_reader, false));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
|
2015-03-11 17:07:11 -04:00
|
|
|
|
|
|
|
|
|
process_types::CrashpadInfo crashpad_info;
|
|
|
|
|
if (image_reader.GetCrashpadInfo(&crashpad_info)) {
|
|
|
|
|
++modules_with_crashpad_info;
|
|
|
|
|
}
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 17:07:11 -04:00
|
|
|
|
EXPECT_GE(modules_with_crashpad_info, 1u);
|
|
|
|
|
|
2014-09-04 11:45:40 -04:00
|
|
|
|
// Now that all of the modules have been verified, make sure that dyld itself
|
|
|
|
|
// can be read properly too.
|
mac: Handle _dyld_get_all_image_infos() not being available on 10.13
_dyld_get_all_image_infos() was only used in test code in Crashpad.
This addresses two related problems.
When running on 10.13 or later, _dyld_get_all_image_infos() is not
available. It appears to still be implemented in dyld, but its symbol is
now private. This was always known to be an “internal” interface. When
it’s not available, fall back to obtaining the address of the process’
dyld_all_image_infos structure by calling task_info(…, TASK_DYLD_INFO,
…). Note that this is the same thing that the code being tested does,
although the tests are not rendered entirely pointless because the code
being tested consumes dyld_all_image_infos through its own
implementation of an out-of-process reader interface, while the
dyld_all_image_infos data obtained by _dyld_get_all_image_infos() is
handled strictly in-process by ordinary memory reads. This is covered by
bug 187.
When building with the 10.13 SDK, no _dyld_get_all_image_infos symbol is
available to link against. In this case, access the symbol strictly at
runtime via dlopen() if it may be available, or when expecting to only
run on 10.13 and later, don’t even bother looking for this symbol. This
is covered by part of bug 188.
Bug: crashpad:185, crashpad:187, crashpad:188
Change-Id: Ib283e070faf5d1ec35deee420213b53ec24fb1d3
Reviewed-on: https://chromium-review.googlesource.com/534633
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-06-14 10:48:30 -04:00
|
|
|
|
const dyld_all_image_infos* dyld_image_infos = DyldGetAllImageInfos();
|
2014-09-05 16:53:18 -04:00
|
|
|
|
ASSERT_GE(dyld_image_infos->version, 1u);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(dyld_image_infos->infoArrayCount, count);
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
2014-09-04 11:45:40 -04:00
|
|
|
|
if (dyld_image_infos->version >= 2) {
|
|
|
|
|
SCOPED_TRACE("dyld");
|
|
|
|
|
|
|
|
|
|
// dyld_all_image_infos::dyldImageLoadAddress is poorly-declared too.
|
|
|
|
|
const MachHeader* mach_header = reinterpret_cast<const MachHeader*>(
|
|
|
|
|
dyld_image_infos->dyldImageLoadAddress);
|
|
|
|
|
mach_vm_address_t image_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(mach_header);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
MachOImageReader image_reader;
|
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
image_reader.Initialize(&process_reader, image_address, "dyld"));
|
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(image_reader.FileType(), implicit_cast<uint32_t>(MH_DYLINKER));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// There’s no good API to get dyld’s slide, so don’t bother checking it.
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectMachImage(
|
|
|
|
|
mach_header, image_address, kSlideUnknown, &image_reader, false));
|
2014-09-05 16:53:18 -04:00
|
|
|
|
|
2014-10-09 15:08:54 -04:00
|
|
|
|
ASSERT_NO_FATAL_FAILURE(ExpectSymbolTable(mach_header, &image_reader));
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
mac: Switch from <AvailabilityMacros.h> to <Availability.h>
The macOS 11.0 SDK, as of Xcode 12b6 12A8189n, has not updated
<AvailabilityMacros.h> with a MAC_OS_X_VERSION_11_0 or
MAC_OS_X_VERSION_10_16 constant. However, the <Availability.h> interface
has been updated to provide both __MAC_11_0 and __MAC_10_16.
<AvailabilityMacros.h>’s MAC_OS_X_VERSION_MAX_ALLOWED, which is supposed
to identify the SDK version, is broken in the 11.0 SDK in that whenever
the deployment target is set to 10.15 or earlier, the SDK will be
mis-identified through this interface as 10.15. When using the
<Availability.h> equivalent, __MAC_OS_X_VERSION_MAX_ALLOWED, the 11.0
SDK is identified as 10.16 (arguably it should be internally versioned
as 11.0, but at least this interface allows it to be detected
unambiguously.) It’s clear that the <AvailabilityMacros.h> interface
provides no meaningful support for the macOS 11.0 SDK at all, but
<Availability.h> does.
<Availability.h> was introduced in the Mac OS X 10.5 SDK, so there is no
relevant SDK version compatibility problem with this interface.
Key differences between these interfaces for the purposes used by
Crashpad:
- <AvailabilityMacros.h> → <Availability.h>
- MAC_OS_X_VERSION_MIN_REQUIRED (DT) → __MAC_OS_X_VERSION_MIN_REQUIRED
- MAC_OS_X_VERSION_MAX_ALLOWED (SDK) → __MAC_OS_X_VERSION_MAX_ALLOWED
- MAC_OS_X_VERSION_x_y → __MAC_x_y
- <Availability.h> __MAC_OS_X_VERSION_* SDK/DT macros are only
available when targeting macOS, while <AvailabilityMacros.h>
MAC_OS_X_VERSION_* SDK/DT macros are available on all Apple platforms,
which may be a source of confusion. (<Availability.h> __MAC_* macros
do remain available on all Apple platforms.)
This change was made mostly mechanically by:
sed -i '' -Ee 's/<AvailabilityMacros.h>/<Availability.h>/g' \
$(git grep -E -l '<AvailabilityMacros.h>' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED))/__\1/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED)' |
grep -v AvailabilityMacros.h)
sed -i '' -Ee 's/(MAC_OS_X_VERSION_(10_[0-9]+))/__MAC_\2/g' \
$(git grep -E -l 'MAC_OS_X_VERSION_(10_[0-9]+)' |
grep -v AvailabilityMacros.h)
Bug: crashpad:347
Change-Id: Ibdcd7a6215a82f7060b7b67d98691f88454085fc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2382421
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-08-28 20:00:15 -04:00
|
|
|
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_7
|
2014-09-04 11:45:40 -04:00
|
|
|
|
// If dyld is new enough to record UUIDs, check the UUID of any module that
|
|
|
|
|
// it says has one. Note that dyld doesn’t record UUIDs of anything that
|
|
|
|
|
// loaded out of the shared cache, but it should at least have a UUID for the
|
|
|
|
|
// main executable if it has one.
|
|
|
|
|
if (dyld_image_infos->version >= 8 && dyld_image_infos->uuidArray) {
|
|
|
|
|
for (uint32_t index = 0;
|
|
|
|
|
index < dyld_image_infos->uuidArrayCount;
|
|
|
|
|
++index) {
|
|
|
|
|
const dyld_uuid_info* dyld_image = &dyld_image_infos->uuidArray[index];
|
|
|
|
|
SCOPED_TRACE(base::StringPrintf("uuid index %u", index));
|
|
|
|
|
|
|
|
|
|
// dyld_uuid_info::imageLoadAddress is poorly-declared too.
|
|
|
|
|
const MachHeader* mach_header =
|
|
|
|
|
reinterpret_cast<const MachHeader*>(dyld_image->imageLoadAddress);
|
|
|
|
|
mach_vm_address_t image_address =
|
2017-04-28 10:08:35 -04:00
|
|
|
|
FromPointerCast<mach_vm_address_t>(mach_header);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
MachOImageReader image_reader;
|
|
|
|
|
ASSERT_TRUE(
|
|
|
|
|
image_reader.Initialize(&process_reader, image_address, "uuid"));
|
|
|
|
|
|
2014-09-05 16:53:18 -04:00
|
|
|
|
// There’s no good way to get the image’s slide here, although the image
|
|
|
|
|
// should have already been checked along with its slide above, in the
|
|
|
|
|
// loop through all images.
|
|
|
|
|
ExpectMachImage(
|
|
|
|
|
mach_header, image_address, kSlideUnknown, &image_reader, false);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
|
|
|
|
|
UUID expected_uuid;
|
|
|
|
|
expected_uuid.InitializeFromBytes(dyld_image->imageUUID);
|
|
|
|
|
UUID actual_uuid;
|
|
|
|
|
image_reader.UUID(&actual_uuid);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_uuid, expected_uuid);
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-12 12:13:27 -04:00
|
|
|
|
#endif
|
2014-09-04 11:45:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|