/// <summary> /// Execute the tests within the specified test set /// </summary> /// <param name="vm">Test explorer view model</param> /// <param name="setToRun">Test set to run</param> /// <param name="token">Token to cancel tests</param> private async Task ExecuteSetTestsAsync(TestExplorerToolWindowViewModel vm, TestSetItem setToRun, CancellationToken token) { if (token.IsCancellationRequested) { return; } // --- Prepare test set for testing setToRun.Log("Test set execution started"); var watch = new Stopwatch(); watch.Start(); try { // --- Set the test set machine context setToRun.Plan.MachineContext = this; // --- Set the startup state of the Spectrum VM var startup = await Package.StateFileManager.SetProjectMachineStartupState(setToRun.Plan.Sp48Mode); if (!startup) { throw new TaskCanceledException(); } // --- Inject the source code into the vm var plan = setToRun.Plan; Package.CodeManager.InjectCodeIntoVm(plan.CodeOutput); // --- Set up registers with default values ExecuteAssignment(plan.InitAssignments); // --- Iterate through individual test cases foreach (var testToRun in setToRun.TestsToRun) { if (token.IsCancellationRequested) { return; } testToRun.State = TestState.Running; SetTestSetState(setToRun); await ExecuteTestsAsync(vm, testToRun, token); SetTestSetState(setToRun); vm.UpdateCounters(); } // --- Stop the Spectrum VM await Package.MachineViewModel.Stop(); } catch (Exception ex) { HandleException(setToRun, ex); } finally { watch.Stop(); // --- Mark inconclusive tests setToRun.TestsToRun.ForEach(i => { if (i.State == TestState.NotRun) { SetSubTreeState(i, TestState.Inconclusive); } }); SetTestSetState(setToRun); // --- Report outcome vm.UpdateCounters(); ReportEllapsedTime("Test set", setToRun, watch); } }
/// <summary> /// Set the state of the test set node according to its tests' state /// </summary> /// <param name="setToRun">Test set node</param> private static void SetTestSetState(TestSetItem setToRun) { SetTestItemState(setToRun, setToRun.ChildItems); }