Currently there are several places that test APC but they use duplicated/similar `apc_func()` so merge all those into single implementation.
From: Dāvis Mosāns davispuh@gmail.com
This reduces duplication since they all do same thing --- dlls/ntdll/tests/exception.c | 75 ++++++++++-------------------------- 1 file changed, 20 insertions(+), 55 deletions(-)
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c index b6d22092a11..c09d54c1445 100644 --- a/dlls/ntdll/tests/exception.c +++ b/dlls/ntdll/tests/exception.c @@ -109,6 +109,16 @@ static void (WINAPI *pRtlGetUnloadEventTraceEx)(ULONG **element_size, ULONG **el #define EH_NESTED_CALL 0x10 #endif
+static UINT apc_count; + +static void CALLBACK apc_func( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) +{ + ok( arg1 == 0x1234 + apc_count, "wrong arg1 %Ix\n", arg1 ); + ok( arg2 == 0x5678, "wrong arg2 %Ix\n", arg2 ); + ok( arg3 == 0xdeadbeef, "wrong arg3 %Ix\n", arg3 ); + apc_count++; +} + #if defined(__x86_64__) typedef struct { @@ -2071,15 +2081,6 @@ static void test_KiUserExceptionDispatcher(void) }
static BYTE saved_KiUserApcDispatcher[7]; -static UINT apc_count; - -static void CALLBACK apc_func( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) -{ - ok( arg1 == 0x1234 + apc_count, "wrong arg1 %Ix\n", arg1 ); - ok( arg2 == 0x5678, "wrong arg2 %Ix\n", arg2 ); - ok( arg3 == 0xdeadbeef, "wrong arg3 %Ix\n", arg3 ); - apc_count++; -}
static void * CDECL hook_KiUserApcDispatcher( void *func, ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) { @@ -2158,7 +2159,7 @@ static void test_KiUserApcDispatcher(void)
apc_count = 0; hook_called = FALSE; - pNtQueueApcThread( GetCurrentThread(), apc_func, 0x1234, 0x5678, 0xdeadbeef ); + pNtQueueApcThread( GetCurrentThread(), apc_func, 0x1234 + apc_count, 0x5678, 0xdeadbeef ); SleepEx( 0, TRUE ); ok( apc_count == 1 || apc_count == 2, "APC count %u\n", apc_count ); ok( hook_called, "hook was not called\n" ); @@ -5238,15 +5239,6 @@ static void test_KiUserExceptionDispatcher(void)
static BYTE saved_KiUserApcDispatcher[12]; -static BOOL apc_called; - -static void CALLBACK apc_func( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) -{ - ok( arg1 == 0x1234, "wrong arg1 %Ix\n", arg1 ); - ok( arg2 == 0x5678, "wrong arg2 %Ix\n", arg2 ); - ok( arg3 == 0xdeadbeef, "wrong arg3 %Ix\n", arg3 ); - apc_called = TRUE; -}
static void * WINAPI hook_KiUserApcDispatcher(CONTEXT *context) { @@ -5312,10 +5304,10 @@ static void test_KiUserApcDispatcher(void) memcpy( pKiUserApcDispatcher, patched_KiUserApcDispatcher, sizeof(patched_KiUserApcDispatcher) );
hook_called = FALSE; - apc_called = FALSE; - pNtQueueApcThread( GetCurrentThread(), apc_func, 0x1234, 0x5678, 0xdeadbeef ); + apc_count = 0; + pNtQueueApcThread( GetCurrentThread(), apc_func, 0x1234 + apc_count, 0x5678, 0xdeadbeef ); SleepEx( 0, TRUE ); - ok( apc_called, "APC was not called\n" ); + ok( apc_count > 0, "APC was not called\n" ); ok( hook_called, "hook was not called\n" );
VirtualProtect( pKiUserApcDispatcher, sizeof(saved_KiUserApcDispatcher), old_protect, &old_protect ); @@ -7625,17 +7617,8 @@ static void test_KiUserExceptionDispatcher(void) VirtualProtect(code_ptr, sizeof(saved_code), old_protect, &old_protect); }
-static UINT apc_count; static UINT alertable_supported;
-static void CALLBACK apc_func( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) -{ - ok( arg1 == 0x1234 + apc_count, "wrong arg1 %Ix\n", arg1 ); - ok( arg2 == 0x5678, "wrong arg2 %Ix\n", arg2 ); - ok( arg3 == 0xdeadbeef, "wrong arg3 %Ix\n", arg3 ); - apc_count++; -} - static void * WINAPI hook_KiUserApcDispatcher(void *stack) { struct @@ -9460,17 +9443,6 @@ static void test_KiUserExceptionDispatcher(void) VirtualProtect(pKiUserExceptionDispatcher, sizeof(saved_code), old_protect, &old_protect); }
- -static UINT apc_count; - -static void CALLBACK apc_func( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) -{ - ok( arg1 == 0x1234 + apc_count, "wrong arg1 %Ix\n", arg1 ); - ok( arg2 == 0x5678, "wrong arg2 %Ix\n", arg2 ); - ok( arg3 == 0xdeadbeef, "wrong arg3 %Ix\n", arg3 ); - apc_count++; -} - static void * WINAPI hook_KiUserApcDispatcher(void *stack) { struct @@ -10706,13 +10678,6 @@ static void test_vectored_continue_handler(void) ok(!ret, "RtlRemoveVectoredContinueHandler succeeded\n"); }
-static BOOL test_apc_called; - -static void CALLBACK test_apc(ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3) -{ - test_apc_called = TRUE; -} - static void test_user_apc(void) { NTSTATUS status; @@ -10775,13 +10740,13 @@ static void test_user_apc(void)
c[0] = context;
- test_apc_called = FALSE; - status = pNtQueueApcThread(GetCurrentThread(), test_apc, 0, 0, 0); + apc_count = 0; + status = pNtQueueApcThread(GetCurrentThread(), apc_func, 0x1234 + apc_count, 0x5678, 0xdeadbeef); ok(!status, "Got unexpected status %#lx.\n", status); SleepEx(0, TRUE); - ok(test_apc_called, "Test user APC was not called.\n"); - test_apc_called = FALSE; - status = pNtQueueApcThread(GetCurrentThread(), test_apc, 0, 0, 0); + ok(apc_count > 0, "Test user APC was not called.\n"); + apc_count = 0; + status = pNtQueueApcThread(GetCurrentThread(), apc_func, 0x1234 + apc_count, 0x5678, 0xdeadbeef); ok(!status, "Got unexpected status %#lx.\n", status); status = NtContinue(&c[0], TRUE );
@@ -10790,7 +10755,7 @@ static void test_user_apc(void) } ok(ret == 0xabacab, "Got return value %#x.\n", ret); ok(pass == 3, "Got unexpected pass %ld.\n", pass); - ok(test_apc_called, "Test user APC was not called.\n"); + ok(apc_count > 0, "Test user APC was not called.\n"); }
static void test_user_callback(void)
Included in !4761 and committed as 2229261f522d9e607c23231c5d37df5d03b332de.
This merge request was closed by Alexandre Julliard.