diff --git a/TESTS/netsocket/README.md b/TESTS/netsocket/README.md new file mode 100644 index 0000000000..7922826ac7 --- /dev/null +++ b/TESTS/netsocket/README.md @@ -0,0 +1,1666 @@ +Network Socket test plan +======================== + +This is a test plan for the Mbed OS Socket API. This describes all test +cases and their intended behaviors. When an API document is not clear, use +this as a reference for implementing correct behavior. + +**NOTE:** Because testing is a moving target, this test plan might define more test cases than Mbed OS +implements. Refer to [test case priorities](#test-case-priorities) for a list of test cases that the target must pass to be compliant with the Mbed OS socket API. + + +Target API +---------- + +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). + +Reference documentation: https://os.mbed.com/docs/latest/reference/network-socket.html + +Tools to use +---------------- + +- Mbed OS. +- Standard Mbed OS development tools as described in https://os.mbed.com/docs/latest/tools/index.html. +- Test server. + +These test cases themselves do not require any special tooling, other than +the test server described in "Test environment" chapter. + +Test environment +---------------- + +As a general guideline, network connectivity with public Internet access +is required. This satisfies Socket tests, but specific connectivity +methods might require some extra configuration or devices within the +network. + +The test environment consist of DUTs, network connection and the test +server. Arm provides a public test server, but it can be installed locally +as well, if an isolated test environment is required. + +### Public test server + +Address: `echo.mbedcloudtesting.com` + +Both IPv4 and IPv6 addresses are available from a public DNS service: + +```.sh +$ host echo.mbedcloudtesting.com +echo.mbedcloudtesting.com has address 52.215.34.155 +echo.mbedcloudtesting.com has IPv6 address 2a05:d018:21f:3800:8584:60f8:bc9f:e614 +``` + +**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. +- Discard protocol, [RFC 863](https://tools.ietf.org/html/rfc863) is + enabled in both TCP and UDP. Port 9. +- 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. +- Time protocol, [RFC 868](https://tools.ietf.org/html/rfc868) in + both TCP and UDP. Port 37. + +Configure the firewall to allow this traffic to access the test server. + +**Example configuration for Debian/Ubuntu Linux** + +These services are available on many operating systems, and installing them is out of +scope of this document. Below is an +example of how to install these services into a Debian/Ubuntu based Linux distribution +using standard Inet Daemon: + +```.sh +$ sudo apt install inetutils-inetd +$ nano /etc/inetd.conf +``` + +Enable following services from /etc/inetd.conf: + +``` +#:INTERNAL: Internal services +discard stream tcp6 nowait root internal +discard dgram udp6 wait root internal +echo stream tcp6 nowait root internal +echo dgram udp6 wait root internal +chargen stream tcp6 nowait root internal +chargen dgram udp6 wait root internal +daytime stream tcp6 nowait root internal +time stream tcp6 nowait root internal +``` + +**Testing the connectivity** + +You can connect to the test server with an NMAP tool like this: + +```.sh +$ nmap -sT -p7,9,13,37 echo.mbedcloudtesting.com + +Starting Nmap 7.12 ( https://nmap.org ) at 2018-04-05 16:17 EEST +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 +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 + +Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds + +$ sudo nmap -sT -p7,9,13,37 echo.mbedcloudtesting.com + +Starting Nmap 7.12 ( https://nmap.org ) at 2018-04-05 16:16 EEST +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 +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 + +Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds +``` + +### Ethernet test environment + +![Ethernet](eth_environment.png) + +The Ethernet test environment consists of devices, an ethernet switch and an optional +firewall that allows connecting to the Echo server. + +### Wi-Fi test environment + +![Wi-Fi](wifi_environment.png) + +The Wi-Fi test environment is equivalent to the Ethernet test environment, except that the +Wi-Fi test environment has two separate access points or one with dual SSID. Connectivity to +echo server is required, but it can be hosted locally, as specified in +the Ethernet environment. + +Test case priorities +-------------------- + +Please refer to the following table for priorities of test cases. Priorities +are labeled as MUST and SHOULD. MUST means this is a requirement and +therefore mandatory to pass the test. SHOULD means it is recommended to +pass the test if the driver implements the feature in question. + +| | Test case | Priority | +|-----|-----------------------------------------|----------| +| 1 | UDPSOCKET_OPEN_DESTRUCT | MUST | +| 2 | UDPSOCKET_OPEN_LIMIT | MUST | +| 3 | UDPSOCKET_OPEN_TWICE | MUST | +| 4 | UDPSOCKET_OPEN_CLOSE_REPEAT | MUST | +| 5 | UDPSOCKET_BIND_PORT | SHOULD | +| 6 | UDPSOCKET_BIND_PORT_FAIL | SHOULD | +| 7 | UDPSOCKET_BIND_ADDRESS_PORT | SHOULD | +| 8 | UDPSOCKET_BIND_ADDRESS_NULL | SHOULD | +| 9 | UDPSOCKET_BIND_ADDRESS_INVALID | SHOULD | +| 10 | UDPSOCKET_BIND_WRONG_TYPE | SHOULD | +| 11 | UDPSOCKET_BIND_ADDRESS | SHOULD | +| 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 | + + +Building test binaries +-------------------------- + +For testing the board and driver, test against the Mbed OS +master branch to get the most recent, up-to-date test cases and drivers. + +To create a build environment: + +```.sh +mbed new network_test +cd network_test +cd mbed-os +git checkout master +cd .. +``` + +Also, building socket test cases requires a special macro to +enable all tests, so create an `mbed_app.json` file with the following +content at minimum: + +``` +{ + "macros": ["MBED_EXTENDED_TESTS"] +} +``` + +Wi-Fi tests require some more configuration, so for Wi-Fi purposes, +the `mbed_app.json` might look like this: + +``` +{ + "config": { + "wifi-secure-ssid": { + "help": "WiFi SSID for WPA2 secured network", + "value": "\"test-network\"" + }, + "wifi-unsecure-ssid": { + "help": "WiFi SSID for unsecure netwrok", + "value": "\"unsecure-test-net\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"password\"" + }, + "wifi-secure-protocol": { + "help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2", + "value": "\"WPA2\"" + }, + "wifi-ch-secure": { + "help": "Channel number of secure SSID", + "value": 6 + }, + "wifi-ch-unsecure": { + "help": "Channel number of unsecure SSID", + "value": 6 + }, + "ap-mac-secure": { + "help": "BSSID of secure AP in form of AA:BB:CC:DD:EE:FF", + "value": "\"58:8b:f3:99:f2:9c\"" + }, + "ap-mac-unsecure": { + "help": "BSSID of unsecure AP in form of \"AA:BB:CC:DD:EE:FF\"", + "value": "\"58:8b:f3:99:c2:08\"" + }, + "max-scan-size": { + "help": "How many networks may appear in Wifi scan result", + "value": 30 + }, + "header-file": { + "help" : "String for including your driver header file", + "value" : "\"MyWifiInterface.h\"" + }, + "object-construction" : { + "value" : "new MyWifiInterface()" + }, + "connect-statement" : { + "help" : "Must use 'net' variable name", + "value" : "net->wifiInterface()->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2)" + }, + "echo-server-addr" : { + "help" : "IP address of echo server", + "value" : "\"echo.mbedcloudtesting.com\"" + }, + "echo-server-port" : { + "help" : "Port of echo server", + "value" : "7" + } + }, + "macros": ["MBED_EXTENDED_TESTS"] +} +``` + +Now build test binaries: + +```.sh +mbed test --compile -t -m -n mbed-os-tests-network-*,mbed-os-tests-netsocket* +``` + +Running tests +------------- + +When device is connected to network, or in case of wireless device near +the access point. + +```.sh +mbed test -n mbed-os-tests-network-*,mbed-os-tests-netsocket* +``` + +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. + +### SOCKET_OPEN_DESTRUCT + +**Description:** + +Call `Socket::open()` and then destruct the socket + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call "delete" for the object +4. Repeat 1000 times. + +**Expected result:** + +`Socket::open()` should always return NSAPI_ERROR_OK + + + +### SOCKET_OPEN_LIMIT + +**Description:** + + Call `Socket::open()` until it runs out of memory or other internal limit +in the stack is reached. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. repeat until `NSAPI_ERROR_NO_MEMORY` or `NSAPI_ERROR_NO_SOCKET` + error is returned. +4. Call "delete" for all previously allocated sockets. +5. repeat + +**Expected result:** + +Should be able to reserve at least 4 sockets. After freeing all sockets, +should be able to reserve same number of sockets. + + + +### SOCKET_OPEN_TWICE + +**Description:** + +Call `Socket::open()` twice + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call `Socket::open(stack)` +4. delete the socket + +**Expected result:** + +`Socket::open()` should first return `NSAPI_ERROR_OK` and second +call `NSAPI_ERROR_PARAMETER`. + + + +### SOCKET_OPEN_CLOSE_REPEAT + +**Description:** + +Call `Socket::open()` followed by `Socket::close()` and then again +`Socket::open()`. Should allow you to reuse the same object. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call `Socket::close(stack)` +4. Call `Socket::open(stack)` +5. Call `Socket::close(stack)` +6. delete the socket + +**Expected result:** + +All `Socket::open()` and `Socket::close()` calls should return +NSAPI_ERROR_OK. + + +### SOCKET_BIND_PORT + +**Description:** + +Call `Socket::bind(port)` + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call `Socket::bind();` +4. destroy socket + +**Expected result:** + +All calls return NSAPI_ERROR_OK + + + +### SOCKET_BIND_PORT_FAIL + +**Description:** + +Call `Socket::bind(port)` on port number that is already used + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call `Socket::bind();` +4. Repeat 1-3 for a new socket. +5. destroy both sockets + +**Expected result:** + +Second `Socket::bind()` should return NSAPI_ERROR_PARAMETER + + + +### SOCKET_BIND_ADDRESS_PORT + +**Description:** + +Call `Socket::bind(addr, port)` + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Get address by calling NetworkInterface::get_ip_address(); +4. Call `Socket::bind(address, );` +5. destroy socket + +**Expected result:** + +All calls return NSAPI_ERROR_OK + + + +### SOCKET_BIND_ADDRESS_NULL + +**Description:** + +Call `Socket::bind(NULL, port)` + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Call `Socket::bind(NULL, );` +4. destroy socket + +**Expected result:** + +`Socket::bind()` should return NSAPI_ERROR_OK + + + +### SOCKET_BIND_ADDRESS_INVALID + +**Description:** + +Call `Socket::bind(address, port)` with and address that is not assigned +to us. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Check whether device is IPv4 or IPv6 connected. + 1. For IPv4: Call `Socket::bind("190.2.3.4", );` + 2. For IPv6: Call `Socket::bind("fe80::ff01", );` + +4. destroy socket + +**Expected result:** + +`Socket::bind()` should return NSAPI_ERROR_PARAMETER + + + +### SOCKET_BIND_ADDRESS_WRONG_TYPE + +**Description:** + +Call `Socket::bind(SocketAddress)` with and address that is not wrong type +for the connection. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Check whether device is IPv4 or IPv6 connected. + 1. For IPv4: Create `SocketAddress("fe80::ff01", );` + 2. For IPv6: Create `SocketAddress("190.2.3.4", );` + +4. Call `Socket::bind(address);` +5. destroy socket + +**Expected result:** + +`Socket::bind()` should return NSAPI_ERROR_PARAMETER + + + +### SOCKET_BIND_ADDRESS + +**Description:** + +Call `Socket::bind(SocketAddress)` + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::open(stack)` +3. Get address by calling NetworkInterface::get_ip_address(); +4. Create a SocketAddress object using this address and any non-used + port number. +5. Call `Socket::bind(address);` +6. destroy socket + +**Expected result:** + +All calls return NSAPI_ERROR_OK + + + +### SOCKET_BIND_UNOPENED + +**Description:** + +Call `Socket::bind()` on socket that has not been opened + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create a object by calling `new Socket()` +2. Call `Socket::bind();` +3. destroy socket + +**Expected result:** + +NSAPI_ERROR_NO_SOCKET + + + +Test cases for UDPSocket class +------------------------------ + +### UDPSOCKET_OPEN_DESTRUCT + +**Description:** Run SOCKET_OPEN_DESTRUCT for UDPSocket + +### UDPSOCKET_OPEN_LIMIT + +**Description:** Run SOCKET_OPEN_LIMIT for UDPSocket + +### UDPSOCKET_OPEN_TWICE + +**Description:** Run SOCKET_OPEN_TWICE for UDPSocket + +### UDPSOCKET_OPEN_CLOSE_REPEAT + +**Description:** Run SOCKET_OPEN_CLOSE_REPEAT for UDPSocket + +### UDPSOCKET_BIND_PORT + +**Description:** Run SOCKET_BIND_PORT for UDPSocket + +### UDPSOCKET_BIND_PORT_FAIL + +**Description:** Run SOCKET_BIND_PORT_FAIL for UDPSocket + +### UDPSOCKET_BIND_ADDRESS_PORT + +**Description:** Run SOCKET_BIND_ADDRESS_PORT for UDPSocket + +### UDPSOCKET_BIND_ADDRESS_NULL + +**Description:** Run SOCKET_BIND_ADDRESS_NULL for UDPSocket + +### UDPSOCKET_BIND_ADDRESS_INVALID + +**Description:** Run SOCKET_BIND_ADDRESS_INVALID for UDPSocket + +### UDPSOCKET_BIND_WRONG_TYPE + +**Description:** Run SOCKET_BIND_WRONG_TYPE for UDPSocket + +### UDPSOCKET_BIND_ADDRESS + +**Description:** Run SOCKET_BIND_ADDRESS for UDPSocket + +### UDPSOCKET_BIND_UNOPENED + +**Description:** Run SOCKET_BIND_UNOPENED for UDPSocket + +### UDPSOCKET_SENDTO_INVALID + +**Description:** + +Call `UDPSocket::sendto()` with invalid parameters. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. UDPSocket is open + +**Test steps:** + +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", 0, "hello", 5);` +7. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9,NULL, 0);` +8. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9, "hello", 5);` +9. 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 + + + +### UDPSOCKET_SENDTO_REPEAT + +**Description:** + +Repeatedly send small packets. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. UDPSocket is open + +**Test steps:** + +1. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 9, "hello", 5);` +2. repeat 100 times +3. Fail if `NSAPI_ERROR_NO_MEMORY` is returned two times in a row, + wait 1 second before retry +4. destroy the socket + +**Expected result:** + +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();` +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:** + +Repeatedly send packets to echo server and read incoming packets back. +Verify working of different packet sizes. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. UDPSocket is open + +**Test steps:** + +1. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , );` +2. Wait for incomming packet. If timeout happens, retry + sending&receiving, max 3 times. +3. Verify incomming content was the same that was sent +4. Repeat 1200 times +5. destroy the socket + +**Expected result:** + +All sendto() calls should return the packet size. All recvfrom() calls +should return the same sized packet that was send with same content. +Calculate packet loss rate, maximum tolerated packet loss rate is 30% + + + +### UDPSOCKET_ECHOTEST_NONBLOCK + +**Description:** + +Repeatedly send packets to echo server and read incoming packets back. +Verify working of different packet sizes. Use socket in non-blocking +mode + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. UDPSocket is open + +**Test steps:** + +1. Call `UDPSocket::set_blocking(false)` +2. Register event handler with `UDPSocket::sigio()` +3. Create another thread that constantly waits signal from sigio() + handler, when received try `UDPSocket::recvfrom()` +4. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , );` +5. Wait for incomming packet for one second. If nothing received retry, + max 3 times. +6. Verify incomming content was the same that was sent +7. Repeat 1200 times +8. destroy the socket + +**Expected result:** + +All sendto() calls should return the packet size. All recvfrom() calls +should return the same sized packet that was send with same content or +NSAPI_ERROR_WOULD_BLOCK. + +Calculate packet loss rate, maximum tolerated packet loss rate is 30% + + + +### UDPSOCKET_RECV_TIMEOUT + +**Description:** + +Test whether timeouts are obeyed in UDPSockets. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Call `UDPSocket::set_timeout(100)` +2. Call `UDPSocket::sendto("echo.mbedcloudtesting.com", 7, , 100);` +3. Repeat 5 times + 1. record a time in millisecond precission + 2. Call `UDPSocket::recvfrom()` + 3. record a time in millisecond precission + +4. repeat testcase 10 times. + +**Expected result:** + +Each `sendto()` calls should return 100. + +Within each loop, one `recvfrom()` may return the received packet size +(100). Other calls should return NSAPI_ERROR_WOULD_BLOCK. + +When NSAPI_ERROR_WOULD_BLOCK is received, check that time consumed is +more that 100 milliseconds but less than 200 milliseconds. + +After repeating for 10 times, at least 5 packets must have been +received. + + +### UDPSOCKET_SENDTO_TIMEOUT + +**Description:** + +Test whether timeouts are obeyed in UDPSockets. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Record time +2. Call `UDPSocket::sendto("echo.mbedcloudtesting.com", 9, , 100);` +3. Record time +4. Call `UDPSocket::set_timeout(1000)` +5. Call `UDPSocket::sendto("echo.mbedcloudtesting.com", 9, , 100);` +6. Record time + +**Expected result:** + +Each sendto() call should return 100. + +All sendto() calls should return faster than 100 milliseconds because +UDP sending should not block that long. + + +Test cases for TCPSocket class +------------------------------ + +### TCPSOCKET_OPEN_DESTRUCT + +**Description:** Run SOCKET_OPEN_DESTRUCT for TCPSocket + +### TCPSOCKET_OPEN_LIMIT + +**Description:** Run SOCKET_OPEN_LIMIT for TCPSocket + +### TCPSOCKET_OPEN_TWICE + +**Description:** Run SOCKET_OPEN_TWICE for TCPSocket + +### TCPSOCKET_OPEN_CLOSE_REPEAT + +**Description:** Run SOCKET_OPEN_CLOSE_REPEAT for TCPSocket + +### TCPSOCKET_BIND_PORT + +**Description:** Run SOCKET_BIND_PORT for TCPSocket + +### TCPSOCKET_BIND_PORT_FAIL + +**Description:** Run SOCKET_BIND_PORT_FAIL for TCPSocket + +### TCPSOCKET_BIND_ADDRESS_PORT + +**Description:** Run SOCKET_BIND_ADDRESS_PORT for TCPSocket + +### TCPSOCKET_BIND_ADDRESS_NULL + +**Description:** Run SOCKET_BIND_ADDRESS_NULL for TCPSocket + +### TCPSOCKET_BIND_ADDRESS_INVALID + +**Description:** Run SOCKET_BIND_ADDRESS_INVALID for TCPSocket + +### TCPSOCKET_BIND_WRONG_TYPE + +**Description:** Run SOCKET_BIND_WRONG_TYPE for TCPSocket + +### TCPSOCKET_BIND_ADDRESS + +**Description:** Run SOCKET_BIND_ADDRESS for TCPSocket + +### TCPSOCKET_BIND_UNOPENED + +**Description:** Run SOCKET_BIND_UNOPENED for TCPSocket + +### TCPSOCKET_CONNECT_INVALID + +**Description:** + +Call `TCPSocket::connect()` with invalid parameters. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket:connect( NULL, 9);` +2. Call `TCPSocket:connect( "", 9);` +3. Call `TCPSocket:connect( "", 0);` +4. Call `TCPSocket:connect( "echo.mbedcloudtesting.com", 0);` +5. Call `TCPSocket:connect( "echo.mbedcloudtesting.com", 9);` +6. destroy the socket + +**Expected result:** + +All connect() calls should return some error code except the number 5 +should return NSAPI_ERROR_OK. + + + +### TCPSOCKET_SEND_REPEAT + +**Description:** + +Repeatedly send small packets. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 9);` +2. Call `TCPSocket::send("hello", 5);` +3. repeat 1000 times +4. destroy the socket + +**Expected result:** + +`TCPSocket::connect()` should return NSAPI_ERROR_OK + +All send() calls should return 5. + + + +### TCPSOCKET_ECHOTEST + +**Description:** + +Repeatedly send packets to echo server and read incoming packets back. +Verify working of different packet sizes. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7);` +2. Call `TCPSocket::send(, );` + 1. If less than was returned, size = sent bytes + +3. Call `TCPSocket::recv(buffer, );` +4. Verify incomming content was the same that was sent +5. Repeat 1200 times +6. destroy the socket + +**Expected result:** + +All send() calls should return the packet size or less. All recv() calls +should return the same sized packet that was send with same content. + +NOTE: This is stream so recv() might return less data than what was +requested. In this case you need to keep calling recv() until all data +that you have sent is returned. + + +### TCPSOCKET_ECHOTEST_NONBLOCK + +**Description:** + +Repeatedly send packets to echo server and read incoming packets back. +Verify working of different packet sizes. Use socket in non-blocking +mode + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7);` +2. Call `TCPSocket::set_blocking(false)` +3. Register event handler with `TCPSocket::sigio()` +4. Create another thread that constantly waits signal from `sigio()` + handler, when received try `TCPSocket::recv(buf+index, - index)`, where index is the amount of data + already received. +5. Call `TCPSocket:send(, );` + 1. If less than was returned, try immeadiately + sending remaining bytes. + 2. If NSAPI_ERROR_WOULD_BLOCK is returned, wait for sigio() call + to happen. + +6. Wait for incomming packet for one second. +7. Verify incomming content was the same that was sent, set index for + receiving thread to zero. +8. Repeat 1200 times +9. destroy the socket + +**Expected result:** + +All send() calls should return the packet size or less. All recv() calls +should return NSAPI_ERROR_WOULD_BLOCK or packet size that is equal or +less than what has been sent. + +### TCPSOCKET_RECV_TIMEOUT + +**Description:** + +Test whether timeouts are obeyed in TCPSockets. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7);` +2. Call `TCPSocket::set_timeout(100);` +3. Call `TCPSocket::send(;, 100);` +4. Repeat 5 times + 1. record a time in millisecond precission + 2. Call `TCPSocket::recv()` + 3. record a time in millisecond precission + +5. repeat testcase 10 times. + +**Expected result:** + +Each send() call should return 100. + +Within each loop, one recv() may return the received packet size (100). +Other calls should return NSAPI_ERROR_WOULD_BLOCK. + +When NSAPI_ERROR_WOULD_BLOCK is received, check that time consumed is +more that 100 milliseconds but less than 200 milliseconds. + + +### TCPSOCKET_SEND_TIMEOUT + +**Description:** + +Repeatedly send small packets in a given time limit + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket:connect("echo.mbedcloudtesting.com", 9);` +3. Call `TCPSocket:set_blocking(false);` +3. Call `TCPSocket:send("hello", 5);` +4. repeat 10 times +5. destroy the socket + +**Expected result:** + +`TCPSocket::connect()` should return NSAPI_ERROR_OK + +All send() calls should return in less than 800 milliseconds + + +### TCPSOCKET_ENDPOINT_CLOSE + +**Description:** + +Test whether we tolerate endpoint closing the connection. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 13);` +2. Call `TCPSocket::recv(, 30);` +3. Repeat until recv() returns 0 +4. Call `TCPSocket::close();` +5. delete socket + +**Expected result:** +Connect should return NSAPI_ERROR_OK. + +First recv() should return more that zero. Something between 10 and 30 +bytes (datetime string) + +Second recv() should return zero because endpoint closed the connection. +(EOF). close() should return NSAPI_ERROR_OK + +### TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID + +**Description:** + +Test we are able to request setting valid TCP keepalive values + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Call `TCPSocket::setsockopt(keepalive, [0,1 or 7200]);` +2. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 9);` +3. Call `TCPSocket::getsockopt(keepalive);` + +**Postconditions:** + +1. Call `TCPSocket::close();` +2. delete socket + +**Expected result:** + +`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 +------------------------------ + +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. + + +### TCPSERVER_ACCEPT + +**Description:** + + Test that `TCPServer::bind()`, `TCPServer::listen()` +and `TCPServer::accept()` works. + +Requires 2 devices. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. DUT1: `TCPServer::bind()` +2. DUT1: `TCPServer::listen()` +3. DUT1: Create a new `TCPSocket` +4. DUT1: `TCPServer::accept()` +5. DUT2: Create a new `TCPSocket` +6. DUT2: `TCPSocket::connect(, )` +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. + +**Expected result:** + +On DUT1 accept() call blocks until connection is received. Other calls +should return NSAPI_ERROR_OK + +On DUT2 all calls should return NSAPI_ERROR_OK + + + +### TCPSERVER_LISTEN + +**Description:** + + Test that `TCPServer::listen()` has the backlog functionality. + +Requires 2 devices. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. DUT1: `TCPServer::bind()` +2. DUT1: `TCPServer::listen(2)` +3. loop 2 times: + 1. DUT2: Create a new TCPSocket + 2. DUT2: `TCPSocket::connect(, )` + +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. + +**Expected result:** + +DUT2 should receive connection before the server have called accept(), +because backlog must be minimum of 2. + + +### TCPSERVER_LISTEN_WITHOUT_BIND + +**Description:** + + Call `TCPServer::listen()` without calling bind() first. Should fail, +because no listening port have been defined. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create TCPServer +2. Call `TCPServer::listen()` + +**Expected result:** + +Should +return NSAPI_ERROR_UNSUPPORTED, NSAPI_ERROR_PARAMETER, NSAPI_ERROR_NO_ADDRESS +or NSAPI_ERROR_DEVICE_ERROR + + +### TCPSERVER_ACCEPT_WITHOUT_LISTEN + +**Description:** + + Call `TCPServer::accept()` without calling listen() first. Should fail, +because socket is not listening for connections. + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up + +**Test steps:** + +1. Create TCPServer +2. Call `TCPServer::bind()` +3. Create new TCPSocket. +4. Call `TCPServer::accept()` + +**Expected result:** + +Should return NSAPI_ERROR_UNSUPPORTED, NSAPI_ERROR_PARAMETER +or NSAPI_ERROR_DEVICE_ERROR + + +Performance tests +----------------- + + +### UDPSOCKET_ECHOTEST_BURST + +**Description:** + +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 + +**Test steps:** + +1. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 100);` +2. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 200);` +3. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 300);` +4. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 120);` +5. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 500);` +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 + +**Expected result:** + +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 number of succesfull rounds, it should be higher than 70 + + +### UDPSOCKET_ECHOTEST_BURST_NONBLOCK + +**Description:** + +Send burst of packets to echo server and read incoming packets back. Use +socket in non-blocking mode + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. UDPSocket is open + +**Test steps:** + +1. Call `UDPSocket::set_blocking(false)` +2. Register event handler with `UDPSocket::sigio()` +3. Create another thread that constantly waits signal from sigio() + handler, when received try `UDPSocket::recvfrom()` +4. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 100);` +5. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 200);` +6. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 300);` +7. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 120);` +8. Call `UDPSocket:sendto("echo.mbedcloudtesting.com", 7, , 500);` +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 + +**Expected result:** + +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 number of succesfull rounds, it should be higher than 70 + + + +### TCPSOCKET_ECHOTEST_BURST + +**Description:** + +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 + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7);` +2. Call `TCPSocket::send(, 100);` +3. Call `TCPSocket::send(, 200);` +4. Call `TCPSocket::send(, 300);` +5. Call `TCPSocket::send(, 120);` +6. Call `TCPSocket::send(, 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 + +**Expected result:** + +All send() calls should return the packet size. + +NOTE: This is stream so recv() might return less data than what was +requested. In this case you need to keep calling recv() with remaining +size until all data that you have sent is returned. + +Consecutive calls to recv() should return all the data that has been +send. Total amount of returned must match 1220. + + +### TCPSOCKET_ECHOTEST_BURST_NONBLOCK + +**Description:** + +Send burst of packets to echo server and read incoming packets back. Use +socket in non-blocking mode + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Register event handler with `TCPSocket::sigio()` +2. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 7);` +3. Call `TCPSocket::set_blocking(false)` +4. Create another thread that constantly waits signal from sigio() + handler, when received try `TCPSocket::recv()` +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() + +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 + +**Expected result:** + +All send() calls should return NSAPI_ERROR_WOULD_BLOCK or size which +is equal or less than requested. + +All recv() calls should return value that is less or equal to what have +been sent. With consecutive calls, size should match. + +When recv() returns NSAPI_ERROR_WOULD_BLOCK wait for next sigio() +event. No other error codes allowed. + + +### TCPSOCKET_RECV_100K + +**Description:** + +Download 100kB of data + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 19);` +2. Call `TCPSocket::recv(buffer, 100);` +3. Verify input according to known pattern. +4. Loop until 100kB of data received. +5. close socket. + +**Expected result:** + +Each recv() call should return equal or less than 100 bytes of data. No +errors should be returned. + +Measure time taken for receiving, report speed + +### TCPSOCKET_RECV_100K_NONBLOCK + +**Description:** + +Download 100kB of data + +**Preconditions:** + +1. Network interface and stack are initialised +2. Network connection is up +3. TCPSocket is open + +**Test steps:** + +1. Call `TCPSocket::connect("echo.mbedcloudtesting.com", 19);` +2. Call `TCPSocket::set_blocking(false)` +3. Create another thread that constantly waits signal from sigio() + handler, when received try `TCPSocket::recv()` + 1. Call `TCPSocket::recv(buffer, 100);` + 2. Verify input according to known pattern. + +4. Wait until 100kB of data received. +5. close socket. + +**Expected result:** + +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 + +### TCPSOCKET_THREAD_PER_SOCKET_SAFETY + +**Description:** + +Run two threads which both exercise the underlying stack and driver +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 + +**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; +2. On main thread + 1. For randomly generated packets, sized 1001, 901, 801,...,101,1 + do + 1. Call `TCPSocket::send(packet, size);` + 2. Verify incoming content was the same that was sent. + Allow recv() to return smaller piezes. + +3. Simultaneously with the earlier step do on the additional thread + 1. For randomly generated packets, sized 10 do + 1. Call `TCPSocket::send(packet, size);` + 2. Verify incomming content was the same that was sent. + Allow recv() to return smaller piezes. + 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 + +**Expected result:** + +Echo server returns data to both threads and received data matches to +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 +- TCPSOCKET_ECHOTEST_NONBLOCK +- TCPSOCKET_RECV_100K +- TCPSOCKET_RECV_100K_NONBLOCK +- TCPSOCKET_RECV_TIMEOUT +- TCPSOCKET_SEND_REPEAT +- UDPSOCKET_BIND_SENDTO +- UDPSOCKET_ECHOTEST +- UDPSOCKET_ECHOTEST_NONBLOCK +- UDPSOCKET_RECV_TIMEOUT +- UDPSOCKET_SENDTO_INVALID +- UDPSOCKET_SENDTO_REPEAT +- UDPSOCKET_SENDTO_TIMEOUT + +### For socket layer driver (AT-driven, external IP stack): + +All Socket, UDPSocket, TCPSocket and TCPServer testcases. diff --git a/TESTS/netsocket/eth_environment.png b/TESTS/netsocket/eth_environment.png new file mode 100644 index 0000000000..0d66872e3d Binary files /dev/null and b/TESTS/netsocket/eth_environment.png differ diff --git a/TESTS/netsocket/wifi_environment.png b/TESTS/netsocket/wifi_environment.png new file mode 100644 index 0000000000..b135af10f6 Binary files /dev/null and b/TESTS/netsocket/wifi_environment.png differ diff --git a/TEST_APPS/readme.md b/TEST_APPS/readme.md index 178be60d61..814e768df2 100644 --- a/TEST_APPS/readme.md +++ b/TEST_APPS/readme.md @@ -21,8 +21,8 @@ You need Icetea and mbed-cli that supports Icetea, installed. Depending on a device, there might be a default network interface type defined in the mbed-os/targets/targets.json, which is used to locate a test-config file by default. If there is not, or you want to use a different interface than the default, you need to provide a relevant test-config -file to the mbed test with --test-config option. -The test-config file contains the necessary information for the test application, there are some test-config files located under mbed-os/tools/test-configs. -Devices which have their network drivers residing inside mbed-os can use generic test-configs like HeapBlockDeviceAndEthernetInterface.json and HeapBlockDeviceAndWifiInterface.json. Otherwise you need to use a device specific test-config. +The test-config file contains the necessary information for the test application, there are some test-config files located under mbed-os/tools/test_configs. +Devices which have their network drivers residing inside mbed-os can use generic test_configs like HeapBlockDeviceAndEthernetInterface.json and HeapBlockDeviceAndWifiInterface.json. Otherwise you need to use a device specific test-config. ### Running the tests @@ -42,10 +42,10 @@ Some devices may offer multiple network interfaces to operate with. For example, The tests can be run for either one of those using already existing test-config -files. To run the tests with Wi-Fi interface: -`>mbed test -m UBLOX_EVK_ODIN_W2 -t --icetea --test-config tools/test-configs/HeapBlockDeviceAndWifiInterface.json` +`>mbed test -m UBLOX_EVK_ODIN_W2 -t --icetea --test-config tools/test_configs/HeapBlockDeviceAndWifiInterface.json` To run the tests with ethernet interface: -`>mbed test -m UBLOX_EVK_ODIN_W2 -t --icetea --test-config tools/test-configs/HeapBlockDeviceAndEthernetInterface.json` +`>mbed test -m UBLOX_EVK_ODIN_W2 -t --icetea --test-config tools/test_configs/HeapBlockDeviceAndEthernetInterface.json` #### Providing Wi-Fi access point information diff --git a/UNITTESTS/README.md b/UNITTESTS/README.md index 2f8a7bc163..180fb49c50 100644 --- a/UNITTESTS/README.md +++ b/UNITTESTS/README.md @@ -69,17 +69,17 @@ pip install "gcovr>=4.1" > In case of running into problems see [troubleshooting](#troubleshooting) section. -`UNITTESTS/mbed_unittest.py` contains testing scripts for Mbed OS unit testing. Mbed CLI supports unit testing through `mbed unittest` command with the same arguments. +`UNITTESTS/mbed_unittest.py` contains testing scripts for Mbed OS unit testing. Mbed CLI supports unit testing through `mbed test --unittests` command with the same arguments. ### Testing with Mbed CLI ``` -mbed unittest +mbed test --unittests ``` A subset of tests can be run by providing `-r` flag for the tool which runs tests matching a regular expression. -e.g. `mbed unittest --run -r features_netsocket` +e.g. `mbed test --unittests --run -r features_netsocket` ### Build manually without Python tools @@ -144,7 +144,7 @@ Run ctest dashboard test and create test results: Python tools use gcovr to build code coverage reports. Generate html report `UNITTESTS/build/coverage/index.html` with: ``` -mbed unittest --coverage html +mbed test --unittests --coverage html ``` To get coverage for a single test suite, run gcovr separately for suite coverage data directory. See [gcovr documentation](https://gcovr.com/guide.html#filter-options) for more information. @@ -211,10 +211,10 @@ A unit test definition file `unittest.cmake` requires variables to be set for a #### Creating unit tests files with Mbed CLI ``` -mbed unittest --new +mbed test --unittests --new ``` -E.g. `mbed unittest --new rtos/Semaphore.cpp` +E.g. `mbed test --unittests --new rtos/Semaphore.cpp` The generator script only creates the files required for a unit test. It does not write unit tests automatically nor does it handle source dependencies. diff --git a/UNITTESTS/stubs/Mutex_stub.cpp b/UNITTESTS/stubs/Mutex_stub.cpp index c287d3bec0..cd226064f8 100644 --- a/UNITTESTS/stubs/Mutex_stub.cpp +++ b/UNITTESTS/stubs/Mutex_stub.cpp @@ -27,7 +27,12 @@ rtos::Mutex::~Mutex() return; } -osStatus rtos::Mutex::lock(unsigned int) +osStatus rtos::Mutex::lock(void) +{ + return osOK; +} + +osStatus rtos::Mutex::lock(uint32_t millisec) { return osOK; } diff --git a/drivers/MbedCRC.cpp b/drivers/MbedCRC.cpp index 54243f5820..34e777a251 100644 --- a/drivers/MbedCRC.cpp +++ b/drivers/MbedCRC.cpp @@ -34,6 +34,14 @@ MbedCRC::MbedCRC(): mbed_crc_ctor(); } +template<> +MbedCRC::MbedCRC(): + _initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(false), _reflect_remainder(false), + _crc_table((uint32_t *)Table_CRC_32bit_Rev_ANSI) +{ + mbed_crc_ctor(); +} + template<> MbedCRC::MbedCRC(): _initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true), diff --git a/drivers/MbedCRC.h b/drivers/MbedCRC.h index b1f44c4751..fd4fa1c7f0 100644 --- a/drivers/MbedCRC.h +++ b/drivers/MbedCRC.h @@ -275,7 +275,7 @@ public: p_crc = (uint32_t)(p_crc << (8 - width)); } // Optimized algorithm for 32BitANSI does not need additional reflect_remainder - if ((TABLE == _mode) && (POLY_32BIT_ANSI == polynomial)) { + if ((TABLE == _mode) && (POLY_32BIT_REV_ANSI == polynomial)) { *crc = (p_crc ^ _final_xor) & get_crc_mask(); } else { *crc = (reflect_remainder(p_crc) ^ _final_xor) & get_crc_mask(); @@ -415,7 +415,6 @@ private: int32_t bitwise_compute_partial(const void *buffer, crc_data_size_t size, uint32_t *crc) const { MBED_ASSERT(crc != NULL); - MBED_ASSERT(buffer != NULL); const uint8_t *data = static_cast(buffer); uint32_t p_crc = *crc; @@ -460,7 +459,6 @@ private: int32_t table_compute_partial(const void *buffer, crc_data_size_t size, uint32_t *crc) const { MBED_ASSERT(crc != NULL); - MBED_ASSERT(buffer != NULL); const uint8_t *data = static_cast(buffer); uint32_t p_crc = *crc; @@ -480,9 +478,17 @@ private: } } else { uint32_t *crc_table = (uint32_t *)_crc_table; - for (crc_data_size_t i = 0; i < size; i++) { - p_crc = (p_crc >> 4) ^ crc_table[(p_crc ^ (data[i] >> 0)) & 0xf]; - p_crc = (p_crc >> 4) ^ crc_table[(p_crc ^ (data[i] >> 4)) & 0xf]; + if (POLY_32BIT_REV_ANSI == polynomial) { + for (crc_data_size_t i = 0; i < size; i++) { + p_crc = (p_crc >> 4) ^ crc_table[(p_crc ^ (data[i] >> 0)) & 0xf]; + p_crc = (p_crc >> 4) ^ crc_table[(p_crc ^ (data[i] >> 4)) & 0xf]; + } + } + else { + for (crc_data_size_t byte = 0; byte < size; byte++) { + data_byte = reflect_bytes(data[byte]) ^ (p_crc >> (width - 8)); + p_crc = crc_table[data_byte] ^ (p_crc << 8); + } } } *crc = p_crc & get_crc_mask(); @@ -497,6 +503,11 @@ private: MBED_STATIC_ASSERT(width <= 32, "Max 32-bit CRC supported"); #ifdef DEVICE_CRC + if (POLY_32BIT_REV_ANSI == polynomial) { + _crc_table = (uint32_t *)Table_CRC_32bit_Rev_ANSI; + _mode = TABLE; + return; + } crc_mbed_config_t config; config.polynomial = polynomial; config.width = width; @@ -510,10 +521,14 @@ private: return; } #endif + switch (polynomial) { case POLY_32BIT_ANSI: _crc_table = (uint32_t *)Table_CRC_32bit_ANSI; break; + case POLY_32BIT_REV_ANSI: + _crc_table = (uint32_t *)Table_CRC_32bit_Rev_ANSI; + break; case POLY_8BIT_CCITT: _crc_table = (uint32_t *)Table_CRC_8bit_CCITT; break; diff --git a/drivers/QSPI.cpp b/drivers/QSPI.cpp index e0cb3b62d1..9a75d79727 100644 --- a/drivers/QSPI.cpp +++ b/drivers/QSPI.cpp @@ -91,7 +91,7 @@ qspi_status_t QSPI::set_frequency(int hz) return ret_status; } -qspi_status_t QSPI::read(unsigned int address, char *rx_buffer, size_t *rx_length) +qspi_status_t QSPI::read(int address, char *rx_buffer, size_t *rx_length) { qspi_status_t ret_status = QSPI_STATUS_ERROR; @@ -115,7 +115,7 @@ qspi_status_t QSPI::read(unsigned int address, char *rx_buffer, size_t *rx_lengt return ret_status; } -qspi_status_t QSPI::write(unsigned int address, const char *tx_buffer, size_t *tx_length) +qspi_status_t QSPI::write(int address, const char *tx_buffer, size_t *tx_length) { qspi_status_t ret_status = QSPI_STATUS_ERROR; @@ -139,7 +139,7 @@ qspi_status_t QSPI::write(unsigned int address, const char *tx_buffer, size_t *t return ret_status; } -qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned int address, char *rx_buffer, size_t *rx_length) +qspi_status_t QSPI::read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length) { qspi_status_t ret_status = QSPI_STATUS_ERROR; @@ -163,7 +163,7 @@ qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned in return ret_status; } -qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned int address, const char *tx_buffer, size_t *tx_length) +qspi_status_t QSPI::write(int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length) { qspi_status_t ret_status = QSPI_STATUS_ERROR; @@ -187,7 +187,7 @@ qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned i return ret_status; } -qspi_status_t QSPI::command_transfer(unsigned int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length) +qspi_status_t QSPI::command_transfer(int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length) { qspi_status_t ret_status = QSPI_STATUS_ERROR; diff --git a/drivers/QSPI.h b/drivers/QSPI.h index c166e4bc55..fc8f6b3b0f 100644 --- a/drivers/QSPI.h +++ b/drivers/QSPI.h @@ -44,8 +44,12 @@ namespace mbed { * * #include "mbed.h" * + * #define CMD_WRITE 0x02 + * #define CMD_READ 0x03 + * #define ADDRESS 0x1000 + * * // hardware ssel (where applicable) - * QSPI qspi_device(QSPI_PIN_IO0, QSPI_PIN_IO1, QSPI_PIN_IO2, QSPI_PIN_IO3, QSPI_PIN_SCK, QSPI_PIN_CSN); // io0, io1, io2, io3, sclk, ssel + * QSPI qspi_device(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN); // io0, io1, io2, io3, sclk, ssel * * * int main() { @@ -53,10 +57,14 @@ namespace mbed { * char rx_buf[4]; * int buf_len = sizeof(tx_buf); * - * int result = qspi_device.write( 0x12 , 0x100000 , 0 , tx_buf, &buf_len ); - * if( !result ) printf("Write failed"); - * int result = qspi_device.read( 0x13 , 0x100000 , 0 , rx_buf, &buf_len ); - * if( !result ) printf("Read failed"); + * qspi_status_t result = qspi_device.write(CMD_WRITE, 0, ADDRESS, tx_buf, &buf_len); + * if (result != QSPI_STATUS_OK) { + * printf("Write failed"); + * } + * result = qspi_device.read(CMD_READ, 0, ADDRESS, rx_buf, &buf_len); + * if (result != QSPI_STATUS_OK) { + * printf("Read failed"); + * } * * } * @endcode @@ -118,7 +126,7 @@ public: * @returns * Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads. */ - qspi_status_t read(unsigned int address, char *rx_buffer, size_t *rx_length); + qspi_status_t read(int address, char *rx_buffer, size_t *rx_length); /** Write to QSPI peripheral using custom write instruction * @@ -129,12 +137,12 @@ public: * @returns * Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads. */ - qspi_status_t write(unsigned int address, const char *tx_buffer, size_t *tx_length); + qspi_status_t write(int address, const char *tx_buffer, size_t *tx_length); /** Read from QSPI peripheral using custom read instruction, alt values * * @param instruction Instruction value to be used in instruction phase - * @param alt Alt value to be used in instruction phase + * @param alt Alt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase * @param address Address to be accessed in QSPI peripheral * @param rx_buffer Buffer for data to be read from the peripheral * @param rx_length Pointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read @@ -142,12 +150,12 @@ public: * @returns * Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads. */ - qspi_status_t read(unsigned int instruction, unsigned int alt, unsigned int address, char *rx_buffer, size_t *rx_length); + qspi_status_t read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length); /** Write to QSPI peripheral using custom write instruction, alt values * * @param instruction Instruction value to be used in instruction phase - * @param alt Alt value to be used in instruction phase + * @param alt Alt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase * @param address Address to be accessed in QSPI peripheral * @param tx_buffer Buffer containing data to be sent to peripheral * @param tx_length Pointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written @@ -155,12 +163,12 @@ public: * @returns * Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads. */ - qspi_status_t write(unsigned int instruction, unsigned int alt, unsigned int address, const char *tx_buffer, size_t *tx_length); + qspi_status_t write(int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length); /** Perform a transaction to write to an address(a control register) and get the status results * * @param instruction Instruction value to be used in instruction phase - * @param address Some instruction might require address. Use -1 for ignoring the address value + * @param address Some instruction might require address. Use -1 if no address * @param tx_buffer Buffer containing data to be sent to peripheral * @param tx_length Pointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written * @param rx_buffer Buffer for data to be read from the peripheral @@ -169,7 +177,7 @@ public: * @returns * Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads. */ - qspi_status_t command_transfer(unsigned int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length); + qspi_status_t command_transfer(int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length); protected: /** Acquire exclusive access to this SPI bus diff --git a/drivers/TableCRC.cpp b/drivers/TableCRC.cpp index f3cb42158a..b6e55aaae8 100644 --- a/drivers/TableCRC.cpp +++ b/drivers/TableCRC.cpp @@ -108,12 +108,48 @@ extern const uint16_t Table_CRC_16bit_IBM[MBED_CRC_TABLE_SIZE] = { 0x220, 0x8225, 0x822f, 0x22a, 0x823b, 0x23e, 0x234, 0x8231, 0x8213, 0x216, 0x21c, 0x8219 }; -extern const uint32_t Table_CRC_32bit_ANSI[MBED_OPTIMIZED_CRC_TABLE_SIZE] = { +extern const uint32_t Table_CRC_32bit_ANSI[MBED_CRC_TABLE_SIZE] = { + 0x0, 0x4c11db7, 0x9823b6e, 0xd4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, + 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, + 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, + 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, + 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, + 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, + 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x18aeb13, 0x54bf6a4, 0x808d07d, 0xcc9cdca, + 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, + 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, + 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, + 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, + 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, + 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, + 0x315d626, 0x7d4cb91, 0xa97ed48, 0xe56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, + 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, + 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, + 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, + 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, + 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x29f3d35, 0x65e2082, 0xb1d065b, 0xfdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, + 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, + 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, + 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 +}; + +extern const uint32_t Table_CRC_32bit_Rev_ANSI[MBED_OPTIMIZED_CRC_TABLE_SIZE] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; + /** @}*/ } // namespace mbed diff --git a/drivers/TableCRC.h b/drivers/TableCRC.h index 6a87159157..478bb25958 100644 --- a/drivers/TableCRC.h +++ b/drivers/TableCRC.h @@ -30,7 +30,8 @@ extern const uint8_t Table_CRC_7Bit_SD[MBED_CRC_TABLE_SIZE]; extern const uint8_t Table_CRC_8bit_CCITT[MBED_CRC_TABLE_SIZE]; extern const uint16_t Table_CRC_16bit_CCITT[MBED_CRC_TABLE_SIZE]; extern const uint16_t Table_CRC_16bit_IBM[MBED_CRC_TABLE_SIZE]; -extern const uint32_t Table_CRC_32bit_ANSI[MBED_OPTIMIZED_CRC_TABLE_SIZE]; +extern const uint32_t Table_CRC_32bit_ANSI[MBED_CRC_TABLE_SIZE]; +extern const uint32_t Table_CRC_32bit_Rev_ANSI[MBED_OPTIMIZED_CRC_TABLE_SIZE]; /** @}*/ } // namespace mbed diff --git a/features/frameworks/mbed-coap/CHANGELOG.md b/features/frameworks/mbed-coap/CHANGELOG.md index 1cbbbee6b3..70c9706541 100644 --- a/features/frameworks/mbed-coap/CHANGELOG.md +++ b/features/frameworks/mbed-coap/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [v4.6.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.6.3) + + - Bug fix: Remove timed out blockwise message from resend queue. If blockwise message was timed out message was still kept in the resend queue which causes unnecessary reconnections on client side. + - Documentation: Document all the available macros. + +-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.6.2...v4.6.3) + ## [v4.6.2](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.6.2) Do not clear block2 in subsequent block request. diff --git a/features/frameworks/mbed-coap/mbed-coap/sn_config.h b/features/frameworks/mbed-coap/mbed-coap/sn_config.h index 8c1477bcdb..5794af5cbc 100644 --- a/features/frameworks/mbed-coap/mbed-coap/sn_config.h +++ b/features/frameworks/mbed-coap/mbed-coap/sn_config.h @@ -36,7 +36,6 @@ /** * \def SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - * * \brief For Message blockwising * Init value for the maximum payload size to be sent and received at one blockwise message * Setting of this value to 0 with SN_COAP_BLOCKWISE_ENABLED will disable this feature, and @@ -45,19 +44,8 @@ */ #undef SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* 0 */ // < Must be 2^x and x is at least 4. Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024 -/** - * \def COAP_DISABLE_OBS_FEATURE - * - * \brief Disables CoAP 'obs' sending feature - * as part of registration message, this might be - * needed to be enabled for some strict LWM2M server implementation. - * By default, this feature is disabled. - */ -#undef COAP_DISABLE_OBS_FEATURE - /** * \def SN_COAP_DISABLE_RESENDINGS - * * \brief Disables resending feature. Resending feature should not be needed * when using CoAP with TCP transport for example. By default resendings are * enabled. Set to 1 to disable. @@ -66,15 +54,20 @@ /** * \def SN_COAP_RESENDING_QUEUE_SIZE_MSGS - * * \brief Sets the number of messages stored * in the resending queue. Default is 2 */ #undef SN_COAP_RESENDING_QUEUE_SIZE_MSGS /* 2 */ // < Default re-sending queue size - defines how many messages can be stored. Setting this to 0 disables feature +/** + * \def DEFAULT_RESPONSE_TIMEOUT + * \brief Sets the CoAP re-send interval in seconds. + * By default is 10 seconds. + */ +#undef DEFAULT_RESPONSE_TIMEOUT + /** * \def SN_COAP_RESENDING_QUEUE_SIZE_BYTES - * * \brief Sets the size of the re-sending buffer. * Setting this to 0 disables this feature. * By default, this feature is disabled. @@ -83,7 +76,6 @@ /** * \def SN_COAP_MAX_INCOMING_MESSAGE_SIZE - * * \brief Sets the maximum size (in bytes) that * mbed Client will allow to be handled while * receiving big payload in blockwise mode. @@ -115,6 +107,75 @@ */ #undef SN_COAP_BLOCKWISE_ENABLED /* 0 */ +/** + * \def SN_COAP_RESENDING_MAX_COUNT + * \brief Defines how many times CoAP library tries to re-send the CoAP packet. + * By default value is 3. + */ +#undef SN_COAP_RESENDING_MAX_COUNT /* 3 */ + +/** + * \def SN_COAP_MAX_ALLOWED_RESENDING_COUNT + * \brief Maximum allowed count of re-sending that can be set at runtime via + * 'sn_coap_protocol_set_retransmission_parameters()' API. + * By default value is 6. + */ +#undef SN_COAP_MAX_ALLOWED_RESENDING_COUNT /* 6 */ + +/** + * \def SN_COAP_MAX_ALLOWED_RESPONSE_TIMEOUT + * \brief Maximum allowed re-send interval in seconds that can be set at runtime via + * 'sn_coap_protocol_set_retransmission_parameters()' API. + * By default value is 40. + */ +#undef SN_COAP_MAX_ALLOWED_RESPONSE_TIMEOUT /* 40 */ + +/** + * \def SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_MSGS + * \brief Maximum allowed count of messages that can be stored into resend buffer at runtime via + * 'sn_coap_protocol_set_retransmission_buffer()' API. + * By default value is 6. + */ +#undef SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_MSGS /* 6 */ + +/** + * \def SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_BYTES + * \brief Maximum size of messages in bytes that can be stored into resend buffer at runtime via + * 'sn_coap_protocol_set_retransmission_buffer()' API. + * By default value is 512. + */ +#undef SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_BYTES /* 512 */ + +/** + * \def SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT + * \brief Maximum allowed number of saved messages for message duplicate searching + * that can be set via 'sn_coap_protocol_set_duplicate_buffer_size' API. + * By default value is 6. + */ +#undef SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT + +/** + * \def SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED + * \brief Maximum time in seconds howe long message is kept for duplicate detection. + * By default 60 seconds. + */ +#undef SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED + +/** + * \def SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED + * \brief Maximum time in seconds how long (messages and payload) are be stored for blockwising. + * Longer time will increase the memory consumption in lossy networks. + * By default 60 seconds. + */ +#undef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED + +/** + * \def SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE + * \brief Maximum size of blockwise message that can be received. + * By default 65535 bytes. + */ +#undef SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE + #ifdef MBED_CLIENT_USER_CONFIG_FILE #include MBED_CLIENT_USER_CONFIG_FILE #endif diff --git a/features/frameworks/mbed-coap/module.json b/features/frameworks/mbed-coap/module.json index 717c79a7f5..97bf7341db 100644 --- a/features/frameworks/mbed-coap/module.json +++ b/features/frameworks/mbed-coap/module.json @@ -1,6 +1,6 @@ { "name": "mbed-coap", - "version": "4.6.2", + "version": "4.6.3", "description": "COAP library", "keywords": [ "coap", diff --git a/features/frameworks/mbed-coap/source/sn_coap_protocol.c b/features/frameworks/mbed-coap/source/sn_coap_protocol.c index 2970678698..377e341550 100644 --- a/features/frameworks/mbed-coap/source/sn_coap_protocol.c +++ b/features/frameworks/mbed-coap/source/sn_coap_protocol.c @@ -1559,6 +1559,7 @@ static void sn_coap_protocol_handle_blockwise_timout(struct coap_s *handle) /* Notify the application about the time out */ removed_blocwise_msg_ptr->coap_msg_ptr->coap_status = COAP_STATUS_BUILDER_BLOCK_SENDING_FAILED; removed_blocwise_msg_ptr->coap_msg_ptr->msg_id = removed_blocwise_msg_ptr->msg_id; + sn_coap_protocol_delete_retransmission(handle, removed_blocwise_msg_ptr->msg_id); handle->sn_coap_rx_callback(removed_blocwise_msg_ptr->coap_msg_ptr, NULL, removed_blocwise_msg_ptr->param); } diff --git a/features/lorawan/lorawan_types.h b/features/lorawan/lorawan_types.h index eef09f2d62..6f57c3c061 100644 --- a/features/lorawan/lorawan_types.h +++ b/features/lorawan/lorawan_types.h @@ -242,10 +242,6 @@ typedef enum lora_events { * 'link_check_resp' callback. The result is thus transported to the application * via callback function provided. * - * As can be seen from declaration, mbed::Callback *link_check_resp) - * carries two parameters. First one is Demodulation Margin and the second one - * is number of gateways involved in the path to network server. - * * 'battery_level' callback goes in the down direction, i.e., it informs * the stack about the battery level by calling a function provided * by the upper layers. @@ -257,11 +253,16 @@ typedef struct { mbed::Callback events; /** - * Optional + * This callback is optional + * + * The first parameter to the callback function is the demodulation margin, and the second + * parameter is the number of gateways that successfully received the last request. */ mbed::Callback link_check_resp; /** + * This callback is optional. If the callback is not set, the stack returns 255 to gateway. + * * Battery level return value must follow the specification * for DevStatusAns MAC command: * diff --git a/features/mbedtls/VERSION.txt b/features/mbedtls/VERSION.txt index b50aaeaa41..e97cf88ec7 100644 --- a/features/mbedtls/VERSION.txt +++ b/features/mbedtls/VERSION.txt @@ -1 +1 @@ -mbedtls-2.13.0 +mbedtls-2.13.1 diff --git a/features/mbedtls/importer/Makefile b/features/mbedtls/importer/Makefile index 02594acd04..a8d55cf91a 100644 --- a/features/mbedtls/importer/Makefile +++ b/features/mbedtls/importer/Makefile @@ -27,7 +27,7 @@ # # Set the mbed TLS release to import (this can/should be edited before import) -MBED_TLS_RELEASE ?= mbedtls-2.13.0 +MBED_TLS_RELEASE ?= mbedtls-2.13.1 # Translate between mbed TLS namespace and mbed namespace TARGET_PREFIX:=../ diff --git a/features/mbedtls/inc/mbedtls/config.h b/features/mbedtls/inc/mbedtls/config.h index 34569f05e3..5d1d5686cf 100644 --- a/features/mbedtls/inc/mbedtls/config.h +++ b/features/mbedtls/inc/mbedtls/config.h @@ -152,12 +152,21 @@ /** * \def MBEDTLS_HAVE_TIME_DATE * - * System has time.h and time(), gmtime() and the clock is correct. + * System has time.h, time(), and an implementation for + * mbedtls_platform_gmtime_r() (see below). * The time needs to be correct (not necesarily very accurate, but at least * the date should be correct). This is used to verify the validity period of * X.509 certificates. * * Comment if your system does not have a correct clock. + * + * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h that + * behaves similarly to the gmtime_r() function from the C standard. Refer to + * the documentation for mbedtls_platform_gmtime_r() for more information. + * + * \note It is possible to configure an implementation for + * mbedtls_platform_gmtime_r() at compile-time by using the macro + * MBEDTLS_PLATFORM_GMTIME_R_ALT. */ //#define MBEDTLS_HAVE_TIME_DATE @@ -3115,6 +3124,25 @@ */ //#define MBEDTLS_PLATFORM_ZEROIZE_ALT +/** + * Uncomment the macro to let Mbed TLS use your alternate implementation of + * mbedtls_platform_gmtime_r(). This replaces the default implementation in + * platform_util.c. + * + * gmtime() is not a thread-safe function as defined in the C standard. The + * library will try to use safer implementations of this function, such as + * gmtime_r() when available. However, if Mbed TLS cannot identify the target + * system, the implementation of mbedtls_platform_gmtime_r() will default to + * using the standard gmtime(). In this case, calls from the library to + * gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex + * if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the + * library are also guarded with this mutex to avoid race conditions. However, + * if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will + * unconditionally use the implementation for mbedtls_platform_gmtime_r() + * supplied at compile time. + */ +//#define MBEDTLS_PLATFORM_GMTIME_R_ALT + /* \} name SECTION: Customisation configuration options */ /* Target and application specific configurations */ diff --git a/features/mbedtls/inc/mbedtls/platform_util.h b/features/mbedtls/inc/mbedtls/platform_util.h index 84f0732eeb..164a1a05f9 100644 --- a/features/mbedtls/inc/mbedtls/platform_util.h +++ b/features/mbedtls/inc/mbedtls/platform_util.h @@ -25,7 +25,17 @@ #ifndef MBEDTLS_PLATFORM_UTIL_H #define MBEDTLS_PLATFORM_UTIL_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include +#if defined(MBEDTLS_HAVE_TIME_DATE) +#include "mbedtls/platform_time.h" +#include +#endif /* MBEDTLS_HAVE_TIME_DATE */ #ifdef __cplusplus extern "C" { @@ -55,6 +65,37 @@ extern "C" { */ void mbedtls_platform_zeroize( void *buf, size_t len ); +#if defined(MBEDTLS_HAVE_TIME_DATE) +/** + * \brief Platform-specific implementation of gmtime_r() + * + * The function is a thread-safe abstraction that behaves + * similarly to the gmtime_r() function from Unix/POSIX. + * + * Mbed TLS will try to identify the underlying platform and + * make use of an appropriate underlying implementation (e.g. + * gmtime_r() for POSIX and gmtime_s() for Windows). If this is + * not possible, then gmtime() will be used. In this case, calls + * from the library to gmtime() will be guarded by the mutex + * mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is + * enabled. It is recommended that calls from outside the library + * are also guarded by this mutex. + * + * If MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, then Mbed TLS will + * unconditionally use the alternative implementation for + * mbedtls_platform_gmtime_r() supplied by the user at compile time. + * + * \param tt Pointer to an object containing time (in seconds) since the + * epoch to be converted + * \param tm_buf Pointer to an object where the results will be stored + * + * \return Pointer to an object of type struct tm on success, otherwise + * NULL + */ +struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, + struct tm *tm_buf ); +#endif /* MBEDTLS_HAVE_TIME_DATE */ + #ifdef __cplusplus } #endif diff --git a/features/mbedtls/inc/mbedtls/threading.h b/features/mbedtls/inc/mbedtls/threading.h index 5112ebb747..75298bf8a3 100644 --- a/features/mbedtls/inc/mbedtls/threading.h +++ b/features/mbedtls/inc/mbedtls/threading.h @@ -99,6 +99,17 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); #if defined(MBEDTLS_FS_IO) extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; #endif + +#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) +/* This mutex may or may not be used in the default definition of + * mbedtls_platform_gmtime_r(), but in order to determine that, + * we need to check POSIX features, hence modify _POSIX_C_SOURCE. + * With the current approach, this declaration is orphaned, lacking + * an accompanying definition, in case mbedtls_platform_gmtime_r() + * doesn't need it, but that's not a problem. */ +extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; +#endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */ + #endif /* MBEDTLS_THREADING_C */ #ifdef __cplusplus diff --git a/features/mbedtls/inc/mbedtls/version.h b/features/mbedtls/inc/mbedtls/version.h index 17b8ba450b..326b8bd451 100644 --- a/features/mbedtls/inc/mbedtls/version.h +++ b/features/mbedtls/inc/mbedtls/version.h @@ -40,16 +40,16 @@ */ #define MBEDTLS_VERSION_MAJOR 2 #define MBEDTLS_VERSION_MINOR 13 -#define MBEDTLS_VERSION_PATCH 0 +#define MBEDTLS_VERSION_PATCH 1 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x020D0000 -#define MBEDTLS_VERSION_STRING "2.13.0" -#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.13.0" +#define MBEDTLS_VERSION_NUMBER 0x020D0100 +#define MBEDTLS_VERSION_STRING "2.13.1" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.13.1" #if defined(MBEDTLS_VERSION_C) diff --git a/features/mbedtls/src/platform_util.c b/features/mbedtls/src/platform_util.c index 1a57de9393..ca5fe4fb87 100644 --- a/features/mbedtls/src/platform_util.c +++ b/features/mbedtls/src/platform_util.c @@ -20,6 +20,14 @@ * This file is part of Mbed TLS (https://tls.mbed.org) */ +/* + * Ensure gmtime_r is available even with -std=c99; must be defined before + * config.h, which pulls in glibc's features.h. Harmless on other platforms. + */ +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200112L +#endif + #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else @@ -27,6 +35,7 @@ #endif #include "mbedtls/platform_util.h" +#include "mbedtls/threading.h" #include #include @@ -65,3 +74,62 @@ void mbedtls_platform_zeroize( void *buf, size_t len ) memset_func( buf, 0, len ); } #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ + +#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) +#include +#if !defined(_WIN32) && (defined(unix) || \ + defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \ + defined(__MACH__))) +#include +#endif /* !_WIN32 && (unix || __unix || __unix__ || + * (__APPLE__ && __MACH__)) */ + +#if !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ + _POSIX_THREAD_SAFE_FUNCTIONS >= 20112L ) ) +/* + * This is a convenience shorthand macro to avoid checking the long + * preprocessor conditions above. Ideally, we could expose this macro in + * platform_util.h and simply use it in platform_util.c, threading.c and + * threading.h. However, this macro is not part of the Mbed TLS public API, so + * we keep it private by only defining it in this file + */ +#if ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) +#define PLATFORM_UTIL_USE_GMTIME +#endif /* ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) */ + +#endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ + _POSIX_THREAD_SAFE_FUNCTIONS >= 20112L ) ) */ + +struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, + struct tm *tm_buf ) +{ +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) + return( ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL ); +#elif !defined(PLATFORM_UTIL_USE_GMTIME) + return( gmtime_r( tt, tm_buf ) ); +#else + struct tm *lt; + +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 ) + return( NULL ); +#endif /* MBEDTLS_THREADING_C */ + + lt = gmtime( tt ); + + if( lt != NULL ) + { + memcpy( tm_buf, lt, sizeof( struct tm ) ); + } + +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 ) + return( NULL ); +#endif /* MBEDTLS_THREADING_C */ + + return( ( lt == NULL ) ? NULL : tm_buf ); +#endif /* _WIN32 && !EFIX64 && !EFI32 */ +} +#endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */ diff --git a/features/mbedtls/src/threading.c b/features/mbedtls/src/threading.c index 7a32e672c7..7c90c7c595 100644 --- a/features/mbedtls/src/threading.c +++ b/features/mbedtls/src/threading.c @@ -19,6 +19,14 @@ * This file is part of mbed TLS (https://tls.mbed.org) */ +/* + * Ensure gmtime_r is available even with -std=c99; must be defined before + * config.h, which pulls in glibc's features.h. Harmless on other platforms. + */ +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200112L +#endif + #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else @@ -29,6 +37,36 @@ #include "mbedtls/threading.h" +#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) + +#if !defined(_WIN32) && (defined(unix) || \ + defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \ + defined(__MACH__))) +#include +#endif /* !_WIN32 && (unix || __unix || __unix__ || + * (__APPLE__ && __MACH__)) */ + +#if !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ + _POSIX_THREAD_SAFE_FUNCTIONS >= 20112L ) ) +/* + * This is a convenience shorthand macro to avoid checking the long + * preprocessor conditions above. Ideally, we could expose this macro in + * platform_util.h and simply use it in platform_util.c, threading.c and + * threading.h. However, this macro is not part of the Mbed TLS public API, so + * we keep it private by only defining it in this file + */ + +#if ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) +#define THREADING_USE_GMTIME +#endif /* ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) */ + +#endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ + _POSIX_THREAD_SAFE_FUNCTIONS >= 20112L ) ) */ + +#endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */ + #if defined(MBEDTLS_THREADING_PTHREAD) static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex ) { @@ -114,6 +152,9 @@ void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * #if defined(MBEDTLS_FS_IO) mbedtls_mutex_init( &mbedtls_threading_readdir_mutex ); #endif +#if defined(THREADING_USE_GMTIME) + mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex ); +#endif } /* @@ -124,6 +165,9 @@ void mbedtls_threading_free_alt( void ) #if defined(MBEDTLS_FS_IO) mbedtls_mutex_free( &mbedtls_threading_readdir_mutex ); #endif +#if defined(THREADING_USE_GMTIME) + mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex ); +#endif } #endif /* MBEDTLS_THREADING_ALT */ @@ -136,5 +180,8 @@ void mbedtls_threading_free_alt( void ) #if defined(MBEDTLS_FS_IO) mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT; #endif +#if defined(THREADING_USE_GMTIME) +mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT; +#endif #endif /* MBEDTLS_THREADING_C */ diff --git a/features/mbedtls/src/x509.c b/features/mbedtls/src/x509.c index 2e6795f750..52b5b649f7 100644 --- a/features/mbedtls/src/x509.c +++ b/features/mbedtls/src/x509.c @@ -29,10 +29,6 @@ * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf */ -/* Ensure gmtime_r is available even with -std=c99; must be included before - * config.h, which pulls in glibc's features.h. Harmless on other platforms. */ -#define _POSIX_C_SOURCE 200112L - #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else @@ -67,6 +63,7 @@ #include "mbedtls/platform_time.h" #endif #if defined(MBEDTLS_HAVE_TIME_DATE) +#include "mbedtls/platform_util.h" #include #endif @@ -901,11 +898,7 @@ static int x509_get_current_time( mbedtls_x509_time *now ) int ret = 0; tt = mbedtls_time( NULL ); -#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) - lt = gmtime_s( &tm_buf, &tt ) == 0 ? &tm_buf : NULL; -#else - lt = gmtime_r( &tt, &tm_buf ); -#endif + lt = mbedtls_platform_gmtime_r( &tt, &tm_buf ); if( lt == NULL ) ret = -1; diff --git a/features/nfc/source/nfc/NFCEEPROM.cpp b/features/nfc/source/nfc/NFCEEPROM.cpp index 704c53b4e1..518b652e4c 100644 --- a/features/nfc/source/nfc/NFCEEPROM.cpp +++ b/features/nfc/source/nfc/NFCEEPROM.cpp @@ -397,6 +397,7 @@ void NFCEEPROM::continue_read() _driver->read_bytes(_eeprom_address, ac_buffer_builder_write_position(buffer_builder), _ndef_buffer_read_sz - _eeprom_address); } else { // Done, close session + _current_op = nfc_eeprom_read_end_session; _operation_result = NFC_OK; _driver->end_session(); } diff --git a/features/storage/TESTS/filesystem/general_filesystem/main.cpp b/features/storage/TESTS/filesystem/general_filesystem/main.cpp index b79659db99..fb2a7da94c 100644 --- a/features/storage/TESTS/filesystem/general_filesystem/main.cpp +++ b/features/storage/TESTS/filesystem/general_filesystem/main.cpp @@ -82,87 +82,87 @@ static void FS_fopen_path_not_valid() //fopen empty file name with r mode static void FS_fopen_empty_path_r_mode() { - int res = !((fd[0] = fopen("fs/" "", "rb")) != NULL); + int res = !((fd[0] = fopen("/default/" "", "rb")) != NULL); TEST_ASSERT_EQUAL(1, res); } //fopen empty file name with w mode static void FS_fopen_empty_path_w_mode() { - int res = !((fd[0] = fopen("fs/" "", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "", "wb")) != NULL); TEST_ASSERT_EQUAL(1, res); } //fopen empty mode static void FS_fopen_invalid_mode() { - int res = !((fd[0] = fopen("fs/" "Invalid_mode", "")) != NULL); + int res = !((fd[0] = fopen("/default/" "Invalid_mode", "")) != NULL); TEST_ASSERT_EQUAL(1, res); } //fopen with valid flowSystemStorage static void FS_fopen_supported_wb_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fopen with append mode static void FS_fopen_supported_a_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "a")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "a")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fopen with read mode static void FS_fopen_supported_r_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(1, res); } //fopen with append update mode static void FS_fopen_supported_a_update_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "a+")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "a+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fopen with read update mode static void FS_fopen_supported_r_update_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "r+")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "r+")) != NULL); TEST_ASSERT_EQUAL(1, res); } //fopen with write update mode static void FS_fopen_supported_w_update_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "w+")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -172,7 +172,7 @@ static void FS_fopen_read_update_create() char write_buf[small_buf_size] = "123456789"; char read_buf[small_buf_size] = ""; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), small_buf_size, fd[0]); @@ -181,7 +181,7 @@ static void FS_fopen_read_update_create() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r+")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), small_buf_size, fd[0]); @@ -191,7 +191,7 @@ static void FS_fopen_read_update_create() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -201,7 +201,7 @@ static void FS_fopen_write_update_create() char write_buf[small_buf_size] = "123456789"; char read_buf[small_buf_size] = ""; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), small_buf_size, fd[0]); @@ -210,7 +210,7 @@ static void FS_fopen_write_update_create() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "w+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "w+")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), small_buf_size, fd[0]); @@ -219,7 +219,7 @@ static void FS_fopen_write_update_create() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } /*----------------fclose()------------------*/ @@ -227,13 +227,13 @@ static void FS_fopen_write_update_create() //fclose valid flow static void FS_fclose_valid_flow() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -244,7 +244,7 @@ static void FS_fwrite_nmemb_zero() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), 0, fd[0]); @@ -253,7 +253,7 @@ static void FS_fwrite_nmemb_zero() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -263,7 +263,7 @@ static void FS_fwrite_valid_flow() char write_buf[small_buf_size] = "good_day"; char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), small_buf_size, fd[0]); @@ -272,7 +272,7 @@ static void FS_fwrite_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), small_buf_size, fd[0]); @@ -282,7 +282,7 @@ static void FS_fwrite_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -291,13 +291,13 @@ static void FS_fwrite_with_fopen_r_mode() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), small_buf_size, fd[0]); @@ -306,7 +306,7 @@ static void FS_fwrite_with_fopen_r_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -317,7 +317,7 @@ static void FS_fread_size_zero() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), small_buf_size, fd[0]); @@ -326,7 +326,7 @@ static void FS_fread_size_zero() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(buffer, 0, small_buf_size, fd[0]); @@ -335,7 +335,7 @@ static void FS_fread_size_zero() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -344,7 +344,7 @@ static void FS_fread_nmemb_zero() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), small_buf_size, fd[0]); @@ -353,7 +353,7 @@ static void FS_fread_nmemb_zero() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(buffer, sizeof(char), 0, fd[0]); @@ -362,7 +362,7 @@ static void FS_fread_nmemb_zero() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -371,13 +371,13 @@ static void FS_fread_with_fopen_w_mode() { char buffer[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(buffer, sizeof(char), small_buf_size, fd[0]); @@ -386,7 +386,7 @@ static void FS_fread_with_fopen_w_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -396,7 +396,7 @@ static void FS_fread_to_fwrite_file() char read_buf[small_buf_size] = {}; char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), small_buf_size, fd[0]); @@ -408,7 +408,7 @@ static void FS_fread_to_fwrite_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -417,13 +417,13 @@ static void FS_fread_empty_file() { char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), small_buf_size, fd[0]); @@ -432,7 +432,7 @@ static void FS_fread_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -442,7 +442,7 @@ static void FS_fread_valid_flow_small_file() char write_buf[small_buf_size] = "good_day"; char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -451,7 +451,7 @@ static void FS_fread_valid_flow_small_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -461,7 +461,7 @@ static void FS_fread_valid_flow_small_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -472,7 +472,7 @@ static void FS_fread_valid_flow_medium_file() char write_buf[medium_buf_size] = { 1 }; char read_buf[medium_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -481,7 +481,7 @@ static void FS_fread_valid_flow_medium_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -491,7 +491,7 @@ static void FS_fread_valid_flow_medium_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -501,7 +501,7 @@ static void FS_fread_valid_flow_large_file() char write_buf[large_buf_size] = { 1 }; char read_buf[large_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -510,7 +510,7 @@ static void FS_fread_valid_flow_large_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -520,7 +520,7 @@ static void FS_fread_valid_flow_large_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -530,7 +530,7 @@ static void FS_fread_valid_flow_small_file_read_more_than_write() char write_buf[small_buf_size] = "good_day"; char read_buf[small_buf_size + 10] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -539,7 +539,7 @@ static void FS_fread_valid_flow_small_file_read_more_than_write() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -549,7 +549,7 @@ static void FS_fread_valid_flow_small_file_read_more_than_write() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -558,13 +558,13 @@ static void FS_fread_valid_flow_small_file_read_more_than_write() //fgetc to an empty file static void FS_fgetc_empty_file() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fgetc(fd[0]); @@ -573,7 +573,7 @@ static void FS_fgetc_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -585,7 +585,7 @@ static void FS_fgetc_valid_flow() int ch = 0; unsigned int i = 0; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -594,7 +594,7 @@ static void FS_fgetc_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); for (i = 0; (i < (sizeof(read_buf) - 1) && ((ch = fgetc(fd[0])) != EOF) && (ch != '\n')); i++) { @@ -607,20 +607,20 @@ static void FS_fgetc_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fgetc to fopen mode w static void FS_fgetc_with_fopen_w_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fgetc(fd[0]); @@ -629,7 +629,7 @@ static void FS_fgetc_with_fopen_w_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -640,13 +640,13 @@ static void FS_fgets_empty_file() { char buffer[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NULL(fgets(buffer, sizeof(buffer), fd[0])); @@ -654,20 +654,20 @@ static void FS_fgets_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fgets with buffer null with zero len of buffer string static void FS_fgets_null_buffer_zero_len() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NULL(fgets(NULL, 0, fd[0])); @@ -675,20 +675,20 @@ static void FS_fgets_null_buffer_zero_len() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fgets with buffer null static void FS_fgets_null_buffer() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NULL(fgets(NULL, small_buf_size, fd[0])); @@ -696,7 +696,7 @@ static void FS_fgets_null_buffer() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -706,7 +706,7 @@ static void FS_fgets_valid_flow() char write_buf[small_buf_size] = "good_day"; char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -715,7 +715,7 @@ static void FS_fgets_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NOT_NULL(fgets(read_buf, sizeof(read_buf), fd[0])); @@ -724,7 +724,7 @@ static void FS_fgets_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -736,7 +736,7 @@ static void FS_fgets_new_line() write_buf[4] = '\n'; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -745,7 +745,7 @@ static void FS_fgets_new_line() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NOT_NULL(fgets(read_buf, sizeof(read_buf), fd[0])); @@ -754,7 +754,7 @@ static void FS_fgets_new_line() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -763,13 +763,13 @@ static void FS_fgets_with_fopen_w_mode() { char buffer[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_NULL(fgets(buffer, sizeof(buffer), fd[0])); @@ -777,7 +777,7 @@ static void FS_fgets_with_fopen_w_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -796,7 +796,7 @@ static void FS_fflush_valid_flow() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), small_buf_size, fd[0]); @@ -808,7 +808,7 @@ static void FS_fflush_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -818,7 +818,7 @@ static void FS_fflush_twice() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(buffer, sizeof(char), small_buf_size, fd[0]); @@ -833,7 +833,7 @@ static void FS_fflush_twice() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -844,7 +844,7 @@ static void FS_fputc_valid_flow() { int write_ch = 10, read_ch = 0; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fputc(write_ch, fd[0]); @@ -853,7 +853,7 @@ static void FS_fputc_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); read_ch = fgetc(fd[0]); @@ -862,7 +862,7 @@ static void FS_fputc_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -871,13 +871,13 @@ static void FS_fputc_in_read_mode() { int write_ch = 10; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fputc(write_ch, fd[0]); @@ -886,7 +886,7 @@ static void FS_fputc_in_read_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -898,7 +898,7 @@ static void FS_fputs_valid_flow() char write_buf[small_buf_size] = "123456789"; char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fputs(write_buf, fd[0]); @@ -907,7 +907,7 @@ static void FS_fputs_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -917,7 +917,7 @@ static void FS_fputs_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -926,13 +926,13 @@ static void FS_fputs_in_read_mode() { char buffer[small_buf_size] = "good_day"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fputs(buffer, fd[0]); @@ -941,7 +941,7 @@ static void FS_fputs_in_read_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -950,13 +950,13 @@ static void FS_fputs_in_read_mode() //fseek empty file, SEEK_SET, offset 0 static void FS_fseek_empty_file_seek_set() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -968,7 +968,7 @@ static void FS_fseek_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -977,7 +977,7 @@ static void FS_fseek_non_empty_file_seek_set() { char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -986,7 +986,7 @@ static void FS_fseek_non_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -998,7 +998,7 @@ static void FS_fseek_non_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1007,13 +1007,13 @@ static void FS_fseek_beyond_empty_file_seek_set() { char read_buf[small_buf_size] = ""; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 10, SEEK_SET); @@ -1028,7 +1028,7 @@ static void FS_fseek_beyond_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1038,7 +1038,7 @@ static void FS_fseek_beyond_non_empty_file_seek_set() char write_buf[small_buf_size] = "123456789"; char read_buf[small_buf_size] = ""; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1047,7 +1047,7 @@ static void FS_fseek_beyond_non_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], sizeof(write_buf) + 1, SEEK_SET); @@ -1062,20 +1062,20 @@ static void FS_fseek_beyond_non_empty_file_seek_set() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fseek empty file, SEEK_CUR, offset 0 static void FS_fseek_empty_file_seek_cur() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_CUR); @@ -1087,7 +1087,7 @@ static void FS_fseek_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1096,7 +1096,7 @@ static void FS_fseek_non_empty_file_seek_cur() { char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1105,7 +1105,7 @@ static void FS_fseek_non_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_CUR); @@ -1117,7 +1117,7 @@ static void FS_fseek_non_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1126,13 +1126,13 @@ static void FS_fseek_beyond_empty_file_seek_cur() { char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 1, SEEK_CUR); @@ -1147,7 +1147,7 @@ static void FS_fseek_beyond_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1157,7 +1157,7 @@ static void FS_fseek_beyond_non_empty_file_seek_cur() char read_buf[small_buf_size] = {}; char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1166,7 +1166,7 @@ static void FS_fseek_beyond_non_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], sizeof(write_buf) + 1, SEEK_CUR); @@ -1181,20 +1181,20 @@ static void FS_fseek_beyond_non_empty_file_seek_cur() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } //fseek empty file, SEEK_END, offset 0 static void FS_fseek_empty_file_seek_end() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_END); @@ -1206,7 +1206,7 @@ static void FS_fseek_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1215,7 +1215,7 @@ static void FS_fseek_non_empty_file_seek_end() { char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1224,7 +1224,7 @@ static void FS_fseek_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_END); @@ -1236,7 +1236,7 @@ static void FS_fseek_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1245,13 +1245,13 @@ static void FS_fseek_beyond_empty_file_seek_end() { char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 1, SEEK_END); @@ -1266,7 +1266,7 @@ static void FS_fseek_beyond_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1276,7 +1276,7 @@ static void FS_fseek_beyond_non_empty_file_seek_end() char read_buf[small_buf_size] = {}; char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1285,7 +1285,7 @@ static void FS_fseek_beyond_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], sizeof(write_buf) + 1, SEEK_END); @@ -1300,7 +1300,7 @@ static void FS_fseek_beyond_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1309,7 +1309,7 @@ static void FS_fseek_negative_non_empty_file_seek_end() { char write_buf[small_buf_size] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1318,7 +1318,7 @@ static void FS_fseek_negative_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], -(sizeof(write_buf)), SEEK_END); @@ -1330,7 +1330,7 @@ static void FS_fseek_negative_non_empty_file_seek_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1344,7 +1344,7 @@ static void FS_fgetpos_rewrite_check_data() char read_buf[small_buf_size] = {}; fpos_t pos; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fgetpos(fd[0], &pos); @@ -1362,7 +1362,7 @@ static void FS_fgetpos_rewrite_check_data() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1372,7 +1372,7 @@ static void FS_fgetpos_rewrite_check_data() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1385,7 +1385,7 @@ static void FS_fscanf_valid_flow() char read_buf[small_buf_size] = {}; int num = 0; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fprintf(fd[0], "%d %s", 123, write_buf); @@ -1394,7 +1394,7 @@ static void FS_fscanf_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fscanf(fd[0], "%d", &num); @@ -1408,7 +1408,7 @@ static void FS_fscanf_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1417,7 +1417,7 @@ static void FS_fscanf_empty_file() { int num = 0; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fscanf(fd[0], "%d", &num); @@ -1426,7 +1426,7 @@ static void FS_fscanf_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1437,7 +1437,7 @@ static void FS_fscanf_more_fields_than_exist() char read_buf[small_buf_size] = {}; int num = 0; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fprintf(fd[0], "%d %s", 123, write_buf); @@ -1446,7 +1446,7 @@ static void FS_fscanf_more_fields_than_exist() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fscanf(fd[0], "%d", &num); @@ -1463,7 +1463,7 @@ static void FS_fscanf_more_fields_than_exist() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1472,13 +1472,13 @@ static void FS_fscanf_more_fields_than_exist() //fprintf in mode r static void FS_fprintf_read_mode() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fprintf(fd[0], "%d", 123); @@ -1487,7 +1487,7 @@ static void FS_fprintf_read_mode() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1496,10 +1496,10 @@ static void FS_fprintf_read_mode() //freopen point to the same file with two file handler static void FS_freopen_point_to_same_file() { - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); - res = !((fd[1] = freopen("fs/" "new_file_name", "wb", fd[0])) != NULL); + res = !((fd[1] = freopen("/default/" "new_file_name", "wb", fd[0])) != NULL); TEST_ASSERT_EQUAL(0, res); TEST_ASSERT_EQUAL(fd[0], fd[1]); @@ -1507,7 +1507,7 @@ static void FS_freopen_point_to_same_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1517,13 +1517,13 @@ static void FS_freopen_valid_flow() char write_buf[small_buf_size] = "123456789"; char read_buf[small_buf_size] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "wb")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "wb")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); TEST_ASSERT_EQUAL(sizeof(write_buf), write_sz); - res = !((fd[1] = freopen("fs/" "filename", "rb", fd[0])) != NULL); + res = !((fd[1] = freopen("/default/" "filename", "rb", fd[0])) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1533,7 +1533,7 @@ static void FS_freopen_valid_flow() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1545,7 +1545,7 @@ static void FS_fopen_write_one_byte_file() char write_buf = 1; char read_buf[1] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(&write_buf, sizeof(char), 1, fd[0]); @@ -1554,7 +1554,7 @@ static void FS_fopen_write_one_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1564,7 +1564,7 @@ static void FS_fopen_write_one_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1574,7 +1574,7 @@ static void FS_fopen_write_two_byte_file() char write_buf[2] = "1"; char read_buf[2] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1583,7 +1583,7 @@ static void FS_fopen_write_two_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1593,7 +1593,7 @@ static void FS_fopen_write_two_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1603,7 +1603,7 @@ static void FS_fopen_write_five_byte_file() char write_buf[5] = "1234"; char read_buf[5] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1612,7 +1612,7 @@ static void FS_fopen_write_five_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1622,7 +1622,7 @@ static void FS_fopen_write_five_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1632,7 +1632,7 @@ static void FS_fopen_write_fifteen_byte_file() char write_buf[15] = "12345678901234"; char read_buf[15] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1641,7 +1641,7 @@ static void FS_fopen_write_fifteen_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1651,7 +1651,7 @@ static void FS_fopen_write_fifteen_byte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1663,7 +1663,7 @@ static void FS_fopen_write_five_Kbyte_file() char read_buf[10] = {}; char check_buf[10] = "123456789"; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); memcpy(write_buf, check_buf, sizeof(check_buf) - 1); @@ -1673,7 +1673,7 @@ static void FS_fopen_write_five_Kbyte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "rb+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "rb+")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf) - 1, fd[0]); @@ -1683,7 +1683,7 @@ static void FS_fopen_write_five_Kbyte_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1695,7 +1695,7 @@ static void FS_fseek_rewrite_non_empty_file_begining() char check_buf[15] = "abcde678901234"; char read_buf[15] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1704,7 +1704,7 @@ static void FS_fseek_rewrite_non_empty_file_begining() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -1716,7 +1716,7 @@ static void FS_fseek_rewrite_non_empty_file_begining() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -1729,7 +1729,7 @@ static void FS_fseek_rewrite_non_empty_file_begining() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1741,7 +1741,7 @@ static void FS_fseek_rewrite_non_empty_file_middle() char check_buf[15] = "12345abcde1234"; char read_buf[15] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1750,7 +1750,7 @@ static void FS_fseek_rewrite_non_empty_file_middle() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 5, SEEK_SET); @@ -1762,7 +1762,7 @@ static void FS_fseek_rewrite_non_empty_file_middle() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -1775,7 +1775,7 @@ static void FS_fseek_rewrite_non_empty_file_middle() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1787,7 +1787,7 @@ static void FS_fseek_rewrite_non_empty_file_end() char check_buf[15] = "123456789abcde"; char read_buf[15] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1796,7 +1796,7 @@ static void FS_fseek_rewrite_non_empty_file_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r+")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 9, SEEK_SET); @@ -1808,7 +1808,7 @@ static void FS_fseek_rewrite_non_empty_file_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); res = fseek(fd[0], 0, SEEK_SET); @@ -1821,7 +1821,7 @@ static void FS_fseek_rewrite_non_empty_file_end() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1831,7 +1831,7 @@ static void FS_append_empty_file() char write_buf[17] = "1234567890123456"; char read_buf[17] = {}; - int res = !((fd[0] = fopen("fs/" "filename", "a")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "a")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf), fd[0]); @@ -1840,7 +1840,7 @@ static void FS_append_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); int read_sz = fread(read_buf, sizeof(char), sizeof(read_buf), fd[0]); @@ -1850,7 +1850,7 @@ static void FS_append_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1862,7 +1862,7 @@ static void FS_append_non_empty_file() char read_buf[34] = {}; char check_buf[34] = "1234567890123456abcdefghijklmnop"; - int res = !((fd[0] = fopen("fs/" "filename", "a")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "a")) != NULL); TEST_ASSERT_EQUAL(0, res); int write_sz = fwrite(write_buf, sizeof(char), sizeof(write_buf) - 1, fd[0]); @@ -1871,7 +1871,7 @@ static void FS_append_non_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "a+")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "a+")) != NULL); TEST_ASSERT_EQUAL(0, res); write_sz = fwrite(rewrite_buf, sizeof(char), sizeof(rewrite_buf), fd[0]); @@ -1880,7 +1880,7 @@ static void FS_append_non_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); memcpy(check_buf, write_buf, sizeof(write_buf) - 1); @@ -1893,7 +1893,7 @@ static void FS_append_non_empty_file() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1904,7 +1904,7 @@ static void FS_write_read_random_data() unsigned int i; // Fill write_buf buffer with random data and write the data into the file - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); for (i = 0; i < medium_buf_size; i++) { @@ -1917,7 +1917,7 @@ static void FS_write_read_random_data() TEST_ASSERT_EQUAL(0, res); // Read back the data from the file and store them in data_read - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); for (i = 0; i < medium_buf_size; i++) { @@ -1928,7 +1928,7 @@ static void FS_write_read_random_data() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } @@ -1937,7 +1937,7 @@ static void FS_fill_data_and_seek() { unsigned int i, j; - int res = !((fd[0] = fopen("fs/" "filename", "w")) != NULL); + int res = !((fd[0] = fopen("/default/" "filename", "w")) != NULL); TEST_ASSERT_EQUAL(0, res); for (i = 0; i < 256; i++) { @@ -1948,7 +1948,7 @@ static void FS_fill_data_and_seek() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = !((fd[0] = fopen("fs/" "filename", "r")) != NULL); + res = !((fd[0] = fopen("/default/" "filename", "r")) != NULL); TEST_ASSERT_EQUAL(0, res); for (i = 1; i <= 255; i++) { @@ -1978,7 +1978,7 @@ static void FS_fill_data_and_seek() res = fclose(fd[0]); TEST_ASSERT_EQUAL(0, res); - res = remove("fs/" "filename"); + res = remove("/default/" "filename"); TEST_ASSERT_EQUAL(0, res); } diff --git a/features/storage/filesystem/littlefs/LittleFileSystem.cpp b/features/storage/filesystem/littlefs/LittleFileSystem.cpp index 74f52f3278..8e17af9a2f 100644 --- a/features/storage/filesystem/littlefs/LittleFileSystem.cpp +++ b/features/storage/filesystem/littlefs/LittleFileSystem.cpp @@ -18,7 +18,14 @@ #include "errno.h" #include "lfs.h" #include "lfs_util.h" +#include "MbedCRC.h" +extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size) +{ + uint32_t initial_xor = *crc; + MbedCRC ct(initial_xor, 0x0, true, false); + ct.compute((void *)buffer, size, (uint32_t *) crc); +} ////// Conversion functions ////// static int lfs_toerror(int err) diff --git a/features/storage/filesystem/littlefs/littlefs/lfs_util.c b/features/storage/filesystem/littlefs/littlefs/lfs_util.c index 9ca0756d96..113632b66b 100644 --- a/features/storage/filesystem/littlefs/littlefs/lfs_util.c +++ b/features/storage/filesystem/littlefs/littlefs/lfs_util.c @@ -6,11 +6,10 @@ */ #include "lfs_util.h" + // Only compile if user does not provide custom config #ifndef LFS_CONFIG - - -// Software CRC implementation with small lookup table +#ifndef __MBED__ void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) { static const uint32_t rtable[16] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, @@ -20,12 +19,10 @@ void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) { }; const uint8_t *data = buffer; - for (size_t i = 0; i < size; i++) { *crc = (*crc >> 4) ^ rtable[(*crc ^ (data[i] >> 0)) & 0xf]; *crc = (*crc >> 4) ^ rtable[(*crc ^ (data[i] >> 4)) & 0xf]; } } - - #endif +#endif \ No newline at end of file diff --git a/features/storage/system_storage/SystemStorage.cpp b/features/storage/system_storage/SystemStorage.cpp index ffccd19389..5ce4146ef7 100644 --- a/features/storage/system_storage/SystemStorage.cpp +++ b/features/storage/system_storage/SystemStorage.cpp @@ -80,15 +80,17 @@ MBED_WEAK FileSystem *FileSystem::get_default_instance() { #if COMPONENT_SPIF || COMPONENT_DATAFLASH - static LittleFileSystem default_fs("fs", BlockDevice::get_default_instance()); + static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); + flash.set_as_default(); - return &default_fs; + return &flash; #elif COMPONENT_SD - static FATFileSystem default_fs("fs", BlockDevice::get_default_instance()); + static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); + sdcard.set_as_default(); - return &default_fs; + return &sdcard; #else diff --git a/hal/crc_api.h b/hal/crc_api.h index 2421e46315..29336feb9b 100644 --- a/hal/crc_api.h +++ b/hal/crc_api.h @@ -33,6 +33,7 @@ typedef enum crc_polynomial { POLY_16BIT_CCITT = 0x1021, // x16+x12+x5+1 POLY_16BIT_IBM = 0x8005, // x16+x15+x2+1 POLY_32BIT_ANSI = 0x04C11DB7, // x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1 + POLY_32BIT_REV_ANSI = 0xEDB88320 } crc_polynomial_t; typedef struct crc_mbed_config { diff --git a/platform/FileBase.cpp b/platform/FileBase.cpp index a6ca848a82..ce0229bace 100644 --- a/platform/FileBase.cpp +++ b/platform/FileBase.cpp @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include + #include "platform/FileBase.h" #include "platform/FileLike.h" #include "platform/FileHandle.h" @@ -21,6 +23,7 @@ namespace mbed { FileBase *FileBase::_head = NULL; SingletonPtr FileBase::_mutex; +FileBase *FileBase::_default = NULL; FileBase::FileBase(const char *name, PathType t) : _next(NULL), _name(name), @@ -52,26 +55,41 @@ FileBase::~FileBase() p->_next = _next; } } + + if (_default == this) { + _default == NULL; + } + _mutex->unlock(); if (getPathType() == FilePathType) { - extern void remove_filehandle(FileHandle * file); - remove_filehandle(static_cast(static_cast(this))); + extern void remove_filehandle(FileHandle *file); + remove_filehandle(static_cast(this)); } } +void FileBase::set_as_default() +{ + _mutex->lock(); + _default = this; + _mutex->unlock(); +} + FileBase *FileBase::lookup(const char *name, unsigned int len) { _mutex->lock(); FileBase *p = _head; while (p != NULL) { /* Check that p->_name matches name and is the correct length */ - if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) { + if (p->_name != NULL && len == std::strlen(p->_name) && std::memcmp(p->_name, name, len) == 0) { _mutex->unlock(); return p; } p = p->_next; } + if (len == (sizeof "default") - 1 && std::memcmp("default", name, len) == 0) { + return _default; + } _mutex->unlock(); return NULL; } diff --git a/platform/FileBase.h b/platform/FileBase.h index 0ef63b40af..25b650145b 100644 --- a/platform/FileBase.h +++ b/platform/FileBase.h @@ -18,9 +18,6 @@ typedef int FILEHANDLE; -#include -#include - #include "platform/platform.h" #include "platform/SingletonPtr.h" #include "platform/PlatformMutex.h" @@ -55,9 +52,11 @@ public: static FileBase *get(int n); - /* disallow copy constructor and assignment operators */ + void set_as_default(); + private: static FileBase *_head; + static FileBase *_default; static SingletonPtr _mutex; FileBase *_next; diff --git a/platform/mbed_version.h b/platform/mbed_version.h index 8fe2258b24..a300bc1bed 100644 --- a/platform/mbed_version.h +++ b/platform/mbed_version.h @@ -29,21 +29,21 @@ * * @note 99 is default value for development version (master branch) */ -#define MBED_MAJOR_VERSION 5 +#define MBED_MAJOR_VERSION 5 /** MBED_MINOR_VERSION * Mbed OS minor version * * @note 99 is default value for development version (master branch) */ -#define MBED_MINOR_VERSION 10 +#define MBED_MINOR_VERSION 10 /** MBED_PATCH_VERSION * Mbed OS patch version * * @note 99 is default value for development version (master branch) */ -#define MBED_PATCH_VERSION 0 +#define MBED_PATCH_VERSION 0 #define MBED_ENCODE_VERSION(major, minor, patch) ((major)*10000 + (minor)*100 + (patch)) diff --git a/targets/TARGET_Freescale/TARGET_K20XX/TARGET_K20D50M/PinNames.h b/targets/TARGET_Freescale/TARGET_K20XX/TARGET_K20D50M/PinNames.h index 19168198f8..7bba6da7ea 100644 --- a/targets/TARGET_Freescale/TARGET_K20XX/TARGET_K20D50M/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_K20XX/TARGET_K20D50M/PinNames.h @@ -236,11 +236,6 @@ typedef enum { TSI_ELEC0 = PTB16, TSI_ELEC1 = PTB17, - - SPI_MOSI = PTD2, - SPI_MISO = PTD3, - SPI_CLK = PTD1, - SPI_PERSISTENT_MEM_CS = PTC2, // Not connected NC = (int)0xFFFFFFFF diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PinNames.h b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PinNames.h index 8b8935d25a..89ebb11aec 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PinNames.h @@ -236,11 +236,6 @@ typedef enum { TSI_ELEC0 = PTB16, TSI_ELEC1 = PTB17, - SPI_MOSI = PTD2, - SPI_MISO = PTD3, - SPI_SCK = PTD1, - SPI_PERSISTENT_MEM_CS = PTD0, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PinNames.h b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PinNames.h index 559c0ee582..83b2dae7b9 100644 --- a/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PinNames.h @@ -242,11 +242,6 @@ typedef enum { TSI_ELEC0 = PTB16, TSI_ELEC1 = PTB17, - SPI_MOSI = PTD6, - SPI_MISO = PTD7, - SPI_SCK = PTD5, - SPI_PERSISTENT_MEM_CS = PTD4, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/TARGET_FRDM/PinNames.h index 39575f953d..7ff8b86d75 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/TARGET_FRDM/PinNames.h @@ -242,11 +242,6 @@ typedef enum { DAC0_OUT = 0xFEFE, /* DAC does not have Pin Name in RM */ - SPI_MOSI = PTE3, - SPI_MISO = PTE1, - SPI_SCK = PTE2, - SPI_PERSISTENT_MEM_CS = PTE4, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/TARGET_FRDM/PinNames.h index 6b46853878..081010164c 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/TARGET_FRDM/PinNames.h @@ -134,11 +134,6 @@ typedef enum { A4 = PTC2, A5 = PTC1, - SPI_MOSI = PTD6, - SPI_MISO = PTD7, - SPI_SCK = PTD5, - SPI_PERSISTENT_MEM_CS = PTD4, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/TARGET_MCU_K22F512/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/TARGET_MCU_K22F512/TARGET_FRDM/PinNames.h index 34fa2e1678..3533d831c7 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/TARGET_MCU_K22F512/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/TARGET_MCU_K22F512/TARGET_FRDM/PinNames.h @@ -243,11 +243,6 @@ typedef enum { DAC0_OUT = 0xFEFE, /* DAC does not have Pin Name in RM */ - SPI_MOSI = PTD6, - SPI_MISO = PTD7, - SPI_SCK = PTD5, - SPI_PERSISTENT_MEM_CS = PTD4, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct index d58db0e15d..e33232db83 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct @@ -9,13 +9,13 @@ #define MBED_APP_SIZE 0x80000 #endif -/* If app_start is 0, do not set aside space for the softdevice */ -#if MBED_APP_START == 0 - #define MBED_RAM_START 0x20000000 - #define MBED_RAM_SIZE 0x10000 -#else +/* If softdevice is present, set aside space for it */ +#if defined(SOFTDEVICE_PRESENT) #define MBED_RAM_START 0x200031D0 #define MBED_RAM_SIZE 0xCE30 +#else + #define MBED_RAM_START 0x20000000 + #define MBED_RAM_SIZE 0x10000 #endif #define MBED_RAM0_START MBED_RAM_START diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_GCC_ARM/NRF52832.ld b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_GCC_ARM/NRF52832.ld index fd76160066..1d2bdfc7df 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_GCC_ARM/NRF52832.ld +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_GCC_ARM/NRF52832.ld @@ -25,13 +25,13 @@ #define MBED_APP_SIZE 0x80000 #endif -/* If app_start is 0, do not set aside space for the softdevice */ -#if MBED_APP_START == 0 - #define MBED_RAM_START 0x20000000 - #define MBED_RAM_SIZE 0x10000 -#else +/* If softdevice is present, set aside space for it */ +#if defined(SOFTDEVICE_PRESENT) #define MBED_RAM_START 0x200031D0 #define MBED_RAM_SIZE 0xCE30 +#else + #define MBED_RAM_START 0x20000000 + #define MBED_RAM_SIZE 0x10000 #endif #define MBED_RAM0_START MBED_RAM_START diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_IAR/nRF52832.icf b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_IAR/nRF52832.icf index 5400c6e5f3..de450f5516 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_IAR/nRF52832.icf +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_IAR/nRF52832.icf @@ -11,13 +11,13 @@ if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x80000; } -/* If app_start is 0, do not set aside space for the softdevice */ -if (MBED_APP_START == 0) { - define symbol MBED_RAM_START = 0x20000000; - define symbol MBED_RAM_SIZE = 0x10000; -} else { +/* If softdevice is present, set aside space for it */ +if (isdefinedsymbol(SOFTDEVICE_PRESENT)) { define symbol MBED_RAM_START = 0x200031D0; define symbol MBED_RAM_SIZE = 0xCE30; +} else { + define symbol MBED_RAM_START = 0x20000000; + define symbol MBED_RAM_SIZE = 0x10000; } define symbol MBED_RAM0_START = MBED_RAM_START; diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h index 6fd118dbf5..5730e040c1 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h @@ -197,11 +197,6 @@ typedef enum { SPIS_PSELMISO = P1_3, SPIS_PSELSS = P1_1, SPIS_PSELSCK = P1_4, - - SPI_MOSI = p20, - SPI_MISO = p21, - SPI_SCK = p19, - SPI_PERSISTENT_MEM_CS = p17, I2C_SDA0 = p26, I2C_SCL0 = p27, diff --git a/targets/TARGET_NUVOTON/TARGET_M451/PinNames.h b/targets/TARGET_NUVOTON/TARGET_M451/PinNames.h index e67c71ce01..4599c86ca9 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/PinNames.h +++ b/targets/TARGET_NUVOTON/TARGET_M451/PinNames.h @@ -128,11 +128,6 @@ typedef enum { SW2 = PA_15, SW3 = PA_14, - SPI_MOSI = PD_13, - SPI_MISO = PD_14, - SPI_SCK = PD_15, - SPI_PERSISTENT_MEM_CS = PD_12, - } PinName; #ifdef __cplusplus diff --git a/targets/TARGET_NUVOTON/TARGET_M480/PinNames.h b/targets/TARGET_NUVOTON/TARGET_M480/PinNames.h index a1f37e9dbe..816d5ece49 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/PinNames.h +++ b/targets/TARGET_NUVOTON/TARGET_M480/PinNames.h @@ -128,11 +128,6 @@ typedef enum { SW2 = PG_15, SW3 = PF_11, - SPI_MOSI = D11, - SPI_MISO = D12, - SPI_SCK = D13, - SPI_PERSISTENT_MEM_CS = D10, - } PinName; #ifdef __cplusplus diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/PinNames.h b/targets/TARGET_NUVOTON/TARGET_NUC472/PinNames.h index e9c9d02646..4beecb4b88 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/PinNames.h +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/PinNames.h @@ -131,11 +131,6 @@ typedef enum { SW1 = PC_12, SW2 = PC_13, - SPI_MOSI = PF_0, - SPI_MISO = PD_15, - SPI_SCK = PD_14, - SPI_PERSISTENT_MEM_CS = PD_13, - } PinName; #ifdef __cplusplus diff --git a/targets/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U37H_401/PinNames.h b/targets/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U37H_401/PinNames.h index 4eeef0a2c5..56e1f557f4 100644 --- a/targets/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U37H_401/PinNames.h +++ b/targets/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U37H_401/PinNames.h @@ -148,11 +148,6 @@ typedef enum { SDSCLK = P1_29, SDSSEL = P1_12, - SPI_MOSI = SDMOSI, - SPI_MISO = SDMISO, - SPI_SCK = SDSCLK, - SPI_PERSISTENT_MEM_CS = SDSSEL, - // Not connected NC = (int)0xFFFFFFFF, } PinName; diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h index da5360291a..fa0b722f70 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h @@ -149,12 +149,6 @@ typedef enum { I2C_SDA2 = P0_10, // pin used by application board I2C_SCL = I2C_SCL2, I2C_SDA = I2C_SDA2, - - SPI_MOSI = p5, - SPI_MISO = p6, - SPI_SCK = p7, - SPI_PERSISTENT_MEM_CS = p8 - } PinName; typedef enum { diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_XBED_LPC1768/PinNames.h b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_XBED_LPC1768/PinNames.h index 0e036ca1ea..50bdb1bb57 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_XBED_LPC1768/PinNames.h +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_XBED_LPC1768/PinNames.h @@ -117,11 +117,6 @@ typedef enum { I2C_SCL = D15, I2C_SDA = D14, - SPI_MOSI = p5, - SPI_MISO = p6, - SPI_SCK = p7, - SPI_PERSISTENT_MEM_CS = p8, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PinNames.h b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PinNames.h index 51f5340e21..7857ad12e5 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PinNames.h +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/TARGET_LPCXpresso/PinNames.h @@ -128,13 +128,7 @@ typedef enum { A2 = P1_8, A3 = P1_10, A4 = P1_4, - A5 = P1_5, - - SPI_MOSI = P0_20, - SPI_MISO = P0_18, - SPI_SCK = P0_19, - SPI_PERSISTENT_MEM_CS = P1_2 - + A5 = P1_5 } PinName; diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/PinNames.h b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/PinNames.h index ed201fe48d..d60a4b5a55 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/PinNames.h +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/PinNames.h @@ -89,11 +89,6 @@ typedef enum { // Standardized button names BUTTON1 = USER_BUTTON0, - SPI_MOSI = P5_6, - SPI_MISO = P5_7, - SPI_SCK = P5_4, - SPI_PERSISTENT_MEM_CS = P5_5, - // Not connected NC = (int)0xFFFFFFFF } PinName; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/PinNames.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/PinNames.h index a9d0fb4e5c..60895420ed 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/PinNames.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/PinNames.h @@ -216,9 +216,7 @@ typedef enum { D15 = PB_2, D16 = PA_1, D17 = PA_0, - D18 = PE_5, - - SPI_PERSISTENT_MEM_CS = D9 + D18 = PE_5 } PinName; diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/PinNames.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/PinNames.h index 4296e71217..6b25d5c481 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/PinNames.h @@ -228,7 +228,6 @@ typedef enum { SPI_MISO = PA_6, SPI_SCK = PA_5, SPI_CS = PB_6, - SPI_PERSISTENT_MEM_CS = PB_6, PWM_OUT = PB_3, /**** OSCILLATOR pins ****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/PinNames.h index 6eb0cc1805..42fa8e5fa1 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/PinNames.h @@ -186,12 +186,9 @@ typedef enum { SPI_MOSI = SPI1_MOSI, SPI_MISO = SPI1_MISO, SPI_SCK = SPI1_SCK, - SPI_CS1 = PA_3, //LCD CS SPI_CS2 = PA_15, //SD Card CS - SPI_PERSISTENT_MEM_CS = SPI_CS2, - SERIAL_TX = PA_2, SERIAL_RX = PA_3, SERIAL_RTS = PA_0, diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_MTB_MXCHIP_EMW3166/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_MTB_MXCHIP_EMW3166/PinNames.h index 019e9caa97..80e698307c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_MTB_MXCHIP_EMW3166/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_MTB_MXCHIP_EMW3166/PinNames.h @@ -219,7 +219,6 @@ typedef enum { SPI_MISO = P_7, SPI_SCK = P_6, SPI_CS = P_5, - SPI_PERSISTENT_MEM_CS = P_33, // STDIO for console print #ifdef MBED_CONF_TARGET_STDIO_UART_TX diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_USI_WM_BN_BM_22/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_USI_WM_BN_BM_22/PinNames.h index 1e7f950e48..42969ea6bc 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_USI_WM_BN_BM_22/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xG/TARGET_USI_WM_BN_BM_22/PinNames.h @@ -271,7 +271,6 @@ typedef enum { SPI_MISO = P_25, SPI_SCK = P_24, SPI_CS = P_22, - SPI_PERSISTENT_MEM_CS = P_36, // STDIO for console print #ifdef MBED_CONF_TARGET_STDIO_UART_TX diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PinNames.h index ad5aef1971..2f9f84c09c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PinNames.h @@ -151,8 +151,6 @@ typedef enum { SPI_MISO = D12, SPI_CLK = D13, SPI_NSS = D10, - SPI_PERSISTENT_MEM_CS = SPI_NSS, - // STDIO for console print #ifdef MBED_CONF_TARGET_STDIO_UART_TX diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_MTB_UBLOX_ODIN_W2/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_MTB_UBLOX_ODIN_W2/PinNames.h index 702b174ff4..c61f4dd431 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_MTB_UBLOX_ODIN_W2/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_MTB_UBLOX_ODIN_W2/PinNames.h @@ -176,7 +176,6 @@ typedef enum { SPI_MISO = SPI0_MISO, SPI_SCK = SPI0_SCK, SPI_CS = SPI0_CS, - SPI_PERSISTENT_MEM_CS = PG_4, // STDIO for console print #ifdef MBED_CONF_TARGET_STDIO_UART_TX diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_UBLOX_EVK_ODIN_W2/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_UBLOX_EVK_ODIN_W2/PinNames.h index da5e2951a0..b876c11f1e 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_UBLOX_EVK_ODIN_W2/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/TARGET_UBLOX_EVK_ODIN_W2/PinNames.h @@ -167,13 +167,12 @@ typedef enum { SPI0_SCK = D13, SPI0_CS = D10, SPI1_CS = D9, - SPI_MOSI = SPI0_MOSI, SPI_MISO = SPI0_MISO, SPI_SCK = SPI0_SCK, SPI_CS = SPI0_CS, - SPI_PERSISTENT_MEM_CS = SPI_CS, + // Standardized button names BUTTON1 = SW0, diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/PinNames.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/PinNames.h index bd6f3b00f1..910facf89a 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/PinNames.h @@ -133,7 +133,6 @@ typedef enum { SPI_MISO = PB_4, SPI_SCK = PB_3, SPI_CS = PA_11, - SPI_PERSISTENT_MEM_CS = PA_11, PWM_OUT = PB_0, /**** OSCILLATOR pins ****/ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PinNames.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PinNames.h index 7e427cc1bd..721cfbc2d1 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PinNames.h @@ -239,16 +239,7 @@ typedef enum { SPI_MISO = D12, SPI_SCK = D13, SPI_CS = D10, - SPI_PERSISTENT_MEM_CS = D10, PWM_OUT = D9, -#ifdef DEVICE_QSPI - QSPI_PIN_IO0 = PE_12, - QSPI_PIN_IO1 = PE_13, - QSPI_PIN_IO2 = PE_14, - QSPI_PIN_IO3 = PE_15, - QSPI_PIN_SCK = PE_10, - QSPI_PIN_CSN = PE_11, -#endif /**** USB pins ****/ USB_OTG_FS_DM = PA_11, diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/PinNames.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/PinNames.h index a5686fc166..8e2bf1d467 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/TARGET_NUCLEO_L476RG/PinNames.h @@ -208,7 +208,6 @@ typedef enum { SPI_MISO = PA_6, SPI_SCK = PA_5, SPI_CS = PB_6, - SPI_PERSISTENT_MEM_CS = PB_6, PWM_OUT = PB_3, /**** USB pins ****/ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/PinNames.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/PinNames.h index 769163db2c..06bb5f4438 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L486xG/TARGET_MTB_ADV_WISE_1570/PinNames.h @@ -124,8 +124,7 @@ typedef enum { SPI_SCK = PA_5, SPI_CS0 = PA_4, SPI_CS = SPI_CS0, - SPI_PERSISTENT_MEM_CS = PB_12, - + I2C1_SDA = PB_11, I2C1_SCL = PB_10, diff --git a/targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c b/targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c index c80d087a73..3bc57b31f9 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c +++ b/targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c @@ -38,8 +38,6 @@ extern uint32_t __mbed_sbrk_start; extern uint32_t __mbed_krbs_start; -#define STM32L4_HEAP_ALIGN 32 -#define STM32L4_ALIGN_UP(X, ALIGN) (((X) + (ALIGN) - 1) & ~((ALIGN) - 1)) /** * The default implementation of _sbrk() (in platform/mbed_retarget.cpp) for GCC_ARM requires one-region model (heap and * stack share one region), which doesn't fit two-region model (heap and stack are two distinct regions), for example, @@ -50,10 +48,10 @@ extern uint32_t __mbed_krbs_start; void *__wrap__sbrk(int incr) { static uint32_t heap_ind = (uint32_t) &__mbed_sbrk_start; - uint32_t heap_ind_old = STM32L4_ALIGN_UP(heap_ind, STM32L4_HEAP_ALIGN); - uint32_t heap_ind_new = STM32L4_ALIGN_UP(heap_ind_old + incr, STM32L4_HEAP_ALIGN); + uint32_t heap_ind_old = heap_ind; + uint32_t heap_ind_new = heap_ind_old + incr; - if (heap_ind_new > &__mbed_krbs_start) { + if (heap_ind_new > (uint32_t)&__mbed_krbs_start) { errno = ENOMEM; return (void *) - 1; } diff --git a/targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFR32MG12/TARGET_TB_SENSE_12/PinNames.h b/targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFR32MG12/TARGET_TB_SENSE_12/PinNames.h index 936b30acfa..39e905f421 100644 --- a/targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFR32MG12/TARGET_TB_SENSE_12/PinNames.h +++ b/targets/TARGET_Silicon_Labs/TARGET_EFM32/TARGET_EFR32MG12/TARGET_TB_SENSE_12/PinNames.h @@ -74,13 +74,7 @@ typedef enum { /* Board Controller */ STDIO_UART_TX = USBTX, - STDIO_UART_RX = USBRX, - - SPI_MOSI = PC6, - SPI_MISO = PC7, - SPI_SCK = PC8, - SPI_PERSISTENT_MEM_CS = PC9 - + STDIO_UART_RX = USBRX } PinName; #ifdef __cplusplus diff --git a/tools/build_api.py b/tools/build_api.py index c3140b455e..4a3de865d3 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -1161,7 +1161,7 @@ def mcu_toolchain_matrix(verbose_html=False, platform_filter=None, release_version - get the matrix for this major version number """ # Only use it in this function so building works without extra modules - from prettytable import PrettyTable + from prettytable import PrettyTable, HEADER release_version = _lowercase_release_version(release_version) version_release_targets = {} version_release_target_names = {} @@ -1183,7 +1183,7 @@ def mcu_toolchain_matrix(verbose_html=False, platform_filter=None, # All tests status table print columns = prepend_columns + unique_supported_toolchains - table_printer = PrettyTable(columns) + table_printer = PrettyTable(columns, junction_char="|", hrules=HEADER) # Align table for col in columns: table_printer.align[col] = "c" @@ -1271,10 +1271,10 @@ def print_build_memory_usage(report): Positional arguments: report - Report generated during build procedure. """ - from prettytable import PrettyTable + from prettytable import PrettyTable, HEADER columns_text = ['name', 'target', 'toolchain'] columns_int = ['static_ram', 'total_flash'] - table = PrettyTable(columns_text + columns_int) + table = PrettyTable(columns_text + columns_int, junction_char="|", hrules=HEADER) for col in columns_text: table.align[col] = 'l' diff --git a/tools/memap.py b/tools/memap.py index eab3864c82..00c5aa36f5 100644 --- a/tools/memap.py +++ b/tools/memap.py @@ -19,7 +19,7 @@ import json from argparse import ArgumentParser from copy import deepcopy from collections import defaultdict -from prettytable import PrettyTable +from prettytable import PrettyTable, HEADER from jinja2 import FileSystemLoader, StrictUndefined from jinja2.environment import Environment @@ -726,7 +726,7 @@ class MemapParser(object): columns = ['Module'] columns.extend(self.print_sections) - table = PrettyTable(columns) + table = PrettyTable(columns, junction_char="|", hrules=HEADER) table.align["Module"] = "l" for col in self.print_sections: table.align[col] = 'r' diff --git a/tools/profiles/debug.json b/tools/profiles/debug.json index 4966eb831d..dc0ace4e0b 100644 --- a/tools/profiles/debug.json +++ b/tools/profiles/debug.json @@ -23,7 +23,7 @@ "asm": [], "c": ["-D__ASSERT_MSG", "-std=gnu99"], "cxx": ["-fno-rtti", "-std=gnu++98"], - "ld": ["--verbose", "--remove", "--show_full_path"] + "ld": ["--verbose", "--remove", "--show_full_path", "--legacyalign"] }, "ARM": { "common": ["-c", "--gnu", "-Otime", "--split_sections", diff --git a/tools/profiles/develop.json b/tools/profiles/develop.json index adcdc72b83..1006de70a8 100644 --- a/tools/profiles/develop.json +++ b/tools/profiles/develop.json @@ -22,7 +22,7 @@ "asm": [], "c": ["-D__ASSERT_MSG", "-std=gnu99"], "cxx": ["-fno-rtti", "-std=gnu++98"], - "ld": ["--show_full_path"] + "ld": ["--show_full_path", "--legacyalign"] }, "ARM": { "common": ["-c", "--gnu", "-Otime", "--split_sections", diff --git a/tools/profiles/release.json b/tools/profiles/release.json index eab730a186..e0c36c979e 100644 --- a/tools/profiles/release.json +++ b/tools/profiles/release.json @@ -22,7 +22,7 @@ "asm": [], "c": ["-D__ASSERT_MSG", "-std=gnu99"], "cxx": ["-fno-rtti", "-std=gnu++98"], - "ld": ["--show_full_path"] + "ld": ["--show_full_path", "--legacyalign"] }, "ARM": { "common": ["-c", "--gnu", "-Ospace", "--split_sections", diff --git a/tools/test_api.py b/tools/test_api.py index 848b5f8405..c5de7318f6 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -32,7 +32,7 @@ import threading import ctypes import functools from colorama import Fore, Back, Style -from prettytable import PrettyTable +from prettytable import PrettyTable, HEADER from copy import copy, deepcopy from time import sleep, time @@ -766,7 +766,7 @@ class SingleTestRunner(object): result_dict[test[TEST_INDEX]][test[TOOLCHAIN_INDEX]] = test[RESULT_INDEX] pt_cols = ["Target", "Test ID", "Test Description"] + unique_target_toolchains - pt = PrettyTable(pt_cols) + pt = PrettyTable(pt_cols, junction_char="|", hrules=HEADER) for col in pt_cols: pt.align[col] = "l" pt.padding_width = 1 # One space between column edges and contents (default) @@ -794,7 +794,7 @@ class SingleTestRunner(object): result = "Test summary:\n" # Pretty table package is used to print results pt = PrettyTable(["Result", "Target", "Toolchain", "Test ID", "Test Description", - "Elapsed Time (sec)", "Timeout (sec)", "Loops"]) + "Elapsed Time (sec)", "Timeout (sec)", "Loops"], junction_char="|", hrules=HEADER) pt.align["Result"] = "l" # Left align pt.align["Target"] = "l" # Left align pt.align["Toolchain"] = "l" # Left align @@ -1328,7 +1328,7 @@ def print_muts_configuration_from_json(json_data, join_delim=", ", platform_filt # Prepare pretty table object to display all MUTs pt_cols = ["index"] + muts_info_cols - pt = PrettyTable(pt_cols) + pt = PrettyTable(pt_cols, junction_char="|", hrules=HEADER) for col in pt_cols: pt.align[col] = "l" @@ -1366,7 +1366,7 @@ def print_test_configuration_from_json(json_data, join_delim=", "): # Prepare pretty table object to display test specification pt_cols = ["mcu"] + sorted(toolchains_info_cols) - pt = PrettyTable(pt_cols) + pt = PrettyTable(pt_cols, junction_char="|", hrules=HEADER) for col in pt_cols: pt.align[col] = "l" @@ -1455,7 +1455,7 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=',' 'duration'] if cols is None else cols # All tests status table print - pt = PrettyTable(test_properties) + pt = PrettyTable(test_properties, junction_char="|", hrules=HEADER) for col in test_properties: pt.align[col] = "l" pt.align['duration'] = "r" @@ -1495,7 +1495,7 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=',' if result_summary and not platform_filter: # Automation result summary test_id_cols = ['automated', 'all', 'percent [%]', 'progress'] - pt = PrettyTable(test_id_cols) + pt = PrettyTable(test_id_cols, junction_char="|", hrules=HEADER) pt.align['automated'] = "r" pt.align['all'] = "r" pt.align['percent [%]'] = "r" @@ -1509,7 +1509,7 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=',' # Test automation coverage table print test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress'] - pt = PrettyTable(test_id_cols) + pt = PrettyTable(test_id_cols, junction_char="|", hrules=HEADER) pt.align['id'] = "l" pt.align['automated'] = "r" pt.align['all'] = "r" diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index edf901bcab..0a12895bed 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -706,8 +706,8 @@ class mbedToolchain: self._add_defines_from_region(region) if region.active: for define in [ - ("%s_START" % active_region_name, region.start), - ("%s_SIZE" % active_region_name, region.size) + ("%s_START" % active_region_name, "0x%x" % region.start), + ("%s_SIZE" % active_region_name, "0x%x" % region.size) ]: define_string = self.make_ld_define(*define) self.ld.append(define_string) @@ -747,6 +747,11 @@ class mbedToolchain: self.config_data = config_data # new configuration data can change labels, so clear the cache self.labels = None + # pass info about softdevice presence to linker (see NRF52) + if "SOFTDEVICE_PRESENT" in config_data[1]: + define_string = self.make_ld_define("SOFTDEVICE_PRESENT", config_data[1]["SOFTDEVICE_PRESENT"].macro_value) + self.ld.append(define_string) + self.flags["ld"].append(define_string) self.add_regions() # Creates the configuration header if needed: diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index cbee5e5a03..d37c94e92b 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -325,7 +325,7 @@ class ARM(mbedToolchain): @staticmethod def make_ld_define(name, value): - return "--predefine=\"-D%s=0x%x\"" % (name, value) + return "--predefine=\"-D%s=%s\"" % (name, value) @staticmethod def redirect_symbol(source, sync, build_dir): @@ -426,7 +426,7 @@ class ARMC6(ARM_STD): self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file] # Add linking time preprocessor macro __DOMAIN_NS if target.core == "Cortex-M23-NS" or self.target.core == "Cortex-M33-NS": - define_string = self.make_ld_define("__DOMAIN_NS", 1) + define_string = self.make_ld_define("__DOMAIN_NS", "0x1") self.flags["ld"].append(define_string) asm_cpu = { diff --git a/tools/toolchains/gcc.py b/tools/toolchains/gcc.py index 65f30477c4..f094fb9702 100644 --- a/tools/toolchains/gcc.py +++ b/tools/toolchains/gcc.py @@ -293,7 +293,7 @@ class GCC(mbedToolchain): @staticmethod def make_ld_define(name, value): - return "-D%s=0x%x" % (name, value) + return "-D%s=%s" % (name, value) @staticmethod def redirect_symbol(source, sync, build_dir): diff --git a/tools/toolchains/iar.py b/tools/toolchains/iar.py index ac73cf0d81..c09a015ec9 100644 --- a/tools/toolchains/iar.py +++ b/tools/toolchains/iar.py @@ -273,7 +273,7 @@ class IAR(mbedToolchain): @staticmethod def make_ld_define(name, value): - return "--config_def %s=0x%x" % (name, value) + return "--config_def %s=%s" % (name, value) @staticmethod def redirect_symbol(source, sync, build_dir):