This patch adds "mx_create_sink" annotation support to MagentaHandleChecker to address the false positives found in Magenta unit tests. After this patch, when a call to a function contains this annotation, MagentaHandleChecker will create a sink node which will suppress the handle leaks warnings if the leak is post-dominated by this function (similar to a noreturn function).
The target problem it tries to solve can be illustrated in following example:
static bool handle_info_test(void) { BEGIN_TEST; mx_handle_t event; ASSERT_EQ(mx_event_create(0u, &event), 0, ""); mx_handle_t duped; mx_status_t status = mx_handle_duplicate(event, MX_RIGHT_SAME_RIGHTS, &duped); ASSERT_EQ(status, MX_OK, ""); // .... }
Unlike the "assert" keyword in C++, the ASSERT_EQ macro will not terminate the execution of the unit test program (in other words, it will not invoke a noreturn function), instead it will return false and the error will be recorded by the unit test runner. Therefore, before this patch, the MagentaHandleChecker will report handle leaks on these assertion failures as the function reaches return and symbol that contains the acquired handles are acquired. These reports are not helpful as assertion failures in unit tests mean test failures. With the help of this patch, we add a call to a function with "mx_create_sink" annotation in the failure branch in definition "ASSERT_EQ". In this case, the MagentaHandleChecker will create a sink node in each assertion failure and suppress the warnings if the leaks are post-dominated by assertion failures.