in Tpm2Tester/TestSubstrate/TestFramework.cs [1928:2039]
private bool RunTest(MethodInfo testMethod, Tpm2 tpm, TestContext testCtx,
bool retryEnabled = false)
{
bool retry = false;
int curPhase = 0;
//NewTest = true;
var attrs = Globs.GetAttr<TestAttribute>(testMethod);
if ( TpmCfg.PlatformDisabled && attrs.SpecialNeeds.HasFlag(Special.Platform)
|| !TpmCfg.PowerControl && attrs.SpecialNeeds.HasFlag(Special.PowerControl)
|| !TpmCfg.LocalityControl && attrs.SpecialNeeds.HasFlag(Special.Locality)
|| !TpmCfg.NvControl && attrs.SpecialNeeds.HasFlag(Special.NvControl)
|| TpmCfg.LockoutAuthUnknown && attrs.SpecialNeeds.HasFlag(Special.Lockout)
|| TestCfg.HasTRM && attrs.SpecialNeeds.HasFlag(Special.NoTRM))
{
WriteToLog(testMethod.Name + " skipped", ConsoleColor.DarkCyan);
return true;
}
// Mark transition of the statistics domain from Tpm2Tester infra to the test
testCtx.TestStarted(testMethod.Name, Substrate.ReseedRng());
if (FuzzMode)
WriteToLog("-seed " + testCtx.CurRngSeed, ConsoleColor.Gray);
else
tpm._SetWarningHandler(testCtx.ReportWarning);
if (DebugExceptions)
{
// If you are developing test cases it is useful for the debugger to
// be invoked at the point the exception is thrown. Set DebugExceptions
// to enable this behavior. Note that this will disable error reporting
// and test restart functionality.
// A better alternative is to request the debugger to break whenever
// a particular exception happens by means of
// Visual Studio Debug | Exceptions
// dialog. This allows to continue with usual exception processing
// after it is inspected in the debugger, leaving all Tpm2Tester
// functionality intact.
testMethod.Invoke(TestContainer, new object[] {tpm, testCtx});
}
else do try
{
retry = false;
int numArgs = testMethod.GetParameters().Length;
if (numArgs == 2)
{
retryEnabled = false;
testMethod.Invoke(TestContainer, new object[] {tpm, testCtx});
}
else
{
// Only test methods with 2- or 3-argument are supported.
Substrate.Assert(numArgs == 3);
curPhase = TheTestState.TestPhase;
testMethod.Invoke(TestContainer, new object[] {tpm, testCtx, TheTestState});
}
tpm._SetInjectCmdCallback(null);
}
catch (Exception e)
{
if (!(e is EscapeException))
Debug.WriteLine($"Unexpected exception {e}");
tpm._SetInjectCmdCallback(null);
retry = retryEnabled
&& TheTestState.TestPhase != TestState.NullPhase
&& curPhase != TheTestState.TestPhase;
if (!(e is TssAssertException ||
(e.InnerException != null && e.InnerException is TssAssertException)))
{
ProcessException(tpm, testCtx, e, testMethod);
}
if (retry)
{
// Mark transition of the statistics domain to the Tpm2Tester infra...
testCtx.TestCompleted();
Substrate.CleanSlots(tpm);
// ... and back to the test
testCtx.TestStarted(testMethod.Name, Substrate.ReseedRng());
}
} while (retry);
bool result = testCtx.CurTestStatus == TestStatus.OK;
// Reset the test state
TheTestState.TestPhase = TestState.NullPhase;
TheTestState.TestParams = null;
testCtx.TestCompleted();
if (TpmCfg.PowerControl)
{
foreach (var kv in testCtx.CmdStats)
{
TpmCc cc = kv.Key;
if (cc == TpmCc.PcrAllocate)
{
uint maxNum, sizeNeeded, sizeAvailable;
tpm.PcrAllocate(TpmRh.Platform, TpmCfg.PcrBanks.ToArray(),
out maxNum, out sizeNeeded, out sizeAvailable);
Substrate.ResetTpm(tpm);
break;
}
}
}
MainTpm._SetWarningHandler(null);
return result;
} // RunTest()