https://git.reactos.org/?p=reactos.git;a=commitdiff;h=935280bf14643b2f8d807…
commit 935280bf14643b2f8d80737efec29b148144131b
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Oct 22 15:13:56 2020 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Nov 1 09:33:14 2020 +0100
[CRT_APITEST] Add test for atexit
---
modules/rostests/apitests/crt/atexit.c | 93 ++++++++++++++++++++++
.../rostests/apitests/crt/msvcrt_crt_apitest.cmake | 2 +-
modules/rostests/apitests/crt/testlist.c | 2 +
3 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/modules/rostests/apitests/crt/atexit.c
b/modules/rostests/apitests/crt/atexit.c
new file mode 100644
index 00000000000..4a976fb4405
--- /dev/null
+++ b/modules/rostests/apitests/crt/atexit.c
@@ -0,0 +1,93 @@
+/*
+* PROJECT: ReactOS API tests
+* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
+* PURPOSE: Test for atexit
+* PROGRAMMER: Timo Kreuzer <timo.kreuzer(a)reactos.org>
+*/
+
+#include <apitest.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ntndk.h>
+
+int g_sequence = 0;
+HANDLE g_hSemaphore;
+
+void exitfunc1(void)
+{
+ ok_int(g_sequence, 1);
+ g_sequence++;
+ ReleaseSemaphore(g_hSemaphore, 1, NULL);
+}
+
+void exitfunc2(void)
+{
+ ok_int(g_sequence, 2);
+ g_sequence++;
+ ReleaseSemaphore(g_hSemaphore, 1, NULL);
+}
+
+void exitfunc3(void)
+{
+ ok_int(g_sequence, 0);
+ g_sequence++;
+ ReleaseSemaphore(g_hSemaphore, 1, NULL);
+ printf("exitfunc3\n");
+}
+
+typedef int (__cdecl *PFN_atexit)(void (__cdecl*)(void));
+
+void Test_atexit()
+{
+ HMODULE hmod;
+ PFN_atexit patexit;
+
+ /* Open the named sempahore to count atexit callbacks */
+ g_hSemaphore = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, FALSE,
"atext_apitest_sempahore");
+ ok(g_hSemaphore != NULL, "couldn't open semaphore.\n");
+
+ /* Load atexit from msvcrt.dll */
+ hmod = GetModuleHandleA("msvcrt.dll");
+ patexit = (PFN_atexit)GetProcAddress(hmod, "atexit");
+ ok(patexit != NULL, "failed to get atexit from msvcrt.dll\n");
+
+ /* Register 3 exit functions, the second one in msvcrt. */
+ ok_int(atexit(exitfunc1), 0);
+ if (patexit != NULL)
+ {
+ ok_int(patexit(exitfunc2), 0);
+ }
+ ok_int(atexit(exitfunc3), 0);
+}
+
+START_TEST(atexit)
+{
+ CHAR Buffer[MAX_PATH];
+ PSTR CommandLine;
+ int result;
+ HANDLE hSemaphore;
+ SEMAPHORE_BASIC_INFORMATION SemInfo;
+ NTSTATUS Status;
+
+ /* Check recursive call */
+ CommandLine = GetCommandLineA();
+ if (strstr(CommandLine, "-run") != NULL)
+ {
+ Test_atexit();
+ return;
+ }
+
+ /* Create a named semaphore to count atexit callbacks in remote process */
+ hSemaphore = CreateSemaphoreA(NULL, 1, 20, "atext_apitest_sempahore");
+
+ /* Run the actual test in a new process */
+ sprintf(Buffer, "%s -run", CommandLine);
+ result = system(Buffer);
+ ok_int(result, 0);
+
+ /* Check the new semaphore state */
+ Status = NtQuerySemaphore(hSemaphore, SemaphoreBasicInformation, &SemInfo,
sizeof(SemInfo), NULL);
+ ok(NT_SUCCESS(Status), "NtQuerySemaphore failed: 0x%lx\n", Status);
+ ok_int(SemInfo.CurrentCount, 4);
+}
diff --git a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
index e53d3b4f6fc..9e76ba0202c 100644
--- a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
+++ b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
@@ -1014,7 +1014,7 @@ list(APPEND SOURCE_MSVCRT
# asin.c
# atan.c
# atan2.c
-# atexit # <-- keep this as an extern, thank you
+ atexit.c
# atof.c
# atoi.c
# atol.c
diff --git a/modules/rostests/apitests/crt/testlist.c
b/modules/rostests/apitests/crt/testlist.c
index 20587372301..9516d540be0 100644
--- a/modules/rostests/apitests/crt/testlist.c
+++ b/modules/rostests/apitests/crt/testlist.c
@@ -6,6 +6,7 @@
#if defined(TEST_MSVCRT)
extern void func__vscprintf(void);
extern void func__vscwprintf(void);
+extern void func_atexit(void);
#endif
#if defined(TEST_NTDLL)
extern void func__vscwprintf(void);
@@ -55,6 +56,7 @@ const struct test winetest_testlist[] =
#endif
#if defined(TEST_STATIC_CRT)
#elif defined(TEST_MSVCRT)
+ { "atexit", func_atexit },
#if defined(_M_IX86)
{ "__getmainargs", func___getmainargs },
#endif