MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / test_netdev_get_functions

Function test_netdev_get_functions

components/net/utest/tc_netdev.c:470–513  ·  view source on GitHub ↗

* @brief Test network device retrieval functions * * This function tests various methods to retrieve network devices: * - Get device by name (valid and invalid names) * - Get device by IP address (valid and invalid addresses) * - Get device by interface index (valid and invalid indices) * - Get first device by flags * - Get device by protocol family (if SAL is enabled) * * @note Tests bot

Source from the content-addressed store, hash-verified

468 * @note Tests both successful and failed retrieval scenarios
469 */
470static void test_netdev_get_functions(void)
471{
472 struct netdev *netdev_found;
473
474 /* Test get_by_name */
475 netdev_found = netdev_get_by_name(netdev_default->name);
476 uassert_true(netdev_found == netdev_default);
477
478 netdev_found = netdev_get_by_name("nonexistent");
479 uassert_true(netdev_found == RT_NULL);
480
481 /* Test get_by_ipaddr */
482 netdev_found = netdev_get_by_ipaddr(&netdev_default->ip_addr);
483 uassert_true(netdev_found == netdev_default);
484
485 ip_addr_t invalid_ip;
486 ip_addr_set_zero(&invalid_ip);
487 netdev_found = netdev_get_by_ipaddr(&invalid_ip);
488 uassert_true(netdev_found == RT_NULL);
489
490 /* Test get_by_ifindex */
491 netdev_found = netdev_get_by_ifindex(netdev_default->ifindex);
492 uassert_true(netdev_found == netdev_default);
493
494 netdev_found = netdev_get_by_ifindex(-1);
495 uassert_true(netdev_found == RT_NULL);
496
497 /* Test get_first_by_flags */
498 netdev_found = netdev_get_first_by_flags(NETDEV_FLAG_UP);
499 uassert_true(netdev_found != RT_NULL);
500
501 netdev_found = netdev_get_first_by_flags(NETDEV_FLAG_UP | NETDEV_FLAG_LINK_UP);
502 uassert_true(netdev_found != RT_NULL);
503
504#ifdef RT_USING_SAL
505 /* Test get_by_family */
506 netdev_found = netdev_get_by_family(AF_INET);
507 uassert_true(netdev_found != RT_NULL);
508
509 /* Test family_get */
510 int family = netdev_family_get(netdev_default);
511 uassert_true(family == AF_INET);
512#endif
513}
514
515/**
516 * @brief Test network device status setting operations

Callers

nothing calls this directly

Calls 6

netdev_get_by_nameFunction · 0.85
netdev_get_by_ipaddrFunction · 0.85
netdev_get_by_ifindexFunction · 0.85
netdev_get_by_familyFunction · 0.85
netdev_family_getFunction · 0.85

Tested by

no test coverage detected