Merge branch 'master' into cm3ds_lp_requirements

Change-Id: I3c687694ee924938ec08ea40d0ddbcaf20dd0a73
pull/8737/head
Bence Káposzta 2018-11-14 11:15:22 +01:00 committed by Bence Kaposzta
commit 5dd6d19253
14 changed files with 4568 additions and 1232 deletions

View File

@ -24,10 +24,14 @@ extern std::list<uint32_t> eventFlagsStubNextRetval;
// InternetSocket is an abstract class, so we have to test it via its child.
class stubInternetSocket : public InternetSocket {
protected:
nsapi_error_t return_value = 0;
nsapi_error_t return_value;
public:
stubInternetSocket() {
return_value = 0;
}
virtual nsapi_error_t connect(const SocketAddress &address)
{
_remote_peer = address;
return return_value;
}
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size)
@ -227,3 +231,25 @@ TEST_F(TestInternetSocket, sigio)
socket->close(); // Trigger event;
EXPECT_EQ(callback_is_called, true);
}
TEST_F(TestInternetSocket, getpeername)
{
SocketAddress peer;
SocketAddress zero;
stack.return_value = NSAPI_ERROR_OK;
EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_NO_SOCKET);
socket->open((NetworkStack *)&stack);
socket->connect(zero);
EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_NO_CONNECTION);
const nsapi_addr_t saddr = {NSAPI_IPv4, {192, 168, 0, 1} };
const SocketAddress remote(saddr, 1024);
socket->connect(remote);
EXPECT_EQ(socket->getpeername(&peer), NSAPI_ERROR_OK);
EXPECT_EQ(remote, peer);
}

View File

@ -24,7 +24,12 @@
class NetworkStackstub : public NetworkStack {
public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value = 0;
nsapi_error_t return_value;
NetworkStackstub() {
return_value = 0;
}
virtual const char *get_ip_address()
{
return "127.0.0.1";

View File

@ -214,3 +214,15 @@ void InternetSocket::attach(Callback<void()> callback)
{
sigio(callback);
}
nsapi_error_t InternetSocket::getpeername(SocketAddress *address)
{
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
if (!_remote_peer) {
return NSAPI_ERROR_NO_CONNECTION;
}
*address = _remote_peer;
return NSAPI_ERROR_OK;
}

View File

@ -117,6 +117,10 @@ public:
*/
virtual void sigio(mbed::Callback<void()> func);
/** @copydoc Socket::getpeername
*/
virtual nsapi_error_t getpeername(SocketAddress *address);
/** Register a callback on state change of the socket.
*
* @see Socket::sigio

View File

@ -254,6 +254,17 @@ public:
* @return NSAPI_ERROR_OK on success, negative error code on failure
*/
virtual nsapi_error_t listen(int backlog = 1) = 0;
/** Get the remote-end peer associated with this socket.
*
* Copy the remote peer address to a SocketAddress structure pointed by
* address parameter. Socket must be connected to have a peer address
* associated.
*
* @param address Pointer to SocketAddress structure.
* @return NSAPI_ERROR_OK on success, negative error code on failure.
*/
virtual nsapi_error_t getpeername(SocketAddress *address) = 0;
};

View File

@ -577,4 +577,12 @@ nsapi_error_t TLSSocketWrapper::listen(int)
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t TLSSocketWrapper::getpeername(SocketAddress *address)
{
if (!_handshake_completed) {
return NSAPI_ERROR_NO_CONNECTION;
}
return _transport->getpeername(address);
}
#endif /* MBEDTLS_SSL_CLI_C */

View File

@ -132,6 +132,7 @@ public:
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen);
virtual Socket *accept(nsapi_error_t *error = NULL);
virtual nsapi_error_t listen(int backlog = 1);
virtual nsapi_error_t getpeername(SocketAddress *address);
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN)
/** Get own certificate directly from Mbed TLS

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include "string.h"
#include "device.h"
#include "flash_api.h"
#include "memory_zones.h"
@ -22,7 +23,7 @@
* The implementation emulates flash over SRAM.
*/
#define FLASH_PAGE_SIZE 256
#define FLASH_PAGE_SIZE 4U
#define FLASH_OFS_START ZBT_SRAM1_START
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_OFS_END (ZBT_SRAM1_START + ZBT_SRAM1_SIZE)

View File

@ -36,11 +36,11 @@ void hal_sleep(void)
* disabling the Microsec ticker in addition */
void hal_deepsleep(void)
{
#if USEC_TIMER_DEV
#if DEVICE_USTICKER
timer_cmsdk_disable(&USEC_TIMER_DEV);
#endif
__WFI();
#if USEC_TIMER_DEV
#if DEVICE_USTICKER
timer_cmsdk_enable(&USEC_TIMER_DEV);
#endif
}

View File

@ -134,12 +134,4 @@ void flash_set_target_config(flash_t *obj)
}
#endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif // #if DEVICE_FLASH

File diff suppressed because it is too large Load Diff

View File

@ -250,39 +250,17 @@ class Resources(object):
dirname[len(label_type) + 1:] not in self._labels[label_type])
def add_file_ref(self, file_type, file_name, file_path):
if sep != self._sep:
ref = FileRef(file_name.replace(sep, self._sep), file_path)
else:
ref = FileRef(file_name, file_path)
self._file_refs[file_type].add(ref)
if file_type:
if sep != self._sep:
file_name = file_name.replace(sep, self._sep)
self._file_refs[file_type].add(FileRef(file_name, file_path))
def get_file_refs(self, file_type):
"""Return a list of FileRef for every file of the given type"""
return list(self._file_refs[file_type])
def _all_parents(self, files):
for name, path in files:
components = name.split(self._sep)
start_at = 0
for index, directory in reversed(list(enumerate(components))):
if directory in self._prefixed_labels:
start_at = index + 1
break
prefix = path.replace(name, "")
for n in range(start_at, len(components)):
parent_name = self._sep.join(components[:n])
parent_path = join(prefix, *components[:n])
yield FileRef(parent_name, parent_path)
def _get_from_refs(self, file_type, key):
if file_type is FileType.INC_DIR:
parents = set(self._all_parents(self._file_refs[FileType.HEADER]))
else:
parents = set()
return sorted(
[key(f) for f in list(parents) + self.get_file_refs(file_type)]
)
return sorted([key(f) for f in self.get_file_refs(file_type)])
def get_file_names(self, file_type):
return self._get_from_refs(file_type, lambda f: f.name)
@ -447,6 +425,19 @@ class Resources(object):
".ar": FileType.LIB_DIR,
}
def _all_parents(self, file_path, base_path, into_path):
suffix = relpath(file_path, base_path)
components = suffix.split(self._sep)
start_at = 0
for index, directory in reversed(list(enumerate(components))):
if directory in self._prefixed_labels:
start_at = index + 1
break
for n in range(start_at, len(components)):
parent_name = self._sep.join([into_path] + components[:n])
parent_path = join(base_path, *components[:n])
yield FileRef(parent_name, parent_path)
def _add_file(self, file_path, base_path, into_path):
""" Add a single file into the resources object that was found by
scanning starting as base_path
@ -459,16 +450,15 @@ class Resources(object):
fake_path = join(into_path, relpath(file_path, base_path))
_, ext = splitext(file_path)
try:
file_type = self._EXT[ext.lower()]
self.add_file_ref(file_type, fake_path, file_path)
except KeyError:
pass
try:
dir_type = self._DIR_EXT[ext.lower()]
self.add_file_ref(dir_type, dirname(fake_path), dirname(file_path))
except KeyError:
pass
file_type = self._EXT.get(ext.lower())
self.add_file_ref(file_type, fake_path, file_path)
if file_type == FileType.HEADER:
for name, path in self._all_parents(file_path, base_path, into_path):
self.add_file_ref(FileType.INC_DIR, name, path)
dir_type = self._DIR_EXT.get(ext.lower())
self.add_file_ref(dir_type, dirname(fake_path), dirname(file_path))
def scan_with_toolchain(self, src_paths, toolchain, dependencies_paths=None,