MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_sliced.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include <chrono>
6#include <cstdint>
7#include <cstring>
8#include <filesystem>
9#include <fstream>
10#include <sstream>
11#include <stdexcept>
12#include <string>
13#include <utility>
14#include <unistd.h>
15#include <catch2/catch_template_test_macros.hpp>
16#include <catch2/catch_test_macros.hpp>
17#include <fmt/base.h>
18#include <mxl/fabrics.h>
19#include "mxl/flow.h"
20
21namespace
22{
23 constexpr auto TEST_OP_TIMEOUT = std::chrono::seconds(5);
24
25 template<typename F, typename... Args>
26 void check(F f, std::string const& msg, Args&&... args)
27 {
28 auto const ret = f(std::forward<Args>(args)...);
29 if (ret != MXL_STATUS_OK)
30 {
31 throw std::runtime_error{msg + " (status " + std::to_string(ret) + ")"};
32 }
33 }
34
35 std::string readFile(std::filesystem::path const& filepath)
36 {
37 if (auto file = std::ifstream{filepath, std::ios::in | std::ios::binary}; file)
38 {
39 auto reader = std::stringstream{};
40 reader << file.rdbuf();
41 return reader.str();
42 }
43 throw std::runtime_error("Failed to open file: " + filepath.string());
44 }
45
46 struct ProviderTCP
47 {
48 constexpr static auto provider = MXL_FABRICS_PROVIDER_TCP;
49 constexpr static char const* targetNode = "127.0.0.1";
50 constexpr static char const* targetService = "0";
51 constexpr static char const* initiatorNode = "127.0.0.1";
52 constexpr static char const* initiatorService = "0";
53 };
54
55 struct ProviderSHM
56 {
57 constexpr static auto provider = MXL_FABRICS_PROVIDER_SHM;
58 constexpr static char const* targetNode = "target";
59 constexpr static char const* targetService = "sliced";
60 constexpr static char const* initiatorNode = "initiator";
61 constexpr static char const* initiatorService = "sliced";
62 };
63
64 struct FlowV210
65 {
66 constexpr static char const* flowDefPath = "../data/v210_flow.json";
67 constexpr static char const* flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
68 constexpr static auto hasAlphaChannel = false;
69 };
70
71 struct FlowV210a
72 {
73 constexpr static char const* flowDefPath = "../data/v210a_flow.json";
74 constexpr static char const* flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
75 constexpr static auto hasAlphaChannel = true;
76 };
77
78 template<typename Provider, typename Flow>
79 struct TestVariant
80 : Provider
81 , Flow
82 {};
83
84 using TCP_V210 = TestVariant<ProviderTCP, FlowV210>;
85 using TCP_V210a = TestVariant<ProviderTCP, FlowV210a>;
86 using SHM_V210 = TestVariant<ProviderSHM, FlowV210>;
87 using SHM_V210a = TestVariant<ProviderSHM, FlowV210a>;
88
89 class TempDomainGuard
90 {
91 public:
92 TempDomainGuard()
93 : _path()
94 {
95 char path[] = "/dev/shm/mxl-domain-XXXXXX";
96 if (::mkdtemp(path) == nullptr)
97 {
98 throw std::runtime_error{"failed to create temporary domain"};
99 }
100
101 _path = path;
102 }
103
104 ~TempDomainGuard()
105 {
106 std::filesystem::remove_all(_path);
107 }
108
109 char const* c_str() const
110 {
111 return _path.c_str();
112 }
113
114 private:
115 std::string _path;
116 };
117
118 template<typename ProviderType>
119 class FabricsTestFixture
120 {
121 public:
122 FabricsTestFixture()
123 : _targetDomain()
124 , _initiatorDomain()
125 {
126 _initiatorInstance = mxlCreateInstance(_initiatorDomain.c_str(), nullptr);
127 if (_initiatorInstance == nullptr)
128 {
129 throw std::runtime_error{"failed to create initiator mxl instance"};
130 }
131 _targetInstance = mxlCreateInstance(_targetDomain.c_str(), nullptr);
132 if (_targetInstance == nullptr)
133 {
134 throw std::runtime_error{"failed to create target mxl instance"};
135 }
136
137 auto const flowDef = readFile(ProviderType::flowDefPath);
138 auto const* flowId = ProviderType::flowId;
139
140 // clang-format off
141 check(mxlFabricsCreateInstance, "failed to create initiator fabrics instance",
142 _initiatorInstance, nullptr, &_initiatorFabricsInstance);
143 check(mxlFabricsCreateInstance, "failed to create target fabrics instance",
144 _targetInstance, nullptr, &_targetFabricsInstance);
145 check(mxlCreateFlowWriter, "failed to create initiator flow writer",
146 _initiatorInstance, flowDef.c_str(), nullptr, &_initiatorWriter, &_flowConfigInfo, nullptr);
147 check(mxlCreateFlowReader, "failed to create initiator flow reader",
148 _initiatorInstance, flowId, nullptr, &_initiatorReader);
149 check(mxlCreateFlowWriter, "failed to create target flow writer",
150 _targetInstance, flowDef.c_str(), nullptr, &_targetWriter, nullptr, nullptr);
151 check(mxlCreateFlowReader, "failed to create target flow reader",
152 _targetInstance, flowId, nullptr, &_targetReader);
153 check(mxlFabricsCreateTarget, "failed to create fabrics target",
154 _targetFabricsInstance, &_target);
155 check(mxlFabricsCreateInitiator, "failed to create fabrics initiator",
156 _initiatorFabricsInstance, &_initiator);
157
158 auto targetConfig = mxlFabricsTargetConfig{
159 .version = MXL_FABRICS_API_VERSION,
160 .interface = {
161 .version = MXL_FABRICS_API_VERSION,
162 .provider = ProviderType::provider,
164 .address = {.node = ProviderType::targetNode, .service = ProviderType::targetService},
165 .attr = nullptr,
166 },
167 .writer = _targetWriter,
168 };
169 check(mxlFabricsTargetSetup, "failed to set up target",
170 _target, &targetConfig, nullptr, &_targetInfo);
171
172 auto initiatorConfig = mxlFabricsInitiatorConfig{
173 .version = MXL_FABRICS_API_VERSION,
174 .interface = {
175 .version = MXL_FABRICS_API_VERSION,
176 .provider = ProviderType::provider,
178 .address = {.node = ProviderType::initiatorNode, .service = ProviderType::initiatorService},
179 .attr = nullptr,
180 },
181 .reader = _initiatorReader,
182 };
183
184 check(mxlFabricsInitiatorSetup, "failed to set up initiator",
185 _initiator, &initiatorConfig, nullptr);
186 check(mxlFabricsInitiatorAddTarget, "failed to add target to initiator",
187 _initiator, _targetInfo);
188 // clang-format on
189
190 driveConnectionProgress();
191 }
192
193 virtual ~FabricsTestFixture()
194 {
195 mxlFabricsDestroyInitiator(_initiatorFabricsInstance, _initiator);
196 mxlFabricsDestroyTarget(_targetFabricsInstance, _target);
197 mxlFabricsFreeTargetInfo(_targetInfo);
198
199 mxlReleaseFlowReader(_targetInstance, _targetReader);
200 mxlReleaseFlowWriter(_targetInstance, _targetWriter);
201 mxlReleaseFlowReader(_initiatorInstance, _initiatorReader);
202 mxlReleaseFlowWriter(_initiatorInstance, _initiatorWriter);
203
204 mxlFabricsDestroyInstance(_initiatorFabricsInstance);
205 mxlFabricsDestroyInstance(_targetFabricsInstance);
206 mxlDestroyInstance(_targetInstance);
207 mxlDestroyInstance(_initiatorInstance);
208 }
209
210 protected:
211 bool hasAlphaChannel() const noexcept
212 {
213 return ProviderType::hasAlphaChannel;
214 }
215
216 // Fill all planes of the initiator grain with zero
217 void fillInitiatorGrainWithZeros(std::uint64_t index)
218 {
219 fillGrainWithZeros(_initiatorWriter, index);
220 }
221
222 // Fill all planes of the target grain with zero
223 void fillTargetGrainWithZeros(std::uint64_t index)
224 {
225 fillGrainWithZeros(_targetWriter, index);
226 }
227
228 mxlGrainInfo getTargetGrainInfo(std::uint64_t index)
229 {
230 auto payload = std::add_pointer_t<std::uint8_t>{nullptr};
231 auto grainInfo = mxlGrainInfo{};
233 return grainInfo;
234 }
235
236 // Get the grain header on the initiator side
237 mxlGrainInfo getInitiatorGrainInfo(std::uint64_t index)
238 {
239 auto payload = std::add_pointer_t<std::uint8_t>{nullptr};
240 auto grainInfo = mxlGrainInfo{};
241 REQUIRE(
242 mxlFlowReaderGetGrainSliceNonBlocking(_initiatorReader, index, MXL_GRAIN_VALID_SLICES_ANY, &grainInfo, &payload) == MXL_STATUS_OK);
243 return grainInfo;
244 }
245
246 // Write a slice of key and fill data on the initiator grain
247 void writeInitiatorGrainSlice(std::uint64_t index, std::uint32_t sliceIndex, std::uint8_t fill, std::uint8_t key)
248 {
249 auto grainInfo = mxlGrainInfo{};
250 auto payload = static_cast<std::uint8_t*>(nullptr);
251 REQUIRE(mxlFlowWriterOpenGrain(_initiatorWriter, index, &grainInfo, &payload) == MXL_STATUS_OK);
252
253 auto planeOffset = std::uint32_t{0};
254 auto planeIndex = std::size_t{0};
255 for (auto const sliceLen : _flowConfigInfo.discrete.sliceSizes)
256 {
257 if (sliceLen == 0)
258 {
259 break;
260 }
261
262 auto sliceStart = payload + planeOffset + (static_cast<std::size_t>(sliceLen) * sliceIndex);
263 std::memset(sliceStart, planeIndex == 0 ? fill : key, sliceLen);
264 planeOffset += static_cast<std::size_t>(sliceLen) * grainInfo.totalSlices;
265 ++planeIndex;
266 }
267
268 grainInfo.validSlices = static_cast<std::uint16_t>(sliceIndex + 1);
269 REQUIRE(mxlFlowWriterCommitGrain(_initiatorWriter, &grainInfo) == MXL_STATUS_OK);
270 }
271
272 // Number of slices in a grain of the flow
273 std::uint16_t totalSlices()
274 {
275 auto grainInfo = mxlGrainInfo{};
276 REQUIRE(mxlFlowWriterGetGrainInfo(_initiatorWriter, 0, &grainInfo) == MXL_STATUS_OK);
277 return grainInfo.totalSlices;
278 }
279
282 std::uint64_t grainCount() const noexcept
283 {
284 return _flowConfigInfo.discrete.grainCount;
285 }
286
287 // Commit an initiator grain that has no valid slices and carries the invalid flag
288 void writeInitiatorInvalidGrain(std::uint64_t index)
289 {
290 auto grainInfo = mxlGrainInfo{};
291 auto payload = static_cast<std::uint8_t*>(nullptr);
292 REQUIRE(mxlFlowWriterOpenGrain(_initiatorWriter, index, &grainInfo, &payload) == MXL_STATUS_OK);
293 grainInfo.validSlices = 0;
294 grainInfo.flags |= MXL_GRAIN_FLAG_INVALID;
295 REQUIRE(mxlFlowWriterCommitGrain(_initiatorWriter, &grainInfo) == MXL_STATUS_OK);
296 }
297
298 // Open and commit a received grain on the target the way a gateway does: without changing the grain info that open returns.
299 // Returns the grain info that open returned.
300 mxlGrainInfo commitReceivedTargetGrain(std::uint64_t index)
301 {
302 auto grainInfo = mxlGrainInfo{};
303 auto payload = static_cast<std::uint8_t*>(nullptr);
304 REQUIRE(mxlFlowWriterOpenGrain(_targetWriter, index, &grainInfo, &payload) == MXL_STATUS_OK);
305 REQUIRE(mxlFlowWriterCommitGrain(_targetWriter, &grainInfo) == MXL_STATUS_OK);
306 return grainInfo;
307 }
308
309 // Run a full grain slice range transfer
310 std::uint64_t transferGrainSlices(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice)
311 {
312 auto deadline = std::chrono::steady_clock::now() + TEST_OP_TIMEOUT;
313 auto initiatorDone = false;
314 auto targetDone = false;
315 auto readIndex = std::uint64_t{0};
316 auto status = MXL_STATUS_OK;
317
318 // Enqueue the transfer until successfull
319 // The SHM provider needs the progress and read calls even if no transfers have been queued yet to become ready.
320 do
321 {
322 status = mxlFabricsInitiatorTransferGrain(_initiator, grainIndex, startSlice, endSlice);
323 mxlFabricsInitiatorMakeProgressNonBlocking(_initiator); // the SHM provider needs a CQ read here sometimes to not get stuck
324 if (mxlFabricsTargetReadGrainNonBlocking(_target, &readIndex) == MXL_STATUS_OK)
325 {
326 // The SHM provider is sometimes ready right after the write has been enqueued.
327 return readIndex;
328 }
329 }
330 while (status != MXL_STATUS_OK && std::chrono::steady_clock::now() < deadline);
331
332 // Timeout of not ok
333 REQUIRE(status == MXL_STATUS_OK);
334
335 // Drive progress on both sides of the connection until the grain slices have been transferred
336 while (std::chrono::steady_clock::now() < deadline)
337 {
338 if (!initiatorDone)
339 {
340 auto status = mxlFabricsInitiatorMakeProgressNonBlocking(_initiator);
341 if (status == MXL_STATUS_OK)
342 {
343 initiatorDone = true;
344 }
345 else
346 {
347 REQUIRE(status == MXL_ERR_NOT_READY);
348 }
349 }
350
351 if (!targetDone)
352 {
353 auto status = mxlFabricsTargetReadGrainNonBlocking(_target, &readIndex);
354 if (status == MXL_STATUS_OK)
355 {
356 targetDone = true;
357 }
358 else
359 {
360 REQUIRE(status == MXL_ERR_NOT_READY);
361 }
362 }
363
364 if (initiatorDone && targetDone)
365 {
366 return readIndex;
367 }
368 }
369
370 FAIL("grain slice transfer did not complete within timeout");
371 return readIndex;
372 }
373
374 std::pair<std::uint8_t, std::uint8_t> readTargetGrainSlice(std::uint64_t index, std::uint32_t sliceIndex, std::uint16_t minValidSlices)
375 {
376 auto grainInfo = mxlGrainInfo{};
377 auto payload = static_cast<std::uint8_t*>(nullptr);
378 REQUIRE(mxlFlowReaderGetGrainSliceNonBlocking(_targetReader, index, minValidSlices, &grainInfo, &payload) == MXL_STATUS_OK);
379
380 auto result = std::pair<std::uint8_t, std::uint8_t>{0, 0};
381 auto planeOffset = std::uint32_t{0};
382 auto planeIndex = std::size_t{0};
383 for (auto const sliceLen : _flowConfigInfo.discrete.sliceSizes)
384 {
385 if (sliceLen == 0)
386 {
387 break;
388 }
389
390 auto byte = *(payload + (planeOffset + static_cast<std::size_t>(sliceLen) * sliceIndex));
391 if (planeIndex == 0)
392 {
393 result.first = byte;
394 }
395 else
396 {
397 result.second = byte;
398 }
399
400 planeOffset += static_cast<std::size_t>(sliceLen) * grainInfo.totalSlices;
401 ++planeIndex;
402 }
403
404 return result;
405 }
406
407 private:
408 // fill a grain at "index" with zero
409 void fillGrainWithZeros(mxlFlowWriter writer, std::uint64_t index)
410 {
411 auto grainInfo = mxlGrainInfo{};
412 auto payload = static_cast<std::uint8_t*>(nullptr);
413 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &grainInfo, &payload) == MXL_STATUS_OK);
414
415 auto planeOffset = std::uint32_t{0};
416 for (auto const sliceLen : _flowConfigInfo.discrete.sliceSizes)
417 {
418 if (sliceLen == 0)
419 {
420 break;
421 }
422
423 std::memset(payload + planeOffset, 0, static_cast<std::size_t>(sliceLen) * grainInfo.totalSlices);
424 planeOffset += static_cast<std::size_t>(sliceLen) * grainInfo.totalSlices;
425 }
426
427 grainInfo.validSlices = 0;
428 grainInfo.flags = 0;
430 }
431
432 // drive progress for the connection to be established
433 void driveConnectionProgress()
434 {
435 auto deadline = std::chrono::steady_clock::now() + TEST_OP_TIMEOUT;
436 while (std::chrono::steady_clock::now() < deadline)
437 {
438 auto dummyIndex = std::uint64_t{0};
439 mxlFabricsTargetReadGrainNonBlocking(_target, &dummyIndex);
440
441 auto status = mxlFabricsInitiatorMakeProgressNonBlocking(_initiator);
442 if (status == MXL_STATUS_OK)
443 {
444 return;
445 }
446 if (status != MXL_ERR_NOT_READY)
447 {
448 throw std::runtime_error{"initiator progress failed with status " + std::to_string(status)};
449 }
450 }
451 throw std::runtime_error{"failed to establish connection within timeout"};
452 }
453
454 private:
455 TempDomainGuard _targetDomain;
456 TempDomainGuard _initiatorDomain;
457
458 mxlInstance _initiatorInstance = nullptr;
459 mxlInstance _targetInstance = nullptr;
460 mxlFabricsInstance _initiatorFabricsInstance = nullptr;
461 mxlFabricsInstance _targetFabricsInstance = nullptr;
462 mxlFabricsTargetInfo _targetInfo = nullptr;
463
464 mxlFlowConfigInfo _flowConfigInfo = {};
465
466 mxlFlowWriter _initiatorWriter = nullptr;
467 mxlFlowReader _initiatorReader = nullptr;
468 mxlFlowWriter _targetWriter = nullptr;
469 mxlFlowReader _targetReader = nullptr;
470
471 mxlFabricsTarget _target = nullptr;
472 mxlFabricsInitiator _initiator = nullptr;
473 };
474}
475
476TEMPLATE_TEST_CASE_METHOD(FabricsTestFixture, "Slice transfer single", "[sliced][single-slices]", TCP_V210, TCP_V210a /*, SHM_V210, SHM_V210a */)
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}
518
519TEMPLATE_TEST_CASE_METHOD(FabricsTestFixture, "Slice transfer blocks", "[sliced][slice-blocks]", TCP_V210, TCP_V210a /*, SHM_V210, SHM_V210a */)
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}
585
586// A gateway on the target side opens each received grain and commits the grain info that open returns. Open must return the slice
587// count and flags that the transfer wrote into the grain header, so that the commit publishes them to local readers.
588TEMPLATE_TEST_CASE_METHOD(FabricsTestFixture, "Target commits received grains", "[sliced][target-commit]", TCP_V210 /*, SHM_V210 */)
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}
616
617TEMPLATE_TEST_CASE_METHOD(FabricsTestFixture, "Target commits a received grain a full ring ahead", "[sliced][target-commit]",
618 TCP_V210 /*, SHM_V210 */)
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}
struct mxlFabricsTargetConfig_t mxlFabricsTargetConfig
MXL_EXPORT mxlStatus mxlFabricsDestroyInitiator(mxlFabricsInstance in_fabricsInstance, mxlFabricsInitiator in_initiator)
Definition fabrics.cpp:395
MXL_EXPORT mxlStatus mxlFabricsInitiatorTransferGrain(mxlFabricsInitiator in_initiator, uint64_t in_grainIndex, uint16_t in_startSlice, uint16_t in_endSlice)
Definition fabrics.cpp:470
@ MXL_FABRICS_IFACE_CAP_BLOCKING_OPERATIONS
Definition fabrics.h:78
@ MXL_FABRICS_IFACE_CAP_REMOTE_WRITE
Definition fabrics.h:79
@ MXL_FABRICS_PROVIDER_TCP
Definition fabrics.h:49
@ MXL_FABRICS_PROVIDER_SHM
Definition fabrics.h:52
MXL_EXPORT mxlStatus mxlFabricsInitiatorMakeProgressNonBlocking(mxlFabricsInitiator in_initiator)
Definition fabrics.cpp:506
MXL_EXPORT mxlStatus mxlFabricsCreateTarget(mxlFabricsInstance in_fabricsInstance, mxlFabricsTarget *out_target)
Definition fabrics.cpp:175
MXL_EXPORT mxlStatus mxlFabricsDestroyInstance(mxlFabricsInstance in_instance)
Definition fabrics.cpp:126
MXL_EXPORT mxlStatus mxlFabricsCreateInstance(mxlInstance in_instance, char const *options, mxlFabricsInstance *out_fabricsInstance)
Definition fabrics.cpp:106
struct mxlFabricsTarget_t * mxlFabricsTarget
Definition fabrics.h:34
MXL_EXPORT mxlStatus mxlFabricsInitiatorAddTarget(mxlFabricsInitiator in_initiator, mxlFabricsTargetInfo in_targetInfo)
Definition fabrics.cpp:432
#define MXL_FABRICS_API_VERSION
Definition fabrics.h:19
MXL_EXPORT mxlStatus mxlFabricsCreateInitiator(mxlFabricsInstance in_fabricsInstance, mxlFabricsInitiator *out_initiator)
Definition fabrics.cpp:376
MXL_EXPORT mxlStatus mxlFabricsFreeTargetInfo(mxlFabricsTargetInfo in_info)
Definition fabrics.cpp:669
MXL_EXPORT mxlStatus mxlFabricsTargetReadGrainNonBlocking(mxlFabricsTarget in_target, uint64_t *out_grainIndex)
Definition fabrics.cpp:238
struct mxlFabricsTargetInfo_t * mxlFabricsTargetInfo
Definition fabrics.h:39
struct mxlFabricsInitiator_t * mxlFabricsInitiator
Definition fabrics.h:44
MXL_EXPORT mxlStatus mxlFabricsTargetSetup(mxlFabricsTarget in_target, mxlFabricsTargetConfig const *in_config, char const *in_options, mxlFabricsTargetInfo *out_info)
Definition fabrics.cpp:215
MXL_EXPORT mxlStatus mxlFabricsDestroyTarget(mxlFabricsInstance in_fabricsInstance, mxlFabricsTarget in_target)
Definition fabrics.cpp:194
struct mxlFabricsInstance_t * mxlFabricsInstance
Definition fabrics.h:29
struct mxlFabricsInitiatorConfig_t mxlFabricsInitiatorConfig
MXL_EXPORT mxlStatus mxlFabricsInitiatorSetup(mxlFabricsInitiator in_initiator, mxlFabricsInitiatorConfig const *in_config, char const *in_options)
Definition fabrics.cpp:413
Public flow reader, writer, payload and synchronization APIs.
MXL_EXPORT mxlStatus mxlFlowWriterOpenGrain(mxlFlowWriter writer, uint64_t index, mxlGrainInfo *mxlGrainInfo, uint8_t **payload)
Definition flow.cpp:446
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
Definition flow.cpp:177
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
struct mxlGrainInfo_t mxlGrainInfo
MXL_EXPORT mxlStatus mxlFlowWriterGetGrainInfo(mxlFlowWriter writer, uint64_t index, mxlGrainInfo *mxlGrainInfo)
Definition flow.cpp:422
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSliceNonBlocking(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, mxlGrainInfo *grain, uint8_t **payload)
Definition flow.cpp:399
#define MXL_GRAIN_FLAG_INVALID
Definition flow.h:33
struct mxlFlowWriter_t * mxlFlowWriter
Definition flow.h:206
#define MXL_GRAIN_VALID_SLICES_ANY
Definition flow.h:39
MXL_EXPORT mxlStatus mxlReleaseFlowWriter(mxlInstance instance, mxlFlowWriter writer)
Definition flow.cpp:262
MXL_EXPORT mxlStatus mxlCreateFlowWriter(mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
Definition flow.cpp:198
MXL_EXPORT mxlStatus mxlCreateFlowReader(mxlInstance instance, char const *flowId, char const *options, mxlFlowReader *reader)
Definition flow.cpp:136
MXL_EXPORT mxlStatus mxlFlowWriterCommitGrain(mxlFlowWriter writer, mxlGrainInfo const *grain)
Definition flow.cpp:487
struct mxlFlowConfigInfo_t mxlFlowConfigInfo
MXL_EXPORT mxlStatus mxlDestroyInstance(mxlInstance in_instance)
Definition mxl.cpp:106
@ MXL_ERR_NOT_READY
Definition mxl.h:49
@ MXL_STATUS_OK
Definition mxl.h:23
MXL_EXPORT mxlInstance mxlCreateInstance(char const *in_mxlDomain, char const *in_options)
Definition mxl.cpp:45
struct mxlInstance_t * mxlInstance
Definition mxl.h:74
Provider
Internal representation of supported libfabric providers.
Definition Provider.hpp:17
std::string readFile(std::filesystem::path const &filepath)
Definition Utils.hpp:78
mxlFlowReader reader
mxlFlowWriter writer
auto const flowId
uint64_t index
auto flowDef
gInfo flags
Mark the grain as invalid.
TEMPLATE_TEST_CASE_METHOD(FabricsTestFixture, "Slice transfer single", "[sliced][single-slices]", TCP_V210, TCP_V210a)
REQUIRE(timeDelta< 33 '366 '667LL)