Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 98a60b0

Browse files
committed
Merge pull request #1913 from stephentoub/ipc_test
Add process/pipes IPC test
2 parents d9a7a40 + 09d92f9 commit 98a60b0

File tree

6 files changed

+262
-3
lines changed

6 files changed

+262
-3
lines changed

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.TestConsoleApp/TestConsoleApp.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.IO.Pipes;
2+
using System.Threading.Tasks;
23

34
namespace System.Diagnostics.ProcessTests
45
{
@@ -44,6 +45,19 @@ static int Main(string[] args)
4445
Sleep(100);
4546
}
4647
}
48+
else if (args[0].Equals("ipc"))
49+
{
50+
using (var inbound = new AnonymousPipeClientStream(PipeDirection.In, args[1]))
51+
using (var outbound = new AnonymousPipeClientStream(PipeDirection.Out, args[2]))
52+
{
53+
// Echo 10 bytes from inbound to outbound
54+
for (int i = 0; i < 10; i++)
55+
{
56+
int b = inbound.ReadByte();
57+
outbound.WriteByte((byte)b);
58+
}
59+
}
60+
}
4761
else
4862
{
4963
Console.WriteLine(string.Join(" ", args));

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.TestConsoleApp/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {
33
"System.Console": "4.0.0-beta-*",
44
"System.IO": "4.0.10-beta-*",
5+
"System.IO.Pipes": "4.0.0-beta-*",
56
"System.Runtime": "4.0.20-beta-*",
67
"System.Threading.Tasks": "4.0.10-beta-*"
78
},

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.TestConsoleApp/project.lock.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@
5454
"lib/any/System.IO.FileSystem.Primitives.dll"
5555
]
5656
},
57+
"System.IO.Pipes/4.0.0-beta-22927": {
58+
"dependencies": {
59+
"System.Runtime": "4.0.20-beta-22927",
60+
"System.Runtime.InteropServices": "4.0.20-beta-22927",
61+
"System.Resources.ResourceManager": "4.0.0-beta-22927",
62+
"System.Runtime.Handles": "4.0.0-beta-22927",
63+
"System.Threading.Overlapped": "4.0.0-beta-22927",
64+
"System.IO.FileSystem.Primitives": "4.0.0-beta-22927",
65+
"System.Security.Principal": "4.0.0-beta-22927",
66+
"System.Threading": "4.0.10-beta-22927",
67+
"System.Threading.Tasks": "4.0.10-beta-22927",
68+
"System.IO": "4.0.10-beta-22927",
69+
"System.Threading.ThreadPool": "4.0.10-beta-22927",
70+
"System.Runtime.Extensions": "4.0.10-beta-22927"
71+
},
72+
"compile": [
73+
"ref/any/System.IO.Pipes.dll"
74+
],
75+
"runtime": [
76+
"lib/DNXCore50/System.IO.Pipes.dll"
77+
]
78+
},
5779
"System.Private.Uri/4.0.0-beta-22927": {
5880
"runtime": [
5981
"lib/DNXCore50/System.Private.Uri.dll"
@@ -104,6 +126,17 @@
104126
"lib/DNXCore50/System.Runtime.dll"
105127
]
106128
},
129+
"System.Runtime.Extensions/4.0.10-beta-22927": {
130+
"dependencies": {
131+
"System.Runtime": "4.0.20-beta-22927"
132+
},
133+
"compile": [
134+
"ref/any/System.Runtime.Extensions.dll"
135+
],
136+
"runtime": [
137+
"lib/DNXCore50/System.Runtime.Extensions.dll"
138+
]
139+
},
107140
"System.Runtime.Handles/4.0.0-beta-22927": {
108141
"dependencies": {
109142
"System.Runtime": "4.0.0-beta-22927"
@@ -129,6 +162,17 @@
129162
"lib/DNXCore50/System.Runtime.InteropServices.dll"
130163
]
131164
},
165+
"System.Security.Principal/4.0.0-beta-22927": {
166+
"dependencies": {
167+
"System.Runtime": "4.0.0-beta-22927"
168+
},
169+
"compile": [
170+
"ref/any/System.Security.Principal.dll"
171+
],
172+
"runtime": [
173+
"lib/any/System.Security.Principal.dll"
174+
]
175+
},
132176
"System.Text.Encoding/4.0.10-beta-22927": {
133177
"dependencies": {
134178
"System.Runtime": "4.0.0-beta-22927"
@@ -164,6 +208,18 @@
164208
"lib/DNXCore50/System.Threading.dll"
165209
]
166210
},
211+
"System.Threading.Overlapped/4.0.0-beta-22927": {
212+
"dependencies": {
213+
"System.Runtime": "4.0.0-beta-22927",
214+
"System.Runtime.Handles": "4.0.0-beta-22927"
215+
},
216+
"compile": [
217+
"ref/any/System.Threading.Overlapped.dll"
218+
],
219+
"runtime": [
220+
"lib/DNXCore50/System.Threading.Overlapped.dll"
221+
]
222+
},
167223
"System.Threading.Tasks/4.0.10-beta-22927": {
168224
"dependencies": {
169225
"System.Runtime": "4.0.0-beta-22927"
@@ -174,6 +230,18 @@
174230
"runtime": [
175231
"lib/DNXCore50/System.Threading.Tasks.dll"
176232
]
233+
},
234+
"System.Threading.ThreadPool/4.0.10-beta-22927": {
235+
"dependencies": {
236+
"System.Runtime": "4.0.0-beta-22927",
237+
"System.Runtime.InteropServices": "4.0.0-beta-22927"
238+
},
239+
"compile": [
240+
"ref/any/System.Threading.ThreadPool.dll"
241+
],
242+
"runtime": [
243+
"lib/DNXCore50/System.Threading.ThreadPool.dll"
244+
]
177245
}
178246
}
179247
},
@@ -231,6 +299,18 @@
231299
"ref/net46/System.IO.FileSystem.Primitives.dll"
232300
]
233301
},
302+
"System.IO.Pipes/4.0.0-beta-22927": {
303+
"sha512": "EqCANNFHv1ueoK0Wfc1iD+4ycDrk63xdDd1xYIQJfblPH3YpbLFoGBFT81jGon9YhEhv49pNN9Uru2ewi/fbuQ==",
304+
"files": [
305+
"System.IO.Pipes.4.0.0-beta-22927.nupkg",
306+
"System.IO.Pipes.4.0.0-beta-22927.nupkg.sha512",
307+
"System.IO.Pipes.nuspec",
308+
"lib/DNXCore50/System.IO.Pipes.dll",
309+
"lib/net46/System.IO.Pipes.dll",
310+
"ref/any/System.IO.Pipes.dll",
311+
"ref/net46/System.IO.Pipes.dll"
312+
]
313+
},
234314
"System.Private.Uri/4.0.0-beta-22927": {
235315
"sha512": "iugPtkQOqHeCuyvBsQ3Z8vc+4YgL1ySVhe5IiMYIJ5J9kVqMGC9/9tb7SNd80nVSMYIOV/L/SPI1dTDYC+FOvA==",
236316
"files": [
@@ -300,6 +380,20 @@
300380
"runtimes/win8-aot/lib/netcore50/System.Runtime.dll"
301381
]
302382
},
383+
"System.Runtime.Extensions/4.0.10-beta-22927": {
384+
"sha512": "8OW2hPfDCo7ASSLjVvgV7hnOKl67K4EFG/JD/Jjv5zi0rZezneJnYGiPRE4KgXNjsxFmJT8NjPrKSDCWZvb2xw==",
385+
"files": [
386+
"System.Runtime.Extensions.4.0.10-beta-22927.nupkg",
387+
"System.Runtime.Extensions.4.0.10-beta-22927.nupkg.sha512",
388+
"System.Runtime.Extensions.nuspec",
389+
"lib/DNXCore50/System.Runtime.Extensions.dll",
390+
"lib/net46/System.Runtime.Extensions.dll",
391+
"lib/netcore50/System.Runtime.Extensions.dll",
392+
"ref/any/System.Runtime.Extensions.dll",
393+
"ref/net46/System.Runtime.Extensions.dll",
394+
"runtimes/win8-aot/lib/netcore50/System.Runtime.Extensions.dll"
395+
]
396+
},
303397
"System.Runtime.Handles/4.0.0-beta-22927": {
304398
"sha512": "fALM0oSPlQjwxgXZG7K0m3IahgNDXIDT6Rk/VSiovrrRjtHTSe3HxKcRwe0oOYdp0URoT/13TH35J/Bg+fHbKw==",
305399
"files": [
@@ -328,6 +422,18 @@
328422
"runtimes/win8-aot/lib/netcore50/System.Runtime.InteropServices.dll"
329423
]
330424
},
425+
"System.Security.Principal/4.0.0-beta-22927": {
426+
"sha512": "jIUqEIJ7vf5B8ZMZW2app5/wQD2M8XCFbuU8kW63cVVLjdvc3ctLv1rO2jSauXP8+eOeg0PhkvDakKVTrFX1Fw==",
427+
"files": [
428+
"System.Security.Principal.4.0.0-beta-22927.nupkg",
429+
"System.Security.Principal.4.0.0-beta-22927.nupkg.sha512",
430+
"System.Security.Principal.nuspec",
431+
"lib/any/System.Security.Principal.dll",
432+
"lib/net46/System.Security.Principal.dll",
433+
"ref/any/System.Security.Principal.dll",
434+
"ref/net46/System.Security.Principal.dll"
435+
]
436+
},
331437
"System.Text.Encoding/4.0.10-beta-22927": {
332438
"sha512": "ZtyyVxaz9Z0zJrA8dwGCpnqdbg/CO5L4OH1dmLIC18ZKJScRXFJhBPbcj+l8uDDCo0grBLbQpbh6OQ5jgmcfqw==",
333439
"files": [
@@ -370,6 +476,19 @@
370476
"runtimes/win8-aot/lib/netcore50/System.Threading.dll"
371477
]
372478
},
479+
"System.Threading.Overlapped/4.0.0-beta-22927": {
480+
"sha512": "Oc4KXDlynLlrdcGkWXFkxx9Cl+WT/EW4Ye1Garefpcqeoxz5QZAj+nSaIF5m9ifBBRZHyGSiUbyrgnyqPDPrdg==",
481+
"files": [
482+
"System.Threading.Overlapped.4.0.0-beta-22927.nupkg",
483+
"System.Threading.Overlapped.4.0.0-beta-22927.nupkg.sha512",
484+
"System.Threading.Overlapped.nuspec",
485+
"lib/DNXCore50/System.Threading.Overlapped.dll",
486+
"lib/net46/System.Threading.Overlapped.dll",
487+
"lib/netcore50/System.Threading.Overlapped.dll",
488+
"ref/any/System.Threading.Overlapped.dll",
489+
"ref/net46/System.Threading.Overlapped.dll"
490+
]
491+
},
373492
"System.Threading.Tasks/4.0.10-beta-22927": {
374493
"sha512": "SeUpExzifr3zENWz5oMF1M0niHwo8c3xKx3k/p5yBZnvmw7Uxrfgj/Pf5kyD50JB48EdqVJ43IhSml6tOX2ZzA==",
375494
"files": [
@@ -383,12 +502,25 @@
383502
"ref/net46/System.Threading.Tasks.dll",
384503
"runtimes/win8-aot/lib/netcore50/System.Threading.Tasks.dll"
385504
]
505+
},
506+
"System.Threading.ThreadPool/4.0.10-beta-22927": {
507+
"sha512": "kq7puy/cjwwktXc5Vyk8bLHyvaLBmWX0bfs2EvYRVoHhA5cYPrG0jpttFd/jOdlQ7EnHo2wxn2HwuqEHBs/Rsw==",
508+
"files": [
509+
"System.Threading.ThreadPool.4.0.10-beta-22927.nupkg",
510+
"System.Threading.ThreadPool.4.0.10-beta-22927.nupkg.sha512",
511+
"System.Threading.ThreadPool.nuspec",
512+
"lib/DNXCore50/System.Threading.ThreadPool.dll",
513+
"lib/net46/System.Threading.ThreadPool.dll",
514+
"ref/any/System.Threading.ThreadPool.dll",
515+
"ref/net46/System.Threading.ThreadPool.dll"
516+
]
386517
}
387518
},
388519
"projectFileDependencyGroups": {
389520
"": [
390521
"System.Console >= 4.0.0-beta-*",
391522
"System.IO >= 4.0.10-beta-*",
523+
"System.IO.Pipes >= 4.0.0-beta-*",
392524
"System.Runtime >= 4.0.20-beta-*",
393525
"System.Threading.Tasks >= 4.0.10-beta-*"
394526
],

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/ProcessTest.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.IO;
6+
using System.IO.Pipes;
67
using System.Linq;
78
using System.Runtime.InteropServices;
89
using System.Threading.Tasks;
@@ -15,6 +16,7 @@ public partial class ProcessTest : IDisposable
1516
private const int WaitInMS = 100 * 1000;
1617
private const string CoreRunName = "corerun";
1718
private const string TestExeName = "System.Diagnostics.Process.TestConsoleApp.exe";
19+
private const int SuccessExitCode = 100;
1820

1921
private Process _process;
2022
private List<Process> _processes = new List<Process>();
@@ -161,7 +163,7 @@ public void Process_ExitCode()
161163
Process p = CreateProcess();
162164
p.Start();
163165
Assert.True(p.WaitForExit(WaitInMS));
164-
Assert.Equal(p.ExitCode, 100);
166+
Assert.Equal(SuccessExitCode, p.ExitCode);
165167
}
166168

167169
{
@@ -731,5 +733,31 @@ public void Process_StartInfo()
731733
Assert.Throws<System.InvalidOperationException>(() => process.StartInfo);
732734
}
733735
}
736+
737+
[Fact]
738+
public void Process_IPC()
739+
{
740+
Process p = CreateProcess("ipc");
741+
742+
using (var outbound = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
743+
using (var inbound = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
744+
{
745+
p.StartInfo.Arguments += " " + outbound.GetClientHandleAsString() + " " + inbound.GetClientHandleAsString();
746+
p.Start();
747+
outbound.DisposeLocalCopyOfClientHandle();
748+
inbound.DisposeLocalCopyOfClientHandle();
749+
750+
for (byte i = 0; i < 10; i++)
751+
{
752+
outbound.WriteByte(i);
753+
int received = inbound.ReadByte();
754+
Assert.Equal(i, received);
755+
}
756+
757+
Assert.True(p.WaitForExit(WaitInMS));
758+
Assert.Equal(SuccessExitCode, p.ExitCode);
759+
}
760+
}
761+
734762
}
735-
}
763+
}

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"System.Collections": "4.0.10-beta-*",
55
"System.Console": "4.0.0-beta-*",
66
"System.IO": "4.0.10-beta-*",
7+
"System.IO.Pipes": "4.0.0-beta-*",
78
"System.Linq": "4.0.0-beta-*",
89
"System.Runtime": "4.0.20-beta-*",
910
"System.Runtime.Extensions": "4.0.10-beta-*",

0 commit comments

Comments
 (0)