private static void _doFaultSimTrace(MyConfig simConfig, IBinInfo binInfo, IEnumerable <TraceRange> glitchRange, out Trace correctSignTraceDataOut, out Trace wrongSignTraceDataOut) { Trace correctSignTraceData = null; Trace wrongSignTraceData = null; try { var normalFipSim = new Simulator(simConfig); simConfig.UseAltData = true; var altFipSim = new Simulator(simConfig); var task1 = Task.Run(() => { Console.WriteLine("Start correct sign trace"); Result correctSignResult; (correctSignResult, correctSignTraceData) = normalFipSim.TraceSimulation(); if (correctSignResult != Result.Completed) { Console.Out.WriteLine("Simulation did not complete; result: " + correctSignResult); Environment.Exit(-1); } Console.WriteLine("Finished correct sign trace"); }); var task2 = Task.Run(() => { Console.WriteLine("Start wrong sign trace"); Result wrongSignResult; (wrongSignResult, wrongSignTraceData) = altFipSim.TraceSimulation(glitchRange); if (wrongSignResult != Result.Failed && wrongSignResult != Result.Timeout) { Console.Out.WriteLine("Simulation did not fail; result: " + wrongSignResult); Environment.Exit(-1); } Console.WriteLine("Finished wrong sign trace"); }); task1.Wait(); task2.Wait(); } catch (SimulationException ex) { Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(); if (ex is PlatformEngineException exception) { exception.Engine.DumpState(Console.Out, binInfo); } Environment.Exit(-1); } correctSignTraceDataOut = correctSignTraceData; wrongSignTraceDataOut = wrongSignTraceData; }
public FaultModelResultsList RunSimulation(IFaultModel[] faultModels, Trace traceData) { var results = new FaultModelResultsList(); var expectedRunsAllModels = faultModels.Aggregate <IFaultModel, ulong>(0, (current, faultModel) => current + faultModel.CountUniqueFaults(traceData)); foreach (var faultModel in faultModels) { var result = new FaultModelResults { Model = faultModel }; if (Debugger.IsAttached) { foreach (var faultDefinition in faultModel.CreateFaultEnumerable(traceData)) { using (var simEngine = CreateEngine()) { var faultResult = _runFaultSimulation(faultDefinition, simEngine); result.Glitches.GetOrAdd(faultResult.Result, new ConcurrentBag <FaultResult>()).Add(faultResult); result.Attempts.Add(faultResult); if (OnGlitchSimulationCompleted != null) { var requestToFinish = OnGlitchSimulationCompleted(expectedRunsAllModels, simEngine, faultResult); if (requestToFinish) { break; } } } } } else { Parallel.ForEach(faultModel.CreateFaultEnumerable(traceData), (faultDefinition, state) => { if (!state.IsStopped) { using (var simEngine = CreateEngine()) { var faultResult = _runFaultSimulation(faultDefinition, simEngine); result.Glitches.GetOrAdd(faultResult.Result, new ConcurrentBag <FaultResult>()).Add(faultResult); result.Attempts.Add(faultResult); if (OnGlitchSimulationCompleted != null) { var requestToFinish = OnGlitchSimulationCompleted(expectedRunsAllModels, simEngine, faultResult); if (requestToFinish) { state.Stop(); } } } } }); } results.Add(result); } return(results); }