base: Fix AddrRange::isSubset() check
authorNikos Nikoleris <nikos.nikoleris@arm.com>
Fri, 13 Dec 2019 16:25:49 +0000 (16:25 +0000)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Tue, 17 Dec 2019 09:41:08 +0000 (09:41 +0000)
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 <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23663
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/addr_range.hh
src/base/addr_range.test.cc

index 2a18551b2db8eeea0874da5339f96927f6024fc1..f53c08b637ad1742fced43e062531c33c3e771b3 100644 (file)
@@ -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;
index 4ab4ae402fd8df76ed3f8e204d64618308fbcd48..890fb4f3a8b2ea42fcd99faa5ec3b1156a53296d 100644 (file)
@@ -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
+}