Fixes findings from Greentea netsocket TCP test cases

pull/6665/head
Veijo Pesonen 2018-05-17 12:52:46 +03:00 committed by Seppo Takalo
parent 3e11a3e666
commit 491a7ea03e
8 changed files with 39 additions and 28 deletions

View File

@ -29,18 +29,17 @@
using namespace utest::v1;
#ifndef MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT
#define MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT 500 //[ms]
#endif
static NetworkInterface* net;
namespace
{
NetworkInterface* net;
}
NetworkInterface* get_interface()
{
return net;
}
void drop_bad_packets(TCPSocket& sock) {
void drop_bad_packets(TCPSocket& sock, int orig_timeout) {
nsapi_error_t err;
sock.set_timeout(0);
while (true) {
@ -49,7 +48,7 @@ void drop_bad_packets(TCPSocket& sock) {
break;
}
}
sock.set_timeout(MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT);
sock.set_timeout(orig_timeout);
}
static void _ifup() {

View File

@ -19,7 +19,7 @@
#define TCP_TESTS_H
NetworkInterface* get_interface();
void drop_bad_packets(TCPSocket& sock);
void drop_bad_packets(TCPSocket& sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len);
void tcpsocket_connect_to_echo_srv(TCPSocket& sock);
void tcpsocket_connect_to_discard_srv(TCPSocket& sock);

View File

@ -65,10 +65,7 @@ void TCPSOCKET_ECHOTEST()
int bytes2recv = sent;
while (bytes2recv) {
recvd = sock.recv(&(rx_buffer[sent-bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
TEST_ASSERT_NOT_EQUAL(osEventTimeout, osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status);
continue;
} else if (recvd <= 0) {
if (recvd < 0) {
printf("[Round#%02d] network error %d\n", x, recvd);
TEST_FAIL();
}

View File

@ -23,11 +23,13 @@
#include "utest.h"
#include "tcp_tests.h"
#define SIGNAL_SIGIO 0x1
#define SIGIO_TIMEOUT 5000 //[ms]
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int BURST_CNT = 100;
static const int BURST_SIZE = 1220;
char rx_buffer[BURST_SIZE] = {0};
@ -77,7 +79,7 @@ void TCPSOCKET_ECHOTEST_BURST()
}
if (bt_left != 0) {
drop_bad_packets(sock);
drop_bad_packets(sock, 0);
TEST_FAIL();
}
@ -134,7 +136,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
if (bt_left != 0) {
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
drop_bad_packets(sock);
drop_bad_packets(sock, -1);
TEST_FAIL();
}

View File

@ -23,6 +23,8 @@
#include "unity/unity.h"
#include "utest.h"
using namespace utest::v1;
void TCPSOCKET_OPEN_CLOSE_REPEAT()
{
TCPSocket *sock = new TCPSocket;

View File

@ -25,8 +25,11 @@
using namespace utest::v1;
#define SIGNAL_SIGIO 0x1
#define SIGIO_TIMEOUT 20000 //[ms]
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
}
static void _tcpsocket_connect_to_chargen_srv(TCPSocket& sock) {
SocketAddress tcp_addr;

View File

@ -23,8 +23,13 @@
#include "utest.h"
#include "tcp_tests.h"
#define SIGNAL_SIGIO 0x1
#define SIGIO_TIMEOUT 5000 //[ms]
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
}
static void _sigio_handler(osThreadId id) {
osSignalSet(id, SIGNAL_SIGIO);
@ -58,7 +63,7 @@ void TCPSOCKET_RECV_TIMEOUT()
TEST_FAIL();
}
printf("MBED: recv() took: %dms\n", timer.read_ms());
TEST_ASSERT_INT_WITHIN(50, (100+200)/2, timer.read_ms());
TEST_ASSERT_INT_WITHIN(50, 150, timer.read_ms());
continue;
} else if (recvd < 0) {
printf("[pkt#%02d] network error %d\n", i, recvd);

View File

@ -25,12 +25,15 @@
using namespace utest::v1;
#define SIGNAL_SIGIO1 0x1
#define SIGNAL_SIGIO2 0x2
#define SIGIO_TIMEOUT 5000 //[ms]
namespace
{
static const int SIGNAL_SIGIO1 = 0x1;
static const int SIGNAL_SIGIO2 = 0x2;
static const int SIGIO_TIMEOUT = 5000; //[ms]
Thread thread;
static volatile bool running = true;
Thread thread;
volatile bool running = true;
}
static void _sigio_handler1(osThreadId id) {
osSignalSet(id, SIGNAL_SIGIO1);
@ -84,7 +87,7 @@ static void check_const_len_rand_sequence()
}
if (bytes2process != 0) {
drop_bad_packets(sock);
drop_bad_packets(sock, 0);
TEST_FAIL();
}
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, BUFF_SIZE));
@ -136,7 +139,7 @@ static void check_var_len_rand_sequence()
}
if (bytes2process != 0) {
drop_bad_packets(sock);
drop_bad_packets(sock, 0);
TEST_FAIL();
}
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, i));