예제 #1
0
        public static void TestCase(Assembly assembly,
                                    RunMode mode,
                                    int duration,
                                    int threads,
                                    int?exceptionThreshold    = null,
                                    bool printMethodName      = false,
                                    bool deadlockDetection    = false,
                                    int randomSeed            = 0,
                                    string[] selectedTests    = null,
                                    string[] overrides        = null,
                                    string[] variations       = null,
                                    string filter             = null,
                                    bool monitorEnabled       = false,
                                    string monitorMachineName = "localhost")
        {
            TestMetrics.Reset();
            TestFinder.AssemblyName = assembly.GetName();
            mode = RunMode.RunAll;

            for (int i = 0; overrides != null && i < overrides.Length; i++)
            {
                TestMetrics.Overrides.Add(overrides[i], overrides[++i]);
            }

            for (int i = 0; variations != null && i < variations.Length; i++)
            {
                TestMetrics.Variations.Add(variations[i]);
            }

            for (int i = 0; selectedTests != null && i < selectedTests.Length; i++)
            {
                TestMetrics.SelectedTests.Add(selectedTests[i]);
            }

            TestMetrics.StressDuration     = duration;
            TestMetrics.StressThreads      = threads;
            TestMetrics.ExceptionThreshold = exceptionThreshold;
            TestMetrics.MonitorEnabled     = monitorEnabled;
            TestMetrics.MonitorMachineName = monitorMachineName;
            TestMetrics.RandomSeed         = randomSeed;
            TestMetrics.Filter             = filter;
            TestMetrics.PrintMethodName    = printMethodName;

            if (deadlockDetection)
            {
                DeadlockDetection.Enable();
            }

            // get and load all the tests
            s_tests = TestFinder.GetTests(assembly);

            // instantiate the stress engine
            s_eng = new StressEngine(TestMetrics.StressThreads, TestMetrics.StressDuration, s_tests, TestMetrics.RandomSeed);
        }
예제 #2
0
        private void RunTask(object state)
        {
            Task inTask = state as Task;

#if DEBUG
            // Remove from the dictionary of queued items
            object ignored;
            _queuedItems.TryRemove(inTask, out ignored);
#endif

            // Note when the thread started work
            DeadlockDetection.AddTaskThread();

            try
            {
                // Run the task
                base.TryExecuteTask(inTask);
            }
            finally
            {
                // Remove the thread from the list when complete
                DeadlockDetection.RemoveThread();
            }
        }
예제 #3
0
        public static void Init(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-a":
                    string assemblyName = args[++i];
                    TestFinder.AssemblyName = new AssemblyName(assemblyName);
                    break;

                case "-all":
                    s_mode = RunMode.RunAll;
                    break;

                case "-override":
                    TestMetrics.Overrides.Add(args[++i], args[++i]);
                    break;

                case "-variation":
                    TestMetrics.Variations.Add(args[++i]);
                    break;

                case "-test":
                    TestMetrics.SelectedTests.Add(args[++i]);
                    break;

                case "-duration":
                    TestMetrics.StressDuration = Int32.Parse(args[++i]);
                    break;

                case "-threads":
                    TestMetrics.StressThreads = Int32.Parse(args[++i]);
                    break;

                case "-verify":
                    s_mode = RunMode.RunVerify;
                    break;

                case "-debug":
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                    else
                    {
                        Console.WriteLine("Current PID: {0}, attach the debugger and press Enter to continue the execution...", System.Diagnostics.Process.GetCurrentProcess().Id);
                        Console.ReadLine();
                    }
                    break;

                case "-exceptionThreshold":
                    TestMetrics.ExceptionThreshold = Int32.Parse(args[++i]);
                    break;

                case "-monitorenabled":
                    TestMetrics.MonitorEnabled = bool.Parse(args[++i]);
                    break;

                case "-randomSeed":
                    TestMetrics.RandomSeed = Int32.Parse(args[++i]);
                    break;

                case "-filter":
                    TestMetrics.Filter = args[++i];
                    break;

                case "-printMethodName":
                    TestMetrics.PrintMethodName = true;
                    break;

                case "-deadlockdetection":
                    if (bool.Parse(args[++i]))
                    {
                        DeadlockDetection.Enable();
                    }
                    break;

                default:
                    s_mode = RunMode.Help;
                    break;
                }
            }

            if (TestFinder.AssemblyName != null)
            {
                Console.WriteLine("Assembly Found for the Assembly Name " + TestFinder.AssemblyName);

                if (TestFinder.AssemblyName != null)
                {
                    // get and load all the tests
                    s_tests = TestFinder.GetTests(Assembly.Load(TestFinder.AssemblyName));

                    // instantiate the stress engine
                    s_eng = new StressEngine(TestMetrics.StressThreads, TestMetrics.StressDuration, s_tests, TestMetrics.RandomSeed);
                }
                else
                {
                    Program.s_error = string.Format("Assembly {0} cannot be found.", TestFinder.AssemblyName);
                    s_mode          = RunMode.ExitWithError;
                }
            }
        }
예제 #4
0
        public void RunStressThread()
        {
            try
            {
                StressTest[] tests             = new StressTest[_allTests.Count];
                List <int>   tmpWeightedLookup = new List <int>();

                for (int i = 0; i < tests.Length; i++)
                {
                    tests[i] = _allTests[i].Clone();
                    tests[i].RunSetup();

                    for (int j = 0; j < tests[i].Weight; j++)
                    {
                        tmpWeightedLookup.Add(i);
                    }
                }

                int[] weightedLookup = tmpWeightedLookup.ToArray();

                Stopwatch timer        = new Stopwatch();
                long      testDuration = (long)_duration * Stopwatch.Frequency;

                timer.Reset();
                timer.Start();

                while (_continue && timer.ElapsedTicks < testDuration)
                {
                    int        n = _rnd.Next(0, weightedLookup.Length);
                    StressTest t = tests[weightedLookup[n]];

                    if (TestMetrics.PrintMethodName)
                    {
                        FakeConsole.WriteLine("{0}: {1}", ++s_globalRequestsCounter, t.Title);
                    }

                    try
                    {
                        DeadlockDetection.AddTestThread();
                        t.Run();
                        if (_perfcounters != null)
                        {
                            _perfcounters.IncrementRequestsCounter();
                        }
                    }
                    catch (Exception e)
                    {
                        if (_perfcounters != null)
                        {
                            _perfcounters.IncrementExceptionsCounter();
                        }

                        t.HandleException(e);

                        bool thresholdExceeded = _exceptions.Record(t.Title, e);
                        if (thresholdExceeded)
                        {
                            FakeConsole.WriteLine("Exception Threshold of {0} has been exceeded on {1} - Halting!\n",
                                                  TestMetrics.ExceptionThreshold, t.Title);
                            break;
                        }
                    }
                    finally
                    {
                        DeadlockDetection.RemoveThread();
                    }
                }

                foreach (StressTest t in tests)
                {
                    t.RunCleanup();
                }
            }
            finally
            {
                _continue = false;
                Interlocked.Decrement(ref _threadsRunning);
            }
        }