diff options
author | Pat Gavlin <pagavlin@microsoft.com> | 2015-11-24 15:40:03 -0800 |
---|---|---|
committer | Pat Gavlin <pagavlin@microsoft.com> | 2015-11-25 10:03:47 -0800 |
commit | 505b6f9d2f77e78923716d8cc26f4f07cd7315eb (patch) | |
tree | 3a6686386c2f8d23e2a7cde83bc43fb8c79e5b24 /tests/src/Common/Coreclr.TestWrapper | |
parent | 49fdf52a0fb9073e54ea42514d401faee891be45 (diff) | |
download | coreclr-505b6f9d2f77e78923716d8cc26f4f07cd7315eb.tar.gz coreclr-505b6f9d2f77e78923716d8cc26f4f07cd7315eb.tar.bz2 coreclr-505b6f9d2f77e78923716d8cc26f4f07cd7315eb.zip |
Clean up the CoreCLR test wrappers.
- Various simplifications to the Xunit wrapper and the test helper
- Allow the specification of the test env script and the CORE_ROOT
directory at the command line on Windows.
Diffstat (limited to 'tests/src/Common/Coreclr.TestWrapper')
3 files changed, 34 insertions, 73 deletions
diff --git a/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs b/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs index 22de3fb97b..39281a8809 100644 --- a/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs +++ b/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs @@ -8,99 +8,58 @@ using System.Diagnostics; using System.IO; using System.Text; using System.Threading; +using System.Threading.Tasks; + namespace CoreclrTestLib { public class CoreclrTestWrapperLib { public const int EXIT_SUCCESS_CODE = 0; - public int RunTest(string cmdLine, string outputfile, string errorfile) + public int RunTest(string executable, string outputFile, string errorFile) { - System.IO.TextWriter output_file = new System.IO.StreamWriter(new FileStream(outputfile, FileMode.Create)); - System.IO.TextWriter err_file = new System.IO.StreamWriter(new FileStream(errorfile, FileMode.Create)); + Debug.Assert(outputFile != errorFile); int exitCode = -100; int timeout = 1000 * 60*10; + + var outputStream = new FileStream(outputFile, FileMode.Create); + var errorStream = new FileStream(errorFile, FileMode.Create); + + using (var outputWriter = new StreamWriter(outputStream)) + using (var errorWriter = new StreamWriter(errorStream)) using (Process process = new Process()) { - process.StartInfo.FileName = cmdLine; + process.StartInfo.FileName = executable; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; - - - StringBuilder output = new StringBuilder(); - StringBuilder error = new StringBuilder(); - - using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) - using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) - { - process.OutputDataReceived += (sender, e) => - { - if (e.Data == null) - { - try - { - outputWaitHandle.Set(); - } - catch (ObjectDisposedException) - { - // Noop for access after timeout. - } - } - else - { - output.AppendLine(e.Data); - } - }; - process.ErrorDataReceived += (sender, e) => - { - if (e.Data == null) - { - try - { - errorWaitHandle.Set(); - } - catch (ObjectDisposedException) - { - // Noop for access after timeout. - } - } - else - { - error.AppendLine(e.Data); - } - }; - process.Start(); + process.Start(); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); + Task copyOutput = process.StandardOutput.BaseStream.CopyToAsync(outputStream); + Task copyError = process.StandardError.BaseStream.CopyToAsync(errorStream); - if (process.WaitForExit(timeout) && - outputWaitHandle.WaitOne(timeout) && - errorWaitHandle.WaitOne(timeout)) - { - // Process completed. Check process.ExitCode here. - exitCode = process.ExitCode; - } - else - { - // Timed out. - output.AppendLine("cmdLine:" + cmdLine + " Timed Out"); - error.AppendLine("cmdLine:" + cmdLine + " Timed Out"); - } + bool completed = process.WaitForExit(timeout) && + copyOutput.Wait(timeout) && + copyError.Wait(timeout); - output_file.WriteLine(output.ToString()); - output_file.WriteLine("Test Harness Exitcode is : " + exitCode.ToString()); - output_file.Flush(); + if (completed) + { + // Process completed. Check process.ExitCode here. + exitCode = process.ExitCode; + } + else + { + // Timed out. + outputWriter.WriteLine("cmdLine:" + executable + " Timed Out"); + errorWriter.WriteLine("cmdLine:" + executable + " Timed Out"); + } - err_file.WriteLine(error.ToString()); - err_file.Flush(); + outputWriter.WriteLine("Test Harness Exitcode is : " + exitCode.ToString()); + outputWriter.Flush(); - output_file.Dispose(); - err_file.Dispose(); - } + errorWriter.Flush(); } return exitCode; diff --git a/tests/src/Common/Coreclr.TestWrapper/project.json b/tests/src/Common/Coreclr.TestWrapper/project.json index cd536cf30e..668501240a 100644 --- a/tests/src/Common/Coreclr.TestWrapper/project.json +++ b/tests/src/Common/Coreclr.TestWrapper/project.json @@ -9,6 +9,7 @@ "System.Runtime.Handles": "4.0.0-beta-23302", "System.Runtime.Loader": "4.0.0-beta-23302", "System.Threading": "4.0.10-beta-23302", + "System.Threading.Tasks": "4.0.10-beta-23302", "System.Globalization.Calendars": "4.0.0-beta-23302", "System.Globalization": "4.0.10-beta-23302", "System.Text.Encoding": "4.0.10-beta-23302", @@ -30,4 +31,4 @@ "frameworks": { "dnxcore50": {} } -}
\ No newline at end of file +} diff --git a/tests/src/Common/Coreclr.TestWrapper/project.lock.json b/tests/src/Common/Coreclr.TestWrapper/project.lock.json index 9860deb251..38c02b86b9 100644 --- a/tests/src/Common/Coreclr.TestWrapper/project.lock.json +++ b/tests/src/Common/Coreclr.TestWrapper/project.lock.json @@ -1914,6 +1914,7 @@ "System.Runtime.Handles >= 4.0.0-beta-23302", "System.Runtime.Loader >= 4.0.0-beta-23302", "System.Threading >= 4.0.10-beta-23302", + "System.Threading.Tasks >= 4.0.10-beta-23302", "System.Globalization.Calendars >= 4.0.0-beta-23302", "System.Globalization >= 4.0.10-beta-23302", "System.Text.Encoding >= 4.0.10-beta-23302", |