X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2FTestDriver.cs;h=b17cb654fa2903fb1327eb7dd2ff4a299eecd179;hb=411a37af27905eaa44dac1a31f6387a11c0b0244;hp=fdd7a10466f2b5f4cbd410f1723cfe5fba5b0dc0;hpb=4c960e1dd530396fdd9400c87729a6ce3101e5c1;p=mono.git diff --git a/mono/mini/TestDriver.cs b/mono/mini/TestDriver.cs index fdd7a10466f..b17cb654fa2 100644 --- a/mono/mini/TestDriver.cs +++ b/mono/mini/TestDriver.cs @@ -13,10 +13,22 @@ public class CategoryAttribute : Attribute get; set; } } +public class TestDriverReporter +{ + public int FailedTests { get; private set; } + public int SkippedTests { get; private set; } + public int ExecutedTests { get; private set; } + + public void ReportResults (int executed, int skipped, int failed) { + ExecutedTests = executed; + SkippedTests = skipped; + FailedTests = failed; + } +}; public class TestDriver { - static public int RunTests (Type type, string[] args) { + static public int RunTests(Type type, string[] args, TestDriverReporter reporter) { int failed = 0, ran = 0; int result, expected; int i, j, iterations; @@ -135,73 +147,47 @@ public class TestDriver { } } + if (reporter != null) { + reporter.ReportResults (ran, nskipped, failed); + } + //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type); return failed; } + + static public int RunTests (Type type, string[] args) { + return RunTests (type, args, null); + } + static public int RunTests (Type type) { - return RunTests (type, null); + return RunTests (type, null, null); } } /// Provide tests with the ability to find out how much time they have to run before being timed out. -public class TestTimeout { - const string ENV_TIMEOUT = "TEST_DRIVER_TIMEOUT_SEC"; - private readonly TimeSpan availableTime; - private TimeSpan slack; - private DateTime startTime; - - /// - /// How much time the test runner provided for us or TimeSpan.Zero if there is no bound. - /// - public TimeSpan AvailableTime { get { return availableTime; } } - - public DateTime StartTime { get { return startTime; } } - - /// Extra time to add when deciding if there - /// is still time to run. Bigger slack means less - /// time left. - /// - public TimeSpan Slack { - get { return slack; } - set { slack = value; } - } +public class TestTimeout +{ + private TimeSpan Timeout { get; } - public TestTimeout () { - availableTime = initializeAvailableTime (); - slack = defaultSlack (); - } + private DateTime StartTime { get; } - /// - /// Consider the test started. - /// - public void Start () - { - startTime = DateTime.UtcNow; - } + public bool HaveTimeLeft { get { return DateTime.UtcNow - StartTime < Timeout; } } - public bool HaveTimeLeft () - { - if (availableTime == TimeSpan.Zero) - return true; - var t = DateTime.UtcNow; - var finishTime = startTime + availableTime - slack; - return (t < finishTime); - } + public static bool IsStressTest { get { return Environment.GetEnvironmentVariable("MONO_TESTS_STRESS") == "1"; } } - private TimeSpan defaultSlack () + private TestTimeout (TimeSpan timeout) { - return TimeSpan.FromSeconds (5); + Timeout = timeout; + StartTime = DateTime.UtcNow; } - private TimeSpan initializeAvailableTime () + public static TestTimeout Start(TimeSpan timeout) { - var e = System.Environment.GetEnvironmentVariable(ENV_TIMEOUT); - double d; - if (Double.TryParse(e, out d)) { - return TimeSpan.FromSeconds(d); - } else { - return TimeSpan.Zero; + if (timeout.Ticks < 0) + { + throw new ArgumentException("timeout"); } - } + return new TestTimeout(timeout); + } }