From 5433365b814bb77c834f719b781b0c72576cdcfa Mon Sep 17 00:00:00 2001 From: Rajkumar Kanagaraj Date: Mon, 5 Jul 2021 03:51:58 -0700 Subject: [PATCH] CMake: Move netsocket stubs to the netsocket dir Move the connectivity netsocket stubs into the connectivity/netsocket component directory. So we can avoid duplicating the mbed-os source tree in a central UNITTESTS folder. --- UNITTESTS/stubs/NetworkStack_stub.h | 2 +- UNITTESTS/stubs/connectivity/CMakeLists.txt | 8 ------ .../netsocket/tests/UNITTESTS/CMakeLists.txt | 1 + .../tests/UNITTESTS/doubles/CMakeLists.txt | 25 +++++++++++++++++++ .../doubles}/CellularInterface_stub.cpp | 0 .../UNITTESTS/doubles}/MeshInterface_stub.cpp | 0 .../NetworkInterfaceDefaults_stub.cpp | 0 .../doubles}/NetworkInterface_stub.cpp | 0 .../UNITTESTS/doubles}/NetworkStack_stub.cpp | 4 +-- .../UNITTESTS/doubles}/SocketAddress_stub.cpp | 0 .../UNITTESTS/doubles}/SocketStats_Stub.cpp | 0 .../UNITTESTS/doubles}/nsapi_dns_stub.cpp | 0 12 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/CellularInterface_stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/MeshInterface_stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/NetworkInterfaceDefaults_stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/NetworkInterface_stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/NetworkStack_stub.cpp (96%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/SocketAddress_stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/SocketStats_Stub.cpp (100%) rename {UNITTESTS/stubs/connectivity => connectivity/netsocket/tests/UNITTESTS/doubles}/nsapi_dns_stub.cpp (100%) diff --git a/UNITTESTS/stubs/NetworkStack_stub.h b/UNITTESTS/stubs/NetworkStack_stub.h index 916937e645..d6b630a1d8 100644 --- a/UNITTESTS/stubs/NetworkStack_stub.h +++ b/UNITTESTS/stubs/NetworkStack_stub.h @@ -40,7 +40,7 @@ public: { } - virtual nsapi_error_t get_ip_address(SocketAddress* address) + virtual nsapi_error_t get_ip_address(SocketAddress *address) { address->set_ip_address("127.0.0.1"); return NSAPI_ERROR_OK; diff --git a/UNITTESTS/stubs/connectivity/CMakeLists.txt b/UNITTESTS/stubs/connectivity/CMakeLists.txt index eaf86ac813..41b6d8b1ea 100644 --- a/UNITTESTS/stubs/connectivity/CMakeLists.txt +++ b/UNITTESTS/stubs/connectivity/CMakeLists.txt @@ -19,17 +19,9 @@ target_compile_definitions(mbed-stubs-connectivity target_sources(mbed-stubs-connectivity PRIVATE aes_stub.c - CellularInterface_stub.cpp cipher_stub.c cmac_stub.c ip4tos_stub.c - MeshInterface_stub.cpp - NetworkInterfaceDefaults_stub.cpp - NetworkInterface_stub.cpp - NetworkStack_stub.cpp - nsapi_dns_stub.cpp - SocketAddress_stub.cpp - SocketStats_Stub.cpp stoip4_stub.c ${mbed-os_SOURCE_DIR}/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c ) diff --git a/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt index e23c5d4290..b54cb6bb8c 100644 --- a/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt +++ b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +add_subdirectory(doubles) add_subdirectory(netsocket) diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt new file mode 100644 index 0000000000..0225b8c0d3 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-stubs-netsocket) + +target_sources(mbed-stubs-netsocket + PRIVATE + CellularInterface_stub.cpp + MeshInterface_stub.cpp + NetworkInterfaceDefaults_stub.cpp + NetworkInterface_stub.cpp + NetworkStack_stub.cpp + nsapi_dns_stub.cpp + SocketAddress_stub.cpp + SocketStats_Stub.cpp +) + +target_link_libraries(mbed-stubs-netsocket + PRIVATE + mbed-stubs-rtos-headers + mbed-headers + mbed-stubs-headers + mbed-stubs-rtos + gtest +) diff --git a/UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/CellularInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/CellularInterface_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/MeshInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/MeshInterface_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterface_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp similarity index 96% rename from UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp index dd68b3e9fb..7d6331a4d9 100644 --- a/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkStack_stub.cpp @@ -94,7 +94,7 @@ nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) return NSAPI_ERROR_UNSUPPORTED; } -nsapi_error_t NetworkStack::get_ip_address(SocketAddress* address) +nsapi_error_t NetworkStack::get_ip_address(SocketAddress *address) { return NSAPI_ERROR_UNSUPPORTED; } @@ -104,7 +104,7 @@ nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address) return NSAPI_ERROR_UNSUPPORTED; } -nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress* address, const char *interface_name) +nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress *address, const char *interface_name) { return NSAPI_ERROR_UNSUPPORTED; } diff --git a/UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketAddress_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/SocketAddress_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/SocketStats_Stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/SocketStats_Stub.cpp diff --git a/UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/nsapi_dns_stub.cpp similarity index 100% rename from UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp rename to connectivity/netsocket/tests/UNITTESTS/doubles/nsapi_dns_stub.cpp