/// <summary> /// Calls 'coyote-rewrite' on the directory passed as the paramerter. This directory should contain /// rewrite.coyote.json file. /// </summary> /// <param name="directory"></param> private static void Rewrite(string directory) { if (directory.Contains("rewritten")) { return; } Debug.WriteLine($"Rewrting the following directory: {directory}"); if (coyote_bin_path == null) { Debug.WriteError("Please give path of the coyote installation, bin directory. Use coyote-path=<> option"); Environment.Exit(1); } // This directory should contain the rewrite.coyote.json file! System.Diagnostics.Debug.Assert(File.Exists(directory + "\\rewrite.coyote.json")); string netruntime = ""; string version = ""; // Try open this file! and load the netcore version it use! foreach (var(info, file) in InsightsEngine.GetTestProjectInfos(directory)) { // Aggregate .NET runtime versions that are used. foreach (var runtimeVersion in info.RuntimeVersions) { string[] ar = runtimeVersion.Split(','); netruntime = ar[0]; version = ar[1]; break; } } string coyote_build_version = ""; if (netruntime.ToLower().Contains(".netframework")) { coyote_build_version = "net48"; } if (netruntime.ToLower().Contains("netcoreapp")) { coyote_build_version = "netcoreapp3.1"; } if (netruntime.ToLower().Contains("netstandard")) { coyote_build_version = "netstandard2.0"; } System.Diagnostics.Debug.Assert(coyote_build_version != ""); string coyote_exe_path = coyote_bin_path + "\\" + coyote_build_version + "\\coyote.exe"; if (!File.Exists(coyote_exe_path)) { Debug.WriteError($"coyote.exe not found in the given path: {coyote_exe_path}"); Environment.Exit(1); } try { System.Diagnostics.Process process = new Process(); process.StartInfo.FileName = coyote_exe_path; process.StartInfo.Arguments = "rewrite " + directory + "\\rewrite.coyote.json"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); string op = process.StandardOutput.ReadToEnd(); string err = process.StandardError.ReadToEnd(); int ex_code = process.ExitCode; // Wait for the process to finish and read its output. Store the output in a file // named log.rewrite.coyote.txt. System.Diagnostics.Debug.Assert(Directory.Exists(directory + "\\rewritten")); File.WriteAllText(directory + "\\rewritten\\log.rewrite.coyote.txt", op + "\n" + err); if (err.Length > 1) { Debug.WriteError(err); } if (ex_code != 0) { Debug.WriteError($"Error: something went wrong in the child process: Exit code = {ex_code} Check: {directory + "\\rewritten\\log.rewrite.coyote.txt"}"); } } catch (Exception e) { Debug.WriteError(e.ToString()); Debug.WriteError("Error: Unable to start a new process. Trying to issue the following command: " + $" {coyote_exe_path} rewrite {directory}\\rewrite.coyote.json"); // Should we terminate the program? Perhaps, no. Let it finish rewriting other directories. return; } }
/// <summary> /// Run testsuite given in the path. The path should contain the test DLL /// </summary> /// <param name="path"></param> private static void RunTestSuite(string path) { Console.WriteLine($"Running test case in dir: {path}"); // Replace the relative path with absolute path path = Path.GetFullPath(path); if (vstest_exe_path == null) { Debug.WriteError("Please give the path to mstest.exe file using mstest-path=<> option"); Environment.Exit(1); } if (!File.Exists(path + "\\cil.insights.json")) { Debug.WriteError($"This directory: {path} does not contain cil.insights.json file!"); Environment.Exit(1); } string testframework = null; string TestDllName = null; // Get the cil.insights.json file and deserialize it foreach (var(info, file) in InsightsEngine.GetTestProjectInfos(path)) { foreach (var testFramework in info.TestFrameworkTypes) { if (testFramework.Contains("MSTest")) { testframework = "MSTest"; break; } else { Debug.WriteError($"Unsupported test framework: {testFramework}"); return; } } foreach (var testAssembly in info.TestAssemblies) { TestDllName = testAssembly; } if (testframework != null && TestDllName != null) { break; } } if (TestDllName == null || testframework == null) { return; } // Check if the Test DLL exists or not if (!File.Exists(path + "\\" + TestDllName)) { Debug.WriteError($"Can not find the following file: {path + "\\" + TestDllName}"); Environment.Exit(1); } TestDllName = path + "\\" + TestDllName; // Used for logging string command_issued = ""; // We are now ready to spawn a new process try { System.Diagnostics.Process process = new Process(); if (testframework == "MSTest") { process.StartInfo.FileName = vstest_exe_path + " "; process.StartInfo.Arguments = "/platform:x64 " + TestDllName; command_issued = process.StartInfo.FileName + process.StartInfo.Arguments; } else { // If it is not MSTest, leave it return; } process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); string op = process.StandardOutput.ReadToEnd(); string err = process.StandardError.ReadToEnd(); int ex_code = process.ExitCode; // MSTest will create this directory. Make sure to remove/change this in case of other // Test framework //System.Diagnostics.Debug.Assert(Directory.Exists(path + "\\TestResults")); File.WriteAllText(path + "\\log.vstest.txt", op); if (err.Length > 1) { Debug.WriteError(err); } if (ex_code != 0) { Debug.WriteError(op); Debug.WriteError($"Error: something went wrong while running the test framework: Perhaps some test failed. Exit code = {ex_code} Check: {path + "\\TestResults"}"); Debug.WriteError("Error: Issued the following command: " + $"{command_issued}"); } } catch (Exception e) { Debug.WriteError(e.ToString()); Debug.WriteError("Error: Unable to start a new process. Trying to issue the following command: " + $"{command_issued}"); // Should we terminate the program? Perhaps, no. Let it finish rewriting other directories. return; } Console.WriteLine($"...Successfully ran test suite in the directory: {path}"); }