39 #include <gtest/gtest.h>
46 TEST(AddrRangeTest, ValidRange)
58 TEST(AddrRangeTest, EmptyRange)
87 TEST(AddrRangeTest, RangeSizeOfOne)
100 TEST(AddrRangeTest, Range16Bit)
113 TEST(AddrRangeTest, InvalidRange)
137 TEST(AddrRangeTest, EqualToNotEqualTo)
154 TEST(AddrRangeTest, MergesWith)
167 TEST(AddrRangeTest, DoesNotMergeWith)
176 TEST(AddrRangeTest, IntersectsCompleteOverlap)
185 TEST(AddrRangeTest, IntersectsAddressWithin)
194 TEST(AddrRangeTest, IntersectsPartialOverlap)
203 TEST(AddrRangeTest, IntersectsNoOverlap)
212 TEST(AddrRangeTest, IntersectsFirstLastAddressOverlap)
225 TEST(AddrRangeTest, isSubsetCompleteOverlap)
234 TEST(AddrRangeTest, isSubsetNoOverlap)
243 TEST(AddrRangeTest, isSubsetTrueSubset)
252 TEST(AddrRangeTest, isSubsetPartialSubset)
261 TEST(AddrRangeTest, isSubsetInterleavedCompleteOverlap)
269 TEST(AddrRangeTest, isSubsetInterleavedNoOverlap)
277 TEST(AddrRangeTest, isSubsetInterleavedPartialOverlap)
299 TEST(AddrRangeTest, ContainsInAnEmptyRange)
306 TEST(AddrRangeTest, RemoveIntlvBits)
315 a =
r.removeIntlvBits(
a);
319 TEST(AddrRangeTest, addIntlvBits)
328 a =
r.addIntlvBits(
a);
332 TEST(AddrRangeTest, OffsetInRange)
338 TEST(AddrRangeTest, OffsetOutOfRangeAfter)
347 TEST(AddrRangeTest, OffsetOutOfRangeBefore)
357 TEST(AddrRangeTest, LsbInterleavingMask)
366 uint8_t intlv_match = 1;
384 EXPECT_EQ(
"[0:0xff] a[0]^\b=1",
r.to_string());
387 TEST(AddrRangeTest, TwoInterleavingMasks)
396 masks.push_back((1 << 1));
397 uint8_t intlv_match = (1 << 1) | 1;
407 EXPECT_EQ(
"[0:0xffff] a[0]^\b=1 a[1]^\b=1",
r.to_string());
410 TEST(AddrRangeTest, ComplexInterleavingMasks)
415 masks.push_back((1 << 1) | 1);
416 masks.push_back((
ULL(1) << 63) | (
ULL(1) << 62));
417 uint8_t intlv_match = 0;
427 EXPECT_EQ(
"[0:0xffff] a[0]^a[1]^\b=0 a[62]^a[63]^\b=0",
r.to_string());
430 TEST(AddrRangeTest, InterleavingAddressesMergesWith)
432 Addr start1 = 0x0000;
435 masks.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
436 masks.push_back((1 << 2));
437 uint8_t intlv_match1 = 0;
438 AddrRange r1(start1, end1, masks, intlv_match1);
440 Addr start2 = 0x0000;
442 uint8_t intlv_match2 = 1;
443 AddrRange r2(start2, end2, masks, intlv_match2);
449 TEST(AddrRangeTest, InterleavingAddressesDoNotMergeWith)
451 Addr start1 = 0x0000;
454 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
455 masks1.push_back((1 << 2));
456 uint8_t intlv_match1 = 0;
457 AddrRange r1(start1, end1, masks1, intlv_match1);
459 Addr start2 = 0x0000;
462 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
463 masks2.push_back((1 << 3));
464 uint8_t intlv_match2 = 1;
465 AddrRange r2(start2, end2, masks2, intlv_match2);
471 TEST(AddrRangeTest, InterleavingAddressesDoNotIntersect)
476 Addr start1 = 0x0000;
480 uint8_t intlv_match1 = 1;
481 AddrRange r1(start1, end1, masks1, intlv_match1);
487 Addr start2 = 0x0000;
491 uint8_t intv_match2 = 0;
492 AddrRange r2(start2, end2, masks2, intv_match2);
498 TEST(AddrRangeTest, InterleavingAddressesIntersectsViaMerging)
500 Addr start1 = 0x0000;
503 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
504 masks1.push_back((1 << 2));
505 uint8_t intlv_match1 = 0;
506 AddrRange r1(start1, end1, masks1, intlv_match1);
508 Addr start2 = 0x0000;
511 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
512 masks2.push_back((1 << 2));
513 uint8_t intlv_match2 = 0;
514 AddrRange r2(start2, end2, masks2, intlv_match2);
520 TEST(AddrRangeTest, InterleavingAddressesDoesNotIntersectViaMerging)
522 Addr start1 = 0x0000;
525 masks1.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
526 masks1.push_back((1 << 2));
527 uint8_t intlv_match1 = 0;
528 AddrRange r1(start1, end1, masks1, intlv_match1);
530 Addr start2 = 0x0000;
533 masks2.push_back((1 << 29) | (1 << 20) | (1 << 10) | 1);
534 masks2.push_back((1 << 2));
539 uint8_t intlv_match2 = 1;
540 AddrRange r2(start2, end2, masks2, intlv_match2);
556 TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersect)
561 Addr start1 = 0x0000;
565 uint8_t intlv_match1 = 0;
566 AddrRange r1(start1, end1, masks1, intlv_match1);
572 Addr start2 = 0x0000;
575 masks2.push_back(1 << 2);
576 uint8_t intlv_match2 = 1;
577 AddrRange r2(start2, end2, masks2, intlv_match2);
583 TEST(AddrRangeTest, DISABLED_InterleavingAddressesIntersectsOnOneByteAddress)
592 uint8_t intlv_match = 1;
593 AddrRange r1(start, end, masks, intlv_match);
602 DISABLED_InterleavingAddressesDoesNotIntersectOnOneByteAddress)
611 uint8_t intlv_match = 1;
612 AddrRange r1(start, end, masks, intlv_match);
626 TEST(AddrRangeTest, DISABLED_InterleavingAddressIsSubset)
629 Addr start1 = 0x0000;
633 uint8_t intlv_match1 = 0;
634 AddrRange r1(start1, end1, masks1, intlv_match1);
638 Addr start2 = 0xF000;
642 uint8_t intlv_match2 = 0;
643 AddrRange r2(start2, end2, masks2, intlv_match2);
649 TEST(AddrRangeTest, DISABLED_InterleavingAddressIsNotSubset)
652 Addr start1 = 0x0000;
656 uint8_t intlv_match1 = 0;
657 AddrRange r1(start1, end1, masks1, intlv_match1);
662 Addr start2 = 0xF000;
666 uint8_t intlv_match2 = 1;
667 AddrRange r2(start2, end2, masks2, intlv_match2);
673 TEST(AddrRangeTest, DISABLED_InterleavingAddressContains)
682 masks.push_back((1 << 4) | 1);
683 uint8_t intlv_match = 0;
687 if (((
addr & 1) && ((1 << 4) &
addr)) ||
688 (!(
addr & 1) && !((1 << 4) &
addr))) {
696 TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBits)
698 Addr start = 0x00000;
702 uint8_t intlv_match = 1;
731 TEST(AddrRangeTest, InterleavingAddressAddRemoveInterlvBitsTwoMasks)
733 Addr start = 0x00000;
736 masks.push_back((1 << 3) | (1 << 2) | (1 << 1) | 1);
737 masks.push_back((1 << 11) | (1 << 10) | (1 << 9) | (1 << 8));
738 uint8_t intlv_match = 1;
741 Addr input = (1 << 9) | (1 << 8) | 1;
758 TEST(AddrRangeTest, AddRemoveInterleavBitsAcrossRange)
767 Addr start = 0x00000;
770 masks.push_back(1 << 2);
771 masks.push_back(1 << 3);
772 masks.push_back(1 << 16);
773 masks.push_back(1 << 30);
774 uint8_t intlv_match = 0xF;
777 for (
Addr i = 0;
i < 0xFFF;
i++) {
778 Addr removedBits =
r.removeIntlvBits(
i);
782 EXPECT_EQ(
i | (1 << 2) | (1 << 3) | (1 << 16) | (1 << 30),
783 r.addIntlvBits(removedBits));
787 TEST(AddrRangeTest, InterleavingAddressesGetOffset)
792 masks.push_back((1 << 4) | (1 << 2));
793 uint8_t intlv_match = 0;
796 Addr value = ((1 << 10) | (1 << 9) | (1 << 8) | (1 << 2) | (1 << 1) | 1);
797 Addr value_interleaving_bits_removed =
798 ((1 << 9) | (1 << 8) | (1 << 7) | (1 << 1) | 1);
800 Addr expected_output = value_interleaving_bits_removed - start;
802 EXPECT_EQ(expected_output,
r.getOffset(value));
805 TEST(AddrRangeTest, InterleavingLessThanStartEquals)
807 Addr start1 = 0x0000FFFF;
808 Addr end1 = 0xFFFF0000;
810 masks1.push_back((1 << 4) | (1 << 2));
811 uint8_t intlv_match1 = 0;
812 AddrRange r1(start1, end1, masks1, intlv_match1);
814 Addr start2 = 0x0000FFFF;
815 Addr end2 = 0x000F0000;
817 masks2.push_back((1 << 4) | (1 << 2));
818 masks2.push_back((1 << 10));
819 uint8_t intlv_match2 = 2;
820 AddrRange r2(start2, end2, masks2, intlv_match2);
830 TEST(AddrRangeTest, InterleavingLessThanStartNotEquals)
832 Addr start1 = 0x0000FFFF;
833 Addr end1 = 0xFFFF0000;
835 masks1.push_back((1 << 4) | (1 << 2));
836 uint8_t intlv_match1 = 0;
837 AddrRange r1(start1, end1, masks1, intlv_match1);
839 Addr start2 = 0x0000FFFE;
840 Addr end2 = 0x000F0000;
842 masks2.push_back((1 << 4) | (1 << 2));
843 masks2.push_back((1 << 10));
844 uint8_t intlv_match2 = 2;
845 AddrRange r2(start2, end2, masks2, intlv_match2);
851 TEST(AddrRangeTest, InterleavingEqualTo)
853 Addr start1 = 0x0000FFFF;
854 Addr end1 = 0xFFFF0000;
856 masks1.push_back((1 << 4) | (1 << 2));
857 uint8_t intlv_match1 = 0;
858 AddrRange r1(start1, end1, masks1, intlv_match1);
860 Addr start2 = 0x0000FFFF;
861 Addr end2 = 0xFFFF0000;
863 masks2.push_back((1 << 4) | (1 << 2));
864 uint8_t intlv_match2 = 0;
865 AddrRange r2(start2, end2, masks2, intlv_match2);
870 TEST(AddrRangeTest, InterleavingNotEqualTo)
872 Addr start1 = 0x0000FFFF;
873 Addr end1 = 0xFFFF0000;
875 masks1.push_back((1 << 4) | (1 << 2));
876 uint8_t intlv_match1 = 0;
877 AddrRange r1(start1, end1, masks1, intlv_match1);
879 Addr start2 = 0x0000FFFF;
880 Addr end2 = 0xFFFF0000;
882 masks2.push_back((1 << 4) | (1 << 2));
883 masks2.push_back((1 << 10));
884 uint8_t intlv_match2 = 2;
885 AddrRange r2(start2, end2, masks2, intlv_match2);
899 TEST(AddrRangeTest, MergingInterleavingAddressRanges)
901 Addr start1 = 0x0000;
904 masks1.push_back((1 << 4) | (1 << 2));
905 uint8_t intlv_match1 = 0;
906 AddrRange r1(start1, end1, masks1, intlv_match1);
908 Addr start2 = 0x0000;
911 masks2.push_back((1 << 4) | (1 << 2));
912 uint8_t intlv_match2 = 1;
913 AddrRange r2(start2, end2, masks2, intlv_match2);
916 to_merge.push_back(r1);
917 to_merge.push_back(r2);
926 TEST(AddrRangeTest, MergingInterleavingAddressRangesOneRange)
935 masks.push_back((1 << 4) | (1 << 2));
936 uint8_t intlv_match = 0;
940 to_merge.push_back(
r);
963 TEST(AddrRangeTest, LegacyConstructorNoInterleaving)
968 AddrRange range(0x0000, 0xFFFF, 0, 0, 0 ,0);
974 TEST(AddrRangeTest, LegacyConstructorOneBitMask)
981 AddrRange range(0x00000000, 0xFFFFFFFF, 0, 0, 1, 0);
990 TEST(AddrRangeTest, LegacyConstructorTwoBitMask)
997 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 0, 2, 3);
1001 masks.push_back((1 << 1));
1007 TEST(AddrRangeTest, LegacyConstructorTwoBitMaskWithXOR)
1015 AddrRange range(0x00000000, 0xFFFFFFFF, 1, 11, 2, 3);
1024 Addr xor_mask = (1 << 11) | (1 << 10);
1025 for (
Addr i = 0;
i < 0x0000FFFF;
i++) {
1027 Addr xor_value = (xor_mask &
i) >> 10;
1032 if (((xor_value ^
i) & 3) == 3) {
1044 TEST(AddrRangeTest, RangeExConstruction)
1051 TEST(AddrRangeTest, RangeInConstruction)
1058 TEST(AddrRangeTest, RangeSizeConstruction){