public Synchronizer(SynchronizationDomain domain, long syncUnit) { this.domain = domain; cts = new CancellationTokenSource(); currentValue = syncUnit; }
public PeripheralMock(Machine machine, SynchronizationDomain syncDomain) { this.machine = machine; this.syncDomain = syncDomain; events = new Queue<Tuple<long, int>>(); }
public void SetUp() { clockSources = new LazyPool<BaseClockSource>(() => new BaseClockSource()); machines = new LazyPool<Machine>(() => new Machine()); syncDomain = new SynchronizationDomain(); temporaryFile = new Lazy<string>(Path.GetTempFileName); }
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 Synchronizer(SynchronizationDomain domain) { this.domain = domain; cts = new CancellationTokenSource(); }