de5d1200b2
Trimming may free up some allocatable pages that can be reused by subsequent allocations. This CL also fixes base::AddressRegion::contains(Address, size_t). Bug: v8:8096 Change-Id: I3b7381fd32f7dbf186dffc1a26d5a88cd8a30d2f Reviewed-on: https://chromium-review.googlesource.com/1249127 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Igor Sheludko <ishell@chromium.org> Cr-Commit-Position: refs/heads/master@{#56284}
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/base/address-region.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace base {
|
|
|
|
using Address = AddressRegion::Address;
|
|
|
|
TEST(AddressRegionTest, Contains) {
|
|
struct {
|
|
Address start;
|
|
size_t size;
|
|
} test_cases[] = {{153, 771}, {0, 227}, {-447, 447}};
|
|
|
|
for (size_t i = 0; i < arraysize(test_cases); i++) {
|
|
Address start = test_cases[i].start;
|
|
size_t size = test_cases[i].size;
|
|
Address end = start + size; // exclusive
|
|
|
|
AddressRegion region(start, size);
|
|
|
|
// Test single-argument contains().
|
|
CHECK(!region.contains(start - 1041));
|
|
CHECK(!region.contains(start - 1));
|
|
CHECK(!region.contains(end));
|
|
CHECK(!region.contains(end + 1));
|
|
CHECK(!region.contains(end + 113));
|
|
|
|
CHECK(region.contains(start));
|
|
CHECK(region.contains(start + 1));
|
|
CHECK(region.contains(start + size / 2));
|
|
CHECK(region.contains(end - 1));
|
|
|
|
// Test two-arguments contains().
|
|
CHECK(!region.contains(start - 1, size));
|
|
CHECK(!region.contains(start, size + 1));
|
|
CHECK(!region.contains(start - 17, 17));
|
|
CHECK(!region.contains(start - 17, size * 2));
|
|
CHECK(!region.contains(end, 1));
|
|
CHECK(!region.contains(end, static_cast<size_t>(0 - end)));
|
|
|
|
CHECK(region.contains(start, size));
|
|
CHECK(region.contains(start, 10));
|
|
CHECK(region.contains(start + 11, 120));
|
|
CHECK(region.contains(end - 13, 13));
|
|
CHECK(!region.contains(end, 0));
|
|
|
|
// Zero-size queries.
|
|
CHECK(!region.contains(start - 10, 0));
|
|
CHECK(!region.contains(start - 1, 0));
|
|
CHECK(!region.contains(end, 0));
|
|
CHECK(!region.contains(end + 10, 0));
|
|
|
|
CHECK(region.contains(start, 0));
|
|
CHECK(region.contains(start + 10, 0));
|
|
CHECK(region.contains(end - 1, 0));
|
|
}
|
|
}
|
|
|
|
} // namespace base
|
|
} // namespace v8
|