Add TLSSocket greentea tests.

TLSSocket tests based on existing TCPSocket greentea tests and TLSSocket icetea tests.
pull/9283/head
Michal Paszta 2019-01-07 16:41:00 +01:00
parent 31579fe4bb
commit d568e2160b
29 changed files with 1490 additions and 25 deletions

View File

@ -17,7 +17,7 @@ The target for this plan is to test:
- [Socket](https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/Socket.h).
- [UDPSocket](https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/UDPSocket.h).
- [TCPSocket](https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.h).
- [TCPServer](https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPServer.h).
- [TLSSocket](https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TLSSocket.h).
Reference documentation: https://os.mbed.com/docs/latest/reference/network-socket.html
@ -102,35 +102,41 @@ time stream tcp6 nowait root internal
You can connect to the test server with an NMAP tool like this:
```.sh
$ nmap -sT -p7,9,13,37 echo.mbedcloudtesting.com
$ nmap -sT -p7,9,13,37,2007,2009,2013 echo.mbedcloudtesting.com
Starting Nmap 7.12 ( https://nmap.org ) at 2018-04-05 16:17 EEST
Starting Nmap 7.01 ( https://nmap.org ) at 2019-01-07 16:45 CET
Nmap scan report for echo.mbedcloudtesting.com (52.215.34.155)
Host is up (0.065s latency).
Other addresses for echo.mbedcloudtesting.com (not scanned): 2a05:d018:21f:3800:8584:60f8:bc9f:e614
Host is up (0.027s latency).
Other addresses for echo.mbedcloudtesting.com (not scanned): 2a05:d018:21f:3800:3164:2a5c:75b3:970b
rDNS record for 52.215.34.155: ec2-52-215-34-155.eu-west-1.compute.amazonaws.com
PORT STATE SERVICE
7/tcp open echo
9/tcp open discard
13/tcp open daytime
37/tcp open time
PORT STATE SERVICE
7/tcp open echo
9/tcp open discard
13/tcp open daytime
37/tcp open time
2007/tcp open dectalk
2009/tcp open news
2013/tcp open raid-am
Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
$ sudo nmap -sT -p7,9,13,37 echo.mbedcloudtesting.com
$ sudo nmap -sU -p7,9,13,37,2007,2009,2013 echo.mbedcloudtesting.com
Starting Nmap 7.12 ( https://nmap.org ) at 2018-04-05 16:16 EEST
Starting Nmap 7.01 ( https://nmap.org ) at 2019-01-08 15:05 CET
Nmap scan report for echo.mbedcloudtesting.com (52.215.34.155)
Host is up (0.068s latency).
Other addresses for echo.mbedcloudtesting.com (not scanned): 2a05:d018:21f:3800:8584:60f8:bc9f:e614
Host is up (0.044s latency).
Other addresses for echo.mbedcloudtesting.com (not scanned): 2a05:d018:21f:3800:3164:2a5c:75b3:970b
rDNS record for 52.215.34.155: ec2-52-215-34-155.eu-west-1.compute.amazonaws.com
PORT STATE SERVICE
7/tcp open echo
9/tcp open discard
13/tcp open daytime
37/tcp open time
PORT STATE SERVICE
7/udp open echo
9/udp open|filtered discard
13/udp closed daytime
37/udp closed time
2007/udp closed raid-am
2009/udp closed whosockami
2013/udp closed raid-cd
Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds
Nmap done: 1 IP address (1 host up) scanned in 1.78 seconds
```
### Ethernet test environment
@ -242,10 +248,18 @@ content at minimum:
"echo-server-port" : {
"help" : "Port of echo server",
"value" : "7"
}
},
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Echo port of echo server",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server",
"value" : "2009"
}
}
}
@ -301,6 +315,10 @@ the `mbed_app.json` might look like this:
"help" : "Port of echo server",
"value" : "7"
}
"echo-server-port-tls" : {
"help" : "Port of echo server TLS",
"value" : "2007"
}
},
"target_overrides": {
"*": {
@ -1651,8 +1669,6 @@ Subset for driver test
### For physical layer driver (emac, PPP):
- TCPSERVER_ACCEPT
- TCPSERVER_LISTEN
- TCPSOCKET_ECHOTEST
- TCPSOCKET_ECHOTEST_BURST
- TCPSOCKET_ECHOTEST_BURST_NONBLOCK
@ -1671,4 +1687,4 @@ Subset for driver test
### For socket layer driver (AT-driven, external IP stack):
All Socket, UDPSocket, TCPSocket and TCPServer testcases.
All Socket, UDPSocket, TCPSocket and TLSSocket testcases.

View File

@ -0,0 +1,214 @@
/*
* Copyright (c) 2019, 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.
*/
#define WIFI 2
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID))
#error [NOT_SUPPORTED] No network configuration found for this target.
#endif
#ifndef MBED_CONF_APP_ECHO_SERVER_ADDR
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json
#endif
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "utest/utest_stack_trace.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
Timer tc_bucket; // Timer to limit a test cases run time
}
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
mbed_stats_socket_t tls_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
#endif
char tls_global::rx_buffer[RX_BUFF_SIZE];
char tls_global::tx_buffer[TX_BUFF_SIZE];
const char *tls_global::cert = \
"-----BEGIN CERTIFICATE-----\n"
"MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/\n"
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
"DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow\n"
"SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT\n"
"GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC\n"
"AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF\n"
"q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8\n"
"SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0\n"
"Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA\n"
"a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj\n"
"/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T\n"
"AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG\n"
"CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv\n"
"bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k\n"
"c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw\n"
"VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC\n"
"ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz\n"
"MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu\n"
"Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF\n"
"AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo\n"
"uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/\n"
"wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu\n"
"X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
"-----END CERTIFICATE-----\n";
void drop_bad_packets(TLSSocket &sock, int orig_timeout)
{
nsapi_error_t err;
sock.set_timeout(0);
while (true) {
err = sock.recv(NULL, 0);
if (err == NSAPI_ERROR_WOULD_BLOCK) {
break;
}
}
sock.set_timeout(orig_timeout);
}
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: TLSClient IP address is '%s'\n", net->get_ip_address());
}
static void _ifdown()
{
NetworkInterface::get_default_instance()->disconnect();
printf("MBED: ifdown\n");
}
nsapi_error_t tlssocket_connect_to_srv(TLSSocket &sock, uint16_t port)
{
SocketAddress tls_addr;
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tls_addr);
tls_addr.set_port(port);
printf("MBED: Server '%s', port %d\n", tls_addr.get_ip_address(), tls_addr.get_port());
nsapi_error_t err = sock.set_root_ca_cert(tls_global::cert);
if (err != NSAPI_ERROR_OK) {
printf("Error from sock.set_root_ca_cert: %d\n", err);
return err;
}
err = sock.open(NetworkInterface::get_default_instance());
if (err != NSAPI_ERROR_OK) {
printf("Error from sock.open: %d\n", err);
return err;
}
err = sock.connect(tls_addr);
if (err != NSAPI_ERROR_OK) {
printf("Error from sock.connect: %d\n", err);
return err;
}
return NSAPI_ERROR_OK;
}
nsapi_error_t tlssocket_connect_to_echo_srv(TLSSocket &sock)
{
return tlssocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_PORT_TLS);
}
nsapi_error_t tlssocket_connect_to_discard_srv(TLSSocket &sock)
{
return tlssocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS);
}
void fill_tx_buffer_ascii(char *buff, size_t len)
{
for (size_t i = 0; i < len; ++i) {
buff[i] = (rand() % 43) + '0';
}
}
int split2half_rmng_tls_test_time()
{
return (tls_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
}
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int fetch_stats()
{
return SocketStats::mbed_stats_socket_get_each(&tls_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
}
#endif
// Test setup
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(tls_global::TESTS_TIMEOUT, "default_auto");
_ifup();
tc_bucket.start();
return greentea_test_setup_handler(number_of_cases);
}
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
{
tc_bucket.stop();
_ifdown();
return greentea_test_teardown_handler(passed, failed, failure);
}
Case cases[] = {
Case("TLSSOCKET_ECHOTEST", TLSSOCKET_ECHOTEST),
Case("TLSSOCKET_ECHOTEST_NONBLOCK", TLSSOCKET_ECHOTEST_NONBLOCK),
Case("TLSSOCKET_CONNECT_INVALID", TLSSOCKET_CONNECT_INVALID),
Case("TLSSOCKET_ECHOTEST_BURST", TLSSOCKET_ECHOTEST_BURST),
Case("TLSSOCKET_ECHOTEST_BURST_NONBLOCK", TLSSOCKET_ECHOTEST_BURST_NONBLOCK),
Case("TLSSOCKET_RECV_TIMEOUT", TLSSOCKET_RECV_TIMEOUT),
Case("TLSSOCKET_ENDPOINT_CLOSE", TLSSOCKET_ENDPOINT_CLOSE),
Case("TLSSOCKET_HANDSHAKE_INVALID", TLSSOCKET_HANDSHAKE_INVALID),
Case("TLSSOCKET_OPEN_TWICE", TLSSOCKET_OPEN_TWICE),
Case("TLSSOCKET_OPEN_LIMIT", TLSSOCKET_OPEN_LIMIT),
Case("TLSSOCKET_OPEN_DESTRUCT", TLSSOCKET_OPEN_DESTRUCT),
Case("TLSSOCKET_SEND_UNCONNECTED", TLSSOCKET_SEND_UNCONNECTED),
Case("TLSSOCKET_SEND_CLOSED", TLSSOCKET_SEND_CLOSED),
Case("TLSSOCKET_SEND_REPEAT", TLSSOCKET_SEND_REPEAT),
Case("TLSSOCKET_SEND_TIMEOUT", TLSSOCKET_SEND_TIMEOUT),
Case("TLSSOCKET_NO_CERT", TLSSOCKET_NO_CERT),
Case("TLSSOCKET_SIMULTANEOUS", TLSSOCKET_SIMULTANEOUS)
};
Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers);
int retval;
void run_test(void)
{
retval = !Harness::run(specification);
}
static unsigned char stack_mem[8192];
int main()
{
Thread *th = new Thread(osPriorityNormal, 8192, stack_mem, "tls_gt_thread");
th->start(callback(run_test));
th->join();
return retval;
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2019, 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.
*/
#ifndef TLS_TESTS_H
#define TLS_TESTS_H
NetworkInterface *get_interface();
void drop_bad_packets(TLSSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tlssocket_connect_to_echo_srv(TLSSocket &sock);
nsapi_error_t tlssocket_connect_to_discard_srv(TLSSocket &sock);
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
extern mbed_stats_socket_t tls_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
int fetch_stats(void);
#endif
/**
* Single testcase might take only half of the remaining execution time
*/
int split2half_rmng_tls_test_time(); // [s]
namespace tls_global {
static const int TESTS_TIMEOUT = 480;
static const int TLS_OS_STACK_SIZE = 2048;
static const int RX_BUFF_SIZE = 1220;
static const int TX_BUFF_SIZE = 1220;
extern char rx_buffer[RX_BUFF_SIZE];
extern char tx_buffer[TX_BUFF_SIZE];
extern const char *cert;
}
/*
* Test cases
*/
void TLSSOCKET_CONNECT_INVALID();
void TLSSOCKET_HANDSHAKE_INVALID();
void TLSSOCKET_ECHOTEST();
void TLSSOCKET_ECHOTEST_NONBLOCK();
void TLSSOCKET_ECHOTEST_BURST();
void TLSSOCKET_ECHOTEST_BURST_NONBLOCK();
void TLSSOCKET_ENDPOINT_CLOSE();
void TLSSOCKET_RECV_TIMEOUT();
void TLSSOCKET_OPEN_TWICE();
void TLSSOCKET_OPEN_LIMIT();
void TLSSOCKET_OPEN_DESTRUCT();
void TLSSOCKET_SEND_UNCONNECTED();
void TLSSOCKET_SEND_CLOSED();
void TLSSOCKET_SEND_REPEAT();
void TLSSOCKET_NO_CERT();
void TLSSOCKET_SIMULTANEOUS();
void TLSSOCKET_SEND_TIMEOUT();
#endif //TLS_TESTS_H

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_CONNECT_INVALID()
{
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
TEST_ASSERT(sock.connect(NULL, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0);
TEST_ASSERT(sock.connect("", MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0);
TEST_ASSERT(sock.connect("", 0) < 0);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,209 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
static const int BUFF_SIZE = 1200;
static const int PKTS = 22;
static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, \
1100, 1200
};
TLSSocket *sock;
Semaphore tx_sem(0, 1);
events::EventQueue *event_queue;
int bytes2recv;
int bytes2recv_total;
Timer tc_exec_time;
int time_allotted;
bool receive_error;
}
void tlssocket_echotest_nonblock_receive();
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
if (event_queue != NULL) {
event_queue->call(tlssocket_echotest_nonblock_receive);
}
}
void TLSSOCKET_ECHOTEST()
{
sock = new TLSSocket;
if (tlssocket_connect_to_echo_srv(*sock) != NSAPI_ERROR_OK) {
printf("Error from tlssocket_connect_to_echo_srv\n");
TEST_FAIL();
return;
delete sock;
}
int recvd;
int sent;
int x = 0;
for (int pkt_s = pkt_sizes[x]; x < PKTS; pkt_s = pkt_sizes[x++]) {
fill_tx_buffer_ascii(tls_global::tx_buffer, BUFF_SIZE);
sent = sock->send(tls_global::tx_buffer, pkt_s);
if (sent < 0) {
printf("[Round#%02d] network error %d\n", x, sent);
TEST_FAIL();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
delete sock;
return;
}
int bytes2recv = sent;
while (bytes2recv) {
recvd = sock->recv(&(tls_global::rx_buffer[sent - bytes2recv]), bytes2recv);
if (recvd < 0) {
printf("[Round#%02d] network error %d\n", x, recvd);
TEST_FAIL();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
delete sock;
return;
}
bytes2recv -= recvd;
}
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, sent));
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
delete sock;
}
void tlssocket_echotest_nonblock_receive()
{
int recvd = sock->recv(&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) {
receive_error = true;
}
return;
} else if (recvd < 0) {
receive_error = true;
} else {
bytes2recv -= recvd;
}
if (bytes2recv == 0) {
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
tx_sem.release();
}
else if (receive_error || bytes2recv < 0) {
TEST_FAIL();
tx_sem.release();
}
// else - no error, not all bytes were received yet.
}
void TLSSOCKET_ECHOTEST_NONBLOCK()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int j = 0;
int count = fetch_stats();
for (; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state);
}
#endif
sock = new TLSSocket;
tc_exec_time.start();
time_allotted = split2half_rmng_tls_test_time(); // [s]
tlssocket_connect_to_echo_srv(*sock);
sock->set_blocking(false);
sock->sigio(callback(_sigio_handler, ThisThread::get_id()));
int bytes2send;
int sent;
int s_idx = 0;
receive_error = false;
unsigned char *stack_mem = (unsigned char *)malloc(tls_global::TLS_OS_STACK_SIZE);
TEST_ASSERT_NOT_NULL(stack_mem);
Thread *receiver_thread = new Thread(osPriorityNormal,
tls_global::TLS_OS_STACK_SIZE,
stack_mem,
"receiver");
EventQueue queue(2 * EVENTS_EVENT_SIZE);
event_queue = &queue;
TEST_ASSERT_EQUAL(osOK, receiver_thread->start(callback(&queue, &EventQueue::dispatch_forever)));
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
pkt_s = pkt_sizes[s_idx];
bytes2recv = pkt_s;
bytes2recv_total = pkt_s;
fill_tx_buffer_ascii(tls_global::tx_buffer, pkt_s);
bytes2send = pkt_s;
while (bytes2send > 0) {
sent = sock->send(&(tls_global::tx_buffer[pkt_s - bytes2send]), bytes2send);
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
goto END;
}
continue;
} else if (sent <= 0) {
printf("[Sender#%02d] network error %d\n", s_idx, sent);
TEST_FAIL();
goto END;
}
bytes2send -= sent;
}
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats();
for (j = 0; j < count; j++) {
if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TLS)) {
break;
}
}
TEST_ASSERT_EQUAL(bytes2send, tls_stats[j].sent_bytes);
#endif
tx_sem.wait();
if (receive_error) {
break;
}
}
END:
sock->sigio(NULL);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
receiver_thread->terminate();
delete receiver_thread;
receiver_thread = NULL;
tc_exec_time.stop();
free(stack_mem);
delete sock;
}

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
static const int BURST_CNT = 100;
static const int BURST_SIZE = 1220;
}
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
void TLSSOCKET_ECHOTEST_BURST()
{
TLSSocket *sock = new TLSSocket;
tlssocket_connect_to_echo_srv(*sock);
sock->sigio(callback(_sigio_handler, ThisThread::get_id()));
// TX buffer to be preserved for comparison
fill_tx_buffer_ascii(tls_global::tx_buffer, BURST_SIZE);
int recvd;
int bt_left;
int sent;
for (int i = 0; i < BURST_CNT; i++) {
bt_left = BURST_SIZE;
while (bt_left > 0) {
sent = sock->send(&(tls_global::tx_buffer[BURST_SIZE - bt_left]), bt_left);
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
goto END;
}
continue;
} else if (sent < 0) {
printf("[%02d] network error %d\n", i, sent);
TEST_FAIL();
goto END;
}
bt_left -= sent;
}
bt_left = BURST_SIZE;
while (bt_left > 0) {
recvd = sock->recv(&(tls_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE);
if (recvd < 0) {
printf("[%02d] network error %d\n", i, recvd);
break;
}
bt_left -= recvd;
}
if (bt_left != 0) {
TEST_FAIL_MESSAGE("bt_left != 0");
goto END;
}
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, BURST_SIZE));
}
END:
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
delete sock;
}
void TLSSOCKET_ECHOTEST_BURST_NONBLOCK()
{
TLSSocket *sock = new TLSSocket;
tlssocket_connect_to_echo_srv(*sock);
sock->set_blocking(false);
sock->sigio(callback(_sigio_handler, ThisThread::get_id()));
// TX buffer to be preserved for comparison
fill_tx_buffer_ascii(tls_global::tx_buffer, BURST_SIZE);
int sent;
int recvd;
int bt_left = 0;
for (int i = 0; i < BURST_CNT; i++) {
bt_left = BURST_SIZE;
while (bt_left > 0) {
sent = sock->send(&(tls_global::tx_buffer[BURST_SIZE - bt_left]), bt_left);
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
goto END;
}
continue;
} else if (sent < 0) {
printf("[%02d] network error %d\n", i, sent);
TEST_FAIL();
goto END;
}
bt_left -= sent;
}
if (bt_left != 0) {
TEST_FAIL();
goto END;
}
bt_left = BURST_SIZE;
while (bt_left > 0) {
recvd = sock->recv(&(tls_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
printf("[bt#%02d] packet timeout...", i);
break;
}
continue;
} else if (recvd < 0) {
printf("[%02d] network error %d\n", i, recvd);
break;
}
bt_left -= recvd;
}
if (bt_left != 0) {
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
TEST_FAIL();
goto END;
}
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, BURST_SIZE));
}
END:
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
delete sock;
}

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
}
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
static nsapi_error_t _tlssocket_connect_to_daytime_srv(TLSSocket &sock)
{
SocketAddress tls_addr;
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tls_addr);
tls_addr.set_port(2013);
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
if (err != NSAPI_ERROR_OK) {
return err;
}
return sock.connect(tls_addr);
}
void TLSSOCKET_ENDPOINT_CLOSE()
{
static const int MORE_THAN_AVAILABLE = 30;
char buff[MORE_THAN_AVAILABLE];
int time_allotted = split2half_rmng_tls_test_time(); // [s]
Timer tc_exec_time;
tc_exec_time.start();
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
if (_tlssocket_connect_to_daytime_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
return;
}
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
int recvd = 0;
int recvd_total = 0;
while (true) {
recvd = sock.recv(&(buff[recvd_total]), MORE_THAN_AVAILABLE);
if (recvd_total > 0 && recvd == 0) {
break; // Endpoint closed socket, success
} else if (recvd <= 0) {
TEST_FAIL();
break;
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
break;
}
continue;
}
recvd_total += recvd;
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);
}
tc_exec_time.stop();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_HANDSHAKE_INVALID()
{
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
TEST_ASSERT_EQUAL(NSAPI_ERROR_NO_CONNECTION,
sock.connect("os.mbed.com", MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_NO_CERT()
{
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_AUTH_FAILURE,
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT_TLS));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2019, 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 "greentea-client/test_env.h"
#include "mbed.h"
#include "TLSSocket.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_OPEN_DESTRUCT()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats();
for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state);
}
#endif
for (int i = 0; i < 1000; i++) {
TLSSocket *sock = new TLSSocket;
if (!sock) {
TEST_FAIL();
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
delete sock;
}
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats();
for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state);
}
#endif
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2019, 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 "greentea-client/test_env.h"
#include "mbed.h"
#include "TLSSocket.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
typedef struct TLSSocketItem {
TLSSocket *sock;
TLSSocketItem *next;
} SocketItem;
}
void TLSSOCKET_OPEN_LIMIT()
{
int open_sockets[2] = {0};
for (int i = 0; i < 2; i++) {
TLSSocketItem *socket_list_head = NULL;
TLSSocketItem *it;
TLSSocket *sock;
int ret;
while (true) {
sock = new TLSSocket;
if (!sock) {
break;
}
ret = sock->open(NetworkInterface::get_default_instance());
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
delete sock;
break;
}
// Hopefully this doesn't interfere when trying to allocate more sockets
it = new TLSSocketItem;
if (!it) {
delete sock;
break;
}
it->sock = sock;
// Order of items in the list doesn't matter
it->next = socket_list_head;
socket_list_head = it;
}
if (!socket_list_head) {
break;
}
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats();
int open_count = 0;
for (int j = 0; j < count; j++) {
if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TLS)) {
open_count++;
}
}
TEST_ASSERT(open_count >= 4);
#endif
TLSSocketItem *tmp;
for (TLSSocketItem *it = socket_list_head; it;) {
++open_sockets[i];
tmp = it;
it = it->next;
socket_list_head = it;
delete tmp->sock;
delete tmp;
}
printf("[round#%02d] %d sockets opened\n", i, open_sockets[i]);
}
TEST_ASSERT_EQUAL(open_sockets[0], open_sockets[1]);
TEST_ASSERT(open_sockets[0] >= 4);
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2019, 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 "greentea-client/test_env.h"
#include "mbed.h"
#include "TLSSocket.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_OPEN_TWICE()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats();
for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state);
}
#endif
TLSSocket *sock = new TLSSocket;
if (!sock) {
TEST_FAIL();
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance()));
delete sock;
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats();
for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state);
}
#endif
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
}
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
void TLSSOCKET_RECV_TIMEOUT()
{
static const int DATA_LEN = 100;
char buff[DATA_LEN] = {0};
int time_allotted = split2half_rmng_tls_test_time(); // [s]
Timer tc_exec_time;
tc_exec_time.start();
TLSSocket sock;
tlssocket_connect_to_echo_srv(sock);
sock.set_timeout(100);
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
int recvd = 0;
int pkt_unrecvd;
Timer timer;
for (int i = 0; i < 5; i++) {
pkt_unrecvd = DATA_LEN;
TEST_ASSERT_EQUAL(DATA_LEN, sock.send(buff, DATA_LEN));
while (pkt_unrecvd) {
timer.reset();
timer.start();
recvd = sock.recv(&(buff[DATA_LEN - pkt_unrecvd]), pkt_unrecvd);
timer.stop();
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout)) {
TEST_FAIL();
goto CLEANUP;
}
printf("MBED: recv() took: %dus\n", timer.read_us());
TEST_ASSERT_INT_WITHIN(51, 150, (timer.read_us() + 500) / 1000);
continue;
} else if (recvd < 0) {
printf("[pkt#%02d] network error %d\n", i, recvd);
TEST_FAIL();
goto CLEANUP;
}
pkt_unrecvd -= recvd;
}
}
CLEANUP:
tc_exec_time.stop();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_SEND_CLOSED()
{
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK,
sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_PORT_TLS));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
TEST_ASSERT_EQUAL(NSAPI_ERROR_NO_SOCKET, sock.send("12345", 5));
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_SEND_REPEAT()
{
TLSSocket sock;
tlssocket_connect_to_discard_srv(sock);
int snd;
Timer timer;
static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 1000; i++) {
snd = sock.send(tx_buffer, sizeof(tx_buffer));
if (snd != sizeof(tx_buffer)) {
TEST_FAIL();
break;
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,52 @@
/*
* 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_SEND_TIMEOUT()
{
TLSSocket sock;
if (tlssocket_connect_to_discard_srv(sock) != NSAPI_ERROR_OK) {
TEST_FAIL();
return;
}
int err;
Timer timer;
static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 10; i++) {
timer.reset();
timer.start();
err = sock.send(tx_buffer, sizeof(tx_buffer));
timer.stop();
if ((err == sizeof(tx_buffer)) &&
(timer.read_ms() <= 800)) {
continue;
}
TEST_FAIL();
break;
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_SEND_UNCONNECTED()
{
TLSSocket sock;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert));
TEST_ASSERT_EQUAL(NSAPI_ERROR_NO_CONNECTION, sock.send("12345", 5));
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2019, 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 "TLSSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"
#include "tls_tests.h"
using namespace utest::v1;
void TLSSOCKET_SIMULTANEOUS()
{
TLSSocket sock1;
TLSSocket sock2;
tlssocket_connect_to_echo_srv(sock1);
tlssocket_connect_to_echo_srv(sock2);
int snd;
int rcvd;
static const char tx_buffer1[] = {'h', 'e', 'l', 'l', 'o', '1'};
static const char tx_buffer2[] = {'h', 'e', 'l', 'l', 'o', '2'};
char rx_buffer1[6];
char rx_buffer2[6];
for (int i = 0; i < 10; i++) {
snd = sock1.send(tx_buffer1, sizeof(tx_buffer1));
if (snd != sizeof(tx_buffer1)) {
TEST_FAIL();
break;
}
snd = sock2.send(tx_buffer2, sizeof(tx_buffer2));
if (snd != sizeof(tx_buffer2)) {
TEST_FAIL();
break;
}
rcvd = sock1.recv(&rx_buffer1, 6);
if ((rcvd != 6) || (memcmp(tx_buffer1, rx_buffer1, 6) != 0)) {
TEST_FAIL();
break;
}
rcvd = sock2.recv(&rx_buffer2, 6);
if ((rcvd != 6) || (memcmp(tx_buffer2, rx_buffer2, 6) != 0)) {
TEST_FAIL();
break;
}
}
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock1.close());
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2.close());
}

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -12,6 +12,14 @@
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"sim-blockdevice": {
"help": "Simulated block device, requires sufficient heap",
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",

View File

@ -12,6 +12,14 @@
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"sim-blockdevice": {
"help": "Simulated block device, requires sufficient heap",
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",

View File

@ -12,6 +12,14 @@
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"wifi-secure-ssid": {
"help": "WiFi SSID for WPA2 secured network",
"value": "\"SSID-SECURE\""

View File

@ -12,6 +12,14 @@
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"WIFI-TX" : {
"help" : "Wifi TX pin",
"value" : "D8"

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
}
},
"target_overrides": {

View File

@ -11,6 +11,14 @@
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : null
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : null
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : null
}
},
"target_overrides": {