From 4ee015f721fb86d1b14c6d70f534b5117a807dfe Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Tue, 4 Apr 2023 22:00:10 +0200 Subject: [PATCH 01/10] dotnet.exe prints error messages to console when launched with empty DOTNET_MULTILEVEL_LOOKUP --- src/native/corehost/hostmisc/pal.windows.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 4dd632ac88d336..6731b7bf808913 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -570,14 +570,18 @@ bool pal::getenv(const char_t* name, string_t* recv) auto err = GetLastError(); if (err != ERROR_ENVVAR_NOT_FOUND) { - trace::error(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); + trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); } return false; } auto buf = new char_t[length]; if (::GetEnvironmentVariableW(name, buf, length) == 0) { - trace::error(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); + auto err = GetLastError(); + if (err != ERROR_ENVVAR_NOT_FOUND) + { + trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); + } return false; } From d280386c2be3f409caf590abf12480b1c04ccbbd Mon Sep 17 00:00:00 2001 From: Badre BSAILA <54767641+pedrobsaila@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:55:18 +0200 Subject: [PATCH 02/10] reuse err variable instead of invoking GetLastError another time Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com> --- src/native/corehost/hostmisc/pal.windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 6731b7bf808913..6e9009a8e0f505 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -580,7 +580,7 @@ bool pal::getenv(const char_t* name, string_t* recv) auto err = GetLastError(); if (err != ERROR_ENVVAR_NOT_FOUND) { - trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); + trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(err)); } return false; } From 88113dca59394e5ce84abf2a07266f6841271ec3 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Thu, 6 Apr 2023 22:56:58 +0200 Subject: [PATCH 03/10] another useless call to GetLastError --- src/native/corehost/hostmisc/pal.windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 6e9009a8e0f505..6afca1fe41de6c 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -570,7 +570,7 @@ bool pal::getenv(const char_t* name, string_t* recv) auto err = GetLastError(); if (err != ERROR_ENVVAR_NOT_FOUND) { - trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError())); + trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(err)); } return false; } From eb22faca0ea784b9bf6246e00ed607bbed4b2cde Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 8 Apr 2023 23:22:21 +0200 Subject: [PATCH 04/10] add tests --- src/installer/tests/HostActivation.Tests/StartupHooks.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index 7f71bb83baa102..c847a29e4c072f 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -173,11 +173,14 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() var startupHookVar = ""; dotnet.Exec(appDll) .EnvironmentVariable(startupHookVarName, startupHookVar) + .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") + .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .CaptureStdOut() .CaptureStdErr() .Execute() .Should().Pass() - .And.HaveStdOutContaining("Hello World"); + .And.HaveStdOutContaining("Hello World") + .And.NotHaveStdErrContaining("Failed to read environment variable"); } // Run the app with a startup hook assembly that depends on assemblies not on the TPA list From 5beffa04c434fd82b84cc20ab8c058fae7e0b28b Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 8 Apr 2023 23:22:39 +0200 Subject: [PATCH 05/10] fix spacing --- src/installer/tests/HostActivation.Tests/StartupHooks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index c847a29e4c072f..6ca5747a6deee3 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -174,7 +174,7 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() dotnet.Exec(appDll) .EnvironmentVariable(startupHookVarName, startupHookVar) .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") - .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") + .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .CaptureStdOut() .CaptureStdErr() .Execute() From 63c3c94f29afde51484828eb4b2c377c5f2f5082 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 8 Apr 2023 23:54:19 +0200 Subject: [PATCH 06/10] add asserts to another test --- .../HostActivation.Tests/PortableAppActivation.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs index 923517816010d7..ffa0e3f2063a0f 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -198,11 +198,14 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .MultilevelLookup(false) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) + .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") + .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .DotNetRoot(null) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) + .And.NotHaveStdErrContaining("Failed to read environment variable"); ; // Verify running from within the working directory Command.Create(appExe) @@ -212,11 +215,14 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .WorkingDirectory(fixture.TestProject.OutputDirectory) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) + .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") + .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .DotNetRoot(null) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) + .And.NotHaveStdErrContaining("Failed to read environment variable"); ; } } From 739aad93b97d196570c68528a42940500b995905 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sun, 9 Apr 2023 00:12:09 +0200 Subject: [PATCH 07/10] delete empty instruction --- .../tests/HostActivation.Tests/PortableAppActivation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs index ffa0e3f2063a0f..cd964c84769bcd 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -205,7 +205,7 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) - .And.NotHaveStdErrContaining("Failed to read environment variable"); ; + .And.NotHaveStdErrContaining("Failed to read environment variable"); // Verify running from within the working directory Command.Create(appExe) @@ -222,7 +222,7 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) - .And.NotHaveStdErrContaining("Failed to read environment variable"); ; + .And.NotHaveStdErrContaining("Failed to read environment variable"); } } From 95540b70271e8335c86478d41d96df760e7bc146 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Mon, 10 Apr 2023 11:20:15 +0200 Subject: [PATCH 08/10] use EnableTracingAndCaptureOutputs --- .../HostActivation.Tests/PortableAppActivation.cs | 10 ++-------- .../tests/HostActivation.Tests/StartupHooks.cs | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs index cd964c84769bcd..ab2bffb96ad8bb 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -193,13 +193,10 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere // Verify running with the default working directory Command.Create(appExe) - .CaptureStdErr() - .CaptureStdOut() + .EnableTracingAndCaptureOutputs() .MultilevelLookup(false) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) - .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") - .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .DotNetRoot(null) .Execute() .Should().Pass() @@ -209,14 +206,11 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere // Verify running from within the working directory Command.Create(appExe) - .CaptureStdErr() - .CaptureStdOut() + .EnableTracingAndCaptureOutputs() .MultilevelLookup(false) .WorkingDirectory(fixture.TestProject.OutputDirectory) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) - .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") - .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") .DotNetRoot(null) .Execute() .Should().Pass() diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index 6ca5747a6deee3..dfce8020e9de7f 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -173,10 +173,7 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() var startupHookVar = ""; dotnet.Exec(appDll) .EnvironmentVariable(startupHookVarName, startupHookVar) - .EnvironmentVariable(Constants.HostTracing.TraceLevelEnvironmentVariable, "1") - .EnvironmentVariable(Constants.HostTracing.VerbosityEnvironmentVariable, "2") - .CaptureStdOut() - .CaptureStdErr() + .EnableTracingAndCaptureOutputs() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") From c23a2eeb4908f3a3eb3fd14ce473fe58368c788a Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Tue, 11 Apr 2023 00:54:05 +0200 Subject: [PATCH 09/10] check just that no error is logged --- .../HostActivation.Tests/PortableAppActivation.cs | 10 ++++++---- .../tests/HostActivation.Tests/StartupHooks.cs | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs index ab2bffb96ad8bb..782d46b05d9145 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -193,7 +193,8 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere // Verify running with the default working directory Command.Create(appExe) - .EnableTracingAndCaptureOutputs() + .CaptureStdErr() + .CaptureStdOut() .MultilevelLookup(false) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet) @@ -202,11 +203,12 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) - .And.NotHaveStdErrContaining("Failed to read environment variable"); + .And.NotHaveStdErr(); // Verify running from within the working directory Command.Create(appExe) - .EnableTracingAndCaptureOutputs() + .CaptureStdErr() + .CaptureStdOut() .MultilevelLookup(false) .WorkingDirectory(fixture.TestProject.OutputDirectory) .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride) @@ -216,7 +218,7 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion) - .And.NotHaveStdErrContaining("Failed to read environment variable"); + .And.NotHaveStdErr(); } } diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index dfce8020e9de7f..d6e25f3e05c51f 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -173,11 +173,12 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() var startupHookVar = ""; dotnet.Exec(appDll) .EnvironmentVariable(startupHookVarName, startupHookVar) - .EnableTracingAndCaptureOutputs() + .CaptureStdErr() + .CaptureStdOut() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.NotHaveStdErrContaining("Failed to read environment variable"); + .And.NotHaveStdErr(); } // Run the app with a startup hook assembly that depends on assemblies not on the TPA list From cfcf4987933152cea27f65ff2b5a78b908383dd2 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Tue, 11 Apr 2023 00:55:01 +0200 Subject: [PATCH 10/10] rollback change correctly --- src/installer/tests/HostActivation.Tests/StartupHooks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/tests/HostActivation.Tests/StartupHooks.cs b/src/installer/tests/HostActivation.Tests/StartupHooks.cs index d6e25f3e05c51f..cbe7fd3e07c151 100644 --- a/src/installer/tests/HostActivation.Tests/StartupHooks.cs +++ b/src/installer/tests/HostActivation.Tests/StartupHooks.cs @@ -173,8 +173,8 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds() var startupHookVar = ""; dotnet.Exec(appDll) .EnvironmentVariable(startupHookVarName, startupHookVar) - .CaptureStdErr() .CaptureStdOut() + .CaptureStdErr() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World")