Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: util/mac/checked_mach_address_range_test.cc

Issue 666483002: Create snapshot/mac and move some files from snapshot and util to there (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad/+/master
Patch Set: Move process_reader, process_types, and mach_o_image*_reader from util/mac to snapshot/mac Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/mac/checked_mach_address_range.cc ('k') | util/mac/mach_o_image_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mac/checked_mach_address_range_test.cc
diff --git a/util/mac/checked_mach_address_range_test.cc b/util/mac/checked_mach_address_range_test.cc
index b0f36c3de3b5cebb61a93172b8244101fdf74210..702715d092a0afec4aa4e7c36351cea658821785 100644
--- a/util/mac/checked_mach_address_range_test.cc
+++ b/util/mac/checked_mach_address_range_test.cc
@@ -22,63 +22,70 @@
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
-#include "util/mac/process_reader.h"
namespace crashpad {
namespace test {
namespace {
-#if defined(ARCH_CPU_64_BITS)
-const bool kValid64Invalid32 = true;
-#else
-const bool kValid64Invalid32 = false;
-#endif
+enum Validity {
+ kInvalid = false,
+ kValid,
+ kValid64Invalid32,
+};
+
+bool ExpectationForValidity32(Validity validity) {
+ return validity == kValid;
+}
+
+bool ExpectationForValidity64(Validity validity) {
+ return validity == kValid || validity == kValid64Invalid32;
+}
TEST(CheckedMachAddressRange, IsValid) {
const struct TestData {
mach_vm_address_t base;
mach_vm_size_t size;
- bool valid;
+ Validity validity;
} kTestData[] = {
- {0, 0, true},
- {0, 1, true},
- {0, 2, true},
- {0, 0x7fffffff, true},
- {0, 0x80000000, true},
- {0, 0xfffffffe, true},
- {0, 0xffffffff, true},
+ {0, 0, kValid},
+ {0, 1, kValid},
+ {0, 2, kValid},
+ {0, 0x7fffffff, kValid},
+ {0, 0x80000000, kValid},
+ {0, 0xfffffffe, kValid},
+ {0, 0xffffffff, kValid},
{0, 0xffffffffffffffff, kValid64Invalid32},
- {1, 0, true},
- {1, 1, true},
- {1, 2, true},
- {1, 0x7fffffff, true},
- {1, 0x80000000, true},
- {1, 0xfffffffe, true},
+ {1, 0, kValid},
+ {1, 1, kValid},
+ {1, 2, kValid},
+ {1, 0x7fffffff, kValid},
+ {1, 0x80000000, kValid},
+ {1, 0xfffffffe, kValid},
{1, 0xffffffff, kValid64Invalid32},
{1, 0xfffffffffffffffe, kValid64Invalid32},
- {1, 0xffffffffffffffff, false},
- {0x7fffffff, 0, true},
- {0x7fffffff, 1, true},
- {0x7fffffff, 2, true},
- {0x7fffffff, 0x7fffffff, true},
- {0x7fffffff, 0x80000000, true},
+ {1, 0xffffffffffffffff, kInvalid},
+ {0x7fffffff, 0, kValid},
+ {0x7fffffff, 1, kValid},
+ {0x7fffffff, 2, kValid},
+ {0x7fffffff, 0x7fffffff, kValid},
+ {0x7fffffff, 0x80000000, kValid},
{0x7fffffff, 0xfffffffe, kValid64Invalid32},
{0x7fffffff, 0xffffffff, kValid64Invalid32},
- {0x80000000, 0, true},
- {0x80000000, 1, true},
- {0x80000000, 2, true},
- {0x80000000, 0x7fffffff, true},
+ {0x80000000, 0, kValid},
+ {0x80000000, 1, kValid},
+ {0x80000000, 2, kValid},
+ {0x80000000, 0x7fffffff, kValid},
{0x80000000, 0x80000000, kValid64Invalid32},
{0x80000000, 0xfffffffe, kValid64Invalid32},
{0x80000000, 0xffffffff, kValid64Invalid32},
- {0xfffffffe, 0, true},
- {0xfffffffe, 1, true},
+ {0xfffffffe, 0, kValid},
+ {0xfffffffe, 1, kValid},
{0xfffffffe, 2, kValid64Invalid32},
{0xfffffffe, 0x7fffffff, kValid64Invalid32},
{0xfffffffe, 0x80000000, kValid64Invalid32},
{0xfffffffe, 0xfffffffe, kValid64Invalid32},
{0xfffffffe, 0xffffffff, kValid64Invalid32},
- {0xffffffff, 0, true},
+ {0xffffffff, 0, kValid},
{0xffffffff, 1, kValid64Invalid32},
{0xffffffff, 2, kValid64Invalid32},
{0xffffffff, 0x7fffffff, kValid64Invalid32},
@@ -90,27 +97,24 @@ TEST(CheckedMachAddressRange, IsValid) {
{0x7fffffffffffffff, 2, kValid64Invalid32},
{0x7fffffffffffffff, 0x7fffffffffffffff, kValid64Invalid32},
{0x7fffffffffffffff, 0x8000000000000000, kValid64Invalid32},
- {0x7fffffffffffffff, 0x8000000000000001, false},
- {0x7fffffffffffffff, 0xfffffffffffffffe, false},
- {0x7fffffffffffffff, 0xffffffffffffffff, false},
+ {0x7fffffffffffffff, 0x8000000000000001, kInvalid},
+ {0x7fffffffffffffff, 0xfffffffffffffffe, kInvalid},
+ {0x7fffffffffffffff, 0xffffffffffffffff, kInvalid},
{0x8000000000000000, 0, kValid64Invalid32},
{0x8000000000000000, 1, kValid64Invalid32},
{0x8000000000000000, 2, kValid64Invalid32},
{0x8000000000000000, 0x7fffffffffffffff, kValid64Invalid32},
- {0x8000000000000000, 0x8000000000000000, false},
- {0x8000000000000000, 0x8000000000000001, false},
- {0x8000000000000000, 0xfffffffffffffffe, false},
- {0x8000000000000000, 0xffffffffffffffff, false},
+ {0x8000000000000000, 0x8000000000000000, kInvalid},
+ {0x8000000000000000, 0x8000000000000001, kInvalid},
+ {0x8000000000000000, 0xfffffffffffffffe, kInvalid},
+ {0x8000000000000000, 0xffffffffffffffff, kInvalid},
{0xfffffffffffffffe, 0, kValid64Invalid32},
{0xfffffffffffffffe, 1, kValid64Invalid32},
- {0xfffffffffffffffe, 2, false},
+ {0xfffffffffffffffe, 2, kInvalid},
{0xffffffffffffffff, 0, kValid64Invalid32},
- {0xffffffffffffffff, 1, false},
+ {0xffffffffffffffff, 1, kInvalid},
};
- ProcessReader process_reader;
- ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
-
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx",
@@ -118,16 +122,18 @@ TEST(CheckedMachAddressRange, IsValid) {
testcase.base,
testcase.size));
- CheckedMachAddressRange range(
- &process_reader, testcase.base, testcase.size);
- EXPECT_EQ(testcase.valid, range.IsValid());
+ CheckedMachAddressRange range_32(false, testcase.base, testcase.size);
+ EXPECT_EQ(ExpectationForValidity32(testcase.validity), range_32.IsValid());
+
+ CheckedMachAddressRange range_64(true, testcase.base, testcase.size);
+ EXPECT_EQ(ExpectationForValidity64(testcase.validity), range_64.IsValid());
}
}
TEST(CheckedMachAddressRange, ContainsValue) {
const struct TestData {
mach_vm_address_t value;
- bool valid;
+ bool expectation;
} kTestData[] = {
{0, false},
{1, false},
@@ -156,36 +162,32 @@ TEST(CheckedMachAddressRange, ContainsValue) {
{0xffffffffffffffff, false},
};
- ProcessReader process_reader;
- ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
-
- CheckedMachAddressRange parent_range(&process_reader, 0x2000, 0x1000);
- ASSERT_TRUE(parent_range.IsValid());
+ CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000);
+ ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
SCOPED_TRACE(
base::StringPrintf("index %zu, value 0x%llx", index, testcase.value));
- EXPECT_EQ(testcase.valid, parent_range.ContainsValue(testcase.value));
+ EXPECT_EQ(testcase.expectation,
+ parent_range_32.ContainsValue(testcase.value));
}
- CheckedMachAddressRange parent_range_64(&process_reader, 0x100000000, 0x1000);
- ASSERT_EQ(kValid64Invalid32, parent_range_64.IsValid());
- if (parent_range_64.IsValid()) {
- EXPECT_FALSE(parent_range_64.ContainsValue(0xffffffff));
- EXPECT_TRUE(parent_range_64.ContainsValue(0x100000000));
- EXPECT_TRUE(parent_range_64.ContainsValue(0x100000001));
- EXPECT_TRUE(parent_range_64.ContainsValue(0x100000fff));
- EXPECT_FALSE(parent_range_64.ContainsValue(0x100001000));
- }
+ CheckedMachAddressRange parent_range_64(true, 0x100000000, 0x1000);
+ ASSERT_TRUE(parent_range_64.IsValid());
+ EXPECT_FALSE(parent_range_64.ContainsValue(0xffffffff));
+ EXPECT_TRUE(parent_range_64.ContainsValue(0x100000000));
+ EXPECT_TRUE(parent_range_64.ContainsValue(0x100000001));
+ EXPECT_TRUE(parent_range_64.ContainsValue(0x100000fff));
+ EXPECT_FALSE(parent_range_64.ContainsValue(0x100001000));
}
TEST(CheckedMachAddressRange, ContainsRange) {
const struct TestData {
mach_vm_address_t base;
mach_vm_size_t size;
- bool valid;
+ bool expectation;
} kTestData[] = {
{0, 0, false},
{0, 1, false},
@@ -217,11 +219,8 @@ TEST(CheckedMachAddressRange, ContainsRange) {
{0x3001, 1, false},
};
- ProcessReader process_reader;
- ASSERT_TRUE(process_reader.Initialize(mach_task_self()));
-
- CheckedMachAddressRange parent_range(&process_reader, 0x2000, 0x1000);
- ASSERT_TRUE(parent_range.IsValid());
+ CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000);
+ ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
@@ -230,27 +229,26 @@ TEST(CheckedMachAddressRange, ContainsRange) {
testcase.base,
testcase.size));
- CheckedMachAddressRange child_range(
- &process_reader, testcase.base, testcase.size);
- ASSERT_TRUE(child_range.IsValid());
- EXPECT_EQ(testcase.valid, parent_range.ContainsRange(child_range));
+ CheckedMachAddressRange child_range_32(false, testcase.base, testcase.size);
+ ASSERT_TRUE(child_range_32.IsValid());
+ EXPECT_EQ(testcase.expectation,
+ parent_range_32.ContainsRange(child_range_32));
}
- CheckedMachAddressRange parent_range_64(&process_reader, 0x100000000, 0x1000);
- ASSERT_EQ(kValid64Invalid32, parent_range_64.IsValid());
- if (parent_range_64.IsValid()) {
- CheckedMachAddressRange child_range_64(&process_reader, 0xffffffff, 2);
- EXPECT_FALSE(parent_range_64.ContainsRange(child_range_64));
+ CheckedMachAddressRange parent_range_64(true, 0x100000000, 0x1000);
+ ASSERT_TRUE(parent_range_64.IsValid());
- child_range_64.SetRange(&process_reader, 0x100000000, 2);
- EXPECT_TRUE(parent_range_64.ContainsRange(child_range_64));
+ CheckedMachAddressRange child_range_64(true, 0xffffffff, 2);
+ EXPECT_FALSE(parent_range_64.ContainsRange(child_range_64));
- child_range_64.SetRange(&process_reader, 0x100000ffe, 2);
- EXPECT_TRUE(parent_range_64.ContainsRange(child_range_64));
+ child_range_64.SetRange(true, 0x100000000, 2);
+ EXPECT_TRUE(parent_range_64.ContainsRange(child_range_64));
- child_range_64.SetRange(&process_reader, 0x100000fff, 2);
- EXPECT_FALSE(parent_range_64.ContainsRange(child_range_64));
- }
+ child_range_64.SetRange(true, 0x100000ffe, 2);
+ EXPECT_TRUE(parent_range_64.ContainsRange(child_range_64));
+
+ child_range_64.SetRange(true, 0x100000fff, 2);
+ EXPECT_FALSE(parent_range_64.ContainsRange(child_range_64));
}
} // namespace
« no previous file with comments | « util/mac/checked_mach_address_range.cc ('k') | util/mac/mach_o_image_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698