public void SetUp() { var sysbusRegistrationPoint = new BusRangeRegistration(1337, 666); machine = new Machine(); peripheral = new PeripheralMock(); peripheral2 = new PeripheralMock(); container = new NullRegistrationPointPeripheralContainerMock(machine); registrationPoint = NullRegistrationPoint.Instance; machine.SystemBus.Register(container, sysbusRegistrationPoint); }
public void ShouldRecordAndPlayEvents() { var temporaryFile = TemporaryFilesManager.Instance.GetTemporaryFile(); var machineFactory = new Func <Machine>(() => { var result = new Machine(); var peripheral = new PeripheralMock(result); result.SystemBus.Register(peripheral, 0.To(1)); result.SetLocalName(peripheral, "mock"); return(result); }); ulong evt; IEnumerable <Tuple <ulong, int> > recordedEvents; using (var machine = machineFactory()) { var peripheralMock = (PeripheralMock)machine["sysbus.mock"]; EmulationManager.Instance.Clear(); EmulationManager.Instance.CurrentEmulation.AddMachine(machine); EmulationManager.Instance.CurrentEmulation.StartAll(); machine.RecordTo(temporaryFile, RecordingBehaviour.DomainExternal); for (var i = 0; i < 100; i++) { peripheralMock.Method(i); peripheralMock.MethodTwoArgs(i, 0); Thread.Sleep(EmulationManager.Instance.CurrentEmulation.RandomGenerator.Next(30)); } EmulationManager.Instance.CurrentEmulation.PauseAll(); evt = EmulationManager.Instance.CurrentEmulation.MasterTimeSource.ElapsedVirtualTime.Ticks; recordedEvents = peripheralMock.Events; EmulationManager.Instance.CurrentEmulation.RemoveMachine(machine); } IEnumerable <Tuple <ulong, int> > playedEvents; using (var machine = machineFactory()) { var peripheralMock = (PeripheralMock)machine["sysbus.mock"]; EmulationManager.Instance.Clear(); EmulationManager.Instance.CurrentEmulation.AddMachine(machine); machine.PlayFrom(temporaryFile); EmulationManager.Instance.CurrentEmulation.StartAll(); while (EmulationManager.Instance.CurrentEmulation.MasterTimeSource.ElapsedVirtualTime.Ticks < evt) { Thread.Yield(); } EmulationManager.Instance.CurrentEmulation.PauseAll(); playedEvents = peripheralMock.Events; } CollectionAssert.AreEqual(recordedEvents, playedEvents); TemporaryFilesManager.Instance.Cleanup(); }
public void ShouldRecordAndPlayEvents() { var random = new Random(); var machineThreadFunctionFactory = new Func <BaseClockSource, ThreadStart>(cSource => new ThreadStart(() => { for (var i = 0; i < 100; i++) { Thread.Sleep(10); cSource.Advance(10); } })); var machineFactory = new Func <BaseClockSource, Machine>(cSource => { var sDomain = new SynchronizationDomain(); var result = new Machine(); result.SetClockSource(cSource); result.SyncUnit = 10; result.SyncDomain = sDomain; var peripheral = new PeripheralMock(result, sDomain); result.SystemBus.Register(peripheral, 0.To(1)); result.SetLocalName(peripheral, "mock"); return(result); }); var clockSource = clockSources[0]; var machine = machineFactory(clockSource); var peripheralMock = (PeripheralMock)machine["sysbus.mock"]; machine.RecordTo(temporaryFile.Value); var machineThread = new Thread(machineThreadFunctionFactory(clockSource)); machineThread.Start(); var eventNo = 0; while (!machineThread.Join(0)) { peripheralMock.Method(eventNo++); peripheralMock.MethodTwoArgs(eventNo++, 0); Thread.Sleep(random.Next(30)); } machine.Dispose(); var recordedEvents = peripheralMock.Events; clockSource = clockSources[1]; machine = machineFactory(clockSource); peripheralMock = (PeripheralMock)machine["sysbus.mock"]; machine.PlayFrom(temporaryFile.Value); machineThread = new Thread(machineThreadFunctionFactory(clockSource)); machineThread.Start(); machineThread.Join(); var playedEvents = peripheralMock.Events; CollectionAssert.AreEqual(recordedEvents, playedEvents); }
public void ShouldRecordAndPlayEvents() { var random = new Random(); var machineThreadFunctionFactory = new Func<BaseClockSource, ThreadStart>(cSource => new ThreadStart(() => { for(var i = 0; i < 100; i++) { Thread.Sleep(10); cSource.Advance(10); } })); var machineFactory = new Func<BaseClockSource, Machine>(cSource => { var sDomain = new SynchronizationDomain(); var result = new Machine(); result.SetClockSource(cSource); result.SyncUnit = 10; result.SyncDomain = sDomain; var peripheral = new PeripheralMock(result, sDomain); result.SystemBus.Register(peripheral, 0.To(1)); result.SetLocalName(peripheral, "mock"); return result; }); var clockSource = clockSources[0]; var machine = machineFactory(clockSource); var peripheralMock = (PeripheralMock)machine["sysbus.mock"]; machine.RecordTo(temporaryFile.Value); var machineThread = new Thread(machineThreadFunctionFactory(clockSource)); machineThread.Start(); var eventNo = 0; while(!machineThread.Join(0)) { peripheralMock.Method(eventNo++); peripheralMock.MethodTwoArgs(eventNo++, 0); Thread.Sleep(random.Next(30)); } machine.Dispose(); var recordedEvents = peripheralMock.Events; clockSource = clockSources[1]; machine = machineFactory(clockSource); peripheralMock = (PeripheralMock)machine["sysbus.mock"]; machine.PlayFrom(temporaryFile.Value); machineThread = new Thread(machineThreadFunctionFactory(clockSource)); machineThread.Start(); machineThread.Join(); var playedEvents = peripheralMock.Events; CollectionAssert.AreEqual(recordedEvents, playedEvents); }