public void RunTest(Func <IRelaTest> makeTest, int numIterations = 10000, ulong liveLockLimit = 5000) { var test = makeTest(); var scheduler = new NaiveRandomScheduler(test.ThreadEntries.Count, numIterations); while (scheduler.NewIteration() && !TestFailed) { TE.RunTest(test, scheduler, liveLockLimit); test = makeTest(); } }
private static void RunExample(string exampleTag, IRelaExample example, Options options) { var TR = TestRunner.TR; while (example.SetNextConfiguration()) { if (!options.SelfTest) { var expectedResult = example.ExpectedToFail ? "fail" : "pass"; Console.WriteLine($"***** Current configuration for '{example.Name}' is '{example.Description}', this is expected to {expectedResult}"); } var sw = new Stopwatch(); sw.Start(); int numIterations = 0; ulong totalOperations = 0; bool testFailed = false; IScheduler scheduler; example.PrepareForIteration(); int numThreads = example.ThreadEntries.Count; switch (options.Scheduling) { case Options.SchedulingAlgorithm.Random: scheduler = new NaiveRandomScheduler(numThreads, options.Iterations); break; case Options.SchedulingAlgorithm.Exhaustive: scheduler = new ExhaustiveScheduler(numThreads, options.LiveLockLimit * 2, options.YieldLookbackPenalty); break; default: throw new Exception($"Unsupported scheduling algorithm '{options.Scheduling}'"); } while (scheduler.NewIteration() && !testFailed) { example.PrepareForIteration(); TR.RunTest(example, scheduler, options.LiveLockLimit); testFailed = TR.TestFailed; totalOperations += TR.ExecutionLength; ++numIterations; } var panic = "*\n*\n*\n*\n*\n*\n*\n*"; if (TR.TestFailed) { if (options.SelfTest) { if (!example.ExpectedToFail) { Console.WriteLine($"{exampleTag}['{example.Description}'] expected to pass but failed on iteration number {numIterations}."); } } else { Console.WriteLine($"Example failed on iteration number: {numIterations}"); Console.WriteLine(example.ExpectedToFail ? "Not to worry, this failure was expected" : $"{panic}\tUh-oh: This example was expected to pass.\n{panic}"); } if (!options.QuietMode && !options.SelfTest) { TR.DumpExecutionLog(Console.Out); } } else { if (options.SelfTest) { if (example.ExpectedToFail) { Console.WriteLine($"{exampleTag}['{example.Description}'] expected to fail but survived {numIterations} iterations."); } } else { Console.WriteLine($"No failures after {numIterations} iterations"); Console.WriteLine(example.ExpectedToFail ? $"{panic}\tUh-oh: This example was expected to fail.\n{panic}" : "That's good, this example was expected to pass."); } } if (!options.SelfTest) { var elapsed = sw.Elapsed.TotalSeconds; Console.WriteLine($"Tested {totalOperations / elapsed:F3} operations per second ({numIterations} iterations at {(numIterations) / elapsed:F3} iterations per second) for {elapsed} seconds."); Console.WriteLine(".........................."); } } }