Skip to content

Commit

Permalink
Remove TargetPlatform before start test host (#3170)
Browse files Browse the repository at this point in the history
Remove TargetPlatform before start test host
  • Loading branch information
MarcoRossignoli authored Nov 15, 2021
1 parent c800707 commit a413f44
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
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

0 comments on commit a413f44

Please sign in to comment.