Merge pull request #9645 from AriParkkila/cellular-netsocket

Change TESTS/netsocket/ for cellular testing
pull/9715/head
Cruz Monrreal 2019-02-13 17:28:35 -06:00 committed by GitHub
commit 2e9d6d2938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 129 additions and 46 deletions

View File

@ -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:**
@ -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:**

View File

@ -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);

View File

@ -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),
@ -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()
{

View File

@ -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;

View File

@ -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) {
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;
}
}
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();
}
// else - no error, not all bytes were received yet.
}
void TCPSOCKET_ECHOTEST_NONBLOCK()

View File

@ -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;
}

View File

@ -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;
@ -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;
@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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"
@ -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;
@ -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};
@ -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()
@ -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) {
@ -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;
@ -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;

View File

@ -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;
@ -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);
}
}
@ -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;

View File

@ -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();

View File

@ -41,8 +41,7 @@ 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();
@ -50,7 +49,6 @@ void UDPSOCKET_SENDTO_TIMEOUT()
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());

View File

@ -0,0 +1,44 @@
{
"config": {
"echo-server-addr" : {
"help" : "IP address of echo server",
"value" : "\"echo.mbedcloudtesting.com\""
},
"echo-server-port" : {
"help" : "Port of echo server",
"value" : "7"
},
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"trace-level": {
"help": "Note that excessive trace prints may mess up with Greentea parsing",
"macro_name": "MBED_TRACE_MAX_LEVEL",
"value": "TRACE_LEVEL_ERROR"
}
},
"target_overrides": {
"*": {
"target.network-default-interface-type": "CELLULAR",
"nsapi.default-cellular-sim-pin": null,
"nsapi.dns-response-wait-time": 30000,
"ppp-cell-iface.apn-lookup": false,
"cellular.use-apn-lookup": false,
"lwip.ipv4-enabled": true,
"lwip.ipv6-enabled": true,
"lwip.tcp-enabled": true,
"lwip.ppp-enabled": true,
"lwip.ethernet-enabled": false,
"cellular.debug-at": false
}
}
}