mirror of https://github.com/ARMmbed/mbed-os.git
parent
420459b8de
commit
096ed1e451
|
@ -83,8 +83,8 @@ Case cases[] = {
|
||||||
Case("Reuse a socket", test_udpsocket_open_close_repeat),
|
Case("Reuse a socket", test_udpsocket_open_close_repeat),
|
||||||
Case("Open at least 3 sockets", test_udpsocket_open_limit),
|
Case("Open at least 3 sockets", test_udpsocket_open_limit),
|
||||||
Case("Receive in given time", test_udpsocket_recv_timeout),
|
Case("Receive in given time", test_udpsocket_recv_timeout),
|
||||||
|
Case("Detect sendto invalid params", test_udpsocket_sendto_invalid),
|
||||||
Case("Send in given time", test_udpsocket_sendto_timeout),
|
Case("Send in given time", test_udpsocket_sendto_timeout),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Specification specification(greentea_setup, cases, greentea_teardown);
|
Specification specification(greentea_setup, cases, greentea_teardown);
|
||||||
|
|
|
@ -29,6 +29,7 @@ void test_udpsocket_echotest_burst_nonblock();
|
||||||
void test_udpsocket_open_close_repeat();
|
void test_udpsocket_open_close_repeat();
|
||||||
void test_udpsocket_open_limit();
|
void test_udpsocket_open_limit();
|
||||||
void test_udpsocket_recv_timeout();
|
void test_udpsocket_recv_timeout();
|
||||||
|
void test_udpsocket_sendto_invalid();
|
||||||
void test_udpsocket_sendto_timeout();
|
void test_udpsocket_sendto_timeout();
|
||||||
|
|
||||||
#endif //UDP_TESTS_H
|
#endif //UDP_TESTS_H
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
|
#include MBED_CONF_APP_HEADER_FILE
|
||||||
|
#include "UDPSocket.h"
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
#include "unity/unity.h"
|
||||||
|
#include "utest.h"
|
||||||
|
#include "udp_tests.h"
|
||||||
|
|
||||||
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
void test_udpsocket_sendto_invalid()
|
||||||
|
{
|
||||||
|
UDPSocket sock;
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||||
|
|
||||||
|
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
|
||||||
|
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
|
||||||
|
TEST_ASSERT(sock.sendto("", 0, NULL, 0) < 0);
|
||||||
|
TEST_ASSERT_EQUAL(5, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 0, "hello", 5));
|
||||||
|
TEST_ASSERT_EQUAL(0, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 9, NULL, 0));
|
||||||
|
TEST_ASSERT_EQUAL(5, sock.sendto(MBED_CONF_APP_ECHO_SERVER_ADDR, 9, "hello", 5));
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
|
#include MBED_CONF_APP_HEADER_FILE
|
||||||
|
#include "UDPSocket.h"
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
#include "unity/unity.h"
|
||||||
|
#include "utest.h"
|
||||||
|
#include "udp_tests.h"
|
||||||
|
|
||||||
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
void test_udpsocket_sendto_repeat()
|
||||||
|
{
|
||||||
|
UDPSocket sock;
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||||
|
|
||||||
|
SocketAddress udp_addr;
|
||||||
|
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||||
|
udp_addr.set_port(9);
|
||||||
|
|
||||||
|
int sent;
|
||||||
|
Timer timer;
|
||||||
|
int i;
|
||||||
|
static const char tx_buffer[] = {'h','e','l','l','o'};
|
||||||
|
bool oom_earlier = false; // 2 times in a row -> time to give up
|
||||||
|
for (i = 0; i < 100; i++) {
|
||||||
|
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||||
|
if (sent == NSAPI_ERROR_NO_MEMORY) {
|
||||||
|
if (oom_earlier) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
oom_earlier = true;
|
||||||
|
wait(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
oom_earlier = false;
|
||||||
|
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
|
||||||
|
}
|
||||||
|
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||||
|
}
|
Loading…
Reference in New Issue