Skip to content
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

[20976] Handle errors when setting socket buffer sizes #4760

Merged
merged 26 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c3330f9
Refs #20972. Method socket_buffer_size in DDS_PIM helpers sets also s…
MiguelCompany May 8, 2024
98b4386
Refs #20972. Improvements in on_sample_lost blackbox tests.
MiguelCompany May 8, 2024
ead1b12
Refs #20972. Move code into new private methods.
MiguelCompany May 8, 2024
0286875
Refs #20972. Refactor on configure_send_buffer_size.
MiguelCompany May 8, 2024
b49b916
Refs #20972. Refactor on configure_receive_buffer_size.
MiguelCompany May 8, 2024
7648c69
Refs #20972. Check user configuration at the beginning of init method.
MiguelCompany May 8, 2024
f87a2cb
Refs #20972. Use maxMessageSize as minimum possible value.
MiguelCompany May 8, 2024
7862ca5
Refs #20972. Applying changes on OpenAndBindUnicastOutputSocket.
MiguelCompany May 8, 2024
d0e9cab
Refs #20972. Add helper header with template method.
MiguelCompany May 9, 2024
72ba395
Refs #20972. Configure methods return boolean.
MiguelCompany May 9, 2024
32e1891
Refs #20972. Configure methods use new template method.
MiguelCompany May 9, 2024
ebd62f2
Refs #20972. OpenAndBindUnicastOutputSocket uses new template method.
MiguelCompany May 9, 2024
ea9ce1f
Refs #20972. Changes in OpenAndBindInputSocket.
MiguelCompany May 9, 2024
930a243
Refs #20972.Setting options on TCP channels.
MiguelCompany May 9, 2024
07aa0c6
Refs #20972. Doxygen.
MiguelCompany May 9, 2024
4f56778
Refs #20972. Check limits of configured sizes.
MiguelCompany May 9, 2024
40f6264
Refs #20972. Add UDP unit tests.
MiguelCompany May 9, 2024
36c8d20
Refs #20972. Add TCP unit tests.
MiguelCompany May 10, 2024
e89db93
Refs #20972. Move checks in TCP to beginning of init.
MiguelCompany May 10, 2024
1769956
Refs #20972. Refactor for common code in UDP.
MiguelCompany May 10, 2024
f683035
Refs #20972. Refactor for common code in TCP.
MiguelCompany May 13, 2024
fd5bb8f
Refs #20972. Remove unused constants in UDP tests.
MiguelCompany May 13, 2024
c3b2a67
Refs #20972. Remove unused constant `s_minimumSocketBuffer`.
MiguelCompany May 13, 2024
27a04e9
Refs #20972. Check final configuration on unit tests.
MiguelCompany May 13, 2024
c0a0f63
Refs #20972. Uncrustify.
MiguelCompany May 14, 2024
6d94732
Refs #20972. Less strict tests.
MiguelCompany May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refs #20972. Add UDP unit tests.
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed May 16, 2024
commit 40f62645386d8a0c57546ed6d32c6f58fa0ebe7a
63 changes: 63 additions & 0 deletions test/unittest/transport/UDPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
#include <memory>
#include <thread>

#include <asio.hpp>
#include <gtest/gtest.h>

#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include <fastdds/utils/IPFinder.h>
#include <fastdds/utils/IPLocator.h>
Expand Down Expand Up @@ -79,6 +81,67 @@ class UDPv4Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(UDPv4Tests, wrong_configuration)
{
// Too big sendBufferSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big receiveBufferSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.receiveBufferSize = std::numeric_limits<uint32_t>::max();
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big maxMessageSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = std::numeric_limits<uint32_t>::max();
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than receiveBufferSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.receiveBufferSize = 5;
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than sendBufferSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.sendBufferSize = 5;
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Buffer sizes automatically decrease
EduPonz marked this conversation as resolved.
Show resolved Hide resolved
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.maxMessageSize = 1470;
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}
}

TEST_F(UDPv4Tests, locators_with_kind_1_supported)
{
// Given
Expand Down
62 changes: 62 additions & 0 deletions test/unittest/transport/UDPv6Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
#include <memory>
#include <thread>

Expand Down Expand Up @@ -87,6 +88,67 @@ class UDPv6Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(UDPv6Tests, wrong_configuration)
{
// Too big sendBufferSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big receiveBufferSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.receiveBufferSize = std::numeric_limits<uint32_t>::max();
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big maxMessageSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = std::numeric_limits<uint32_t>::max();
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than receiveBufferSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.receiveBufferSize = 5;
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than sendBufferSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.sendBufferSize = 5;
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Buffer sizes automatically decrease
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.maxMessageSize = 1470;
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}
}

TEST_F(UDPv6Tests, conversion_to_ip6_string)
{
Locator_t locator;
Expand Down