public DataSetColumns GetDataSetColumns()
 {
     return(new DataSetColumns()
     {
         CPUCount = CPUCount.ToArray(),
         TotalMemory = TotalMemory.ToArray(),
         SystemUpTime = SystemUpTime.ToArray(),
         SumTriggers = SumTriggers.ToArray()
     });
 }
Esempio n. 2
0
        public bool Run(TestInfo test, int pass, int testNumber)
        {
            if (_showStatus)
            {
                Log("#@ Running {0} ({1})...\n", test.TestMethod.Name, Language.TwoLetterISOLanguageName);
            }

            if (_buildMode)
            {
                Log("{0,3}. {1,-46} ",
                    testNumber,
                    test.TestMethod.Name);
            }
            else
            {
                var time = DateTime.Now;
                Log("[{0}:{1}] {2,3}.{3,-3} {4,-46} ({5}) ",
                    time.Hour.ToString("D2"),
                    time.Minute.ToString("D2"),
                    pass,
                    testNumber,
                    test.TestMethod.Name,
                    Language.TwoLetterISOLanguageName);
            }

            Exception exception = null;
            var       stopwatch = new Stopwatch();

            stopwatch.Start();
            var  saveCulture    = Thread.CurrentThread.CurrentCulture;
            var  saveUICulture  = Thread.CurrentThread.CurrentUICulture;
            long crtLeakedBytes = 0;

            try
            {
                // Create test class.
                var testObject = Activator.CreateInstance(test.TestClassType);

                // Set the TestContext.
                TestContext.Properties["AccessInternet"]               = AccessInternet.ToString();
                TestContext.Properties["RunPerfTests"]                 = RunPerfTests.ToString();
                TestContext.Properties["TestSmallMolecules"]           = AddSmallMoleculeNodes.ToString();     // Add the magic small molecule test node to every document?
                TestContext.Properties["RunSmallMoleculeTestVersions"] = RunsSmallMoleculeVersions.ToString(); // Run the AsSmallMolecule version of tests when available?
                TestContext.Properties["LiveReports"] = LiveReports.ToString();
                if (test.SetTestContext != null)
                {
                    var context = new object[] { TestContext };
                    test.SetTestContext.Invoke(testObject, context);
                }

                // Switch to selected culture.
                LocalizationHelper.CurrentCulture = LocalizationHelper.CurrentUICulture = Language;
                LocalizationHelper.InitThread();

                // Run the test and time it.
                if (test.TestInitialize != null)
                {
                    test.TestInitialize.Invoke(testObject, null);
                }

                if (CheckCrtLeaks > 0)
                {
                    // TODO: CrtDebugHeap class used to be provided by Crawdad.dll
                    // If we ever want to enable this funcationality again, we need to find another .dll
                    // to put this in.
                    //CrtDebugHeap.Checkpoint();
                }
                test.TestMethod.Invoke(testObject, null);
                if (CheckCrtLeaks > 0)
                {
                    //crtLeakedBytes = CrtDebugHeap.DumpLeaks(true);
                }

                if (test.TestCleanup != null)
                {
                    test.TestCleanup.Invoke(testObject, null);
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            stopwatch.Stop();
            LastTestDuration = (int)(stopwatch.ElapsedMilliseconds / 1000);

            // Restore culture.
            Thread.CurrentThread.CurrentCulture   = saveCulture;
            Thread.CurrentThread.CurrentUICulture = saveUICulture;

            MemoryManagement.FlushMemory();

            const int mb            = 1024 * 1024;
            var       managedMemory = (double)GC.GetTotalMemory(true) / mb;

            if (exception == null)
            {
                // Test succeeded.
                Log(
                    "{0,3} failures, {1:F2}/{2:F1} MB, {3} sec.\r\n",
                    FailureCount,
                    managedMemory,
                    TotalMemory,
                    LastTestDuration);
                if (crtLeakedBytes > CheckCrtLeaks)
                {
                    Log("!!! {0} CRT-LEAKED {1} bytes", test.TestMethod.Name, crtLeakedBytes);
                }

                using (var writer = new FileStream("TestRunnerMemory.log", FileMode.Append, FileAccess.Write, FileShare.Read))
                    using (var stringWriter = new StreamWriter(writer))
                    {
                        stringWriter.WriteLine(TotalMemory.ToString("F1"));
                    }
                return(true);
            }

            // Save failure information.
            FailureCount++;
            if (FailureCounts.ContainsKey(test.TestMethod.Name))
            {
                FailureCounts[test.TestMethod.Name]++;
            }
            else
            {
                FailureCounts[test.TestMethod.Name] = 1;
            }
            var message     = exception.InnerException == null ? exception.Message : exception.InnerException.Message;
            var stackTrace  = exception.InnerException == null ? exception.StackTrace : exception.InnerException.StackTrace;
            var failureInfo = "# " + test.TestMethod.Name + "FAILED:\n" +
                              message + "\n" +
                              stackTrace;

            if (ErrorCounts.ContainsKey(failureInfo))
            {
                ErrorCounts[failureInfo]++;
            }
            else
            {
                ErrorCounts[failureInfo] = 1;
            }

            Log(
                "{0,3} failures, {1:F2}/{2:F1} MB\r\n\r\n!!! {3} FAILED\r\n{4}\r\n{5}\r\n!!!\r\n\r\n",
                FailureCount, managedMemory, TotalMemory, test.TestMethod.Name,
                message,
                stackTrace);
            return(false);
        }