Exemple #1
0
        } // GenerateTestCasesTable

        internal void GenerateReport(string fileName)
        {
            TimeSpan testTimeSpan = DateTime.Now - TestSessStartTime;

            StringBuilder  sb = new StringBuilder();
            StringWriter   sw = new System.IO.StringWriter(sb);
            HtmlTextWriter w  = new HtmlTextWriter(sw);

            w.RenderBeginTag(HtmlTextWriterTag.Body);

            WriteLine(w, "TPM Test Report", HtmlTextWriterTag.H1);
            WriteLine(w, "Start Time: " + TestSessStartTime.ToString("F"));
            WriteLine(w, "Duration: " + testTimeSpan.TotalMinutes.ToString("F2") + " min");

            bool failed   = CumulativeFailures.Count != 0;
            bool aborted  = AbortedTests.Count != 0;
            bool warnings = CumulativeWarnings.Count != 0;

            string title;

            if (failed)
            {
                title = "Some tests FAILED"
                        + (aborted ? " or were ABORTED" : "")
                        + (warnings ? " and there were WARNINGS" : "");
            }
            else
            {
                title = "All Tests PASSED"
                        + (warnings ? " with WARNINGS" : "")
                        + (aborted ? (warnings ? " and" : " but") + " some were ABORTED" : "");
            }
            WriteLine(w, title, HtmlTextWriterTag.H1);

            WriteLine(w, "Total Substrate.Assertions Checked = " + TotalNumAsserts);

            // ================  FAILING CASES SECTION ==========================
            GenerateTestCasesTable(CumulativeFailures, "Failing Cases", w);

            // ================  ABORTED CASES SECTION ==========================
            if (AbortedTests.Count != 0)
            {
                WriteLine(w, "Aborted Cases", HtmlTextWriterTag.H2);
                WriteLine(w, "Tests aborted because of commands not implemented by " +
                          "the target TPM, or blocked by OS.");

                BeginTable(w, "Test Case", "Abort Reason");
                foreach (var item in AbortedTests)
                {
                    WriteTableRow(w, item.Key, GetAbortReasonMessage(item.Value));
                }
                EndTable(w); // table
            }

            // ================  WARNINGS SECTION ==========================
            GenerateTestCasesTable(CumulativeWarnings, "Warnings", w);

            // ================  COMMAND STATS SECTION ==========================
            WriteLine(w, "Command Statistics", HtmlTextWriterTag.H2);
            WriteLine(w, "Total TPM Commands Executed = " + TotalNumCommands);

            BeginTable(w, "Command Code", "Successes", "Failures",
                       "Average<br>Success<br>Time, ms", "Average<br>Failure<br>Time, ms",
                       "Error Codes", "Calling Tests");

            var sortedStats = CumulativeCmdStats.OrderBy(item => item.Key.ToString()); // item.Value.NumSuccess

            //var sortedStats = CumulativeCmdStats;
            foreach (var item in sortedStats)
            {
                CommandStats stat           = item.Value;
                string       avgSuccessTime = stat.NumSuccess == 0 ? "-" : String.Format("{0:F1}",
                                                                                         stat.SuccessExecutionTime.TotalMilliseconds / stat.NumSuccess);
                string avgFailureTime = stat.NumFailures == 0 ? "-" : String.Format("{0:F2}",
                                                                                    stat.FailureExecutionTime.TotalMilliseconds / stat.NumFailures);
                WriteTableRow(w, item.Key, stat.NumSuccess, stat.NumFailures,
                              avgSuccessTime, avgFailureTime,
                              Globs.ToString(stat.FailureResponses, ", ", "-"),
                              Globs.ToString(stat.CallerTests, ", ", "-"));
            }
            EndTable(w);

            // commands not executed -
            List <TpmCc> notExecuted = new List <TpmCc>();

            foreach (var c in CommandInformation.Info)
            {
                int num = sortedStats.Sum(y => (y.Key == c.CommandCode) ? 1 : 0);
                if (num == 0)
                {
                    Debug.WriteLine("Not executed:" + c.CommandCode.ToString());
                }
            }

            // ================  TEST ROUTINE STATS SECTION ==========================
            WriteLine(w, "Test Routine Statistics", HtmlTextWriterTag.H2);

            int totalTestRoutineCount = this.TestRoutinesStats.Sum(item =>
                                                                   item.Value.NumAborted + item.Value.NumFailed + item.Value.NumSuccess);

            WriteLine(w, "Total Test Routines Executed = " + totalTestRoutineCount);

            BeginTable(w, "Test Name", "Succeeded", "Failed", "Aborted", "Average<BR>Time, s");

            var sortedTestStats = TestRoutinesStats.OrderBy(item => item.Key.ToString());

            foreach (var item in sortedTestStats)
            {
                TestStats stat = item.Value;
                int       n    = stat.NumSuccess + stat.NumFailed + stat.NumAborted;
                if (n == 0)
                {
                    continue;
                }
                string avgTime = String.Format("{0:F2}",
                                               (double)stat.TotalExecutionTime / n / 1000);
                WriteTableRow(w, item.Key, stat.NumSuccess, stat.NumFailed,
                              stat.NumAborted, avgTime);
            }
            EndTable(w);

            w.RenderEndTag(); // Body
            File.WriteAllText(fileName, sb.ToString());
        }