Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions components/net/utest/tc_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ rt_err_t multiple_ping_test(struct netdev *netdev, const char *host, rt_uint32_t
*/
static void test_netdev_ping(void)
{
#define UTEST_INTRANET_WRONG_IP_ADDR "192.256.0.321" /* Invalid IP format */
#define UTEST_EXTERNAL_IP_ADDR "8.8.8.8" /* Valid external IP */
#define UTEST_EXTERNAL_WRONG_IP_ADDR "123.456.789.012" /* Invalid IP format */
#define UTEST_EXTERNAL_URL "www.baidu.com" /* Valid external URL */
#define UTEST_EXTERNAL_WRONG_URL "www.abcsdd.com" /* Non-existent URL */
#define UTEST_INTRANET_WRONG_IP_ADDR "192.256.0.321" /* Invalid IP format */
#define UTEST_EXTERNAL_IP_ADDR "114.114.114.114" /* Valid external IP */
#define UTEST_EXTERNAL_URL "www.baidu.com" /* Valid external URL */
#define UTEST_EXTERNAL_WRONG_IP_ADDR "123.456.789.012" /* Invalid IP format */
#define UTEST_EXTERNAL_WRONG_URL "www.abcsdd.com" /* Non-existent URL */

rt_err_t res = RT_EOK;

Expand All @@ -105,17 +105,19 @@ static void test_netdev_ping(void)
res = multiple_ping_test(netdev_default, UTEST_INTRANET_WRONG_IP_ADDR, 1);
uassert_false(res == RT_EOK);

/* Test ping to external IP address - should succeed */
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_IP_ADDR, 10);
uassert_true(res == RT_EOK);

/* Test ping to invalid external IP - should fail */
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_WRONG_IP_ADDR, 1);
uassert_false(res == RT_EOK);

#ifndef RT_USING_CI_ACTION
/* Test ping to external IP address - should succeed */
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_IP_ADDR, 10);
uassert_true(res == RT_EOK);

/* Test ping to external URL - should succeed */
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_URL, 10);
uassert_true(res == RT_EOK);
#endif

/* Test ping to invalid external URL - should fail */
res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_WRONG_URL, 1);
Expand Down
35 changes: 29 additions & 6 deletions components/utilities/utest/utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#endif
#include <rtdbg.h>

#if RT_CONSOLEBUF_SIZE < 256
#if defined(RT_CONSOLEBUF_SIZE) && RT_CONSOLEBUF_SIZE < 256
#error "RT_CONSOLEBUF_SIZE is less than 256!"
#endif

Expand Down Expand Up @@ -108,8 +108,9 @@ int utest_init(void)
extern const int UtestTcTab$$Base;
extern const int UtestTcTab$$Limit;
tc_table = (utest_tc_export_t)&UtestTcTab$$Base;
// cppcheck-suppress subtractPointers
tc_num = (utest_tc_export_t)&UtestTcTab$$Limit - tc_table;
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
#elif defined(__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
tc_table = (utest_tc_export_t)__section_begin("UtestTcTab");
tc_num = (utest_tc_export_t)__section_end("UtestTcTab") - tc_table;
#else
Expand All @@ -124,21 +125,26 @@ int utest_init(void)
ptr_end = (unsigned int *)&__tc_export_end;
ptr_begin += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
#endif
while (*ptr_begin == 0) ptr_begin++;
#if defined(__GNUC__) || defined(_MSC_VER)
while (*ptr_begin == 0)
ptr_begin++;
ptr_end--;
while (*ptr_end == 0) ptr_end--;
while (*ptr_end == 0)
ptr_end--;
/* copy tc_table from rodata section to ram */
for (unsigned int *ptr = ptr_begin; ptr < ptr_end;)
{
if (!tc_table)
tc_table = (utest_tc_export_t)rt_malloc(sizeof(struct utest_tc_export));
else
tc_table = (utest_tc_export_t)rt_realloc(tc_table, (tc_num + 1)* sizeof(struct utest_tc_export));
tc_table = (utest_tc_export_t)rt_realloc(tc_table, (tc_num + 1) * sizeof(struct utest_tc_export));
RT_ASSERT(tc_table);
tc_table[tc_num++] = *((utest_tc_export_t)ptr);
ptr += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
while (*ptr == 0) ptr++;
while (*ptr == 0)
ptr++;
}
#endif
#endif

LOG_I("utest is initialize success.");
Expand Down Expand Up @@ -279,6 +285,10 @@ static void utest_do_run(const char *utest_name)

if (tc_table[i].tc != RT_NULL)
{
local_utest.error = UTEST_PASSED;
local_utest.passed_num = 0;
local_utest.failed_num = 0;

tc_table[i].tc();
if (local_utest.failed_num == 0)
{
Expand Down Expand Up @@ -433,6 +443,9 @@ utest_t utest_handle_get(void)

void utest_unit_run(test_unit_func func, const char *unit_func_name)
{
rt_uint32_t passed_num = local_utest.passed_num;
rt_uint32_t failed_num = local_utest.failed_num;

LOG_I("[==========] utest unit name: (%s)", unit_func_name);
local_utest.error = UTEST_PASSED;
local_utest.passed_num = 0;
Expand All @@ -442,6 +455,16 @@ void utest_unit_run(test_unit_func func, const char *unit_func_name)
{
func();
}

passed_num += local_utest.passed_num;
failed_num += local_utest.failed_num;

local_utest.passed_num = passed_num;
local_utest.failed_num = failed_num;
if (local_utest.failed_num != 0)
{
local_utest.error = UTEST_FAILED;
}
}

/*
Expand Down
14 changes: 10 additions & 4 deletions src/utest/signal_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
static volatile int receive_sig = 0;
static struct rt_semaphore _received_signal;

#ifdef RT_USING_MUSLLIBC
#define UTEST_SIGNAL_MIN 1
#else
#define UTEST_SIGNAL_MIN 0
#endif

void sig_handle_default(int signo)
{
receive_sig = signo;
Expand All @@ -145,7 +151,7 @@ static void rt_signal_install_test(void)
rt_sighandler_t result;

/* case 1:rt_signal_install, install all available signal. */
for (signo = 0; signo < RT_SIG_MAX; signo++)
for (signo = UTEST_SIGNAL_MIN; signo < RT_SIG_MAX; signo++)
{
result = rt_signal_install(signo, sig_handle_default);
uassert_true(result != SIG_ERR);
Expand All @@ -163,7 +169,7 @@ static void rt_signal_unmask_test(void)
rt_sighandler_t result;

/* case 3:rt_signal_mask/unmask, one thread self, install and unmask, then kill, should received. */
for (signo = 0; signo < RT_SIG_MAX; signo++)
for (signo = UTEST_SIGNAL_MIN; signo < RT_SIG_MAX; signo++)
{
receive_sig = -1;
result = rt_signal_install(signo, sig_handle_default);
Expand All @@ -183,7 +189,7 @@ static void rt_signal_mask_test(void)
rt_sighandler_t result;

/* case 4:rt_signal_mask/unmask, one thread self, install and unmask and mask, then kill, should can't received. */
for (signo = 0; signo < RT_SIG_MAX; signo++)
for (signo = UTEST_SIGNAL_MIN; signo < RT_SIG_MAX; signo++)
{
receive_sig = -1;
result = rt_signal_install(signo, sig_handle_default);
Expand All @@ -206,7 +212,7 @@ static void rt_signal_kill_test(void)
rt_sighandler_t result;

/* case 7:rt_signal_kill, kill legal thread, return 0; */
for (signo = 0; signo < RT_SIG_MAX; signo++)
for (signo = UTEST_SIGNAL_MIN; signo < RT_SIG_MAX; signo++)
{
receive_sig = -1;
result = rt_signal_install(signo, sig_handle_default);
Expand Down
Loading