Skip to content
Merged
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
77 changes: 54 additions & 23 deletions source/TestAdapter/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,52 @@ private async Task<List<TestResult>> RunTestOnHardwareAsync(List<TestCase> tests
List<TestResult> results = PrepareListResult(tests);
List<byte[]> assemblies = new List<byte[]>();
int retryCount = 0;
NanoDeviceBase device = null;

var serialDebugClient = PortBase.CreateInstanceForSerial(true, 2000);
bool realHardwarePortSet = !string.IsNullOrEmpty(_settings.RealHardwarePort);

retryConnection:
PortBase serialDebugClient;

if (string.IsNullOrEmpty(_settings.RealHardwarePort))
if (realHardwarePortSet)
{
_logger.LogMessage($"Waiting for device enumeration to complete.", Settings.LoggingLevel.Verbose);
serialDebugClient = PortBase.CreateInstanceForSerial(false);

_logger.LogMessage($"Checking device on port {_settings.RealHardwarePort}.", Settings.LoggingLevel.Verbose);

try
{
serialDebugClient.AddDevice(_settings.RealHardwarePort);

device = serialDebugClient.NanoFrameworkDevices[0];

// all good here, proceed to execute tests
goto executeTests;
}
#if DEBUG
catch (Exception ex)
#else
catch
#endif
{
results.First().Outcome = TestOutcome.Failed;
results.First().ErrorMessage = $"Couldn't find any valid nanoDevice @ {_settings.RealHardwarePort}. Maybe try to disable the device watchers in Visual Studio Extension! If the situation persists reboot the device and/or disconnect and connect it again.";

_logger.LogMessage($"Couldn't find any valid nanoDevice @ {_settings.RealHardwarePort}.", Settings.LoggingLevel.Verbose);

return results;
}
}
else
{
_logger.LogMessage($"Checking device on port {_settings.RealHardwarePort}.", Settings.LoggingLevel.Verbose);
serialDebugClient = PortBase.CreateInstanceForSerial(true,
2000);
}

retryConnection:

if (string.IsNullOrEmpty(_settings.RealHardwarePort))
{
_logger.LogMessage($"Waiting for device enumeration to complete.", Settings.LoggingLevel.Verbose);
}

while (!serialDebugClient.IsDevicesEnumerationComplete)
Expand All @@ -220,40 +254,34 @@ private async Task<List<TestResult>> RunTestOnHardwareAsync(List<TestCase> tests
if (retryCount > _numberOfRetries)
{
results.First().Outcome = TestOutcome.Failed;
results.First().ErrorMessage = $"Couldn't find any device, please try to disable the device scanning in the Visual Studio Extension! If the situation persists reboot the device as well.";
results.First().ErrorMessage = "Couldn't find any valid nanoDevice. Maybe try to disable the device watchers in Visual Studio Extension! If the situation persists reboot the device and/or disconnect and connect it again.";

_logger.LogMessage("Couldn't find any valid nanoDevice.", Settings.LoggingLevel.Verbose);

return results;
}
else
{
// add retry counter before trying again
retryCount++;

// re-scan devices
serialDebugClient.ReScanDevices();

goto retryConnection;
}
}

retryCount = 0;
NanoDeviceBase device;

if (serialDebugClient.NanoFrameworkDevices.Count > 1
&& !string.IsNullOrEmpty(_settings.RealHardwarePort))
{
// get the device at the requested COM port (if there is one)
device = serialDebugClient.NanoFrameworkDevices.FirstOrDefault(m => m.SerialNumber == _settings.RealHardwarePort);

// sanity check
if (device is null)
{
// no device, done here
_logger.LogMessage($"No device available at {_settings.RealHardwarePort}.", Settings.LoggingLevel.Verbose);
return results;
}
}
else
if (serialDebugClient.NanoFrameworkDevices.Count > 1)
{
// no COM port requested, just grab the 1st one
// grab the 1st device available
device = serialDebugClient.NanoFrameworkDevices[0];
}

executeTests:

_logger.LogMessage(
$"Getting things ready with {device.Description}",
Settings.LoggingLevel.Detailed);
Expand Down Expand Up @@ -290,6 +318,7 @@ private async Task<List<TestResult>> RunTestOnHardwareAsync(List<TestCase> tests
}

retryCount = 0;

retryErase:
// erase the device
_logger.LogMessage($"Erase deployment block storage. Attempt {retryCount}/{_numberOfRetries}.", Settings.LoggingLevel.Verbose);
Expand All @@ -300,6 +329,7 @@ private async Task<List<TestResult>> RunTestOnHardwareAsync(List<TestCase> tests
null);

_logger.LogMessage($"Erase result is {eraseResult}.", Settings.LoggingLevel.Verbose);

if (!eraseResult)
{
if (retryCount < _numberOfRetries)
Expand All @@ -318,6 +348,7 @@ private async Task<List<TestResult>> RunTestOnHardwareAsync(List<TestCase> tests
}

retryCount = 0;

// initial check
if (device.DebugEngine.IsDeviceInInitializeState())
{
Expand Down