mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
style: format code with clang-format [skip ci]
This commit is contained in:
1 parent
25dcad752c
commit
ff82e23d13
2 files changed
+57
-55
No files matched your search
@@ -50,8 +50,8 @@ static rt_bool_t initial_dhcp_enabled; /**< Initial DHCP enable status */
|
||||
*/
|
||||
rt_err_t multiple_ping_test(struct netdev *netdev, const char *host, rt_uint32_t n)
|
||||
{
|
||||
#define UTEST_PING_DATA_LEN 32 /* Ping data packet size */
|
||||
#define UTEST_PING_TIMEOUT (5 * RT_TICK_PER_SECOND) /* Ping timeout: 5 seconds */
|
||||
#define UTEST_PING_DATA_LEN 32 /* Ping data packet size */
|
||||
#define UTEST_PING_TIMEOUT (5 * RT_TICK_PER_SECOND) /* Ping timeout: 5 seconds */
|
||||
|
||||
rt_uint32_t success_num = 0, i;
|
||||
rt_err_t res = RT_EOK;
|
||||
@@ -88,8 +88,8 @@ rt_err_t multiple_ping_test(struct netdev *netdev, const char *host, rt_uint32_t
|
||||
static void test_netdev_ping(void)
|
||||
{
|
||||
#define UTEST_INVALID_HOST_NAME "" /* Rejected before DNS lookup */
|
||||
#define UTEST_EXTERNAL_IP_ADDR "8.8.8.8" /* Valid external IP */
|
||||
#define UTEST_EXTERNAL_URL "www.baidu.com" /* Valid external URL */
|
||||
#define UTEST_EXTERNAL_IP_ADDR "8.8.8.8" /* Valid external IP */
|
||||
#define UTEST_EXTERNAL_URL "www.baidu.com" /* Valid external URL */
|
||||
|
||||
rt_err_t res = RT_EOK;
|
||||
|
||||
@@ -110,7 +110,6 @@ static void test_netdev_ping(void)
|
||||
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_URL, 10);
|
||||
uassert_true(res == RT_EOK);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,11 +169,11 @@ static void test_netdev_netstat(void)
|
||||
*/
|
||||
static void test_netdev_dns(void)
|
||||
{
|
||||
#define UTEST_DNS "114.114.114.114" /* Valid DNS server */
|
||||
#define UTEST_INVALID_HOST "" /* Rejected before DNS lookup */
|
||||
#define UTEST_HOST_ADDR "www.rt-thread.org" /* RT-Thread official website */
|
||||
#define UTEST_DNS "114.114.114.114" /* Valid DNS server */
|
||||
#define UTEST_INVALID_HOST "" /* Rejected before DNS lookup */
|
||||
#define UTEST_HOST_ADDR "www.rt-thread.org" /* RT-Thread official website */
|
||||
|
||||
ip_addr_t ipaddr = {0};
|
||||
ip_addr_t ipaddr = { 0 };
|
||||
struct hostent *res = RT_NULL;
|
||||
struct sal_proto_family *netdev_inet = RT_NULL;
|
||||
rt_err_t err;
|
||||
@@ -266,7 +265,7 @@ static void test_netdev_dhcp(void)
|
||||
|
||||
/* Check if IP and gateway are properly restored */
|
||||
if (!ip_addr_isany(&netdev_default->ip_addr) &&
|
||||
!ip_addr_isany(&netdev_default->gw))
|
||||
!ip_addr_isany(&netdev_default->gw))
|
||||
{
|
||||
rt_kprintf("Network configuration restored after %d retries\n", retry_count);
|
||||
rt_kprintf("Current IP: %s, Gateway: %s\n",
|
||||
@@ -299,9 +298,9 @@ static void test_netdev_dhcp(void)
|
||||
*/
|
||||
static void test_netdev_ifconfig_set(void)
|
||||
{
|
||||
#define UTEST_WRONG_IP_ADDR "192.1.4.125" /* Test IP address */
|
||||
#define UTEST_HOST_ADDR "www.rt-thread.org" /* Test hostname */
|
||||
#define UTEST_WRONG_GW_IP_ADDR "192.168.99.1" /* Test gateway address */
|
||||
#define UTEST_WRONG_IP_ADDR "192.1.4.125" /* Test IP address */
|
||||
#define UTEST_HOST_ADDR "www.rt-thread.org" /* Test hostname */
|
||||
#define UTEST_WRONG_GW_IP_ADDR "192.168.99.1" /* Test gateway address */
|
||||
|
||||
ip_addr_t ipaddr, true_ipaddr;
|
||||
rt_err_t res = RT_EOK;
|
||||
@@ -397,9 +396,9 @@ static void test_netdev_set_default_netdev(void)
|
||||
*/
|
||||
static void test_netdev_ipaddr_conversion(void)
|
||||
{
|
||||
#define UTEST_IP4_ADDR_STR "192.168.1.1" /* Valid IPv4 address */
|
||||
#define UTEST_IP4_ADDR_STR2 "10.0.0.1" /* Another valid IPv4 address */
|
||||
#define UTEST_INVALID_IP_STR "999.999.999.999" /* Invalid IPv4 address */
|
||||
#define UTEST_IP4_ADDR_STR "192.168.1.1" /* Valid IPv4 address */
|
||||
#define UTEST_IP4_ADDR_STR2 "10.0.0.1" /* Another valid IPv4 address */
|
||||
#define UTEST_INVALID_IP_STR "999.999.999.999" /* Invalid IPv4 address */
|
||||
|
||||
ip4_addr_t ip4_addr;
|
||||
char buf[16]; /* Maximum length for IPv4 string representation */
|
||||
@@ -575,7 +574,7 @@ static void test_netdev_config_set(void)
|
||||
ip_addr_t original_netmask = netdev_default->netmask;
|
||||
ip_addr_t original_dns0 = netdev_default->dns_servers[0];
|
||||
ip_addr_t original_dns1 = netdev_default->dns_servers[1];
|
||||
ip_addr_t test_netmask = {0}, test_dns = {0};
|
||||
ip_addr_t test_netmask = { 0 }, test_dns = { 0 };
|
||||
rt_err_t res;
|
||||
|
||||
/* Test set_netmask */
|
||||
@@ -1055,19 +1054,24 @@ static rt_err_t utest_tc_cleanup(void)
|
||||
|
||||
/* Restore network configuration */
|
||||
res = netdev_set_ipaddr(netdev_default, &initial_ip_addr);
|
||||
if (res != RT_EOK) rt_kprintf("Warning: Failed to restore IP address: %d\n", res);
|
||||
if (res != RT_EOK)
|
||||
rt_kprintf("Warning: Failed to restore IP address: %d\n", res);
|
||||
|
||||
res = netdev_set_netmask(netdev_default, &initial_netmask);
|
||||
if (res != RT_EOK) rt_kprintf("Warning: Failed to restore netmask: %d\n", res);
|
||||
if (res != RT_EOK)
|
||||
rt_kprintf("Warning: Failed to restore netmask: %d\n", res);
|
||||
|
||||
res = netdev_set_gw(netdev_default, &initial_gw);
|
||||
if (res != RT_EOK) rt_kprintf("Warning: Failed to restore gateway: %d\n", res);
|
||||
if (res != RT_EOK)
|
||||
rt_kprintf("Warning: Failed to restore gateway: %d\n", res);
|
||||
|
||||
res = netdev_set_dns_server(netdev_default, 0, &initial_dns0);
|
||||
if (res != RT_EOK) rt_kprintf("Warning: Failed to restore DNS0: %d\n", res);
|
||||
if (res != RT_EOK)
|
||||
rt_kprintf("Warning: Failed to restore DNS0: %d\n", res);
|
||||
|
||||
res = netdev_set_dns_server(netdev_default, 1, &initial_dns1);
|
||||
if (res != RT_EOK) rt_kprintf("Warning: Failed to restore DNS1: %d\n", res);
|
||||
if (res != RT_EOK)
|
||||
rt_kprintf("Warning: Failed to restore DNS1: %d\n", res);
|
||||
|
||||
/* Restore DHCP state */
|
||||
if (initial_dhcp_enabled)
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include "utest.h"
|
||||
#include "utest_log.h"
|
||||
|
||||
#define DBG_TAG "utest"
|
||||
#define DBG_TAG "utest"
|
||||
#ifdef UTEST_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
#define DBG_LVL DBG_INFO
|
||||
#define DBG_LVL DBG_INFO
|
||||
#endif
|
||||
#include <rtdbg.h>
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef UTEST_THR_PRIORITY
|
||||
#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY
|
||||
#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY
|
||||
#else
|
||||
#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY
|
||||
#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY
|
||||
#endif
|
||||
|
||||
static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
|
||||
@@ -43,27 +43,25 @@ static utest_tc_export_t tc_table = RT_NULL;
|
||||
static rt_size_t tc_num;
|
||||
static rt_uint32_t tc_loop;
|
||||
static rt_uint8_t *tc_fail_list;
|
||||
static struct utest local_utest = {UTEST_PASSED, 0, 0};
|
||||
static struct utest local_utest = { UTEST_PASSED, 0, 0 };
|
||||
|
||||
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
|
||||
#pragma section="UtestTcTab"
|
||||
#pragma section = "UtestTcTab"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma section("UtestTcTab$a", read)
|
||||
__declspec(allocate("UtestTcTab$a")) const struct utest_tc_export __tc_export_begin =
|
||||
{
|
||||
__declspec(allocate("UtestTcTab$a")) const struct utest_tc_export __tc_export_begin = {
|
||||
"__start",
|
||||
};
|
||||
|
||||
#pragma section("UtestTcTab$z", read)
|
||||
__declspec(allocate("UtestTcTab$z")) const struct utest_tc_export __tc_export_end =
|
||||
{
|
||||
__declspec(allocate("UtestTcTab$z")) const struct utest_tc_export __tc_export_end = {
|
||||
"__end",
|
||||
};
|
||||
#endif
|
||||
|
||||
#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8)
|
||||
#define TC_FAIL_LIST_MARK_FAILED(index) (tc_fail_list[index / 8] |= (1UL << (index % 8)))
|
||||
#define TC_FAIL_LIST_IS_FAILED(index) (tc_fail_list[index / 8] & (1UL << (index % 8)))
|
||||
#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8)
|
||||
#define TC_FAIL_LIST_MARK_FAILED(index) (tc_fail_list[index / 8] |= (1UL << (index % 8)))
|
||||
#define TC_FAIL_LIST_IS_FAILED(index) (tc_fail_list[index / 8] & (1UL << (index % 8)))
|
||||
|
||||
void utest_log_lv_set(rt_uint8_t lv)
|
||||
{
|
||||
@@ -152,7 +150,7 @@ int utest_init(void)
|
||||
if (tc_num > 0)
|
||||
{
|
||||
tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE);
|
||||
if(!tc_fail_list)
|
||||
if (!tc_fail_list)
|
||||
{
|
||||
LOG_E("no memory, tc_fail_list init failed!");
|
||||
}
|
||||
@@ -184,8 +182,8 @@ static const char *file_basename(const char *file)
|
||||
char *end_ptr = RT_NULL;
|
||||
char *rst = RT_NULL;
|
||||
|
||||
if (!((end_ptr = strrchr(file, '\\')) != RT_NULL || \
|
||||
(end_ptr = strrchr(file, '/')) != RT_NULL) || \
|
||||
if (!((end_ptr = strrchr(file, '\\')) != RT_NULL ||
|
||||
(end_ptr = strrchr(file, '/')) != RT_NULL) ||
|
||||
(rt_strlen(file) < 2))
|
||||
{
|
||||
rst = (char *)file;
|
||||
@@ -232,7 +230,7 @@ static void utest_do_run(const char *utest_name)
|
||||
rt_uint32_t tc_fail_num = 0;
|
||||
rt_uint32_t tc_run_num = 0;
|
||||
|
||||
for (index = 0; index < tc_loop; index ++)
|
||||
for (index = 0; index < tc_loop; index++)
|
||||
{
|
||||
i = 0;
|
||||
is_find = RT_FALSE;
|
||||
@@ -246,7 +244,7 @@ static void utest_do_run(const char *utest_name)
|
||||
|
||||
LOG_I("[==========] [ utest ] loop %d/%d", index + 1, tc_loop);
|
||||
LOG_I("[==========] [ utest ] started");
|
||||
while(i < tc_num)
|
||||
while (i < tc_num)
|
||||
{
|
||||
if (utest_name)
|
||||
{
|
||||
@@ -276,7 +274,7 @@ static void utest_do_run(const char *utest_name)
|
||||
if (tc_table[i].init() != RT_EOK)
|
||||
{
|
||||
TC_FAIL_LIST_MARK_FAILED(i);
|
||||
tc_fail_num ++;
|
||||
tc_fail_num++;
|
||||
tc_failed = RT_TRUE;
|
||||
LOG_E("[ FAILED ] [ result ] testcase init (%s)", tc_table[i].name);
|
||||
goto __tc_continue;
|
||||
@@ -297,7 +295,7 @@ static void utest_do_run(const char *utest_name)
|
||||
else
|
||||
{
|
||||
TC_FAIL_LIST_MARK_FAILED(i);
|
||||
tc_fail_num ++;
|
||||
tc_fail_num++;
|
||||
tc_failed = RT_TRUE;
|
||||
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
||||
}
|
||||
@@ -305,7 +303,7 @@ static void utest_do_run(const char *utest_name)
|
||||
else
|
||||
{
|
||||
TC_FAIL_LIST_MARK_FAILED(i);
|
||||
tc_fail_num ++;
|
||||
tc_fail_num++;
|
||||
tc_failed = RT_TRUE;
|
||||
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
||||
}
|
||||
@@ -317,17 +315,17 @@ static void utest_do_run(const char *utest_name)
|
||||
if (tc_failed == RT_FALSE)
|
||||
{
|
||||
TC_FAIL_LIST_MARK_FAILED(i);
|
||||
tc_fail_num ++;
|
||||
tc_fail_num++;
|
||||
}
|
||||
LOG_E("[ FAILED ] [ result ] testcase cleanup (%s)", tc_table[i].name);
|
||||
goto __tc_continue;
|
||||
}
|
||||
}
|
||||
|
||||
__tc_continue:
|
||||
__tc_continue:
|
||||
LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name);
|
||||
|
||||
tc_run_num ++;
|
||||
tc_run_num++;
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -341,10 +339,10 @@ static void utest_do_run(const char *utest_name)
|
||||
LOG_I("[==========] [ utest ] %d tests from %d testcase ran.", tc_run_num, tc_num);
|
||||
LOG_I("[ PASSED ] [ result ] %d tests.", tc_run_num - tc_fail_num);
|
||||
|
||||
if(tc_fail_list && (tc_fail_num > 0))
|
||||
if (tc_fail_list && (tc_fail_num > 0))
|
||||
{
|
||||
LOG_E("[ FAILED ] [ result ] %d tests, listed below:", tc_fail_num);
|
||||
for(i = 0; i < tc_num; i ++)
|
||||
for (i = 0; i < tc_num; i++)
|
||||
{
|
||||
if (TC_FAIL_LIST_IS_FAILED(i))
|
||||
{
|
||||
@@ -387,7 +385,7 @@ static int utest_auto_run(void)
|
||||
INIT_APP_EXPORT(utest_auto_run);
|
||||
#endif /* RT_UTEST_USING_AUTO_RUN */
|
||||
|
||||
int utest_testcase_run(int argc, char** argv)
|
||||
int utest_testcase_run(int argc, char **argv)
|
||||
{
|
||||
static char utest_name[UTEST_NAME_MAX_LEN];
|
||||
rt_memset(utest_name, 0x0, sizeof(utest_name));
|
||||
@@ -404,7 +402,7 @@ int utest_testcase_run(int argc, char** argv)
|
||||
{
|
||||
if (argc == 3 || argc == 4)
|
||||
{
|
||||
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
|
||||
rt_strncpy(utest_name, argv[2], sizeof(utest_name) - 1);
|
||||
if (argc == 4)
|
||||
{
|
||||
tc_loop = atoi(argv[3]);
|
||||
@@ -418,7 +416,7 @@ int utest_testcase_run(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
|
||||
rt_strncpy(utest_name, argv[1], sizeof(utest_name) - 1);
|
||||
if (argc == 3)
|
||||
{
|
||||
tc_loop = atoi(argv[2]);
|
||||
@@ -434,7 +432,7 @@ int utest_testcase_run(int argc, char** argv)
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num], optenable);
|
||||
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run[-thread or -help][testcase name][loop num], optenable);
|
||||
|
||||
utest_t utest_handle_get(void)
|
||||
{
|
||||
@@ -485,7 +483,7 @@ rt_bool_t utest_assert(int value, const char *file, int line, const char *func,
|
||||
if (!(value))
|
||||
{
|
||||
local_utest.error = UTEST_FAILED;
|
||||
local_utest.failed_num ++;
|
||||
local_utest.failed_num++;
|
||||
LOG_E("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)", file_basename(file), func, line, msg);
|
||||
rst = RT_FALSE;
|
||||
}
|
||||
@@ -496,7 +494,7 @@ rt_bool_t utest_assert(int value, const char *file, int line, const char *func,
|
||||
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
|
||||
}
|
||||
local_utest.error = UTEST_PASSED;
|
||||
local_utest.passed_num ++;
|
||||
local_utest.passed_num++;
|
||||
rst = RT_TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user