From d886ab431671a3dbcd97b560515636ecdc59f81f Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Tue, 23 Apr 2024 22:13:53 +1000 Subject: [PATCH 1/8] Add mimalloc submodule and update build script --- .gitmodules | 4 ++++ inouealc.c | 26 ++++++++++++++------------ libs/mimalloc | 1 + psqlodbc.h | 32 ++++++++++++++++++++++++++++++++ winbuild/BuildAll.ps1 | 28 ++++++++++++++++++++++++++-- winbuild/psqlodbc.vcxproj | 15 +++++++++++---- 6 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 .gitmodules create mode 160000 libs/mimalloc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..0b66fd3b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "libs/mimalloc"] + path = libs/mimalloc + url = https://github.com/microsoft/mimalloc + branch = master diff --git a/inouealc.c b/inouealc.c index 977990a5..a7d21918 100644 --- a/inouealc.c +++ b/inouealc.c @@ -1,6 +1,7 @@ #undef _MEMORY_DEBUG_ #include "psqlodbc.h" +#ifndef _MIMALLOC_ #ifdef WIN32 #ifdef _DEBUG /* #include */ @@ -10,6 +11,7 @@ #include #endif /* _DEBUG */ #endif /* WIN32 */ +#endif /* _MIMALLOC_ */ #include #include "misc.h" @@ -26,20 +28,20 @@ CSTR ALCERR = "alcerr"; void * pgdebug_alloc(size_t size) { void * alloced; - alloced = malloc(size); + alloced = pg_malloc(size); MYLOG(2, " alloced=%p(" FORMAT_SIZE_T ")\n", alloced, size); if (alloced) { if (!alsize) { alsize = 100; - altbl = (ALADR *) malloc(alsize * sizeof(ALADR)); + altbl = (ALADR *) pg_malloc(alsize * sizeof(ALADR)); } else if (tbsize >= alsize) { ALADR *al; alsize *= 2; - if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + if (al = (ALADR *) pg_realloc(altbl, alsize * sizeof(ALADR)), NULL == al) return alloced; altbl = al; } @@ -53,20 +55,20 @@ MYLOG(2, " alloced=%p(" FORMAT_SIZE_T ")\n", alloced, size); } void * pgdebug_calloc(size_t n, size_t size) { - void * alloced = calloc(n, size); + void * alloced = pg_calloc(n, size); if (alloced) { if (!alsize) { alsize = 100; - altbl = (ALADR *) malloc(alsize * sizeof(ALADR)); + altbl = (ALADR *) pg_malloc(alsize * sizeof(ALADR)); } else if (tbsize >= alsize) { ALADR *al; alsize *= 2; - if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + if (al = (ALADR *) pg_realloc(altbl, alsize * sizeof(ALADR)), NULL == al) return alloced; altbl = al; } @@ -85,7 +87,7 @@ void * pgdebug_realloc(void * ptr, size_t size) if (!ptr) return pgdebug_alloc(size); - alloced = realloc(ptr, size); + alloced = pg_realloc(ptr, size); if (!alloced) { MYLOG(0, "%s %p error\n", ALCERR, ptr); @@ -109,7 +111,7 @@ void * pgdebug_realloc(void * ptr, size_t size) } char * pgdebug_strdup(const char * ptr) { - char * alloced = strdup(ptr); + char * alloced = pg_strdup(ptr); if (!alloced) { MYLOG(0, "%s %p error\n", ALCERR, ptr); @@ -119,13 +121,13 @@ char * pgdebug_strdup(const char * ptr) if (!alsize) { alsize = 100; - altbl = (ALADR *) malloc(alsize * sizeof(ALADR)); + altbl = (ALADR *) pg_malloc(alsize * sizeof(ALADR)); } else if (tbsize >= alsize) { ALADR *al; alsize *= 2; - if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + if (al = (ALADR *) pg_realloc(altbl, alsize * sizeof(ALADR)), NULL == al) return alloced; altbl = al; } @@ -168,7 +170,7 @@ void pgdebug_free(void * ptr) } else MYLOG(2, "ptr=%p\n", ptr); - free(ptr); + pg_free(ptr); } static BOOL out_check(void *out, size_t len, const char *name) @@ -253,7 +255,7 @@ void debug_memory_check(void) if (0 == tbsize) { MYLOG(0, "no memry leak found and max count allocated so far is %d\n", alsize); - free(altbl); + pg_free(altbl); alsize = 0; } else diff --git a/libs/mimalloc b/libs/mimalloc new file mode 160000 index 00000000..4e50d671 --- /dev/null +++ b/libs/mimalloc @@ -0,0 +1 @@ +Subproject commit 4e50d6714d471b72b2285e25a3df6c92db944593 diff --git a/psqlodbc.h b/psqlodbc.h index bf259608..5b40b586 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -24,6 +24,9 @@ #endif #include "version.h" +#ifdef _MIMALLOC_ +#include +#else /* _MIMALLOC_ */ #ifdef WIN32 #ifdef _DEBUG #ifndef _MEMORY_DEBUG_ @@ -41,6 +44,11 @@ #else /* WIN32 */ #include #endif /* WIN32 */ +#endif /* _MIMALLOC_ */ + +#ifdef WIN32 +#include +#endif /* WIN32 */ #ifdef __INCLUDE_POSTGRES_FE_H__ /* currently not defined */ /* @@ -61,6 +69,21 @@ #endif /* __GNUC__ || __IBMC__ */ #endif /* __INCLUDE_POSTGRES_FE_H__ */ +#ifdef _MIMALLOC_ +#include +#define pg_malloc mi_malloc +#define pg_realloc mi_realloc +#define pg_calloc mi_calloc +#define pg_strdup mi_strdup +#define pg_free mi_free +#else /* _MIMALLOC_ */ +#define pg_malloc malloc +#define pg_realloc realloc +#define pg_calloc calloc +#define pg_strdup _strdup +#define pg_free free +#endif /* _MIMALLOC_ */ + #ifdef _MEMORY_DEBUG_ void *pgdebug_alloc(size_t); void *pgdebug_calloc(size_t, size_t); @@ -87,6 +110,15 @@ void debug_memory_check(void); /* #define strncpy_null pgdebug_strncpy_null */ #define memcpy pgdebug_memcpy #define memset pgdebug_memset +#else /* _MEMORY_DEBUG_ */ +#ifdef WIN32 +#undef strdup +#endif /* WIN32 */ +#define malloc pg_malloc +#define realloc pg_realloc +#define calloc pg_calloc +#define strdup pg_strdup +#define free pg_free #endif /* _MEMORY_DEBUG_ */ #ifdef WIN32 diff --git a/winbuild/BuildAll.ps1 b/winbuild/BuildAll.ps1 index 3deed985..783018f9 100755 --- a/winbuild/BuildAll.ps1 +++ b/winbuild/BuildAll.ps1 @@ -30,6 +30,10 @@ Specify the configuration xml file name if you want to use the configuration file other than standard one. The relative path is relative to the current directory. +.PARAMETER UseMimalloc + Whether to use the mimalloc allocator for improved performance. + Requires a toolset of v141, v142 or later. Specify "yes" or + "no"(default). .EXAMPLE > .\BuildAll Build with default or automatically selected parameters. @@ -65,7 +69,9 @@ Param( [ValidateSet("Debug", "Release")] [String]$Configuration="Release", [string]$BuildConfigPath, -[switch]$AlongWithInstallers +[switch]$AlongWithInstallers, +[ValidateSet("yes", "no")] +[string]$UseMimalloc="no" ) function buildPlatform([xml]$configInfo, [string]$Platform) @@ -100,7 +106,25 @@ function buildPlatform([xml]$configInfo, [string]$Platform) $BUILD_MACROS = $BUILD_MACROS -replace '"', '`"' $macroList = iex "write-output $BUILD_MACROS" } - & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN $macroList + + if ($UseMimalloc -eq "yes") { + switch ($VCVersion) { + "10.0" { $mimallocIdeDir = "vs2017" } + "11.0" { $mimallocIdeDir = "vs2017" } + "12.0" { $mimallocIdeDir = "vs2017" } + "14.0" { $mimallocIdeDir = "vs2017" } + "15.0" { $mimallocIdeDir = "vs2017" } + "16.0" { $mimallocIdeDir = "vs2019" } + "17.0" { $mimallocIdeDir = "vs2022" } + default { throw "Unable to resolve mimalloc IDE directory for VC ${VCVersion}."} + } + + # build mimalloc dependency + & ${msbuildexe} ..\libs\mimalloc\ide\$mimallocIdeDir\mimalloc.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} + } + + # build psqlodbc + & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN /p:MIMALLOC=$UseMimalloc $macroList } $scriptPath = (Split-Path $MyInvocation.MyCommand.Path) diff --git a/winbuild/psqlodbc.vcxproj b/winbuild/psqlodbc.vcxproj index 5d1d9e81..9eeeeabd 100755 --- a/winbuild/psqlodbc.vcxproj +++ b/winbuild/psqlodbc.vcxproj @@ -131,6 +131,13 @@ $(ADD_DEFINES);_MEMORY_DEBUG_ + + + $(ADD_DEFINES);_MIMALLOC_ + $(ADD_INC);..\libs\mimalloc\include + $(ADD_LIBPATH);..\libs\mimalloc\out\msvc-$(Platform)\$(Configuration) + $(CALL_LIB);mimalloc-static.lib + true @@ -158,7 +165,7 @@ $(DELAY_LOAD_DLLS);%(DelayLoadDLLs) $(ADD_LIBPATH);$(OutDir);%(AdditionalLibraryDirectories) - libpq.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;wsock32.lib;ws2_32.lib;secur32.lib;winmm.lib;%(AdditionalDependencies) + $(CALL_LIB);libpq.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;wsock32.lib;ws2_32.lib;secur32.lib;winmm.lib;%(AdditionalDependencies) $(MAINDEF) true @@ -177,7 +184,7 @@ $(DELAY_LOAD_DLLS);%(DelayLoadDLLs) $(ADD_LIBPATH);$(OutDir);%(AdditionalLibraryDirectories) - libpq.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;wsock32.lib;ws2_32.lib;secur32.lib;winmm.lib;%(AdditionalDependencies) + $(CALL_LIB);libpq.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;wsock32.lib;ws2_32.lib;secur32.lib;winmm.lib;%(AdditionalDependencies) $(MAINDEF) true @@ -196,7 +203,7 @@ $(DELAY_LOAD_DLLS);%(DelayLoadDLLs) $(ADD_LIBPATH);$(OutDir);%(AdditionalLibraryDirectories) - libpq.lib;winmm.lib;wsock32.lib;ws2_32.lib;secur32.lib;%(AdditionalDependencies) + $(CALL_LIB);libpq.lib;winmm.lib;wsock32.lib;ws2_32.lib;secur32.lib;%(AdditionalDependencies) $(MAINDEF) true @@ -215,7 +222,7 @@ $(DELAY_LOAD_DLLS);%(DelayLoadDLLs) $(ADD_LIBPATH);$(OutDir);%(AdditionalLibraryDirectories) - libpq.lib;winmm.lib;wsock32.lib;ws2_32.lib;secur32.lib;%(AdditionalDependencies) + $(CALL_LIB);libpq.lib;winmm.lib;wsock32.lib;ws2_32.lib;secur32.lib;%(AdditionalDependencies) $(MAINDEF) true From 92ee21756709858ae088d7991465187095d49a26 Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Wed, 24 Apr 2024 00:06:40 +1000 Subject: [PATCH 2/8] Add steps to build and test with UseMimalloc --- .github/workflows/main.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4203264c..cb1da55c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,9 @@ env: # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix BUILD_CONFIGURATION: Release + # Path to the directory where the build artifacts will be placed. + PSQLODBC_OBJBASE: ${{ github.workspace }}/out/default + permissions: contents: read @@ -198,6 +201,19 @@ jobs: shell: powershell run: | winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" + - name: build psqlodbc with UseMimalloc + shell: powershell + run: | + copy .github\workflows\configuration.xml winbuild + winbuild\BuildAll.ps1 -UseMimalloc yes + env: + PSQLODBC_OBJBASE: ${{ github.workspace }}/out/UseMimalloc + - name: test psqlodbc with UseMimalloc + shell: powershell + run: | + winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" + env: + PSQLODBC_OBJBASE: ${{ github.workspace }}/out/UseMimalloc - name: Upload x64 merge module uses: actions/upload-artifact@v4 with: From 33a780496903309b8cc000625364980a3a12bb4f Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Wed, 24 Apr 2024 22:42:41 +1000 Subject: [PATCH 3/8] Update mimalloc submodule --- libs/mimalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mimalloc b/libs/mimalloc index 4e50d671..229ec9cb 160000 --- a/libs/mimalloc +++ b/libs/mimalloc @@ -1 +1 @@ -Subproject commit 4e50d6714d471b72b2285e25a3df6c92db944593 +Subproject commit 229ec9cbdc81cf1ffb705cbd8a07503589847426 From 1bc7ea80ee302c4cdd4ffe97bb2391e331c9a252 Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Wed, 24 Apr 2024 22:43:32 +1000 Subject: [PATCH 4/8] Change UseMimalloc parameter type to switch --- winbuild/BuildAll.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/winbuild/BuildAll.ps1 b/winbuild/BuildAll.ps1 index 783018f9..ac8bc70d 100755 --- a/winbuild/BuildAll.ps1 +++ b/winbuild/BuildAll.ps1 @@ -31,9 +31,8 @@ the configuration file other than standard one. The relative path is relative to the current directory. .PARAMETER UseMimalloc - Whether to use the mimalloc allocator for improved performance. - Requires a toolset of v141, v142 or later. Specify "yes" or - "no"(default). + Specify whether to use the mimalloc allocator for improved performance. + Requires a toolset of v141, v142 or later. .EXAMPLE > .\BuildAll Build with default or automatically selected parameters. @@ -70,8 +69,7 @@ Param( [String]$Configuration="Release", [string]$BuildConfigPath, [switch]$AlongWithInstallers, -[ValidateSet("yes", "no")] -[string]$UseMimalloc="no" +[switch]$UseMimalloc ) function buildPlatform([xml]$configInfo, [string]$Platform) @@ -107,7 +105,9 @@ function buildPlatform([xml]$configInfo, [string]$Platform) $macroList = iex "write-output $BUILD_MACROS" } - if ($UseMimalloc -eq "yes") { + if ($UseMimalloc) { + $mimallocProperty = "yes" + switch ($VCVersion) { "10.0" { $mimallocIdeDir = "vs2017" } "11.0" { $mimallocIdeDir = "vs2017" } @@ -124,7 +124,7 @@ function buildPlatform([xml]$configInfo, [string]$Platform) } # build psqlodbc - & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN /p:MIMALLOC=$UseMimalloc $macroList + & ${msbuildexe} ./platformbuild.vcxproj /tv:$MSToolsV "/p:Platform=$Platform;Configuration=$Configuration;PlatformToolset=${Toolset}" /t:$target /p:VisualStudioVersion=${VCVersion} /p:DRIVERVERSION=$DRIVERVERSION /p:PG_INC=$PG_INC /p:PG_LIB=$PG_LIB /p:PG_BIN=$PG_BIN /p:MIMALLOC=$mimallocProperty $macroList } $scriptPath = (Split-Path $MyInvocation.MyCommand.Path) From 8cd7f28d4cda1c8c41a67f65a20a8771b3472cc6 Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Wed, 24 Apr 2024 22:43:57 +1000 Subject: [PATCH 5/8] Add ExpectMimalloc parameter --- winbuild/regress.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/winbuild/regress.ps1 b/winbuild/regress.ps1 index bff0b7e8..0a0a0ed1 100644 --- a/winbuild/regress.ps1 +++ b/winbuild/regress.ps1 @@ -38,6 +38,8 @@ The relative path is relative to the current directory. .PARAMETER ReinstallDriver Reinstall the driver in any case. +.PARAMETER ExpectMimalloc + Specify whether usage of the mimalloc allocator is expected. .EXAMPLE > .\regress Build with default or automatically selected parameters @@ -85,7 +87,8 @@ Param( [string]$DeclareFetch="on", [string]$DsnInfo, [string]$SpecificDsn, -[switch]$ReinstallDriver +[switch]$ReinstallDriver, +[switch]$ExpectMimalloc ) @@ -227,6 +230,7 @@ function RunTest($scriptPath, $Platform, $testexes) if ($LASTEXITCODE -ne 0) { throw "`treset_db error" } + $env:MIMALLOC_VERBOSE = 1 $cnstr = @() switch ($DeclareFetch) { "off" { $cnstr += "UseDeclareFetch=0" } @@ -244,11 +248,17 @@ function RunTest($scriptPath, $Platform, $testexes) $env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST += ";Database=contrib_regression;ConnSettings={set lc_messages='C'}" } write-host "`n`tSetting by env variable:$env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST" - .\runsuite $testexes --inputdir=$origdir + .\runsuite $testexes --inputdir=$origdir 2>&1 | Tee-Object -Variable runsuiteOutput + + # Check whether mimalloc ran by searching for a message printed by the MIMALLOC_VERBOSE option + if ($ExpectMimalloc -xor ($runsuiteOutput -match "mimalloc: process done")) { + throw "`tmimalloc usage was expected to be $ExpectMimalloc" + } } } catch [Exception] { throw $error[0] } finally { + $env:MIMALLOC_VERBOSE = $null $env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST = $null } } From 8b4bd08c110bb17f0638c16c98a43082d028d785 Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Wed, 24 Apr 2024 22:45:09 +1000 Subject: [PATCH 6/8] Fetch mimalloc submodule and use mimalloc parameters --- .github/workflows/main.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cb1da55c..02891fd1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -187,6 +187,8 @@ jobs: sc config "postgresql-x64-14" start= auto - name: get psqlodbc uses: actions/checkout@v4 + with: + submodules: true - name: 'setup msvc for psqlodbc' uses: TheMrMilchmann/setup-msvc-dev@v3 with: @@ -201,19 +203,19 @@ jobs: shell: powershell run: | winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" - - name: build psqlodbc with UseMimalloc + - name: build psqlodbc with mimalloc shell: powershell run: | copy .github\workflows\configuration.xml winbuild - winbuild\BuildAll.ps1 -UseMimalloc yes + winbuild\BuildAll.ps1 -UseMimalloc env: - PSQLODBC_OBJBASE: ${{ github.workspace }}/out/UseMimalloc - - name: test psqlodbc with UseMimalloc + PSQLODBC_OBJBASE: ${{ github.workspace }}/out/mimalloc + - name: test psqlodbc with mimalloc shell: powershell run: | - winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" + winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" -ExpectMimalloc -ReinstallDriver env: - PSQLODBC_OBJBASE: ${{ github.workspace }}/out/UseMimalloc + PSQLODBC_OBJBASE: ${{ github.workspace }}/out/mimalloc - name: Upload x64 merge module uses: actions/upload-artifact@v4 with: From f119320d9b3e01a07562da89f4e25467c2f21355 Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Thu, 25 Apr 2024 22:25:31 +1000 Subject: [PATCH 7/8] Prevent MIMALLOC_VERBOSE aborting tests --- winbuild/regress.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/winbuild/regress.ps1 b/winbuild/regress.ps1 index 0a0a0ed1..be33df0e 100644 --- a/winbuild/regress.ps1 +++ b/winbuild/regress.ps1 @@ -210,6 +210,8 @@ function vcxfile_make($testnames, $dirnames, $vcxfile) function RunTest($scriptPath, $Platform, $testexes) { + $originalErrorActionPreference = $ErrorActionPreference + # Run regression tests if ($Platform -eq "x64") { $targetdir="test_x64" @@ -230,7 +232,6 @@ function RunTest($scriptPath, $Platform, $testexes) if ($LASTEXITCODE -ne 0) { throw "`treset_db error" } - $env:MIMALLOC_VERBOSE = 1 $cnstr = @() switch ($DeclareFetch) { "off" { $cnstr += "UseDeclareFetch=0" } @@ -241,6 +242,9 @@ function RunTest($scriptPath, $Platform, $testexes) if ($cnstr.length -eq 0) { $cnstr += $null } + # Temporarily set $ErrorActionPreference to "Continue" because MIMALLOC_VERBOSE writes to stderr + $ErrorActionPreference = "Continue" + $env:MIMALLOC_VERBOSE = 1 for ($i = 0; $i -lt $cnstr.length; $i++) { $env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST = $cnstr[$i] @@ -250,7 +254,7 @@ function RunTest($scriptPath, $Platform, $testexes) write-host "`n`tSetting by env variable:$env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST" .\runsuite $testexes --inputdir=$origdir 2>&1 | Tee-Object -Variable runsuiteOutput - # Check whether mimalloc ran by searching for a message printed by the MIMALLOC_VERBOSE option + # Check whether mimalloc ran by searching for a verbose message from mimalloc if ($ExpectMimalloc -xor ($runsuiteOutput -match "mimalloc: process done")) { throw "`tmimalloc usage was expected to be $ExpectMimalloc" } @@ -258,8 +262,9 @@ function RunTest($scriptPath, $Platform, $testexes) } catch [Exception] { throw $error[0] } finally { - $env:MIMALLOC_VERBOSE = $null $env:COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST = $null + $env:MIMALLOC_VERBOSE = $null + $ErrorActionPreference = $originalErrorActionPreference } } From dcae06aa968fedcdc6973b03790b9d0b3996ecbb Mon Sep 17 00:00:00 2001 From: Adrian Grucza Date: Thu, 25 Apr 2024 22:26:47 +1000 Subject: [PATCH 8/8] Uninstall driver after tests; upload mimalloc artifacts --- .github/workflows/main.yml | 98 +++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02891fd1..bba823be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,9 +18,6 @@ env: # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix BUILD_CONFIGURATION: Release - # Path to the directory where the build artifacts will be placed. - PSQLODBC_OBJBASE: ${{ github.workspace }}/out/default - permissions: contents: read @@ -193,63 +190,110 @@ jobs: uses: TheMrMilchmann/setup-msvc-dev@v3 with: arch: x86 - - name: build psqlodbc + + - name: build psqlodbc standard shell: powershell run: | copy .github\workflows\configuration.xml winbuild winbuild\BuildAll.ps1 installer\buildInstallers.ps1 - - name: test psqlodbc + env: + PSQLODBC_OBJBASE: ${{ github.workspace }}\winbuild\standard + - name: test psqlodbc standard shell: powershell run: | winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" - - name: build psqlodbc with mimalloc + standard\test_x86\RegisterRegdsn.exe uninstall_driver postgres_devw + standard\test_x64\RegisterRegdsn.exe uninstall_driver postgres_devw + env: + PSQLODBC_OBJBASE: ${{ github.workspace }}\winbuild\standard + + - name: build psqlodbc mimalloc shell: powershell run: | copy .github\workflows\configuration.xml winbuild winbuild\BuildAll.ps1 -UseMimalloc + installer\buildInstallers.ps1 env: - PSQLODBC_OBJBASE: ${{ github.workspace }}/out/mimalloc - - name: test psqlodbc with mimalloc + PSQLODBC_OBJBASE: ${{ github.workspace }}\winbuild\mimalloc + - name: test psqlodbc mimalloc shell: powershell run: | - winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" -ExpectMimalloc -ReinstallDriver + winbuild\regress.ps1 -DsnInfo "SERVER=localhost|DATABASE=contrib_regression|PORT=5432|UID=postgres|PWD=password" -ExpectMimalloc + mimalloc\test_x86\RegisterRegdsn.exe uninstall_driver postgres_devw + mimalloc\test_x64\RegisterRegdsn.exe uninstall_driver postgres_devw env: - PSQLODBC_OBJBASE: ${{ github.workspace }}/out/mimalloc - - name: Upload x64 merge module + PSQLODBC_OBJBASE: ${{ github.workspace }}\winbuild\mimalloc + + - name: Upload standard x64 merge module + uses: actions/upload-artifact@v4 + with: + name: psqlODBC Standard x64 Merge Module + path: winbuild/standard/installer/x64/*.msm + retention-days: 5 + if-no-files-found: error + - name: Upload standard x64 installer package + uses: actions/upload-artifact@v4 + with: + name: psqlODBC Standard x64 Installer + path: winbuild/standard/installer/x64/*.msi + retention-days: 5 + if-no-files-found: error + - name: Upload standard x86 merge module + uses: actions/upload-artifact@v4 + with: + name: psqlODBC Standard x86 Merge Module + path: winbuild/standard/installer/x86/*.msm + retention-days: 5 + if-no-files-found: error + - name: Upload standard x86 installer package + uses: actions/upload-artifact@v4 + with: + name: psqlODBC Standard x86 Installer + path: winbuild/standard/installer/x86/*.msi + retention-days: 5 + if-no-files-found: error + - name: Upload standard x64 setup + uses: actions/upload-artifact@v4 + with: + name: psqlODBC Standard x64 Setup + path: winbuild/standard/installer/psqlodbc-setup/bin/Release/psqlodbc-setup.exe + retention-days: 5 + if-no-files-found: error + + - name: Upload mimalloc x64 merge module uses: actions/upload-artifact@v4 with: - name: psqlODBC x64 Merge Module - path: ./installer/x64/*.msm + name: psqlODBC mimalloc x64 Merge Module + path: winbuild/mimalloc/installer/x64/*.msm retention-days: 5 if-no-files-found: error - - name: Upload x64 installer package + - name: Upload mimalloc x64 installer package uses: actions/upload-artifact@v4 with: - name: psqlODBC x64 Installer - path: ./installer/x64/*.msi + name: psqlODBC mimalloc x64 Installer + path: winbuild/mimalloc/installer/x64/*.msi retention-days: 5 if-no-files-found: error - - name: Upload x86 merge module + - name: Upload mimalloc x86 merge module uses: actions/upload-artifact@v4 with: - name: psqlODBC x86 Merge Module - path: ./installer/x86/*.msm + name: psqlODBC mimalloc x86 Merge Module + path: winbuild/mimalloc/installer/x86/*.msm retention-days: 5 if-no-files-found: error - - name: Upload x86 installer package + - name: Upload mimalloc x86 installer package uses: actions/upload-artifact@v4 with: - name: psqlODBC x86 Installer - path: ./installer/x86/*.msi + name: psqlODBC mimalloc x86 Installer + path: winbuild/mimalloc/installer/x86/*.msi retention-days: 5 if-no-files-found: error - - name: Upload x64 setup - id: x64_setup + - name: Upload mimalloc x64 setup uses: actions/upload-artifact@v4 with: - name: psqlODBC x64 Setup - path: ./installer/psqlodbc-setup/bin/Release/psqlodbc-setup.exe + name: psqlODBC mimalloc x64 Setup + path: winbuild/mimalloc/installer/psqlodbc-setup/bin/Release/psqlodbc-setup.exe retention-days: 5 if-no-files-found: error @@ -261,4 +305,4 @@ jobs: draft: false prerelease: false token: ${{secrets.RELEASE_TOKEN}} - artifacts: "./installer/x86/*.msi,./installer/x86/*.msm,./installer/psqlodbc-setup/bin/Release/psqlodbc-setup.exe" + artifacts: "winbuild/standard/installer/x86/*.msi,winbuild/standard/installer/x86/*.msm,winbuild/standard/installer/psqlodbc-setup/bin/Release/psqlodbc-setup.exe"