mirror of
https://github.com/espressif/esp-modbus.git
synced 2026-08-03 20:24:09 +02:00
Merge branch 'bugfix/fix_printing_after_node_destroy' into 'main'
fix: new observed idf related ci issues See merge request idf/esp-modbus!148
This commit is contained in:
+12
-9
@@ -57,11 +57,6 @@ after_script:
|
||||
- test "$CI_CCACHE_STATS" == 1 && test -n "$(which ccache)" && ccache --show-stats || true
|
||||
dependencies: []
|
||||
|
||||
.before_script_build_jobs:
|
||||
before_script:
|
||||
- pip install idf-component-manager --upgrade
|
||||
- pip install "idf_build_apps" --upgrade
|
||||
|
||||
.check_idf_ver: &check_idf_ver |
|
||||
export IDF_PATH=$(find /opt -type d -name "*idf*" \
|
||||
\( -exec test -f '{}/tools/idf.py' \; -and -exec test -f '{}/tools/idf_tools.py' \; \
|
||||
@@ -76,6 +71,18 @@ after_script:
|
||||
echo "ESP-IDF: $IDF_VERSION"
|
||||
fi
|
||||
|
||||
.before_script_build_jobs:
|
||||
before_script:
|
||||
- *check_idf_ver
|
||||
- *setup_idf_tools
|
||||
#- COMPOTE_VER_START=$(compote version)
|
||||
#- pip install idf-component-manager --upgrade # to avoid the issue with component manager v2.4.3
|
||||
- pip install "idf_build_apps" --upgrade
|
||||
- COMPOTE_VER=$(compote version)
|
||||
- echo "Component manager version ${COMPOTE_VER}"
|
||||
- PIP_VERS=$(python -m pip freeze)
|
||||
- echo "PIP component versions ${PIP_VERS}"
|
||||
|
||||
# Note: this script builds the folder against all targets and then deletes
|
||||
# all other artifacts except the esp32 to decrease the size of artifacs (may cause failures)
|
||||
.build_cur_folder: &build_cur_folder |
|
||||
@@ -110,10 +117,6 @@ after_script:
|
||||
- .before_script_build_jobs
|
||||
script:
|
||||
# The script below will build all test applications defined in environment variable $TEST_TARGETS
|
||||
- *check_idf_ver
|
||||
# This is workaround to build library under esp-idf v4.4
|
||||
- pip install idf-component-manager --upgrade
|
||||
- ${IDF_PATH}/install.sh --enable-ci
|
||||
- cd ${TEST_DIR}/test_apps
|
||||
- *build_cur_folder
|
||||
- cd ${TEST_DIR}/examples
|
||||
|
||||
+9
-27
@@ -148,7 +148,7 @@ class MbObject:
|
||||
|
||||
|
||||
class ModbusTestDut(IdfDut):
|
||||
TEST_IP_PROMPT = r"Waiting IP([0-9]{1,2}) from stdin:\r\r\n"
|
||||
TEST_IP_PROMPT = r"Waiting IP([0-9]{1,2}) from stdin:"
|
||||
TEST_IP_ADDRESS_REGEXP = r".*example_[a-z]+: .* IPv4 [a-z]+:.* ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*"
|
||||
TEST_APP_NAME = r"I \([0-9]+\) [a-z_]+: Project name:\s+([_a-z]*)"
|
||||
|
||||
@@ -377,7 +377,7 @@ class ModbusTestDut(IdfDut):
|
||||
def dut_send_ip(self, slave_ip: Optional[str]) -> Optional[int]:
|
||||
"""The function sends the slave IP address defined as a parameter to master"""
|
||||
addr_num: int = 0
|
||||
self.expect(self.TEST_IP_PROMPT, timeout=self.TEST_ACK_TIMEOUT)
|
||||
self.expect(self.TEST_IP_PROMPT, timeout=self.TEST_EXPECT_STR_TIMEOUT)
|
||||
if isinstance(slave_ip, str):
|
||||
for addr_num in range(0, self.TEST_MAX_CIDS):
|
||||
message = r"IP{}={}".format(addr_num, slave_ip)
|
||||
@@ -385,19 +385,6 @@ class ModbusTestDut(IdfDut):
|
||||
self.write(message)
|
||||
return addr_num
|
||||
|
||||
def get_expect_proc(self) -> Optional[object]:
|
||||
"""The function is a workaround to use expect method"""
|
||||
expect_proc: object = None
|
||||
try:
|
||||
expect_proc = self.__getattribute__("pexpect_proc")
|
||||
except:
|
||||
expect_proc = self.__getattribute__("_p")
|
||||
finally:
|
||||
if expect_proc and callable(getattr(expect_proc, "expect")):
|
||||
return expect_proc
|
||||
else:
|
||||
return None
|
||||
|
||||
def dut_stats_info(self) -> ModbusDutStats:
|
||||
"""The function retrieves all success and fail parameters per DUT to plot stats graph"""
|
||||
all_success_params: List[int] = []
|
||||
@@ -515,7 +502,6 @@ class ModbusTestDut(IdfDut):
|
||||
:keyword timeout: timeout for expect
|
||||
:return: matched item
|
||||
"""
|
||||
|
||||
def process_expected_item(
|
||||
item_raw: Tuple[str, Callable[..., Any]],
|
||||
) -> Dict[str, Any]:
|
||||
@@ -534,28 +520,24 @@ class ModbusTestDut(IdfDut):
|
||||
]
|
||||
match_item = None
|
||||
|
||||
# Workaround: We need to use the original expect method of pexpect process which returns
|
||||
# index of matched pattern instead of Match object returned by dut.expect()
|
||||
expect_proc: Optional[object] = self.get_expect_proc()
|
||||
|
||||
if expect_proc is not None:
|
||||
match_index = expect_proc.expect(expect_patterns, timeout)
|
||||
if self.pexpect_proc is not None:
|
||||
match_index = self.pexpect_proc.expect(expect_patterns, timeout)
|
||||
|
||||
if isinstance(match_index, int):
|
||||
match_item = expect_items_list[match_index] # type: ignore
|
||||
match_item["index"] = match_index # type: ignore
|
||||
match_item["index"] = match_index # type: ignore # keep match index
|
||||
if (
|
||||
isinstance(expect_proc.match, Match)
|
||||
and len(expect_proc.match.groups()) > 0
|
||||
isinstance(self.pexpect_proc.match, Match)
|
||||
and len(self.pexpect_proc.match.groups()) > 0
|
||||
):
|
||||
match_item["ret"] = expect_proc.match.groups()
|
||||
match_item["ret"] = self.pexpect_proc.match.groups()
|
||||
if match_item["callback"]:
|
||||
match_item["callback"](
|
||||
match_item["ret"]
|
||||
) # execution of callback function
|
||||
else:
|
||||
self.logger.error(
|
||||
"%s: failed to parse output. Please check component versions",
|
||||
"%s: failed to parse output. Please check component versions.",
|
||||
self.app_name,
|
||||
)
|
||||
raise RuntimeError from None
|
||||
|
||||
@@ -12,7 +12,7 @@ CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000
|
||||
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=300
|
||||
CONFIG_FMB_TCP_UID_ENABLED=y
|
||||
CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHOD=y
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=n
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
CONFIG_FMB_EXT_TYPE_SUPPORT=y
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=3000
|
||||
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=300
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
CONFIG_FMB_TCP_UID_ENABLED=y
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=n
|
||||
CONFIG_MB_SLAVE_IP_FROM_STDIN=y
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=n
|
||||
CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHOD=y
|
||||
CONFIG_FMB_EXT_TYPE_SUPPORT=y
|
||||
|
||||
@@ -105,12 +105,24 @@ test_configs = [
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_modbus_tcp_communication(dut: Tuple[ModbusTestDut, ModbusTestDut]) -> None:
|
||||
def test_modbus_tcp_communication(app_path: str, dut: Tuple[ModbusTestDut, ModbusTestDut]) -> None:
|
||||
dut_slave = dut[0]
|
||||
dut_master = dut[1]
|
||||
|
||||
logger.info("DUT: %s start.", dut_master.dut_get_name())
|
||||
logger.info("DUT: %s start.", dut_slave.dut_get_name())
|
||||
logger.info(f"DUT test application path: {app_path}.")
|
||||
|
||||
dut_slave_name = dut_slave.dut_get_name()
|
||||
dut_master_name = dut_master.dut_get_name()
|
||||
|
||||
dut_slave_port = dut_slave.app.sdkconfig.get("FMB_TCP_PORT_DEFAULT")
|
||||
dut_stdin_en = dut_master.app.sdkconfig.get("MB_SLAVE_IP_FROM_STDIN")
|
||||
dut_slave_ip_address = dut_slave.dut_get_ip()
|
||||
logger.info(f"DUT: {dut_slave_name}, ip address: {dut_slave_ip_address}.")
|
||||
|
||||
if dut_stdin_en:
|
||||
dut_master.dut_send_ip(slave_ip=dut_slave_ip_address)
|
||||
|
||||
print(f"Start testing for {dut_slave_name}:{dut_slave_port}, {dut_stdin_en}")
|
||||
|
||||
dut_slave.dut_test_start(dictionary=pattern_dict_slave)
|
||||
dut_master.dut_test_start(dictionary=pattern_dict_master)
|
||||
|
||||
@@ -652,9 +652,9 @@ MB_EVENT_HANDLER(mbm_on_close)
|
||||
if (pnode && (MB_GET_NODE_STATE(pnode) >= MB_SOCK_STATE_OPENED)
|
||||
&& FD_ISSET(pnode->index, &drv_obj->open_set)) {
|
||||
// Close node immediately
|
||||
mb_drv_close(drv_obj, fd);
|
||||
MB_SET_NODE_STATE(pnode, MB_SOCK_STATE_READY);
|
||||
ESP_LOGD(TAG, "%p, Close node %d, sock #%d.", ctx, fd, pnode->sock_id);
|
||||
mb_drv_close(drv_obj, fd);
|
||||
}
|
||||
}
|
||||
(void)mb_drv_set_status_flag(drv_obj, MB_FLAG_DISCONNECTED);
|
||||
|
||||
@@ -24,7 +24,7 @@ extern "C" {
|
||||
bool port_check_host_addr(const char *host_str, ip_addr_t *host_addr)
|
||||
{
|
||||
MB_RETURN_ON_FALSE((host_str), false, TAG, "wrong host name or IP.");
|
||||
char cstr[HOST_STR_MAX_LEN];
|
||||
char cstr[MDNS_NAME_BUF_LEN] = {0};
|
||||
char *string_ptr = &cstr[0];
|
||||
ip_addr_t target_addr;
|
||||
struct addrinfo hint;
|
||||
@@ -364,7 +364,7 @@ err_t port_connect(void *ctx, mb_node_info_t *info_ptr)
|
||||
}
|
||||
port_driver_t *drv_obj = MB_GET_DRV_PTR(ctx);
|
||||
err_t err = ERR_OK;
|
||||
char str[HOST_STR_MAX_LEN];
|
||||
char str[MDNS_NAME_BUF_LEN];
|
||||
char *string_ptr = NULL;
|
||||
ip_addr_t target_addr;
|
||||
struct addrinfo hint;
|
||||
@@ -481,8 +481,9 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
||||
int ret = 0;
|
||||
uint16_t index = 0;
|
||||
uint16_t port = 0;
|
||||
char name_buffer[MDNS_NAME_BUF_LEN + 1] = {0};
|
||||
|
||||
MB_RETURN_ON_FALSE((buffer && (strlen(buffer) < (HOST_STR_MAX_LEN - 8)) && info_ptr),
|
||||
MB_RETURN_ON_FALSE((buffer && (strlen(buffer) < (MDNS_NAME_BUF_LEN - 8)) && info_ptr),
|
||||
-1, TAG, "check input parameters fail.");
|
||||
|
||||
#if CONFIG_LWIP_IPV6
|
||||
@@ -557,9 +558,10 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
||||
|
||||
// Configuration format:
|
||||
// "01;mb_node_tcp_01;502"
|
||||
ret = sscanf(buffer, "%" PRIu16 ";%m[a-z0-9_];%" PRIu16, &index, &host_str, &port);
|
||||
ret = sscanf(buffer, "%" PRIu16 ";%" XSTR(MDNS_NAME_BUF_LEN) "[a-z0-9_];%" PRIu16, &index, name_buffer, &port);
|
||||
if ((ret == MB_STR_LEN_HOST) || (ret == MB_STR_LEN_IDX_HOST_PORT)) {
|
||||
info_ptr->node_name_str = (host_str && strlen(host_str)) ? host_str : info_ptr->node_name_str;
|
||||
host_str = (strlen((const char *)name_buffer)) ? strdup((const char *)name_buffer) : NULL;
|
||||
info_ptr->node_name_str = (host_str) ? host_str : info_ptr->node_name_str;
|
||||
info_ptr->ip_addr_str = (info_ptr->node_name_str) ? info_ptr->node_name_str : info_ptr->ip_addr_str;
|
||||
info_ptr->uid = index;
|
||||
info_ptr->fd = UNDEF_FD;
|
||||
@@ -570,15 +572,15 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
||||
}
|
||||
|
||||
// Configuration format:
|
||||
// "mb_node_tcp_01"
|
||||
ret = sscanf(buffer, "%m[a-z0-9_]", &host_str);
|
||||
if (ret == MB_STR_LEN_HOST) {
|
||||
|
||||
info_ptr->node_name_str = (host_str && strlen(host_str)) ? host_str : info_ptr->node_name_str;
|
||||
// "mb_node_tcp_01;502"
|
||||
ret = sscanf(buffer, "%" XSTR(MDNS_NAME_BUF_LEN) "[a-z0-9_];%" PRIu16, name_buffer, &port);
|
||||
if ((ret == MB_STR_LEN_HOST) || (ret == MB_STR_LEN_HOST_PORT)) {
|
||||
host_str = (strlen((const char *)name_buffer)) ? strdup((const char *)name_buffer) : NULL;
|
||||
info_ptr->node_name_str = (host_str) ? host_str : info_ptr->node_name_str;
|
||||
info_ptr->ip_addr_str = (info_ptr->node_name_str) ? info_ptr->node_name_str : info_ptr->ip_addr_str;
|
||||
info_ptr->uid = index;
|
||||
info_ptr->fd = UNDEF_FD;
|
||||
info_ptr->port = CONFIG_FMB_TCP_PORT_DEFAULT;
|
||||
info_ptr->port = (ret == MB_STR_LEN_HOST_PORT) ? port : CONFIG_FMB_TCP_PORT_DEFAULT;
|
||||
info_ptr->addr_type = MB_IPV4;
|
||||
info_ptr->proto = MB_TCP;
|
||||
return ret;
|
||||
@@ -594,7 +596,7 @@ static int mdns_instance_count = 0;
|
||||
// This function has limitation of working with IP6 address only
|
||||
esp_err_t port_start_mdns_service(char **dns_name, bool is_master, int uid, void *node_netif)
|
||||
{
|
||||
char temp_str[HOST_STR_MAX_LEN] = {0};
|
||||
char temp_str[MDNS_NAME_BUF_LEN] = {0};
|
||||
esp_ip6_addr_t ip6[LWIP_IPV6_NUM_ADDRESSES];
|
||||
int ip6_addrs_count = 0;
|
||||
esp_err_t err = ESP_ERR_INVALID_STATE;
|
||||
@@ -612,7 +614,7 @@ esp_err_t port_start_mdns_service(char **dns_name, bool is_master, int uid, void
|
||||
uint8_t mac[6];
|
||||
MB_RETURN_ON_FALSE((esp_netif_get_mac(pnetif, mac) == ESP_OK),
|
||||
err, TAG, "get MAC fail, err = %d.", (int)err);
|
||||
snprintf(temp_str, HOST_STR_MAX_LEN, "%s_%02x%02x%02x", MB_MDNS_INST_NAME(is_master), mac[3], mac[4], mac[5]);
|
||||
snprintf(temp_str, MDNS_NAME_BUF_LEN, "%s_%02x%02x%02x", MB_MDNS_INST_NAME(is_master), mac[3], mac[4], mac[5]);
|
||||
err = mdns_hostname_set(temp_str);
|
||||
MB_RETURN_ON_FALSE((err == ESP_OK),
|
||||
err, TAG, "could not set mdns host name, err = %d.", (int)err);
|
||||
|
||||
@@ -38,11 +38,23 @@ extern "C" {
|
||||
// Workaround for MDNS_NAME_BUF_LEN being defined in private header
|
||||
#ifndef MDNS_NAME_BUF_LEN
|
||||
#define MDNS_NAME_BUF_LEN 64
|
||||
#else
|
||||
# undef MDNS_NAME_BUF_LEN
|
||||
# if defined(CONFIG_LWIP_IPV6) && defined(CONFIG_MDNS_RESPOND_REVERSE_QUERIES)
|
||||
# define MDNS_NAME_BUF_LEN 69
|
||||
# else
|
||||
# define MDNS_NAME_BUF_LEN 65
|
||||
# endif
|
||||
# if (MDNS_NAME_MAX_LEN + 1) != MDNS_NAME_BUF_LEN
|
||||
# error "wrong MDNS_NAME_MAX_LEN value; check with mdns.h header"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define HOST_STR_MAX_LEN (MDNS_NAME_BUF_LEN)
|
||||
#define MB_TCP_NET_LISTEN_BACKLOG (SOMAXCONN)
|
||||
|
||||
#define STRCAT(x) #x
|
||||
#define XSTR(x) STRCAT(x)
|
||||
|
||||
#if MB_MDNS_IS_INCLUDED
|
||||
|
||||
#define MB_ID_BYTE0(id) ((uint8_t)(id))
|
||||
@@ -66,6 +78,7 @@ extern "C" {
|
||||
|
||||
#define MB_STR_LEN_HOST 1 // "mb_node_tcp_01"
|
||||
#define MB_STR_LEN_IDX_HOST 2 // "12;mb_node_tcp_01"
|
||||
#define MB_STR_LEN_HOST_PORT 2 // "mb_node_tcp_01;502"
|
||||
#define MB_STR_LEN_IDX_HOST_PORT 3 // "01;mb_node_tcp_01;1502"
|
||||
#define MB_STR_LEN_IP4_ONLY 4 // "192.168.1.1"
|
||||
#define MB_STR_LEN_IDX_IP4 5 // "1;192.168.1.1"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS "../../test_common") # test library exposes the library internals for test
|
||||
|
||||
# The workaround for the test_utils under ESP-IDF v6.0
|
||||
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "5.5")
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/test_apps/components")
|
||||
else()
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
|
||||
endif()
|
||||
|
||||
set(COMPONENTS main)
|
||||
|
||||
project(test_config_parser)
|
||||
@@ -0,0 +1,3 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
set(srcs "test_config_parser.c")
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES test_common test_utils unity)
|
||||
@@ -0,0 +1,45 @@
|
||||
menu "Modbus Test Configuration"
|
||||
|
||||
config MB_PORT_ADAPTER_EN
|
||||
bool "Enable Modbus port adapter to substitute hardware layer for test."
|
||||
default y
|
||||
help
|
||||
When option is enabled the port communication layer is substituted by
|
||||
port adapter layer to allow testing of higher layers without access to physical layer.
|
||||
|
||||
config MB_TEST_SLAVE_TASK_PRIO
|
||||
int "Modbus master test task priority"
|
||||
range 4 23
|
||||
default 4
|
||||
help
|
||||
Modbus master task priority for the test.
|
||||
|
||||
config MB_TEST_MASTER_TASK_PRIO
|
||||
int "Modbus slave test task priority"
|
||||
range 4 23
|
||||
default 4
|
||||
help
|
||||
Modbus slave task priority for the test.
|
||||
|
||||
config MB_TEST_COMM_CYCLE_COUNTER
|
||||
int "Modbus communication cycle counter for test"
|
||||
range 10 1000
|
||||
default 10
|
||||
help
|
||||
Modbus communication cycle counter for test.
|
||||
|
||||
config MB_TEST_LEAK_WARN_LEVEL
|
||||
int "Modbus test leak warning level"
|
||||
range 4 256
|
||||
default 32
|
||||
help
|
||||
Modbus test leak warning level.
|
||||
|
||||
config MB_TEST_LEAK_CRITICAL_LEVEL
|
||||
int "Modbus test leak critical level"
|
||||
range 4 1024
|
||||
default 64
|
||||
help
|
||||
Modbus test leak critical level.
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,5 @@
|
||||
dependencies:
|
||||
idf: ">=5.0"
|
||||
espressif/esp-modbus:
|
||||
version: "^2"
|
||||
override_path: "../../../../"
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "port_tcp_utils.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define TAG "TEST_MB_CONFIG_PARSER"
|
||||
|
||||
// The below is the test for configuration parser of modbus master tcp
|
||||
|
||||
TEST_CASE("Test tcp configuration parser.", "[MB_CONFIGURATION]")
|
||||
{
|
||||
mb_uid_info_t uid_info = {0};
|
||||
|
||||
// UID, Hostname, Port
|
||||
int result = port_scan_addr_string((char *)"01;mb_node_tcp_01;502", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 3);
|
||||
TEST_ASSERT(uid_info.uid == 1);
|
||||
TEST_ASSERT(uid_info.node_name_str && strcmp(uid_info.node_name_str, "mb_node_tcp_01") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
TEST_ASSERT(uid_info.port == 502);
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// UID, Hostname, Port, the incorect UID provided (only decimal representation is supported)
|
||||
result = port_scan_addr_string("c8;mb_slave_tcp_c8;1502", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 1);
|
||||
TEST_ASSERT(uid_info.uid == 0);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "c8") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
TEST_ASSERT(uid_info.port == 502); // default port
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// UID, Hostname, Port, the incorect host name
|
||||
result = port_scan_addr_string("15;mb_slave**_tcp_c8;1502", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 1);
|
||||
TEST_ASSERT(uid_info.uid == 15);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "15") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
TEST_ASSERT(uid_info.port == 502); // default port
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// Hostname only
|
||||
result = port_scan_addr_string("mb_slave_tcp_01", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 1);
|
||||
TEST_ASSERT(uid_info.uid == 0);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "mb_slave_tcp_01") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// Hostname only
|
||||
result = port_scan_addr_string("mb_slave_tcp_01;1234", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 2);
|
||||
TEST_ASSERT(uid_info.uid == 0);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "mb_slave_tcp_01") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
TEST_ASSERT(uid_info.port == 1234); // default port
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// UID, IPV4 Address, Port
|
||||
result = port_scan_addr_string("2;192.168.1.1;3456", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 6);
|
||||
TEST_ASSERT(uid_info.uid == 2);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "192.168.1.1") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV4);
|
||||
TEST_ASSERT(uid_info.port == 3456); // default port
|
||||
free(uid_info.node_name_str);
|
||||
|
||||
// UID, IPV6 Address, Port
|
||||
result = port_scan_addr_string("12;2001:0db8:85a3:0000:0000:8a2e:0370:7334;502", &uid_info);
|
||||
TEST_ASSERT(uid_info.node_name_str);
|
||||
printf("Test config parser result: %d, index: %d, host: %s, port: %d \r\n", result, uid_info.uid, uid_info.node_name_str, uid_info.port);
|
||||
TEST_ASSERT(result == 10);
|
||||
TEST_ASSERT(uid_info.uid == 12);
|
||||
TEST_ASSERT(strcmp(uid_info.node_name_str, "2001:0db8:85a3:0000:0000:8a2e:0370:7334") == 0);
|
||||
TEST_ASSERT(uid_info.addr_type == MB_IPV6);
|
||||
free(uid_info.node_name_str);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["esp32"], indirect=True)
|
||||
@pytest.mark.multi_dut_modbus_generic
|
||||
def test_mb_config_parser(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
||||
@@ -0,0 +1,2 @@
|
||||
# General options for test
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
Reference in New Issue
Block a user