42 #include <gtest/gtest.h> 49 TEST(AddrRangeTest, ValidRange)
61 TEST(AddrRangeTest, EmptyRange)
90 TEST(AddrRangeTest, RangeSizeOfOne)
103 TEST(AddrRangeTest, Range16Bit)
116 TEST(AddrRangeTest, InvalidRange)
140 TEST(AddrRangeTest, EqualToNotEqualTo)
157 TEST(AddrRangeTest, MergesWith)
170 TEST(AddrRangeTest, DoesNotMergeWith)
179 TEST(AddrRangeTest, IntersectsCompleteOverlap)
188 TEST(AddrRangeTest, IntersectsAddressWithin)
197 TEST(AddrRangeTest, IntersectsPartialOverlap)
206 TEST(AddrRangeTest, IntersectsNoOverlap)
215 TEST(AddrRangeTest, IntersectsFirstLastAddressOverlap)
228 TEST(AddrRangeTest, isSubsetCompleteOverlap)
237 TEST(AddrRangeTest, isSubsetNoOverlap)
246 TEST(AddrRangeTest, isSubsetTrueSubset)
255 TEST(AddrRangeTest, isSubsetPartialSubset)
264 TEST(AddrRangeTest, isSubsetInterleavedCompleteOverlap)
272 TEST(AddrRangeTest, isSubsetInterleavedNoOverlap)
280 TEST(AddrRangeTest, isSubsetInterleavedPartialOverlap)
302 TEST(AddrRangeTest, ContainsInAnEmptyRange)
309 TEST(AddrRangeTest, RemoveIntlvBits)
322 TEST(AddrRangeTest, addIntlvBits)
335 TEST(AddrRangeTest, OffsetInRange)
341 TEST(AddrRangeTest, OffsetOutOfRangeAfter)
350 TEST(AddrRangeTest, OffsetOutOfRangeBefore)
360 TEST(AddrRangeTest, LsbInterleavingMask)
369 uint8_t intlv_match = 1;
390 TEST(AddrRangeTest, TwoInterleavingMasks)
399 masks.push_back((1 << 1));
400 uint8_t intlv_match = (1 << 1) | 1;
413 TEST(AddrRangeTest, ComplexInterleavingMasks)
418 masks.push_back((1 << 1) | 1);
419 masks.push_back((
ULL(1) << 63) | (
ULL(1) << 62));
420 uint8_t intlv_match = 0;
433 TEST(AddrRangeTest, InterleavingAddressesMergesWith)
435 Addr start1 = 0x0000;
438 masks.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
439 masks.push_back((1 << 2));
440 uint8_t intlv_match1 = 0;
441 AddrRange r1(start1, end1, masks, intlv_match1);
443 Addr start2 = 0x0000;
445 uint8_t intlv_match2 = 1;
446 AddrRange r2(start2, end2, masks, intlv_match2);
452 TEST(AddrRangeTest, InterleavingAddressesDoNotMergeWith)
454 Addr start1 = 0x0000;
457 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
458 masks1.push_back((1 << 2));
459 uint8_t intlv_match1 = 0;
460 AddrRange r1(start1, end1, masks1, intlv_match1);
462 Addr start2 = 0x0000;
465 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
466 masks2.push_back((1 << 3));
467 uint8_t intlv_match2 = 1;
468 AddrRange r2(start2, end2, masks2, intlv_match2);
474 TEST(AddrRangeTest, InterleavingAddressesDoNotIntersect)
479 Addr start1 = 0x0000;
483 uint8_t intlv_match1 = 1;
484 AddrRange r1(start1, end1, masks1, intlv_match1);
490 Addr start2 = 0x0000;
494 uint8_t intv_match2 = 0;
495 AddrRange r2(start2, end2, masks2, intv_match2);
501 TEST(AddrRangeTest, InterleavingAddressesIntersectsViaMerging)
503 Addr start1 = 0x0000;
506 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
507 masks1.push_back((1 << 2));
508 uint8_t intlv_match1 = 0;
509 AddrRange r1(start1, end1, masks1, intlv_match1);
511 Addr start2 = 0x0000;
514 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
515 masks2.push_back((1 << 2));
516 uint8_t intlv_match2 = 0;
517 AddrRange r2(start2, end2, masks2, intlv_match2);
523 TEST(AddrRangeTest, InterleavingAddressesDoesNotIntersectViaMerging)
525 Addr start1 = 0x0000;
528 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
529 masks1.push_back((1 << 2));
530 uint8_t intlv_match1 = 0;
531 AddrRange r1(start1, end1, masks1, intlv_match1);
533 Addr start2 = 0x0000;
536 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
537 masks2.push_back((1 << 2));
542 uint8_t intlv_match2 = 1;
543 AddrRange r2(start2, end2, masks2, intlv_match2);
559 TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersect)
564 Addr start1 = 0x0000;
568 uint8_t intlv_match1 = 0;
569 AddrRange r1(start1, end1, masks1, intlv_match1);
575 Addr start2 = 0x0000;
578 masks2.push_back(1 << 2);
579 uint8_t intlv_match2 = 1;
580 AddrRange r2(start2, end2, masks2, intlv_match2);
586 TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersectsOnOneByteAddress)
595 uint8_t intlv_match = 1;
596 AddrRange r1(start, end, masks, intlv_match);
605 DISABLED_InterleavingAddressesDoesNotIntersectOnOneByteAddress)
614 uint8_t intlv_match = 1;
615 AddrRange r1(start, end, masks, intlv_match);
629 TEST(AddrRangeTest, DISABLED_InterleavingAddressIsSubset)
632 Addr start1 = 0x0000;
636 uint8_t intlv_match1 = 0;
637 AddrRange r1(start1, end1, masks1, intlv_match1);
641 Addr start2 = 0xF000;
645 uint8_t intlv_match2 = 0;
646 AddrRange r2(start2, end2, masks2, intlv_match2);
652 TEST(AddrRangeTest, DISABLED_InterleavingAddressIsNotSubset)
655 Addr start1 = 0x0000;
659 uint8_t intlv_match1 = 0;
660 AddrRange r1(start1, end1, masks1, intlv_match1);
665 Addr start2 = 0xF000;
669 uint8_t intlv_match2 = 1;
670 AddrRange r2(start2, end2, masks2, intlv_match2);
676 TEST(AddrRangeTest, DISABLED_InterleavingAddressContains)
685 masks.push_back((1 << 4) | 1);
686 uint8_t intlv_match = 0;
690 if (((
addr & 1) && ((1 << 4) &
addr)) ||
691 (!(
addr & 1) && !((1 << 4) &
addr))) {
699 TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBits)
701 Addr start = 0x00000;
705 uint8_t intlv_match = 1;
734 TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBitsTwoMasks)
736 Addr start = 0x00000;
739 masks.push_back((1 << 3) | (1 << 2) | (1 << 1) | 1);
740 masks.push_back((1 << 11) | (1 << 10) | (1 << 9) | (1 << 8));
741 uint8_t intlv_match = 1;
744 Addr input = (1 << 9) | (1 << 8) | 1;
761 TEST(AddrRangeTest, AddRemoveInterleavBitsAcrossRange)
770 Addr start = 0x00000;
773 masks.push_back(1 << 2);
774 masks.push_back(1 << 3);
775 masks.push_back(1 << 16);
776 masks.push_back(1 << 30);
777 uint8_t intlv_match = 0xF;
780 for (
Addr i = 0;
i < 0xFFF;
i++) {
785 EXPECT_EQ(
i | (1 << 2) | (1 << 3) | (1 << 16) | (1 << 30),
790 TEST(AddrRangeTest, InterleavingAddressesGetOffset)
795 masks.push_back((1 << 4) | (1 << 2));
796 uint8_t intlv_match = 0;
799 Addr value = ((1 << 10) | (1 << 9) | (1 << 8) | (1 << 2) | (1 << 1) | 1);
800 Addr value_interleaving_bits_removed =
801 ((1 << 9) | (1 << 8) | (1 << 7) | (1 << 1) | 1);
803 Addr expected_output = value_interleaving_bits_removed - start;
808 TEST(AddrRangeTest, InterleavingLessThanStartEquals)
810 Addr start1 = 0x0000FFFF;
811 Addr end1 = 0xFFFF0000;
813 masks1.push_back((1 << 4) | (1 << 2));
814 uint8_t intlv_match1 = 0;
815 AddrRange r1(start1, end1, masks1, intlv_match1);
817 Addr start2 = 0x0000FFFF;
818 Addr end2 = 0x000F0000;
820 masks2.push_back((1 << 4) | (1 << 2));
821 masks2.push_back((1 << 10));
822 uint8_t intlv_match2 = 2;
823 AddrRange r2(start2, end2, masks2, intlv_match2);
833 TEST(AddrRangeTest, InterleavingLessThanStartNotEquals)
835 Addr start1 = 0x0000FFFF;
836 Addr end1 = 0xFFFF0000;
838 masks1.push_back((1 << 4) | (1 << 2));
839 uint8_t intlv_match1 = 0;
840 AddrRange r1(start1, end1, masks1, intlv_match1);
842 Addr start2 = 0x0000FFFE;
843 Addr end2 = 0x000F0000;
845 masks2.push_back((1 << 4) | (1 << 2));
846 masks2.push_back((1 << 10));
847 uint8_t intlv_match2 = 2;
848 AddrRange r2(start2, end2, masks2, intlv_match2);
854 TEST(AddrRangeTest, InterleavingEqualTo)
856 Addr start1 = 0x0000FFFF;
857 Addr end1 = 0xFFFF0000;
859 masks1.push_back((1 << 4) | (1 << 2));
860 uint8_t intlv_match1 = 0;
861 AddrRange r1(start1, end1, masks1, intlv_match1);
863 Addr start2 = 0x0000FFFF;
864 Addr end2 = 0xFFFF0000;
866 masks2.push_back((1 << 4) | (1 << 2));
867 uint8_t intlv_match2 = 0;
868 AddrRange r2(start2, end2, masks2, intlv_match2);
873 TEST(AddrRangeTest, InterleavingNotEqualTo)
875 Addr start1 = 0x0000FFFF;
876 Addr end1 = 0xFFFF0000;
878 masks1.push_back((1 << 4) | (1 << 2));
879 uint8_t intlv_match1 = 0;
880 AddrRange r1(start1, end1, masks1, intlv_match1);
882 Addr start2 = 0x0000FFFF;
883 Addr end2 = 0xFFFF0000;
885 masks2.push_back((1 << 4) | (1 << 2));
886 masks2.push_back((1 << 10));
887 uint8_t intlv_match2 = 2;
888 AddrRange r2(start2, end2, masks2, intlv_match2);
902 TEST(AddrRangeTest, MergingInterleavingAddressRanges)
904 Addr start1 = 0x0000;
907 masks1.push_back((1 << 4) | (1 << 2));
908 uint8_t intlv_match1 = 0;
909 AddrRange r1(start1, end1, masks1, intlv_match1);
911 Addr start2 = 0x0000;
914 masks2.push_back((1 << 4) | (1 << 2));
915 uint8_t intlv_match2 = 1;
916 AddrRange r2(start2, end2, masks2, intlv_match2);
919 to_merge.push_back(r1);
920 to_merge.push_back(r2);
929 TEST(AddrRangeTest, MergingInterleavingAddressRangesOneRange)
938 masks.push_back((1 << 4) | (1 << 2));
939 uint8_t intlv_match = 0;
943 to_merge.push_back(r);
966 TEST(AddrRangeTest, LegacyConstructorNoInterleaving)
971 AddrRange range(0x0000, 0xFFFF, 0, 0, 0 ,0);
977 TEST(AddrRangeTest, LegacyConstructorOneBitMask)
984 AddrRange range(0x00000000, 0xFFFFFFFF, 0, 0, 1, 0);
993 TEST(AddrRangeTest, LegacyConstructorTwoBitMask)
1000 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 0, 2, 3);
1004 masks.push_back((1 << 1));
1010 TEST(AddrRangeTest, LegacyConstructorTwoBitMaskWithXOR)
1018 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 11, 2, 3);
1027 Addr xor_mask = (1 << 11) | (1 << 10);
1028 for (
Addr i = 0;
i < 0x0000FFFF;
i++) {
1030 Addr xor_value = (xor_mask &
i) >> 10;
1035 if (((xor_value ^
i) & 3) == 3) {
1047 TEST(AddrRangeTest, RangeExConstruction)
1054 TEST(AddrRangeTest, RangeInConstruction)
1061 TEST(AddrRangeTest, RangeSizeConstruction){
AddrRange RangeSize(Addr start, Addr size)
static void output(const char *filename)
uint64_t granularity() const
Determing the interleaving granularity of the range.
bool contains(const Addr &a) const
Determine if the range contains an address.
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Addr removeIntlvBits(Addr a) const
Remove the interleaving bits from an input address.
uint32_t stripes() const
Determine the number of interleaved address stripes this range is part of.
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
bool valid() const
Determine if the range is valid.
#define EXPECT_TRUE(expr)
A macro which verifies that expr evaluates to true.
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 })
Addr end() const
Get the end address of the range.
Addr addIntlvBits(Addr a) const
This method adds the interleaving bits removed by removeIntlvBits.
AddrRange RangeIn(Addr start, Addr end)
#define EXPECT_FALSE(expr)
A macro which verifies that expr evaluates to false.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define ULL(N)
uint64_t constant
TEST(AddrRangeTest, ValidRange)
AddrRange RangeEx(Addr start, Addr end)
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
bool interleaved() const
Determine if the range is interleaved or not.
Addr start() const
Get the start address of the range.
Addr getOffset(const Addr &a) const
Determine the offset of an address within the range.
Addr size() const
Get the size of the address range.
std::string to_string() const
Get a string representation of the range.
#define EXPECT_EQ(lhs, rhs)
A macro which verifies that lhs and rhs are equal to each other.