当前位置: 首页>>代码示例>>C#>>正文


C# Machine.SetClockSource方法代码示例

本文整理汇总了C#中System.Machine.SetClockSource方法的典型用法代码示例。如果您正苦于以下问题:C# Machine.SetClockSource方法的具体用法?C# Machine.SetClockSource怎么用?C# Machine.SetClockSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Machine的用法示例。


在下文中一共展示了Machine.SetClockSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldBeDescending

 public void ShouldBeDescending()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 100, 100000, Direction.Descending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         machine.Start();
         var oldValue = timer.Limit;
         for(var i = 0; i < 100; i++)
         {
             manualClockSource.AdvanceBySeconds(1);
             var value = timer.Value;
             Assert.Less(value, oldValue, "Timer is not monotonic.");
             oldValue = value;
         }
         machine.Pause();
     }
 }
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:19,代码来源:CoreTimerTest.cs

示例2: ShouldNotExceedLimitAscending

 public void ShouldNotExceedLimitAscending()
 {
     var limit = 100;
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 1, limit, Direction.Ascending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         machine.Start();
         manualClockSource.AdvanceBySeconds(limit - 1);
         for(var i = 0; i < 3; ++i)
         {
             var value = timer.Value;
             Assert.LessOrEqual(value, limit, "Timer exceeded given limit.");
             Assert.GreaterOrEqual(value, 0, "Timer returned negative value.");
             manualClockSource.AdvanceBySeconds(1);
         }
         Thread.Sleep(7);
         machine.Pause();
     }
 }
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:21,代码来源:CoreTimerTest.cs

示例3: ShouldSwitchDirectionProperly

 public void ShouldSwitchDirectionProperly()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 100, 100000, Direction.Ascending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         timer.EventEnabled = true;
         var ticked = false;
         timer.LimitReached += () => ticked = true;
         machine.Start();
         manualClockSource.AdvanceBySeconds(2);
         timer.Direction = Direction.Descending; // and then change the direction
         manualClockSource.AdvanceBySeconds(2);
         Assert.IsTrue(ticked);
       
     }
 }
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:18,代码来源:CoreTimerTest.cs

示例4: ShouldFireAlarmWhenInterruptsAreEnabled

 public void ShouldFireAlarmWhenInterruptsAreEnabled()
 {
     using(var machine = new Machine())
     {
         var timer = new LimitTimer(machine, 1, 10, Direction.Descending, true);
         var manualClockSource = new ManualClockSource();
         machine.SetClockSource(manualClockSource);
         timer.EventEnabled = true;
         var ticked = false;
         timer.LimitReached += () => ticked = true;
         machine.Start();
         // var val =timer.Value;
         manualClockSource.AdvanceBySeconds(110);
         Assert.IsTrue(ticked);
     }
 }
开发者ID:bhuvanchandra,项目名称:emul8,代码行数:16,代码来源:CoreTimerTest.cs

示例5: ShouldRecordAndPlayEvents

        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);
        }
开发者ID:rte-se,项目名称:emul8,代码行数:58,代码来源:SyncDomainsTest.cs


注:本文中的System.Machine.SetClockSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。