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

Fix warnings in tcp/udp UT #2744

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

JohanBertrand
Copy link
Contributor

@JohanBertrand JohanBertrand commented May 23, 2024

Related Issue(s) #2706
Has Unit Tests (y/n)
Documentation Included (y/n)

Change Description

I am not sure we want to have those changes in the codebase. That could be used as a baseline for a better update.

Most of the warnings in the UT with TCP/UDP module should be fixed with those changes. A mutex is making sure that the receive/open/startup functions are called only if the stop/close function are not going to be called in an other thread.

I added the changes in the unit tests instead of the class itself (in open/close), because I did not find a way to make it work properly.

I also needed to make recv to stop iterating if errno == EAGAIN to avoid a timeout. I'm not sure if that's the proper way to fix this issue.

The only warning still happening for me, after 10.000 tests, is the following (happened only once):

[ RUN      ] Reconnect.ReceiveThreadReconnect
Listening for single client at 127.0.0.1:32769
Connected to 127.0.0.1:32769 as a tcp client
Accepted client at 127.0.0.1:32769
Connected to 127.0.0.1:32769 as a tcp client
Accepted client at 127.0.0.1:32769
Connected to 127.0.0.1:32769 as a tcp client
Accepted client at 127.0.0.1:32769
Accepted client at 127.0.0.1:32769
[WARNING] Failed to recv from port with status -8 and errno 0

I feel like the warnings in the test should make the UT to fail. However, I am not sure how to catch the warning streamed through Fw::Logger::logMsg.

Also fix an error in StringUtils.cpp when compiled on ubuntu20.04 with a FW_ASSERT:

/home/fprime/Fw/Types/StringUtils.cpp:51:40: error: comparison of integer expressions of different signedness: ‘FwSizeType’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
   51 |     FW_ASSERT((source_size - sub_size) <= std::numeric_limits<FwSignedSizeType>::max());

Fw/Types/StringUtils.cpp Outdated Show resolved Hide resolved
Drv/Ip/IpSocket.cpp Show resolved Hide resolved
@@ -72,13 +72,15 @@ void SocketReadTask::readTask(void* pointer) {
SocketIpStatus status = SOCK_SUCCESS;
SocketReadTask* self = reinterpret_cast<SocketReadTask*>(pointer);
do {
self->m_task_lock.lock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense!

if (recv_thread) {
//this->component.close();
if ((1 + i) == iterations) {
this->component.m_task_lock.lock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These locks should be done in the shutdown and close methods, not just the UT.

Copy link
Contributor Author

@JohanBertrand JohanBertrand Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the mutex in the close/shutdown functions. I had to update the TcpServerTester.cpp a bit for it to work: the client needs to be closed after the server is closed. I do not have the explanation for this behavior, but otherwise I was getting the following warning:

Connected to 127.0.0.1:57755 as a tcp client
Accepted client at 127.0.0.1:57755
[WARNING] Failed to recv from port with status -8 and errno 0

There was a comment stating: // Client must be closed first or the server risks binding to an existing address. Let me know if it is a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added the muted on the stop function. Can you confirm that it is something that is expected?

@JohanBertrand
Copy link
Contributor Author

@LeStarch is there something we can do in the UT to check that no warnings are logged using Fw::Logger::logMsg, and cause the UT to fail if it contains warnings?

During my tests, I used that warning messages to realize that something was wrong.

I also used a timeout to make sure that the tests were not taking too long. It was especially useful for checking that the TcpServer tests were working properly. The test could take a few seconds on failure, where it's supposed to be less than 500ms in nominal conditions on my hardware. However, I don't think that's something that can/should be implemented, since it's hardware dependent.

// Properly stop the client on the last iteration
if ((1 + i) == iterations && recv_thread) {
this->component.shutdown();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeStarch Can you confirm that we do not need this shutdown, since it's already part of the stop function?

Keeping it is causing a timeout on my setup (the UT tasking more than 1s)

@JohanBertrand
Copy link
Contributor Author

@LeStarch @thomas-bc Let me know if there is something else to change in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants