Hello, I looked at changes and I have few comments for some of them. See below.
On Tuesday 16 June 2026 00:35:17 Kirill Makurin wrote: > Hello, > > Some time ago, in some discussion, I suggested that we add some "init" > function which should be called from each test program in > mingw-w64-crt/testcases/. This "init" function, for example, would call > (among other things) `_set_error_mode` and `_set_abort_behavior` so that > failed assert() and calls to abort() do not pop up a message box; it is > annoying, and it also could have pretty bad effect in CI runs. > > This patch series, among other changes, adds a small static library libtest.a > which contains helper functions which can be used by the test programs; > currently it just contains "init" function `mingw_test_init`, but it can be > extended in future to avoid code duplication in test programs. This library > is declared as check_LIBRARIES target, so it is only built with `make check` > and is not installed. > > The rest of the changes includes: > > - tidy up testcases/Makefile.am > - reformat some old source files in testcases/ subdirectory (mostly > indentation/whitespace changes) > - add tests which exist in testcases/ subdirectory, but for some reason are > not included in testcases/Makefile.am; some of those had to be fixed/updated > first > - update some existing tests > > I want to note that I had to disable three C++ tests (t_iostream, t_tls_cpp > and t_wrongret) on arm64ec, where we link libc++ statically. The reason is > that when we link libc++ statically with msvcrt.dll, libc++ contains > references to functions which are not available in msvcrt.dll: > > ``` > CXXLD t_iostream.exe > ld.lld: error: undefined symbol: __declspec(dllimport) _strftime_l (EC symbol) > >>> referenced by > >>> libc++.a(locale.cpp.obj):(#_ZNKSt3__18time_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEE6do_putES4_RNS_8ios_baseEcPK2tmcc) > >>> referenced by > >>> libc++.a(locale.cpp.obj):(#_ZNKSt3__18time_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEE6do_putES4_RNS_8ios_baseEcPK2tmcc) > >>> referenced by > >>> libc++.a(locale.cpp.obj):(#_ZNKSt3__110__time_put8__do_putEPcRS1_PK2tmcc) > >>> referenced 11 more times > clang-22: error: linker command failed with exit code 1 (use -v to see > invocation) > make[3]: *** [Makefile:2908: t_iostream.exe] Error 1 > ``` > > Which is weird... how does libc++ builds with msvcrt.dll if it does not > contain _strftime_l? Or maybe we link against wrong static libc++ (e.g. > configured for UCRT)? I don't have access to aarch64 machine to investigate > it myself. It is also possible that static libc++ is broken in this way on > all archs, not only arm64ec. > > The changes are based on top of c28e9555bb8800c53449f42a465ad9a5676fce88, so > they add a call to `mingw_test_init` from t_fromat_Z tests pushed yesterday. > > GitHub CI run: > https://github.com/maiddaisuki/mingw-w64/actions/runs/27583895869 > > - Kirill Makurin > From bbc25a0188bf12fce25b12b575ed2bfa419ee406 Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:20 +0900 > Subject: [PATCH 10/30] crt: tests: update t_aligned_alloc [2/2] > > On aarch64, due to buggy `_aligned_realloc`, some subtests were skipped > (when `BROKEN_REALLOC_SHRINK` is defined to non-zero). > > Instead of entirely skipping those subtests, do the test, and in case if it > fails, exit only if that test was not expected to fail. This is achieved by > extening `TEST` and `TEST_MEM` macros to take an extra argument which > indicates > whether this subtest is expected to fail. > > For subtests which were previously skipped when `BROKEN_REALLOC_SHRINK` is > defined to non-zero, the extra argument to `TEST` and `TEST_MEM` is > `BROKEN_REALLOC_SHRINK` itself; subtest is expected to fail when > `BROKEN_REALLOC_SHRINK` is non-zero. > > For other subtests, the extra argument is zero; subtest is not expected to > fail. > > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/t_aligned_alloc.c | 76 +++++++++++------------ > 1 file changed, 37 insertions(+), 39 deletions(-) > > diff --git a/mingw-w64-crt/testcases/t_aligned_alloc.c > b/mingw-w64-crt/testcases/t_aligned_alloc.c > index 16de738fb..c29b920e6 100644 > --- a/mingw-w64-crt/testcases/t_aligned_alloc.c > +++ b/mingw-w64-crt/testcases/t_aligned_alloc.c > @@ -4,23 +4,27 @@ > #include <stdio.h> > #include <string.h> > > -#define TEST(a, b, msg, ...) do { \ > +#define TEST(xfail, a, b, msg, ...) do { \ > if ((a) != (b)) { \ > fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ > fprintf(stderr, msg, ##__VA_ARGS__); \ > fputc('\n', stderr); \ > - return 1; \ > + if (!xfail) { \ > + return 1; \ > + } \ > } \ > } while (0) > > -#define TEST_MEM(ptr, byte, size, msg, ...) do { \ > +#define TEST_MEM(xfail, ptr, byte, size, msg, ...) do { \ > size_t i; \ > for (i = 0; i < size; i++) { \ > if (((unsigned char *)ptr)[i] != (unsigned char)byte) { \ > fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ > fprintf(stderr, msg, ##__VA_ARGS__); \ > fputc('\n', stderr); \ > - return 1; \ > + if (!xfail) { \ > + return 1; \ > + } \ > } \ > } \ > } while (0) For these two macros there is missing opposite direction of xfail. If the test passes and xfail is set then it should return 1 (indicate failure). > From 9c1dceb0ce521ffc08fe0e71a9530419d4412d1d Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:20 +0900 > Subject: [PATCH 18/30] crt: tests: update t_pow > > This test has a few issues: > > 1. It calls `atoi`, but does not include stdlib.h. > > 2. typedef for `pow` is missing `__cdecl`; this would result in compilation > error on i386 as all CRT functions have __cdecl calling convention. > > 3. `set_pow_msvcrt` does not check whether it was able to load `msvcrt.dll` > and > whether pointer returned by `GetProcAddress` is non-NULL; either could > result > in memory access violation. Also note that msvcrt.dll is not available on > Windows NT 3.1 and Windows 95. > > In order to fix this: > > 1. Include stdlib.h. > > 2. Add `__cdecl` to typedef for `pow`. > > 3. Instead of loading msvcrt.dll with `LoadLibrary`, call `GetModuleHandle` to > obtain handle of CRT the test is linked against and check if it is non-NULL. > If returned handler is non-NULL, check whether pointer returned by > `GetProcAddress` is non-NULL as well. > > 4. Test CRT's `pow` only if we successfully obtained its address; otherwise > simply skip this subtest. > > Add t_pow to testcases/Makefile.am. > > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/Makefile.am | 1 + > mingw-w64-crt/testcases/t_pow.c | 80 +++++++++++++++++++++++++---- > 2 files changed, 70 insertions(+), 11 deletions(-) > > diff --git a/mingw-w64-crt/testcases/Makefile.am > b/mingw-w64-crt/testcases/Makefile.am > index 86b3b0ce2..a384637dd 100644 > --- a/mingw-w64-crt/testcases/Makefile.am > +++ b/mingw-w64-crt/testcases/Makefile.am > @@ -55,6 +55,7 @@ testcase_progs = \ > t_mbrtowc \ > t_mbsrtowcs \ > t_nullptrexception \ > + t_pow \ > t_printf \ > t_printf_g_width \ > t_readdir \ > diff --git a/mingw-w64-crt/testcases/t_pow.c b/mingw-w64-crt/testcases/t_pow.c > index 6027fead0..1bf7aee12 100644 > --- a/mingw-w64-crt/testcases/t_pow.c > +++ b/mingw-w64-crt/testcases/t_pow.c > @@ -1,20 +1,63 @@ > #include <math.h> > #include <stdio.h> > +#include <stdlib.h> > > #define WIN32_LEAN_AND_MEAN > #include <windows.h> > > -typedef double (*my_pow)(double, double); > +#ifndef __MSVCRT_VERSION__ > +#define __MSVCRT_VERSION__ 0x0000 > +#endif > > +#if defined(_UCRT) || __MSVCRT_VERSION__ >= 0x0E00 > +#define CRT_FILENAME "ucrtbase.dll" > +#elif __MSVCRT_VERSION__ >= 0x0C00 > +#define CRT_FILENAME "msvcr120.dll" > +#elif __MSVCRT_VERSION__ >= 0x0B00 > +#define CRT_FILENAME "msvcr110.dll" > +#elif __MSVCRT_VERSION__ >= 0x0A00 > +#define CRT_FILENAME "msvcr100.dll" > +#elif __MSVCRT_VERSION__ >= 0x0900 > +#define CRT_FILENAME "msvcr90.dll" > +#elif __MSVCRT_VERSION__ >= 0x0800 > +#define CRT_FILENAME "msvcr80.dll" > +#elif __MSVCRT_VERSION__ >= 0x0710 > +#define CRT_FILENAME "msvcr71.dll" > +#elif __MSVCRT_VERSION__ >= 0x0700 > +#define CRT_FILENAME "msvcr70.dll" > +#elif __MSVCRT_VERSION__ >= 0x0410 > +#define CRT_FILENAME "msvcrt.dll" > +#elif __MSVCRT_VERSION__ >= 0x0400 > +#define CRT_FILENAME "msvcrt40.dll" > +#elif __MSVCRT_VERSION__ >= 0x0200 > +#define CRT_FILENAME "msvcrt20.dll" > +#elif __MSVCRT_VERSION__ >= 0x0100 > +#define CRT_FILENAME "msvcrt10.dll" > +#else > +#define CRT_FILENAME "crtdll.dll" > +#endif > + > +/* All CRT functions have __cdecl calling convention */ > +typedef double (__cdecl *my_pow)(double, double); > + > +/* The `pow` implementation to test */ > static my_pow fpow = pow; > > -static void set_pow_msvcrt(void) > +/* Set `fpow` to CRT's `pow` */ > +static void set_pow_crt(void) > { > - HMODULE hMod = LoadLibrary ("msvcrt.dll"); > - fpow = (my_pow) GetProcAddress (hMod, "pow"); > + my_pow ptr_pow = NULL; > + HMODULE hMod = GetModuleHandleA (CRT_FILENAME); > + > + if (hMod != NULL) { > + ptr_pow = (my_pow) (UINT_PTR) GetProcAddress (hMod, "pow"); > + } > + > + fpow = ptr_pow; > } Those ifdefs for library name is really ugly. I needed it more times and I was thinking about this idea: What about providing one specific symbol into every mingw-w64 CRT import library which would be a global char array with content of the library name? With this, it would be needed just to reference that symbol (e.g. __mingw_crt_library_name) and could be used in any application which needs this. Another idea: Via WinAPI it is possible to get HMODULE from any passed address of function. So what about using address of exit function (which is available in every CRT library) then deduce HMODULE of it (which would be the currently linked CRT DLL library) and on that call GetProcAddress? > From 63b96efcf1f5fa0adfac8fb836a9938241cfd703 Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:21 +0900 > Subject: [PATCH 24/30] crt: tests: update t_winmain_assert > > It is unclear what is the purpose of t_winmain_assert; it could be a simple > test program to observe behavior of assert() in an application using `WinMain` > as the entry point. > > While this test uses `WinMain` as its entry point, it does not actually create > any windows, which allows to run it just like any other test program. > > Update test test to assert that `lpCmdLine` argument is non-NULL. > > Add t_winmain_assert to testcases/Makefile.am. > > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/Makefile.am | 1 + > mingw-w64-crt/testcases/t_winmain_assert.c | 4 +--- > 2 files changed, 2 insertions(+), 3 deletions(-) > > diff --git a/mingw-w64-crt/testcases/Makefile.am > b/mingw-w64-crt/testcases/Makefile.am > index bea64c01f..58eaf81de 100644 > --- a/mingw-w64-crt/testcases/Makefile.am > +++ b/mingw-w64-crt/testcases/Makefile.am > @@ -103,6 +103,7 @@ testcase_progs = \ > t_wcstok_s \ > t_wctob \ > t_wctype \ > + t_winmain_assert \ > t_wreaddir > > # FIXME: the following tests are disabled on arm64ec; linking them statically > diff --git a/mingw-w64-crt/testcases/t_winmain_assert.c > b/mingw-w64-crt/testcases/t_winmain_assert.c > index a690c317a..6b9f10ad6 100644 > --- a/mingw-w64-crt/testcases/t_winmain_assert.c > +++ b/mingw-w64-crt/testcases/t_winmain_assert.c > @@ -4,14 +4,12 @@ > * No warranty is given; refer to the file DISCLAIMER.PD within this package. > */ > #include <assert.h> > -#include <string.h> > > #define WIN32_LEAN_AND_MEAN > #include <windows.h> > > int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR > lpCmdLine, int nCmdShow) > { > - int argc = strlen (lpCmdLine); > - assert (argc & 1); > + assert (lpCmdLine != NULL); > return 0; > } > -- > 2.51.0.windows.1 > I think that this test should still asserts that the lpCmdLine[0] is not '\0' like it was done before. > From 77185cbb932b1b24a3bd01e4a5fcdf8103c8f354 Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:21 +0900 > Subject: [PATCH 26/30] crt: tests: compile t_winmain with `make check` without > running it > > Test t_winmain creates a windows which makes it unsuitable for automated > environments such as GitHub CI. However, we can compile it as part of > `make check` without actually running it. > > Once compiled, this program can be run locally as `./testcases/t_winmain.exe`. > > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/Makefile.am | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/mingw-w64-crt/testcases/Makefile.am > b/mingw-w64-crt/testcases/Makefile.am > index 046ed822b..3e230fbea 100644 > --- a/mingw-w64-crt/testcases/Makefile.am > +++ b/mingw-w64-crt/testcases/Makefile.am > @@ -11,7 +11,8 @@ libprocdetach.dll: libprocdetach.o > # The following tests are compiled but not run with `make check`. > testcase_compile_only = \ > t_intrin \ > - t_intrin_cpp > + t_intrin_cpp \ > + t_winmain > > # Note that this list is usually sorted in alphabetical order. > # An exception is when variants of the same test are grouped together. > @@ -167,6 +168,9 @@ t_tls_ansi_CFLAGS = -std=c89 $(AM_CFLAGS) > # Compile t_tls_c11 in C11 mode > t_tls_c11_CFLAGS = -std=c11 $(AM_CFLAGS) > > +# Link t_winmain against gdi32.dll > +t_winmain_LDADD = -lgdi32 > + > if ENABLE_TESTS_UNICODE > # The following tests require compiler support for -municode option > testcase_progs += \ > -- > 2.51.0.windows.1 > The proper way to compile windows gui application is to pass -mwindows command line switch. It will properly sets subsystem to gui and correctly choose required gui library. So the -lgdi32 is not needed in this case. > From 1bdded069fe54f530a469abfae7bf11f27ee6f83 Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:21 +0900 > Subject: [PATCH 28/30] crt: tests: remove explicit calls to `__mingw_printf` > > Tests `t_float` and `t_speed_powl` directly call `__mingw_printf`; according > to relevant commit messages, it was done to suppress some compiler warnings. > > Instead of calling `__mingw_printf` directly, define `__MINGW_USE_ANSI_STDIO` > to non-zero and use mingw-w64's `printf`. This is not quite correct. Usage of __MINGW_USE_ANSI_STDIO replaces _all_ usage of (ms)printf by (mingw)printf. I think that the purpose of test was to check that code works correctly with the default (possible) (ms)printf functions. And just usage of long double needs to be done explicitly by (mingw)printf as the ms variant has no 80-bit float support. So IMHO the previous code was correct. > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/t_float.c | 3 ++- > mingw-w64-crt/testcases/t_speed_powl.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mingw-w64-crt/testcases/t_float.c > b/mingw-w64-crt/testcases/t_float.c > index 59d7f7496..fc0659929 100644 > --- a/mingw-w64-crt/testcases/t_float.c > +++ b/mingw-w64-crt/testcases/t_float.c > @@ -1,3 +1,4 @@ > +#define __MINGW_USE_ANSI_STDIO 1 > #include <inttypes.h> > #include <math.h> > #include <stdio.h> > @@ -111,7 +112,7 @@ int main() > ARG3_FCT (fma, 2.0, 1.5); > printf ("%g is%s nan\n", (double) in1, isnan (in1) ? "" :" not"); > printf ("%g is%s inf\n", (double) in1, isinf (in1) ? "" :" not"); > - __mingw_printf ("Ld:%Lg d:%g f:%g\n", ld1, ld2, (double) ld3); > + printf ("Ld:%Lg d:%g f:%g\n", ld1, ld2, (double) ld3); > > return 0; > } > diff --git a/mingw-w64-crt/testcases/t_speed_powl.c > b/mingw-w64-crt/testcases/t_speed_powl.c > index 87a7e94f7..bd2dfd436 100644 > --- a/mingw-w64-crt/testcases/t_speed_powl.c > +++ b/mingw-w64-crt/testcases/t_speed_powl.c > @@ -1,3 +1,4 @@ > +#define __MINGW_USE_ANSI_STDIO 1 > #include <math.h> > #include <stdio.h> > > @@ -23,7 +24,7 @@ int main() > > start_ticks = GetTickCount() - start_ticks; > > - __mingw_printf ("Loop %d times with result %Lg\n", i, ld); > + printf ("Loop %d times with result %Lg\n", i, ld); > printf ("Has %g calculations / ms\n", (double) i / (double) start_ticks); > > (void)sum; > -- > 2.51.0.windows.1 > > From 03d343a80521d2c2909fb4bc88225146f8c85725 Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:21 +0900 > Subject: [PATCH 29/30] crt: tests: add helper library libtest.a > > This static library contains helper functions for use by test programs; > it is linked into every test program. > > Signed-off-by: Kirill Makurin <[email protected]> > --- > mingw-w64-crt/testcases/Makefile.am | 21 +++++- > mingw-w64-crt/testcases/libtest.c | 113 ++++++++++++++++++++++++++++ > mingw-w64-crt/testcases/libtest.h | 37 +++++++++ > 3 files changed, 167 insertions(+), 4 deletions(-) > create mode 100644 mingw-w64-crt/testcases/libtest.c > create mode 100644 mingw-w64-crt/testcases/libtest.h > > diff --git a/mingw-w64-crt/testcases/Makefile.am > b/mingw-w64-crt/testcases/Makefile.am > index 1bf8f5acd..0b6336e80 100644 > --- a/mingw-w64-crt/testcases/Makefile.am > +++ b/mingw-w64-crt/testcases/Makefile.am > @@ -4,6 +4,21 @@ TEST_CFLAGS=-Wno-format -Wno-unused-parameter > -Wno-error=unused-function > AM_CFLAGS=@ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@ > $(TEST_CFLAGS) -Wno-missing-prototypes > AM_CXXFLAGS=@ADD_C_CXX_WARNING_FLAGS@ @ADD_CXX_ONLY_WARNING_FLAGS@ > $(TEST_CFLAGS) > > +# Link all test programs against libtest.a; for targets with their own > +# target-specifc *_LDADD variable, make sure to add $(LDADD). > +LDADD = $(builddir)/libtest.a > + > +check_LIBRARIES = \ > + libtest.a > + > +# libtest.a is a static library containing helper function for use by tests > +# programs. > +# > +# When you write a new test, please include libtest.h and add a call to > +# mingw_test_init() function upon entry to main(). > +libtest_a_SOURCES = \ > + libtest.c libtest.h > + > # Used by t_safe_flush > libprocdetach.dll: libprocdetach.o > $(LINK) -shared libprocdetach.o -o libprocdetach.dll > @@ -165,7 +180,7 @@ endif > t_intrinc_CFLAGS = -std=c99 $(AM_CFLAGS) > > # Link t_safe_flush against libprocdetach.dll > -t_safe_flush_LDADD = libprocdetach.dll > +t_safe_flush_LDADD = libprocdetach.dll $(LDADD) > > # Compile t_tls_ansi in C89 mode > t_tls_ansi_CFLAGS = -std=c89 $(AM_CFLAGS) > @@ -174,7 +189,7 @@ t_tls_ansi_CFLAGS = -std=c89 $(AM_CFLAGS) > t_tls_c11_CFLAGS = -std=c11 $(AM_CFLAGS) > > # Link t_winmain against gdi32.dll > -t_winmain_LDADD = -lgdi32 > +t_winmain_LDADD = -lgdi32 $(LDADD) > > if ENABLE_TESTS_UNICODE > # The following tests require compiler support for -municode option > @@ -188,8 +203,6 @@ if ENABLE_TESTS_UNICODE > t__wstat_all_CFLAGS = -municode $(AM_CFLAGS) > endif > > -check_LIBRARIES = > - > check_PROGRAMS = \ > $(testcase_compile_only) \ > $(testcase_progs) > diff --git a/mingw-w64-crt/testcases/libtest.c > b/mingw-w64-crt/testcases/libtest.c > new file mode 100644 > index 000000000..9d39c4061 > --- /dev/null > +++ b/mingw-w64-crt/testcases/libtest.c > @@ -0,0 +1,113 @@ > +/** > + * This file has no copyright assigned and is placed in the Public Domain. > + * This file is part of the mingw-w64 runtime package. > + * No warranty is given; refer to the file DISCLAIMER.PD within this package. > + */ > + > +#ifdef NDEBUG > +#undef NDEBUG > +#endif > + > +#include <assert.h> > +#include <crtdbg.h> > +#include <errno.h> > +#include <stdio.h> > +#include <stdlib.h> > +#include <wchar.h> > + > +#define WIN32_LEAN_AND_MEAN > +#include <windows.h> > + > +#include "libtest.h" > + > +/** > + * Invalid parameter handler. > + */ > +__attribute__ ((__noreturn__)) > +static void __cdecl mingw_test_invalid_parameter_handler ( > + const wchar_t *expression, > + const wchar_t *function, > + const wchar_t *file, > + unsigned int line, > + uintptr_t pReserved > +) { > + fprintf(stderr, "Invalid parameter: %ls", expression); > + /* Additional arguments are non-NULL only for debug CRT DLLs */ > + if (function) > + fprintf(stderr, ", function %ls", function); > + if (file) > + fprintf(stderr, ", file %ls", file); > + if (line) > + fprintf(stderr, ", line %d", line); > + fprintf(stderr, "\n"); > + (void)pReserved; > + /* Ensure that this handler does not return, as the whole handler replaces > calling of Dr. Watson */ > + abort (); nit: There is a mix of TABs and spaces (something which you tried to clean in previous changes in series). > +} > + > +static int __cdecl mingw_test_fini (void) { > + _CrtCheckMemory (); > + _CrtDumpMemoryLeaks (); > + > + return EXIT_SUCCESS; > +} > + > +void mingw_test_init (void) { > + UINT oldErrorMode = SetErrorMode (0); > + SetErrorMode (oldErrorMode | SEM_FAILCRITICALERRORS | > SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); > + > + /** > + * msvcr80.dll and later attempt to set multibyte code page to active > + * ANSI code page during initialization. > + * > + * If active ANSI code page is 65001 (UTF-8), _setmbcp will fail > + * and set `errno` to EINVAL. > + * > + * Some tests may assume `errno` to be set to zero when entering main. > + */ > + errno = 0; > + > + /* Set CRT _invalid_parameter() output to CRT stderr and call abort (the > default is to just call Dr. Watson) */ > + _set_invalid_parameter_handler (mingw_test_invalid_parameter_handler); > + > + /** > + * Disable buffering. > + * This ensures that all output is written to log files. > + */ > + setvbuf (stdout, NULL, _IONBF, 0); > + setvbuf (stderr, NULL, _IONBF, 0); > + > +#if __MSVCRT_VERSION__ >= 0x0800 > + /** > + * Make `abort` as silent as possible. > + */ > + _set_abort_behavior (0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); > +#endif > + > +#if __MSVCRT_VERSION__ >= 0x0400 > + /** > + * We don't want failed assertions to pop-up a message box. > + */ > + assert (_set_error_mode (_OUT_TO_STDERR) != -1); assert here is wrong. If the _set_error_mode fails then the assert will pop-up message box. > +#endif > + > + /** > + * Redirect `_CRT_WARN` debug messages to `stderr`. > + */ > + assert (_CrtSetReportMode (_CRT_WARN, _CRTDBG_MODE_DEBUG | > _CRTDBG_MODE_FILE) != -1); > + assert (_CrtSetReportFile (_CRT_WARN, _CRTDBG_FILE_STDERR) != > _CRTDBG_HFILE_ERROR); > + > + /** > + * Redirect `_CRT_ERROR` debug messages to `stderr`. > + */ > + assert (_CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_DEBUG | > _CRTDBG_MODE_FILE) != -1); > + assert (_CrtSetReportFile (_CRT_ERROR, _CRTDBG_FILE_STDERR) != > _CRTDBG_HFILE_ERROR); > + > + /** > + * Redirect `_CRT_ASSERT` debug messages to `stderr`. > + */ > + assert (_CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_DEBUG | > _CRTDBG_MODE_FILE) != -1); > + assert (_CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDERR) != > _CRTDBG_HFILE_ERROR); > + > + _onexit (mingw_test_fini); > +} > From 5273f8bbdf925a038618519bbf6d6ae9e87d62ce Mon Sep 17 00:00:00 2001 > From: Kirill Makurin <[email protected]> > Date: Tue, 16 Jun 2026 08:45:21 +0900 > Subject: [PATCH 30/30] crt: tests: add call to mingw_test_init() from test > programs > > Signed-off-by: Kirill Makurin <[email protected]> > --- ... > diff --git a/mingw-w64-crt/testcases/t__fstat_all.c > b/mingw-w64-crt/testcases/t__fstat_all.c > index 9338ade5a..3893faaef 100644 > --- a/mingw-w64-crt/testcases/t__fstat_all.c > +++ b/mingw-w64-crt/testcases/t__fstat_all.c > @@ -3,6 +3,9 @@ > #include <string.h> > #include <sys/stat.h> > > +/* mingw-w64 headers */ > +#include "libtest.h" > + > int main() { > int ret; > struct _stat st = {}; > @@ -10,6 +13,9 @@ int main() { > struct _stat32i64 st32i64 = {}; > struct _stat64 st64 = {}; > struct _stat64i32 st64i32 = {}; > + > + mingw_test_init (); > + I would propose to call this function at the beginning of main() before declaring or initializing any variable, to ensure that it is always called at the beginning. Initialization of variable could be done by function call which could potentially cause assert/failure. _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
