diff --git a/TESTS/netsocket/tcp/main.cpp b/TESTS/netsocket/tcp/main.cpp index 3988711f76..47fe7b155c 100644 --- a/TESTS/netsocket/tcp/main.cpp +++ b/TESTS/netsocket/tcp/main.cpp @@ -93,6 +93,7 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t Case cases[] = { Case("Echo burst", test_tcpsocket_echotest_burst), Case("Echo burst non-block", test_tcpsocket_echotest_burst_nonblock), + Case("Reuse a socket", test_tcpsocket_open_close_repeat), Case("Open at least 4 sockets", test_tcpsocket_open_limit), Case("Receive 100k from CHARGEN service", test_tcpsocket_recv_100k), Case("Receive 100k from CHARGEN service non-block", test_tcpsocket_recv_100k_nonblock), diff --git a/TESTS/netsocket/tcp/tcp_tests.h b/TESTS/netsocket/tcp/tcp_tests.h index a62f153141..cec6be6ee6 100644 --- a/TESTS/netsocket/tcp/tcp_tests.h +++ b/TESTS/netsocket/tcp/tcp_tests.h @@ -28,6 +28,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len); void test_tcpsocket_echotest_burst(); void test_tcpsocket_echotest_burst_nonblock(); void test_tcpsocket_endpoint_close(); +void test_tcpsocket_open_close_repeat(); void test_tcpsocket_open_limit(); void test_tcpsocket_recv_100k(); void test_tcpsocket_recv_100k_nonblock(); diff --git a/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp new file mode 100644 index 0000000000..9da8e5d11e --- /dev/null +++ b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "greentea-client/test_env.h" +#include "mbed.h" +#include MBED_CONF_APP_HEADER_FILE +#include "tcp_tests.h" +#include "TCPSocket.h" +#include "unity/unity.h" +#include "utest.h" + +void test_tcpsocket_open_close_repeat() +{ + TCPSocket *sock = new TCPSocket; + if (!sock) { + TEST_FAIL(); + } + + for (int i = 0; i < 2; i++) { + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); + } + delete sock; +} diff --git a/TESTS/netsocket/udp/main.cpp b/TESTS/netsocket/udp/main.cpp index 4d86c96fbd..0d61c53b89 100644 --- a/TESTS/netsocket/udp/main.cpp +++ b/TESTS/netsocket/udp/main.cpp @@ -80,6 +80,7 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t Case cases[] = { Case("Echo burst", test_udpsocket_echotest_burst), Case("Echo burst non-block", test_udpsocket_echotest_burst_nonblock), + Case("Reuse a socket", test_udpsocket_open_close_repeat), Case("Open at least 3 sockets", test_udpsocket_open_limit), Case("Receive in given time", test_udpsocket_recv_timeout), Case("Send in given time", test_udpsocket_sendto_timeout), diff --git a/TESTS/netsocket/udp/udp_tests.h b/TESTS/netsocket/udp/udp_tests.h index ba33fa41fc..3544442142 100644 --- a/TESTS/netsocket/udp/udp_tests.h +++ b/TESTS/netsocket/udp/udp_tests.h @@ -26,6 +26,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len); */ void test_udpsocket_echotest_burst(); void test_udpsocket_echotest_burst_nonblock(); +void test_udpsocket_open_close_repeat(); void test_udpsocket_open_limit(); void test_udpsocket_recv_timeout(); void test_udpsocket_sendto_timeout(); diff --git a/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp b/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp new file mode 100644 index 0000000000..0d81e46956 --- /dev/null +++ b/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "greentea-client/test_env.h" +#include "mbed.h" +#include MBED_CONF_APP_HEADER_FILE +#include "udp_tests.h" +#include "UDPSocket.h" +#include "unity/unity.h" +#include "utest.h" + +void test_udpsocket_open_close_repeat() +{ + UDPSocket *sock = new UDPSocket; + if (!sock) { + TEST_FAIL(); + } + + for (int i = 0; i < 2; i++) { + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface())); + TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); + } + delete sock; +}