Exemple #1
0
        protected ITestingEngine AssertSucceeded(Configuration configuration, Action <PSharpRuntime> test)
        {
            InMemoryLogger   logger = new InMemoryLogger();
            BugFindingEngine engine = null;

            try
            {
                engine = BugFindingEngine.Create(configuration, test);
                engine.SetLogger(logger);
                engine.Run();

                var numErrors = engine.TestReport.NumOfFoundBugs;
                Assert.True(numErrors == 0, GetBugReport(engine));
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }

            return(engine);
        }
Exemple #2
0
        public void TestCustomLogWriter()
        {
            Configuration configuration = GetConfiguration().WithStrategy(SchedulingStrategy.DFS);
            BugFindingEngine engine = BugFindingEngine.Create(configuration,
                r =>
                {
                    r.SetLogWriter(new CustomLogWriter());
                    r.CreateMachine(typeof(M));
                });

            try
            {
                engine.Run();

                var numErrors = engine.TestReport.NumOfFoundBugs;
                Assert.True(numErrors == 1, GetBugReport(engine));
                Assert.True(engine.ReadableTrace != null, "Readable trace is null.");
                Assert.True(engine.ReadableTrace.Length > 0, "Readable trace is empty.");

                string expected = @"<TestHarnessLog> Running anonymous test.
<CreateLog>.
<StateLog>.
<ActionLog> Machine 'Microsoft.PSharp.TestingServices.Tests.LogMessages.M()' in state 'Init' invoked action 'InitOnEntry'.
<CreateLog>.
<StateLog>.
<DequeueLog> Machine 'Microsoft.PSharp.TestingServices.Tests.LogMessages.N()' in state 'Init' dequeued event 'Microsoft.PSharp.TestingServices.Tests.LogMessages.E'.
<ActionLog> Machine 'Microsoft.PSharp.TestingServices.Tests.LogMessages.N()' in state 'Init' invoked action 'Act'.
<DequeueLog> Machine 'Microsoft.PSharp.TestingServices.Tests.LogMessages.M()' in state 'Init' dequeued event 'Microsoft.PSharp.TestingServices.Tests.LogMessages.E'.
<ActionLog> Machine 'Microsoft.PSharp.TestingServices.Tests.LogMessages.M()' in state 'Init' invoked action 'Act'.
<ErrorLog> Bug found!
<StrategyLog> Found bug using 'DFS' strategy.
<StrategyLog> Testing statistics:
<StrategyLog> Found  bug.
<StrategyLog> Scheduling statistics:
<StrategyLog> Explored  schedule:  fair and  unfair.
<StrategyLog> Found .% buggy schedules.";
                string actual = Regex.Replace(engine.ReadableTrace.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.Equal(expected, actual);
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemple #3
0
        private ITestingEngine Test(BugFindingEngine engine)
        {
            var logger = new Common.TestOutputLogger(this.TestOutput);

            try
            {
                engine.SetLogger(logger);
                engine.Run();

                var numErrors = engine.TestReport.NumOfFoundBugs;
                Assert.True(numErrors == 0, GetBugReport(engine));
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }

            return(engine);
        }