Skip to content

Commit

Permalink
Improve UpdateNanoCLRInstance (#289)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Dec 26, 2024
1 parent 097d83f commit c149452
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
10 changes: 10 additions & 0 deletions poc/NFUnit Test DemoByReference.ChildProcessDbgSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ChildProcessDebuggingSettings IsEnabled="true" xmlns="http://schemas.microsoft.com/vstudio/ChildProcessDebuggingSettings/2014">
<DefaultRule EngineFilter="[inherit]" />
<Rule IsEnabled="true" ProcessName="TE.ProcessHost.Managed.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.discoveryengine.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.discoveryengine.x86.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.executionengine.n.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.executionengine.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
<Rule IsEnabled="true" ProcessName="vstest.executionengine.x86.exe" EngineFilter="{92ef0900-2251-11d2-b72e-0000f87572ef}" />
</ChildProcessDebuggingSettings>
23 changes: 15 additions & 8 deletions source/TestAdapter/NanoCLRHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,29 @@ public static void UpdateNanoCLRInstance(
"Upate nanoCLR instance",
Settings.LoggingLevel.Verbose);

var arguments = "instance --update";
string arguments = "instance --update";

if (!string.IsNullOrEmpty(clrVersion))
{
arguments += $" --clrversion {clrVersion}";
}

var cmd = Cli.Wrap("nanoclr")
Command cmd = Cli.Wrap("nanoclr")
.WithArguments(arguments)
.WithValidation(CommandResultValidation.None);

// setup cancellation token with a timeout of 1 minute
using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
{
var cliResult = cmd.ExecuteBufferedAsync(cts.Token).Task.Result;
BufferedCommandResult cliResult = cmd.ExecuteBufferedAsync(cts.Token).Task.Result;

if (cliResult.ExitCode == 0)
{
// this will be either (on update):
// Updated to v1.8.1.102
// or (on same version):
// Already at v1.8.1.102
var regexResult = Regex.Match(cliResult.StandardOutput, @"((?>v)(?'version'\d+\.\d+\.\d+\.\d+))");
Match regexResult = Regex.Match(cliResult.StandardOutput, @"((?>v)(?'version'\d+\.\d+\.\d+\.\d+))");

if (regexResult.Success)
{
Expand All @@ -203,17 +203,24 @@ public static void UpdateNanoCLRInstance(
}
else
{
logger.LogPanicMessage($"*** Failed to update nanoCLR instance ***");
LogUpdateFailure(logger, cliResult);
}
}
else
{
logger.LogMessage(
$"Failed to update nanoCLR instance. Exit code {cliResult.ExitCode}.",
Settings.LoggingLevel.Detailed);
LogUpdateFailure(logger, cliResult);
}
}
}

private static void LogUpdateFailure(
LogMessenger logger,
BufferedCommandResult cliResult)
{
logger.LogPanicMessage($"*** Failed to update nanoCLR instance ***");
logger.LogPanicMessage($"\r\nExit code {cliResult.ExitCode}. \r\nOutput: {Environment.NewLine} {cliResult.StandardOutput}");
}

internal class NuGetPackage
{
public string[] Versions { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions source/TestAdapter/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"nanoFramework.TestAdapter": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe",
"commandLineArgs": "E:\\GitHub\\nf-nanoFramework.TestFramework\\poc\\TestOfTestFramework\\bin\\Debug\\NFUnitTest.dll /Settings:E:\\GitHub\\nf-nanoFramework.TestFramework\\poc\\.runsettings /TestAdapterPath:."
"commandLineArgs": "E:\\GitHub\\nf-nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\bin\\Debug\\NFUnitTest.dll /Settings:E:\\GitHub\\nf-nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\nano.runsettings /TestAdapterPath:E:\\GitHub\\nf-nanoFramework.TestFramework\\source\\TestAdapter\\bin\\Debug\\net48",
"workingDirectory": "E:\\GitHub\\nf-nanoFramework.TestFramework\\source\\TestAdapter\\bin\\Debug\\net48",
},
"nanoFramework.TestAdapter Enterprise": {
"commandName": "Executable",
"executablePath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe",
"commandLineArgs": "C:\\Repos\\nanoFramework\\lib-CoreLibrary\\nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\bin\\Debug\\NFUnitTest.dll /Settings:C:\\Repos\\nanoFramework\\lib-CoreLibrary\\nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\.runsettings /TestAdapterPath:."
"commandLineArgs": "C:\\Repos\\nanoFramework\\lib-CoreLibrary\\nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\bin\\Debug\\NFUnitTest.dll /Settings:C:\\Repos\\nanoFramework\\lib-CoreLibrary\\nanoFramework.TestFramework\\poc\\TestOfTestFrameworkByReference\\.runsettings /TestAdapterPath:.",
}
}
}

0 comments on commit c149452

Please sign in to comment.