diff --git a/.github/workflows/host-test.yml b/.github/workflows/host-test.yml new file mode 100644 index 000000000..387cbe768 --- /dev/null +++ b/.github/workflows/host-test.yml @@ -0,0 +1,44 @@ +name: Host test + +on: [push, pull_request] + +jobs: + host_test: + name: Build and test + runs-on: ubuntu-20.04 + container: espressif/idf:release-v4.3 + env: + lwip: lwip-2.1.2 + lwip_contrib: contrib-2.1.0 + lwip_uri: http://download.savannah.nongnu.org/releases/lwip + + + steps: + - name: Checkout esp-protocols + uses: actions/checkout@master + with: + path: esp-protocols + + - name: Build and Test + shell: bash + run: | + apt-get update && apt-get install -y gcc-8 g++-8 + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8 + export LWIP_PATH=`pwd`/${{ env.lwip }} + export LWIP_CONTRIB_PATH=`pwd`/${{ env.lwip_contrib }} + wget --no-verbose ${lwip_uri}/${lwip}.zip + unzip -oq ${lwip}.zip + wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip + unzip -oq ${lwip_contrib}.zip + . ${IDF_PATH}/export.sh + cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/examples/linux_modem + idf.py build + cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/test/host_test + idf.py build + ./build/host_modem_test.elf -r junit -o junit.xml + + - name: Publish Results + uses: EnricoMi/publish-unit-test-result-action@v1 + if: always() + with: + files: esp-protocols/components/esp_modem/test/host_test/junit.xml diff --git a/components/esp_modem/CMakeLists.txt b/components/esp_modem/CMakeLists.txt index dea720007..2687ef4fd 100644 --- a/components/esp_modem/CMakeLists.txt +++ b/components/esp_modem/CMakeLists.txt @@ -7,6 +7,7 @@ if(${target} STREQUAL "linux") set(dependencies esp_system_protocols_linux) else() set(platform_srcs src/esp_modem_primitives_freertos.cpp + src/esp_modem_api_target.cpp src/esp_modem_uart.cpp src/esp_modem_term_uart.cpp src/esp_modem_netif.cpp) diff --git a/components/esp_modem/port/linux/esp_netif_linux/CMakeLists.txt b/components/esp_modem/port/linux/esp_netif_linux/CMakeLists.txt index 515e342b2..fc6e78f54 100644 --- a/components/esp_modem/port/linux/esp_netif_linux/CMakeLists.txt +++ b/components/esp_modem/port/linux/esp_netif_linux/CMakeLists.txt @@ -3,18 +3,20 @@ set(LWIP_CONTRIB_DIR "$ENV{LWIP_CONTRIB_PATH}") set(lwipcontribportunix_SRCS ${LWIP_CONTRIB_DIR}/ports/unix/port/sys_arch.c) -include(${LWIP_DIR}/src/Filelists.cmake) +if(NOT CMAKE_BUILD_EARLY_EXPANSION) -set (LWIP_INCLUDE_DIRS + include(${LWIP_DIR}/src/Filelists.cmake) + + set (LWIP_INCLUDE_DIRS "${LWIP_DIR}/src/include" "${LWIP_CONTRIB_DIR}/ports/unix/port/include") -list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/netif/slipif.c") -list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ip4.c") -list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv6/ip6.c") + list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/netif/slipif.c") + list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv4/ip4.c") + list(REMOVE_ITEM lwipnoapps_SRCS "${LWIP_DIR}/src/core/ipv6/ip6.c") +endif() - -idf_component_register(SRCS esp_netif_linux.cpp tun_io.c ip6_stub.c ${lwipnoapps_SRCS} ${lwipcontribportunix_SRCS} +idf_component_register(SRCS esp_netif_linux.cpp tun_io.c ip4_stub.c ip6_stub.c ${lwipnoapps_SRCS} ${lwipcontribportunix_SRCS} INCLUDE_DIRS include ${LWIP_INCLUDE_DIRS} PRIV_INCLUDE_DIRS . REQUIRES esp_system_protocols_linux) diff --git a/components/esp_modem/port/linux/esp_netif_linux/esp_netif_linux.cpp b/components/esp_modem/port/linux/esp_netif_linux/esp_netif_linux.cpp index bef1f30cf..6f97d74f6 100644 --- a/components/esp_modem/port/linux/esp_netif_linux/esp_netif_linux.cpp +++ b/components/esp_modem/port/linux/esp_netif_linux/esp_netif_linux.cpp @@ -90,43 +90,6 @@ public: extern "C" esp_netif_t *esp_netif_new(const esp_netif_config_t *config) { return new NetifStorage(config); -// struct ifreq ifr = { }; -// esp_netif_t * netif = netif_storage; -// if (netif == NULL) { -// return NULL; -// } -// if ((netif->fd = open(config->dev_name, O_RDWR)) == -1) { -// ESP_LOGE(TAG, "Cannot open %s", config->dev_name); -// goto cleanup; -// } -// ifr.ifr_flags = IFF_TUN; -// strncpy(ifr.ifr_name, config->if_name, IFNAMSIZ); -// -// if (ioctl(netif->fd, TUNSETIFF, (void *)&ifr) == -1) { -// ESP_LOGE(TAG, "Cannot set ioctl TUNSETIFF %m"); -// goto cleanup; -// } -// ioctl(netif->fd, TUNSETNOCSUM, 1); -// -// netif->in_buf = new uint8_t[BUF_SIZE]; -// netif->out_buf = new uint8_t[BUF_SIZE]; -// if (netif->in_buf == nullptr || netif->out_buf == nullptr) { -// goto cleanup; -// } -// -// if (!ppp_netif_init(netif)) { -// ESP_LOGE(TAG, "Cannot initialize pppos lwip netif %m"); -// goto cleanup; -// } -// -// return netif; -// -//cleanup: -// close(netif->fd); -// delete[] netif->in_buf; -// delete[] netif->out_buf; -// delete netif_storage; -// return nullptr; } void esp_netif_destroy(esp_netif_t *netif) diff --git a/components/esp_modem/port/linux/esp_netif_linux/ip4_stub.c b/components/esp_modem/port/linux/esp_netif_linux/ip4_stub.c new file mode 100644 index 000000000..2d049c85e --- /dev/null +++ b/components/esp_modem/port/linux/esp_netif_linux/ip4_stub.c @@ -0,0 +1,17 @@ +#include "lwip/ip4.h" + +err_t +ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, + u8_t proto, struct netif *netif) +{ return ERR_OK; } + +struct netif * +ip4_route(const ip4_addr_t *dest) +{ return NULL; } + +err_t +ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, + u8_t proto, struct netif *netif) +{ return ERR_OK; } diff --git a/components/esp_modem/src/esp_modem_api.cpp b/components/esp_modem/src/esp_modem_api.cpp index cc5c5b24f..f2c118f26 100644 --- a/components/esp_modem/src/esp_modem_api.cpp +++ b/components/esp_modem/src/esp_modem_api.cpp @@ -30,13 +30,6 @@ struct PdpContext; static const char *TAG = "modem_api"; #endif -std::shared_ptr create_uart_dte(const dte_config *config) -{ - TRY_CATCH_RET_NULL( - auto term = create_uart_terminal(config); - return std::make_shared(config, std::move(term)); - ) -} std::shared_ptr create_vfs_dte(const dte_config *config) { diff --git a/components/esp_modem/src/esp_modem_api_target.cpp b/components/esp_modem/src/esp_modem_api_target.cpp new file mode 100644 index 000000000..c72175c23 --- /dev/null +++ b/components/esp_modem/src/esp_modem_api_target.cpp @@ -0,0 +1,39 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "esp_log.h" +#include "cxx_include/esp_modem_dte.hpp" +#include "uart_terminal.hpp" +#include "vfs_termial.hpp" +#include "cxx_include/esp_modem_api.hpp" +#include "cxx_include/esp_modem_dce_factory.hpp" +#include "esp_modem_config.h" +#include "exception_stub.hpp" + +namespace esp_modem { + +#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS +static const char *TAG = "modem_api_target"; +#endif + +std::shared_ptr create_uart_dte(const dte_config *config) +{ + TRY_CATCH_RET_NULL( + auto term = create_uart_terminal(config); + return std::make_shared(config, std::move(term)); + ) +} + +} // namespace esp_modem diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index ec508fa80..7c48fb406 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -27,6 +27,10 @@ #define ESP_MODEM_C_API_STR_MAX 64 #endif +#ifndef HAVE_STRLCPY +size_t strlcpy(char *dest, const char *src, size_t len); +#endif + // // C API definitions using namespace esp_modem; diff --git a/components/esp_modem/src/esp_modem_primitives_freertos.cpp b/components/esp_modem/src/esp_modem_primitives_freertos.cpp index 66ddcc29e..f1da74adb 100644 --- a/components/esp_modem/src/esp_modem_primitives_freertos.cpp +++ b/components/esp_modem/src/esp_modem_primitives_freertos.cpp @@ -111,4 +111,4 @@ void Task::Delay(uint32_t ms) vTaskDelay(pdMS_TO_TICKS(ms)); } -} // namespace esp_modem \ No newline at end of file +} // namespace esp_modem diff --git a/components/esp_modem/src/esp_modem_primitives_linux.cpp b/components/esp_modem/src/esp_modem_primitives_linux.cpp index dd1553bc9..dd4875b60 100644 --- a/components/esp_modem/src/esp_modem_primitives_linux.cpp +++ b/components/esp_modem/src/esp_modem_primitives_linux.cpp @@ -89,4 +89,9 @@ void Task::Relinquish() usleep(0); } -} // namespace esp_modem \ No newline at end of file +void Task::Delay(uint32_t ms) +{ + usleep(ms*1000); +} + +} // namespace esp_modem