diff options
author | Ludovic Henry <ludovic@xamarin.com> | 2017-02-16 21:10:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 21:10:33 +0300 |
commit | b6f511dc167873896a163599d2de9ce1e34ecc6c (patch) | |
tree | 9bbc6a5b6f949dd7a65267c78c07d4674a6b3f6e /mcs/class/System/Test | |
parent | deda0b8d8ce00b81bef7752b528b3117bf0ead20 (diff) |
[process] Allocate a handle even for non-child processes (#4393)
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r-- | mcs/class/System/Test/System.Diagnostics/ProcessTest.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs b/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs index dcf83695f06..45d578d3f58 100644 --- a/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs +++ b/mcs/class/System/Test/System.Diagnostics/ProcessTest.cs @@ -14,6 +14,7 @@ using System.Diagnostics; using System.IO; using System.Text; using System.Threading; +using System.Runtime.InteropServices; using NUnit.Framework; @@ -1130,5 +1131,57 @@ namespace MonoTests.System.Diagnostics string v = Process.GetProcessById (1).ProcessName; } + + [Test] + public void NonChildProcessWaitForExit () + { + if (!RunningOnUnix) + Assert.Ignore ("accessing parent pid, only available on unix"); + + using (Process process = Process.GetProcessById (getppid ())) + { + Assert.IsFalse (process.WaitForExit (10), "#1"); + Assert.IsFalse (process.HasExited, "#2"); + Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#3"); + + process.Exited += (s, e) => Assert.Fail ("#4"); + + Assert.IsFalse (process.WaitForExit (10), "#5"); + Assert.IsFalse (process.HasExited, "#6"); + Assert.Throws<InvalidOperationException>(delegate { int exitCode = process.ExitCode; }, "#7"); + } + } + + [Test] + public void NonChildProcessName () + { + if (!RunningOnUnix) + Assert.Ignore ("accessing parent pid, only available on unix"); + + using (Process process = Process.GetProcessById (getppid ())) + { + string pname = process.ProcessName; + Assert.IsNotNull (pname, "#1"); + AssertHelper.IsNotEmpty (pname, "#2"); + } + } + + [Test] + public void NonChildProcessId () + { + if (!RunningOnUnix) + Assert.Ignore ("accessing parent pid, only available on unix"); + + int ppid; + using (Process process = Process.GetProcessById (ppid = getppid ())) + { + int pid = process.Id; + Assert.AreEqual (ppid, pid, "#1"); + AssertHelper.Greater (pid, 0, "#2"); + } + } + + [DllImport ("libc")] + static extern int getppid(); } } |