Example #1
0
        public async SystemTasks.Task TestCustomLogger()
        {
            CustomLogger  logger = new CustomLogger();
            Configuration config = Configuration.Create().WithVerbosityEnabled();

            ICoyoteRuntime runtime = RuntimeFactory.Create(config);

            runtime.SetLogger(logger);

            Generator generator = Generator.Create();

            Task task = Task.Run(() =>
            {
                int result = generator.NextInteger(10);
                logger.WriteLine($"Task '{Task.CurrentId}' completed with result '{result}'.");
            });

            await task;

            string expected = @"<RandomLog> Task '' nondeterministically chose ''. Task '' completed with result ''.";
            string actual   = RemoveNonDeterministicValuesFromReport(logger.ToString());

            Assert.Equal(expected, actual);

            logger.Dispose();
        }
Example #2
0
        public async Task TestGraphLoggerCollapsed()
        {
            CustomLogger  logger = new CustomLogger();
            Configuration config = Configuration.Create().WithVerbosityEnabled();

            var graphBuilder = new ActorRuntimeLogGraphBuilder(false);

            graphBuilder.CollapseMachineInstances = true;

            var           tcs     = TaskCompletionSource.Create <bool>();
            IActorRuntime runtime = CreateTestRuntime(config, tcs, logger);

            runtime.RegisterLog(graphBuilder);

            ActorId serverId = runtime.CreateActor(typeof(Server));

            runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId));
            runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId));
            runtime.CreateActor(typeof(Client), new ClientSetupEvent(serverId));

            await WaitAsync(tcs.Task, 5000000);

            await Task.Delay(1000);

            string actual = graphBuilder.Graph.ToString();

            Assert.Contains("<Node Id='Microsoft.Coyote.Production.Tests.Actors.CustomActorRuntimeLogTests+Client.Client' Label='Client'/>", actual);
            Assert.Contains("<Node Id='Microsoft.Coyote.Production.Tests.Actors.CustomActorRuntimeLogTests+Server.Complete' Label='Complete'/>", actual);

            logger.Dispose();
        }
Example #3
0
        public async Task TestGraphLogger()
        {
            CustomLogger  logger = new CustomLogger();
            Configuration config = Configuration.Create().WithVerbosityEnabled();

            var           graphBuilder = new ActorRuntimeLogGraphBuilder(false);
            var           tcs          = TaskCompletionSource.Create <bool>();
            IActorRuntime runtime      = CreateTestRuntime(config, tcs, logger);

            runtime.RegisterLog(graphBuilder);

            runtime.CreateActor(typeof(M));

            await WaitAsync(tcs.Task);

            await Task.Delay(200);

            string expected = @"<DirectedGraph xmlns='http://schemas.microsoft.com/vs/2009/dgml'>
  <Nodes>
    <Node Id='M()' Category='Actor' Group='Expanded'/>
    <Node Id='M().M()' Label='M()'/>
    <Node Id='N()' Category='StateMachine' Group='Expanded'/>
    <Node Id='N().Act' Label='Act'/>
    <Node Id='N().Init' Label='Init'/>
    <Node Id='TestMonitor' Group='Expanded'/>
    <Node Id='TestMonitor.Init' Label='Init'/>
    <Node Id='TestMonitor.OnCompleted' Label='OnCompleted'/>
  </Nodes>
  <Links>
    <Link Source='M().M()' Target='N().Init' Label='E' Index='' EventId='E' HandledBy='Init'/>
    <Link Source='M().M()' Target='TestMonitor.Init' Label='CompletedEvent' Index='' EventId='CompletedEvent'/>
    <Link Source='M()' Target='M().M()' Category='Contains'/>
    <Link Source='N().Act' Target='M().M()' Label='E' Index='' EventId='E'/>
    <Link Source='N().Init' Target='N().Act' Label='E' Index='' EventId='E' HandledBy='Init'/>
    <Link Source='N()' Target='N().Act' Category='Contains'/>
    <Link Source='N()' Target='N().Init' Category='Contains'/>
    <Link Source='TestMonitor.Init' Target='TestMonitor.OnCompleted' Label='CompletedEvent' Index='' EventId='CompletedEvent'/>
    <Link Source='TestMonitor' Target='TestMonitor.Init' Category='Contains'/>
    <Link Source='TestMonitor' Target='TestMonitor.OnCompleted' Category='Contains'/>
  </Links>
</DirectedGraph>
";

            string actual = RemoveNonDeterministicValuesFromReport(graphBuilder.Graph.ToString());

            Assert.Equal(expected, actual);

            logger.Dispose();
        }
Example #4
0
        public void TestCustomLoggerNoVerbosity()
        {
            CustomLogger logger = new CustomLogger();

            PSharpRuntime runtime = PSharpRuntime.Create();

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();

            Assert.Equal("", logger.ToString());

            logger.Dispose();
        }
Example #5
0
        public async Task TestCustomLoggerNoVerbosity()
        {
            CustomLogger logger = new CustomLogger(false);

            var runtime = PSharpRuntime.Create();

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));

            await WaitAsync(tcs.Task);

            Assert.Equal(string.Empty, logger.ToString());

            logger.Dispose();
        }
Example #6
0
        public async Task TestCustomLogger()
        {
            CustomLogger  logger = new CustomLogger();
            Configuration config = Configuration.Create().WithVerbosityEnabled();

            IActorRuntime runtime = RuntimeFactory.Create(config);

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateActor(typeof(M), new SetupEvent(tcs));

            await WaitAsync(tcs.Task);

            await Task.Delay(200);

            string expected = @"<CreateLog> M() was created by task ''.
<StateLog> M() enters state 'Init'.
<ActionLog> M() invoked action 'InitOnEntry' in state 'Init'.
<CreateLog> N() was created by M().
<StateLog> N() enters state 'Init'.
<ActionLog> N() invoked action 'InitOnEntry' in state 'Init'.
<SendLog> M() in state 'Init' sent event 'E' to N().
<EnqueueLog> N() enqueued event 'E'.
<DequeueLog> N() dequeued event 'E' in state 'Init'.
<GotoLog> N() is transitioning from state 'Init' to state 'N.Act'.
<StateLog> N() exits state 'Init'.
<StateLog> N() enters state 'Act'.
<ActionLog> N() invoked action 'ActOnEntry' in state 'Act'.
<SendLog> N() in state 'Act' sent event 'E' to M().
<EnqueueLog> M() enqueued event 'E'.
<DequeueLog> M() dequeued event 'E' in state 'Init'.
<ActionLog> M() invoked action 'Act' in state 'Init'.
";

            string actual = RemoveNonDeterministicValuesFromReport(logger.ToString());

            Assert.Equal(expected, actual);

            logger.Dispose();
        }
Example #7
0
        public async Task TestCustomLogger()
        {
            CustomLogger  logger = new CustomLogger();
            Configuration config = Configuration.Create().WithVerbosityEnabled();

            var           tcs     = TaskCompletionSource.Create <bool>();
            IActorRuntime runtime = CreateTestRuntime(config, tcs, logger);

            runtime.CreateActor(typeof(M));

            await WaitAsync(tcs.Task);

            await Task.Delay(200);

            string expected = @"<CreateLog> M() was created by task ''.
<CreateLog> N() was created by M().
<StateLog> N() enters state 'Init'.
<ActionLog> N() invoked action 'OnInitEntry' in state 'Init'.
<SendLog> M() in state '' sent event 'E' to N().
<EnqueueLog> N() enqueued event 'E'.
<DequeueLog> N() dequeued event 'E' in state 'Init'.
<GotoLog> N() is transitioning from state 'Init' to state 'N.Act'.
<StateLog> N() exits state 'Init'.
<StateLog> N() enters state 'Act'.
<ActionLog> N() invoked action 'ActOnEntry' in state 'Act'.
<SendLog> N() in state 'Act' sent event 'E' to M().
<EnqueueLog> M() enqueued event 'E'.
<DequeueLog> M() dequeued event 'E' in state ''.
<ActionLog> M() invoked action 'Act'.
<MonitorLog> TestMonitor is processing event 'CompletedEvent' in state 'Init'.
<MonitorLog> TestMonitor executed action 'Init[]' in state 'OnCompleted'.
";

            string actual = RemoveNonDeterministicValuesFromReport(logger.ToString());

            actual   = SortLines(actual); // threading makes this non-deterministic otherwise.
            expected = SortLines(expected);
            Assert.Equal(expected, actual);

            logger.Dispose();
        }
Example #8
0
        public async Task TestCustomLogger()
        {
            CustomLogger logger = new CustomLogger(true);

            Configuration config  = Configuration.Create().WithVerbosityEnabled();
            var           runtime = PSharpRuntime.Create(config);

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));

            await WaitAsync(tcs.Task);

            string expected = @"<CreateLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' was created by the runtime.
<StateLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' enters state 'Init'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' in state 'Init' invoked action 'InitOnEntry'.
<CreateLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' was created by machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()'.
<StateLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' enters state 'Init'.
<SendLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' in state 'Init' sent event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E' to machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()'.
<EnqueueLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' enqueued event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E'.
<DequeueLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' in state 'Init' dequeued event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' in state 'Init' invoked action 'Act'.
<SendLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+N()' in state 'Init' sent event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E' to machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()'.
<EnqueueLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' enqueued event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E'.
<DequeueLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' in state 'Init' dequeued event 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+E'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.CustomLoggerTest+M()' in state 'Init' invoked action 'Act'.
";
            string actual   = Regex.Replace(logger.ToString(), "[0-9]", string.Empty);

            HashSet <string> expectedSet = new HashSet <string>(Regex.Split(expected, "\r\n|\r|\n"));
            HashSet <string> actualSet   = new HashSet <string>(Regex.Split(actual, "\r\n|\r|\n"));

            Assert.True(expectedSet.SetEquals(actualSet));

            logger.Dispose();
        }
Example #9
0
        public void TestCustomLogger()
        {
            CustomLogger logger = new CustomLogger();

            Configuration config  = Configuration.Create().WithVerbosityEnabled(2);
            PSharpRuntime runtime = PSharpRuntime.Create(config);

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();

            string expected = @"<CreateLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' was created by the Runtime.
<StateLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' enters state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init'.
<ActionLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init' invoked action 'InitOnEntry'.
<CreateLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' was created by machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0'.
<StateLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' enters state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init'.
<SendLog> Operation Group <none>: Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init' sent event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E' to machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0'.
<EnqueueLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' enqueued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<DequeueLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init' dequeued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<ActionLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init' invoked action 'Act'.
<SendLog> Operation Group <none>: Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init' sent event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E' to machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0'.
<EnqueueLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' enqueued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<DequeueLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init' dequeued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<ActionLog> Machine '(Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M)-0' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init' invoked action 'Act'.
";
            string actual   = logger.ToString();

            HashSet <string> expectedSet = new HashSet <string>(Regex.Split(expected, "\r\n|\r|\n"));
            HashSet <string> actualSet   = new HashSet <string>(Regex.Split(actual, "\r\n|\r|\n"));

            Assert.True(expectedSet.SetEquals(actualSet));

            logger.Dispose();
        }