Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Explicitly set DOTNET_MULTILEVEL_LOOKUP in tests (#7541)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Aug 2, 2019
1 parent ccf0024 commit 9b9814c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 95 deletions.
12 changes: 12 additions & 0 deletions src/test/HostActivation.Tests/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public static Command EnableTracingAndCaptureOutputs(this Command command)
.CaptureStdErr();
}

public static Command DotNetRoot(this Command command, string dotNetRoot)
{
return command
.EnvironmentVariable("DOTNET_ROOT", dotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", dotNetRoot);
}

public static Command MultilevelLookup(this Command command, bool enable)
{
return command.EnvironmentVariable(Constants.MultilevelLookup.EnvironmentVariable, enable ? "1" : "0");
}

public static Command RuntimeId(this Command command, string rid)
{
return command.EnvironmentVariable(Constants.RuntimeId.EnvironmentVariable, rid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public CommandResult RunComponentResolutionTest(string componentPath, TestApp ho
};

Command command = Command.Create(NativeHostPath, args)
.EnableTracingAndCaptureOutputs();
.EnableTracingAndCaptureOutputs()
.MultilevelLookup(false);
commandCustomizer?.Invoke(command);

return command.Execute()
Expand All @@ -86,6 +87,7 @@ public CommandResult RunComponentResolutionMultiThreadedTest(string componentOne

return Command.Create(NativeHostPath, args)
.EnableTracingAndCaptureOutputs()
.MultilevelLookup(false)
.Execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ protected CommandResult RunTest(
}

CommandResult result = command
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", multiLevelLookup ? "1" : "0")
.EnableTracingAndCaptureOutputs()
.MultilevelLookup(multiLevelLookup)
.Environment(settings.Environment)
.CaptureStdOut()
.CaptureStdErr()
.Execute();

resultAction?.Invoke(result);
Expand Down
1 change: 1 addition & 0 deletions src/test/HostActivation.Tests/MockCoreClrSanity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Muxer_ExecAppSequence()
DotNet.Exec("--roll-forward-on-no-candidate-fx", "2", appDll, "argumentOne", "arg2")
.CaptureStdOut()
.CaptureStdErr()
.MultilevelLookup(false)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("mock coreclr_initialize() called")
Expand Down
40 changes: 24 additions & 16 deletions src/test/HostActivation.Tests/NativeHosting/Comhost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public void ActivateClass(int count, bool synchronous)
return;
}

string scenario = synchronous ? "synchronous" : "concurrent";
string args = $"comhost {scenario} {count} {sharedState.ComHostPath} {sharedState.ClsidString}";
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.EnableTracingAndCaptureOutputs()
.EnvironmentVariable("DOTNET_ROOT", sharedState.ComLibraryFixture.BuiltDotnet.BinPath)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.ComLibraryFixture.BuiltDotnet.BinPath)
string [] args = {
"comhost",
synchronous ? "synchronous" : "concurrent",
$"{count}",
sharedState.ComHostPath,
sharedState.ClsidString
};
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.ComLibraryFixture.BuiltDotnet.BinPath)
.Execute();

result.Should().Pass()
Expand Down Expand Up @@ -64,11 +66,14 @@ public void ActivateClass_IgnoreAppLocalHostFxr()
fixture.TestProject.BuiltApp.Location,
$"{ fixture.TestProject.AssemblyName }.comhost.dll");

string args = $"comhost synchronous 1 {comHostWithAppLocalFxr} {sharedState.ClsidString}";
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.EnableTracingAndCaptureOutputs()
.EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath)
.EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath)
string[] args = {
"comhost",
"synchronous",
"1",
comHostWithAppLocalFxr,
sharedState.ClsidString
};
CommandResult result = sharedState.CreateNativeHostCommand(args, fixture.BuiltDotnet.BinPath)
.Execute();

result.Should().Pass()
Expand Down Expand Up @@ -98,11 +103,14 @@ public void ActivateClass_ValidateIErrorInfoResult()
fixture.TestProject.BuiltApp.Location,
$"{ fixture.TestProject.AssemblyName }.comhost.dll");

string args = $"comhost errorinfo 1 {comHost} {sharedState.ClsidString}";
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.EnableTracingAndCaptureOutputs()
.EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath)
.EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath)
string[] args = {
"comhost",
"errorinfo",
"1",
comHost,
sharedState.ClsidString
};
CommandResult result = sharedState.CreateNativeHostCommand(args, fixture.BuiltDotnet.BinPath)
.Execute();

result.Should().Pass()
Expand Down
21 changes: 3 additions & 18 deletions src/test/HostActivation.Tests/NativeHosting/ComponentActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ public void CallDelegate(bool validPath, bool validType, bool validMethod)
validType ? sharedState.ComponentTypeName : $"Component.BadType, {componentProject.AssemblyName}",
validMethod ? sharedState.ComponentEntryPoint1 : "BadMethod",
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should()
Expand Down Expand Up @@ -90,12 +85,7 @@ public void CallDelegate_MultipleEntryPoints(int callCount)
args = args.Concat(componentInfo);
}

CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
Expand Down Expand Up @@ -139,12 +129,7 @@ public void CallDelegate_MultipleComponents(int callCount)
args = args.Concat(componentInfo);
}

CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
Expand Down
49 changes: 7 additions & 42 deletions src/test/HostActivation.Tests/NativeHosting/HostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ public void RunApp(CommandLine commandLine, bool isSelfContained, string checkPr
SharedTestState.AppPropertyName,
newPropertyName
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args.Concat(commandArgs).Concat(appArgs))
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args.Concat(commandArgs).Concat(appArgs), sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
Expand Down Expand Up @@ -176,12 +171,7 @@ public void GetDelegate(string checkProperties)
SharedTestState.ConfigPropertyName,
newPropertyName
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
Expand All @@ -203,12 +193,7 @@ public void InitializeConfig_SelfContained_Fails()
sharedState.SelfContainedHostFxrPath,
sharedState.SelfContainedConfigPath
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Fail()
Expand Down Expand Up @@ -236,12 +221,7 @@ public void GetDelegate_Multiple(string checkProperties)
SharedTestState.ConfigPropertyName,
SharedTestState.SecondaryConfigPropertyName
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
Expand Down Expand Up @@ -289,13 +269,8 @@ public void RunApp_GetDelegate(string scenario, string checkProperties)
SharedTestState.AppPropertyName,
SharedTestState.ConfigPropertyName
};
CommandResult result = Command.Create(sharedState.NativeHostPath, args.Concat(appArgs))
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
CommandResult result = sharedState.CreateNativeHostCommand(args.Concat(appArgs), sharedState.DotNetRoot)
.EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
.EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block")
.EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal")
.Execute();
Expand Down Expand Up @@ -380,13 +355,8 @@ public void CompatibilityCheck_Frameworks(string scenario, string frameworkName,
CommandResult result;
try
{
result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
.EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block")
.EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal")
.Execute();
Expand Down Expand Up @@ -476,13 +446,8 @@ public void CompatibilityCheck_Properties(string scenario, bool hasMultiplePrope
CommandResult result;
try
{
result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.EnvironmentVariable("COREHOST_TRACE_VERBOSITY", "3")
.EnvironmentVariable("DOTNET_ROOT", sharedState.DotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.DotNetRoot)
.EnvironmentVariable("TEST_BLOCK_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.block")
.EnvironmentVariable("TEST_SIGNAL_MOCK_EXECUTE_ASSEMBLY", $"{sharedState.AppPath}.signal")
.Execute();
Expand Down
3 changes: 1 addition & 2 deletions src/test/HostActivation.Tests/NativeHosting/Nethost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public void GetHostFxrPath_DotNetRootEnvironment(bool explicitLoad, bool useAsse
string dotNetRoot = isValid ? Path.Combine(sharedState.ValidInstallRoot, "dotnet") : sharedState.InvalidInstallRoot;
CommandResult result = Command.Create(sharedState.NativeHostPath, $"{GetHostFxrPath} {explicitLoad} {(useAssemblyPath ? sharedState.TestAssemblyPath : string.Empty)}")
.EnableTracingAndCaptureOutputs()
.EnvironmentVariable("DOTNET_ROOT", dotNetRoot)
.EnvironmentVariable("DOTNET_ROOT(x86)", dotNetRoot)
.DotNetRoot(dotNetRoot)
.Execute();

result.Should().HaveStdErrContaining("Using environment variable");
Expand Down
10 changes: 10 additions & 0 deletions src/test/HostActivation.Tests/NativeHosting/SharedTestStateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.DotNet.Cli.Build.Framework;
using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting
Expand Down Expand Up @@ -37,6 +39,14 @@ public SharedTestStateBase()
NethostPath);
}

public Command CreateNativeHostCommand(IEnumerable<string> args, string dotNetRoot)
{
return Command.Create(NativeHostPath, args)
.EnableTracingAndCaptureOutputs()
.DotNetRoot(dotNetRoot)
.MultilevelLookup(false);
}

public void Dispose()
{
Dispose(true);
Expand Down
19 changes: 8 additions & 11 deletions src/test/HostActivation.Tests/PortableAppActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ public void Muxer_Activation_With_Templated_AdditionalProbingPath_Succeeds()
"exec",
"--additionalprobingpath", additionalProbingPath,
appDll)
.EnvironmentVariable("COREHOST_TRACE", "1")
.EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
Expand Down Expand Up @@ -279,8 +276,8 @@ public void Framework_Dependent_AppHost_Succeeds()
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("DOTNET_ROOT", builtDotnet)
.EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet)
.DotNetRoot(builtDotnet)
.MultilevelLookup(false)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
Expand All @@ -290,8 +287,8 @@ public void Framework_Dependent_AppHost_Succeeds()
// Verify running from within the working directory
Command.Create(appExe)
.WorkingDirectory(fixture.TestProject.OutputDirectory)
.EnvironmentVariable("DOTNET_ROOT", builtDotnet)
.EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet)
.DotNetRoot(builtDotnet)
.MultilevelLookup(false)
.CaptureStdErr()
.CaptureStdOut()
.Execute()
Expand Down Expand Up @@ -347,6 +344,7 @@ public void Framework_Dependent_AppHost_From_Global_Location_Succeeds(bool useRe
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.MultilevelLookup(false)
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
.Execute()
Expand All @@ -358,6 +356,7 @@ public void Framework_Dependent_AppHost_From_Global_Location_Succeeds(bool useRe
Command.Create(appExe)
.CaptureStdErr()
.CaptureStdOut()
.MultilevelLookup(false)
.WorkingDirectory(fixture.TestProject.OutputDirectory)
.ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
.EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
Expand All @@ -378,9 +377,7 @@ public void ComputedTPADoesntEndWithPathSeparator()
var appDll = fixture.TestProject.AppDll;

dotnet.Exec(appDll)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdErrMatching($"Property TRUSTED_PLATFORM_ASSEMBLIES = .*[^{Path.PathSeparator}]$", System.Text.RegularExpressions.RegexOptions.Multiline);
Expand Down
3 changes: 2 additions & 1 deletion src/test/TestUtils/DotNetCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public Command Exec(string command, params string[] args)
}

return Command.Create(DotnetExecutablePath, newArgs)
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1")
.EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0"); // Avoid looking at machine state by default
}

public Command Restore(params string[] args) => Exec("restore", args);
Expand Down

0 comments on commit 9b9814c

Please sign in to comment.