MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_sliced.cpp File Reference
#include <chrono>
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <unistd.h>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <fmt/base.h>
#include <mxl/fabrics.h>
#include "mxl/flow.h"
Include dependency graph for test_sliced.cpp:

Go to the source code of this file.

Functions

 TEMPLATE_TEST_CASE_METHOD (FabricsTestFixture, "Slice transfer blocks", "[sliced][slice-blocks]", TCP_V210, TCP_V210a)
 TEMPLATE_TEST_CASE_METHOD (FabricsTestFixture, "Slice transfer single", "[sliced][single-slices]", TCP_V210, TCP_V210a)
 TEMPLATE_TEST_CASE_METHOD (FabricsTestFixture, "Target commits a received grain a full ring ahead", "[sliced][target-commit]", TCP_V210)
 TEMPLATE_TEST_CASE_METHOD (FabricsTestFixture, "Target commits received grains", "[sliced][target-commit]", TCP_V210)

Function Documentation

◆ TEMPLATE_TEST_CASE_METHOD() [1/4]

TEMPLATE_TEST_CASE_METHOD ( FabricsTestFixture ,
"Slice transfer blocks" ,
"" [sliced][slice-blocks],
TCP_V210 ,
TCP_V210a  )

Definition at line 519 of file test_sliced.cpp.

520{
521 // test different block sizes
522 constexpr auto const blockSizes = std::array{2, 13, 73, 720};
523 for (auto const blockSize : blockSizes)
524 {
525 auto const startGrainIndex = std::uint64_t{140 + static_cast<std::uint64_t>(blockSize)};
526 for (auto iteration = std::size_t{0}; iteration < 4; ++iteration)
527 {
528 auto lastSlice = std::uint16_t{0};
529 auto const grainIndex = startGrainIndex + iteration;
530 this->fillInitiatorGrainWithZeros(grainIndex);
531 this->fillTargetGrainWithZeros(grainIndex);
532
533 auto startSlice = std::uint16_t{0};
534 auto info = this->getInitiatorGrainInfo(grainIndex);
535 for (;;)
536 {
537 auto endSlice = startSlice + blockSize;
538 if (endSlice >= info.totalSlices)
539 {
540 endSlice = info.totalSlices;
541 }
542
543 // find a slice in the middle of the block <= (endSlice - 1)
544 auto middleSlice = std::min(startSlice + (blockSize / 2), endSlice - 1);
545 auto [fillValueBefore, keyValueBefore] = this->readTargetGrainSlice(grainIndex, middleSlice, MXL_GRAIN_VALID_SLICES_ANY);
546 REQUIRE(fillValueBefore == 0x00);
547 if (this->hasAlphaChannel())
548 {
549 REQUIRE(keyValueBefore == 0x00);
550 }
551
552 // generate a value for fill and key buffer
553 auto fillValue = static_cast<std::uint8_t>(0xAC & ~middleSlice);
554 auto keyValue = static_cast<std::uint8_t>(0xAB & ~middleSlice);
555
556 // write to a slice in the middle of the block
557 this->writeInitiatorGrainSlice(grainIndex, middleSlice, fillValue, keyValue);
558
559 // transfer the slices
560 REQUIRE(this->transferGrainSlices(grainIndex, lastSlice, endSlice) == grainIndex);
561
562 // check that the payload is correct. the whole block up to endSlice has been transferred, so the slice
563 // in the middle of it must be valid.
564 auto [fillValueAfter,
565 keyValueAfter] = this->readTargetGrainSlice(grainIndex, middleSlice, static_cast<std::uint16_t>(middleSlice + 1));
566 REQUIRE(fillValueAfter == fillValue);
567 if (this->hasAlphaChannel())
568 {
569 REQUIRE(keyValueAfter == keyValue);
570 }
571
572 // check that validSlices was updated
573 auto const targetGrainInfo = this->getTargetGrainInfo(grainIndex);
574 REQUIRE(targetGrainInfo.validSlices == endSlice);
575
576 startSlice += blockSize;
577 if (startSlice >= info.totalSlices)
578 {
579 break;
580 }
581 }
582 }
583 }
584}
#define MXL_GRAIN_VALID_SLICES_ANY
Definition flow.h:39
REQUIRE(timeDelta< 33 '366 '667LL)

◆ TEMPLATE_TEST_CASE_METHOD() [2/4]

TEMPLATE_TEST_CASE_METHOD ( FabricsTestFixture ,
"Slice transfer single" ,
"" [sliced][single-slices],
TCP_V210 ,
TCP_V210a  )

Definition at line 476 of file test_sliced.cpp.

477{
478 constexpr auto const startGrainIndex = std::uint64_t{140};
479 for (auto iteration = std::size_t{0}; iteration < 4; ++iteration)
480 {
481 auto lastSlice = std::uint16_t{0};
482 auto const grainIndex = startGrainIndex + iteration;
483 this->fillInitiatorGrainWithZeros(grainIndex);
484 this->fillTargetGrainWithZeros(grainIndex);
485
486 auto info = this->getInitiatorGrainInfo(grainIndex);
487 for (auto slice = std::uint16_t{0}; slice < info.totalSlices; ++slice)
488 {
489 // check that the target slice is zeroed
490 auto [fillBefore, keyBefore] = this->readTargetGrainSlice(grainIndex, slice, MXL_GRAIN_VALID_SLICES_ANY);
491 REQUIRE(fillBefore == 0x00);
492 if (this->hasAlphaChannel())
493 {
494 REQUIRE(keyBefore == 0x00);
495 }
496
497 auto fillValue = static_cast<std::uint8_t>(0xAC & ~slice);
498 auto keyValue = static_cast<std::uint8_t>(0xAB & ~slice);
499
500 // write pattern to initiator grain buffer
501 this->writeInitiatorGrainSlice(grainIndex, slice, fillValue, keyValue);
502 REQUIRE(this->transferGrainSlices(grainIndex, lastSlice, slice + 1) == grainIndex);
503
504 // read after transfer, the transferred slice must now be valid
505 auto [fillAfter, keyAfter] = this->readTargetGrainSlice(grainIndex, slice, static_cast<std::uint16_t>(slice + 1));
506 REQUIRE(fillAfter == fillValue);
507 if (this->hasAlphaChannel())
508 {
509 REQUIRE(keyAfter == keyValue);
510 }
511
512 // check that validSlices has been updated
513 auto const targetGrainInfo = this->getTargetGrainInfo(grainIndex);
514 REQUIRE(targetGrainInfo.validSlices == slice + 1);
515 }
516 }
517}

◆ TEMPLATE_TEST_CASE_METHOD() [3/4]

TEMPLATE_TEST_CASE_METHOD ( FabricsTestFixture ,
"Target commits a received grain a full ring ahead" ,
"" [sliced][target-commit],
TCP_V210  )

Definition at line 617 of file test_sliced.cpp.

619{
620 // A target receives a grain grainCount or more grains past its last committed grain when its initiator stops and starts again. The ring
621 // buffer entry of the first skipped grain is the entry of the received grain.
622 auto const sliceCount = this->totalSlices();
623 auto const grainCount = this->grainCount();
624
625 auto grainIndex = std::uint64_t{400};
626 this->writeInitiatorGrainSlice(grainIndex, sliceCount - 1U, 0xAC, 0xAB);
627 REQUIRE(this->transferGrainSlices(grainIndex, 0, sliceCount) == grainIndex);
628 REQUIRE(this->commitReceivedTargetGrain(grainIndex).validSlices == sliceCount);
629
630 for (auto const skippedCount : {grainCount, (3U * grainCount) + 2U})
631 {
632 CAPTURE(skippedCount);
633 grainIndex += skippedCount + 1U;
634 this->writeInitiatorGrainSlice(grainIndex, sliceCount - 1U, 0xAD, 0xAB);
635 REQUIRE(this->transferGrainSlices(grainIndex, 0, sliceCount) == grainIndex);
636
637 auto const openedInfo = this->commitReceivedTargetGrain(grainIndex);
638 REQUIRE(openedInfo.validSlices == sliceCount);
639
640 auto const [fill, key] = this->readTargetGrainSlice(grainIndex, sliceCount - 1U, sliceCount);
641 REQUIRE(fill == 0xAD);
642 }
643
644 // A header-only transfer of an invalid grain a full ring ahead keeps the invalid flag.
645 grainIndex += grainCount + 1U;
646 this->writeInitiatorInvalidGrain(grainIndex);
647 REQUIRE(this->transferGrainSlices(grainIndex, 0, 0) == grainIndex);
648
649 auto const openedInfo = this->commitReceivedTargetGrain(grainIndex);
650 REQUIRE((openedInfo.flags & MXL_GRAIN_FLAG_INVALID) != 0);
651 REQUIRE((this->getTargetGrainInfo(grainIndex).flags & MXL_GRAIN_FLAG_INVALID) != 0);
652}
#define MXL_GRAIN_FLAG_INVALID
Definition flow.h:33
gInfo flags
Mark the grain as invalid.

◆ TEMPLATE_TEST_CASE_METHOD() [4/4]

TEMPLATE_TEST_CASE_METHOD ( FabricsTestFixture ,
"Target commits received grains" ,
"" [sliced][target-commit],
TCP_V210  )

Definition at line 588 of file test_sliced.cpp.

589{
590 constexpr auto const startGrainIndex = std::uint64_t{300};
591 auto const sliceCount = this->totalSlices();
592
593 // Full grain transfers. Each grain is a new grain for the target writer.
594 for (auto iteration = std::uint64_t{0}; iteration < 3; ++iteration)
595 {
596 auto const grainIndex = startGrainIndex + iteration;
597 this->writeInitiatorGrainSlice(grainIndex, sliceCount - 1U, 0xAC, 0xAB);
598 REQUIRE(this->transferGrainSlices(grainIndex, 0, sliceCount) == grainIndex);
599
600 auto const openedInfo = this->commitReceivedTargetGrain(grainIndex);
601 REQUIRE(openedInfo.validSlices == sliceCount);
602
603 auto const [fill, key] = this->readTargetGrainSlice(grainIndex, sliceCount - 1U, sliceCount);
604 REQUIRE(fill == 0xAC);
605 }
606
607 // A header-only transfer of an invalid grain keeps the invalid flag.
608 auto const invalidGrainIndex = startGrainIndex + 3U;
609 this->writeInitiatorInvalidGrain(invalidGrainIndex);
610 REQUIRE(this->transferGrainSlices(invalidGrainIndex, 0, 0) == invalidGrainIndex);
611
612 auto const openedInfo = this->commitReceivedTargetGrain(invalidGrainIndex);
613 REQUIRE((openedInfo.flags & MXL_GRAIN_FLAG_INVALID) != 0);
614 REQUIRE((this->getTargetGrainInfo(invalidGrainIndex).flags & MXL_GRAIN_FLAG_INVALID) != 0);
615}