Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -44,5 +44,128 @@ namespace MonoTests.Helpers {
throw new ApplicationException ($"Could not find available local port after {counter} retries");
}
// Bind to the specified address using a system-assigned port.
// Returns the assigned port.
public static void Bind (this Socket socket, IPAddress address, out int port)
{
socket.Bind (new IPEndPoint (address, 0));
port = ((IPEndPoint) socket.LocalEndPoint).Port;
}
// Bind to the specified address using a system-assigned port.
// Returns the resulting end local end point.
public static void Bind (this Socket socket, IPAddress address, out IPEndPoint ep)
{
socket.Bind (new IPEndPoint (address, 0));
ep = (IPEndPoint) socket.LocalEndPoint;
}
// Creates and starts a TcpListener using a system-assigned port.
// Returns the assigned port.
public static TcpListener CreateAndStartTcpListener (out int port)
{
var rv = new TcpListener (0);
rv.Start ();
port = ((IPEndPoint) rv.LocalEndpoint).Port;
return rv;
}
// Creates and starts a TcpListener using a system-assigned port.
// Returns the resulting local end point.
public static TcpListener CreateAndStartTcpListener (out IPEndPoint ep)
{
var rv = new TcpListener (0);
rv.Start ();
ep = (IPEndPoint) rv.LocalEndpoint;
return rv;
}
// Creates and starts a TcpListener using the specified address and a system-assigned port.
// Returns the assigned port.
public static TcpListener CreateAndStartTcpListener (IPAddress address, out int port)
{
var rv = new TcpListener (address, 0);
rv.Start ();
port = ((IPEndPoint) rv.LocalEndpoint).Port;
return rv;
}
// Creates and starts a TcpListener using the specified address and a system-assigned port.
// Returns the resulting local end point.
public static TcpListener CreateAndStartTcpListener (IPAddress address, out IPEndPoint ep)
{
var rv = new TcpListener (address, 0);
rv.Start ();
ep = (IPEndPoint) rv.LocalEndpoint;
return rv;
}
// Creates and starts an HttpListener using the specified host, port,
// path and authSchemes.
//
// If specified, the initializer will be called immediately after the
// HttpListener is created (typical usage would be to set/change
// properties before starting the listener)
public static HttpListener CreateAndStartHttpListener (string host, int port, string path, AuthenticationSchemes? authSchemes = null, Action<HttpListener> initializer = null)
{
var prefix = host + port + path;
HttpListener listener = new HttpListener ();
if (initializer != null)
initializer (listener);
if (authSchemes.HasValue)
listener.AuthenticationSchemes = authSchemes.Value;
listener.Prefixes.Add (prefix);
listener.Start ();
return listener;
}
// Creates and starts an HttpListener using the specified host, path
// and authSchemes. The method will try to find an unused port, and
// use that (multiple attempts with random port numbers will be made).
//
// If specified, the initializer will be called immediately after the
// HttpListener is created (typical usage would be to set/change
// properties before starting the listener). Be aware that the
// initializer can be called multiple times (in case multiple creation
// attempts have to be made).
public static HttpListener CreateAndStartHttpListener (string host, out int port, string path, AuthenticationSchemes? authSchemes = null, Action<HttpListener> initializer = null)
{
// There's no way to create an HttpListener with a system-assigned port.
// So we use NetworkHelpers.FindFreePort, and re-try if we fail because someone else has already used the port.
for (int i = 0; i < 10; i++) {
try {
var tentativePort = NetworkHelpers.FindFreePort ();
var listener = CreateAndStartHttpListener (host, tentativePort, path, authSchemes, initializer);
port = tentativePort;
return listener;
} catch (SocketException se) {
if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
continue;
throw;
}
}
throw new Exception ("Unable to create HttpListener after 10 attempts");
}
// Creates and starts an HttpListener using the specified host, path
// and authSchemes. The method will try to find an unused port, and
// use that (multiple attempts with random port numbers will be made).
//
// If specified, the initializer will be called immediately after the
// HttpListener is created (typical usage would be to set/change
// properties before starting the listener). Be aware that the
// initializer can be called multiple times (in case multiple creation
// attempts have to be made).
//
// The resulting uri will also be returned (this is just host + port + path).
public static HttpListener CreateAndStartHttpListener (string host, out int port, string path, out string uri, AuthenticationSchemes? authSchemes = null, Action<HttpListener> initializer = null)
{
var rv = CreateAndStartHttpListener (host, out port, path, authSchemes, initializer);
uri = host + port + path;
return rv;
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace MonoTests.Helpers {
/// <summary>
/// Represents a temporary directory. Creating an instance creates a directory at the specified path,
/// and disposing the instance deletes the directory.
/// </summary>
public sealed class TempDirectory : IDisposable
{
/// <summary>Gets the created directory's path.</summary>
public string Path { get; private set; }
public TempDirectory ()
: this (CreateTemporaryDirectory ())
{
}
public TempDirectory (string path)
{
Path = path;
}
~TempDirectory ()
{
Dispose ();
}
public void Dispose()
{
GC.SuppressFinalize (this);
DeleteDirectory (Path);
}
// Tries to recursively delete the specified path.
// Doesn't throw exceptions if path is null, empty, or doesn't exist.
public static void DeleteDirectory (string path)
{
if (string.IsNullOrEmpty (path))
return;
if (Directory.Exists (path))
Directory.Delete (path, true);
}
// Creates a unique temporary directory.
//
// The calling method's type/method name will be a part of the
// returned path to make it somewhat nicer/more useful.
//
// This method is only meant for testing code, not production code (it
// will leave some temporary directories behind).
static string CreateTemporaryDirectory ()
{
var name = string.Empty;
var calling_method = new StackFrame (2).GetMethod ();
if (calling_method != null)
name = calling_method.DeclaringType.FullName + "_" + calling_method.Name + "_";
var rv = global::System.IO.Path.Combine (global::System.IO.Path.GetTempPath (), name + Guid.NewGuid ().ToString ());
Directory.CreateDirectory (rv);
return rv;
}
}
}

View File

@@ -6,10 +6,13 @@ namespace System
public static readonly bool IsNotWinRT = true;
public static readonly bool IsWinRT = false;
public static readonly bool IsWindowsNanoServer = false;
public static readonly bool IsNotWindowsNanoServer = true;
public static readonly bool IsNotWindowsServerCore = true;
public static bool IsNotWindowsNanoServer => true;
public static bool IsNotWindowsServerCore => true;
public static bool IsWindows7 => false;
public static bool IsWindows10Version1607OrGreater => false;
public static bool IsWindows10Version1703OrGreater => false;
public static bool IsWindows10Version1709OrGreater => false;
public static bool IsFullFramework => false;
public static bool IsNonZeroLowerBoundArraySupported => true;
public static bool IsUap => false;
@@ -19,12 +22,19 @@ namespace System
public static bool IsWindowsSubsystemForLinux => false;
public static bool IsFedora => false;
public static bool IsRedHatFamily => false;
public static bool IsRedHatFamily6 => false;
public static bool IsOpenSUSE => false;
public static bool IsUbuntu1404 => false;
public static bool IsNotRedHatFamily6 => true;
public static bool IsMacOsHighSierraOrHigher => false;
public static bool IsDebian8 => false;
public static bool IsInvokingStaticConstructorsSupported => true;
public static bool IsReflectionEmitSupported => true;
public static bool IsNetfx462OrNewer => false;
public static bool IsSsl2AndSsl3Supported => false;
public static bool IsWindows {
get {
PlatformID id = Environment.OSVersion.Platform;
@@ -32,5 +42,7 @@ namespace System
}
}
public static bool IsInAppContainer => false;
public static bool IsAlpine => false;
public static bool IsNetCore => false;
}
}
}

View File

@@ -13,7 +13,7 @@ namespace System.Diagnostics
// protected static readonly string HostRunnerName = "mono";
protected static readonly string HostRunner = Process.GetCurrentProcess().MainModule.FileName;
// Should be ../lib/$(PROFILE)/RemoteExecutorConsoleApp.exe
// Should be ../lib/$(PROFILE)/tests/RemoteExecutorConsoleApp.exe
static readonly string ExtraParameter = "--debug " + Environment.GetEnvironmentVariable ("REMOTE_EXECUTOR");
}
}

View File

@@ -67,6 +67,14 @@ namespace MonoTests.Helpers
listenTask = Task.Run ((Action) Listen);
}
// Starts listening on IPAddress.Loopback on a system-assigned port.
// Returns the resulting IPEndPoint (which contains the assigned port).
public SocketResponder (out IPEndPoint ep, SocketRequestHandler rh)
: this (new IPEndPoint (IPAddress.Loopback, 0), rh)
{
ep = (IPEndPoint) tcpListener.LocalEndpoint;
}
public void Dispose ()
{
if (disposed)