Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@ -90,7 +90,9 @@ namespace System.Net.NetworkInformation
pingEventSafeWaitHandle,
IntPtr.Zero,
IntPtr.Zero,
(uint)address.GetAddress(),
#pragma warning disable CS0618 // Address is marked obsolete
(uint)address.Address,
#pragma warning restore CS0618
_requestBuffer,
(ushort)buffer.Length,
ref ipOptions,

View File

@ -2,7 +2,9 @@
// 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.Net.Sockets;
using System.Net.Test.Common;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@ -32,6 +34,19 @@ namespace System.Net.NetworkInformation.Tests
}
}
private static void PingResultValidator(PingReply pingReply, IPAddress localIpAddress)
{
if (pingReply.Status == IPStatus.TimedOut)
{
// Workaround OSX ping6 bug, refer issue #15018
Assert.Equal(AddressFamily.InterNetworkV6, localIpAddress.AddressFamily);
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
return;
}
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
}
[Fact]
public async Task SendPingAsync_InvalidArgs()
@ -90,8 +105,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
});
}
@ -105,8 +119,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress.ToString()),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
});
}
@ -120,8 +133,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
});
}
@ -137,9 +149,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout, buffer),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
Assert.Equal(buffer, pingReply.Buffer);
});
}
@ -155,8 +165,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout, buffer),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
// Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
if (Capability.CanUseRawSockets(localIpAddress.AddressFamily))
@ -183,8 +192,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout, buffer, options),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
Assert.Equal(buffer, pingReply.Buffer);
Assert.InRange(pingReply.RoundtripTime, 0, long.MaxValue);
});
@ -201,8 +209,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout, buffer, new PingOptions()),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
// Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
if (Capability.CanUseRawSockets(localIpAddress.AddressFamily))
@ -226,8 +233,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
});
}
@ -241,8 +247,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
});
}
@ -258,9 +263,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
Assert.Equal(buffer, pingReply.Buffer);
});
}
@ -276,8 +279,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
// Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
if (Capability.CanUseRawSockets(localIpAddress.AddressFamily))
@ -303,8 +305,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer, new PingOptions()),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
Assert.Equal(buffer, pingReply.Buffer);
});
@ -321,8 +322,7 @@ namespace System.Net.NetworkInformation.Tests
(ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer, new PingOptions()),
(pingReply) =>
{
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
// Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
if (Capability.CanUseRawSockets(localIpAddress.AddressFamily))
@ -347,8 +347,7 @@ namespace System.Net.NetworkInformation.Tests
for (int i = 0; i < 3; i++)
{
PingReply pingReply = await p.SendPingAsync(TestSettings.LocalHost);
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
}
}
}
@ -364,8 +363,7 @@ namespace System.Net.NetworkInformation.Tests
for (int i = 0; i < 3; i++)
{
PingReply pingReply = p.Send(TestSettings.LocalHost);
Assert.Equal(IPStatus.Success, pingReply.Status);
Assert.True(pingReply.Address.Equals(localIpAddress));
PingResultValidator(pingReply, localIpAddress);
}
}
}
@ -399,8 +397,7 @@ namespace System.Net.NetworkInformation.Tests
await tcs.Task;
Assert.NotNull(ea);
Assert.Equal(IPStatus.Success, ea.Reply.Status);
Assert.True(ea.Reply.Address.Equals(localIpAddress));
PingResultValidator(ea.Reply, localIpAddress);
}
// Several canceled iterations

View File

@ -26,9 +26,6 @@
<Compile Include="$(CommonTestPath)\System\Net\Capability.RawSocketPermissions.cs">
<Link>Common\System\Net\Capability.RawSocketPermissions.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\tests\System\PlatformDetection.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Xunit;
@ -22,7 +23,7 @@ namespace System.Net.NetworkInformation.Tests
[InlineData(1)]
[InlineData(50)]
[InlineData(1000)]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests un-priviledged Ping support on Unix
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests un-priviledged Ping support on Unix
public static async Task PacketSizeIsRespected(int payloadSize)
{
IPAddress localAddress = await TestSettings.GetLocalIPAddress();
@ -39,6 +40,13 @@ namespace System.Net.NetworkInformation.Tests
string pingOutput = p.StandardOutput.ReadToEnd();
Assert.True(p.WaitForExit(TestSettings.PingTimeout), "Ping process did not exit in " + TestSettings.PingTimeout + " ms.");
if (p.ExitCode == 1 || p.ExitCode == 2)
{
// Workaround known OSX bug in ping6 utility.
Assert.Equal(utilityPath, UnixCommandLinePing.Ping6UtilityPath);
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
return;
}
try
{