Beispiel #1
0
        internal static TestExceptionInfo ParseException(Exception e)
        {
            TestExceptionInfo ei = new TestExceptionInfo();

            while (e.InnerException != null)
            {
                e = e.InnerException;
            }

            ei.message = "";
            if (e is TssException)
            {
                TssException tssException = (TssException)e;
                if (e is TpmException)
                {
                    var tei = e as TpmException;
                    ei.message  = "TPM Error: " + tei.ErrorString + ". ";
                    ei.cmdParms = tei.CmdParms;
                }
                else
                {
                    ei.message = "TSS Error: ";
                }
                ei.message += tssException.Message;
#if !TSS_NO_STACK
                ei.fullStack   = tssException.StackTrace;
                ei.callerStack = tssException.CallerStack;
#endif
            }
            else
            {
                ei.message   = "Exception " + e.GetType() + ": " + e.Message;
                ei.fullStack = e.StackTrace;
#if !TSS_NO_STACK
                ei.callerStack = null;
#endif
            }
            return(ei);
        }
Beispiel #2
0
        internal void ReportTestFailure(bool testException, string assertName, Object[] parms)
        {
            if (!ReportErrors)
            {
                return;
            }

            string fullMsg;

#if !TSS_NO_STACK
            StackTrace callerStack = null;
#endif
            string fullTestCase   = FullTestCaseName(assertName);
            string fullStackTrace = "";

            if (!string.IsNullOrEmpty(assertName))
            {
                if (FailedAssertions.ContainsKey(fullTestCase))
                {
                    FailedAssertions[fullTestCase]++;
                    return;
                }
                FailedAssertions.Add(fullTestCase, 1);
            }

            if (testException)
            {
                Debug.Assert(parms.Length == 1);
                TestExceptionInfo ei = TestLogger.ParseException((Exception)parms[0]);
                fullMsg = ei.message;
#if !TSS_NO_STACK
                callerStack = ei.callerStack;
#endif
                fullStackTrace = ei.fullStack;
                parms          = ConcatParams(CurTestPhaseParms,
                                              ei.cmdParms == null ? null
                                                         : new object[] { ei.cmdParms });
            }
            else
            {
                fullMsg = "Assertion " + assertName + " failed";
#if !TSS_NO_STACK
                callerStack    = new StackTrace(true);
                fullStackTrace = TestLogger.GetLocationAsText(callerStack.GetFrames(), "\n");
                parms          = ConcatParams(parms, CurTestPhaseParms);
#endif
            }
            string location = "";
#if !TSS_NO_STACK
            StackFrame[] locationFrames = GetFramesToReport(callerStack);
            location = locationFrames.Length == 0 ? fullStackTrace
                                  : TestLogger.GetLocationAsText(locationFrames, "\n");
#endif

            if (testException)
            {
                LastExceptionInfo = fullMsg + "\n\n" + location;
            }

            var t = new TestCaseInfo {
                TestCase         = fullTestCase,
                Message          = fullMsg,
                Parms            = parms,
                Location         = location,
                StackTrace       = fullStackTrace,
                RngSeed          = CurRngSeed,
                RepeatedFailures = 1
            };
            FailedTests.Add(t);

            int    pos = fullMsg.IndexOf("Details:");
            string msg;
            string details = "";

            if (pos != -1)
            {
                msg     = fullMsg.Substring(0, pos);
                details = fullMsg.Substring(pos) + "\n";
            }
            else
            {
                msg = fullMsg + "\n";
            }

            details += TestLogger.GetParamsList(parms, "\n");

            Logger.ThreadSafePrint(msg, ConsoleColor.Red);
            Logger.ThreadSafePrint("To reproduce use option: -seed "
                                   + CurRngSeed + "\n", ConsoleColor.Gray);
            if (details != "")
            {
                Logger.ThreadSafePrint(details, ConsoleColor.DarkYellow);
            }
            Logger.ThreadSafePrint(location, ConsoleColor.Yellow);
        } // ReportTestFailure