Skip to content

Commit c48312d

Browse files
Missing socket greentea tests implementation
1 parent 211c662 commit c48312d

25 files changed

+1120
-0
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ Case cases[] = {
153153
Case("TCPSOCKET_CONNECT_INVALID", TCPSOCKET_CONNECT_INVALID),
154154
Case("TCPSOCKET_ECHOTEST_BURST", TCPSOCKET_ECHOTEST_BURST),
155155
Case("TCPSOCKET_ECHOTEST_BURST_NONBLOCK", TCPSOCKET_ECHOTEST_BURST_NONBLOCK),
156+
Case("TCPSOCKET_OPEN_DESTRUCT", TCPSOCKET_OPEN_DESTRUCT),
157+
Case("TCPSOCKET_OPEN_TWICE", TCPSOCKET_OPEN_TWICE),
158+
Case("TCPSOCKET_BIND_PORT", TCPSOCKET_BIND_PORT),
159+
Case("TCPSOCKET_BIND_PORT_FAIL", TCPSOCKET_BIND_PORT_FAIL),
160+
Case("TCPSOCKET_BIND_ADDRESS_PORT", TCPSOCKET_BIND_ADDRESS_PORT),
161+
Case("TCPSOCKET_BIND_ADDRESS_NULL", TCPSOCKET_BIND_ADDRESS_NULL),
162+
Case("TCPSOCKET_BIND_ADDRESS_INVALID", TCPSOCKET_BIND_ADDRESS_INVALID),
163+
Case("TCPSOCKET_BIND_ADDRESS", TCPSOCKET_BIND_ADDRESS),
164+
Case("TCPSOCKET_BIND_WRONG_TYPE", TCPSOCKET_BIND_WRONG_TYPE),
165+
Case("TCPSOCKET_BIND_UNOPENED", TCPSOCKET_BIND_UNOPENED),
166+
Case("TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID", TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID)
156167
Case("TCPSOCKET_RECV_100K", TCPSOCKET_RECV_100K),
157168
Case("TCPSOCKET_RECV_100K_NONBLOCK", TCPSOCKET_RECV_100K_NONBLOCK),
158169
Case("TCPSOCKET_RECV_TIMEOUT", TCPSOCKET_RECV_TIMEOUT),

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,24 @@ void TCPSOCKET_ECHOTEST_NONBLOCK();
5454
void TCPSOCKET_ECHOTEST_BURST();
5555
void TCPSOCKET_ECHOTEST_BURST_NONBLOCK();
5656
void TCPSOCKET_ENDPOINT_CLOSE();
57+
void TCPSOCKET_OPEN_DESTRUCT();
5758
void TCPSOCKET_OPEN_CLOSE_REPEAT();
5859
void TCPSOCKET_OPEN_LIMIT();
60+
void TCPSOCKET_OPEN_TWICE();
61+
void TCPSOCKET_BIND_PORT();
62+
void TCPSOCKET_BIND_PORT_FAIL();
63+
void TCPSOCKET_BIND_ADDRESS_PORT();
64+
void TCPSOCKET_BIND_ADDRESS_NULL();
65+
void TCPSOCKET_BIND_ADDRESS_INVALID();
66+
void TCPSOCKET_BIND_ADDRESS();
67+
void TCPSOCKET_BIND_WRONG_TYPE();
68+
void TCPSOCKET_BIND_UNOPENED();
5969
void TCPSOCKET_RECV_100K();
6070
void TCPSOCKET_RECV_100K_NONBLOCK();
6171
void TCPSOCKET_RECV_TIMEOUT();
6272
void TCPSOCKET_SEND_REPEAT();
6373
void TCPSOCKET_SEND_TIMEOUT();
6474
void TCPSOCKET_THREAD_PER_SOCKET_SAFETY();
75+
void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID();
6576

6677
#endif //TCP_TESTS_H
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_ADDRESS()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
42+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(sockAddr));
43+
44+
delete sock;
45+
46+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
47+
count = fetch_stats();
48+
for (int j = 0; j < count; j++) {
49+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
50+
}
51+
#endif
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_ADDRESS_INVALID()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->bind("190.2.3.4", 1024));
42+
43+
delete sock;
44+
45+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
46+
count = fetch_stats();
47+
for (int j = 0; j < count; j++) {
48+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
49+
}
50+
#endif
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_ADDRESS_NULL()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(NULL, 1024));
42+
43+
delete sock;
44+
45+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
46+
count = fetch_stats();
47+
for (int j = 0; j < count; j++) {
48+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
49+
}
50+
#endif
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_ADDRESS_PORT()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(get_interface()->get_ip_address(), 80));
42+
43+
delete sock;
44+
45+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
46+
count = fetch_stats();
47+
for (int j = 0; j < count; j++) {
48+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
49+
}
50+
#endif
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_PORT()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(1024));
42+
43+
delete sock;
44+
45+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
46+
count = fetch_stats();
47+
for (int j = 0; j < count; j++) {
48+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
49+
}
50+
#endif
51+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 "tcp_tests.h"
21+
#include "TCPSocket.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
25+
using namespace utest::v1;
26+
27+
void TCPSOCKET_BIND_PORT_FAIL()
28+
{
29+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
30+
int count = fetch_stats();
31+
for (int j = 0; j < count; j++) {
32+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
33+
}
34+
#endif
35+
36+
TCPSocket *sock = new TCPSocket;
37+
if (!sock) {
38+
TEST_FAIL();
39+
}
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
41+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(1024));
42+
43+
TCPSocket *sock2 = new TCPSocket;
44+
if (!sock2) {
45+
TEST_FAIL();
46+
}
47+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_interface()));
48+
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
49+
50+
delete sock;
51+
delete sock2;
52+
53+
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
54+
count = fetch_stats();
55+
for (int j = 0; j < count; j++) {
56+
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
57+
}
58+
#endif
59+
}

0 commit comments

Comments
 (0)