-
Notifications
You must be signed in to change notification settings - Fork 498
Fixes for issues 431 & 399 #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/unittest/transport/can/test_can_transport_custom_config_millisecs.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /// @copyright | ||
| /// Copyright (C) OpenCyphal Development Team <opencyphal.org> | ||
| /// Copyright Amazon.com Inc. or its affiliates. | ||
| /// SPDX-License-Identifier: MIT | ||
|
|
||
| // The main purpose of this test file is make sure that CAN transport | ||
| // could be compiled with custom time representation (32-bit milliseconds) instead of the default one. | ||
| // Milliseconds are chosen b/c there is no implicit conversion from native lizard's microseconds | ||
| // to lower precision units like milliseconds, so proper explicit `std::chrono::duration_cast` is needed. | ||
| // For details also see https://github.com/OpenCyphal-Garage/libcyphal/issues/431. | ||
| #include "custom_libcyphal_config.hpp" // NOLINT(misc-include-cleaner) | ||
|
|
||
| #include "media_mock.hpp" | ||
| #include "tracking_memory_resource.hpp" | ||
| #include "virtual_time_scheduler.hpp" | ||
|
|
||
| #include <canard.h> | ||
| #include <cetl/pf17/cetlpf.hpp> | ||
| #include <libcyphal/transport/can/can_transport.hpp> | ||
| #include <libcyphal/transport/can/can_transport_impl.hpp> | ||
| #include <libcyphal/transport/can/media.hpp> | ||
| #include <libcyphal/types.hpp> | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <array> | ||
| #include <utility> | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| using libcyphal::UniquePtr; | ||
| using namespace libcyphal::transport::can; // NOLINT This our main concern here in the unit tests. | ||
|
|
||
| using testing::Eq; | ||
| using testing::Return; | ||
| using testing::IsEmpty; | ||
| using testing::NotNull; | ||
| using testing::ReturnRef; | ||
| using testing::StrictMock; | ||
| using testing::VariantWith; | ||
|
|
||
| class TestCanTransportCustomConfigMilliseconds : public testing::Test | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| cetl::pmr::set_default_resource(&mr_); | ||
|
|
||
| EXPECT_CALL(media_mock_, getMtu()).WillRepeatedly(Return(CANARD_MTU_CAN_CLASSIC)); | ||
| EXPECT_CALL(media_mock_, getTxMemoryResource()).WillRepeatedly(ReturnRef(mr_)); | ||
| } | ||
|
|
||
| void TearDown() override | ||
| { | ||
| EXPECT_THAT(mr_.allocations, IsEmpty()); | ||
| EXPECT_THAT(mr_.total_allocated_bytes, mr_.total_deallocated_bytes); | ||
| } | ||
|
|
||
| // MARK: Data members: | ||
|
|
||
| // NOLINTBEGIN | ||
| libcyphal::VirtualTimeScheduler scheduler_{}; | ||
| TrackingMemoryResource mr_; | ||
| StrictMock<MediaMock> media_mock_{}; | ||
| // NOLINTEND | ||
| }; | ||
|
|
||
| // MARK: - Tests: | ||
|
|
||
| TEST_F(TestCanTransportCustomConfigMilliseconds, makeTransport_getLocalNodeId) | ||
| { | ||
| std::array<IMedia*, 1> media_array{&media_mock_}; | ||
| auto maybe_transport = makeTransport(mr_, scheduler_, media_array, 0); | ||
| ASSERT_THAT(maybe_transport, VariantWith<UniquePtr<ICanTransport>>(NotNull())); | ||
|
|
||
| const auto transport = cetl::get<UniquePtr<ICanTransport>>(std::move(maybe_transport)); | ||
| EXPECT_THAT(transport->getLocalNodeId(), Eq(cetl::nullopt)); | ||
| } | ||
|
|
||
| } // namespace |
79 changes: 79 additions & 0 deletions
79
test/unittest/transport/udp/test_udp_transport_custom_config_millisecs.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /// @copyright | ||
| /// Copyright (C) OpenCyphal Development Team <opencyphal.org> | ||
| /// Copyright Amazon.com Inc. or its affiliates. | ||
| /// SPDX-License-Identifier: MIT | ||
|
|
||
| // The main purpose of this test file is make sure that UDP transport | ||
| // could be compiled with custom time representation (32-bit milliseconds) instead of the default one. | ||
| // Milliseconds are chosen b/c there is no implicit conversion from native lizard's microseconds | ||
| // to lower precision units like milliseconds, so proper explicit `std::chrono::duration_cast` is needed. | ||
| // For details also see https://github.com/OpenCyphal-Garage/libcyphal/issues/431. | ||
| #include "custom_libcyphal_config.hpp" // NOLINT(misc-include-cleaner) | ||
|
|
||
| #include "media_mock.hpp" | ||
| #include "tracking_memory_resource.hpp" | ||
| #include "virtual_time_scheduler.hpp" | ||
|
|
||
| #include <cetl/pf17/cetlpf.hpp> | ||
| #include <libcyphal/transport/udp/media.hpp> | ||
| #include <libcyphal/transport/udp/udp_transport.hpp> | ||
| #include <libcyphal/transport/udp/udp_transport_impl.hpp> | ||
| #include <libcyphal/types.hpp> | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <array> | ||
| #include <utility> | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| using libcyphal::UniquePtr; | ||
| using namespace libcyphal::transport::udp; // NOLINT This our main concern here in the unit tests. | ||
|
|
||
| using testing::Eq; | ||
| using testing::IsEmpty; | ||
| using testing::NotNull; | ||
| using testing::ReturnRef; | ||
| using testing::StrictMock; | ||
| using testing::VariantWith; | ||
|
|
||
| class TestUpdTransportCustomConfigMilliseconds : public testing::Test | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| cetl::pmr::set_default_resource(&mr_); | ||
|
|
||
| EXPECT_CALL(media_mock_, getTxMemoryResource()).WillRepeatedly(ReturnRef(mr_)); | ||
| } | ||
|
|
||
| void TearDown() override | ||
| { | ||
| EXPECT_THAT(mr_.allocations, IsEmpty()); | ||
| EXPECT_THAT(mr_.total_allocated_bytes, mr_.total_deallocated_bytes); | ||
| } | ||
|
|
||
| // MARK: Data members: | ||
|
|
||
| // NOLINTBEGIN | ||
| libcyphal::VirtualTimeScheduler scheduler_{}; | ||
| TrackingMemoryResource mr_; | ||
| StrictMock<MediaMock> media_mock_{}; | ||
| // NOLINTEND | ||
| }; | ||
|
|
||
| // MARK: - Tests: | ||
|
|
||
| TEST_F(TestUpdTransportCustomConfigMilliseconds, makeTransport_getLocalNodeId) | ||
| { | ||
| std::array<IMedia*, 1> media_array{&media_mock_}; | ||
| auto maybe_transport = makeTransport({mr_}, scheduler_, media_array, 0); | ||
| ASSERT_THAT(maybe_transport, VariantWith<UniquePtr<IUdpTransport>>(NotNull())); | ||
|
|
||
| const auto transport = cetl::get<UniquePtr<IUdpTransport>>(std::move(maybe_transport)); | ||
| EXPECT_THAT(transport->getLocalNodeId(), Eq(cetl::nullopt)); | ||
| } | ||
|
|
||
| } // namespace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.