Skip to content
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
4 changes: 2 additions & 2 deletions TESTS/netsocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Call `Socket::open()` and then destruct the socket
1. Create a object by calling `new Socket()`
2. Call `Socket::open(stack)`
3. Call "delete" for the object
4. Repeat 1000 times.
4. Repeat 100 times.

**Expected result:**

Expand Down Expand Up @@ -1027,7 +1027,7 @@ Repeatedly send small packets.

1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 9);`
2. Call `TCPSocket::send("hello", 5);`
3. repeat 1000 times
3. repeat 100 times
4. destroy the socket

**Expected result:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int result_exp_timeout;
void ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT()
{

for (int i = 0; i < 100; i++) {
for (int i = 0; i < 10; i++) {
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem,
&result_dns_failure, &result_exp_timeout);

Expand Down
16 changes: 14 additions & 2 deletions TESTS/netsocket/dns/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,26 @@ static void net_bringup()
printf("MBED: IP address is '%s'\n", net->get_ip_address());
}

static void net_bringdown()
{
NetworkInterface::get_default_instance()->disconnect();
printf("MBED: ifdown\n");
}

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(200, "default_auto");
GREENTEA_SETUP(10 * 60, "default_auto");
net_bringup();
return verbose_test_setup_handler(number_of_cases);
}

void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
{
net_bringdown();
return greentea_test_teardown_handler(passed, failed, failure);
}

Case cases[] = {
Case("ASYNCHRONOUS_DNS", ASYNCHRONOUS_DNS),
Case("ASYNCHRONOUS_DNS_SIMULTANEOUS", ASYNCHRONOUS_DNS_SIMULTANEOUS),
Expand All @@ -181,7 +193,7 @@ Case cases[] = {
Case("SYNCHRONOUS_DNS_INVALID", SYNCHRONOUS_DNS_INVALID),
};

Specification specification(test_setup, cases, greentea_continue_handlers);
Specification specification(test_setup, cases, greentea_teardown, greentea_continue_handlers);

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tcp/tcp_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int fetch_stats(void);
int split2half_rmng_tcp_test_time(); // [s]

namespace tcp_global {
static const int TESTS_TIMEOUT = 480;
static const int TESTS_TIMEOUT = (10 * 60);
static const int TCP_OS_STACK_SIZE = 2048;

static const int RX_BUFF_SIZE = 1220;
Expand Down
41 changes: 22 additions & 19 deletions TESTS/netsocket/tcp/tcpsocket_echotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,32 @@ void TCPSOCKET_ECHOTEST()

void tcpsocket_echotest_nonblock_receive()
{
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) {
while (bytes2recv > 0) {
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) {
TEST_FAIL();
receive_error = true;
tx_sem.release();
return;
}
continue;
} else if (recvd < 0) {
TEST_FAIL();
receive_error = true;
tx_sem.release();
return;
}
return;
} else if (recvd < 0) {
receive_error = true;
} else {
bytes2recv -= recvd;
}

if (bytes2recv == 0) {
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));

static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
tx_sem.release();
} else if (receive_error || bytes2recv < 0) {
TEST_FAIL();
tx_sem.release();
bytes2recv -= recvd;
if (!bytes2recv) {
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
tx_sem.release();
break;
}
}
// else - no error, not all bytes were received yet.
}

void TCPSOCKET_ECHOTEST_NONBLOCK()
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]

static const int BURST_CNT = 100;
static const int BURST_CNT = 20;
static const int BURST_SIZE = 1220;
}

Expand Down
18 changes: 18 additions & 0 deletions TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@

using namespace utest::v1;

namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
}

static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}

static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
{
SocketAddress tcp_addr;
Expand Down Expand Up @@ -52,6 +62,7 @@ void TCPSOCKET_ENDPOINT_CLOSE()
TEST_FAIL();
return;
}
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));

int recvd = 0;
int recvd_total = 0;
Expand All @@ -62,6 +73,13 @@ void TCPSOCKET_ENDPOINT_CLOSE()
} else if (recvd <= 0) {
TEST_ASSERT_EQUAL(0, recvd);
break;
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
break;
}
continue;
}
recvd_total += recvd;
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TCPSOCKET_OPEN_DESTRUCT()
}
#endif

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
TCPSocket *sock = new TCPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tcp/tcpsocket_send_repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void TCPSOCKET_SEND_REPEAT()
int snd;
Timer timer;
static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
snd = sock.send(tx_buffer, sizeof(tx_buffer));
if (snd != sizeof(tx_buffer)) {
TEST_FAIL();
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 @@ -44,6 +44,7 @@ void TCPSOCKET_SEND_TIMEOUT()
(timer.read_ms() <= 800)) {
continue;
}
printf("send: err %d, time %d", err, timer.read_ms());
TEST_FAIL();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tls/tls_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int fetch_stats(void);
int split2half_rmng_tls_test_time(); // [s]

namespace tls_global {
static const int TESTS_TIMEOUT = 480;
static const int TESTS_TIMEOUT = (10 * 60);
static const int TLS_OS_STACK_SIZE = 2048;

static const int RX_BUFF_SIZE = 1220;
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tls/tlssocket_echotest_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]

static const int BURST_CNT = 100;
static const int BURST_CNT = 20;
static const int BURST_SIZE = 1220;
}

Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tls/tlssocket_open_destruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void TLSSOCKET_OPEN_DESTRUCT()
}
#endif

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
TLSSocket *sock = new TLSSocket;
if (!sock) {
TEST_FAIL();
Expand Down
1 change: 0 additions & 1 deletion TESTS/netsocket/tls/tlssocket_recv_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void TLSSOCKET_RECV_TIMEOUT()
goto CLEANUP;
}
printf("MBED: recv() took: %dus\n", timer.read_us());
TEST_ASSERT_INT_WITHIN(51, 150, (timer.read_us() + 500) / 1000);
continue;
} else if (recvd < 0) {
printf("[pkt#%02d] network error %d\n", i, recvd);
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/tls/tlssocket_send_repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TLSSOCKET_SEND_REPEAT()
int snd;
Timer timer;
static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
snd = sock.send(tx_buffer, sizeof(tx_buffer));
if (snd != sizeof(tx_buffer)) {
TEST_FAIL();
Expand Down
15 changes: 9 additions & 6 deletions TESTS/netsocket/udp/udpsocket_echotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "mbed.h"
#include "UDPSocket.h"
#include "EventFlags.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
Expand All @@ -25,7 +26,8 @@
using namespace utest::v1;

namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO_RX = 0x1;
static const int SIGNAL_SIGIO_TX = 0x2;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int WAIT2RECV_TIMEOUT = 1000; //[ms]
static const int RETRIES = 2;
Expand All @@ -35,6 +37,7 @@ static const double TOLERATED_LOSS_RATIO = 0.3;

UDPSocket sock;
Semaphore tx_sem(0, 1);
EventFlags signals;

static const int BUFF_SIZE = 1200;
char rx_buffer[BUFF_SIZE] = {0};
Expand All @@ -49,9 +52,9 @@ Timer tc_exec_time;
int time_allotted;
}

static void _sigio_handler(osThreadId id)
static void _sigio_handler()
{
osSignalSet(id, SIGNAL_SIGIO);
signals.set(SIGNAL_SIGIO_RX | SIGNAL_SIGIO_TX);
}

void UDPSOCKET_ECHOTEST()
Expand Down Expand Up @@ -111,7 +114,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
if (tc_exec_time.read() >= time_allotted) {
break;
}
wait_ms(WAIT2RECV_TIMEOUT);
signals.wait_all(SIGNAL_SIGIO_RX, WAIT2RECV_TIMEOUT);
--retry_cnt;
continue;
} else if (recvd < 0) {
Expand Down Expand Up @@ -146,7 +149,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()

TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
sock.set_blocking(false);
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
sock.sigio(callback(_sigio_handler));

int sent;
int s_idx = 0;
Expand Down Expand Up @@ -174,7 +177,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
}
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
osSignalWait(SIGNAL_SIGIO_TX, SIGIO_TIMEOUT).status == osEventTimeout) {
continue;
}
--retry_cnt;
Expand Down
11 changes: 8 additions & 3 deletions TESTS/netsocket/udp/udpsocket_echotest_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int RECV_TIMEOUT = 1; //[s]

static const int BURST_CNT = 100;
static const int BURST_CNT = 20;
static const int BURST_PKTS = 5;
static const int PKG_SIZES[BURST_PKTS] = {100, 200, 300, 120, 500};
static const int RECV_TOTAL = 1220;
Expand Down Expand Up @@ -130,7 +130,7 @@ void UDPSOCKET_ECHOTEST_BURST()
ok_bursts++;
} else {
drop_bad_packets(sock, TIMEOUT);
printf("[%02d] burst failure\n", i);
printf("[%02d] burst failure, rcv %d\n", i, bt_total);
}
}

Expand Down Expand Up @@ -168,7 +168,12 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
int bt_total = 0;
for (int i = 0; i < BURST_CNT; i++) {
for (int x = 0; x < BURST_PKTS; x++) {
TEST_ASSERT_EQUAL(tx_buffers[x].len, sock.sendto(udp_addr, tx_buffers[x].payload, tx_buffers[x].len));
nsapi_size_or_error_t sent = sock.sendto(udp_addr, tx_buffers[x].payload, tx_buffers[x].len);
if (sent != NSAPI_ERROR_WOULD_BLOCK) {
TEST_ASSERT_EQUAL(tx_buffers[x].len, sent);
} else {
x--;
}
}

recvd = 0;
Expand Down
2 changes: 1 addition & 1 deletion TESTS/netsocket/udp/udpsocket_open_destruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void UDPSOCKET_OPEN_DESTRUCT()
}
#endif

for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
UDPSocket *sock = new UDPSocket;
if (!sock) {
TEST_FAIL();
Expand Down
4 changes: 1 addition & 3 deletions TESTS/netsocket/udp/udpsocket_sendto_timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ void UDPSOCKET_SENDTO_TIMEOUT()
int sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
timer.stop();
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
TEST_ASSERT(timer.read_ms() <= 100);

printf("MBED: Time taken: %fs\n", timer.read());
sock.set_timeout(1000);

timer.reset();
timer.start();
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
timer.stop();
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
TEST_ASSERT(timer.read_ms() <= 1000);
printf("MBED: Time taken: %fs\n", timer.read());

TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
Expand Down
Loading