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