Esempio n. 1
0
        private void LogTestAttributes(TpmSt sessionTag, TpmCc command)
        {
            if (!TestCategorizer.CommandDefined(command))
            {
                return;
            }

            if (sessionTag.Equals(TpmSt.Null))
            {
                TestIsThreadSafe        = false;
                TestWithinMinTpmProfile = false;
                return;
            }

            bool threadSafe = TestCategorizer.GetThreadSafety(command);

            if (!threadSafe)
            {
                TestIsThreadSafe = false;
            }
            if (!TestCategorizer.InProfile0(command))
            {
                TestWithinMinTpmProfile = false;
                return;
            }
            // else is P0 command.  What privileges are needed?
            NecessaryPrivilege priv = TestCategorizer.GetNecessaryPrivileges(command);

            if (priv > MaximumPrivilege)
            {
                MaximumPrivilege = priv;
            }
        }
Esempio n. 2
0
        internal void GenerateWLKReport(ref int Run, ref int Fail, ref int Success, bool PassFailedTests)
        {
            foreach (TestCaseInfo c in CumulativeFailures)
            {
                string parmsText = "";

                // >>> write parms
                if (c.Parms != null)
                {
                    foreach (Object o in c.Parms)
                    {
                        if (o is TestCaseInfo)
                        {
                            // Formerly this parameter contained an exception object,
                            // information from which is now encapsulated in 'c'.
                            continue;
                        }
                        else if (o is Enum)
                        {
                            parmsText += Enum.GetName(o.GetType(), o) + " : ";

                            bool  first  = true;
                            Enum  e      = o as Enum;
                            Array values = Enum.GetValues(o.GetType());

                            foreach (Enum v in values)
                            {
                                if (e.HasFlag(v))
                                {
                                    if (!first)
                                    {
                                        parmsText += " | ";
                                    }
                                    else
                                    {
                                        first = false;
                                    }
                                    parmsText += Enum.GetName(o.GetType(), v);
                                }
                            }
                        }
                        else if (o is byte[])
                        {
                            parmsText += Globs.HexFromByteArray((byte[])o);
                        }
                        else
                        {
                            parmsText += o.ToString();
                        }
                        parmsText += "<p>";
                    }
                }
                else
                {
                    parmsText = "<br>";
                }

                string details = c.Message + "\n"
                                 + c.Location + "\n"
                                 + "Parameters:\n" + parmsText
                                 + (string.IsNullOrEmpty(c.RngSeed) ? ""
                                    : "To reproduce use option: -seed " + c.RngSeed + "\n");
                details.Replace("\r", "");

                string errorText = c.TestCase.Replace(":", " : ") + ";\n" + details;
                // c.StackTrace.Replace("\r", "");

                WriteToWLKLog(errorText, TestResult.Failed, PassFailedTests);
            }

            // ================  ABORTED CASES SECTION ==========================
            foreach (var item in AbortedTests)
            {
                string errorText = "TestCaseInfo:" + item.Key + " aborted because: "
                                   + GetAbortReasonMessage(item.Value);
                if (item.Value.reason == AbortReason.BlockedCommand)
                {
                    WriteToWLKLog(errorText, TestResult.NotRun, PassFailedTests);
                }
                else
                {
                    WriteToWLKLog(errorText, TestResult.Failed, PassFailedTests);
                }
            }

            // ================  COMMAND STATS SECTION ==========================
            Log.Comment(string.Format("Total TPM command count: {0}", TotalNumCommands));

            string successfulCommands = "Commands executed: ";
            var    sortedStats        = CumulativeCmdStats.OrderBy(item => item.Key.ToString());

            //var sortedStats = CumulativeCmdStats;
            foreach (var item in sortedStats)
            {
                CommandStats stat = item.Value;
                successfulCommands += item.Key + " (" + stat.NumSuccess + ") ";
            }
            Log.Comment(successfulCommands);
            WriteToLog(successfulCommands);

            // 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 && TestCategorizer.CommandDefinedForMinTpm(c.CommandCode))
                {
                    Log.Comment("Command " + c.CommandCode + " not executed.");
                }
            }

            // ================  TEST ROUTINE STATS SECTION ==========================
            int totalTestRoutineCount = this.TestRoutinesStats.Sum(item =>
                                                                   item.Value.NumAborted + item.Value.NumFailed + item.Value.NumSuccess);
            var sortedTestStats = TestRoutinesStats.OrderByDescending(item => item.Value.NumFailed);

            foreach (var item in sortedTestStats)
            {
                if (item.Value.NumFailed == 0)
                {
                    break;  // no more failures
                }
                WriteToWLKLog(string.Format("{0} failed.", item.Key),
                              TestResult.Failed, PassFailedTests);
                Fail++;
            }
            sortedTestStats = TestRoutinesStats.OrderByDescending(item => item.Value.NumSuccess);
            foreach (var item in sortedTestStats)
            {
                if (item.Value.NumSuccess == 0)
                {
                    break;  // no more failures
                }
                Verify.IsTrue(true, item.Key);
                WriteToLog("{0} passed.", item.Key);
                Success++;
            }
            foreach (var item in sortedTestStats)
            {
                TestStats stat = item.Value;
                if (stat.NumSuccess == 0 && stat.NumFailed == 0)
                {
                    Log.Result(TestResult.NotRun, string.Format("{0} not run.", item.Key));
                    Run++;
                }
            }
        }