Skip to content

Commit f1a8eec

Browse files
authored
Merge pull request #11289 from michalpasztamobica/unity_replace_macro
Replace TEST_ASSERT_INT_WITHIN usage in netsocket tests
2 parents b786e68 + 05e94af commit f1a8eec

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ void TCPSOCKET_RECV_TIMEOUT()
6767
TEST_FAIL();
6868
goto CLEANUP;
6969
}
70-
printf("MBED: recv() took: %dus\n", timer.read_us());
71-
TEST_ASSERT_INT_WITHIN(51, 150, (timer.read_us() + 500) / 1000);
70+
int recv_time_ms = (timer.read_us() + 500) / 1000;
71+
printf("MBED: recv() took: %dus\n", recv_time_ms);
72+
if (recv_time_ms > 150) {
73+
TEST_ASSERT(150 - recv_time_ms < 51);
74+
} else {
75+
TEST_ASSERT(recv_time_ms - 150 < 51);
76+
}
7277
continue;
7378
} else if (recvd < 0) {
7479
printf("[pkt#%02d] network error %d\n", i, recvd);

TESTS/netsocket/udp/udpsocket_echotest_burst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void UDPSOCKET_ECHOTEST_BURST()
146146
// Packet loss up to 30% tolerated
147147
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
148148
// 70% of the bursts need to be successful
149-
TEST_ASSERT_INT_WITHIN(3 * (BURST_CNT / 10), BURST_CNT, ok_bursts);
149+
TEST_ASSERT(BURST_CNT - ok_bursts < 3 * (BURST_CNT / 10));
150150

151151
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
152152
}
@@ -229,7 +229,7 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
229229
// Packet loss up to 30% tolerated
230230
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
231231
// 70% of the bursts need to be successful
232-
TEST_ASSERT_INT_WITHIN(3 * (BURST_CNT / 10), BURST_CNT, ok_bursts);
232+
TEST_ASSERT(BURST_CNT - ok_bursts < 3 * (BURST_CNT / 10));
233233

234234
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
235235
}

TESTS/netsocket/udp/udpsocket_recv_timeout.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ void UDPSOCKET_RECV_TIMEOUT()
6363
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
6464
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT);
6565
printf("MBED: recvfrom() took: %dms\n", timer.read_ms());
66-
TEST_ASSERT_INT_WITHIN(51, 150, timer.read_ms());
66+
if (timer.read_ms() > 150) {
67+
TEST_ASSERT(150 - timer.read_ms() < 51);
68+
} else {
69+
TEST_ASSERT(timer.read_ms() - 150 < 51);
70+
}
6771
continue;
6872
} else if (recvd < 0) {
6973
printf("[bt#%02d] network error %d\n", i, recvd);

0 commit comments

Comments
 (0)