runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Improve code coverage for System.IO.Pipes

Open stephentoub opened this issue 11 years ago • 12 comments

According to the current code coverage report, this library is only at ~25%. Our general goal is closer to 90%, though this will depend on the library. We should investigate to see whether the current coverage level is appropriate, and if not, improve our test suites to provide better coverage.

stephentoub avatar Mar 15 '15 14:03 stephentoub

Please add me as doing this. I've started to do some of these tests; first I'm doing parameter checking tests ie verify that bad parameters throw the appropriate errors

bpschoch avatar Apr 01 '15 16:04 bpschoch

Thanks, @bpschoch.

stephentoub avatar Apr 03 '15 03:04 stephentoub

I would keep this open. there is more that I'm working on to increase code coverage in this component.

bpschoch avatar Apr 21 '15 12:04 bpschoch

Reopened. It got closed automatically because of your "Fix" reference to it dotnet/corefx#1430's description.

stephentoub avatar Apr 21 '15 12:04 stephentoub

I'm making progress on more coverage on System.IO.Pipes, however I need some suggestions/feedback on how to test the following functionality:

  1. NamedPipeClientStream can pass a TokenImpersonationLevel field to allow the server access to levels of security from the client. Any suggestions on what I should use/pass through to verify that that capability is working properly?

  2. NamedPipeServerStream can retrieve the user name using GetImpersonationUserName(); how should I construct a test that will works both on CI and user systems ie how to setup a username that I can verify

  3. Both named client and server have constructors where you can pass in an existing safepipehandle. The only way I know to test that is to copy the handles from an existing NamedPipeClient/server instance. Any better or other way?

  4. I need to be able to pass what appears to be a safepipehandle to the constructor but is one that doesn't point to a pipe (e.g. a file handle) in order to verify that the code properly checks for a valid pipe handle What is the best way to do this?

  5. NamePipeServerStream supports input and output buffer sizes which appear to be passed into the win32 side of things. Any ideas on how to verify that it is working correctly?

  6. There seems to be subtle behavior documented on the win32 side of pipes regarding how writes maybe block until a corresponding read happens but it seems to be non-deterministic at least as far as what is documented. Is this something we want to test on pipes, e.g. write something, make sure it blocks, do a read to watch it unblock etc.

Pipes in general seems to have a lot of gray areas in the behavior of how they work. To what level of details do we want the testing to verify that kind of behavior? I also then suspect that the behavior would probably then be different on other platforms e.g. *nix

bpschoch avatar May 05 '15 20:05 bpschoch

  1. Both named client and server have constructors where you can pass in an existing safepipehandle. The only way I know to test that is to copy the handles from an existing NamedPipeClient/server instance. Any better or other way?

That's a fine way.

  1. I need to be able to pass what appears to be a safepipehandle to the constructor but is one that doesn't point to a pipe (e.g. a file handle) in order to verify that the code properly checks for a valid pipe handle What is the best way to do this?

You should be able to open a file to get a FileStream, then get that FileStream's SafeFileHandle, and then get from it the IntPtr handle you can then pass to SafePipeHandle's ctor.

  1. NamePipeServerStream supports input and output buffer sizes which appear to be passed into the win32 side of things. Any ideas on how to verify that it is working correctly?

You can check that the associated properties return the appropriate values, but that won't tell you that the underlying OS constructs have been configured appropriately. For the latter, you could try P/Invoking to a function like GetNamedPipeInfo. That'll only work on Win32, but then again at least currently these buffer sizes aren't implemented on Linux/OSX, so you'd want to special-case any buffer size tests, anyway.

Pipes in general seems to have a lot of gray areas in the behavior of how they work. To what level of details do we want the testing to verify that kind of behavior? I also then suspect that the behavior would probably then be different on other platforms e.g. *nix

Yes, the deeper you get, the more differences will become apparent, especially around bidirectional pipes. At that point you'll likely need to restrict the tests to run on only the relevant platforms, or to special-case the results you're checking for based on platform. In terms of what to test for, ideally we'd at least have tests for behaviors documented in MSDN's coverage of the types.

stephentoub avatar May 06 '15 02:05 stephentoub

On 3, I'm not sure how to extract the intptr handle from the safefilehandle (there isn't any properties/methods that I can see). Also assuming I can get around that, what would be the recommend way of accessing the filestream class? here is the issue, each set of tests only reference it's own library, so the pipes test only reference the pipes library and not the files library. Now I can add the files library but to keep the pipes solution kosher, I would need to add the files library to the pipes solution. I thought about using the framework library also that then I think I'll run into issues of cross library usage.

bpschoch avatar May 07 '15 18:05 bpschoch

I'm not sure how to extract the intptr handle from the safefilehandle (there isn't any properties/methods that I can see)

You can use SafeHandle.DangerousGetHandle (with appropriate use of DangerousAddRef and DangerousRelease), e.g.

bool gotRef = false;
try
{
    safeHandle.DangerousAddRef(ref gotRef);
    IntPtr handle = safeHandle.DangerousGetHandle();
    // ... use handle here
}
finally
{
    if (gotRef)
        safeHandle.DangerousRelease();
}

Also assuming I can get around that, what would be the recommend way of accessing the filestream class?

Add System.IO.FileSystem to the project.json file for the test project.

stephentoub avatar May 07 '15 18:05 stephentoub

Thanks, learn something new everyday.

I added System.IO.FileSystem to the project.json file however ti seems I need to do something else as when I build I get this errors:

C:\Users\Bernard\Source\Repos\corefx\packages\Microsoft.DotNet.BuildTools.1.0.2 5-prerelease-00040\lib\packageresolve.targets(31,5): error : Unable to locate S ystem.IO.FileSystem >= 4.0.10-beta-22809 [C:\Users\Bernard\Source\Repos\corefx
src\System.IO.Pipes\tests\System.IO.Pipes.Tests.csproj] C:\Users\Bernard\Source\Repos\corefx\packages\Microsoft.DotNet.BuildTools.1.0.2 5-prerelease-00040\lib\packageresolve.targets(31,5): error MSB3073: The command ""C:\Users\Bernard\Source\Repos\corefx\packages//dnx-coreclr-win-x86.1.0.0-bet a5-11580/\bin\dnu.cmd" restore --packages "C:\Users\Bernard\Source\Repos\corefx \packages" "C:\Users\Bernard\Source\Repos\corefx\src\System.IO.Pipes\tests/proj ect.json"" exited with code 1. [C:\Users\Bernard\Source\Repos\corefx\src\System .IO.Pipes\tests\System.IO.Pipes.Tests.csproj] Done Building Project "C:\Users\Bernard\Source\Repos\corefx\src\System.IO.Pipes \tests\System.IO.Pipes.Tests.csproj" (BuildAndTest target(s)) -- FAILED.

bpschoch avatar May 07 '15 19:05 bpschoch

I believe the System.IO.FileSystem version should be 4.0.0-beta-22809, not 4.0.10-beta-22809.

stephentoub avatar May 07 '15 19:05 stephentoub

Ok thanks, that fixed. But how did you know it was that version? where do you find that out? project.json is a bit of a black hole to me right now.

bpschoch avatar May 07 '15 20:05 bpschoch

But how did you know it was that version? where do you find that out?

I usually just look at other project.json files from other libraries to see what version they're using. I've also updated the corefx homepage to show the latest version of each package available.

stephentoub avatar May 11 '15 21:05 stephentoub