Skip to content

Commit 56badd8

Browse files
author
Ari Parkkila
committed
Change TESTS/netsocket/ for cellular testing
1 parent 709e6ff commit 56badd8

20 files changed

+129
-46
lines changed

TESTS/netsocket/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ Call `Socket::open()` and then destruct the socket
402402
1. Create a object by calling `new Socket()`
403403
2. Call `Socket::open(stack)`
404404
3. Call "delete" for the object
405-
4. Repeat 1000 times.
405+
4. Repeat 100 times.
406406

407407
**Expected result:**
408408

@@ -1027,7 +1027,7 @@ Repeatedly send small packets.
10271027

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

10331033
**Expected result:**

TESTS/netsocket/dns/asynchronous_dns_simultaneous_repeat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int result_exp_timeout;
3333
void ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT()
3434
{
3535

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

TESTS/netsocket/dns/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,26 @@ static void net_bringup()
157157
printf("MBED: IP address is '%s'\n", net->get_ip_address());
158158
}
159159

160+
static void net_bringdown()
161+
{
162+
NetworkInterface::get_default_instance()->disconnect();
163+
printf("MBED: ifdown\n");
164+
}
165+
160166
// Test setup
161167
utest::v1::status_t test_setup(const size_t number_of_cases)
162168
{
163-
GREENTEA_SETUP(200, "default_auto");
169+
GREENTEA_SETUP(10 * 60, "default_auto");
164170
net_bringup();
165171
return verbose_test_setup_handler(number_of_cases);
166172
}
167173

174+
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
175+
{
176+
net_bringdown();
177+
return greentea_test_teardown_handler(passed, failed, failure);
178+
}
179+
168180
Case cases[] = {
169181
Case("ASYNCHRONOUS_DNS", ASYNCHRONOUS_DNS),
170182
Case("ASYNCHRONOUS_DNS_SIMULTANEOUS", ASYNCHRONOUS_DNS_SIMULTANEOUS),
@@ -181,7 +193,7 @@ Case cases[] = {
181193
Case("SYNCHRONOUS_DNS_INVALID", SYNCHRONOUS_DNS_INVALID),
182194
};
183195

184-
Specification specification(test_setup, cases, greentea_continue_handlers);
196+
Specification specification(test_setup, cases, greentea_teardown, greentea_continue_handlers);
185197

186198
int main()
187199
{

TESTS/netsocket/tcp/tcp_tests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int fetch_stats(void);
3636
int split2half_rmng_tcp_test_time(); // [s]
3737

3838
namespace tcp_global {
39-
static const int TESTS_TIMEOUT = 480;
39+
static const int TESTS_TIMEOUT = (10 * 60);
4040
static const int TCP_OS_STACK_SIZE = 2048;
4141

4242
static const int RX_BUFF_SIZE = 1220;

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,32 @@ void TCPSOCKET_ECHOTEST()
9696

9797
void tcpsocket_echotest_nonblock_receive()
9898
{
99-
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
100-
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
101-
if (tc_exec_time.read() >= time_allotted) {
99+
while (bytes2recv > 0) {
100+
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
101+
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
102+
if (tc_exec_time.read() >= time_allotted) {
103+
TEST_FAIL();
104+
receive_error = true;
105+
tx_sem.release();
106+
return;
107+
}
108+
continue;
109+
} else if (recvd < 0) {
110+
TEST_FAIL();
102111
receive_error = true;
112+
tx_sem.release();
113+
return;
103114
}
104-
return;
105-
} else if (recvd < 0) {
106-
receive_error = true;
107-
} else {
108-
bytes2recv -= recvd;
109-
}
110115

111-
if (bytes2recv == 0) {
112-
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
113-
114-
static int round = 0;
115-
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
116-
tx_sem.release();
117-
} else if (receive_error || bytes2recv < 0) {
118-
TEST_FAIL();
119-
tx_sem.release();
116+
bytes2recv -= recvd;
117+
if (!bytes2recv) {
118+
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
119+
static int round = 0;
120+
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
121+
tx_sem.release();
122+
break;
123+
}
120124
}
121-
// else - no error, not all bytes were received yet.
122125
}
123126

124127
void TCPSOCKET_ECHOTEST_NONBLOCK()

TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace {
2828
static const int SIGNAL_SIGIO = 0x1;
2929
static const int SIGIO_TIMEOUT = 20000; //[ms]
3030

31-
static const int BURST_CNT = 100;
31+
static const int BURST_CNT = 20;
3232
static const int BURST_SIZE = 1220;
3333
}
3434

TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424

2525
using namespace utest::v1;
2626

27+
namespace {
28+
static const int SIGNAL_SIGIO = 0x1;
29+
static const int SIGIO_TIMEOUT = 20000; //[ms]
30+
}
31+
32+
static void _sigio_handler(osThreadId id)
33+
{
34+
osSignalSet(id, SIGNAL_SIGIO);
35+
}
36+
2737
static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
2838
{
2939
SocketAddress tcp_addr;
@@ -52,6 +62,7 @@ void TCPSOCKET_ENDPOINT_CLOSE()
5262
TEST_FAIL();
5363
return;
5464
}
65+
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
5566

5667
int recvd = 0;
5768
int recvd_total = 0;
@@ -62,6 +73,13 @@ void TCPSOCKET_ENDPOINT_CLOSE()
6273
} else if (recvd <= 0) {
6374
TEST_ASSERT_EQUAL(0, recvd);
6475
break;
76+
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
77+
if (tc_exec_time.read() >= time_allotted ||
78+
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
79+
TEST_FAIL();
80+
break;
81+
}
82+
continue;
6583
}
6684
recvd_total += recvd;
6785
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);

TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void TCPSOCKET_OPEN_DESTRUCT()
3333
}
3434
#endif
3535

36-
for (int i = 0; i < 1000; i++) {
36+
for (int i = 0; i < 100; i++) {
3737
TCPSocket *sock = new TCPSocket;
3838
if (!sock) {
3939
TEST_FAIL();

TESTS/netsocket/tcp/tcpsocket_send_repeat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void TCPSOCKET_SEND_REPEAT()
3232
int snd;
3333
Timer timer;
3434
static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
35-
for (int i = 0; i < 1000; i++) {
35+
for (int i = 0; i < 100; i++) {
3636
snd = sock.send(tx_buffer, sizeof(tx_buffer));
3737
if (snd != sizeof(tx_buffer)) {
3838
TEST_FAIL();

TESTS/netsocket/tcp/tcpsocket_send_timeout.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void TCPSOCKET_SEND_TIMEOUT()
4444
(timer.read_ms() <= 800)) {
4545
continue;
4646
}
47+
printf("send: err %d, time %d", err, timer.read_ms());
4748
TEST_FAIL();
4849
break;
4950
}

0 commit comments

Comments
 (0)