protected override XElement CreateTestTypeXml(MethodInfo testMethod)
        {
            MChessOptions mchessOpts = new MChessOptions();

            if (_MaxSchedules.HasValue)
            {
                mchessOpts.MaxExecs = MaxSchedules;
            }
            if (_MaxRunTime.HasValue)
            {
                mchessOpts.MaxChessTime = MaxRunTime;
            }
            if (_MaxPreemptions.HasValue)
            {
                mchessOpts.MaxPreemptions = MaxPreemptions;
            }
            if (_PreemptAllAccesses.HasValue)
            {
                mchessOpts.PreemptAllAccesses = PreemptAllAccesses;
            }
            var xopts = mchessOpts.ToXElement();

            return(new XElement(XNames.ScheduleTest
                                , xopts.HasAttributes || xopts.HasElements ? xopts : null
                                ));
        }
Esempio n. 2
0
        private void SetupMChessOptions()
        {
            // Add cmd line switches for mchess options
            _mcopts = new MChessOptions(TestCase.XMChessOptions);

            // This should not be serialized, and only set in the runner code
            // If the expected results are looking for HBExecs, we need to turn it on so it gets reported
            var expResult = TestCase.EntityOfType <ExpectedChessTestResultEntity>();

            if (expResult != null && expResult.LastHBExecSteps.HasValue)
            {
                _mcopts.ShowHBExecs = true;
            }

            // Need to save the schedule file if specified
            if (_mcopts.XSchedule != null)
            {
                _mcopts.ScheduleFilePath = Path.Combine(TaskFolderPath, InputChessScheduleFilename);
            }

            // If an observation filename is specified, we need to make sure it's relative
            // to the task folder
            if (!String.IsNullOrEmpty(_mcopts.ObservationFile))
            {
                _mcopts.ObservationFile = Path.Combine(TaskFolderPath, _mcopts.ObservationFile);
            }
        }
Esempio n. 3
0
        void setField(FieldInfo fieldInfo, MChessOptions options, string value)
        {
#if SHIP_BUILD
            bool ok;
            ok = fieldInfo.Name == "notime" || fieldInfo.Name == "showHbexecs" || fieldInfo.Name == "nopopups" || fieldInfo.Name == "doSleepSets";
            if (!ok)
            {
                // TODO: interaction with ChessBoard??
                Console.WriteLine("WARNING: This version of CHESS ignores the option /p:{0}={1}.", fieldInfo.Name, value);
                return;
            }
#endif
            if (fieldInfo.FieldType == typeof(bool))
            {
                fieldInfo.SetValue(options, Convert.ToBoolean(value));
            }
            else if (fieldInfo.FieldType == typeof(int))
            {
                fieldInfo.SetValue(options, Convert.ToInt32(value));
            }
            else if (fieldInfo.FieldType == typeof(string))
            {
                fieldInfo.SetValue(options, value);
            }
        }
Esempio n. 4
0
        protected override void OnBindToContext()
        {
            base.OnBindToContext();
            if (!Applicable)
            {
                return;
            }

            XElement xaction = Context.MCutTestRun.GetChessXActionMatchingStartOf(Text);

            Applicable &= xaction != null &&
                          Context.LastXSchedule != null
                          // Don't allow repro of a repro
                          && Context.MCutTestRun.RunType != MCutTestRunType.Repro
            ;
            if (!Applicable)
            {
                return;
            }

            // Need to add the last schedule from the TestRun
            var opts = new MChessOptions();

            opts.EnableRepro = true;
            opts.XSchedule   = Context.LastXSchedule;

            // Merge with existing options
            opts.MergeWith(MChessOptions);
            MChessOptions = opts;
        }
Esempio n. 5
0
 public ClrSyncManager(MChessOptions m)
 {
     if (onlyOne == null)
     {
         ClrSyncManager.onlyOne = this;
         Conversions.SetOptions(m);
         this.TrackGC         = m.monitorAccesses || m.monitorVolatiles || m.preemptAccesses;
         this.TrackVolatile   = m.monitorVolatiles;
         this.allowFinalizers = true;
         this.CurrentTid      = -1;
         this.initTask        = -1;
         this.syncVarManager  = new SyncVarManager();
         this.joinableTasks   = new SafeDictionary <ChessTask, bool>();
         this.weakReferences  = new SafeDictionary <object, bool>(ObjectIdentity <object> .Comparer);
         this.finalizeThese   = new SafeList <object>();
         this.mco             = m;
         if (TrackGC || TrackVolatile)
         {
             // add handlers to get raw reads and writes
             ObjectAccessThreadMonitor.ReadRawAccess  += new RawAccessHandler(this.ObjectAccessThreadMonitor_ReadAccess);
             ObjectAccessThreadMonitor.WriteRawAccess += new RawAccessHandler(this.ObjectAccessThreadMonitor_WriteAccess);
         }
         if (m.finesse)
         {
             this.DelayFinalizers = false;
             ObjectAccessThreadMonitor.ObjectAllocationHandlerEvent += new ObjectAllocationHandler(this.ObjectAccessThreadMonitor_AllocationAccess);
         }
     }
     else
     {
         throw new System.InvalidOperationException();
     }
 }
Esempio n. 6
0
 private void popups(MChessOptions m)
 {
     // no popups
     if (m.nopopups)
     {
         Trace.Listeners.Clear();
         Microsoft.ExtendedReflection.Utilities.Safe.Diagnostics.SafeDebug.SetCrashOnAssert("");
     }
 }
        /// <summary>
        /// Sets up the base <see cref="MChessOptions"/> instance for a fresh run of this test.
        /// This is the part that usually differentiate tests using MChess from each other.
        /// </summary>
        /// <returns></returns>
        public virtual void SetBaseMChessOptionsForTestExecution(AppTasks.RunMChessBasedTestTask runTestTask, MChessOptions opts)
        {
            // Look to see if the test defines an MChessOptions element
            var xopts = DataElement.Element(XChessNames.MChessOptions);

            if (xopts != null)
            {
                var testOpts = new MChessOptions(xopts);
                opts.MergeWith(testOpts);
            }
        }
Esempio n. 8
0
        public override void ApplyModifier(AActionModifier modifier)
        {
            base.ApplyModifier(modifier);

            if (modifier is AMChessOptionsModifier)
            {
                var opts = MChessOptions ?? new MChessOptions();
                opts.MergeWith(((AMChessOptionsModifier)modifier).MChessOptions);
                MChessOptions = opts;
            }
        }
Esempio n. 9
0
        protected override void OnBindToContext()
        {
            base.OnBindToContext();

            var prevRun = Context.MCutTestRun;

            if (prevRun != null)
            {
                // Incorporate the prev run's options in, while being overridden by the current options
                MChessOptions opts = new MChessOptions(prevRun.TestCase.XMChessOptions);
                opts.MergeWith(MChessOptions);
                MChessOptions = opts;
            }
        }
Esempio n. 10
0
        void IPexCopDetector.Initialize(IPexCopComponent host)
        {
            pce = host.Services.Options;
            if (pce.MonitorVolatile)
            {
                host.Services.MonitorManager.RegisterObjectAccessThreadMonitor();
            }

            // set this up for BeforeMain
            mco = new MChessOptions();

            // Use Reflection to go through the various public members of MChessChessOptions
            // use TryGetProperty to see if we have a property of the particular name
            // convert the value to the proper type (bool, int, string)
            foreach (FieldInfo fi in typeof(MChessOptions).GetFields())
            {
                string res;
                if (pce.TryGetProperty(fi.Name, out res))
                {
                    // Console.WriteLine("got {0}={1}", fi.Name, res);
                    if (fi.FieldType == typeof(bool))
                    {
                        fi.SetValue(mco, Convert.ToBoolean(res));
                        // Console.WriteLine("param {0}={1}", fi.Name, (bool)fi.GetValue(mco));
                    }
                    else if (fi.FieldType == typeof(int))
                    {
                        fi.SetValue(mco, Convert.ToInt32(res));
                    }
                    else if (fi.FieldType == typeof(string))
                    {
                        fi.SetValue(mco, res);
                    }
                    else
                    {
                        // print a warning
                    }
                }
            }

            // real arguments override whatever we hacked in with properties

            mco.preemption_bound        = pce.CSB;
            mco.load_schedule           = pce.LoadSchedule;
            mco.break_on_deadlock       = pce.Breaks.Contains("d");
            mco.break_on_context_switch = pce.Breaks.Contains("c");
            mco.break_on_preemptions    = pce.Breaks.Contains("p");
            mco.break_on_timeout        = pce.Breaks.Contains("t");
        }
Esempio n. 11
0
        private MChessOptions CreateBaseMChessOptions()
        {
            var opts = new MChessOptions();

            // Add the options derived from the test method hierarchy. (these aren't specified by the context)
            opts.IncludedAssemblies = ChessTestUtil.GetAssembliesToInstrument(Test.OwningTestMethod).ToArray();
            ChessTestUtil.SetPreemptionOptions(opts, Test.OwningTestMethod);

            // ** Add options that come from the context
            var context = TestContext as IMChessTestContext;

            if (context != null)
            {
                opts.MergeWith(context.ToMChessOptions());
            }

            return(opts);
        }
Esempio n. 12
0
        public ChessMain(MChessOptions m, Assembly a, string testClassName, string unitTestName)
        {
            this.mco                = m;
            this.testAssembly       = a;
            this.testclass          = testClassName;
            this.unitTestMethodName = unitTestName;
            this.runUnitTest        = !String.IsNullOrEmpty(unitTestMethodName);

            this.manager = new ClrSyncManager(m);
            MChessChess.Init(manager, mco);

            TryLoadReferencedAssemblies(new[] { testAssembly });
            get_entries(testAssembly);
            popups(m);

            this.manager.SetExitCallBack((c, ex) => {
                string msg = "";
                if (ex != null)
                {
                    msg = @"Child thread raised exception
" + ex.Message + @"
Stack trace:
" + ex.StackTrace + @"
";
                    ReportErrorAndExit(msg, c, true, ex);
                }
                ReportErrorAndExitRaw("", c, true, true, null);
            });

            try
            {
                do_startup();

                // print warning if races are disabled
                if (MChessChess.GetExitCode() == 0 && !(mco.preemptAccesses || mco.sober ||
                                                        mco.maxExecutions == 1 || !String.IsNullOrEmpty(mco.enumerateObservations)))
                {
                    MChessChess.ReportWarning("Race Detection Disabled. Races May Hide Bugs.", "", false);
                }

                // RunTest loop
                bool moreToTest = true;
                while (moreToTest)
                {
                    if (!MChessChess.StartTest())
                    {
                        ReportErrorAndExit("Internal failure: CHESS.StartTest failed", ChessExitCode.ChessFailure, false, null);
                    }

                    if (MyEngine.EnvironmentVars.FlipPreemptSense)
                    {
                        MChessChess.PreemptionDisable();
                    }
                    do_run();
                    if (MyEngine.EnvironmentVars.FlipPreemptSense)
                    {
                        MChessChess.PreemptionEnable();
                    }

                    if (manager.BreakDeadlockMode)
                    {
                        MChessChess.EnterChess();
                        MChessChess.WakeNextDeadlockedThread(true, false);
                        // we are now done with the deadlock-breaking mode!
                        Debug.Assert(!MChessChess.IsBreakingDeadlock());
                        manager.BreakDeadlockMode = false;
                        MChessChess.LeaveChess();
                    }
                    moreToTest = MChessChess.EndTest();
                }

                do_shutdown();
            }
            catch (Exception ex)
            {
                string message = @"CHESS internal failure.
" + ex.Message + @"
" + ex.StackTrace + @"
";
                ReportErrorAndExit(message, ChessExitCode.ChessFailure, false, ex);
            }
            ReportErrorAndExit("", (ChessExitCode)MChessChess.GetExitCode(), false, null);
        }
Esempio n. 13
0
        public override void SetBaseMChessOptionsForTestExecution(AppTasks.RunMChessBasedTestTask runTestTask, MChessOptions opts)
        {
            base.SetBaseMChessOptionsForTestExecution(runTestTask, opts);

            opts.CheckObservations = true;
            opts.ObservationMode   = CheckingMode.ToChessObservationMode();

            string fileIdentity = ResolveFileIdentity();
            string contextName  = runTestTask.TestContext.Name;
            string obsFileName  = ObservationGeneratorEntity.ComposeObservationFilename(OwningTestMethod, fileIdentity, contextName, runTestTask.TestArgs);

            opts.ObservationFile = obsFileName;
        }
Esempio n. 14
0
        public override void SetBaseMChessOptionsForTestExecution(AppTasks.RunMChessBasedTestTask runTestTask, MChessOptions opts)
        {
            base.SetBaseMChessOptionsForTestExecution(runTestTask, opts);

            // Enable data race detection
            opts.EnableRaceDetection = true;
            opts.MaxExecs            = 20;
        }
Esempio n. 15
0
        public override void SetBaseMChessOptionsForTestExecution(AppTasks.RunMChessBasedTestTask runTestTask, MChessOptions opts)
        {
            base.SetBaseMChessOptionsForTestExecution(runTestTask, opts);

            opts.EnumerateObservations = true;
            opts.ObservationMode       = Granularity.ToChessObservationMode();

            string contextName = runTestTask.TestContext.Name;
            string obsFileName = ComposeObservationFilename(OwningTestMethod, FileIdentity, contextName, runTestTask.TestArgs);

            opts.ObservationFile = obsFileName;
        }
Esempio n. 16
0
        public override void SetBaseMChessOptionsForTestExecution(AppTasks.RunMChessBasedTestTask runTestTask, MChessOptions opts)
        {
            base.SetBaseMChessOptionsForTestExecution(runTestTask, opts);

            opts.EnableDeterminismChecking = true;
        }
Esempio n. 17
0
        private MChessOptions SetOptions(EnvironmentVars pce)
        {
            var mco = new MChessOptions();

            // real arguments override whatever we hacked in with properties
            mco.PCT                     = pce.M_PCT;
            mco.PCT_VB                  = pce.M_VB_PCT;
            mco.DeRandomizedPCT         = pce.M_DeRandomizedPCT;
            mco.PCT_num_of_runs         = pce.M_num_of_runs;
            mco.varLabels               = pce.VarLabels;
            mco.PCT_bug_depth           = pce.M_bug_depth;
            mco.var_bound               = pce.M_var_bound;
            mco.PCT_seed                = pce.M_pct_seed;
            mco.breakOnAssert           = pce.Breaks.Contains("a");
            mco.breakOnDeadlock         = pce.Breaks.Contains("d");
            mco.breakOnPreemptions      = pce.Breaks.Contains("p");
            mco.breakAfterPreemptions   = pce.Breaks.Contains("P");
            mco.breakOnContextSwitch    = pce.Breaks.Contains("c");
            mco.breakAfterContextSwitch = pce.Breaks.Contains("C");
            mco.breakOnTimeout          = pce.Breaks.Contains("t");
            mco.breakOnTaskResume       = pce.Breaks.Contains("f");
            mco.breakOnRace             = pce.Breaks.Contains("r");

            mco.checkObservations     = pce.CheckObservations;
            mco.loadSchedule          = (pce.LoadSchedule || pce.Continue);
            mco.delayBound            = pce.MaxDelays;
            mco.preemptionBound       = pce.MaxPreemptions;
            mco.observationMode       = pce.ObservationMode;
            mco.enumerateObservations = pce.EnumerateObservations;
            mco.finesse              = pce.Finesse;
            mco.logging              = pce.Logging;
            mco.xmlCommandline       = pce.XmlCommandline;
            mco.maxExecutions        = pce.MaxExecs;
            mco.maxChessTime         = pce.MaxChessTime;
            mco.maxExecTime          = pce.MaxExecTime;
            mco.maxStackSize         = pce.MaxExecSteps;
            mco.monitorVolatiles     = pce.MonitorVolatile;
            mco.monitorAccesses      = pce.MonitorAccesses;
            mco.monitorCctors        = pce.MonitorCCTOR;
            mco.outputPrefix         = pce.OutputPrefix;
            mco.preemptionVars       = pce.PreemptionVars;
            mco.preemptAccesses      = pce.PreemptAccesses;
            mco.trace                = pce.PrintTrace;
            mco.processorCount       = pce.ProcessorCount;
            mco.showProgress         = pce.ShowProgress;
            mco.sober                = pce.Sober;
            mco.soberTargetrace      = pce.Targetrace;
            mco.loadScheduleFile     = pce.SchedFile;
            mco.recordPreemptMethods = pce.LoadSchedule && !pce.Continue;
            mco.tolerateDeadlock     = pce.TolerateDeadlock;
            // Best-first search options
            mco.doDpor    = pce.Dpor;
            mco.bounded   = pce.Bounded;
            mco.bestFirst = pce.BestFirst;
            if (pce.BestFirst)
            {
                if (pce.Bounded || !pce.Dpor)
                {
                    if (pce.PrioritizeMethods.Count > 0)
                    {
                        // if we're prioritizing methods, add that to the priority function
                        mco.bestFirstPriority = "wdpor_method";
                    }
                    else
                    {
                        mco.bestFirstPriority = "wdpor";
                    }
                }
                else
                {
                    if (pce.PrioritizeMethods.Count > 0)
                    {
                        // if we're prioritizing methods, add that to the priority function
                        mco.bestFirstPriority = "wdpor_pb_method";
                    }
                    else
                    {
                        mco.bestFirstPriority = "wdpor_pb";
                    }
                }
            }

            // TODO: CHECK THIS
            // ??? for load-schedule, we default to max_executions=1
            if (pce.LoadSchedule)
            {
                mco.maxExecutions = 1;
            }

            // Use Reflection to go through the various public members of MChessChessOptions
            // use TryGetProperty to see if we have a property of the particular name
            // convert the value to the proper type (bool, int, string)
            foreach (FieldInfo fi in typeof(MChessOptions).GetFields())
            {
                string res;
                if (pce.TryGetProperty(fi.Name, out res))
                {
                    setField(fi, mco, res);
                }
                // convert camlCase to deprecated, underscores
                string underscored = "";
                for (int i = 0; i < fi.Name.Length; i++)
                {
                    if (char.IsLetter(fi.Name, i) && (char.IsUpper(fi.Name, i)))
                    {
                        underscored += ("_" + char.ToLower(fi.Name[i]));
                    }
                    else
                    {
                        underscored += fi.Name[i];
                    }
                }
                if (pce.TryGetProperty(underscored, out res))
                {
                    setField(fi, mco, res);
                }
            }
            return(mco);
        }