39#include <gmock/gmock.h>
40#include <gtest/gtest.h>
49using testing::ElementsAre;
51TEST(AddrRangeTest, ValidRange)
54 EXPECT_FALSE(
r.valid());
63TEST(AddrRangeTest, EmptyRange)
70 EXPECT_TRUE(
r.valid());
71 EXPECT_EQ(0x0,
r.start());
72 EXPECT_EQ(0x0,
r.end());
73 EXPECT_EQ(0,
r.size());
78 EXPECT_EQ(0,
r.granularity());
83 EXPECT_FALSE(
r.interleaved());
88 EXPECT_EQ(1ULL,
r.stripes());
89 EXPECT_EQ(
"[0:0]",
r.to_string());
92TEST(AddrRangeTest, RangeSizeOfOne)
95 EXPECT_TRUE(
r.valid());
96 EXPECT_EQ(0x0,
r.start());
97 EXPECT_EQ(0x1,
r.end());
98 EXPECT_EQ(1,
r.size());
99 EXPECT_EQ(1,
r.granularity());
100 EXPECT_FALSE(
r.interleaved());
101 EXPECT_EQ(1ULL,
r.stripes());
102 EXPECT_EQ(
"[0:0x1]",
r.to_string());
108 EXPECT_TRUE(
r.valid());
109 EXPECT_EQ(0xF000,
r.start());
110 EXPECT_EQ(0xFFFF,
r.end());
111 EXPECT_EQ(0x0FFF,
r.size());
112 EXPECT_EQ(0x0FFF,
r.granularity());
113 EXPECT_FALSE(
r.interleaved());
114 EXPECT_EQ(1ULL,
r.stripes());
115 EXPECT_EQ(
"[0xf000:0xffff]",
r.to_string());
118TEST(AddrRangeTest, InvalidRange)
121 EXPECT_FALSE(
r.valid());
136 EXPECT_TRUE(r1 < r2);
137 EXPECT_FALSE(r2 < r1);
138 EXPECT_FALSE(r1 < r3);
139 EXPECT_FALSE(r3 < r1);
142TEST(AddrRangeTest, EqualToNotEqualTo)
148 EXPECT_TRUE(r1 == r2);
149 EXPECT_FALSE(r1 == r3);
150 EXPECT_FALSE(r1 != r2);
151 EXPECT_TRUE(r1 != r3);
153 EXPECT_TRUE(r2 == r1);
154 EXPECT_FALSE(r3 == r1);
155 EXPECT_FALSE(r2 != r1);
156 EXPECT_TRUE(r3 != r1);
172TEST(AddrRangeTest, DoesNotMergeWith)
181TEST(AddrRangeTest, IntersectsCompleteOverlap)
190TEST(AddrRangeTest, IntersectsAddressWithin)
199TEST(AddrRangeTest, IntersectsPartialOverlap)
208TEST(AddrRangeTest, IntersectsNoOverlap)
217TEST(AddrRangeTest, IntersectsFirstLastAddressOverlap)
230TEST(AddrRangeTest, isSubsetCompleteOverlap)
239TEST(AddrRangeTest, isSubsetNoOverlap)
248TEST(AddrRangeTest, isSubsetTrueSubset)
257TEST(AddrRangeTest, isSubsetPartialSubset)
266TEST(AddrRangeTest, isSubsetInterleavedCompleteOverlap)
271 EXPECT_TRUE(r2.isSubset(r1));
274TEST(AddrRangeTest, isSubsetInterleavedNoOverlap)
279 EXPECT_FALSE(r2.isSubset(r1));
282TEST(AddrRangeTest, isSubsetInterleavedPartialOverlap)
287 EXPECT_FALSE(r2.isSubset(r1));
294 EXPECT_FALSE(
r.contains(0xEF));
295 EXPECT_TRUE(
r.contains(0xF0));
296 EXPECT_TRUE(
r.contains(0xF1));
297 EXPECT_TRUE(
r.contains(0xF2));
298 EXPECT_TRUE(
r.contains(0xF3));
299 EXPECT_TRUE(
r.contains(0xF4));
300 EXPECT_FALSE(
r.contains(0xF5));
301 EXPECT_FALSE(
r.contains(0xF6));
304TEST(AddrRangeTest, ContainsInAnEmptyRange)
308 EXPECT_FALSE(
r.contains(0x1));
311TEST(AddrRangeTest, RemoveIntlvBits)
320 a =
r.removeIntlvBits(
a);
324TEST(AddrRangeTest, addIntlvBits)
333 a =
r.addIntlvBits(
a);
337TEST(AddrRangeTest, OffsetInRange)
340 EXPECT_EQ(0x04,
r.getOffset(0x5));
343TEST(AddrRangeTest, OffsetOutOfRangeAfter)
349 EXPECT_EQ(
MaxAddr,
r.getOffset(0xF0));
352TEST(AddrRangeTest, OffsetOutOfRangeBefore)
355 EXPECT_EQ(
MaxAddr,
r.getOffset(0x04));
362TEST(AddrRangeTest, LsbInterleavingMask)
371 uint8_t intlv_match = 1;
374 EXPECT_TRUE(
r.valid());
375 EXPECT_EQ(start,
r.start());
376 EXPECT_EQ(end,
r.end());
381 EXPECT_EQ(0x7F,
r.size());
386 EXPECT_EQ(1,
r.granularity());
387 EXPECT_TRUE(
r.interleaved());
388 EXPECT_EQ(2ULL,
r.stripes());
389 EXPECT_EQ(
"[0:0xff] a[0]^\b=1",
r.to_string());
392TEST(AddrRangeTest, TwoInterleavingMasks)
401 masks.push_back((1 << 1));
402 uint8_t intlv_match = (1 << 1) | 1;
405 EXPECT_TRUE(
r.valid());
406 EXPECT_EQ(start,
r.start());
407 EXPECT_EQ(end,
r.end());
409 EXPECT_EQ(0x3FFF,
r.size());
410 EXPECT_TRUE(
r.interleaved());
411 EXPECT_EQ(4ULL,
r.stripes());
412 EXPECT_EQ(
"[0:0xffff] a[0]^\b=1 a[1]^\b=1",
r.to_string());
415TEST(AddrRangeTest, ComplexInterleavingMasks)
420 masks.push_back((1 << 1) | 1);
421 masks.push_back((1ULL << 63) | (1ULL << 62));
422 uint8_t intlv_match = 0;
425 EXPECT_TRUE(
r.valid());
426 EXPECT_EQ(start,
r.start());
427 EXPECT_EQ(end,
r.end());
429 EXPECT_EQ(0x3FFF,
r.size());
430 EXPECT_TRUE(
r.interleaved());
431 EXPECT_EQ(4ULL,
r.stripes());
432 EXPECT_EQ(
"[0:0xffff] a[0]^a[1]^\b=0 a[62]^a[63]^\b=0",
r.to_string());
435TEST(AddrRangeTest, InterleavingAddressesMergesWith)
437 Addr start1 = 0x0000;
440 masks.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
441 masks.push_back((1 << 2));
442 uint8_t intlv_match1 = 0;
443 AddrRange r1(start1, end1, masks, intlv_match1);
445 Addr start2 = 0x0000;
447 uint8_t intlv_match2 = 1;
448 AddrRange r2(start2, end2, masks, intlv_match2);
454TEST(AddrRangeTest, InterleavingAddressesDoNotMergeWith)
456 Addr start1 = 0x0000;
459 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
460 masks1.push_back((1 << 2));
461 uint8_t intlv_match1 = 0;
462 AddrRange r1(start1, end1, masks1, intlv_match1);
464 Addr start2 = 0x0000;
467 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
468 masks2.push_back((1 << 3));
469 uint8_t intlv_match2 = 1;
470 AddrRange r2(start2, end2, masks2, intlv_match2);
476TEST(AddrRangeTest, InterleavingAddressesDoNotIntersect)
481 Addr start1 = 0x0000;
485 uint8_t intlv_match1 = 1;
486 AddrRange r1(start1, end1, masks1, intlv_match1);
492 Addr start2 = 0x0000;
496 uint8_t intv_match2 = 0;
497 AddrRange r2(start2, end2, masks2, intv_match2);
503TEST(AddrRangeTest, InterleavingAddressesIntersectsViaMerging)
505 Addr start1 = 0x0000;
508 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
509 masks1.push_back((1 << 2));
510 uint8_t intlv_match1 = 0;
511 AddrRange r1(start1, end1, masks1, intlv_match1);
513 Addr start2 = 0x0000;
516 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
517 masks2.push_back((1 << 2));
518 uint8_t intlv_match2 = 0;
519 AddrRange r2(start2, end2, masks2, intlv_match2);
525TEST(AddrRangeTest, InterleavingAddressesDoesNotIntersectViaMerging)
527 Addr start1 = 0x0000;
530 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
531 masks1.push_back((1 << 2));
532 uint8_t intlv_match1 = 0;
533 AddrRange r1(start1, end1, masks1, intlv_match1);
535 Addr start2 = 0x0000;
538 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
539 masks2.push_back((1 << 2));
544 uint8_t intlv_match2 = 1;
545 AddrRange r2(start2, end2, masks2, intlv_match2);
561TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersect)
566 Addr start1 = 0x0000;
570 uint8_t intlv_match1 = 0;
571 AddrRange r1(start1, end1, masks1, intlv_match1);
577 Addr start2 = 0x0000;
580 masks2.push_back(1 << 2);
581 uint8_t intlv_match2 = 1;
582 AddrRange r2(start2, end2, masks2, intlv_match2);
588TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersectsOnOneByteAddress)
597 uint8_t intlv_match = 1;
598 AddrRange r1(start, end, masks, intlv_match);
607 DISABLED_InterleavingAddressesDoesNotIntersectOnOneByteAddress)
616 uint8_t intlv_match = 1;
617 AddrRange r1(start, end, masks, intlv_match);
631TEST(AddrRangeTest, DISABLED_InterleavingAddressIsSubset)
634 Addr start1 = 0x0000;
638 uint8_t intlv_match1 = 0;
639 AddrRange r1(start1, end1, masks1, intlv_match1);
643 Addr start2 = 0xF000;
647 uint8_t intlv_match2 = 0;
648 AddrRange r2(start2, end2, masks2, intlv_match2);
654TEST(AddrRangeTest, DISABLED_InterleavingAddressIsNotSubset)
657 Addr start1 = 0x0000;
661 uint8_t intlv_match1 = 0;
662 AddrRange r1(start1, end1, masks1, intlv_match1);
667 Addr start2 = 0xF000;
671 uint8_t intlv_match2 = 1;
672 AddrRange r2(start2, end2, masks2, intlv_match2);
678TEST(AddrRangeTest, DISABLED_InterleavingAddressContains)
687 masks.push_back((1 << 4) | 1);
688 uint8_t intlv_match = 0;
692 if (((
addr & 1) && ((1 << 4) &
addr)) ||
693 (!(
addr & 1) && !((1 << 4) &
addr))) {
694 EXPECT_TRUE(
r.contains(
addr));
696 EXPECT_FALSE(
r.contains(
addr));
701TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBits)
703 Addr start = 0x00000;
707 uint8_t intlv_match = 1;
728 EXPECT_EQ(input >> 1,
output);
733 EXPECT_EQ(input,
r.addIntlvBits(
output));
736TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBitsTwoMasks)
738 Addr start = 0x00000;
741 masks.push_back((1 << 3) | (1 << 2) | (1 << 1) | 1);
742 masks.push_back((1 << 11) | (1 << 10) | (1 << 9) | (1 << 8));
743 uint8_t intlv_match = 1;
746 Addr input = (1 << 9) | (1 << 8) | 1;
755 EXPECT_EQ((1 << 7),
output);
760 EXPECT_EQ(input,
r.addIntlvBits(
output));
763TEST(AddrRangeTest, AddRemoveInterleavBitsAcrossRange)
772 Addr start = 0x00000;
775 masks.push_back(1 << 2);
776 masks.push_back(1 << 3);
777 masks.push_back(1 << 7);
778 masks.push_back(1 << 11);
779 uint8_t intlv_match = 0xF;
782 for (
Addr i = 0;
i < 0xFFF;
i++) {
783 Addr removedBits =
r.removeIntlvBits(
i);
787 EXPECT_EQ(
i | (1 << 2) | (1 << 3) | (1 << 7) | (1 << 11),
788 r.addIntlvBits(removedBits));
792TEST(AddrRangeTest, AddRemoveInterleavBitsAcrossContiguousRange)
801 Addr start = 0x00000;
804 masks.push_back(1 << 2);
805 masks.push_back(1 << 3);
806 masks.push_back(1 << 4);
807 uint8_t intlv_match = 0x7;
810 for (
Addr i = 0;
i < 0xFFF;
i++) {
811 Addr removedBits =
r.removeIntlvBits(
i);
815 EXPECT_EQ(
i | (1 << 2) | (1 << 3) | (1 << 4),
816 r.addIntlvBits(removedBits));
820TEST(AddrRangeTest, InterleavingAddressesGetOffset)
825 masks.push_back((1 << 4) | (1 << 2));
826 uint8_t intlv_match = 0;
829 Addr value = ((1 << 10) | (1 << 9) | (1 << 8) | (1 << 2) | (1 << 1) | 1);
830 Addr value_interleaving_bits_removed =
831 ((1 << 9) | (1 << 8) | (1 << 7) | (1 << 1) | 1);
833 Addr expected_output = value_interleaving_bits_removed - start;
835 EXPECT_EQ(expected_output,
r.getOffset(value));
838TEST(AddrRangeTest, InterleavingLessThanStartEquals)
840 Addr start1 = 0x0000FFFF;
841 Addr end1 = 0xFFFF0000;
843 masks1.push_back((1 << 4) | (1 << 2));
844 uint8_t intlv_match1 = 0;
845 AddrRange r1(start1, end1, masks1, intlv_match1);
847 Addr start2 = 0x0000FFFF;
848 Addr end2 = 0x000F0000;
850 masks2.push_back((1 << 4) | (1 << 2));
851 masks2.push_back((1 << 10));
852 uint8_t intlv_match2 = 2;
853 AddrRange r2(start2, end2, masks2, intlv_match2);
859 EXPECT_TRUE(r1 < r2);
860 EXPECT_FALSE(r2 < r1);
863TEST(AddrRangeTest, InterleavingLessThanStartNotEquals)
865 Addr start1 = 0x0000FFFF;
866 Addr end1 = 0xFFFF0000;
868 masks1.push_back((1 << 4) | (1 << 2));
869 uint8_t intlv_match1 = 0;
870 AddrRange r1(start1, end1, masks1, intlv_match1);
872 Addr start2 = 0x0000FFFE;
873 Addr end2 = 0x000F0000;
875 masks2.push_back((1 << 4) | (1 << 2));
876 masks2.push_back((1 << 10));
877 uint8_t intlv_match2 = 2;
878 AddrRange r2(start2, end2, masks2, intlv_match2);
880 EXPECT_TRUE(r2 < r1);
881 EXPECT_FALSE(r1 < r2);
884TEST(AddrRangeTest, InterleavingEqualTo)
886 Addr start1 = 0x0000FFFF;
887 Addr end1 = 0xFFFF0000;
889 masks1.push_back((1 << 4) | (1 << 2));
890 uint8_t intlv_match1 = 0;
891 AddrRange r1(start1, end1, masks1, intlv_match1);
893 Addr start2 = 0x0000FFFF;
894 Addr end2 = 0xFFFF0000;
896 masks2.push_back((1 << 4) | (1 << 2));
897 uint8_t intlv_match2 = 0;
898 AddrRange r2(start2, end2, masks2, intlv_match2);
900 EXPECT_TRUE(r1 == r2);
903TEST(AddrRangeTest, InterleavingNotEqualTo)
905 Addr start1 = 0x0000FFFF;
906 Addr end1 = 0xFFFF0000;
908 masks1.push_back((1 << 4) | (1 << 2));
909 uint8_t intlv_match1 = 0;
910 AddrRange r1(start1, end1, masks1, intlv_match1);
912 Addr start2 = 0x0000FFFF;
913 Addr end2 = 0xFFFF0000;
915 masks2.push_back((1 << 4) | (1 << 2));
916 masks2.push_back((1 << 10));
917 uint8_t intlv_match2 = 2;
918 AddrRange r2(start2, end2, masks2, intlv_match2);
923 EXPECT_FALSE(r1 == r2);
932TEST(AddrRangeTest, MergingInterleavingAddressRanges)
934 Addr start1 = 0x0000;
937 masks1.push_back((1 << 4) | (1 << 2));
938 uint8_t intlv_match1 = 0;
939 AddrRange r1(start1, end1, masks1, intlv_match1);
941 Addr start2 = 0x0000;
944 masks2.push_back((1 << 4) | (1 << 2));
945 uint8_t intlv_match2 = 1;
946 AddrRange r2(start2, end2, masks2, intlv_match2);
949 to_merge.push_back(r1);
950 to_merge.push_back(r2);
954 EXPECT_EQ(0x0000,
output.start());
955 EXPECT_EQ(0xFFFF,
output.end());
956 EXPECT_FALSE(
output.interleaved());
959TEST(AddrRangeTest, MergingInterleavingAddressRangesOneRange)
968 masks.push_back((1 << 4) | (1 << 2));
969 uint8_t intlv_match = 0;
973 to_merge.push_back(
r);
996TEST(AddrRangeTest, LegacyConstructorNoInterleaving)
1001 AddrRange range(0x0000, 0xFFFF, 0, 0, 0 ,0);
1007TEST(AddrRangeTest, LegacyConstructorOneBitMask)
1014 AddrRange range(0x00000000, 0xFFFFFFFF, 0, 0, 1, 0);
1023TEST(AddrRangeTest, LegacyConstructorTwoBitMask)
1030 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 0, 2, 3);
1034 masks.push_back((1 << 1));
1040TEST(AddrRangeTest, LegacyConstructorTwoBitMaskWithXOR)
1048 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 11, 2, 3);
1057 Addr xor_mask = (1 << 11) | (1 << 10);
1058 for (
Addr i = 0;
i < 0x0000FFFF;
i++) {
1060 Addr xor_value = (xor_mask &
i) >> 10;
1065 if (((xor_value ^
i) & 3) == 3) {
1077TEST(AddrRangeTest, RangeExConstruction)
1080 EXPECT_EQ(0x6,
r.start());
1081 EXPECT_EQ(0xE,
r.end());
1084TEST(AddrRangeTest, RangeInConstruction)
1087 EXPECT_EQ(0x6,
r.start());
1088 EXPECT_EQ(0xF,
r.end());
1091TEST(AddrRangeTest, RangeSizeConstruction){
1093 EXPECT_EQ(0x5,
r.start());
1094 EXPECT_EQ(0xA,
r.end());
1116 auto ranges =
r.exclude(exclude_ranges);
1118 EXPECT_TRUE(ranges.empty());
1133TEST(AddrRangeTest, ExcludeAllEqual)
1140 auto ranges =
r.exclude(exclude_ranges);
1142 EXPECT_TRUE(ranges.empty());
1157TEST(AddrRangeTest, ExcludeAllMultiple)
1166 auto ranges =
r.exclude(exclude_ranges);
1168 EXPECT_TRUE(ranges.empty());
1187TEST(AddrRangeTest, ExcludeAllOverlapping)
1196 auto ranges =
r.exclude(exclude_ranges);
1198 EXPECT_TRUE(ranges.empty());
1215 auto ranges =
r.exclude(exclude_ranges);
1217 EXPECT_EQ(ranges.size(), 1);
1218 EXPECT_EQ(ranges.front(),
r);
1241 auto ranges =
r.exclude(exclude_ranges);
1243 EXPECT_EQ(ranges.size(), 1);
1244 EXPECT_EQ(ranges.front(),
r);
1261TEST(AddrRangeTest, DoubleExclusion)
1268 const AddrRange expected_range1(0x130, 0x140);
1269 const AddrRange expected_range2(0x170, 0x200);
1272 auto ranges =
r.exclude(exclude_ranges);
1274 EXPECT_EQ(ranges.size(), 2);
1275 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1292TEST(AddrRangeTest, MultipleExclusion)
1300 const AddrRange expected_range1(0x130, 0x140);
1301 const AddrRange expected_range2(0x170, 0x180);
1304 auto ranges =
r.exclude(exclude_ranges);
1306 EXPECT_EQ(ranges.size(), 2);
1307 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1326TEST(AddrRangeTest, MultipleExclusionOverlapping)
1334 const AddrRange expected_range1(0x130, 0x140);
1337 auto ranges =
r.exclude(exclude_ranges);
1339 EXPECT_EQ(ranges.size(), 1);
1340 EXPECT_THAT(ranges, ElementsAre(expected_range1));
1361TEST(AddrRangeTest, ExclusionOverlapping)
1368 const AddrRange expected_range1(0x100, 0x120);
1369 const AddrRange expected_range2(0x180, 0x200);
1372 auto ranges =
r.exclude(exclude_ranges);
1374 EXPECT_EQ(ranges.size(), 2);
1375 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1394TEST(AddrRangeTest, MultipleExclusionUnsorted)
1402 const AddrRange expected_range1(0x130, 0x140);
1403 const AddrRange expected_range2(0x170, 0x180);
1406 auto ranges =
r.exclude(exclude_ranges);
1408 EXPECT_EQ(ranges.size(), 2);
1409 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1412TEST(AddrRangeTest, ExclusionOfSingleRange)
1414 const AddrRange expected_range1(0x100, 0x140);
1415 const AddrRange expected_range2(0x1c0, 0x200);
1418 auto ranges =
r.exclude(
AddrRange(0x140, 0x1c0));
1420 EXPECT_EQ(ranges.size(), 2);
1421 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1424TEST(AddrRangeTest, ExclusionOfRangeFromRangeList)
1428 const AddrRange expected_range1(0x100, 0x180);
1429 const AddrRange expected_range2(0x380, 0x400);
1433 EXPECT_EQ(ranges.size(), 2);
1434 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1437TEST(AddrRangeTest, ExclusionOfRangeListFromRangeList)
1441 const AddrRange expected_range1(0x100, 0x140);
1442 const AddrRange expected_range2(0x180, 0x200);
1443 const AddrRange expected_range3(0x300, 0x340);
1444 const AddrRange expected_range4(0x380, 0x400);
1450 EXPECT_EQ(ranges.size(), 4);
1451 EXPECT_THAT(ranges, ElementsAre(
1452 expected_range1, expected_range2,
1453 expected_range3, expected_range4));
1456TEST(AddrRangeTest, SubtractionOperatorRange)
1458 const AddrRange expected_range1(0x100, 0x140);
1459 const AddrRange expected_range2(0x1c0, 0x200);
1464 EXPECT_EQ(ranges.size(), 2);
1465 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1468TEST(AddrRangeTest, SubtractionOperatorRangeList)
1470 const AddrRange expected_range1(0x100, 0x140);
1471 const AddrRange expected_range2(0x160, 0x180);
1472 const AddrRange expected_range3(0x1a0, 0x200);
1478 EXPECT_EQ(ranges.size(), 3);
1479 EXPECT_THAT(ranges, ElementsAre(
1480 expected_range1, expected_range2, expected_range3));
1483TEST(AddrRangeTest, SubtractionOfRangeFromRangeList)
1487 const AddrRange expected_range1(0x100, 0x180);
1488 const AddrRange expected_range2(0x380, 0x400);
1492 EXPECT_EQ(ranges.size(), 2);
1493 EXPECT_THAT(ranges, ElementsAre(expected_range1, expected_range2));
1496TEST(AddrRangeTest, SubtractionOfRangeListFromRangeList)
1500 const AddrRange expected_range1(0x100, 0x140);
1501 const AddrRange expected_range2(0x180, 0x200);
1502 const AddrRange expected_range3(0x300, 0x340);
1503 const AddrRange expected_range4(0x380, 0x400);
1507 auto ranges =
base - to_exclude;
1509 EXPECT_EQ(ranges.size(), 4);
1510 EXPECT_THAT(ranges, ElementsAre(
1511 expected_range1, expected_range2,
1512 expected_range3, expected_range4));
1515TEST(AddrRangeTest, SubtractionAssignmentOfRangeFromRangeList)
1519 const AddrRange expected_range1(0x100, 0x180);
1520 const AddrRange expected_range2(0x380, 0x400);
1524 EXPECT_EQ(
base.size(), 2);
1525 EXPECT_THAT(
base, ElementsAre(expected_range1, expected_range2));
1528TEST(AddrRangeTest, SubtractionAssignmentOfRangeListFromRangeList)
1532 const AddrRange expected_range1(0x100, 0x140);
1533 const AddrRange expected_range2(0x180, 0x200);
1534 const AddrRange expected_range3(0x300, 0x340);
1535 const AddrRange expected_range4(0x380, 0x400);
1541 EXPECT_EQ(
base.size(), 4);
1542 EXPECT_THAT(
base, ElementsAre(
1543 expected_range1, expected_range2,
1544 expected_range3, expected_range4));
1547TEST(AddrRangeTest, isNotSubsetLastByte)
1558 EXPECT_FALSE(last_four_bytes.
isSubset(first_four_bytes));
1561TEST(AddrRangeTest, isSubsetLastByte)
1574 EXPECT_TRUE(not_wrapped_last_bytes.
isSubset(last_four_bytes));
1581TEST(AddrRangeDeathTest, ExcludeInterleavingRanges)
1591 GTEST_SKIP() <<
"Skipping as assetions are stripped from fast builds.";
1599 EXPECT_TRUE(
r.interleaved());
1600 EXPECT_DEATH(
r.exclude(exclude_ranges),
"");
TEST(AddrRangeTest, ValidRange)
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
std::vector< SwitchingFiber * > expected({ &a, &b, &a, &a, &a, &b, &c, &a, &c, &c, &c })
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
AddrRange RangeEx(Addr start, Addr end)
AddrRange RangeSize(Addr start, Addr size)
AddrRange RangeIn(Addr start, Addr end)
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
bool contains(const Addr &a) const
Determine if the range contains an address.
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
static AddrRangeList exclude(const AddrRangeList &base, AddrRangeList to_exclude)
static void output(const char *filename)