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

@@ -14,6 +14,8 @@ using System;
using System.IO;
using System.Globalization;
using System.Threading;
using System.Runtime.InteropServices;
using NUnit.Framework;
@@ -2680,5 +2682,53 @@ namespace MonoTests.System.IO
MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
}
[DllImport ("libc", SetLastError=true)]
public static extern int symlink (string oldpath, string newpath);
[Test]
public void SymLinkLoop ()
{
if (!RunningOnUnix)
Assert.Ignore ("Symlink are hard on windows");
var name1 = Path.GetRandomFileName ();
var name2 = Path.GetRandomFileName ();
var path1 = Path.Combine (Path.GetTempPath (), name1);
var path2 = Path.Combine (Path.GetTempPath (), name2);
File.Delete (path1);
File.Delete (path2);
try {
symlink (path1, path2);
symlink (path2, path1);
Assert.IsTrue (File.Exists (path1), "File.Exists must return true for path1 symlink loop");
Assert.IsTrue (File.Exists (path2), "File.Exists must return true for path2 symlink loop");
try {
using (var f = File.Open (path1, FileMode.Open, FileAccess.Read)) {
Assert.Fail ("File.Open must throw for symlink loops");
}
} catch (IOException ex) {
Assert.AreEqual (0x80070781u, (uint)ex.HResult, "Ensure HRESULT is correct");
}
File.Delete (path1); //Delete must not throw and must work
Assert.IsFalse (File.Exists (path1), "File.Delete must delete symlink loops");
} finally {
try {
File.Delete (path1);
File.Delete (path2);
} catch (IOException) {
//Don't double fault any exception from the tests.
}
}
}
}
}

View File

@@ -1844,5 +1844,68 @@ public class AssemblyBuilderTest
} catch (NotSupportedException e) {
}
}
class AssemblyBuilderResolver {
private Assembly mock;
private ResolveEventHandler d;
private string theName;
public AssemblyBuilderResolver (string theName) {
mock = CreateMock (theName);
d = new ResolveEventHandler (HandleResolveEvent);
this.theName = theName;
}
public void StartHandling () {
AppDomain.CurrentDomain.AssemblyResolve += d;
}
public void StopHandling () {
AppDomain.CurrentDomain.AssemblyResolve -= d;
}
public Assembly HandleResolveEvent (Object sender, ResolveEventArgs args) {
if (args.Name.StartsWith (theName))
return mock;
else
return null;
}
private static Assembly CreateMock (string name) {
var an = new AssemblyName (name);
var ab = AssemblyBuilder.DefineDynamicAssembly (an, AssemblyBuilderAccess.ReflectionOnly);
var mb = ab.DefineDynamicModule (an.Name);
// Just make some content for the assembly
var tb = mb.DefineType ("Foo", TypeAttributes.Public);
tb.DefineDefaultConstructor (MethodAttributes.Public);
tb.CreateType ();
return ab;
}
}
[Test]
public void ResolveEventHandlerReflectionOnlyError ()
{
// Regression test for 57850.
// If a ResolveEventHandler returns a reflection-only
// AssemblyBuilder, we should throw a FileNotFoundException.
var s = "ResolveEventHandlerReflectionOnlyErrorAssembly";
var h = new AssemblyBuilderResolver (s);
Assert.Throws<FileNotFoundException>(() => {
h.StartHandling ();
var aName = new AssemblyName (s);
try {
AppDomain.CurrentDomain.Load (aName);
} finally {
h.StopHandling ();
}
});
}
}
}

View File

@@ -303,6 +303,86 @@ namespace MonoTests.System.Reflection.Emit
Assert.AreEqual (FieldAttributes.RTSpecialName, value.Attributes & FieldAttributes.RTSpecialName);
}
[Test]
public void TestCreateTypeIncompleteEnumStaticField ()
{
ModuleBuilder modBuilder = GenerateModule ();
EnumBuilder enumBuilder = GenerateEnum (modBuilder);
GenerateField (enumBuilder);
var tb = modBuilder.DefineType ("T", TypeAttributes.Public);
tb.DefineDefaultConstructor (MethodAttributes.Public);
tb.DefineField ("e", enumBuilder, FieldAttributes.Static | FieldAttributes.Public);
var t = tb.CreateType ();
Assert.IsNotNull (t);
bool caught = false;
try {
object x = Activator.CreateInstance (t);
} catch (TypeLoadException exn) {
Assert.AreEqual (t.Name, exn.TypeName);
caught = true;
}
if (!caught)
Assert.Fail ("Expected CreateInstance of a broken type to throw TLE");
}
[Test]
public void TestEnumBuilderTokenUsable () {
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58361
// Create an EnumBuilder and use it in an ILGenerator that consumes its token.
var modBuilder = GenerateModule ();
EnumBuilder enumBuilder = GenerateEnum (modBuilder);
var tb = modBuilder.DefineType ("Foo", TypeAttributes.Public);
var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
Type.EmptyTypes);
var ilg = cb.GetILGenerator ();
ilg.Emit (OpCodes.Ldtoken, enumBuilder);
ilg.Emit (OpCodes.Pop);
ilg.Emit (OpCodes.Ret);
var t = tb.CreateType ();
enumBuilder.CreateType ();
var ci = t.GetConstructor (Type.EmptyTypes);
var x = ci.Invoke (null);
Assert.IsNotNull (x);
}
[Test]
public void TestEnumBuilderTokenUsableCrossAssembly () {
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58361
// Create an EnumBuilder and use it in an ILGenerator that consumes its token in a different assembly.
var modBuilder = GenerateModule ();
var modBuilder2 = GenerateModule ();
EnumBuilder enumBuilder = GenerateEnum (modBuilder2);
// N.B. "tb" is in modBuilder but enumBuilder is in modBuilder2
var tb = modBuilder.DefineType ("Foo", TypeAttributes.Public);
var cb = tb.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard,
Type.EmptyTypes);
var ilg = cb.GetILGenerator ();
ilg.Emit (OpCodes.Ldtoken, enumBuilder);
ilg.Emit (OpCodes.Pop);
ilg.Emit (OpCodes.Ret);
var t = tb.CreateType ();
enumBuilder.CreateType ();
var ci = t.GetConstructor (Type.EmptyTypes);
var x = ci.Invoke (null);
Assert.IsNotNull (x);
}
private static void VerifyType (Type type)
{
Assert.IsNotNull (type.Assembly, "#V1");

View File

@@ -353,5 +353,60 @@ namespace MonoTests.System.Reflection.Emit
Assert.AreEqual (TypeAttributes.Public, gparam.Attributes, "#1");
}
[Test]
public void ActionConstructorInfoTest ()
{
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=58454
//
// Need to check that GenericTypeParameterBuilderTest:InternalResolve() passes the declaring type to GetMethodFromHandle()
//
/* Want to generate:
public class Store<TState> {
public Action<TSelection> Subscribe<TSelection> (TState state) {
return new Action<TSelection> (Foo<TSelection>);
}
public static void Foo<X> (X x) { }
}
... and then: new Store<string>().Subscribe<int>("x");
*/
SetUp (AssemblyBuilderAccess.Run);
var tb = module.DefineType ("Store");
var tparsStore = tb.DefineGenericParameters ("TState");
tb.DefineDefaultConstructor (MethodAttributes.Public);
var methFoo = tb.DefineMethod ("Foo", MethodAttributes.Public | MethodAttributes.Static);
var tparsFoo = methFoo.DefineGenericParameters ("X");
methFoo.SetReturnType (typeof(void));
methFoo.SetParameters (tparsFoo[0]);
methFoo.GetILGenerator().Emit (OpCodes.Ret);
var methSub = tb.DefineMethod ("Subscribe", MethodAttributes.Public | MethodAttributes.Static);
var tparsSub = methSub.DefineGenericParameters ("TSelection");
var actOfSel = typeof(Action<>).MakeGenericType (tparsSub[0]); // Action<TSelection>
methSub.SetReturnType (actOfSel);
methSub.SetParameters (tparsStore[0]); // TState
var ilg = methSub.GetILGenerator ();
ilg.Emit (OpCodes.Ldnull); // instance == null
ilg.Emit (OpCodes.Ldftn, methFoo.MakeGenericMethod (tparsSub[0])); // ldftn void class Store`1<!TState>::Foo<!!0> (!!0)
var aaa = TypeBuilder.GetConstructor (actOfSel, typeof(Action<>).GetConstructors()[0]);
ilg.Emit (OpCodes.Newobj, aaa); // new Action<TSelection> (Foo<TSelection>);
ilg.Emit (OpCodes.Ret);
var tgen = tb.CreateType (); // TState`1
var t = tgen.MakeGenericType(typeof(string));
var x = t.GetConstructor(Type.EmptyTypes).Invoke (null); // x = new Store<string> ()
var mgen = t.GetMethod("Subscribe");
var m = mgen.MakeGenericMethod (typeof (int)); // Action<int> Store<string>.Subscribe<int> (string)
var y = m.Invoke (x, new object[] {"hello"}); // x.Subscribte<int> ("hello")
Assert.IsNotNull (y);
}
}
}

View File

@@ -1 +1 @@
e011b6a087581526200eda571e3418538ec57da9
cf74124675f61fe27a093af6f9970fd092ba413d

View File

@@ -0,0 +1,76 @@
//
// MonoTests.System.Runtime.Remoting.Proxies.RealProxyTest.cs
//
//
using System;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Remoting.Proxies {
[TestFixture]
public class RealProxyTest {
public class ExampleInterfaceProxy : RealProxy {
public bool Called;
public ExampleInterfaceProxy () : base (typeof(IComparable))
{
Called = false;
}
public override IMessage Invoke (IMessage msg)
{
Called = true;
return new ReturnMessage (typeof(IComparable), null, 0, null, null);
}
}
[Test]
public void InterfaceProxyGetTypeOkay ()
{
// Regression test for #17325
// Check that GetType () for a proxy of an interface
// returns the interface.
var prox = new ExampleInterfaceProxy ();
var tprox = prox.GetTransparentProxy ();
Assert.IsNotNull (tprox, "#1");
var tproxType = tprox.GetType ();
Assert.IsFalse (prox.Called, "#2"); // this is true on .NET Framework, but false on Mono.
Assert.IsNotNull (tproxType, "#3");
Assert.IsTrue (tproxType.IsAssignableFrom (typeof(IComparable)), "#4");
}
[Test]
public void InterfaceProxyGetTypeViaReflectionOkay ()
{
// Regression test for #17325
// Check that GetType () for a proxy of an interface
// returns the interface.
//
// This versions calls GetType using reflection, which
// avoids the fast path in the JIT.
var prox = new ExampleInterfaceProxy ();
var tprox = prox.GetTransparentProxy ();
Assert.IsNotNull (tprox, "#1");
var m = typeof(object).GetMethod ("GetType");
var tproxType = m.Invoke (tprox, null);
Assert.IsTrue (prox.Called, "#2");
Assert.IsNotNull (tproxType, "#3");
Assert.IsTrue (tproxType is Type, "#4");
Assert.IsTrue ((tproxType as Type).IsAssignableFrom (typeof(IComparable)), "#5");
}
}
}

View File

@@ -341,7 +341,7 @@ namespace MonoTests.System.Runtime.Remoting
Thread tr = new Thread (new ThreadStart (CallbackThread));
tr.Start();
bool terminated = tr.Join(2000);
bool terminated = tr.Join(10000);
Assert.IsTrue(terminated, "Thread didn't get lock of context bound object.");
Assert.IsTrue (!otResult, "Concurrency detected in CallbackThread");

View File

@@ -68,8 +68,6 @@ namespace MonoTests.System.Security.Cryptography.X509Certificates {
public void TearDown ()
{
Thread.CurrentThread.CurrentCulture = oldcult;
File.Delete("temp.cer");
File.Delete("temp.b64");
}
#if !MOBILE && !MONOMAC

View File

@@ -1 +1 @@
ee5c13285bf8fdb2210b00103954378a01435b59
3e6958d083b6c9235b39497ec57d2a30e40b73e8

View File

@@ -847,7 +847,7 @@ namespace MonoTests.System.Threading.Tasks
int r1 = 0, r2 = 0;
ThreadPool.QueueUserWorkItem (delegate {
cntd.Signal ();
if (!t.Wait (1000))
if (!t.Wait (2000))
r1 = 20; // 20 -> task wait failed
else if (t.Result != 1)
r1 = 30 + t.Result; // 30 -> task result is bad
@@ -861,7 +861,7 @@ namespace MonoTests.System.Threading.Tasks
});
ThreadPool.QueueUserWorkItem (delegate {
cntd.Signal ();
if (!t.Wait (1000))
if (!t.Wait (2000))
r2 = 40; // 40 -> task wait failed
else if (t.Result != 1)
r2 = 50 + t.Result; // 50 -> task result is bad
@@ -874,9 +874,9 @@ namespace MonoTests.System.Threading.Tasks
Monitor.Pulse (monitor);
}
});
Assert.IsTrue (cntd.Wait (2000), "#1");
Assert.IsTrue (cntd.Wait (4000), "#1");
evt.Set ();
Assert.IsTrue (cntd2.Wait (2000), "#2");
Assert.IsTrue (cntd2.Wait (4000), "#2");
Assert.AreEqual (2, r1, "r1");
Assert.AreEqual (3, r2, "r2");

View File

@@ -3687,5 +3687,17 @@ public class ArrayTest
Assert.AreEqual (10, ((object[])arr [i]).Length);
}
}
[Test]
public unsafe void PointerArraysBoxing ()
{
var x = new int*[10];
var e = x.GetEnumerator ();
e.MoveNext ();
Assert.Throws<NotSupportedException> (() => { var _ = e.Current; }, "#1");
Assert.Throws<NotSupportedException> (() => { var _ = x.GetValue (0); }, "#2");
Assert.Throws<NotSupportedException> (() => { x.SetValue (0, 0); }, "#3");
}
}
}

View File

@@ -14,6 +14,8 @@ using System.Runtime.CompilerServices;
using System.Threading;
using System.Collections.Generic;
#pragma warning disable CS1718
namespace MonoTests.System
{
[TestFixture]

View File

@@ -1 +1 @@
9cc8ca79a413f707d27ad210899583c3fdb03456
d03e4c21f2af694ee1ea2bf45fa97fad43341c19