From: Nikos Nikoleris Date: Fri, 13 Dec 2019 16:25:49 +0000 (+0000) Subject: base: Fix AddrRange::isSubset() check X-Git-Tag: v19.0.0.0~181 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e63a5a1aeaf00773df7e95a87d5468a790e0c708;p=gem5.git base: Fix AddrRange::isSubset() check Making _end non-inclusive, introduced a bug in isSubset() which was checking if _end is included in the input address range. This CL changes the behavior and now we test if _end - 1 is in the range. Change-Id: Ib8822472b7c266e10d55f3d5cf22a46aa45c1fc7 Signed-off-by: Nikos Nikoleris Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23663 Reviewed-by: Bobby R. Bruce Reviewed-by: Jason Lowe-Power Maintainer: Bobby R. Bruce Tested-by: kokoro --- diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh index 2a18551b2..f53c08b63 100644 --- a/src/base/addr_range.hh +++ b/src/base/addr_range.hh @@ -390,7 +390,7 @@ class AddrRange // whether it would fit in a continuous segment of the input // addr range. if (r.interleaved()) { - return r.contains(_start) && r.contains(_end) && + return r.contains(_start) && r.contains(_end - 1) && size() <= r.granularity(); } else { return _start >= r._start && _end <= r._end; diff --git a/src/base/addr_range.test.cc b/src/base/addr_range.test.cc index 4ab4ae402..890fb4f3a 100644 --- a/src/base/addr_range.test.cc +++ b/src/base/addr_range.test.cc @@ -261,6 +261,30 @@ TEST(AddrRangeTest, isSubsetPartialSubset) EXPECT_FALSE(r2.isSubset(r1)); } +TEST(AddrRangeTest, isSubsetInterleavedCompleteOverlap) +{ + AddrRange r1(0x00, 0x100, {0x40}, 0); + AddrRange r2(0x00, 0x40); + + EXPECT_TRUE(r2.isSubset(r1)); +} + +TEST(AddrRangeTest, isSubsetInterleavedNoOverlap) +{ + AddrRange r1(0x00, 0x100, {0x40}, 1); + AddrRange r2(0x00, 0x40); + + EXPECT_FALSE(r2.isSubset(r1)); +} + +TEST(AddrRangeTest, isSubsetInterleavedPartialOverlap) +{ + AddrRange r1(0x00, 0x100, {0x40}, 0); + AddrRange r2(0x10, 0x50); + + EXPECT_FALSE(r2.isSubset(r1)); +} + TEST(AddrRangeTest, Contains) { AddrRange r(0xF0, 0xF5); @@ -1038,4 +1062,4 @@ TEST(AddrRangeTest, RangeSizeConstruction){ AddrRange r = RangeSize(0x5, 5); EXPECT_EQ(0x5, r.start()); EXPECT_EQ(0xA, r.end()); -} \ No newline at end of file +}