mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 18:27:31 +02:00
Merge pull request #298 from david-cermak/bugfix/improve_ci
fix(websocket): Add unit tests to the workflow
This commit is contained in:
@ -14,7 +14,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
||||
test: [ { app: example, path: "examples" } ]
|
||||
test: [ { app: example, path: "examples" }, { app: unit_test, path: "test" } ]
|
||||
runs-on: ubuntu-20.04
|
||||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
env:
|
||||
@ -53,7 +53,7 @@ jobs:
|
||||
matrix:
|
||||
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
||||
idf_target: ["esp32"]
|
||||
test: [ { app: example, path: "examples" } ]
|
||||
test: [ { app: example, path: "examples" }, { app: unit_test, path: "test" } ]
|
||||
runs-on:
|
||||
- self-hosted
|
||||
- ESP32-ETHERNET-KIT
|
||||
|
@ -10,4 +10,3 @@ idf_component_register(SRCS "esp_websocket_client.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES lwip esp-tls tcp_transport http_parser
|
||||
PRIV_REQUIRES esp_timer esp_event)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
||||
|
@ -424,7 +424,9 @@ static void destroy_and_free_resources(esp_websocket_client_handle_t client)
|
||||
free(client->if_name);
|
||||
}
|
||||
esp_websocket_client_destroy_config(client);
|
||||
esp_transport_list_destroy(client->transport_list);
|
||||
if (client->transport_list) {
|
||||
esp_transport_list_destroy(client->transport_list);
|
||||
}
|
||||
vQueueDelete(client->lock);
|
||||
free(client->tx_buffer);
|
||||
free(client->rx_buffer);
|
||||
@ -1105,7 +1107,7 @@ int esp_websocket_client_send_with_opcode(esp_websocket_client_handle_t client,
|
||||
}
|
||||
|
||||
if (xSemaphoreTakeRecursive(client->lock, timeout) != pdPASS) {
|
||||
ESP_LOGE(TAG, "Could not lock ws-client within %d timeout", timeout);
|
||||
ESP_LOGE(TAG, "Could not lock ws-client within %" PRIu32 " timeout", timeout);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
idf_component_register(SRCS "websocket_example.c"
|
||||
INCLUDE_DIRS ".")
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
||||
|
@ -170,7 +170,7 @@ static void websocket_app_start(void)
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "[APP] Startup..");
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());
|
||||
esp_log_level_set("*", ESP_LOG_INFO);
|
||||
esp_log_level_set("websocket_client", ESP_LOG_DEBUG);
|
||||
|
@ -1,2 +1,8 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_REQUIRES cmock test_utils esp_websocket_client)
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ../../esp_websocket_client
|
||||
"$ENV{IDF_PATH}/tools/unit-test-app/components")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(websocket_unit_test)
|
||||
|
4
components/esp_websocket_client/test/main/CMakeLists.txt
Normal file
4
components/esp_websocket_client/test/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "test_websocket_client.c"
|
||||
REQUIRES test_utils
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity esp_websocket_client esp_event)
|
@ -13,19 +13,36 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_websocket_client.h>
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "unity_fixture.h"
|
||||
#include "memory_checks.h"
|
||||
|
||||
static void test_leak_setup(const char *file, long line)
|
||||
TEST_GROUP(websocket);
|
||||
|
||||
TEST_SETUP(websocket)
|
||||
{
|
||||
printf("%s:%ld\n", file, line);
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)
|
||||
/* IDF v5.0 runs some lazy inits within printf()
|
||||
* This test sets the leak threshold to 0, so we need to call printf()
|
||||
* before recording the heap size in test_utils_record_free_mem()
|
||||
*/
|
||||
printf("TEST_SETUP: websocket\n");
|
||||
#endif
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
|
||||
TEST_TEAR_DOWN(websocket)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(0, 0);
|
||||
}
|
||||
|
||||
|
||||
TEST(websocket, websocket_init_deinit)
|
||||
{
|
||||
test_leak_setup(__FILE__, __LINE__);
|
||||
const esp_websocket_client_config_t websocket_cfg = {
|
||||
// no connection takes place, but the uri has to be valid for init() to succeed
|
||||
.uri = "ws://echo.websocket.org",
|
||||
@ -35,9 +52,8 @@ TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
|
||||
esp_websocket_client_destroy(client);
|
||||
}
|
||||
|
||||
TEST_CASE("websocket init with invalid url", "[websocket][leaks=0]")
|
||||
TEST(websocket, websocket_init_invalid_url)
|
||||
{
|
||||
test_leak_setup(__FILE__, __LINE__);
|
||||
const esp_websocket_client_config_t websocket_cfg = {
|
||||
.uri = "INVALID",
|
||||
};
|
||||
@ -45,12 +61,23 @@ TEST_CASE("websocket init with invalid url", "[websocket][leaks=0]")
|
||||
TEST_ASSERT_NULL(client);
|
||||
}
|
||||
|
||||
TEST_CASE("websocket set url with invalid url", "[websocket][leaks=0]")
|
||||
TEST(websocket, websocket_set_invalid_url)
|
||||
{
|
||||
test_leak_setup(__FILE__, __LINE__);
|
||||
const esp_websocket_client_config_t websocket_cfg = {};
|
||||
esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
|
||||
TEST_ASSERT_NOT_EQUAL(NULL, client);
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_websocket_client_set_uri(client, "INVALID"));
|
||||
esp_websocket_client_destroy(client);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(websocket)
|
||||
{
|
||||
RUN_TEST_CASE(websocket, websocket_init_deinit)
|
||||
RUN_TEST_CASE(websocket, websocket_init_invalid_url)
|
||||
RUN_TEST_CASE(websocket, websocket_set_invalid_url)
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN(websocket);
|
||||
}
|
8
components/esp_websocket_client/test/pytest_websocket.py
Normal file
8
components/esp_websocket_client/test/pytest_websocket.py
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
def test_websocket(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
3
components/esp_websocket_client/test/sdkconfig.ci
Normal file
3
components/esp_websocket_client/test/sdkconfig.ci
Normal file
@ -0,0 +1,3 @@
|
||||
CONFIG_IDF_TARGET="esp32"
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
2
components/esp_websocket_client/test/sdkconfig.defaults
Normal file
2
components/esp_websocket_client/test/sdkconfig.defaults
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
@ -4,5 +4,5 @@
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
def test_lwip(dut: Dut) -> None:
|
||||
def test_mdns(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
||||
|
Reference in New Issue
Block a user