Skip to content

Commit 096ed1e

Browse files
Veijo PesonenSeppo Takalo
authored andcommitted
Adds UDP Greentea test case
udpsocket_sendto_invalid
1 parent 420459b commit 096ed1e

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

TESTS/netsocket/udp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Case cases[] = {
8383
Case("Reuse a socket", test_udpsocket_open_close_repeat),
8484
Case("Open at least 3 sockets", test_udpsocket_open_limit),
8585
Case("Receive in given time", test_udpsocket_recv_timeout),
86+
Case("Detect sendto invalid params", test_udpsocket_sendto_invalid),
8687
Case("Send in given time", test_udpsocket_sendto_timeout),
87-
8888
};
8989

9090
Specification specification(greentea_setup, cases, greentea_teardown);

TESTS/netsocket/udp/udp_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void test_udpsocket_echotest_burst_nonblock();
2929
void test_udpsocket_open_close_repeat();
3030
void test_udpsocket_open_limit();
3131
void test_udpsocket_recv_timeout();
32+
void test_udpsocket_sendto_invalid();
3233
void test_udpsocket_sendto_timeout();
3334

3435
#endif //UDP_TESTS_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include MBED_CONF_APP_HEADER_FILE
20+
#include "UDPSocket.h"
21+
#include "greentea-client/test_env.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
#include "udp_tests.h"
25+
26+
using namespace utest::v1;
27+
28+
void test_udpsocket_sendto_invalid()
29+
{
30+
UDPSocket sock;
31+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
32+
33+
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
34+
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
35+
TEST_ASSERT(sock.sendto("", 0, NULL, 0) < 0);
36+
TEST_ASSERT_EQUAL(5, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 0, "hello", 5));
37+
TEST_ASSERT_EQUAL(0, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 9, NULL, 0));
38+
TEST_ASSERT_EQUAL(5, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 9, "hello", 5));
39+
40+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
41+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include MBED_CONF_APP_HEADER_FILE
20+
#include "UDPSocket.h"
21+
#include "greentea-client/test_env.h"
22+
#include "unity/unity.h"
23+
#include "utest.h"
24+
#include "udp_tests.h"
25+
26+
using namespace utest::v1;
27+
28+
void test_udpsocket_sendto_repeat()
29+
{
30+
UDPSocket sock;
31+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
32+
33+
SocketAddress udp_addr;
34+
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
35+
udp_addr.set_port(9);
36+
37+
int sent;
38+
Timer timer;
39+
int i;
40+
static const char tx_buffer[] = {'h','e','l','l','o'};
41+
bool oom_earlier = false; // 2 times in a row -> time to give up
42+
for (i = 0; i < 100; i++) {
43+
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
44+
if (sent == NSAPI_ERROR_NO_MEMORY) {
45+
if (oom_earlier) {
46+
break;
47+
}
48+
oom_earlier = true;
49+
wait(1);
50+
continue;
51+
}
52+
oom_earlier = false;
53+
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
54+
}
55+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
56+
}

0 commit comments

Comments
 (0)