Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/IronPythonTest/Cases/AllCPythonCasesManifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Ignore=false
Arguments="$(TEST_FILE)"
WorkingDirectory=$(TEST_FILE_DIR)
Redirect=false
Timeout=600000 ; 10 minute timeout

[AllCPython.test___all__]
IsolationLevel=PROCESS
Expand Down Expand Up @@ -816,7 +817,6 @@ RunCondition='$(OS)' != 'Unix' AND NOT $(IS_NETCOREAPP)
Reason=TODO: figure out
IsolationLevel=PROCESS
Redirect=true
Timeout=300000

[AllCPython.test_sunau]
Ignore=true
Expand Down
1 change: 1 addition & 0 deletions Src/IronPythonTest/Cases/CTypesCPythonCasesManifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WorkingDirectory=$(TEST_FILE_DIR)
Redirect=false
RunCondition=NOT $(IS_NETCOREAPP) AND NOT $(IS_MACOS)
Reason=ctypes is not working on .NET Core yet
Timeout=600000 ; 10 minute timeout

[CTypesCPython.test_errno]
Ignore=true
Expand Down
35 changes: 26 additions & 9 deletions Src/IronPythonTest/Cases/CaseExecuter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using IronPython.Hosting;
using IronPython.Runtime;
Expand Down Expand Up @@ -164,7 +166,7 @@ private int GetEngineTest(TestInfo testcase) {
var source = engine.CreateScriptSourceFromString(
testcase.Text, testcase.Path, SourceCodeKind.File);

return GetResult(engine, source, testcase.Path, testcase.Options.WorkingDirectory);
return GetResult(testcase, engine, source, testcase.Path, testcase.Options.WorkingDirectory);
}

private int GetProcessTest(TestInfo testcase) {
Expand Down Expand Up @@ -202,7 +204,7 @@ private int GetProcessTest(TestInfo testcase) {

if (!proc.WaitForExit(testcase.Options.Timeout)) {
proc.Kill();
Console.Error.Write($"Timed out after {testcase.Options.Timeout / 1000.0} seconds.");
NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
}
exitCode = proc.ExitCode;
}
Expand Down Expand Up @@ -232,10 +234,10 @@ private int GetScopeTest(TestInfo testcase) {
var source = this.defaultEngine.CreateScriptSourceFromString(
testcase.Text, testcase.Path, SourceCodeKind.File);

return GetResult(this.defaultEngine, source, testcase.Path, testcase.Options.WorkingDirectory);
return GetResult(testcase, this.defaultEngine, source, testcase.Path, testcase.Options.WorkingDirectory);
}

private int GetResult(ScriptEngine engine, ScriptSource source, string testPath, string workingDir) {
private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource source, string testPath, string workingDir) {
int res = 0;
var path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
if (string.IsNullOrEmpty(path)) {
Expand All @@ -255,12 +257,27 @@ private int GetResult(ScriptEngine engine, ScriptSource source, string testPath,
var scope = engine.CreateScope();
engine.GetSysModule().SetVariable("argv", List.FromArrayNoCopy(new object[] { source.Path }));
var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" });

var thread = new Thread(() => {
try {
res = engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0);
} catch (SystemExitException ex) {
res = ex.GetExitCode(out object otherCode);
} catch (ThreadAbortException) {
Thread.ResetAbort();
}
}) {
IsBackground = true
};

try {
res = engine.Operations.ConvertTo<int>(compiledCode.Execute(scope) ?? 0);
} catch (SystemExitException ex) {
object otherCode;
res = ex.GetExitCode(out otherCode);
thread.Start();

if (!thread.Join(testcase.Options.Timeout)) {
if(!ClrModule.IsNetCoreApp) {
thread.Abort();
}
NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
res = -1;
}
} finally {
Environment.CurrentDirectory = cwd;
Expand Down
1 change: 1 addition & 0 deletions Src/IronPythonTest/Cases/IronPythonCasesManifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Arguments="$(TEST_FILE)"
IsolationLevel=PROCESS
WorkingDirectory=$(TEST_FILE_DIR)
Redirect=false
Timeout=600000 ; 10 minute timeout

[IronPython.test_cliclass]
RunCondition='$(OS)' != 'Unix'
Expand Down
1 change: 1 addition & 0 deletions Src/IronPythonTest/Cases/StandardCPythonCasesManifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Ignore=false
WorkingDirectory=$(TEST_FILE_DIR)
Redirect=false
Timeout=600000 ; 10 minute timeout

[StandardCPython.test_builtin]
Ignore=true
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPythonTest/Util/TestManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public bool Redirect {

public int Timeout {
get {
return this.manifest.GetInt(this.testName, "Timeout", -1);
return this.manifest.GetInt(this.testName, "Timeout", System.Threading.Timeout.Infinite);
}
}

Expand Down