From a23bd54750c53e6a2f50f5e3c0d647eee0df2b02 Mon Sep 17 00:00:00 2001 From: David Machaj <46852402+dmachaj@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:04:17 -0800 Subject: [PATCH 1/4] Add a stress test project that includes every single projected SDK header and treats warnings as errors --- cppwinrt.sln | 20 ++++ .../stress_test/GeneratePrecompiledHeader.ps1 | 26 +++++ test/stress_test/main.cpp | 7 ++ test/stress_test/pch.cpp | 1 + test/stress_test/stress_test.vcxproj | 99 +++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 test/stress_test/GeneratePrecompiledHeader.ps1 create mode 100644 test/stress_test/main.cpp create mode 100644 test/stress_test/pch.cpp create mode 100644 test/stress_test/stress_test.vcxproj diff --git a/cppwinrt.sln b/cppwinrt.sln index 5964f976b..b471f7916 100644 --- a/cppwinrt.sln +++ b/cppwinrt.sln @@ -132,6 +132,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution run_tests.cmd = run_tests.cmd EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stress_test", "test\stress_test\stress_test.vcxproj", "{FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}" + ProjectSection(ProjectDependencies) = postProject + {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} = {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} + {D613FB39-5035-4043-91E2-BAB323908AF4} = {D613FB39-5035-4043-91E2-BAB323908AF4} + {F1C915B3-2C64-4992-AFB7-7F035B1A7607} = {F1C915B3-2C64-4992-AFB7-7F035B1A7607} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -394,6 +401,18 @@ Global {D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Release|x64.Build.0 = Release|x64 {D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Release|x86.ActiveCfg = Release|Win32 {D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Release|x86.Build.0 = Release|Win32 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|ARM64.Build.0 = Debug|ARM64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|x64.ActiveCfg = Debug|x64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|x64.Build.0 = Debug|x64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|x86.ActiveCfg = Debug|Win32 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Debug|x86.Build.0 = Debug|Win32 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|ARM64.ActiveCfg = Release|ARM64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|ARM64.Build.0 = Release|ARM64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|x64.ActiveCfg = Release|x64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|x64.Build.0 = Release|x64 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|x86.ActiveCfg = Release|Win32 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -417,6 +436,7 @@ Global {08C40663-B6A3-481E-8755-AE32BAD99501} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0} {5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0} {D4C8F881-84D5-4A7B-8BDE-AB4E34A05374} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0} + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2783B8FD-EA3B-4D6B-9F81-662D289E02AA} diff --git a/test/stress_test/GeneratePrecompiledHeader.ps1 b/test/stress_test/GeneratePrecompiledHeader.ps1 new file mode 100644 index 000000000..0d91b994c --- /dev/null +++ b/test/stress_test/GeneratePrecompiledHeader.ps1 @@ -0,0 +1,26 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$true)] + [string]$generatedFilesDir, + + [Parameter(Mandatory=$true)] + [string]$cppwinrtHeaderFolder +) + +if (!(Test-Path $generatedFilesDir)) +{ + mkdir $generatedFilesDir; +} + +$generatedPchContent = "#pragma once`r`n`r`n"; + +$allHeaders = Get-ChildItem "$cppwinrtHeaderFolder\\Windows.*.h"; +foreach ($header in $allHeaders) +{ + $chunks = $header.FullName.Split("\\"); + $header = $chunks[$chunks.Length - 1]; + $generatedPchContent += "#include `r`n"; +} + +Set-Content -Path "$generatedFilesDir\\pch.h" -Value $generatedPchContent -Force -Encoding UTF8 \ No newline at end of file diff --git a/test/stress_test/main.cpp b/test/stress_test/main.cpp new file mode 100644 index 000000000..f12a4d942 --- /dev/null +++ b/test/stress_test/main.cpp @@ -0,0 +1,7 @@ +#include "pch.h" + +using namespace winrt; + +int main() +{ +} diff --git a/test/stress_test/pch.cpp b/test/stress_test/pch.cpp new file mode 100644 index 000000000..1d9f38c57 --- /dev/null +++ b/test/stress_test/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/test/stress_test/stress_test.vcxproj b/test/stress_test/stress_test.vcxproj new file mode 100644 index 000000000..5e781f968 --- /dev/null +++ b/test/stress_test/stress_test.vcxproj @@ -0,0 +1,99 @@ + + + + + Debug + ARM64 + + + Debug + Win32 + + + Release + ARM64 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + true + true + true + true + 16.0 + {FF5FDA08-F84A-4AB1-9D8C-0EC78EA5A08C} + stress_test + stress_test + Application + + ..\_build\$(Platform)\$(Configuration) + false + + + + true + + + false + true + + + + + $(OutputPath);Generated Files;..;..\..\cppwinrt + true + + + Console + + + + powershell.exe -NoProfile -NonInteractive -File "$(ProjectDir)GeneratePrecompiledHeader.ps1" -generatedFilesDir "$(ProjectDir)Generated Files" -cppwinrtHeaderFolder "$(CppWinRTDir)\winrt" + + + + + MaxSpeed + true + true + NOMINMAX;_MBCS;%(PreprocessorDefinitions) + MultiThreaded + + + true + true + + + + + Disabled + _MBCS;%(PreprocessorDefinitions) + MultiThreadedDebug + + + + + Use + + + Create + + + + + + + + + \ No newline at end of file From ffdfecc31985abfe6af90940617409efef4b094e Mon Sep 17 00:00:00 2001 From: David Machaj <46852402+dmachaj@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:42:12 -0800 Subject: [PATCH 2/4] Try to tweak some things so that warnings are detected and break the build --- cppwinrt.sln | 1 - strings/base_macros.h | 4 ++-- test/stress_test/GeneratePrecompiledHeader.ps1 | 2 +- test/stress_test/main.cpp | 6 ++++++ test/stress_test/stress_test.vcxproj | 6 ++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cppwinrt.sln b/cppwinrt.sln index b471f7916..0c0482f61 100644 --- a/cppwinrt.sln +++ b/cppwinrt.sln @@ -136,7 +136,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stress_test", "test\stress_ ProjectSection(ProjectDependencies) = postProject {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} = {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} {D613FB39-5035-4043-91E2-BAB323908AF4} = {D613FB39-5035-4043-91E2-BAB323908AF4} - {F1C915B3-2C64-4992-AFB7-7F035B1A7607} = {F1C915B3-2C64-4992-AFB7-7F035B1A7607} EndProjectSection EndProject Global diff --git a/strings/base_macros.h b/strings/base_macros.h index d9e19547e..5f7cdf0c3 100644 --- a/strings/base_macros.h +++ b/strings/base_macros.h @@ -17,10 +17,10 @@ #ifdef _MSC_VER // Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler. -#pragma warning(disable : 5046) +//#pragma warning(disable : 5046) // Note: this is a workaround for a false-positive warning produced by the Visual C++ 16.3 compiler. -#pragma warning(disable : 4268) +//#pragma warning(disable : 4268) #endif #if defined(__cpp_lib_coroutine) || defined(__cpp_coroutines) || defined(_RESUMABLE_FUNCTIONS_SUPPORTED) diff --git a/test/stress_test/GeneratePrecompiledHeader.ps1 b/test/stress_test/GeneratePrecompiledHeader.ps1 index 0d91b994c..fd276c792 100644 --- a/test/stress_test/GeneratePrecompiledHeader.ps1 +++ b/test/stress_test/GeneratePrecompiledHeader.ps1 @@ -20,7 +20,7 @@ foreach ($header in $allHeaders) { $chunks = $header.FullName.Split("\\"); $header = $chunks[$chunks.Length - 1]; - $generatedPchContent += "#include `r`n"; + $generatedPchContent += "#include `"winrt/$header`"`r`n"; } Set-Content -Path "$generatedFilesDir\\pch.h" -Value $generatedPchContent -Force -Encoding UTF8 \ No newline at end of file diff --git a/test/stress_test/main.cpp b/test/stress_test/main.cpp index f12a4d942..66a992392 100644 --- a/test/stress_test/main.cpp +++ b/test/stress_test/main.cpp @@ -4,4 +4,10 @@ using namespace winrt; int main() { + init_apartment(); + + winrt::Windows::Foundation::Uri uri{ L"https://www.microsoft.com" }; + const auto asString = uri.ToString(); + + return 0; } diff --git a/test/stress_test/stress_test.vcxproj b/test/stress_test/stress_test.vcxproj index 5e781f968..1f072ed34 100644 --- a/test/stress_test/stress_test.vcxproj +++ b/test/stress_test/stress_test.vcxproj @@ -39,6 +39,9 @@ ..\_build\$(Platform)\$(Configuration) false + + + @@ -53,6 +56,9 @@ $(OutputPath);Generated Files;..;..\..\cppwinrt true + + + Console From 71a15b387755e9f404db2928e589904138115f92 Mon Sep 17 00:00:00 2001 From: David Machaj <46852402+dmachaj@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:48:58 -0800 Subject: [PATCH 3/4] Clean back up some after finally detecting the warning Ive been trying to detect --- test/stress_test/GeneratePrecompiledHeader.ps1 | 2 +- test/stress_test/main.cpp | 4 ++++ test/stress_test/stress_test.vcxproj | 15 +++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/stress_test/GeneratePrecompiledHeader.ps1 b/test/stress_test/GeneratePrecompiledHeader.ps1 index fd276c792..0d91b994c 100644 --- a/test/stress_test/GeneratePrecompiledHeader.ps1 +++ b/test/stress_test/GeneratePrecompiledHeader.ps1 @@ -20,7 +20,7 @@ foreach ($header in $allHeaders) { $chunks = $header.FullName.Split("\\"); $header = $chunks[$chunks.Length - 1]; - $generatedPchContent += "#include `"winrt/$header`"`r`n"; + $generatedPchContent += "#include `r`n"; } Set-Content -Path "$generatedFilesDir\\pch.h" -Value $generatedPchContent -Force -Encoding UTF8 \ No newline at end of file diff --git a/test/stress_test/main.cpp b/test/stress_test/main.cpp index 66a992392..b8d2c2422 100644 --- a/test/stress_test/main.cpp +++ b/test/stress_test/main.cpp @@ -9,5 +9,9 @@ int main() winrt::Windows::Foundation::Uri uri{ L"https://www.microsoft.com" }; const auto asString = uri.ToString(); + // Cause the "if constexpr" block to be reachable, possibly triggering a build warning. + winrt::Windows::Networking::Sockets::StreamWebSocket socket{ nullptr }; + socket.Close(1000, L""); + return 0; } diff --git a/test/stress_test/stress_test.vcxproj b/test/stress_test/stress_test.vcxproj index 1f072ed34..f8e034043 100644 --- a/test/stress_test/stress_test.vcxproj +++ b/test/stress_test/stress_test.vcxproj @@ -40,8 +40,9 @@ ..\_build\$(Platform)\$(Configuration) false - - + + + true @@ -55,16 +56,18 @@ $(OutputPath);Generated Files;..;..\..\cppwinrt + AllRules.ruleset true - - - + Level4 + true + AllRules.ruleset + %(AdditionalOptions) /Wv:19.40 + true Console - powershell.exe -NoProfile -NonInteractive -File "$(ProjectDir)GeneratePrecompiledHeader.ps1" -generatedFilesDir "$(ProjectDir)Generated Files" -cppwinrtHeaderFolder "$(CppWinRTDir)\winrt" From ba327d8899bb821c22225ce72dadf1ba1efb2a9c Mon Sep 17 00:00:00 2001 From: David Machaj <46852402+dmachaj@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:47:48 -0800 Subject: [PATCH 4/4] It helps if the project is actually part of the build when getting build results --- .github/workflows/ci.yml | 2 +- .gitignore | 1 + build_test_all.cmd | 1 + run_tests.cmd | 1 + test/stress_test/main.cpp | 4 ---- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f99be8fb..c3f3bf26a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: compiler: [MSVC, clang-cl] arch: [x86, x64, arm64] config: [Debug, Release] - test_exe: [test, test_cpp20, test_cpp20_no_sourcelocation, test_fast, test_slow, test_old, test_module_lock_custom, test_module_lock_none] + test_exe: [test, test_cpp20, test_cpp20_no_sourcelocation, test_fast, test_slow, test_old, test_module_lock_custom, test_module_lock_none, stress_test] exclude: - arch: arm64 config: Debug diff --git a/.gitignore b/.gitignore index 9493fdad5..8a95a64fa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.nupkg test*.xml test*_results.txt +stress_test_results.txt test_failures.txt build packages diff --git a/build_test_all.cmd b/build_test_all.cmd index 4372acfd5..b3f2c229e 100644 --- a/build_test_all.cmd +++ b/build_test_all.cmd @@ -36,5 +36,6 @@ call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platfor call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_module_lock_none call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_module_lock_none call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\old_tests\test_old +call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\stress_test call run_tests.cmd %target_platform% %target_configuration% diff --git a/run_tests.cmd b/run_tests.cmd index 77d883642..49ad986f2 100644 --- a/run_tests.cmd +++ b/run_tests.cmd @@ -16,6 +16,7 @@ call :run_test test_slow call :run_test test_old call :run_test test_module_lock_custom call :run_test test_module_lock_none +call :run_test stress_test goto :eof :run_test diff --git a/test/stress_test/main.cpp b/test/stress_test/main.cpp index b8d2c2422..66a992392 100644 --- a/test/stress_test/main.cpp +++ b/test/stress_test/main.cpp @@ -9,9 +9,5 @@ int main() winrt::Windows::Foundation::Uri uri{ L"https://www.microsoft.com" }; const auto asString = uri.ToString(); - // Cause the "if constexpr" block to be reachable, possibly triggering a build warning. - winrt::Windows::Networking::Sockets::StreamWebSocket socket{ nullptr }; - socket.Close(1000, L""); - return 0; }