From 6b4d2c8127ff58f133f94c610188886cf21e86ee Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 17 Sep 2025 17:05:49 -0400 Subject: [PATCH] tests: Add a test for #19755 to the SocketTests. --- .../system/network/posixnet/SocketTests.cpp | 27 +++++++++++++++++-- .../system/network/posixnet/SocketTests.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/tests/system/network/posixnet/SocketTests.cpp b/src/tests/system/network/posixnet/SocketTests.cpp index cdca9337b5..d3ff9d79d3 100644 --- a/src/tests/system/network/posixnet/SocketTests.cpp +++ b/src/tests/system/network/posixnet/SocketTests.cpp @@ -14,7 +14,8 @@ // This test reproduces a KDL from issue #13927 where a socket is created // and an attempt is made to connect to an address, which fails. The socket // is closed and then reused to connect to a *different* address. -void SocketTests::ClientSocketReuseTest() +void +SocketTests::ClientSocketReuseTest() { // TODO: Try to find unused ports instead of using these hard-coded ones. const uint16_t kFirstPort = 14025; @@ -49,12 +50,34 @@ void SocketTests::ClientSocketReuseTest() } -void SocketTests::AddTests(BTestSuite &parent) { +// This test reproduces a KDL from issue #19755. +void +SocketTests::TcpRecvmsgTest() +{ + // create a client socket + int fd = socket(AF_INET, SOCK_STREAM, 0); + CPPUNIT_ASSERT(fd >= 0); + + struct msghdr msg; + memset(&msg, 0, sizeof(msg)); + ssize_t r = recvmsg(fd, &msg, 0); + CPPUNIT_ASSERT(r == -1); + + close(fd); +} + + +void +SocketTests::AddTests(BTestSuite &parent) +{ CppUnit::TestSuite &suite = *new CppUnit::TestSuite("SocketTests"); suite.addTest(new CppUnit::TestCaller( "SocketTests::ClientSocketReuseTest", &SocketTests::ClientSocketReuseTest)); + suite.addTest(new CppUnit::TestCaller( + "SocketTests::TcpRecvmsgTest", + &SocketTests::TcpRecvmsgTest)); parent.addTest("SocketTests", &suite); } diff --git a/src/tests/system/network/posixnet/SocketTests.h b/src/tests/system/network/posixnet/SocketTests.h index 2dd3d835d4..19fbf55c55 100644 --- a/src/tests/system/network/posixnet/SocketTests.h +++ b/src/tests/system/network/posixnet/SocketTests.h @@ -7,6 +7,7 @@ class SocketTests : public BTestCase { public: void ClientSocketReuseTest(); + void TcpRecvmsgTest(); static void AddTests(BTestSuite& suite); };