// Heuristics to return a suitable frame to report as part of an error report. // Returns the first entity in the stack with a tester-attribute. public static StackFrame[] GetFramesToReport(StackTrace s) { if (s == null) { return(new StackFrame[0]); } StackFrame[] stackFrames = s.GetFrames(); if (stackFrames == null) { return(new StackFrame[0]); } var framesToReport = new List <StackFrame>(); bool reportThisFrame = false; for (int j = 0; j < stackFrames.Length; j++) { StackFrame f = stackFrames[j]; MethodBase b = f.GetMethod(); MethodInfo m = b is MethodInfo ? (MethodInfo)b : null; if (m == null) { Debug.Assert(!reportThisFrame); continue; } if (reportThisFrame) { framesToReport.Add(f); } if (Globs.GetAttr <TestAttribute>(f.GetMethod()) != null) { if (!reportThisFrame) { framesToReport.Add(f); } break; } reportThisFrame = Globs.GetAttr <TpmCommandAttribute>(f.GetMethod()) != null || f.GetMethod().ToString().Contains("Void Test("); } return(framesToReport.ToArray()); }
public List <string> GetTestListFromAttrs(Func <TestAttribute, bool> fits) { return(Globs.ConvertAll(Target.AllTests.Where( item => fits(Globs.GetAttr <TestAttribute>(item))), item => item.Name)); }
// This routine checks that the observed test behavior matches the attributes. // It is called during a -validate pass on a full TPM simulator internal void ValidateTestAttributeCollection(MethodInfo test, Tpm2 tpm) { var attr = Globs.GetAttr <TestAttribute>(test); // check that the cumulative attributes match the claimed attributes if (attr.SpecialNeeds.HasFlag(Special.NotThreadSafe) == TestIsThreadSafe) { string s = "<Benign>"; if (!TestIsThreadSafe) { // It is safe to say you are not thread safe if you are not (and // there are commands that the test harness does not understand // that might lead you to be not thread safe s = "<Critical - must be fixed>"; SetColorCritical(true); } else { SetColorCritical(false); } Logger.WriteErrorToLog("\nThread safety attribute does not match " + "observed behavior for {0} {1}", test.Name, s); } bool PowerCycleWasIssued = ((TpmPassThroughDevice)tpm._GetUnderlyingDevice()) .GetPowerCycleDirtyBit(); if (attr.SpecialNeeds.HasFlag(Special.PowerControl) != PowerCycleWasIssued) { SetColorCritical(PowerCycleWasIssued); Logger.WriteErrorToLog("\nPower-cycle attribute does not match observed behavior"); } if ((attr.CommProfile == Profile.MinTPM) != TestWithinMinTpmProfile) { SetColorCritical(attr.CommProfile == Profile.MinTPM); string profile = attr.CommProfile.ToString(); Logger.WriteErrorToLog("\nClaimed profile {0} but this does not match " + "observed behavior for {1}", profile, test.Name); } // change privUsed and privStated into a number so that we can compare // bigger numbers are more privileged int privUsed, privStated; switch (MaximumPrivilege) { case NecessaryPrivilege.User: privUsed = 0; break; case NecessaryPrivilege.Admin: privUsed = 1; break; case NecessaryPrivilege.Special: privUsed = 2; break; case NecessaryPrivilege.Debug: privUsed = 3; break; default: throw new Exception("tester fault"); } switch (attr.Privileges) { case Privileges.StandardUser: privStated = 0; break; case Privileges.Admin: privStated = 1; break; case Privileges.Special: privStated = 3; break; default: throw new Exception("badly attributed test. Need a stated privilege"); } bool maxPrivOk = (privStated >= privUsed); bool privilegesMatch = privUsed == privStated || (privStated == 3 && privUsed == 2); /* * switch (MaximumPrivilege) * { * case NecessaryPrivilege.User: * if (attr.Privileges != PrivilegesNeeded.StandardUser) maxPrivOk = false; * break; * case NecessaryPrivilege.Admin: * if (attr.Privileges != PrivilegesNeeded.Admin) maxPrivOk = false; * break; * case NecessaryPrivilege.Special: * if (attr.Privileges != PrivilegesNeeded.Special) maxPrivOk = false; * break; * default: * throw new Exception(""); * } * // maxPriv is only defined for commands within the MinTPM profile */ if (!privilegesMatch) { SetColorCritical(!maxPrivOk); Logger.WriteErrorToLog("\nPrivilege used is {0} but stated {1} for test {2}", MaximumPrivilege, attr.Privileges, test.Name); if (!maxPrivOk) { Logger.WriteErrorToLog("critical - must fix."); } } if (TestUsesPlatformAuth) { // not allowed for if (attr.CommProfile == Profile.MinTPM) { SetColorCritical(true); string profile = attr.CommProfile.ToString(); Logger.WriteErrorToLog("\nClaimed profile {0} but used PlatformAuth: {1}", profile, test.Name); } } Console.ResetColor(); }