Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@@ -2,6 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyKey>Open</AssemblyKey>
</PropertyGroup>
</Project>

View File

@@ -3,12 +3,9 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.IO.Ports.csproj">
<SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.IO.Ports.csproj" />
<NotSupportedOnTargetFramework Include="netcore50">
<PackageTargetRuntime>win</PackageTargetRuntime>
</NotSupportedOnTargetFramework>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -3,6 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netstandard;
netfx;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -3,12 +3,18 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{75DE4259-43BB-4067-9F30-3AC920D51AEC}</ProjectGuid>
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netfx'">true</IsPartialFacadeAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.IO.Ports.cs" />
<Reference Include="netstandard" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netfx'">
<Reference Include="mscorlib" />
<Reference Include="System" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -3,6 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netstandard-Windows_NT;
netstandard;
netfx;
</BuildConfigurations>
</PropertyGroup>

View File

@@ -130,9 +130,6 @@
<data name="NotSupported_UnseekableStream" xml:space="preserve">
<value>Stream does not support seeking.</value>
</data>
<data name="IO_EOF_ReadBeyondEOF" xml:space="preserve">
<value>Unable to read beyond the end of the stream.</value>
</data>
<data name="ObjectDisposed_StreamClosed" xml:space="preserve">
<value>Can not access a closed Stream.</value>
</data>
@@ -169,4 +166,7 @@
<data name="UnauthorizedAccess_IODenied_Path" xml:space="preserve">
<value>Access to the port '{0}' is denied.</value>
</data>
<data name="PlatformNotSupported_IOPorts" xml:space="preserve">
<value>System.IO.Ports is currently only supported on Windows.</value>
</data>
</root>

View File

@@ -5,13 +5,17 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProjectGuid>{187503F4-BEF9-4369-A1B2-E3DC5D564E4E}</ProjectGuid>
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netfx'">true</IsPartialFacadeAssembly>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetGroup)' == 'netstandard' AND '$(TargetsWindows)' != 'true'">SR.PlatformNotSupported_IOPorts</GeneratePlatformNotSupportedAssemblyMessage>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
</PropertyGroup>
<!-- Default configurations to help VS understand the options -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)' != 'netfx'">
<ItemGroup Condition="'$(TargetGroup)' != 'netfx' AND '$(TargetsWindows)' == 'true'">
<Compile Include="System\IO\Ports\Handshake.cs" />
<Compile Include="System\IO\Ports\InternalResources.cs" />
<Compile Include="System\IO\Ports\NativeMethods.cs" />

View File

@@ -8,6 +8,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
// Notes about the SerialStream:
// * The stream is always opened via the SerialStream constructor.
@@ -52,6 +53,7 @@ namespace System.IO.Ports
// internal-use members
internal SafeFileHandle _handle = null;
internal EventLoopRunner _eventRunner;
private Task _waitForComEventTask = null;
private byte[] _tempBuf; // used to avoid multiple array allocations in ReadByte()
@@ -714,10 +716,8 @@ namespace System.IO.Ports
// prep. for starting event cycle.
_eventRunner = new EventLoopRunner(this);
Thread eventLoopThread = new Thread(new ThreadStart(_eventRunner.WaitForCommEvent));
eventLoopThread.IsBackground = true;
eventLoopThread.Start();
_waitForComEventTask = Task.Factory.StartNew(s => ((EventLoopRunner)s).WaitForCommEvent(), _eventRunner, CancellationToken.None,
TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
catch
{
@@ -742,7 +742,6 @@ namespace System.IO.Ports
{
try
{
_eventRunner.endEventLoop = true;
Thread.MemoryBarrier();
@@ -790,12 +789,9 @@ namespace System.IO.Ports
DiscardOutBuffer();
}
if (disposing && _eventRunner != null)
if (disposing && _eventRunner != null && _waitForComEventTask != null)
{
// now we need to wait for the event loop to tell us it's done. Without this we could get into a race where the
// event loop kept the port open even after Dispose ended.
_eventRunner.eventLoopEndedSignal.WaitOne();
_eventRunner.eventLoopEndedSignal.Close();
_waitForComEventTask.GetAwaiter().GetResult();
_eventRunner.waitCommEventWaitHandle.Close();
}
}
@@ -1304,6 +1300,8 @@ namespace System.IO.Ports
// Later the user may change this via the NullDiscard property.
SetDcbFlag(NativeMethods.FNULL, discardNull ? 1 : 0);
// SerialStream does not handle the fAbortOnError behaviour, so we must make sure it's not enabled
SetDcbFlag(NativeMethods.FABORTONOERROR, 0);
// Setting RTS control, which is RTS_CONTROL_HANDSHAKE if RTS / RTS-XOnXOff handshaking
// used, RTS_ENABLE (RTS pin used during operation) if rtsEnable true but XOnXoff / No handshaking
@@ -1642,7 +1640,6 @@ namespace System.IO.Ports
internal sealed class EventLoopRunner
{
private WeakReference streamWeakReference;
internal ManualResetEvent eventLoopEndedSignal = new ManualResetEvent(false);
internal ManualResetEvent waitCommEventWaitHandle = new ManualResetEvent(false);
private SafeFileHandle handle = null;
private bool isAsync;
@@ -1776,7 +1773,6 @@ namespace System.IO.Ports
endEventLoop = true;
Overlapped.Free(intOverlapped);
}
eventLoopEndedSignal.Set();
}
private unsafe void FreeNativeOverlappedCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)

View File

@@ -3,6 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netstandard-Windows_NT;
netfx;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -1,101 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// This is a regression test for a crashing bug in Serial Port.
// The original bug is DevDiv Bugs #142639, fixed with a QFE in WhidbeyQFE. It only repros in 64-bit.
// BWadswor later reported the bug again using essentially the following code. See Dev10 #619306.
using System;
using System.Threading;
using System.IO.Ports;
using System.Diagnostics;
using Legacy.Support;
internal class Test_CLRS
{
private static bool s_done;
public static void gc_food()
{
object[] bah = new object[100];
Random r = new Random(-55);
while (!s_done)
{
int i = r.Next(100);
bah[i] = new object[r.Next(1000)];
GC.Collect(2, GCCollectionMode.Forced);
}
}
private static int Main()
{
try
{
String[] portNames = PortHelper.GetPorts();
if (portNames.Length == 0)
{
Debug.WriteLine("No serial ports available. Not running test.");
}
else
{
s_done = false;
Thread food = null;
food = new Thread(new ThreadStart(gc_food));
food.Start();
foreach (String portName in portNames)
{
Debug.WriteLine(portName);
OpenClose(portName);
LeaveOpen(portName);
}
}
// if neither of these crashed, then pass.
s_done = true; // stop the gc thread
return 100;
}
catch (Exception ex)
{
Debug.WriteLine("Unexpected exception! " + ex.ToString());
return 99;
}
}
private static void OpenClose(String portName)
{
Debug.WriteLine("OpenClose (should finish quickly)");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
SerialPort Port = new SerialPort(portName);
Port.Open();
Port.Close();
Port.Open();
Port.Close();
Port.Open();
Port.Close();
Port.Open();
Port.Close();
Port.Open();
Port.Close();
stopwatch.Stop();
Debug.WriteLine("Elapsed time: {0:mm'm'ss'.'fff's'}", stopwatch.Elapsed);
}
private static void LeaveOpen(String portName)
{
Debug.WriteLine("LeaveOpen (runs for 1 minute)");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Thread.Sleep(100);
SerialPort Port = new SerialPort(portName);
Port.Open();
while (Port.IsOpen && stopwatch.ElapsedMilliseconds < 60000) // 1 minute
{
Thread.Sleep(10);
}
Port.Close();
stopwatch.Stop();
Debug.WriteLine("Elapsed time: {0:mm'm'ss'.'fff's'}", stopwatch.Elapsed);
}
}

View File

@@ -1,90 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// This is a regression test for Dev10 #511456, DevDiv Bugs #186131, and DevDiv Bugs #191753.
// Unplugged USB virtual serial port causes SerialPort object to crash application in finalizer thread.
//
// For this manual test, you will need a USB Serial adapater, probably one like this:
// Keyspan (keyspan.com) model USA-19HS
// http://www.tripplite.com/en/products/model.cfm?txtSeriesID=518&txtModelID=3914
// There should be one around here somewhere.
// This site should have a driver if you need one.
//
// Connect the serial end to loopback (connect pins 3 and 4).
//
// Plug the adapter into a USB port on the machine, and run this test.
// By default it runs using COM3. If you need a different port name, pass it as an argument.
// Unplug the adapter from the USB port when prompted.
// Look for no exception and a passing exit code.
//
// Before the fix, an unhandled exception would be seen:
// Unhandled Exception: System.UnauthorizedAccessException: Access to the port is denied.
// at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
// at System.IO.Ports.SerialStream.Dispose(Boolean disposing)
// at System.IO.Ports.SerialStream.Finalize()
using System;
using System.Diagnostics;
using System.IO.Ports;
public class Test
{
public static void UnhandledExceptionHandler(Object sender, UnhandledExceptionEventArgs eventArgs)
{
Debug.WriteLine("Exception caught in UnhandledExceptionHandler: {0}", eventArgs.ExceptionObject);
Environment.ExitCode = 97;
}
public static void Main(String[] args)
{
System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
try
{
Debug.WriteLine("Connect the USB/serial adapter to a USB port and press Enter to continue...");
Console.ReadLine();
// Get the port name, if one is passed in.
String portName = "COM3";
if (args.Length > 0)
portName = args[0];
SerialPort port = new SerialPort(portName);
Debug.WriteLine("Using {0}", portName);
try
{
port.Open();
}
catch (System.IO.IOException)
{
Debug.WriteLine("Error opening serial port. This can happen if the adapter was just connected. Sleeping 5 seconds before trying again...");
System.Threading.Thread.Sleep(5000);
try
{
port.Open();
}
catch (System.IO.IOException ex)
{
Debug.WriteLine("Error opening serial port. Make sure the USB serial adapter is plugged into a USB port and that the port name is correct.");
Debug.WriteLine(ex);
Environment.ExitCode = 98;
}
}
Debug.WriteLine("{0} opened.", port.PortName);
Debug.WriteLine("Disconnect USB serial adapter and press Enter to continue...");
Console.ReadLine();
// Calling port.Close() after the adapter is disconnected will still get an
// UnauthorizedAccessException, so don't do it.
Debug.WriteLine("Pass if no exception and exitcode==100.");
Environment.ExitCode = 100;
}
catch (Exception ex)
{
Debug.WriteLine("Exception caught in Main() - {0}", ex);
Environment.ExitCode = 99;
}
}
}

View File

@@ -0,0 +1,72 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.IO.PortsTests;
using System.Reflection;
using Legacy.Support;
using Xunit;
namespace System.IO.Ports.Tests
{
public class AbortOnError : PortsTest
{
/// <summary>
/// This is a test for GH issue 17396, Connect issue 584116
///
/// The situation is as follows:
/// * Some user of the port causes DCB.fAbortOnError to be set at some point
/// * The port is later opened by SerialPort - which doesn't clear fAbortOnError
/// when it's initialising the port
/// * Subsequent errors on the port are mishandled, because fAbortOnError causes
/// the error behaviour to be different, and SerialPort isn't prepared for this
///
/// To test this, we need to do the following
/// 1. Open the port, then use a private SerialStream method to set fAbortOnError to TRUE and then close the port
/// 2. Reopen the port
/// 3. Verify that the fAbortOnError flag is clear
///
/// </summary>
[ConditionalFact(nameof(HasOneSerialPort))]
public void AbortOnErrorShouldBeClearedOnOpen()
{
// Open the port, set the fAbortOnError flag and then close the port
SetAbortOnError(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
{
com.Open();
Assert.False(ReadAbortOnErrorFlag(com), "fAbortOnError should be clear when port is opened");
}
}
private static bool ReadAbortOnErrorFlag(SerialPort com)
{
Stream baseStream = com.BaseStream;
int flagValue = (int)baseStream.GetType()
.GetMethod("GetDcbFlag", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(baseStream, new object[] {14});
return flagValue != 0;
}
private void SetAbortOnError(string port)
{
using (SerialPort com = new SerialPort(port))
{
com.Open();
Stream baseStream = com.BaseStream;
// Invoke the private method SetDcbFlag to set bit 14 in the DCB flags
// This just updates the _dcb.Flags member of SerialStream
baseStream.GetType().GetMethod("SetDcbFlag", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(baseStream, new object[] { 14, 1 });
// Force the DCB to get written to the driver
com.DataBits = 7;
com.DataBits = 8;
}
}
}
}

View File

@@ -139,7 +139,7 @@ namespace System.IO.Ports.Tests
public const int ERROR_INSUFFICIENT_BUFFER = 122;
public const int ERROR_MORE_DATA = 234;
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "QueryDosDeviceW", CharSet = CharSet.Unicode)]
private static extern int QueryDosDevice(string lpDeviceName, char[] lpTargetPath, int ucchMax);
}
}

View File

@@ -82,7 +82,6 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow Test")]
[ConditionalFact(nameof(HasNullModem))]
public void ErrorReceived_Close_Stress()
{

View File

@@ -21,7 +21,6 @@ namespace System.IO.Ports.Tests
#region Test Cases
[OuterLoop("Slow Test")]
[ConditionalFact(nameof(HasNullModem))]
public void EventHandlers_CalledSerially()
{
@@ -219,7 +218,6 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow Test")]
[ConditionalFact(nameof(HasNullModem))]
public void Thread_In_PinChangedEvent()
{
@@ -256,7 +254,6 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow Test")]
[ConditionalFact(nameof(HasNullModem))]
public void Thread_In_ReceivedEvent()
{
@@ -296,7 +293,6 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow Test")]
[ConditionalFact(nameof(HasNullModem))]
public void Thread_In_ErrorEvent()
{

View File

@@ -14,6 +14,7 @@ namespace System.IO.Ports.Tests
#region Test Cases
[Fact]
[ActiveIssue("https://github.com/dotnet/corefx/issues/20588 - GetPortNames() has registry dependency.", TargetFrameworkMonikers.UapAot)]
private void OpenEveryPortName()
{
string[] portNames = SerialPort.GetPortNames();

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Threading;
using Legacy.Support;
using Xunit;
using Xunit.NetCore.Extensions;
namespace System.IO.Ports.Tests
{
@@ -68,7 +69,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void Timeout()
{
@@ -85,7 +86,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void SuccessiveReadTimeoutNoData()
{

View File

@@ -9,6 +9,7 @@ using System.Text;
using System.Threading;
using Legacy.Support;
using Xunit;
using Xunit.NetCore.Extensions;
namespace System.IO.Ports.Tests
{
@@ -70,7 +71,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void Timeout()
{
@@ -86,7 +87,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void SuccessiveReadTimeoutNoData()
{

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Threading;
using Legacy.Support;
using Xunit;
using Xunit.NetCore.Extensions;
namespace System.IO.Ports.Tests
{
@@ -79,7 +80,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void Timeout()
{
@@ -95,7 +96,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void SuccessiveReadTimeoutNoData()
{

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Threading;
using Legacy.Support;
using Xunit;
using Xunit.NetCore.Extensions;
namespace System.IO.Ports.Tests
{
@@ -77,7 +78,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void Timeout()
{
@@ -94,7 +95,7 @@ namespace System.IO.Ports.Tests
}
}
[OuterLoop("Slow test")]
[Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Timing-sensitive
[ConditionalFact(nameof(HasOneSerialPort))]
public void SuccessiveReadTimeoutNoData()
{

Some files were not shown because too many files have changed in this diff Show More