[mobile_static] Make mono/tests runner handle steps necessary for mobile_static
authorAlexander Kyte <alexmkyte@fastmail.com>
Wed, 1 Jun 2016 18:16:54 +0000 (14:16 -0400)
committerAlexander Kyte <alexmkyte@gmail.com>
Mon, 18 Jul 2016 19:03:40 +0000 (15:03 -0400)
mono/tests/test-runner.cs

index cf9bf3351eb76d2a306b93717f1b687a27eec4ab..4e2827424c8e620af0197eb22db1298ccf08a80d 100644 (file)
@@ -16,6 +16,7 @@ using System.Diagnostics;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Xml;
+using System.Text;
 using System.Text.RegularExpressions;
 
 #if !MOBILE_STATIC
@@ -30,6 +31,7 @@ public class TestRunner
 {
        const string TEST_TIME_FORMAT = "mm\\:ss\\.fff";
        const string ENV_TIMEOUT = "TEST_DRIVER_TIMEOUT_SEC";
+       const string MONO_PATH = "MONO_PATH";
 
        class ProcessData {
                public string test;
@@ -49,13 +51,15 @@ public class TestRunner
                string testsuiteName = null;
                string inputFile = null;
 
-               // FIXME: Add support for runtime arguments + env variables
-
                string disabled_tests = null;
                string runtime = "mono";
                string config = null;
+               string mono_path = null;
                var opt_sets = new List<string> ();
 
+               string aot_run_flags = null;
+               string aot_build_flags = null;
+
                // Process options
                int i = 0;
                while (i < args.Length) {
@@ -127,6 +131,35 @@ public class TestRunner
                                        }
                                        inputFile = args [i + 1];
                                        i += 2;
+                               } else if (args [i] == "--runtime") {
+                                       if (i + 1 >= args.Length) {
+                                               Console.WriteLine ("Missing argument to --runtime command line option.");
+                                               return 1;
+                                       }
+                                       runtime = args [i + 1];
+                                       i += 2;
+                               } else if (args [i] == "--mono-path") {
+                                       if (i + 1 >= args.Length) {
+                                               Console.WriteLine ("Missing argument to --mono-path command line option.");
+                                               return 1;
+                                       }
+                                       mono_path = args [i + 1].Substring(0, args [i + 1].Length);
+
+                                       i += 2;
+                               } else if (args [i] == "--aot-run-flags") {
+                                       if (i + 1 >= args.Length) {
+                                               Console.WriteLine ("Missing argument to --aot-run-flags command line option.");
+                                               return 1;
+                                       }
+                                       aot_run_flags = args [i + 1].Substring(0, args [i + 1].Length);
+                                       i += 2;
+                               } else if (args [i] == "--aot-build-flags") {
+                                       if (i + 1 >= args.Length) {
+                                               Console.WriteLine ("Missing argument to --aot-build-flags command line option.");
+                                               return 1;
+                                       }
+                                       aot_build_flags = args [i + 1].Substring(0, args [i + 1].Length);
+                                       i += 2;
                                } else {
                                        Console.WriteLine ("Unknown command line option: '" + args [i] + "'.");
                                        return 1;
@@ -189,6 +222,36 @@ public class TestRunner
 
                DateTime test_start_time = DateTime.UtcNow;
 
+               if (aot_build_flags != null)  {
+                       var allTests = new StringBuilder();
+                       foreach (string test in tests) {
+                               allTests.Append(test);
+                               allTests.Append(" ");
+                       }
+
+                       string aot_args = aot_build_flags + " " + allTests.ToString();
+
+                       ProcessStartInfo job = new ProcessStartInfo (runtime, aot_args);
+                       job.UseShellExecute = false;
+                       job.EnvironmentVariables[ENV_TIMEOUT] = timeout.ToString();
+                       job.EnvironmentVariables[MONO_PATH] = mono_path;
+                       Process compiler = new Process ();
+                       compiler.StartInfo = job;
+
+                       compiler.Start ();
+
+                       if (!compiler.WaitForExit (timeout * 1000)) {
+                               try {
+                                       compiler.Kill ();
+                               } catch {
+                               }
+                               throw new Exception(String.Format("Timeout AOT compiling tests"));
+                       } else if (compiler.ExitCode != 0) {
+                               throw new Exception(String.Format("Error AOT compiling tests"));
+                       }
+               }
+
+
                for (int j = 0; j < concurrency; ++j) {
                        Thread thread = new Thread (() => {
                                while (true) {
@@ -207,12 +270,20 @@ public class TestRunner
 
                                        output.Write (String.Format ("{{0,-{0}}} ", output_width), test);
 
+                                       string test_invoke;
+
+                                       if (aot_run_flags != null)
+                                               test_invoke = aot_run_flags + " " + test;
+                                       else
+                                               test_invoke = test;
+
                                        /* Spawn a new process */
                                        string process_args;
                                        if (opt_set == null)
-                                               process_args = test;
+                                               process_args = test_invoke;
                                        else
-                                               process_args = "-O=" + opt_set + " " + test;
+                                               process_args = "-O=" + opt_set + " " + test_invoke;
+
                                        ProcessStartInfo info = new ProcessStartInfo (runtime, process_args);
                                        info.UseShellExecute = false;
                                        info.RedirectStandardOutput = true;
@@ -220,6 +291,8 @@ public class TestRunner
                                        info.EnvironmentVariables[ENV_TIMEOUT] = timeout.ToString();
                                        if (config != null)
                                                info.EnvironmentVariables["MONO_CONFIG"] = config;
+                                       if (mono_path != null)
+                                               info.EnvironmentVariables[MONO_PATH] = mono_path;
                                        Process p = new Process ();
                                        p.StartInfo = info;