private bool RunTestsSerially()

in Tpm2Tester/TestSubstrate/TestFramework.cs [1769:1897]


        private bool RunTestsSerially(List<MethodInfo> tests, Tpm2 tpm, TestContext testCtx,
                                      DateTime endTime, bool parallel, string remainingTestsFile,
                                      out bool aborted)
        {
            aborted = false;
            if (tests.Count == 0)
                return true;

            bool testsFailed = false,
                 sharpDeadline = DateTime.Now <= endTime;
            do {
                if (TestCfg.Shuffle)
                    tests = Shuffle(tests);
                for (int j = 0; j < tests.Count; j++)
                {
                    // get remaining tests and print them out if requests
                    if (remainingTestsFile != null)
                    {
                        string testsLeft = "";
                        for (int k = j; k < tests.Count; k++)
                            testsLeft += tests[k].Name + " ";
                        try
                        {
                            File.WriteAllText(remainingTestsFile, testsLeft, Encoding.ASCII);
                        }
                        catch (Exception)
                        {
                            WriteErrorToLog("Failed to write remaining tests file");
                        }
                    }
                    if (TestCfg.TestValidationRun)
                    {
                        testCtx.ResetAttributeCollection(tpm);
                    }

                    MethodInfo test = tests[j];
#if !TSS_NO_TCP
                    TheTransportLogger.NotifyTestStart(test.Name);

                    if (TheTransportLogger.IsLogging())
                    {
                        // we want the log files to be standalone, so restart the TPM
                        if (TpmProcess == null)
                        {
                            WriteErrorToLog("TPM must be started using -tpm flag");
                        }
                        else
                        {
                            KillTpmProcess();
                            Thread.Sleep(1000);
                            StartTpm();
                            Thread.Sleep(1000);
                        }

                        Tpm2Device tpmDevice = tpm._GetUnderlyingDevice();
                        tpmDevice.Connect();

                        if (!PowerUpTpm(tpmDevice))
                        {
                            WriteErrorToLog("Failed to power-up the TPM");
                            return false;
                        }
                        if (!TpmCfg.PlatformDisabled)
                        {
                            // set the seed to a deterministic value
                            tpm.Clear(TpmRh.Platform);
                        }
                    }
#endif //!TSS_NO_TCP

                    bool succeeded = RunTest(test, tpm, testCtx, !parallel);

                    if (testCtx.ClearWasExecuted && parallel)
                    {
                        throw new Exception("Test case error: Clear() called in stress mode");
                    }

                    if (!succeeded)
                        testsFailed = true;

                    try
                    {
                        if (parallel)
                        {
                            ResetTpmDaLogic(tpm);
                        }
                        else
                        {
                            if (!succeeded)
                                RecoverTpm(tpm);
                            else
                            {
                                ResetTpmDaLogic(tpm);
                                if (InitTPM)
                                {
                                    if (TpmHelper.AreAnySlotsFull(tpm))
                                    {
                                        WriteErrorToLog("Test {0} leaks object handles\n", test.Name);
                                        Substrate.CleanSlots(tpm);
                                    }

                                    bool lostIndicesFound;
                                    CleanNv(tpm, out lostIndicesFound);
                                    if (lostIndicesFound)
                                        WriteErrorToLog("Test {0} leaks NV indices\n", test.Name);
                                }
                            }

                            if (TestCfg.TestValidationRun)
                                testCtx.ValidateTestAttributeCollection(test, tpm);
                        }
                    } catch (Exception e)
                    {
                        // Test run was aborted because of either test infra failure
                        // or TPM getting into the failure mode.
                        ProcessException(e);
                        aborted = true;
                        break;
                    }
#if !TSS_NO_TCP
                    TheTransportLogger.NotifyTestComplete();
#endif
                    if (sharpDeadline && DateTime.Now > endTime)
                        break;
                }
            } while (!aborted && DateTime.Now < endTime);

            return !testsFailed;
        } // RunTestsSerially()