Skip to content

Commit 56dfd02

Browse files
committed
Correct test udp_dtls_handshake
A call to `UDPSocket::recvfrom(SocketAddress *address, void *data, nsapi_size_t size)` returns, following the mbed documentation, the number of received bytes on success, and a negative error code on failure. So in case of success, the return value depends on both the value of parameter `size` but also on the amount of data already available. This means, that the value returned can be lower than or equal to the `size` of the `data` buffer passed as argument to the call. Therefore, in the case of `test_udp_dtls_handshake()`, the call to `sock.recvfrom()` might return up to `sizeof(buffer)` (i.e. 512) bytes, while the test expects that exactly `udp_dtls_handshake_pattern[step]` bytes are being received by this call. This commit applies a *workaround* to this situation by specifying `udp_dtls_handshake_pattern[step]` as the `size` of the `data` buffer in the call to `sock.recvfrom()`, which inhibits that a too big amount of bytes gets received by this call. This is just a *workaround* as it is still possible that the call to `sock.recvfrom()` might return less than the number of bytes expected by the test.
1 parent 70e7b40 commit 56dfd02

File tree

1 file changed

+1
-1
lines changed
  • TESTS/netsocket/udp_dtls_handshake

1 file changed

+1
-1
lines changed

TESTS/netsocket/udp_dtls_handshake/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void test_udp_dtls_handshake() {
108108

109109
int step = 0;
110110
while (step < udp_dtls_handshake_count) {
111-
err = sock.recvfrom(NULL, buffer, sizeof(buffer));
111+
err = sock.recvfrom(NULL, buffer, udp_dtls_handshake_pattern[step]);
112112
printf("UDP: rx <- %d ", err);
113113

114114
// check length

0 commit comments

Comments
 (0)