Skip to content

TCP/TLS Socket tests will skip if TCP is not supported #10037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions TESTS/netsocket/tcp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
return tcpsocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT);
}

bool is_tcp_supported()
{
static bool supported;
static bool tested = false;
if (!tested) {
TCPSocket socket;
supported = socket.open(NetworkInterface::get_default_instance()) == NSAPI_ERROR_OK;
}
return supported;
}

void fill_tx_buffer_ascii(char *buff, size_t len)
{
for (size_t i = 0; i < len; ++i) {
Expand Down
6 changes: 6 additions & 0 deletions TESTS/netsocket/tcp/tcp_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ nsapi_version_t get_ip_version();
void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
bool is_tcp_supported();

#define SKIP_IF_TCP_UNSUPPORTED() \
if (!is_tcp_supported()) { \
TEST_SKIP_MESSAGE("TCP not supported"); \
}

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
extern mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_ADDRESS()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_ADDRESS_INVALID()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_address_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_ADDRESS_NULL()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_address_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_ADDRESS_PORT()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_PORT()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_PORT_FAIL()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_unopened.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_UNOPENED()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_BIND_WRONG_TYPE()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_connect_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_CONNECT_INVALID()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));

Expand Down
2 changes: 2 additions & 0 deletions TESTS/netsocket/tcp/tcpsocket_echotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void _sigio_handler(osThreadId id)

void TCPSOCKET_ECHOTEST()
{
SKIP_IF_TCP_UNSUPPORTED();
if (tcpsocket_connect_to_echo_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
return;
Expand Down Expand Up @@ -127,6 +128,7 @@ void tcpsocket_echotest_nonblock_receive()

void TCPSOCKET_ECHOTEST_NONBLOCK()
{
SKIP_IF_TCP_UNSUPPORTED();
tc_exec_time.start();
time_allotted = split2half_rmng_tcp_test_time(); // [s]

Expand Down
2 changes: 2 additions & 0 deletions TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static void _sigio_handler(osThreadId id)

void TCPSOCKET_ECHOTEST_BURST()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
tcpsocket_connect_to_echo_srv(sock);
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
Expand Down Expand Up @@ -92,6 +93,7 @@ void TCPSOCKET_ECHOTEST_BURST()

void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
tcpsocket_connect_to_echo_srv(sock);
sock.set_blocking(false);
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)

void TCPSOCKET_ENDPOINT_CLOSE()
{
SKIP_IF_TCP_UNSUPPORTED();
static const int MORE_THAN_AVAILABLE = 30;
char buff[MORE_THAN_AVAILABLE];
int time_allotted = split2half_rmng_tcp_test_time(); // [s]
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_OPEN_CLOSE_REPEAT()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_OPEN_DESTRUCT()
{
SKIP_IF_TCP_UNSUPPORTED();
for (int i = 0; i < 100; i++) {
TCPSocket *sock = new TCPSocket;
if (!sock) {
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_open_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct TCPSocketItem {

void TCPSOCKET_OPEN_LIMIT()
{
SKIP_IF_TCP_UNSUPPORTED();
int open_sockets[2] = {0};

for (int i = 0; i < 2; i++) {
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_open_twice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_OPEN_TWICE()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
2 changes: 2 additions & 0 deletions TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void rcv_n_chk_against_rfc864_pattern(TCPSocket &sock)

void TCPSOCKET_RECV_100K()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
if (_tcpsocket_connect_to_chargen_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
Expand Down Expand Up @@ -172,6 +173,7 @@ static void _sigio_handler(osThreadId id)

void TCPSOCKET_RECV_100K_NONBLOCK()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
nsapi_error_t err = _tcpsocket_connect_to_chargen_srv(sock);

Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void _sigio_handler(osThreadId id)

void TCPSOCKET_RECV_TIMEOUT()
{
SKIP_IF_TCP_UNSUPPORTED();
static const int DATA_LEN = 100;
char buff[DATA_LEN] = {0};
int time_allotted = split2half_rmng_tcp_test_time(); // [s]
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_send_repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_SEND_REPEAT()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
tcpsocket_connect_to_discard_srv(sock);

Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_send_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_SEND_TIMEOUT()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
if (tcpsocket_connect_to_discard_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace utest::v1;

void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID()
{
SKIP_IF_TCP_UNSUPPORTED();
TCPSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
int32_t seconds = 7200;
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static void check_var_len_rand_sequence()

void TCPSOCKET_THREAD_PER_SOCKET_SAFETY()
{
SKIP_IF_TCP_UNSUPPORTED();
thread.start(callback(check_const_len_rand_sequence));

check_var_len_rand_sequence();
Expand Down
11 changes: 11 additions & 0 deletions TESTS/netsocket/tls/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ nsapi_error_t tlssocket_connect_to_discard_srv(TLSSocket &sock)
return tlssocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS);
}

bool is_tcp_supported()
{
static bool supported;
static bool tested = false;
if (!tested) {
TCPSocket socket;
supported = socket.open(NetworkInterface::get_default_instance()) == NSAPI_ERROR_OK;
}
return supported;
}

void fill_tx_buffer_ascii(char *buff, size_t len)
{
for (size_t i = 0; i < len; ++i) {
Expand Down
6 changes: 6 additions & 0 deletions TESTS/netsocket/tls/tls_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ void drop_bad_packets(TLSSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tlssocket_connect_to_echo_srv(TLSSocket &sock);
nsapi_error_t tlssocket_connect_to_discard_srv(TLSSocket &sock);
bool is_tcp_supported();

#define SKIP_IF_TCP_UNSUPPORTED() \
if (!is_tcp_supported()) { \
TEST_SKIP_MESSAGE("TCP not supported"); \
}

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED
extern mbed_stats_socket_t tls_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_connect_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_CONNECT_INVALID()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
Expand Down
2 changes: 2 additions & 0 deletions TESTS/netsocket/tls/tlssocket_echotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void _sigio_handler(osThreadId id)

void TLSSOCKET_ECHOTEST()
{
SKIP_IF_TCP_UNSUPPORTED();
sock = new TLSSocket;
if (tlssocket_connect_to_echo_srv(*sock) != NSAPI_ERROR_OK) {
printf("Error from tlssocket_connect_to_echo_srv\n");
Expand Down Expand Up @@ -133,6 +134,7 @@ void tlssocket_echotest_nonblock_receive()

void TLSSOCKET_ECHOTEST_NONBLOCK()
{
SKIP_IF_TCP_UNSUPPORTED();
sock = new TLSSocket;
tc_exec_time.start();
time_allotted = split2half_rmng_tls_test_time(); // [s]
Expand Down
2 changes: 2 additions & 0 deletions TESTS/netsocket/tls/tlssocket_echotest_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static void _sigio_handler(osThreadId id)

void TLSSOCKET_ECHOTEST_BURST()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket *sock = new TLSSocket;
tlssocket_connect_to_echo_srv(*sock);
sock->sigio(callback(_sigio_handler, ThisThread::get_id()));
Expand Down Expand Up @@ -95,6 +96,7 @@ void TLSSOCKET_ECHOTEST_BURST()

void TLSSOCKET_ECHOTEST_BURST_NONBLOCK()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket *sock = new TLSSocket;
tlssocket_connect_to_echo_srv(*sock);
sock->set_blocking(false);
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_endpoint_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static nsapi_error_t _tlssocket_connect_to_daytime_srv(TLSSocket &sock)

void TLSSOCKET_ENDPOINT_CLOSE()
{
SKIP_IF_TCP_UNSUPPORTED();
static const int MORE_THAN_AVAILABLE = 30;
char buff[MORE_THAN_AVAILABLE];
int time_allotted = split2half_rmng_tls_test_time(); // [s]
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_handshake_invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_HANDSHAKE_INVALID()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_no_cert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_NO_CERT()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE,
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_open_destruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_OPEN_DESTRUCT()
{
SKIP_IF_TCP_UNSUPPORTED();
for (int i = 0; i < 100; i++) {
TLSSocket *sock = new TLSSocket;
if (!sock) {
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_open_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct TLSSocketItem {

void TLSSOCKET_OPEN_LIMIT()
{
SKIP_IF_TCP_UNSUPPORTED();
int open_sockets[2] = {0};

for (int i = 0; i < 2; i++) {
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_open_twice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_OPEN_TWICE()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket *sock = new TLSSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_recv_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static void _sigio_handler(osThreadId id)

void TLSSOCKET_RECV_TIMEOUT()
{
SKIP_IF_TCP_UNSUPPORTED();
static const int DATA_LEN = 100;
char buff[DATA_LEN] = {0};
int time_allotted = split2half_rmng_tls_test_time(); // [s]
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_send_closed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_SEND_CLOSED()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_send_repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_SEND_REPEAT()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
tlssocket_connect_to_discard_srv(sock);

Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_send_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_SEND_TIMEOUT()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
if (tlssocket_connect_to_discard_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_send_unconnected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_SEND_UNCONNECTED()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
Expand Down
1 change: 1 addition & 0 deletions TESTS/netsocket/tls/tlssocket_simultaneous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace utest::v1;

void TLSSOCKET_SIMULTANEOUS()
{
SKIP_IF_TCP_UNSUPPORTED();
TLSSocket sock1;
TLSSocket sock2;
tlssocket_connect_to_echo_srv(sock1);
Expand Down