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

Function test_callback_operation

components/net/utest/tc_netdev.c:672–709  ·  view source on GitHub ↗

* @brief Helper function for testing callback operations * * This function performs a network operation and waits for the corresponding * callback to be triggered within a specified timeout. * * @param operation Function pointer to the operation to perform * @param param Parameter to pass to the operation * @param event_mask Event mask to wait for * @param callback_flag Pointer to callback

Source from the content-addressed store, hash-verified

670 * @param test_name Name of the test for logging purposes
671 */
672static void test_callback_operation(rt_err_t (*operation)(struct netdev *, void *),
673 void *param,
674 rt_uint32_t event_mask,
675 rt_bool_t *callback_flag,
676 const char *test_name)
677{
678 rt_err_t res;
679 rt_uint32_t recved;
680
681 /* Reset callback flag */
682 *callback_flag = RT_FALSE;
683
684 /* Perform operation */
685 res = operation(netdev_default, param);
686 if (res == RT_EOK)
687 {
688 /* Wait for callback event */
689 rt_err_t event_res = rt_event_recv(callback_event, event_mask,
690 RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
691 CALLBACK_EVENT_TIMEOUT, &recved);
692 if (event_res == RT_EOK && *callback_flag)
693 {
694 rt_kprintf("%s test passed\n", test_name);
695 uassert_true(RT_TRUE);
696 }
697 else
698 {
699 rt_kprintf("%s test failed - event_res=%d, callback_called=%d\n",
700 test_name, event_res, *callback_flag);
701 uassert_true(RT_FALSE);
702 }
703 }
704 else
705 {
706 rt_kprintf("Failed to perform %s: %d\n", test_name, res);
707 uassert_true(RT_FALSE);
708 }
709}
710
711/* Wrapper functions for callback testing */
712static rt_err_t set_ipaddr_wrapper(struct netdev *netdev, void *param)

Callers 1

test_netdev_callbacksFunction · 0.85

Calls 2

rt_event_recvFunction · 0.85
rt_kprintfFunction · 0.85

Tested by

no test coverage detected