Commit 141dd667 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][cleanup] Use AddressRange instead of std::pair

In the wasm code manager unittest, use the more specific AddressRange
class instead of a generic std::pair.
Also, rename the two {CheckLooksLike} methods to capture what they
actually check ({CheckPool} and {CheckRange}).

R=ahaas@chromium.org

Bug: v8:8015
Change-Id: Ia02523eabb1ddd8a3e8a255cc3987017b8338721
Reviewed-on: https://chromium-review.googlesource.com/1240135Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56176}
parent ac66c97c
...@@ -18,35 +18,34 @@ namespace wasm_heap_unittest { ...@@ -18,35 +18,34 @@ namespace wasm_heap_unittest {
class DisjointAllocationPoolTest : public ::testing::Test { class DisjointAllocationPoolTest : public ::testing::Test {
public: public:
Address A(size_t n) { return static_cast<Address>(n); } Address A(size_t n) { return static_cast<Address>(n); }
void CheckLooksLike(const DisjointAllocationPool& mem, void CheckPool(const DisjointAllocationPool& mem,
std::vector<std::pair<size_t, size_t>> expectation); std::initializer_list<AddressRange> expected_ranges);
void CheckLooksLike(AddressRange range, void CheckRange(AddressRange range1, AddressRange range2);
std::pair<size_t, size_t> expectation); DisjointAllocationPool Make(std::initializer_list<AddressRange> ranges);
DisjointAllocationPool Make(std::vector<std::pair<size_t, size_t>> model);
}; };
void DisjointAllocationPoolTest::CheckLooksLike( void DisjointAllocationPoolTest::CheckPool(
const DisjointAllocationPool& mem, const DisjointAllocationPool& mem,
std::vector<std::pair<size_t, size_t>> expectation) { std::initializer_list<AddressRange> expected_ranges) {
const auto& ranges = mem.ranges(); const auto& ranges = mem.ranges();
CHECK_EQ(ranges.size(), expectation.size()); CHECK_EQ(ranges.size(), expected_ranges.size());
auto iter = expectation.begin(); auto iter = expected_ranges.begin();
for (auto it = ranges.begin(), e = ranges.end(); it != e; ++it, ++iter) { for (auto it = ranges.begin(), e = ranges.end(); it != e; ++it, ++iter) {
CheckLooksLike(*it, *iter); CHECK_EQ(*it, *iter);
} }
} }
void DisjointAllocationPoolTest::CheckLooksLike( void DisjointAllocationPoolTest::CheckRange(AddressRange range1,
AddressRange range, std::pair<size_t, size_t> expectation) { AddressRange range2) {
CHECK_EQ(range.start, A(expectation.first)); CHECK_EQ(range1.start, range2.start);
CHECK_EQ(range.end, A(expectation.second)); CHECK_EQ(range1.end, range2.end);
} }
DisjointAllocationPool DisjointAllocationPoolTest::Make( DisjointAllocationPool DisjointAllocationPoolTest::Make(
std::vector<std::pair<size_t, size_t>> model) { std::initializer_list<AddressRange> ranges) {
DisjointAllocationPool ret; DisjointAllocationPool ret;
for (auto& pair : model) { for (auto& range : ranges) {
ret.Merge({A(pair.first), A(pair.second)}); ret.Merge(range);
} }
return ret; return ret;
} }
...@@ -54,24 +53,24 @@ DisjointAllocationPool DisjointAllocationPoolTest::Make( ...@@ -54,24 +53,24 @@ DisjointAllocationPool DisjointAllocationPoolTest::Make(
TEST_F(DisjointAllocationPoolTest, ConstructEmpty) { TEST_F(DisjointAllocationPoolTest, ConstructEmpty) {
DisjointAllocationPool a; DisjointAllocationPool a;
CHECK(a.IsEmpty()); CHECK(a.IsEmpty());
CheckLooksLike(a, {}); CheckPool(a, {});
a.Merge({1, 5}); a.Merge({1, 5});
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
} }
TEST_F(DisjointAllocationPoolTest, ConstructWithRange) { TEST_F(DisjointAllocationPoolTest, ConstructWithRange) {
DisjointAllocationPool a({1, 5}); DisjointAllocationPool a({1, 5});
CHECK(!a.IsEmpty()); CHECK(!a.IsEmpty());
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
} }
TEST_F(DisjointAllocationPoolTest, SimpleExtract) { TEST_F(DisjointAllocationPoolTest, SimpleExtract) {
DisjointAllocationPool a = Make({{1, 5}}); DisjointAllocationPool a = Make({{1, 5}});
AddressRange b = a.Allocate(2); AddressRange b = a.Allocate(2);
CheckLooksLike(a, {{3, 5}}); CheckPool(a, {{3, 5}});
CheckLooksLike(b, {1, 3}); CheckRange(b, {1, 3});
a.Merge(b); a.Merge(b);
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
CHECK_EQ(a.ranges().size(), 1); CHECK_EQ(a.ranges().size(), 1);
CHECK_EQ(a.ranges().front().start, A(1)); CHECK_EQ(a.ranges().front().start, A(1));
CHECK_EQ(a.ranges().front().end, A(5)); CHECK_EQ(a.ranges().front().end, A(5));
...@@ -80,64 +79,64 @@ TEST_F(DisjointAllocationPoolTest, SimpleExtract) { ...@@ -80,64 +79,64 @@ TEST_F(DisjointAllocationPoolTest, SimpleExtract) {
TEST_F(DisjointAllocationPoolTest, ExtractAll) { TEST_F(DisjointAllocationPoolTest, ExtractAll) {
DisjointAllocationPool a({A(1), A(5)}); DisjointAllocationPool a({A(1), A(5)});
AddressRange b = a.Allocate(4); AddressRange b = a.Allocate(4);
CheckLooksLike(b, {1, 5}); CheckRange(b, {1, 5});
CHECK(a.IsEmpty()); CHECK(a.IsEmpty());
a.Merge(b); a.Merge(b);
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
} }
TEST_F(DisjointAllocationPoolTest, FailToExtract) { TEST_F(DisjointAllocationPoolTest, FailToExtract) {
DisjointAllocationPool a = Make({{1, 5}}); DisjointAllocationPool a = Make({{1, 5}});
AddressRange b = a.Allocate(5); AddressRange b = a.Allocate(5);
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
CHECK(b.is_empty()); CHECK(b.is_empty());
} }
TEST_F(DisjointAllocationPoolTest, FailToExtractExact) { TEST_F(DisjointAllocationPoolTest, FailToExtractExact) {
DisjointAllocationPool a = Make({{1, 5}, {10, 14}}); DisjointAllocationPool a = Make({{1, 5}, {10, 14}});
AddressRange b = a.Allocate(5); AddressRange b = a.Allocate(5);
CheckLooksLike(a, {{1, 5}, {10, 14}}); CheckPool(a, {{1, 5}, {10, 14}});
CHECK(b.is_empty()); CHECK(b.is_empty());
} }
TEST_F(DisjointAllocationPoolTest, ExtractExact) { TEST_F(DisjointAllocationPoolTest, ExtractExact) {
DisjointAllocationPool a = Make({{1, 5}, {10, 15}}); DisjointAllocationPool a = Make({{1, 5}, {10, 15}});
AddressRange b = a.Allocate(5); AddressRange b = a.Allocate(5);
CheckLooksLike(a, {{1, 5}}); CheckPool(a, {{1, 5}});
CheckLooksLike(b, {10, 15}); CheckRange(b, {10, 15});
} }
TEST_F(DisjointAllocationPoolTest, Merging) { TEST_F(DisjointAllocationPoolTest, Merging) {
DisjointAllocationPool a = Make({{10, 15}, {20, 25}}); DisjointAllocationPool a = Make({{10, 15}, {20, 25}});
a.Merge({15, 20}); a.Merge({15, 20});
CheckLooksLike(a, {{10, 25}}); CheckPool(a, {{10, 25}});
} }
TEST_F(DisjointAllocationPoolTest, MergingMore) { TEST_F(DisjointAllocationPoolTest, MergingMore) {
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}}); DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
a.Merge({15, 20}); a.Merge({15, 20});
a.Merge({25, 30}); a.Merge({25, 30});
CheckLooksLike(a, {{10, 35}}); CheckPool(a, {{10, 35}});
} }
TEST_F(DisjointAllocationPoolTest, MergingSkip) { TEST_F(DisjointAllocationPoolTest, MergingSkip) {
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}}); DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
a.Merge({25, 30}); a.Merge({25, 30});
CheckLooksLike(a, {{10, 15}, {20, 35}}); CheckPool(a, {{10, 15}, {20, 35}});
} }
TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrc) { TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrc) {
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}}); DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
a.Merge({25, 30}); a.Merge({25, 30});
a.Merge({35, 40}); a.Merge({35, 40});
CheckLooksLike(a, {{10, 15}, {20, 40}}); CheckPool(a, {{10, 15}, {20, 40}});
} }
TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrcWithGap) { TEST_F(DisjointAllocationPoolTest, MergingSkipLargerSrcWithGap) {
DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}}); DisjointAllocationPool a = Make({{10, 15}, {20, 25}, {30, 35}});
a.Merge({25, 30}); a.Merge({25, 30});
a.Merge({36, 40}); a.Merge({36, 40});
CheckLooksLike(a, {{10, 15}, {20, 35}, {36, 40}}); CheckPool(a, {{10, 15}, {20, 35}, {36, 40}});
} }
enum ModuleStyle : int { Fixed = 0, Growable = 1 }; enum ModuleStyle : int { Fixed = 0, Growable = 1 };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment