mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9283 from michalpasztamobica/tlssocket_greentea
Add TLSSocket greentea tests.pull/9541/head
commit
7d036b52cd
|
@ -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
|
||||
|
||||
|
@ -58,14 +58,14 @@ echo.mbedcloudtesting.com has IPv6 address 2a05:d018:21f:3800:8584:60f8:bc9f:e61
|
|||
**Open services in the test server**
|
||||
|
||||
- Echo protocol, [RFC 862](https://tools.ietf.org/html/rfc862) is
|
||||
enabled in both TCP and UDP. Port 7.
|
||||
enabled in both TCP and UDP. Port 7. Port 2007 for TLS.
|
||||
- Discard protocol, [RFC 863](https://tools.ietf.org/html/rfc863) is
|
||||
enabled in both TCP and UDP. Port 9.
|
||||
enabled in both TCP and UDP. Port 9. Port 2009 for TLS.
|
||||
- Character generator protocol, [RFC 864](https://tools.ietf.org/html/rfc864) is
|
||||
enabled in both TCP and UDP. Port 19. Output pattern should follow
|
||||
the proposed example pattern in RFC.
|
||||
- Daytime protocol, [RFC 867](https://tools.ietf.org/html/rfc867) in
|
||||
both TCP and UDP. Port 13.
|
||||
both TCP and UDP. Port 13. Port 2013 for TLS.
|
||||
- Time protocol, [RFC 868](https://tools.ietf.org/html/rfc868) in
|
||||
both TCP and UDP. Port 37.
|
||||
|
||||
|
@ -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
|
||||
|
@ -173,43 +179,55 @@ pass the test if the driver implements the feature in question.
|
|||
| 12 | UDPSOCKET_BIND_UNOPENED | SHOULD |
|
||||
| 13 | UDPSOCKET_SENDTO_INVALID | MUST |
|
||||
| 14 | UDPSOCKET_SENDTO_REPEAT | MUST |
|
||||
| 15 | UDPSOCKET_BIND_SENDTO | SHOULD |
|
||||
| 16 | UDPSOCKET_ECHOTEST | MUST |
|
||||
| 17 | UDPSOCKET_ECHOTEST_NONBLOCK | MUST |
|
||||
| 18 | UDPSOCKET_RECV_TIMEOUT | SHOULD |
|
||||
| 19 | UDPSOCKET_SENDTO_TIMEOUT | SHOULD |
|
||||
| 20 | TCPSOCKET_OPEN_DESTRUCT | MUST |
|
||||
| 21 | TCPSOCKET_OPEN_LIMIT | MUST |
|
||||
| 22 | TCPSOCKET_OPEN_TWICE | MUST |
|
||||
| 23 | TCPSOCKET_OPEN_CLOSE_REPEAT | MUST |
|
||||
| 24 | TCPSOCKET_BIND_PORT | SHOULD |
|
||||
| 25 | TCPSOCKET_BIND_PORT_FAIL | SHOULD |
|
||||
| 26 | TCPSOCKET_BIND_ADDRESS_PORT | SHOULD |
|
||||
| 27 | TCPSOCKET_BIND_ADDRESS_NULL | SHOULD |
|
||||
| 28 | TCPSOCKET_BIND_ADDRESS_INVALID | SHOULD |
|
||||
| 29 | TCPSOCKET_BIND_WRONG_TYPE | SHOULD |
|
||||
| 30 | TCPSOCKET_BIND_ADDRESS | SHOULD |
|
||||
| 31 | TCPSOCKET_BIND_UNOPENED | SHOULD |
|
||||
| 32 | TCPSOCKET_CONNECT_INVALID | MUST |
|
||||
| 33 | TCPSOCKET_SEND_REPEAT | MUST |
|
||||
| 34 | TCPSOCKET_ECHOTEST | MUST |
|
||||
| 35 | TCPSOCKET_ECHOTEST_NONBLOCK | MUST |
|
||||
| 36 | TCPSOCKET_RECV_TIMEOUT | SHOULD |
|
||||
| 37 | TCPSOCKET_SEND_TIMEOUT | SHOULD |
|
||||
| 38 | TCPSOCKET_ENDPOINT_CLOSE | MUST |
|
||||
| 39 | TCPSERVER_ACCEPT | SHOULD |
|
||||
| 40 | TCPSERVER_LISTEN | SHOULD |
|
||||
| 41 | TCPSERVER_LISTEN_WITHOUT_BIND | SHOULD |
|
||||
| 42 | TCPSERVER_ACCEPT_WITHOUT_LISTEN | SHOULD |
|
||||
| 43 | UDPSOCKET_ECHOTEST_BURST | MUST |
|
||||
| 44 | UDPSOCKET_ECHOTEST_BURST_NONBLOCK | MUST |
|
||||
| 45 | TCPSOCKET_ECHOTEST_BURST | MUST |
|
||||
| 46 | TCPSOCKET_ECHOTEST_BURST_NONBLOCK | MUST |
|
||||
| 47 | TCPSOCKET_RECV_100K | MUST |
|
||||
| 48 | TCPSOCKET_RECV_100K_NONBLOCK | MUST |
|
||||
| 49 | TCPSOCKET_THREAD_PER_SOCKET_SAFETY | MUST |
|
||||
| 50 | TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID | SHOULD |
|
||||
| 51 | TCPSOCKET_SETSOCKOPT_KEEPALIVE_INVALID | SHOULD |
|
||||
| 15 | UDPSOCKET_ECHOTEST | MUST |
|
||||
| 16 | UDPSOCKET_ECHOTEST_NONBLOCK | MUST |
|
||||
| 17 | UDPSOCKET_RECV_TIMEOUT | SHOULD |
|
||||
| 18 | UDPSOCKET_SENDTO_TIMEOUT | SHOULD |
|
||||
| 19 | TCPSOCKET_OPEN_DESTRUCT | MUST |
|
||||
| 20 | TCPSOCKET_OPEN_LIMIT | MUST |
|
||||
| 21 | TCPSOCKET_OPEN_TWICE | MUST |
|
||||
| 22 | TCPSOCKET_OPEN_CLOSE_REPEAT | MUST |
|
||||
| 23 | TCPSOCKET_BIND_PORT | SHOULD |
|
||||
| 24 | TCPSOCKET_BIND_PORT_FAIL | SHOULD |
|
||||
| 25 | TCPSOCKET_BIND_ADDRESS_PORT | SHOULD |
|
||||
| 26 | TCPSOCKET_BIND_ADDRESS_NULL | SHOULD |
|
||||
| 27 | TCPSOCKET_BIND_ADDRESS_INVALID | SHOULD |
|
||||
| 28 | TCPSOCKET_BIND_WRONG_TYPE | SHOULD |
|
||||
| 29 | TCPSOCKET_BIND_ADDRESS | SHOULD |
|
||||
| 30 | TCPSOCKET_BIND_UNOPENED | SHOULD |
|
||||
| 31 | TCPSOCKET_CONNECT_INVALID | MUST |
|
||||
| 32 | TCPSOCKET_SEND_REPEAT | MUST |
|
||||
| 33 | TCPSOCKET_ECHOTEST | MUST |
|
||||
| 34 | TCPSOCKET_ECHOTEST_NONBLOCK | MUST |
|
||||
| 35 | TCPSOCKET_RECV_TIMEOUT | SHOULD |
|
||||
| 36 | TCPSOCKET_SEND_TIMEOUT | SHOULD |
|
||||
| 37 | TCPSOCKET_ENDPOINT_CLOSE | MUST |
|
||||
| 38 | UDPSOCKET_ECHOTEST_BURST | MUST |
|
||||
| 39 | UDPSOCKET_ECHOTEST_BURST_NONBLOCK | MUST |
|
||||
| 40 | TCPSOCKET_ECHOTEST_BURST | MUST |
|
||||
| 41 | TCPSOCKET_ECHOTEST_BURST_NONBLOCK | MUST |
|
||||
| 42 | TCPSOCKET_RECV_100K | MUST |
|
||||
| 43 | TCPSOCKET_RECV_100K_NONBLOCK | MUST |
|
||||
| 44 | TCPSOCKET_THREAD_PER_SOCKET_SAFETY | MUST |
|
||||
| 45 | TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID | SHOULD |
|
||||
| 46 | TLSSOCKET_OPEN_DESTRUCT | SHOULD |
|
||||
| 47 | TLSSOCKET_OPEN_LIMIT | SHOULD |
|
||||
| 48 | TLSSOCKET_OPEN_TWICE | SHOULD |
|
||||
| 49 | TLSSOCKET_CONNECT_INVALID | SHOULD |
|
||||
| 50 | TLSSOCKET_HANDSHAKE_INVALID | SHOULD |
|
||||
| 51 | TLSSOCKET_SEND_CLOSED | SHOULD |
|
||||
| 52 | TLSSOCKET_SEND_UNCONNECTED | SHOULD |
|
||||
| 53 | TLSSOCKET_SEND_REPEAT | SHOULD |
|
||||
| 54 | TLSSOCKET_SEND_TIMEOUT | SHOULD |
|
||||
| 55 | TLSSOCKET_ECHOTEST | SHOULD |
|
||||
| 56 | TLSSOCKET_ECHOTEST_NONBLOCK | SHOULD |
|
||||
| 57 | TLSSOCKET_ENDPOINT_CLOSE | SHOULD |
|
||||
| 58 | TLSSOCKET_NO_CERT | SHOULD |
|
||||
| 59 | TLSSOCKET_RECV_TIMEOUT | SHOULD |
|
||||
| 60 | TLSSOCKET_SIMULTANEOUS_TEST | SHOULD |
|
||||
| 61 | TLSSOCKET_ECHOTEST_BURST | SHOULD |
|
||||
| 62 | TLSSOCKET_ECHOTEST_BURST_NONBLOCK | SHOULD |
|
||||
|
||||
|
||||
|
||||
Building test binaries
|
||||
|
@ -242,10 +260,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 +327,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": {
|
||||
"*": {
|
||||
|
@ -336,7 +366,10 @@ Test cases for Socket class
|
|||
These test are equal for UDPSocket and TCPSocket but are described here
|
||||
because of identical API and behaviour. Socket class is abstract so it
|
||||
cannot be instantiated, therefore these test cases are implemented using
|
||||
both TCPSocket and UDPSocket.
|
||||
both TCPSocket and UDPSocket. Some of these tests are also implemented
|
||||
for TLSSocket class. In such case certificate has to be set for the Socket
|
||||
before calling `open()`, unless specified otherwise in the test's
|
||||
description.
|
||||
|
||||
### SOCKET_OPEN_DESTRUCT
|
||||
|
||||
|
@ -715,19 +748,16 @@ Call `UDPSocket::sendto()` with invalid parameters.
|
|||
1. Call `UDPSocket:sendto( NULL, 9, NULL, 0);`
|
||||
2. Call `UDPSocket:sendto( "", 9, NULL, 0);`
|
||||
3. Call `UDPSocket:sendto( "", 0, NULL, 0);`
|
||||
4. Call `UDPSocket:sendto(NULL, 9, "hello", 5);`
|
||||
5. Call `UDPSocket:sendto(NULL, 0, "hello", 5);`
|
||||
6. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9,NULL, 0);`
|
||||
7. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9, "hello", 5);`
|
||||
8. destroy the socket
|
||||
4. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9,NULL, 0);`
|
||||
5. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9, "hello", 5);`
|
||||
6. destroy the socket
|
||||
|
||||
**Expected result:**
|
||||
|
||||
All sendto() calls should return some error code except:
|
||||
|
||||
- step 6 should return 5
|
||||
- step 7 should return 0
|
||||
- step 8 should return 5
|
||||
- step 4 should return 0
|
||||
- step 5 should return 5
|
||||
|
||||
|
||||
|
||||
|
@ -757,41 +787,6 @@ All sendto() calls should return 5.
|
|||
|
||||
|
||||
|
||||
### UDPSOCKET_BIND_SENDTO
|
||||
|
||||
**Description:**
|
||||
|
||||
Bind the socket to specific port before sending. Verify from DUT2 that
|
||||
packet was coming from correct port.
|
||||
|
||||
Requires two devices with LAN connectivity (Eth, WiFi or mesh). For
|
||||
Cellular or WAN connectivity, skip this test.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. UDPSocket is open
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. DUT1&2: Call `UDPSocket::bind(<unuser port number>);`
|
||||
2. DUT2: Get devices IP address
|
||||
3. DUT1: Call `UDPSocket::sendto( dut2, port, "hello", 5);`
|
||||
4. DUT2: Call `UDPSocket::recvfrom();`
|
||||
5. destroy the sockets
|
||||
|
||||
**Expected result:**
|
||||
|
||||
`UDPSocket::bind()` should return NSAPI_ERROR_OK.
|
||||
|
||||
`UDPSocket::sendto()` call should return 5.
|
||||
|
||||
`UDPSocket::recvfrom()` should return 5 and port number should match the
|
||||
one used in bind() call. Data should contain "hello"
|
||||
|
||||
|
||||
|
||||
### UDPSOCKET_ECHOTEST
|
||||
|
||||
**Description:**
|
||||
|
@ -996,7 +991,7 @@ Call `TCPSocket::connect()` with invalid parameters.
|
|||
|
||||
**Expected result:**
|
||||
|
||||
All connect() calls should return some error code except the number 5
|
||||
All connect() calls should return some error code except the number 4
|
||||
should return NSAPI_ERROR_OK.
|
||||
|
||||
|
||||
|
@ -1220,52 +1215,30 @@ Test we are able to request setting valid TCP keepalive values
|
|||
`TCPSocket::getsockopt(keepalive)` returns same value as was set with
|
||||
`TCPSocket::setsockopt()` or NSAPI_ERROR_UNSUPPORTED
|
||||
|
||||
### TCPSOCKET_SETSOCKOPT_KEEPALIVE_INVALID
|
||||
|
||||
**Description:**
|
||||
|
||||
Test we are able to detect if an invalid TCP keepalive value is tried to
|
||||
be set
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. Call `TCPSocket::setsockopt(keepalive, [-1 or 7201]);`
|
||||
2. Call `TCPSocket::getsockopt(keepalive);`
|
||||
|
||||
**Postconditions:**
|
||||
|
||||
1. Call `TCPSocket::close();`
|
||||
2. delete socket
|
||||
|
||||
**Expected result:**
|
||||
|
||||
`TCPSocket::setsockopt(keepalive)` returns error code or
|
||||
NSAPI_ERROR_UNSUPPORTED
|
||||
|
||||
`TCPSocket::getsockopt()` returns 0 or NSAPI_ERROR_UNSUPPORTED
|
||||
|
||||
|
||||
Test cases for TCPServer class
|
||||
Test cases for TLSSocket class
|
||||
------------------------------
|
||||
|
||||
These tests require two devices under test and connectivity between
|
||||
them. Therefore they can only be ran with LAN connectivity (Eth, Wifi or
|
||||
Mesh) or if there is no firewall between devices.
|
||||
### TLSSOCKET_OPEN_DESTRUCT
|
||||
|
||||
**Description:** Run SOCKET_OPEN_DESTRUCT for TLSSocket
|
||||
|
||||
### TCPSERVER_ACCEPT
|
||||
### TLSSOCKET_OPEN_LIMIT
|
||||
|
||||
**Description:** Run SOCKET_OPEN_LIMIT for TLSSocket
|
||||
|
||||
### TLSSOCKET_OPEN_TWICE
|
||||
|
||||
**Description:** Run SOCKET_OPEN_TWICE for TLSSocket
|
||||
|
||||
### TLSSOCKET_CONNECT_INVALID
|
||||
|
||||
**Description:** Run SOCKET_CONNECT_INVALID for TLSSocket
|
||||
|
||||
### TLSSOCKET_HANDSHAKE_INVALID
|
||||
|
||||
**Description:**
|
||||
|
||||
Test that `TCPServer::bind()`, `TCPServer::listen()`
|
||||
and `TCPServer::accept()` works.
|
||||
|
||||
Requires 2 devices.
|
||||
Execute TLS handshake by calling `TLSSocket::connect()` - server must not match to the certificate used by to os.mbed.com
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
|
@ -1274,34 +1247,20 @@ Requires 2 devices.
|
|||
|
||||
**Test steps:**
|
||||
|
||||
1. DUT1: `TCPServer::bind(<port>)`
|
||||
2. DUT1: `TCPServer::listen()`
|
||||
3. DUT1: Create a new `TCPSocket`
|
||||
4. DUT1: `TCPServer::accept()`
|
||||
5. DUT2: Create a new `TCPSocket`
|
||||
6. DUT2: `TCPSocket::connect(<dut1>, <port>)`
|
||||
7. DUT1: should receive new socket from accept(),
|
||||
call `TCPSocket::send("hello",5)` for it
|
||||
8. DUT2: call `TCPSocket::recv(buffer, 5)`
|
||||
9. DUT2: Verify that it received "hello"
|
||||
10. destroy all sockets.
|
||||
1. Create TLSSocket
|
||||
2. Call `TLSSocket::open()`
|
||||
3. Call `TLSSocket::connect("os.mbed.com", 2009)`
|
||||
4. Call `TLSSocket::close()`
|
||||
|
||||
**Expected result:**
|
||||
|
||||
On DUT1 accept() call blocks until connection is received. Other calls
|
||||
should return NSAPI_ERROR_OK
|
||||
TLSSocket::connect must return an error
|
||||
|
||||
On DUT2 all calls should return NSAPI_ERROR_OK
|
||||
|
||||
|
||||
|
||||
### TCPSERVER_LISTEN
|
||||
### TLSSOCKET_SEND_CLOSED
|
||||
|
||||
**Description:**
|
||||
|
||||
Test that `TCPServer::listen()` has the backlog functionality.
|
||||
|
||||
Requires 2 devices.
|
||||
Make a HTTP request to a closed socket
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
|
@ -1310,34 +1269,29 @@ Requires 2 devices.
|
|||
|
||||
**Test steps:**
|
||||
|
||||
1. DUT1: `TCPServer::bind(<port>)`
|
||||
2. DUT1: `TCPServer::listen(2)`
|
||||
3. loop 2 times:
|
||||
1. DUT2: Create a new TCPSocket
|
||||
2. DUT2: `TCPSocket::connect(<dut1>, <port>)`
|
||||
|
||||
4. loop 2 times:
|
||||
1. DUT1: Create a new TCPSocket
|
||||
2. DUT1: `TCPServer::accept()`
|
||||
3. DUT1: should receive new socket from accept(),
|
||||
call `TCPSocket::send("hello",5)` for it
|
||||
|
||||
5. DUT2: call `TCPSocket::recv(buffer, 5)` for both socket.
|
||||
6. DUT2: Verify that it received "hello"
|
||||
7. destroy all sockets.
|
||||
1. Create TLSSocket
|
||||
2. Call `TLSSocket::open()`
|
||||
3. Call `TLSSocket::connect("echo.mbedcloudtesting.com", 2007)`
|
||||
4. Call `TLSSocket::close()`
|
||||
5. Call `TLSSocket::send("12345", 5)`
|
||||
|
||||
**Expected result:**
|
||||
|
||||
DUT2 should receive connection before the server have called accept(),
|
||||
because backlog must be minimum of 2.
|
||||
TLSSocket::send must return an error
|
||||
|
||||
### TLSSOCKET_SEND_REPEAT
|
||||
|
||||
### TCPSERVER_LISTEN_WITHOUT_BIND
|
||||
**Description:** Run SOCKET_SEND_REPEAT for TLSSOCKET by using port number 2009.
|
||||
|
||||
**Description:**
|
||||
### TLSSOCKET_SEND_TIMEOUT
|
||||
|
||||
Call `TCPServer::listen()` without calling bind() first. Should fail,
|
||||
because no listening port have been defined.
|
||||
**Description:** Run SOCKET_SEND_TIMEOUT for TLSSOCKET by using port number 2009.
|
||||
|
||||
### TLSSOCKET_SEND_UNCONNECTED
|
||||
|
||||
**Description:**
|
||||
|
||||
Make a HTTP request to an unconnected socket
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
|
@ -1346,22 +1300,32 @@ because no listening port have been defined.
|
|||
|
||||
**Test steps:**
|
||||
|
||||
1. Create TCPServer
|
||||
2. Call `TCPServer::listen()`
|
||||
1. Create TLSSocket
|
||||
2. Call `TLSSocket::open()`
|
||||
3. Call `TLSSocket::send("12345", 5)`
|
||||
4. Call `TLSSocket::connect("echo.mbedcloudtesting.com", 2007)`
|
||||
|
||||
**Expected result:**
|
||||
|
||||
Should
|
||||
return NSAPI_ERROR_UNSUPPORTED, NSAPI_ERROR_PARAMETER, NSAPI_ERROR_NO_ADDRESS
|
||||
or NSAPI_ERROR_DEVICE_ERROR
|
||||
TLSSocket::send must return an error
|
||||
|
||||
### TLSSOCKET_ECHOTEST
|
||||
|
||||
### TCPSERVER_ACCEPT_WITHOUT_LISTEN
|
||||
**Description:** Run SOCKET_ECHOTEST for TLSSOCKET by using port number 2007.
|
||||
|
||||
### TLSSOCKET_ECHOTEST_NONBLOCK
|
||||
|
||||
**Description:** Run SOCKET_ECHOTEST_NONBLOCK for TLSSOCKET by using port number 2007.
|
||||
|
||||
### TLSSOCKET_ENDPOINT_CLOSE
|
||||
|
||||
**Description:** Run SOCKET_ENDPOINT_CLOSE for TLSSOCKET by using port number 2013.
|
||||
|
||||
### TLSSOCKET_NO_CERT
|
||||
|
||||
**Description:**
|
||||
|
||||
Call `TCPServer::accept()` without calling listen() first. Should fail,
|
||||
because socket is not listening for connections.
|
||||
Verify that TLS Socket fails to connect without certificate.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
|
@ -1370,16 +1334,60 @@ because socket is not listening for connections.
|
|||
|
||||
**Test steps:**
|
||||
|
||||
1. Create TCPServer
|
||||
2. Call `TCPServer::bind(<unused port number>)`
|
||||
3. Create new TCPSocket.
|
||||
4. Call `TCPServer::accept()`
|
||||
1. Create TLSSocket, without adding a default certificate.
|
||||
2. Call `TLSSocket::open()`
|
||||
3. Call `TLSSocket::connect("echo.mbedcloudtesting.com", 2009)`
|
||||
|
||||
**Expected result:**
|
||||
|
||||
Should return NSAPI_ERROR_UNSUPPORTED, NSAPI_ERROR_PARAMETER
|
||||
or NSAPI_ERROR_DEVICE_ERROR
|
||||
TLSSocket::connect must return an error if the certificate is not present.
|
||||
|
||||
### TLSSOCKET_RECV_TIMEOUT
|
||||
|
||||
**Description:**
|
||||
|
||||
Run TCPSOCKET_RECV_TIMEOUT for TLSSOCKET by using port number 2007.
|
||||
|
||||
### TLSSOCKET_SIMULTANEOUS_TEST
|
||||
|
||||
**Description:**
|
||||
|
||||
Simultaneously send packets to echo server on two opened sockets and read incoming packets back. Verify working of two TLS sockets open and operate simultaneously.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. TLSSockets are open and one additional thread has been created
|
||||
|
||||
4. Both threads get their own socket instance
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. On main thread:
|
||||
1. Call `TLSSocket::connect("echo.mbedcloudtesting.com", 2007);`
|
||||
2. Call `TLSSocket::send(<random packet, size = loop index>, <loop index>);`
|
||||
1. If less than <loop index> was returned, size = sent bytes
|
||||
|
||||
3. `Call TLSSocket::recv(buffer, <size>);`
|
||||
4. Verify incomming content was the same that was sent
|
||||
5. Repeat 100 times
|
||||
|
||||
2. Simultaneously with the earlier step do on the additional thread:
|
||||
1. Call `TLSSocket::connect("echo.mbedcloudtesting.com", 2007);`
|
||||
2. Call `TLSSocket::send(<random packet, size = loop index>, <loop index>);`
|
||||
1. If less than <loop index> was returned, size = sent bytes
|
||||
|
||||
3. Call `TLSSocket::recv(buffer, <size>);`
|
||||
4. Verify incomming content was the same that was sent
|
||||
5. Repeat 100 times
|
||||
|
||||
3. Wait for end additional thread
|
||||
4. Close and destroy the sockets
|
||||
|
||||
**Expected result:**
|
||||
|
||||
All send() calls should return the packet size or less. All recv() calls on main thread should return the same sized packet that was send with same content. All recv() calls on additional thread should return the valid daytime string .
|
||||
|
||||
Performance tests
|
||||
-----------------
|
||||
|
@ -1393,9 +1401,9 @@ Send burst of packets to echo server and read incoming packets back.
|
|||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. UDPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. UDPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1407,8 +1415,8 @@ Send burst of packets to echo server and read incoming packets back.
|
|||
6. Wait for incomming packets for five second.
|
||||
7. Verify incomming content was the same that was sent. Allow
|
||||
packet reordering.
|
||||
8. Repeat 100 times
|
||||
9. destroy the socket
|
||||
8. Repeat 100 times.
|
||||
9. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1417,9 +1425,9 @@ All sendto() calls should return the packet size.
|
|||
All recvfrom() calls should return the same sized packet that was send
|
||||
with same content. Allow packet reordering.
|
||||
|
||||
Calculate packet loss rate, maximum tolerated packet loss rate is 30%
|
||||
Calculate packet loss rate, maximum tolerated packet loss rate is 30%.
|
||||
|
||||
Calculate number of succesfull rounds, it should be higher than 70
|
||||
Calculate number of succesfull rounds, it should be higher than 70.
|
||||
|
||||
|
||||
### UDPSOCKET_ECHOTEST_BURST_NONBLOCK
|
||||
|
@ -1427,13 +1435,13 @@ Calculate number of succesfull rounds, it should be higher than 70
|
|||
**Description:**
|
||||
|
||||
Send burst of packets to echo server and read incoming packets back. Use
|
||||
socket in non-blocking mode
|
||||
socket in non-blocking mode.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. UDPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. UDPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1449,8 +1457,8 @@ socket in non-blocking mode
|
|||
9. Wait for incomming packets for five second.
|
||||
10. Verify incomming content was the same that was sent. Allow
|
||||
packet reordering.
|
||||
11. Repeat 100 times
|
||||
12. destroy the socket
|
||||
11. Repeat 100 times.
|
||||
12. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1459,9 +1467,9 @@ All sendto() calls should return the packet size.
|
|||
All recvfrom() calls should return the same sized packet that was send
|
||||
with same content. Allow packet reordering.
|
||||
|
||||
Calculate packet loss rate, maximum tolerated packet loss rate is 30%
|
||||
Calculate packet loss rate, maximum tolerated packet loss rate is 30%.
|
||||
|
||||
Calculate number of succesfull rounds, it should be higher than 70
|
||||
Calculate number of succesfull rounds, it should be higher than 70.
|
||||
|
||||
|
||||
|
||||
|
@ -1473,9 +1481,9 @@ Send burst of packets to echo server and read incoming packets back.
|
|||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. TCPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. TCPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1487,8 +1495,8 @@ Send burst of packets to echo server and read incoming packets back.
|
|||
6. Call `TCPSocket::send(<random packet, size = 500>, 500);`
|
||||
7. Call `TCPSocket::recv(buf, 1220)`
|
||||
8. Verify incomming content was the same that was sent.
|
||||
9. Repeat 100 times
|
||||
10. destroy the socket
|
||||
9. Repeat 100 times.
|
||||
10. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1507,13 +1515,13 @@ send. Total amount of returned must match 1220.
|
|||
**Description:**
|
||||
|
||||
Send burst of packets to echo server and read incoming packets back. Use
|
||||
socket in non-blocking mode
|
||||
socket in non-blocking mode.
|
||||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. TCPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. TCPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1525,13 +1533,13 @@ socket in non-blocking mode
|
|||
5. For randomly generated packets, sized 100, 200, 300, 120 and 500 do
|
||||
1. Call `TCPSocket::send(packet, size);`
|
||||
2. If less than size is sent, repeat with remaining.
|
||||
3. If NSAPI_ERROR_WOULD_BLOCK returned, wait for next sigio()
|
||||
3. If NSAPI_ERROR_WOULD_BLOCK returned, wait for next sigio().
|
||||
|
||||
6. Wait for incomming packets for five second.
|
||||
7. Verify incomming content was the same that was sent. Allow recv() to
|
||||
return smaller piezes.
|
||||
8. Repeat 100 times
|
||||
9. destroy the socket
|
||||
8. Repeat 100 times.
|
||||
9. Destroy the socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1553,9 +1561,9 @@ Download 100kB of data
|
|||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. TCPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. TCPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1563,7 +1571,7 @@ Download 100kB of data
|
|||
2. Call `TCPSocket::recv(buffer, 100);`
|
||||
3. Verify input according to known pattern.
|
||||
4. Loop until 100kB of data received.
|
||||
5. close socket.
|
||||
5. Close socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1580,9 +1588,9 @@ Download 100kB of data
|
|||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. TCPSocket is open
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. TCPSocket is open.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
|
@ -1594,7 +1602,7 @@ Download 100kB of data
|
|||
2. Verify input according to known pattern.
|
||||
|
||||
4. Wait until 100kB of data received.
|
||||
5. close socket.
|
||||
5. Close socket.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
|
@ -1602,7 +1610,7 @@ Each recv() call should return equal or less than 100 bytes of data or
|
|||
NSAPI_ERROR_WOULD_BLOCK in which case thread should wait for another
|
||||
sigio(). No errors should be returned.
|
||||
|
||||
Measure time taken for receiving, report speed
|
||||
Measure time taken for receiving, report speed.
|
||||
|
||||
### TCPSOCKET_THREAD_PER_SOCKET_SAFETY
|
||||
|
||||
|
@ -1613,16 +1621,16 @@ through a dedicated socket
|
|||
|
||||
**Preconditions:**
|
||||
|
||||
1. Network interface and stack are initialised
|
||||
2. Network connection is up
|
||||
3. 2 TCPSockets are open and one additional thread has been created
|
||||
4. Both threads get their own socket instance
|
||||
1. Network interface and stack are initialised.
|
||||
2. Network connection is up.
|
||||
3. 2 TCPSockets are open and one additional thread has been created.
|
||||
4. Both threads get their own socket instance.
|
||||
|
||||
**Test steps:**
|
||||
|
||||
1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7)`
|
||||
in both threads - in the main thread executing the test case and on
|
||||
the additional one;
|
||||
the additional one.
|
||||
2. On main thread
|
||||
1. For randomly generated packets, sized 1001, 901, 801,...,101,1
|
||||
do
|
||||
|
@ -1638,21 +1646,19 @@ through a dedicated socket
|
|||
3. stop the thread if inconsistensies were found and report it
|
||||
to main thread
|
||||
|
||||
4. Kill the additional thread
|
||||
5. Close and destroy the sockets
|
||||
4. Kill the additional thread.
|
||||
5. Close and destroy the sockets.
|
||||
|
||||
**Expected result:**
|
||||
|
||||
Echo server returns data to both threads and received data matches to
|
||||
send data. The additional thread isn't stopped prematurely
|
||||
send data. The additional thread isn't stopped prematurely.
|
||||
|
||||
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 +1677,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.
|
||||
|
|
|
@ -0,0 +1,222 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||
|
||||
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),
|
||||
#ifndef __IAR_SYSTEMS_ICC__
|
||||
Case("TLSSOCKET_SIMULTANEOUS", TLSSOCKET_SIMULTANEOUS)
|
||||
#endif
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#else
|
||||
#error [NOT_SUPPORTED] This device does not support SSL library
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
#include "TLSSocket.h"
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||
|
||||
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 // defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
|
||||
|
||||
#endif //TLS_TESTS_H
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -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 "TLSSocket.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
#include "tls_tests.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // defined(MBEDTLS_SSL_CLI_C)
|
|
@ -97,6 +97,7 @@ Case cases[] = {
|
|||
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
|
||||
Case("UDPSOCKET_OPEN_CLOSE_REPEAT", UDPSOCKET_OPEN_CLOSE_REPEAT),
|
||||
Case("UDPSOCKET_OPEN_LIMIT", UDPSOCKET_OPEN_LIMIT),
|
||||
Case("UDPSOCKET_RECV_TIMEOUT", UDPSOCKET_RECV_TIMEOUT),
|
||||
Case("UDPSOCKET_SENDTO_TIMEOUT", UDPSOCKET_SENDTO_TIMEOUT),
|
||||
Case("UDPSOCKET_OPEN_DESTRUCT", UDPSOCKET_OPEN_DESTRUCT),
|
||||
Case("UDPSOCKET_OPEN_TWICE", UDPSOCKET_OPEN_TWICE),
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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\""
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue