diff --git a/common/tests/tqueue_ut/tqueue_ut.c b/common/tests/tqueue_ut/tqueue_ut.c index d658f7f3..0920ce1e 100644 --- a/common/tests/tqueue_ut/tqueue_ut.c +++ b/common/tests/tqueue_ut/tqueue_ut.c @@ -347,87 +347,14 @@ TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_with_non_NULL_dispose_item_with_1_item_calls_d /* Tests_SRS_TQUEUE_01_011: [ For each item in the queue, dispose_item_function shall be called with dispose_item_function_context and a pointer to the array entry value (T*). ]*/ /* Tests_SRS_TQUEUE_01_056: [ The lock initialized in TQUEUE_CREATE(T) shall be de-initialized. ] */ /* Tests_SRS_TQUEUE_01_057: [ The array backing the queue shall be freed. ] */ -TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_with_non_NULL_dispose_item_with_2_items_calls_dispose_item_2_times) +PARAMETERIZED_TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_with_non_NULL_dispose_item_with_2_items_calls_dispose_item_2_times, + ARGS(uint32_t, initial_queue_size, uint32_t, max_queue_size), + CASE((1024, 1024), same_initial_and_max_size), + CASE((1024, 2048), max_size_bigger_than_initial_size), + CASE((1, 2048), queue_that_was_grown)) { // arrange - TQUEUE(int32_t) queue = test_queue_create(1024, 1024, test_copy_item, test_dispose_item, (void*)0x4242); - test_queue_push(queue, 42); - test_queue_push(queue, 42); - - STRICT_EXPECTED_CALL(interlocked_decrement(IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 0)); // head - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 0)); // tail - STRICT_EXPECTED_CALL(test_dispose_item((void*)0x4242, IGNORED_ARG)); - STRICT_EXPECTED_CALL(test_dispose_item((void*)0x4242, IGNORED_ARG)); - STRICT_EXPECTED_CALL(srw_lock_ll_deinit(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - TQUEUE_ASSIGN(int32_t)(&queue, NULL); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); -} - -/* Tests_SRS_TQUEUE_01_009: [ Otherwise, TQUEUE_DISPOSE_FUNC(T) shall obtain the current queue head by calling interlocked_add_64. ]*/ -/* Tests_SRS_TQUEUE_01_010: [ TQUEUE_DISPOSE_FUNC(T) shall obtain the current queue tail by calling interlocked_add_64. ]*/ -/* Tests_SRS_TQUEUE_01_011: [ For each item in the queue, dispose_item_function shall be called with dispose_item_function_context and a pointer to the array entry value (T*). ]*/ -/* Tests_SRS_TQUEUE_01_056: [ The lock initialized in TQUEUE_CREATE(T) shall be de-initialized. ] */ -/* Tests_SRS_TQUEUE_01_057: [ The array backing the queue shall be freed. ] */ -TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_for_a_queue_with_max_size_bigger_than_initial_size_frees_resources) -{ - // arrange - TQUEUE(int32_t) queue = test_queue_create(1024, 2048, test_copy_item, test_dispose_item, (void*)0x4242); - test_queue_push(queue, 42); - test_queue_push(queue, 42); - - STRICT_EXPECTED_CALL(interlocked_decrement(IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 0)); // head - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 0)); // tail - STRICT_EXPECTED_CALL(test_dispose_item((void*)0x4242, IGNORED_ARG)); - STRICT_EXPECTED_CALL(test_dispose_item((void*)0x4242, IGNORED_ARG)); - STRICT_EXPECTED_CALL(srw_lock_ll_deinit(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - TQUEUE_ASSIGN(int32_t)(&queue, NULL); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); -} - -/* Tests_SRS_TQUEUE_01_056: [ The lock initialized in TQUEUE_CREATE(T) shall be de-initialized. ] */ -/* Tests_SRS_TQUEUE_01_057: [ The array backing the queue shall be freed. ] */ -TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_for_a_queue_with_max_size_bigger_than_initial_size_with_NULL_copy_and_dispose_function_frees_resources) -{ - // arrange - TQUEUE(int32_t) queue = test_queue_create(1024, 2048, NULL, NULL, (void*)0x4242); - test_queue_push(queue, 42); - test_queue_push(queue, 42); - - STRICT_EXPECTED_CALL(interlocked_decrement(IGNORED_ARG)); - STRICT_EXPECTED_CALL(srw_lock_ll_deinit(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - TQUEUE_ASSIGN(int32_t)(&queue, NULL); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); -} - -/* Tests_SRS_TQUEUE_01_009: [ Otherwise, TQUEUE_DISPOSE_FUNC(T) shall obtain the current queue head by calling interlocked_add_64. ]*/ -/* Tests_SRS_TQUEUE_01_010: [ TQUEUE_DISPOSE_FUNC(T) shall obtain the current queue tail by calling interlocked_add_64. ]*/ -/* Tests_SRS_TQUEUE_01_011: [ For each item in the queue, dispose_item_function shall be called with dispose_item_function_context and a pointer to the array entry value (T*). ]*/ -/* Tests_SRS_TQUEUE_01_056: [ The lock initialized in TQUEUE_CREATE(T) shall be de-initialized. ] */ -/* Tests_SRS_TQUEUE_01_057: [ The array backing the queue shall be freed. ] */ -TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_for_a_queue_that_was_grown_frees_resources) -{ - // arrange - TQUEUE(int32_t) queue = test_queue_create(1, 2048, test_copy_item, test_dispose_item, (void*)0x4242); + TQUEUE(int32_t) queue = test_queue_create(initial_queue_size, max_queue_size, test_copy_item, test_dispose_item, (void*)0x4242); test_queue_push(queue, 42); test_queue_push(queue, 42); @@ -449,10 +376,13 @@ TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_for_a_queue_that_was_grown_frees_resources) /* Tests_SRS_TQUEUE_01_056: [ The lock initialized in TQUEUE_CREATE(T) shall be de-initialized. ] */ /* Tests_SRS_TQUEUE_01_057: [ The array backing the queue shall be freed. ] */ -TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_for_a_queue_that_was_grown__with_NULL_copy_and_dispose_function_frees_resources) +PARAMETERIZED_TEST_FUNCTION(TQUEUE_DISPOSE_FUNC_with_NULL_copy_and_dispose_function_frees_resources, + ARGS(uint32_t, initial_queue_size, uint32_t, max_queue_size), + CASE((1024, 2048), max_size_bigger_than_initial_size), + CASE((1, 2048), queue_that_was_grown)) { // arrange - TQUEUE(int32_t) queue = test_queue_create(1, 2048, NULL, NULL, (void*)0x4242); + TQUEUE(int32_t) queue = test_queue_create(initial_queue_size, max_queue_size, NULL, NULL, (void*)0x4242); test_queue_push(queue, 42); test_queue_push(queue, 42); @@ -607,7 +537,12 @@ TEST_FUNCTION(TQUEUE_PUSH_twice_for_queue_size_1_returns_QUEUE_FULL) TQUEUE_ASSIGN(int32_t)(&queue, NULL); } -static void test_TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_again(QUEUE_ENTRY_STATE queue_entry_state) +/* Tests_SRS_TQUEUE_01_023: [ If the state of the array entry corresponding to the head is not NOT_USED, TQUEUE_PUSH(T) shall retry the whole push. ]*/ +PARAMETERIZED_TEST_FUNCTION(TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_again, + ARGS(QUEUE_ENTRY_STATE, queue_entry_state), + CASE((QUEUE_ENTRY_STATE_PUSHING), PUSHING), + CASE((QUEUE_ENTRY_STATE_POPPING), POPPING), + CASE((QUEUE_ENTRY_STATE_USED), USED)) { // arrange int32_t item = 42; @@ -644,24 +579,6 @@ static void test_TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_a TQUEUE_ASSIGN(int32_t)(&queue, NULL); } -/* Tests_SRS_TQUEUE_01_023: [ If the state of the array entry corresponding to the head is not NOT_USED, TQUEUE_PUSH(T) shall retry the whole push. ]*/ -TEST_FUNCTION(TQUEUE_PUSH_when_entry_state_is_PUSHING_tries_again) -{ - test_TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_again(QUEUE_ENTRY_STATE_PUSHING); -} - -/* Tests_SRS_TQUEUE_01_023: [ If the state of the array entry corresponding to the head is not NOT_USED, TQUEUE_PUSH(T) shall retry the whole push. ]*/ -TEST_FUNCTION(TQUEUE_PUSH_when_entry_state_is_POPPING_tries_again) -{ - test_TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_again(QUEUE_ENTRY_STATE_POPPING); -} - -/* Tests_SRS_TQUEUE_01_023: [ If the state of the array entry corresponding to the head is not NOT_USED, TQUEUE_PUSH(T) shall retry the whole push. ]*/ -TEST_FUNCTION(TQUEUE_PUSH_when_entry_state_is_USED_tries_again) -{ - test_TQUEUE_PUSH_when_entry_state_is_different_than_NOT_USED_tries_again(QUEUE_ENTRY_STATE_USED); -} - /* Tests_SRS_TQUEUE_01_043: [ If the queue head has changed, TQUEUE_PUSH(T) shall set the state back to NOT_USED and retry the push. ]*/ TEST_FUNCTION(when_head_changes_TQUEUE_PUSH_tries_again) { @@ -1214,7 +1131,12 @@ TEST_FUNCTION(TQUEUE_POP_when_queue_is_empty_after_a_push_and_a_pop_and_queue_si TQUEUE_ASSIGN(int32_t)(&queue, NULL); } -static void test_TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again(QUEUE_ENTRY_STATE queue_entry_state) +/* Tests_SRS_TQUEUE_01_036: [ If the state of the array entry corresponding to the tail is not USED, TQUEUE_POP(T) shall try again. ]*/ +PARAMETERIZED_TEST_FUNCTION(TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again, + ARGS(QUEUE_ENTRY_STATE, queue_entry_state), + CASE((QUEUE_ENTRY_STATE_PUSHING), PUSHING), + CASE((QUEUE_ENTRY_STATE_POPPING), POPPING), + CASE((QUEUE_ENTRY_STATE_NOT_USED), NOT_USED)) { // arrange int32_t item = 45; @@ -1246,24 +1168,6 @@ static void test_TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again( TQUEUE_ASSIGN(int32_t)(&queue, NULL); } -/* Tests_SRS_TQUEUE_01_036: [ If the state of the array entry corresponding to the tail is not USED, TQUEUE_POP(T) shall try again. ]*/ -TEST_FUNCTION(TQUEUE_POP_when_entry_state_is_PUSHING_tries_again) -{ - test_TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again(QUEUE_ENTRY_STATE_PUSHING); -} - -/* Tests_SRS_TQUEUE_01_036: [ If the state of the array entry corresponding to the tail is not USED, TQUEUE_POP(T) shall try again. ]*/ -TEST_FUNCTION(TQUEUE_POP_when_entry_state_is_POPPING_tries_again) -{ - test_TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again(QUEUE_ENTRY_STATE_POPPING); -} - -/* Tests_SRS_TQUEUE_01_036: [ If the state of the array entry corresponding to the tail is not USED, TQUEUE_POP(T) shall try again. ]*/ -TEST_FUNCTION(TQUEUE_POP_when_entry_state_is_NOT_USED_tries_again) -{ - test_TQUEUE_POP_when_entry_state_is_different_than_USED_tries_again(QUEUE_ENTRY_STATE_NOT_USED); -} - /* Tests_SRS_TQUEUE_01_037: [ If copy_item_function and sispose_item_function were specified in TQUEUE_CREATE(T): ]*/ /* Tests_SRS_TQUEUE_01_038: [ TQUEUE_POP(T) shall call copy_item_function with copy_item_function_context as context, the array entry value whose state was changed to POPPING to item as pop_src and item as pop_dst. ]*/ /* Tests_SRS_TQUEUE_01_045: [ TQUEUE_POP(T) shall call dispose_item_function with dispose_item_function_context as context and the array entry value whose state was changed to POPPING as item. ]*/ diff --git a/deps/c-testrunnerswitcher b/deps/c-testrunnerswitcher index a62e7067..48b0066e 160000 --- a/deps/c-testrunnerswitcher +++ b/deps/c-testrunnerswitcher @@ -1 +1 @@ -Subproject commit a62e7067882f11addd52aee5c569d2cdfb9eddaf +Subproject commit 48b0066eef2dd726ba0ea48189923060aacfb449 diff --git a/deps/umock-c b/deps/umock-c index e051923e..b1803d97 160000 --- a/deps/umock-c +++ b/deps/umock-c @@ -1 +1 @@ -Subproject commit e051923ef27c842d2b22417c702a933e9d7f8388 +Subproject commit b1803d9775c4474af4ee1a7526387d27654ae7cf diff --git a/linux/tests/async_socket_linux_ut/async_socket_linux_ut.c b/linux/tests/async_socket_linux_ut/async_socket_linux_ut.c index 752a1d4f..d274750a 100644 --- a/linux/tests/async_socket_linux_ut/async_socket_linux_ut.c +++ b/linux/tests/async_socket_linux_ut/async_socket_linux_ut.c @@ -1856,204 +1856,34 @@ TEST_FUNCTION(event_complete_func_recv_returns_0_bytes_success) } // Tests_SRS_ASYNC_SOCKET_LINUX_04_008: [ event_complete_callback shall call the notify complete callback with an ABANDONED flag when the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_IN_EPOLLRDHUP_and_abandons_the_connection) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_EPOLLRDHUP); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - -// Tests_SRS_ASYNC_SOCKET_LINUX_04_008: [ event_complete_callback shall call the notify complete callback with an ABANDONED flag when the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_IN_ABANDONED_and_abandons_the_connection) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_ABANDONED); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - -// Tests_SRS_ASYNC_SOCKET_LINUX_04_008: [ event_complete_callback shall call the notify complete callback with an ABANDONED flag when the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_OUT_EPOLLRDHUP_and_abandons_the_connection) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_EPOLLRDHUP); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - -// Tests_SRS_ASYNC_SOCKET_LINUX_04_008: [ event_complete_callback shall call the notify complete callback with an ABANDONED flag when the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_OUT_ABANDONED_and_abandons_the_connection) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_ABANDONED); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - // Tests_SRS_ASYNC_SOCKET_LINUX_04_009: [ If the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY then event_complete_callback shall call the notify complete callback with an IN flag. ] -TEST_FUNCTION(event_complete_func_notify_EPOLLIN_calls_callback_with_IN_flag) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_IN)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_EPOLLIN); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - // Tests_SRS_ASYNC_SOCKET_LINUX_04_010: [ If the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY then event_complete_callback shall call the notify complete callback with an OUT flag. ] -TEST_FUNCTION(event_complete_func_notify_EPOLLOUT_calls_callback_with_OUT_flag) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_OUT)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_EPOLLOUT); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - // Tests_SRS_ASYNC_SOCKET_LINUX_04_011: [ If the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY then event_complete_callback shall call the notify complete callback with an ERROR flag. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_IN_ERROR_calls_callback_with_ERROR_flag) +PARAMETERIZED_TEST_FUNCTION(event_complete_func_notify_calls_callback_with_expected_result, + ARGS(ASYNC_SOCKET_NOTIFY_IO_TYPE, io_type, COMPLETION_PORT_EPOLL_ACTION, epoll_action, ASYNC_SOCKET_NOTIFY_IO_RESULT, expected_result), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, COMPLETION_PORT_EPOLL_EPOLLRDHUP, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED), IN_EPOLLRDHUP_abandons), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, COMPLETION_PORT_EPOLL_ABANDONED, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED), IN_ABANDONED_abandons), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, COMPLETION_PORT_EPOLL_EPOLLRDHUP, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED), OUT_EPOLLRDHUP_abandons), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, COMPLETION_PORT_EPOLL_ABANDONED, ASYNC_SOCKET_NOTIFY_IO_RESULT_ABANDONED), OUT_ABANDONED_abandons), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, COMPLETION_PORT_EPOLL_EPOLLIN, ASYNC_SOCKET_NOTIFY_IO_RESULT_IN), IN_EPOLLIN), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, COMPLETION_PORT_EPOLL_EPOLLOUT, ASYNC_SOCKET_NOTIFY_IO_RESULT_OUT), OUT_EPOLLOUT), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, COMPLETION_PORT_EPOLL_ERROR, ASYNC_SOCKET_NOTIFY_IO_RESULT_ERROR), IN_ERROR), + CASE((ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, COMPLETION_PORT_EPOLL_ERROR, ASYNC_SOCKET_NOTIFY_IO_RESULT_ERROR), OUT_ERROR)) { // arrange ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); ASSERT_IS_NOT_NULL(async_socket); ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_IN, test_on_notify_complete, test_callback_ctx)); + ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, io_type, test_on_notify_complete, test_callback_ctx)); umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ERROR)); + STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, expected_result)); STRICT_EXPECTED_CALL(free(IGNORED_ARG)); // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_ERROR); - - // assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - async_socket_close(async_socket); - async_socket_destroy(async_socket); -} - -// Tests_SRS_ASYNC_SOCKET_LINUX_04_011: [ If the IO type is ASYNC_SOCKET_IO_TYPE_NOTIFY then event_complete_callback shall call the notify complete callback with an ERROR flag. ] -TEST_FUNCTION(event_complete_func_notify_for_io_type_OUT_ERROR_calls_callback_with_ERROR_flag) -{ - // arrange - ASYNC_SOCKET_HANDLE async_socket = async_socket_create(test_execution_engine); - ASSERT_IS_NOT_NULL(async_socket); - ASSERT_ARE_EQUAL(int, 0, async_socket_open_async(async_socket, test_socket, test_on_open_complete, test_callback_ctx)); - - ASSERT_ARE_EQUAL(int, 0, async_socket_notify_io_async(async_socket, ASYNC_SOCKET_NOTIFY_IO_TYPE_OUT, test_on_notify_complete, test_callback_ctx)); - - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(test_on_notify_complete(test_callback_ctx, ASYNC_SOCKET_NOTIFY_IO_RESULT_ERROR)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - // act - g_event_callback(g_event_callback_ctx, COMPLETION_PORT_EPOLL_ERROR); + g_event_callback(g_event_callback_ctx, epoll_action); // assert ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); diff --git a/win32/tests/file_win32_ut/file_win32_ut.c b/win32/tests/file_win32_ut/file_win32_ut.c index d60e0889..69381edc 100644 --- a/win32/tests/file_win32_ut/file_win32_ut.c +++ b/win32/tests/file_win32_ut/file_win32_ut.c @@ -806,171 +806,33 @@ TEST_FUNCTION(file_extend_returns_zero) /*Tests_SRS_FILE_WIN32_43_034: [ on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped. ]*/ /*Tests_SRS_FILE_WIN32_43_066: [ on_file_io_complete_win32 shall call user_callback with is_successful as true if and only if io_result is equal to NO_ERROR and number_of_bytes_transferred is equal to the number of bytes requested by the user. ]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_successfully_for_write) -{ - ///arrange - unsigned char source[10]; - uint64_t position = 11; - void* user_context = (void*)20; - - PTP_WIN32_IO_CALLBACK captured_callback = NULL; - LPOVERLAPPED captured_ov; - - FILE_HANDLE file_handle = start_file_io_async(FILE_WRITE_ASYNC, source, sizeof(source), position, mock_user_callback, user_context, &captured_callback, &captured_ov); - - STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(mock_user_callback(user_context, true)); - ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); - - ///act - captured_callback(NULL, NULL, captured_ov, NO_ERROR, sizeof(source), NULL); - - ///assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - ///cleanup - file_destroy(file_handle); -} - -/*Tests_SRS_FILE_WIN32_43_034: [ on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped. ]*/ /*Tests_SRS_FILE_WIN32_43_068: [ If either io_result is not equal to NO_ERROR or number_of_bytes_transferred is not equal to the bytes requested by the user, on_file_io_complete_win32 shall return false. ]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_unsuccessfully_for_write_because_io_failed) +PARAMETERIZED_TEST_FUNCTION(on_file_io_complete_win32_calls_callback, + ARGS(FILE_IO_ASYNC_TYPE, io_type, ULONG, io_result, ULONG_PTR, num_bytes_transferred, bool, expected_success), + CASE((FILE_WRITE_ASYNC, NO_ERROR, 10, true), write_success), + CASE((FILE_WRITE_ASYNC, ERROR_IO_INCOMPLETE, 10, false), write_io_failed), + CASE((FILE_WRITE_ASYNC, NO_ERROR, 9, false), write_num_bytes_less), + CASE((FILE_READ_ASYNC, NO_ERROR, 10, true), read_success), + CASE((FILE_READ_ASYNC, ERROR_IO_INCOMPLETE, 10, false), read_io_failed), + CASE((FILE_READ_ASYNC, NO_ERROR, 9, false), read_num_bytes_less)) { ///arrange - unsigned char source[10]; - uint64_t position = 11; - void* user_context = (void*)20; - - PTP_WIN32_IO_CALLBACK captured_callback = NULL; - LPOVERLAPPED captured_ov; - - FILE_HANDLE file_handle = start_file_io_async(FILE_WRITE_ASYNC, source, sizeof(source), position, mock_user_callback, user_context, &captured_callback, &captured_ov); - - STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - - STRICT_EXPECTED_CALL(mock_user_callback(user_context, false)); - ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); - - ///act - captured_callback(NULL, NULL, captured_ov, ERROR_IO_INCOMPLETE, sizeof(source), NULL); - - ///assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - ///cleanup - file_destroy(file_handle); -} - -/*Tests_SRS_FILE_WIN32_43_034: [on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped.]*/ -/*Tests_SRS_FILE_WIN32_43_068 : [If either io_result is not equal to NO_ERROR or number_of_bytes_transferred is not equal to the bytes requested by the user, on_file_io_complete_win32 shall return false.]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_unsuccessfully_for_write_because_num_bytes_is_less) -{ - ///arrange - unsigned char source[10]; - uint64_t position = 11; - void* user_context = (void*)20; - - PTP_WIN32_IO_CALLBACK captured_callback = NULL; - LPOVERLAPPED captured_ov; - - FILE_HANDLE file_handle = start_file_io_async(FILE_WRITE_ASYNC, source, sizeof(source), position, mock_user_callback, user_context, &captured_callback, &captured_ov); - - STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(mock_user_callback(user_context, false)); - ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); - - ///act - captured_callback(NULL, NULL, captured_ov, NO_ERROR, sizeof(source)-1, NULL); - - ///assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - ///cleanup - file_destroy(file_handle); -} - -/*Tests_SRS_FILE_WIN32_43_034: [ on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped. ]*/ -/*Tests_SRS_FILE_WIN32_43_066: [ on_file_io_complete_win32 shall call user_callback with is_successful as true if and only if io_result is equal to NO_ERROR and number_of_bytes_transferred is equal to the number of bytes requested by the user. ]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_successfully_for_read) -{ - ///arrange - unsigned char destination[10]; - uint64_t position = 11; - void* user_context = (void*)20; - - PTP_WIN32_IO_CALLBACK captured_callback = NULL; - LPOVERLAPPED captured_ov; - - FILE_HANDLE file_handle = start_file_io_async(FILE_READ_ASYNC, destination, sizeof(destination), position, mock_user_callback, user_context, &captured_callback, &captured_ov); - - STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(mock_user_callback(user_context, true)); - ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); - - ///act - captured_callback(NULL, NULL, captured_ov, NO_ERROR, sizeof(destination), NULL); - - ///assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - ///cleanup - file_destroy(file_handle); -} - -/*Tests_SRS_FILE_WIN32_43_034: [ on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped. ]*/ -/*Tests_SRS_FILE_WIN32_43_068: [ If either io_result is not equal to NO_ERROR or number_of_bytes_transferred is not equal to the bytes requested by the user, on_file_io_complete_win32 shall return false. ]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_unsuccessfully_for_read_because_io_failed) -{ - ///arrange - unsigned char destination[10]; - uint64_t position = 11; - void* user_context = (void*)20; - - PTP_WIN32_IO_CALLBACK captured_callback = NULL; - LPOVERLAPPED captured_ov; - - FILE_HANDLE file_handle = start_file_io_async(FILE_READ_ASYNC, destination, sizeof(destination), position, mock_user_callback, user_context, &captured_callback, &captured_ov); - - STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(mock_user_callback(user_context, false)); - ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); - - ///act - captured_callback(NULL, NULL, captured_ov, ERROR_IO_INCOMPLETE, sizeof(destination), NULL); - - ///assert - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - ///cleanup - file_destroy(file_handle); -} - -/*Tests_SRS_FILE_WIN32_43_034: [on_file_io_complete_win32 shall recover the file handle, the number of bytes requested by the user, user_callback and user_context from the context containing overlapped.]*/ -/*Tests_SRS_FILE_WIN32_43_068 : [If either io_result is not equal to NO_ERROR or number_of_bytes_transferred is not equal to the bytes requested by the user, on_file_io_complete_win32 shall return false.]*/ -TEST_FUNCTION(on_file_io_complete_win32_calls_callback_unsuccessfully_for_read_because_num_bytes_is_less) -{ - ///arrange - unsigned char destination[10]; + unsigned char buffer[10]; uint64_t position = 11; void* user_context = (void*)20; PTP_WIN32_IO_CALLBACK captured_callback = NULL; LPOVERLAPPED captured_ov; - FILE_HANDLE file_handle = start_file_io_async(FILE_READ_ASYNC, destination, sizeof(destination), position, mock_user_callback, user_context, &captured_callback, &captured_ov); + FILE_HANDLE file_handle = start_file_io_async(io_type, buffer, sizeof(buffer), position, mock_user_callback, user_context, &captured_callback, &captured_ov); STRICT_EXPECTED_CALL(mock_CloseHandle(IGNORED_ARG)); STRICT_EXPECTED_CALL(free(IGNORED_ARG)); - STRICT_EXPECTED_CALL(mock_user_callback(user_context, false)); + STRICT_EXPECTED_CALL(mock_user_callback(user_context, expected_success)); ASSERT_ARE_EQUAL(uint64_t, position, captured_ov->Offset); ///act - captured_callback(NULL, NULL, captured_ov, NO_ERROR, sizeof(destination) -1, NULL); + captured_callback(NULL, NULL, captured_ov, io_result, num_bytes_transferred, NULL); ///assert ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); diff --git a/win32/tests/gballoc_hl_metrics_ut/gballoc_hl_metrics_ut.c b/win32/tests/gballoc_hl_metrics_ut/gballoc_hl_metrics_ut.c index 4cad2bb8..b8d7fb0b 100644 --- a/win32/tests/gballoc_hl_metrics_ut/gballoc_hl_metrics_ut.c +++ b/win32/tests/gballoc_hl_metrics_ut/gballoc_hl_metrics_ut.c @@ -191,52 +191,11 @@ TEST_FUNCTION(gballoc_hl_deinit_when_not_initialized_returns) /* Tests_SRS_GBALLOC_HL_METRICS_01_044: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc shall store it as the new minimum malloc latency. ]*/ /* Tests_SRS_GBALLOC_HL_METRICS_01_045: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc shall store it as the new maximum malloc latency. ]*/ /* Tests_SRS_GBALLOC_HL_METRICS_01_042: [ gballoc_hl_malloc shall increment the count of malloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_malloc_calls_gballoc_ll_malloc_and_returns_the_result) -{ - // arrange - void* result; - void* gballoc_ll_malloc_result; - STRICT_EXPECTED_CALL(gballoc_ll_init(NULL)); - (void)gballoc_hl_init(NULL, NULL); - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(5); - STRICT_EXPECTED_CALL(gballoc_ll_malloc(42)) - .CaptureReturn(&gballoc_ll_malloc_result); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(7); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 2)); - // min - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 2, IGNORED_ARG)); - // max - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 2, IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); - - // act - result = gballoc_hl_malloc(42); - - // assert - ASSERT_IS_NOT_NULL(result); - ASSERT_ARE_EQUAL(void_ptr, result, gballoc_ll_malloc_result); - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - gballoc_hl_free(result); - gballoc_hl_deinit(); -} - -/* Tests_SRS_GBALLOC_HL_METRICS_01_028: [ gballoc_hl_malloc shall call timer_global_get_elapsed_us to obtain the start time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_007: [ gballoc_hl_malloc shall call gballoc_ll_malloc(size) and return the result of gballoc_ll_malloc. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_029: [ gballoc_hl_malloc shall call timer_global_get_elapsed_us to obtain the end time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_043: [ gballoc_hl_malloc shall add the computed latency to the running malloc latency sum used to compute the average. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_044: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc shall store it as the new minimum malloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_045: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc shall store it as the new maximum malloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_042: [ gballoc_hl_malloc shall increment the count of malloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_malloc_with_1_byte_calls_gballoc_ll_malloc_and_returns_the_result) +PARAMETERIZED_TEST_FUNCTION(gballoc_hl_malloc_calls_gballoc_ll_malloc_and_returns_the_result, + ARGS(size_t, alloc_size, double, timer_start_value, double, timer_end_value, int32_t, expected_latency), + CASE((42, 5, 7, 2), with_42_bytes), + CASE((1, 1, 8, 7), with_1_byte), + CASE((0, 1, 8, 7), with_0_bytes)) { // arrange void* result; @@ -247,67 +206,22 @@ TEST_FUNCTION(gballoc_hl_malloc_with_1_byte_calls_gballoc_ll_malloc_and_returns_ STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(1); - STRICT_EXPECTED_CALL(gballoc_ll_malloc(1)) + .SetReturn(timer_start_value); + STRICT_EXPECTED_CALL(gballoc_ll_malloc(alloc_size)) .CaptureReturn(&gballoc_ll_result); STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(8); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 7)); + .SetReturn(timer_end_value); + STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, expected_latency)); // min STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); + STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, expected_latency, IGNORED_ARG)); // max STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); + STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, expected_latency, IGNORED_ARG)); STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); // act - result = gballoc_hl_malloc(1); - - // assert - ASSERT_IS_NOT_NULL(result); - ASSERT_ARE_EQUAL(void_ptr, result, gballoc_ll_result); - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - gballoc_hl_free(result); - gballoc_hl_deinit(); -} - -/* Tests_SRS_GBALLOC_HL_METRICS_01_028: [ gballoc_hl_malloc shall call timer_global_get_elapsed_us to obtain the start time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_007: [ gballoc_hl_malloc shall call gballoc_ll_malloc(size) and return the result of gballoc_ll_malloc. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_029: [ gballoc_hl_malloc shall call timer_global_get_elapsed_us to obtain the end time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_043: [ gballoc_hl_malloc shall add the computed latency to the running malloc latency sum used to compute the average. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_044: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc shall store it as the new minimum malloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_045: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc shall store it as the new maximum malloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_042: [ gballoc_hl_malloc shall increment the count of malloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_malloc_with_0_bytes_calls_gballoc_ll_malloc_and_returns_the_result) -{ - // arrange - void* result; - void* gballoc_ll_result; - STRICT_EXPECTED_CALL(gballoc_ll_init(NULL)); - (void)gballoc_hl_init(NULL, NULL); - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(1); - STRICT_EXPECTED_CALL(gballoc_ll_malloc(0)) - .CaptureReturn(&gballoc_ll_result); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(8); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 7)); - // min - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - // max - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); - - // act - result = gballoc_hl_malloc(0); + result = gballoc_hl_malloc(alloc_size); // assert ASSERT_IS_NOT_NULL(result); @@ -825,97 +739,11 @@ TEST_FUNCTION(gballoc_hl_calloc_when_not_initialized_fails) /* Tests_SRS_GBALLOC_HL_METRICS_01_059: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc shall store it as the new minimum realloc latency. ]*/ /* Tests_SRS_GBALLOC_HL_METRICS_01_060: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc shall store it as the new maximum realloc latency. ]*/ /* Tests_SRS_GBALLOC_HL_METRICS_01_061: [ gballoc_hl_realloc shall increment the count of realloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_realloc_with_NULL_calls_gballoc_ll_realloc_and_returns_the_result) -{ - // arrange - void* result; - void* gballoc_ll_result; - STRICT_EXPECTED_CALL(gballoc_ll_init(NULL)); - (void)gballoc_hl_init(NULL, NULL); - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(1); - STRICT_EXPECTED_CALL(gballoc_ll_realloc(NULL, 42)) - .CaptureReturn(&gballoc_ll_result); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(8); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 7)); - // min - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - // max - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); - - // act - result = gballoc_hl_realloc(NULL, 42); - - // assert - ASSERT_IS_NOT_NULL(result); - ASSERT_ARE_EQUAL(void_ptr, result, gballoc_ll_result); - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - gballoc_hl_free(result); - gballoc_hl_deinit(); -} - -/* Tests_SRS_GBALLOC_HL_METRICS_01_032: [ gballoc_hl_realloc shall call timer_global_get_elapsed_us to obtain the start time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_013: [ gballoc_hl_realloc shall call gballoc_ll_realloc(ptr, size) and return the result of gballoc_ll_realloc ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_033: [ gballoc_hl_realloc shall call timer_global_get_elapsed_us to obtain the end time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_058: [ gballoc_hl_realloc shall add the computed latency to the running realloc latency sum used to compute the average. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_059: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc shall store it as the new minimum realloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_060: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc shall store it as the new maximum realloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_061: [ gballoc_hl_realloc shall increment the count of realloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_realloc_with_1_byte_size_with_NULL_ptr_calls_gballoc_ll_realloc_and_returns_the_result) -{ - // arrange - void* result; - void* gballoc_ll_result; - STRICT_EXPECTED_CALL(gballoc_ll_init(NULL)); - (void)gballoc_hl_init(NULL, NULL); - umock_c_reset_all_calls(); - - STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(1); - STRICT_EXPECTED_CALL(gballoc_ll_realloc(NULL, 1)) - .CaptureReturn(&gballoc_ll_result); - STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) - .SetReturn(8); - STRICT_EXPECTED_CALL(interlocked_add_64(IGNORED_ARG, 7)); - // min - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - // max - STRICT_EXPECTED_CALL(interlocked_add(IGNORED_ARG, 0)); - STRICT_EXPECTED_CALL(interlocked_compare_exchange(IGNORED_ARG, 7, IGNORED_ARG)); - STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); - - // act - result = gballoc_hl_realloc(NULL, 1); - - // assert - ASSERT_IS_NOT_NULL(result); - ASSERT_ARE_EQUAL(void_ptr, result, gballoc_ll_result); - ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); - - // cleanup - gballoc_hl_free(result); - gballoc_hl_deinit(); -} - -/* Tests_SRS_GBALLOC_HL_METRICS_01_032: [ gballoc_hl_realloc shall call timer_global_get_elapsed_us to obtain the start time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_013: [ gballoc_hl_realloc shall call gballoc_ll_realloc(ptr, size) and return the result of gballoc_ll_realloc ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_033: [ gballoc_hl_realloc shall call timer_global_get_elapsed_us to obtain the end time of the allocate. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_058: [ gballoc_hl_realloc shall add the computed latency to the running realloc latency sum used to compute the average. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_059: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc shall store it as the new minimum realloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_060: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc shall store it as the new maximum realloc latency. ]*/ -/* Tests_SRS_GBALLOC_HL_METRICS_01_061: [ gballoc_hl_realloc shall increment the count of realloc latency samples. ]*/ -TEST_FUNCTION(gballoc_hl_realloc_with_0_bytes_size_with_NULL_ptr_calls_gballoc_ll_realloc_and_returns_the_result) +PARAMETERIZED_TEST_FUNCTION(gballoc_hl_realloc_with_NULL_calls_gballoc_ll_realloc_and_returns_the_result, + ARGS(size_t, alloc_size), + CASE((42), with_42_bytes), + CASE((1), with_1_byte), + CASE((0), with_0_bytes)) { // arrange void* result; @@ -927,7 +755,7 @@ TEST_FUNCTION(gballoc_hl_realloc_with_0_bytes_size_with_NULL_ptr_calls_gballoc_l STRICT_EXPECTED_CALL(lazy_init(IGNORED_ARG, IGNORED_ARG, NULL)); STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) .SetReturn(1); - STRICT_EXPECTED_CALL(gballoc_ll_realloc(NULL, 0)) + STRICT_EXPECTED_CALL(gballoc_ll_realloc(NULL, alloc_size)) .CaptureReturn(&gballoc_ll_result); STRICT_EXPECTED_CALL(timer_global_get_elapsed_us()) .SetReturn(8); @@ -941,7 +769,7 @@ TEST_FUNCTION(gballoc_hl_realloc_with_0_bytes_size_with_NULL_ptr_calls_gballoc_l STRICT_EXPECTED_CALL(interlocked_increment(IGNORED_ARG)); // act - result = gballoc_hl_realloc(NULL, 0); + result = gballoc_hl_realloc(NULL, alloc_size); // assert ASSERT_IS_NOT_NULL(result);