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

Function test_netdev_callbacks

components/net/utest/tc_netdev.c:774–815  ·  view source on GitHub ↗

* @brief Test network device callback mechanism * * This function tests the callback functionality for network events: * - Setting status and address callbacks * - IP address change callbacks * - Gateway change callbacks * - DHCP enable callbacks * - Callback synchronization using events * - Callback cleanup * * @note Uses event synchronization to verify callbacks are properly triggered

Source from the content-addressed store, hash-verified

772 * @note Uses event synchronization to verify callbacks are properly triggered
773 */
774static void test_netdev_callbacks(void)
775{
776 ip_addr_t test_ip, test_gw;
777 rt_bool_t dhcp_enable = RT_TRUE;
778
779 /* Reset callback test variables */
780 callback_called = RT_FALSE;
781 last_callback_type = NETDEV_CB_ADDR_IP;
782 ip_callback_called = RT_FALSE;
783 gw_callback_called = RT_FALSE;
784 dhcp_callback_called = RT_FALSE;
785
786 /* Set status callback */
787 netdev_set_status_callback(netdev_default, test_callback);
788 /* Set address callback */
789 netdev_set_addr_callback(netdev_default, test_callback);
790
791 /* Test IP address change callback */
792 inet_aton("192.168.1.100", &test_ip);
793 test_callback_operation(set_ipaddr_wrapper, &test_ip,
794 1 << NETDEV_CB_ADDR_IP, &ip_callback_called, "IP address");
795
796 /* Reset callback flags */
797 ip_callback_called = RT_FALSE;
798 gw_callback_called = RT_FALSE;
799
800 /* Test gateway change callback */
801 inet_aton("192.168.1.1", &test_gw);
802 test_callback_operation(set_gw_wrapper, &test_gw,
803 1 << NETDEV_CB_ADDR_GATEWAY, &gw_callback_called, "Gateway");
804
805 /* Reset callback flags */
806 dhcp_callback_called = RT_FALSE;
807
808 /* Test DHCP enable callback */
809 test_callback_operation(dhcp_enable_wrapper, &dhcp_enable,
810 1 << NETDEV_CB_STATUS_DHCP_ENABLE, &dhcp_callback_called, "DHCP enable");
811
812 /* Clear callbacks */
813 netdev_set_status_callback(netdev_default, empty_callback);
814 netdev_set_addr_callback(netdev_default, empty_callback);
815}
816
817/**
818 * @brief Test multiple network interfaces functionality

Callers

nothing calls this directly

Calls 3

netdev_set_addr_callbackFunction · 0.85
test_callback_operationFunction · 0.85

Tested by

no test coverage detected