Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TargetPlatform before start test host #3170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ public string RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, Action
updatedRunSettingsXml = InferRunSettingsHelper.MakeRunsettingsCompatible(runsettingsXml);
}

// We can remove "TargetPlatform" because is not needed, process is already in a "specific" target platform after test host process start,
// so the default architecture is always the correct one.
// This allow us to support new architecture enumeration without the need to update old test sdk.
updatedRunSettingsXml = InferRunSettingsHelper.RemoveTargetPlatformElement(updatedRunSettingsXml);

return updatedRunSettingsXml;
}

Expand Down
54 changes: 33 additions & 21 deletions src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public class InferRunSettingsHelper
/// <param name="runsettingsXml">string content of runsettings </param>
/// <returns>compatible runsettings</returns>
public static string MakeRunsettingsCompatible(string runsettingsXml)
{
// These are the list of valid RunConfiguration setting name which old testhost understand.
var listOfValidRunConfigurationSettings = new HashSet<string>
{
"TargetPlatform",
"TargetFrameworkVersion",
"TestAdaptersPaths",
"ResultsDirectory",
"SolutionDirectory",
"MaxCpuCount",
"DisableParallelization",
"DisableAppDomain"
};
return MakeRunsettingsCompatible(runsettingsXml, listOfValidRunConfigurationSettings, null);
}

private static string MakeRunsettingsCompatible(string runsettingsXml, HashSet<string> listOfValidRunConfigurationSettings, HashSet<string> listOfInValidRunConfigurationSettings)
{
var updatedRunSettingsXml = runsettingsXml;

Expand All @@ -80,31 +97,23 @@ public static string MakeRunsettingsCompatible(string runsettingsXml)
}
else if (runSettingsNavigator.HasChildren)
{
var listOfInValidRunConfigurationSettings = new List<string>();

// These are the list of valid RunConfiguration setting name which old testhost understand.
var listOfValidRunConfigurationSettings = new HashSet<string>
if (listOfInValidRunConfigurationSettings is null)
{
"TargetPlatform",
"TargetFrameworkVersion",
"TestAdaptersPaths",
"ResultsDirectory",
"SolutionDirectory",
"MaxCpuCount",
"DisableParallelization",
"DisableAppDomain"
};
listOfInValidRunConfigurationSettings = new HashSet<string>();
}

// Find all invalid RunConfiguration Settings
runSettingsNavigator.MoveToFirstChild();
do
if (listOfValidRunConfigurationSettings != null)
{
if (!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName))
do
{
listOfInValidRunConfigurationSettings.Add(runSettingsNavigator.LocalName);
}

} while (runSettingsNavigator.MoveToNext());
if (!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName))
{
listOfInValidRunConfigurationSettings.Add(runSettingsNavigator.LocalName);
}
} while (runSettingsNavigator.MoveToNext());
}

// Delete all invalid RunConfiguration Settings
if (listOfInValidRunConfigurationSettings.Count > 0)
Expand Down Expand Up @@ -134,6 +143,9 @@ public static string MakeRunsettingsCompatible(string runsettingsXml)
return updatedRunSettingsXml;
}

public static string RemoveTargetPlatformElement(string runsettingsXml)
=> MakeRunsettingsCompatible(runsettingsXml, null, new HashSet<string> { "TargetPlatform" });

/// <summary>
/// Updates the run settings XML with the specified values.
/// </summary>
Expand Down Expand Up @@ -330,7 +342,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio
}
}

if(legacySettingElements.Count > 0)
if (legacySettingElements.Count > 0)
{
legacySettingsTelemetry.Add(LegacyElementsString, string.Join(", ", legacySettingElements));
}
Expand All @@ -350,7 +362,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio
}
}
}
catch(Exception ex)
catch (Exception ex)
{
EqtTrace.Error("Error while trying to read legacy settings. Message: {0}", ex.ToString());
return false;
Expand Down