From 505b6f9d2f77e78923716d8cc26f4f07cd7315eb Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Tue, 24 Nov 2015 15:40:03 -0800 Subject: 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. --- tests/runtest.proj | 149 ++++++++++----------- tests/src/CLRTest.Execute.Batch.targets | 23 ++++ .../Coreclr.TestWrapper/CoreclrTestWrapperLib.cs | 103 +++++--------- tests/src/Common/Coreclr.TestWrapper/project.json | 3 +- .../Common/Coreclr.TestWrapper/project.lock.json | 1 + 5 files changed, 129 insertions(+), 150 deletions(-) diff --git a/tests/runtest.proj b/tests/runtest.proj index a667bb102f..413a627303 100644 --- a/tests/runtest.proj +++ b/tests/runtest.proj @@ -201,94 +201,89 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). - + + <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_").Replace("\","_").Replace("-","_")) + <_ClassName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace("cmd","").Replace(".","_").Replace("\","_").Replace("-","_")) - <_FactName>$([System.String]::Copy('%(AllCMDs.FullPath)').Replace("$(_CMDDIR)",'').Replace(".","_")) <_XunitFact > set CORE_ROOT=" + coreRoot + "\n" + + "> " + testExecutable + "\n"%3B + Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B } - + } } - ]]> - - + + diff --git a/tests/src/CLRTest.Execute.Batch.targets b/tests/src/CLRTest.Execute.Batch.targets index 6def6679e8..f8c27be279 100644 --- a/tests/src/CLRTest.Execute.Batch.targets +++ b/tests/src/CLRTest.Execute.Batch.targets @@ -137,6 +137,29 @@ IF NOT "%CLRTestExitCode%"=="%CLRTestExpectedExitCode%" ( ]]> Run testcases under debugger. + + + true + envScriptFullPath + + Run the specified script to set environment variables before running the test. + + + + true + envScriptFullPath + + Set CORE_ROOT to the specified value before running the test. + 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", -- cgit v1.2.3