Skip to content

Commit 491a7ea

Browse files
Veijo PesonenSeppo Takalo
authored andcommitted
Fixes findings from Greentea netsocket TCP test cases
1 parent 3e11a3e commit 491a7ea

8 files changed

+39
-28
lines changed

TESTS/netsocket/tcp/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@
2929

3030
using namespace utest::v1;
3131

32-
#ifndef MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT
33-
#define MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT 500 //[ms]
34-
#endif
35-
36-
static NetworkInterface* net;
32+
namespace
33+
{
34+
NetworkInterface* net;
35+
}
3736

3837
NetworkInterface* get_interface()
3938
{
4039
return net;
4140
}
4241

43-
void drop_bad_packets(TCPSocket& sock) {
42+
void drop_bad_packets(TCPSocket& sock, int orig_timeout) {
4443
nsapi_error_t err;
4544
sock.set_timeout(0);
4645
while (true) {
@@ -49,7 +48,7 @@ void drop_bad_packets(TCPSocket& sock) {
4948
break;
5049
}
5150
}
52-
sock.set_timeout(MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT);
51+
sock.set_timeout(orig_timeout);
5352
}
5453

5554
static void _ifup() {

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define TCP_TESTS_H
2020

2121
NetworkInterface* get_interface();
22-
void drop_bad_packets(TCPSocket& sock);
22+
void drop_bad_packets(TCPSocket& sock, int orig_timeout);
2323
void fill_tx_buffer_ascii(char *buff, size_t len);
2424
void tcpsocket_connect_to_echo_srv(TCPSocket& sock);
2525
void tcpsocket_connect_to_discard_srv(TCPSocket& sock);

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ void TCPSOCKET_ECHOTEST()
6565
int bytes2recv = sent;
6666
while (bytes2recv) {
6767
recvd = sock.recv(&(rx_buffer[sent-bytes2recv]), bytes2recv);
68-
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
69-
TEST_ASSERT_NOT_EQUAL(osEventTimeout, osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status);
70-
continue;
71-
} else if (recvd <= 0) {
68+
if (recvd < 0) {
7269
printf("[Round#%02d] network error %d\n", x, recvd);
7370
TEST_FAIL();
7471
}

TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
#include "utest.h"
2424
#include "tcp_tests.h"
2525

26-
#define SIGNAL_SIGIO 0x1
27-
#define SIGIO_TIMEOUT 5000 //[ms]
26+
using namespace utest::v1;
2827

2928
namespace
3029
{
30+
static const int SIGNAL_SIGIO = 0x1;
31+
static const int SIGIO_TIMEOUT = 5000; //[ms]
32+
3133
static const int BURST_CNT = 100;
3234
static const int BURST_SIZE = 1220;
3335
char rx_buffer[BURST_SIZE] = {0};
@@ -77,7 +79,7 @@ void TCPSOCKET_ECHOTEST_BURST()
7779
}
7880

7981
if (bt_left != 0) {
80-
drop_bad_packets(sock);
82+
drop_bad_packets(sock, 0);
8183
TEST_FAIL();
8284
}
8385

@@ -134,7 +136,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
134136

135137
if (bt_left != 0) {
136138
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
137-
drop_bad_packets(sock);
139+
drop_bad_packets(sock, -1);
138140
TEST_FAIL();
139141
}
140142

TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "unity/unity.h"
2424
#include "utest.h"
2525

26+
using namespace utest::v1;
27+
2628
void TCPSOCKET_OPEN_CLOSE_REPEAT()
2729
{
2830
TCPSocket *sock = new TCPSocket;

TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
using namespace utest::v1;
2727

28-
#define SIGNAL_SIGIO 0x1
29-
#define SIGIO_TIMEOUT 20000 //[ms]
28+
namespace
29+
{
30+
static const int SIGNAL_SIGIO = 0x1;
31+
static const int SIGIO_TIMEOUT = 20000; //[ms]
32+
}
3033

3134
static void _tcpsocket_connect_to_chargen_srv(TCPSocket& sock) {
3235
SocketAddress tcp_addr;

TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
#include "utest.h"
2424
#include "tcp_tests.h"
2525

26-
#define SIGNAL_SIGIO 0x1
27-
#define SIGIO_TIMEOUT 5000 //[ms]
26+
using namespace utest::v1;
27+
28+
namespace
29+
{
30+
static const int SIGNAL_SIGIO = 0x1;
31+
static const int SIGIO_TIMEOUT = 5000; //[ms]
32+
}
2833

2934
static void _sigio_handler(osThreadId id) {
3035
osSignalSet(id, SIGNAL_SIGIO);
@@ -58,7 +63,7 @@ void TCPSOCKET_RECV_TIMEOUT()
5863
TEST_FAIL();
5964
}
6065
printf("MBED: recv() took: %dms\n", timer.read_ms());
61-
TEST_ASSERT_INT_WITHIN(50, (100+200)/2, timer.read_ms());
66+
TEST_ASSERT_INT_WITHIN(50, 150, timer.read_ms());
6267
continue;
6368
} else if (recvd < 0) {
6469
printf("[pkt#%02d] network error %d\n", i, recvd);

TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525

2626
using namespace utest::v1;
2727

28-
#define SIGNAL_SIGIO1 0x1
29-
#define SIGNAL_SIGIO2 0x2
30-
#define SIGIO_TIMEOUT 5000 //[ms]
28+
namespace
29+
{
30+
static const int SIGNAL_SIGIO1 = 0x1;
31+
static const int SIGNAL_SIGIO2 = 0x2;
32+
static const int SIGIO_TIMEOUT = 5000; //[ms]
3133

32-
Thread thread;
33-
static volatile bool running = true;
34+
Thread thread;
35+
volatile bool running = true;
36+
}
3437

3538
static void _sigio_handler1(osThreadId id) {
3639
osSignalSet(id, SIGNAL_SIGIO1);
@@ -84,7 +87,7 @@ static void check_const_len_rand_sequence()
8487
}
8588

8689
if (bytes2process != 0) {
87-
drop_bad_packets(sock);
90+
drop_bad_packets(sock, 0);
8891
TEST_FAIL();
8992
}
9093
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, BUFF_SIZE));
@@ -136,7 +139,7 @@ static void check_var_len_rand_sequence()
136139
}
137140

138141
if (bytes2process != 0) {
139-
drop_bad_packets(sock);
142+
drop_bad_packets(sock, 0);
140143
TEST_FAIL();
141144
}
142145
TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, i));

0 commit comments

Comments
 (0)