Skip to content

Commit 698e5b5

Browse files
Extend test coverage and update existing tests to match the new behavior
1 parent 45cd82c commit 698e5b5

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

tests/test_private_rx.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ TEST_CASE("rxSessionUpdate")
497497
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
498498
ins.getAllocator().deallocate(transfer.payload);
499499

500-
// Restart by TID timeout, not the first frame.
500+
// TID timeout does not occur until SOT; see https://github.com/OpenCyphal/libcanard/issues/212.
501501
frame.timestamp_usec = 30'000'000;
502502
frame.transfer_id = 12; // Goes back.
503503
frame.start_of_transfer = false;
@@ -507,18 +507,34 @@ TEST_CASE("rxSessionUpdate")
507507
frame.payload = reinterpret_cast<const uint8_t*>("\x0A\x0A\x0A\x0A\x0A\x0A\x0A");
508508
REQUIRE(0 == update(2, 1'000'000, 16));
509509
REQUIRE(rxs.transfer_timestamp_usec == 20'000'100); // No change.
510-
REQUIRE(rxs.payload_size == 0);
511-
REQUIRE(rxs.payload == nullptr);
512-
REQUIRE(rxs.calculated_crc == 0xFFFF);
513-
REQUIRE(rxs.transfer_id == 13U);
514-
REQUIRE(rxs.toggle);
515-
REQUIRE(rxs.redundant_transport_index == 2);
510+
REQUIRE(rxs.transfer_id == 14U); // No change.
511+
REQUIRE(rxs.toggle); // No change.
512+
REQUIRE(rxs.redundant_transport_index == 0); // No change.
516513
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 0);
517514
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 0);
518515

516+
// Restart by TID timeout. This may only occur when SOT is set.
517+
frame.timestamp_usec = 30'000'000;
518+
frame.transfer_id = 12; // Goes back.
519+
frame.start_of_transfer = true;
520+
frame.end_of_transfer = false;
521+
frame.toggle = true;
522+
frame.payload_size = 7;
523+
frame.payload = reinterpret_cast<const uint8_t*>("\x0A\x0A\x0A\x0A\x0A\x0A\x0A");
524+
REQUIRE(0 == update(2, 1'000'000, 16));
525+
REQUIRE(rxs.transfer_timestamp_usec == 30'000'000); // Updated from the frame.
526+
REQUIRE(rxs.payload_size == 7); // From the frame.
527+
REQUIRE(rxs.payload != nullptr);
528+
REQUIRE(rxs.calculated_crc == 0x23C7);
529+
REQUIRE(rxs.transfer_id == 12U); // Updated from the frame.
530+
REQUIRE(!rxs.toggle); // In anticipation of the next frame.
531+
REQUIRE(rxs.redundant_transport_index == 2); // Updated from the update.
532+
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
533+
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
534+
519535
// Restart by TID mismatch.
520536
frame.timestamp_usec = 20'000'200; // Goes back.
521-
frame.transfer_id = 11; // Goes back.
537+
frame.transfer_id = 10; // Goes back.
522538
frame.start_of_transfer = true;
523539
frame.end_of_transfer = false;
524540
frame.toggle = true;
@@ -529,15 +545,15 @@ TEST_CASE("rxSessionUpdate")
529545
REQUIRE(rxs.payload_size == 7);
530546
REQUIRE(0 == std::memcmp(rxs.payload, "\x0B\x0B\x0B\x0B\x0B\x0B\x0B", 7));
531547
REQUIRE(rxs.calculated_crc == crc("\x0B\x0B\x0B\x0B\x0B\x0B\x0B"));
532-
REQUIRE(rxs.transfer_id == 11U);
548+
REQUIRE(rxs.transfer_id == 10U);
533549
REQUIRE(!rxs.toggle);
534550
REQUIRE(rxs.redundant_transport_index == 2);
535551
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
536552
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
537553

538554
// Duplicate start rejected (toggle mismatch).
539555
frame.timestamp_usec = 20'000'300;
540-
frame.transfer_id = 11;
556+
frame.transfer_id = 10;
541557
frame.start_of_transfer = true;
542558
frame.end_of_transfer = true;
543559
frame.toggle = true;
@@ -548,15 +564,15 @@ TEST_CASE("rxSessionUpdate")
548564
REQUIRE(rxs.payload_size == 7);
549565
REQUIRE(0 == std::memcmp(rxs.payload, "\x0B\x0B\x0B\x0B\x0B\x0B\x0B", 7));
550566
REQUIRE(rxs.calculated_crc == crc("\x0B\x0B\x0B\x0B\x0B\x0B\x0B"));
551-
REQUIRE(rxs.transfer_id == 11U);
567+
REQUIRE(rxs.transfer_id == 10U);
552568
REQUIRE(!rxs.toggle);
553569
REQUIRE(rxs.redundant_transport_index == 2);
554570
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
555571
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
556572

557573
// Continue & finalize.
558574
frame.timestamp_usec = 20'000'400;
559-
frame.transfer_id = 11;
575+
frame.transfer_id = 10;
560576
frame.start_of_transfer = false;
561577
frame.end_of_transfer = true;
562578
frame.toggle = false;
@@ -567,15 +583,15 @@ TEST_CASE("rxSessionUpdate")
567583
REQUIRE(rxs.payload_size == 0);
568584
REQUIRE(rxs.payload == nullptr);
569585
REQUIRE(rxs.calculated_crc == 0xFFFF);
570-
REQUIRE(rxs.transfer_id == 12U);
586+
REQUIRE(rxs.transfer_id == 11U);
571587
REQUIRE(rxs.toggle);
572588
REQUIRE(rxs.redundant_transport_index == 2);
573589
REQUIRE(transfer.timestamp_usec == 20'000'200);
574590
REQUIRE(transfer.metadata.priority == CanardPrioritySlow);
575591
REQUIRE(transfer.metadata.transfer_kind == CanardTransferKindMessage);
576592
REQUIRE(transfer.metadata.port_id == 2'222);
577593
REQUIRE(transfer.metadata.remote_node_id == 55);
578-
REQUIRE(transfer.metadata.transfer_id == 11);
594+
REQUIRE(transfer.metadata.transfer_id == 10);
579595
REQUIRE(transfer.payload_size == 10);
580596
REQUIRE(0 == std::memcmp(transfer.payload, "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0D\x0D\x0D", 10));
581597
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);

0 commit comments

Comments
 (0)