Esempio n. 1
0
        private static bool UnitTests(Options options, bool enabled)
        {
            Console.WriteLine("Unit Tests - Started");

            TestResultCode result = TestResultCode.Skipped;

            if (enabled)
            {
                result = TestResultCode.Failed;
                if (Debugger.IsAttached || options.failHard)
                {
                    UnitTestsKernel(options);
                    result = TestResultCode.Passed;
                }
                else
                {
                    try
                    {
                        UnitTestsKernel(options);
                        result = TestResultCode.Passed;
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.ToString());
                    }
                }
            }

            WritePassFail("Unit Tests - Finished", result);
            return(result == TestResultCode.Passed);
        }
Esempio n. 2
0
        public static void WritePassFail(string message, TestResultCode code, string customResult = null)
        {
            ConsoleColor savedForeColor = Console.ForegroundColor;
            ConsoleColor savedBackColor = Console.BackgroundColor;

            Console.Write("{0}: ", message);

            string result = customResult;

            if (result == null)
            {
                switch (code)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case TestResultCode.Passed:
                    result = "PASSED";
                    break;

                case TestResultCode.Failed:
                    result = "FAILED";
                    break;

                case TestResultCode.Skipped:
                    result = "SKIPPED";
                    break;
                }
            }
            switch (code)
            {
            default:
                Debug.Assert(false);
                throw new ArgumentException();

            case TestResultCode.Passed:
                Console.BackgroundColor = ConsoleColor.DarkGreen;
                break;

            case TestResultCode.Failed:
                Console.BackgroundColor = ConsoleColor.DarkRed;
                break;

            case TestResultCode.Skipped:
                Console.BackgroundColor = ConsoleColor.DarkRed;
                break;
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(result);

            Console.ForegroundColor = savedForeColor;
            Console.BackgroundColor = savedBackColor;

            Console.WriteLine();
        }
Esempio n. 3
0
        private static bool IsNotEqual <AnyType>(AnyType Actual, AnyType Expected, string Message) where AnyType : IComparable
        {
            if (Actual.CompareTo(Expected) != 0)
            {
                TestResult = CombineResults(TestResult, TestResultCode.PASSED);

                return(true);
            }
            else
            {
                TestResult = CombineResults(TestResult, TestResultCode.FAILED);

                return(false);
            }
        }
Esempio n. 4
0
        private static bool MemoryTests(Options options, bool enabled)
        {
            Console.WriteLine("Memory Tests - Started");

            TestResultCode result = TestResultCode.Skipped;

            if (enabled)
            {
                result = TestResultCode.Failed;
                if (new TestMemory().Do())
                {
                    result = TestResultCode.Passed;
                }
            }

            WritePassFail("Memory Tests - Finished", result);
            return(result == TestResultCode.Passed);
        }
Esempio n. 5
0
        private static TestResultCode CombineResults(TestResultCode OldResult, TestResultCode NewResult)
        {
            if (OldResult == TestResultCode.FAILED)
            {
                return(TestResultCode.FAILED);
            }

            if (OldResult == TestResultCode.PASSED || OldResult == TestResultCode.SKIPPED)
            {
                switch (NewResult)
                {
                case TestResultCode.FAILED: return(TestResultCode.FAILED);

                case TestResultCode.PASSED: return(TestResultCode.PASSED);

                case TestResultCode.SKIPPED: return(TestResultCode.PASSED);
                }
            }

            // I don't know how this can happen, but anyway...
            return(TestResultCode.FAILED);
        }
Esempio n. 6
0
 public static void ResetTestResult()
 {
     TestResult = TestResultCode.PASSED;
 }
Esempio n. 7
0
        private static bool StochasticTests(Options options, bool enabled)
        {
            Console.Write("Stochastic Tests - Started [Seed ");
            ConsoleColor savedColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("{0}", options.seed);
            Console.ForegroundColor = savedColor;
            Console.WriteLine("]");

            TestResultCode result = TestResultCode.Skipped;

            if (enabled)
            {
                result = TestResultCode.Failed;

                StochasticControls control = new StochasticControls();

                int bufferHeight1           = Math.Max(1, (Console.WindowHeight - 6) / StochasticTestCount - 2);
                StochasticTestEntry[] tests = new StochasticTestEntry[StochasticTestCount]
                {
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "map")],
                        new StochasticTestMap(options.breakIterations, 0),
                        new ConsoleBuffer("Map/List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rangemap")],
                        new StochasticTestRangeMap(options.breakIterations, 0),
                        new ConsoleBuffer("Range Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rangelist")],
                        new StochasticTestRangeList(options.breakIterations, 0),
                        new ConsoleBuffer("Range List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "range2map")],
                        new StochasticTestRange2Map(options.breakIterations, 0),
                        new ConsoleBuffer("Range2 Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "range2list")],
                        new StochasticTestRange2List(options.breakIterations, 0),
                        new ConsoleBuffer("Range2 List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rankmap")],
                        new StochasticTestRankMap(options.breakIterations, 0),
                        new ConsoleBuffer("Rank Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "multirankmap")],
                        new StochasticTestMultiRankMap(options.breakIterations, 0),
                        new ConsoleBuffer("MultiRank Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "hugelist")],
                        new StochasticTestHugeList(options.breakIterations, 0),
                        new ConsoleBuffer("HugeList Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                };
                for (int i = 0; i < tests.Length; i++)
                {
                    tests[i].actuallyDo = Array.Find(options.stochasticEnables, x => String.Equals(x.Key, tests[i].token)).Value;
                    tests[i].Start();
                }

                int totalHeight = tests.Length * (bufferHeight1 + 1) + 2;
                for (int i = 0; i < totalHeight; i++)
                {
                    Console.WriteLine();
                }
                Console.CursorTop = Math.Max(0, Console.CursorTop - totalHeight);

                Stopwatch started          = Stopwatch.StartNew();
                const int PollIntervalMSec = 250;
                while (true)
                {
                    if (!Array.TrueForAll(tests, delegate(StochasticTestEntry candidate) { return(!candidate.consoleBuffer.Changed); }))
                    {
                        int y = Console.CursorTop;
                        RefreshConsoles(tests);
                        Console.CursorTop = y;
                    }

                    while (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo keyInfo = Console.ReadKey(true /*intercept*/);
                        if (keyInfo.Key == ConsoleKey.Q)
                        {
                            goto Done;
                        }
                        else if (keyInfo.KeyChar == '+')
                        {
                            int i = Array.BinarySearch(ReportingIntervals, control.ReportingInterval);
                            i = i >= 0 ? i + 1 : ~i;
                            control.ReportingInterval = i < ReportingIntervals.Length ? ReportingIntervals[i] : control.ReportingInterval * 2;
                        }
                        else if (keyInfo.KeyChar == '-')
                        {
                            int i = Array.BinarySearch(ReportingIntervals, control.ReportingInterval);
                            i = i >= 0 ? i - 1 : ~i - 1;
                            control.ReportingInterval = Math.Max(i >= 0 ? ReportingIntervals[i] : control.ReportingInterval / 2, 1);
                        }
                    }

                    Thread.Sleep(PollIntervalMSec);

                    if (options.timeLimit.HasValue && (started.ElapsedMilliseconds >= 1000L * options.timeLimit.Value))
                    {
                        break;
                    }
                }
Done:
                control.Stop = true;
                bool allStopped = false;
                while (!allStopped)
                {
                    allStopped = true;
                    foreach (StochasticTestEntry test in tests)
                    {
                        if (test.thread.ThreadState != System.Threading.ThreadState.Stopped)
                        {
                            allStopped = false;
                            break;
                        }
                    }
                }
                RefreshConsoles(tests);

                Console.WriteLine();

                if (!control.Failed)
                {
                    result = TestResultCode.Passed;
                }
            }

            WritePassFail("Stochastic Tests - Finished", result);
            return(result == TestResultCode.Passed);
        }