From 4dc906aa53f82454d78b0f317e0b13f620fc97c9 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 11 Jun 2018 21:50:36 +0200 Subject: [PATCH] ucrtbase: Add quick_exit tests To: wine-devel --- dlls/ucrtbase/tests/misc.c | 83 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 354fab1e94..230999eeff 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -125,6 +125,10 @@ static int (CDECL *p_fesetround)(int); static void (CDECL *p___setusermatherr)(MSVCRT_matherr_func); static int* (CDECL *p_errno)(void); static char* (CDECL *p_asctime)(const struct tm *); +static int (CDECL *p__crt_at_quick_exit)(void (CDECL*)(void)); +static void (CDECL *p_quick_exit)(int); +static int (CDECL *p__crt_atexit)(void (CDECL*)(void)); +static void (CDECL *p_exit)(int); static void test__initialize_onexit_table(void) { @@ -429,6 +433,10 @@ static BOOL init(void) p___setusermatherr = (void*)GetProcAddress(module, "__setusermatherr"); p_errno = (void*)GetProcAddress(module, "_errno"); p_asctime = (void*)GetProcAddress(module, "asctime"); + p__crt_at_quick_exit = (void*)GetProcAddress(module, "_crt_at_quick_exit"); + p_quick_exit = (void*)GetProcAddress(module, "quick_exit"); + p__crt_atexit = (void*)GetProcAddress(module, "_crt_atexit"); + p_exit = (void*)GetProcAddress(module, "exit"); return TRUE; } @@ -765,6 +773,73 @@ static void test_asctime(void) ok(!strcmp(ret, "Thu Jan 1 00:00:00 1970\n"), "asctime returned %s\n", ret); } +static void test_quick_exit(const char *argv0) +{ + HANDLE quick_exit_event, exit_event; + PROCESS_INFORMATION proc; + STARTUPINFOA startup; + char path[MAX_PATH]; + DWORD ret; + + quick_exit_event = CreateEventA(NULL, FALSE, FALSE, "quick_exit_event"); + exit_event = CreateEventA(NULL, FALSE, FALSE, "exit_event"); + + sprintf(path, "%s misc quick_exit", argv0); + memset(&startup, 0, sizeof(startup)); + startup.cb = sizeof(startup); + CreateProcessA(NULL, path, NULL, NULL, TRUE, + 0, NULL, NULL, &startup, &proc); + winetest_wait_child_process(proc.hProcess); + ret = WaitForSingleObject(quick_exit_event, 0); + ok(ret == WAIT_OBJECT_0, "quick_exit_event was not set (%x)\n", ret); + ret = WaitForSingleObject(exit_event, 0); + ok(ret == WAIT_TIMEOUT, "exit_event should not be set (%x)\n", ret); + + sprintf(path, "%s misc exit", argv0); + memset(&startup, 0, sizeof(startup)); + startup.cb = sizeof(startup); + CreateProcessA(NULL, path, NULL, NULL, TRUE, + 0, NULL, NULL, &startup, &proc); + winetest_wait_child_process(proc.hProcess); + ret = WaitForSingleObject(quick_exit_event, 0); + ok(ret == WAIT_TIMEOUT, "quick_exit_event should not be set (%x)\n", ret); + ret = WaitForSingleObject(exit_event, 0); + ok(ret == WAIT_OBJECT_0, "exit_event was not set (%x)\n", ret); + + CloseHandle(quick_exit_event); + CloseHandle(exit_event); +} + +static void CDECL at_quick_exit_func(void) +{ + HANDLE quick_exit_event = CreateEventA(NULL, FALSE, FALSE, "quick_exit_event"); + ok(quick_exit_event != NULL, "CreateEvent failed: %d\n", GetLastError()); + SetEvent(quick_exit_event); + CloseHandle(quick_exit_event); +} + +static void CDECL at_exit_func(void) +{ + HANDLE exit_event = CreateEventA(NULL, FALSE, FALSE, "exit_event"); + ok(exit_event != NULL, "CreateEvent failed: %d\n", GetLastError()); + SetEvent(exit_event); + CloseHandle(exit_event); +} + +static void test_call_quick_exit(void) +{ + ok(!p__crt_at_quick_exit(at_quick_exit_func), "_crt_at_quick_exit failed\n"); + ok(!p__crt_atexit(at_exit_func), "_crt_atexit failed\n"); + p_quick_exit(0); +} + +static void test_call_exit(void) +{ + ok(!p__crt_at_quick_exit(at_quick_exit_func), "_crt_at_quick_exit failed\n"); + ok(!p__crt_atexit(at_exit_func), "_crt_atexit failed\n"); + p_exit(0); +} + START_TEST(misc) { int arg_c; @@ -775,7 +850,12 @@ START_TEST(misc) arg_c = winetest_get_mainargs(&arg_v); if(arg_c == 3) { - test__get_narrow_winmain_command_line(NULL); + if(!strcmp(arg_v[2], "cmd")) + test__get_narrow_winmain_command_line(NULL); + else if(!strcmp(arg_v[2], "quick_exit")) + test_call_quick_exit(); + else if(!strcmp(arg_v[2], "exit")) + test_call_exit(); return; } @@ -791,4 +871,5 @@ START_TEST(misc) test_isblank(); test_math_errors(); test_asctime(); + test_quick_exit(arg_v[0]); } -- 2.16.4