Skip to content

Commit c86bf1a

Browse files
Veijo PesonenSeppo Takalo
authored andcommitted
Adds more TCP and UDP test cases
Adds TCP and UDP test cases tcpsocket_open_limit udpsocket_open_limit
1 parent 8e81d01 commit c86bf1a

File tree

6 files changed

+181
-0
lines changed

6 files changed

+181
-0
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t
9393
Case cases[] = {
9494
Case("Echo burst", test_tcpsocket_echotest_burst),
9595
Case("Echo burst non-block", test_tcpsocket_echotest_burst_nonblock),
96+
Case("Open at least 4 sockets", test_tcpsocket_open_limit),
9697
Case("Receive 100k from CHARGEN service", test_tcpsocket_recv_100k),
9798
Case("Receive 100k from CHARGEN service non-block", test_tcpsocket_recv_100k_nonblock),
9899
Case("Receive in given time", test_tcpsocket_recv_timeout),

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
2828
void test_tcpsocket_echotest_burst();
2929
void test_tcpsocket_echotest_burst_nonblock();
3030
void test_tcpsocket_endpoint_close();
31+
void test_tcpsocket_open_limit();
3132
void test_tcpsocket_recv_100k();
3233
void test_tcpsocket_recv_100k_nonblock();
3334
void test_tcpsocket_recv_timeout();
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "greentea-client/test_env.h"
19+
#include "mbed.h"
20+
#include MBED_CONF_APP_HEADER_FILE
21+
#include "tcp_tests.h"
22+
#include "TCPSocket.h"
23+
#include "unity/unity.h"
24+
#include "utest.h"
25+
26+
using namespace utest::v1;
27+
28+
namespace
29+
{
30+
typedef struct TCPSocketItem {
31+
TCPSocket *sock;
32+
TCPSocketItem *next;
33+
} SocketItem;
34+
}
35+
36+
void test_tcpsocket_open_limit()
37+
{
38+
int open_sockets[2] = {0};
39+
40+
for (int i = 0; i < 2; i++) {
41+
TCPSocketItem *socket_list_head = NULL;
42+
TCPSocketItem *it;
43+
44+
TCPSocket *sock;
45+
int ret;
46+
while (true) {
47+
sock = new TCPSocket;
48+
if (!sock) {
49+
break;
50+
}
51+
ret = sock->open(get_interface());
52+
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
53+
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
54+
delete sock;
55+
break;
56+
}
57+
58+
// Hopefully this doesn't interfere when trying to allocate more sockets
59+
it = new TCPSocketItem;
60+
if (!it) {
61+
delete sock;
62+
break;
63+
}
64+
65+
it->sock = sock;
66+
// Order of items in the list doesn't matter
67+
it->next = socket_list_head;
68+
socket_list_head = it;
69+
}
70+
71+
if (!socket_list_head) {
72+
break;
73+
}
74+
75+
TCPSocketItem *tmp;
76+
for(TCPSocketItem *it = socket_list_head; it;) {
77+
++open_sockets[i];
78+
tmp = it;
79+
it = it->next;
80+
socket_list_head = it;
81+
delete tmp->sock;
82+
delete tmp;
83+
}
84+
printf("[round#%02d] %d sockets opened\n", i, open_sockets[i]);
85+
}
86+
TEST_ASSERT_EQUAL(open_sockets[0], open_sockets[1]);
87+
TEST_ASSERT(open_sockets[0] >= 4);
88+
}

TESTS/netsocket/udp/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t
8080
Case cases[] = {
8181
Case("Echo burst", test_udpsocket_echotest_burst),
8282
Case("Echo burst non-block", test_udpsocket_echotest_burst_nonblock),
83+
Case("Open at least 3 sockets", test_udpsocket_open_limit),
8384
Case("Receive in given time", test_udpsocket_recv_timeout),
8485
Case("Send in given time", test_udpsocket_sendto_timeout),
8586

TESTS/netsocket/udp/udp_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
2626
*/
2727
void test_udpsocket_echotest_burst();
2828
void test_udpsocket_echotest_burst_nonblock();
29+
void test_udpsocket_open_limit();
2930
void test_udpsocket_recv_timeout();
3031
void test_udpsocket_sendto_timeout();
3132

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "greentea-client/test_env.h"
19+
#include "mbed.h"
20+
#include MBED_CONF_APP_HEADER_FILE
21+
#include "udp_tests.h"
22+
#include "UDPSocket.h"
23+
#include "unity/unity.h"
24+
#include "utest.h"
25+
26+
using namespace utest::v1;
27+
28+
namespace
29+
{
30+
typedef struct UDPSocketItem {
31+
UDPSocket *sock;
32+
UDPSocketItem *next;
33+
} SocketItem;
34+
}
35+
36+
void test_udpsocket_open_limit()
37+
{
38+
int open_sockets[2] = {0};
39+
40+
for (int i = 0; i < 2; i++) {
41+
UDPSocketItem *socket_list_head = NULL;
42+
UDPSocketItem *it;
43+
44+
UDPSocket *sock;
45+
int ret;
46+
while (true) {
47+
sock = new UDPSocket;
48+
if (!sock) {
49+
break;
50+
}
51+
ret = sock->open(get_interface());
52+
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
53+
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
54+
delete sock;
55+
break;
56+
}
57+
58+
// Hopefully this doesn't interfere when trying to allocate more sockets
59+
it = new UDPSocketItem;
60+
if (!it) {
61+
delete sock;
62+
break;
63+
}
64+
65+
it->sock = sock;
66+
// Order of items in the list doesn't matter
67+
it->next = socket_list_head;
68+
socket_list_head = it;
69+
}
70+
71+
if (!socket_list_head) {
72+
break;
73+
}
74+
75+
UDPSocketItem *tmp;
76+
for(UDPSocketItem *it = socket_list_head; it;) {
77+
++open_sockets[i];
78+
tmp = it;
79+
it = it->next;
80+
socket_list_head = it;
81+
delete tmp->sock;
82+
delete tmp;
83+
}
84+
printf("[round#%02d] %d sockets opened\n", i, open_sockets[i]);
85+
}
86+
TEST_ASSERT_EQUAL(open_sockets[0], open_sockets[1]);
87+
// In case of lwIP one is taken by DHCP -> reduction by one to three
88+
TEST_ASSERT(open_sockets[0] >= 3);
89+
}

0 commit comments

Comments
 (0)