mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-23 23:37:31 +02:00
fix(websocket): Added unit tests to CI + minor fix to pass it
This commit is contained in:
@ -14,7 +14,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
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
|
runs-on: ubuntu-20.04
|
||||||
container: espressif/idf:${{ matrix.idf_ver }}
|
container: espressif/idf:${{ matrix.idf_ver }}
|
||||||
env:
|
env:
|
||||||
@ -53,7 +53,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
|
||||||
idf_target: ["esp32"]
|
idf_target: ["esp32"]
|
||||||
test: [ { app: example, path: "examples" } ]
|
test: [ { app: example, path: "examples" }, { app: unit_test, path: "test" } ]
|
||||||
runs-on:
|
runs-on:
|
||||||
- self-hosted
|
- self-hosted
|
||||||
- ESP32-ETHERNET-KIT
|
- ESP32-ETHERNET-KIT
|
||||||
|
@ -424,7 +424,9 @@ static void destroy_and_free_resources(esp_websocket_client_handle_t client)
|
|||||||
free(client->if_name);
|
free(client->if_name);
|
||||||
}
|
}
|
||||||
esp_websocket_client_destroy_config(client);
|
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);
|
vQueueDelete(client->lock);
|
||||||
free(client->tx_buffer);
|
free(client->tx_buffer);
|
||||||
free(client->rx_buffer);
|
free(client->rx_buffer);
|
||||||
|
@ -1,2 +1,8 @@
|
|||||||
idf_component_register(SRC_DIRS "."
|
# This is the project CMakeLists.txt file for the test subproject
|
||||||
PRIV_REQUIRES cmock test_utils esp_websocket_client)
|
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 <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <esp_websocket_client.h>
|
#include <esp_websocket_client.h>
|
||||||
|
#include "esp_event.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
#include "test_utils.h"
|
||||||
|
|
||||||
|
#include "unity_fixture.h"
|
||||||
#include "memory_checks.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_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 = {
|
const esp_websocket_client_config_t websocket_cfg = {
|
||||||
// no connection takes place, but the uri has to be valid for init() to succeed
|
// no connection takes place, but the uri has to be valid for init() to succeed
|
||||||
.uri = "ws://echo.websocket.org",
|
.uri = "ws://echo.websocket.org",
|
||||||
@ -35,9 +52,8 @@ TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
|
|||||||
esp_websocket_client_destroy(client);
|
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 = {
|
const esp_websocket_client_config_t websocket_cfg = {
|
||||||
.uri = "INVALID",
|
.uri = "INVALID",
|
||||||
};
|
};
|
||||||
@ -45,12 +61,23 @@ TEST_CASE("websocket init with invalid url", "[websocket][leaks=0]")
|
|||||||
TEST_ASSERT_NULL(client);
|
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 = {};
|
const esp_websocket_client_config_t websocket_cfg = {};
|
||||||
esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
|
esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
|
||||||
TEST_ASSERT_NOT_EQUAL(NULL, client);
|
TEST_ASSERT_NOT_EQUAL(NULL, client);
|
||||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_websocket_client_set_uri(client, "INVALID"));
|
TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_websocket_client_set_uri(client, "INVALID"));
|
||||||
esp_websocket_client_destroy(client);
|
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
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
def test_lwip(dut: Dut) -> None:
|
def test_mdns(dut: Dut) -> None:
|
||||||
dut.expect_unity_test_output()
|
dut.expect_unity_test_output()
|
||||||
|
Reference in New Issue
Block a user