* @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
| 468 | * @note Tests both successful and failed retrieval scenarios |
| 469 | */ |
| 470 | static 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 |
nothing calls this directly
no test coverage detected