From 8e6e8255d593a9315631f3adaa3a2e189426f1a1 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 bbb6fabb30b79f..d62c4374753a2c 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 dbcde1315a227973e512eeeebfe822c0d5cbda4c 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 d62c4374753a2c..5f5da1cc794ca5 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 279a6139cea1f63a0cc7bcbb797d3ab58944a3e0 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 5f5da1cc794ca5..f5155933cba813 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 0856c2dd9893431716a6cd01be93dc47f9319121 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 565116b673a1536ede9d7a323b57b5e3518a45e2 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 f702c6ca33c6a2447760c6bf186770259bdb7edc 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 ca97f1f8e01656..a63fa564a8d92c 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -318,11 +318,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) @@ -332,11 +335,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 45dcab080f5231a04caf2dd83af7724bc36aa169 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 a63fa564a8d92c..3febff3bce2222 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -325,7 +325,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) @@ -342,7 +342,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 e30855d4f933be5f0ed02334f250d86c12a7d4f9 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 3febff3bce2222..5bf25c3a2a7acb 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -313,13 +313,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() @@ -329,14 +326,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 7193ae2264437c6cb5e29946b4b220f6dee5b63b 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 5bf25c3a2a7acb..1c7e8683c4563e 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -313,7 +313,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) @@ -322,11 +323,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) @@ -336,7 +338,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 ea496fb515fa4312fefbbe40446c884e0cde0679 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")