-
Notifications
You must be signed in to change notification settings - Fork 3k
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 UDP socket test cases #12267
Fix UDP socket test cases #12267
Conversation
@AriParkkila, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clean up. I just have doubts if the extra branch is necessary or not... In case it is, can we use TEST_FAIL_MESSAGE()
so the reason for failure is visible without checking source code?
@@ -129,6 +129,8 @@ void NIDDSOCKET_ECHOTEST_NONBLOCK() | |||
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent); | |||
tr_info("Packets sent: %d, packets received %d, loss ratio %.2lf", packets_sent, packets_recv, loss_ratio); | |||
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the if (packets_sent > 0)
was here to avoid division by 0, not to detect that packets were sent or not. If they were not sent we would fail in line 117. So I think this is dead code.
Unless I am not seeing some failure mode, that in fact leads to this branch being a possible option?
@@ -267,6 +269,8 @@ void UDPSOCKET_ECHOTEST_NONBLOCK_impl(bool use_sendto) | |||
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); | |||
|
|||
#endif | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Will this ever trigger?
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); | ||
|
||
#endif | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no packets were sent then packets_sent
equals to 0, there is no extra check as in the two cases above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right for the multihoming case - this makes sense,
In the two other cases these lines will not allow the situation where packets_sent
is 0:
// Make sure that at least one packet of every size was sent.
TEST_ASSERT_TRUE(packets_sent > packets_sent_prev);
If no packets get sent, this assertion fails and we never reach the if (packets_sent > 0)
, so perhaps we could actually remove this check (although I believe it's left there in case someone modifies the code and forgets the division by 0 situation or for the static analysis?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalpasztamobica Fixed the two cases you mentioned, please review.
d6cb87b
to
8be36f8
Compare
@@ -146,6 +146,8 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto) | |||
double loss_ratio = 1 - ((double)packets_recv / (double)packets_sent); | |||
tr_info("Packets sent: %d, packets received %d, loss ratio %.2lf", packets_sent, packets_recv, loss_ratio); | |||
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); | |||
} else { | |||
TEST_FAIL(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AriParkkila Should this be here? Looks like the TEST_ASSERT_TRUE(packets_sent > packets_sent_prev);
is just above...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True not needed here, fixed.
8be36f8
to
d1a72b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you amend the info you provided in the first comment about the fix (plus from discussion with @michalpasztamobica about else conditions). It would be helpful.
Otherwise LGTM
Fix UDP socket test cases to check more strictly on failure, and lower trace levels to not print errors on successful cases.
d1a72b6
to
031d90a
Compare
@0xc0170 Commit message updated. Should be ready for merge now. |
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
@@ -84,7 +84,7 @@ void MULTIHOMING_UDPSOCKET_ECHOTEST() | |||
packets_sent++; | |||
} | |||
if (sent != pkt_s) { | |||
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent); | |||
tr_warn("[Round#%02d - Sender] error, returned %d\n", s_idx, sent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi all
Seems #define TRACE_GROUP "GRNT" is missing here ?
[Error] multihoming_udpsocket_echotest.cpp@87,25: use of undeclared identifier 'TRACE_GROUP'
[Error] multihoming_udpsocket_echotest.cpp@102,17: use of undeclared identifier 'TRACE_GROUP'
[Error] multihoming_udpsocket_echotest.cpp@182,25: use of undeclared identifier 'TRACE_GROUP'
[Error] multihoming_udpsocket_echotest.cpp@201,17: use of undeclared identifier 'TRACE_GROUP'
Summary of changes
Fix UDP socket test cases to check more strictly on failure, and lower trace levels to not print errors on successful cases.
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers