Skip to content

Commit

Permalink
Merge branch 'main' into darc-main-eafa88b6-7170-475b-9dce-8205fe62b0c3
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Jul 14, 2022
2 parents 5ec7ad4 + e468e75 commit e904e71
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 322 deletions.
6 changes: 5 additions & 1 deletion mk/xamarin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MONO_BRANCH := $(shell cd $(MONO_PATH) 2> /dev/null && git symbolic-ref --sho
endif

ifdef ENABLE_XAMARIN
NEEDED_MACCORE_VERSION := 713bcb2442ac70e1741f4dccd2afa5cfed546fdb
NEEDED_MACCORE_VERSION := 813beaf11a3f5b3320c4ad8d4732542bd8b1bd09
NEEDED_MACCORE_BRANCH := main

MACCORE_DIRECTORY := maccore
Expand All @@ -16,6 +16,10 @@ MACCORE_VERSION := $(shell cd $(MACCORE_PATH) 2> /dev/null && git rev-parse HE
MACCORE_BRANCH := $(shell cd $(MACCORE_PATH) 2> /dev/null && git symbolic-ref --short HEAD 2> /dev/null)
endif

# Available versions can be seen here:
# https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/Microsoft.Tools.Mlaunch/versions
MLAUNCH_NUGET_VERSION=1.0.1

define CheckVersionTemplate
check-$(1)::
@rm -f $(THISDIR)/.stamp-reset-$(1)
Expand Down
102 changes: 0 additions & 102 deletions runtime/monotouch-debug.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
void monotouch_connect_usb ();
void monotouch_connect_wifi (NSMutableArray *hosts);
void xamarin_connect_http (NSMutableArray *hosts);
int monotouch_debug_listen (int debug_port, int output_port);
int monotouch_debug_connect (NSMutableArray *hosts, int debug_port, int output_port);
void monotouch_configure_debugging ();
void monotouch_load_profiler ();
Expand Down Expand Up @@ -1414,107 +1413,6 @@ static ssize_t sdb_recv (void *buf, size_t len)
}
}

int monotouch_debug_listen (int debug_port, int output_port)
{
struct sockaddr_in listen_addr;
int listen_socket;
int output_socket;
socklen_t len;
int rv;
long flags;
int flag;
fd_set rset;
struct timeval tv;

// Create the listen socket and set it up
listen_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listen_socket == -1) {
PRINT (PRODUCT ": Could not create socket for the IDE to connect to: %s", strerror (errno));
return 1;
} else {
flag = 1;
if (setsockopt (listen_socket, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (flag)) == -1) {
PRINT (PRODUCT ": Could not set SO_REUSEADDR on the listening socket (%s)", strerror (errno));
// not a fatal failure
}

memset (&listen_addr, 0, sizeof (listen_addr));
listen_addr.sin_family = AF_INET;
listen_addr.sin_port = htons (output_port);
listen_addr.sin_addr.s_addr = INADDR_ANY;
rv = bind (listen_socket, (struct sockaddr *) &listen_addr, sizeof (listen_addr));
if (rv == -1) {
PRINT (PRODUCT ": Could not bind to address: %s", strerror (errno));
close (listen_socket);
return 2;
} else {
// Make the socket non-blocking
flags = fcntl (listen_socket, F_GETFL, NULL);
flags |= O_NONBLOCK;
fcntl (listen_socket, F_SETFL, flags);

rv = listen (listen_socket, 1);
if (rv == -1) {
PRINT (PRODUCT ": Could not listen for the IDE: %s", strerror (errno));
close (listen_socket);
return 2;
} else {
// Yay!
}
}
}

tv.tv_sec = 2;
tv.tv_usec = 0;

FD_ZERO (&rset);
FD_SET (listen_socket, &rset);

do {
if ((rv = select (listen_socket + 1, &rset, NULL, NULL, &tv)) == 0) {
// timeout hit, no connections available.
PRINT (PRODUCT ": Listened for connections from the IDE for 2 seconds, nobody connected.");
close (listen_socket);
return 3;
}
} while (rv == -1 && errno == EINTR);

if (rv == -1) {
PRINT (PRODUCT ": Failed while waiting for the IDE to connect: %s", strerror (errno));
close (listen_socket);
return 2;
}

len = sizeof (struct sockaddr_in);
output_socket = accept (listen_socket, (struct sockaddr *) &listen_addr, &len);
if (output_socket == -1) {
PRINT (PRODUCT ": Failed to accept connection from the IDE: %s", strerror (errno));
close (listen_socket);
return 3;
}

flag = 1;
if (setsockopt (output_socket, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof (flag)) < 0) {
PRINT (PRODUCT ": Could not set TCP_NODELAY on socket (%s)", strerror (errno));
// not a fatal failure
}

LOG (PRODUCT ": Successfully received USB connection from the IDE on port %i.\n", output_port);

// make the socket block on reads/writes
flags = fcntl (output_socket, F_GETFL, NULL);
fcntl (output_socket, F_SETFL, flags & ~O_NONBLOCK);

dup2 (output_socket, 1);
dup2 (output_socket, 2);

close (listen_socket); // no need to listen anymore

debug_host = strdup ("127.0.0.1");

return 0;
}

// SUCCESS = 0
// FAILURE > 0
int monotouch_debug_connect (NSMutableArray *ips, int debug_port, int output_port)
Expand Down
31 changes: 16 additions & 15 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
enum InitializationFlags : int {
InitializationFlagsIsPartialStaticRegistrar = 0x01,
/* unused = 0x02,*/
InitializationFlagsDynamicRegistrar = 0x04,
/* unused = 0x04,*/
/* unused = 0x08,*/
InitializationFlagsIsSimulator = 0x10,
InitializationFlagsIsCoreCLR = 0x20,
Expand Down Expand Up @@ -2240,32 +2240,33 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
break;
case MarshalObjectiveCExceptionModeThrowManagedException:
exc_handle = [[ns_exception userInfo] objectForKey: @"XamarinManagedExceptionHandle"];
GCHandle handle;
if (exc_handle != NULL) {
GCHandle handle = [exc_handle getHandle];
GCHandle e_handle = [exc_handle getHandle];
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = xamarin_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
MonoObject *exc = xamarin_gchandle_get_target (e_handle);
handle = xamarin_gchandle_new (exc, false);
xamarin_mono_object_release (&exc);
MONO_EXIT_GC_UNSAFE;
} else {
GCHandle handle = xamarin_create_ns_exception (ns_exception, &exception_gchandle);
handle = xamarin_create_ns_exception (ns_exception, &exception_gchandle);
if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while creating a managed NSException wrapper (will throw this exception instead):");
PRINT ("%@", xamarin_print_all_exceptions (exception_gchandle));
handle = exception_gchandle;
exception_gchandle = INVALID_GCHANDLE;
}
}

if (output_exception == NULL) {
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = xamarin_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
xamarin_mono_object_release (&exc);
xamarin_gchandle_free (handle);
MONO_EXIT_GC_UNSAFE;
} else {
*output_exception = handle;
}
if (output_exception == NULL) {
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = xamarin_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
xamarin_mono_object_release (&exc);
xamarin_gchandle_free (handle);
MONO_EXIT_GC_UNSAFE;
} else {
*output_exception = handle;
}
break;
case MarshalObjectiveCExceptionModeAbort:
Expand Down
14 changes: 7 additions & 7 deletions src/ObjCRuntime/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ unsafe static IntPtr FindClass (Type type, out bool is_custom_type)
type = type.GetGenericTypeDefinition ();

// Look for the type in the type map.
var asm_name = type.Assembly.GetName ().Name;
var asm_name = type.Assembly.GetName ().Name!;
var mod_token = type.Module.MetadataToken;
var type_token = type.MetadataToken & ~0x02000000;
for (int i = 0; i < map->map_count; i++) {
Expand Down Expand Up @@ -284,15 +284,15 @@ unsafe static IntPtr FindClass (Type type, out bool is_custom_type)
return IntPtr.Zero;
}

unsafe static bool CompareTokenReference (string? asm_name, int mod_token, int type_token, uint token_reference)
unsafe static bool CompareTokenReference (string asm_name, int mod_token, int type_token, uint token_reference)
{
var map = Runtime.options->RegistrationMap;
IntPtr assembly_name;

if ((token_reference & 0x1) == 0x1) {
// full token reference
var idx = (int) (token_reference >> 1);
var entry = Runtime.options->RegistrationMap->full_token_references + (IntPtr.Size + 8) * idx;
var entry = map->full_token_references + (IntPtr.Size + 8) * idx;
// first compare what's most likely to fail (the type's metadata token)
var token = (uint) Marshal.ReadInt32 (entry + IntPtr.Size + 4);
type_token |= 0x02000000 /* TypeDef - the token type is explicit in the full token reference, but not present in the type_token argument, so we have to add it before comparing */;
Expand Down Expand Up @@ -369,7 +369,7 @@ static unsafe int FindMapIndex (Runtime.MTClassMap *array, int lo, int hi, IntPt
type = ResolveTypeTokenReference (type_reference);

#if LOG_TYPELOAD
Console.WriteLine ($"FindType (0x{@class:X} = {Marshal.PtrToStringAuto (class_getName (@class))}) => {type.FullName}; is custom: {is_custom_type} (token reference: 0x{type_reference:X}).");
Console.WriteLine ($"FindType (0x{@class:X} = {Marshal.PtrToStringAuto (class_getName (@class))}) => {type?.FullName}; is custom: {is_custom_type} (token reference: 0x{type_reference:X}).");
#endif

class_to_type [mapIndex] = type;
Expand Down Expand Up @@ -451,7 +451,7 @@ static unsafe int FindMapIndex (Runtime.MTClassMap *array, int lo, int hi, IntPt
case 0x06000000: // Method
var method = module.ResolveMethod ((int) token);
#if LOG_TYPELOAD
Console.WriteLine ($"ResolveToken (0x{token:X}) => Method: {method.DeclaringType.FullName}.{method.Name}");
Console.WriteLine ($"ResolveToken (0x{token:X}) => Method: {method?.DeclaringType?.FullName}.{method.Name}");
#endif
return method;
default:
Expand Down Expand Up @@ -495,7 +495,7 @@ internal unsafe static uint GetTokenReference (Type type, bool throw_exception =
if (type.IsGenericType)
type = type.GetGenericTypeDefinition ();

var asm_name = type.Module.Assembly.GetName ().Name;
var asm_name = type.Module.Assembly.GetName ().Name!;

// First check if there's a full token reference to this type
var token = GetFullTokenReference (asm_name, type.Module.MetadataToken, type.MetadataToken);
Expand Down Expand Up @@ -538,7 +538,7 @@ internal unsafe static uint GetTokenReference (Type type, bool throw_exception =
}

// Look for the specified metadata token in the table of full token references.
static unsafe uint GetFullTokenReference (string? assembly_name, int module_token, int metadata_token)
static unsafe uint GetFullTokenReference (string assembly_name, int module_token, int metadata_token)
{
var map = Runtime.options->RegistrationMap;
for (int i = 0; i < map->full_token_reference_count; i++) {
Expand Down
21 changes: 19 additions & 2 deletions src/ObjCRuntime/Dlfcn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public enum RTLD {
MainOnly = -5
}

[Flags]
public enum Mode : int {
None = 0x0,
Lazy = 0x1,
Now = 0x2,
Local = 0x4,
Global = 0x8,
NoLoad = 0x10,
NoDelete = 0x80,
First = 0x100,
}

#if MONOMAC
[DllImport (Constants.libcLibrary)]
internal static extern int dladdr (IntPtr addr, out Dl_info info);
Expand All @@ -97,13 +109,18 @@ internal struct Dl_info
public static extern int dlclose (IntPtr handle);

[DllImport (Constants.libSystemLibrary, EntryPoint="dlopen")]
internal static extern IntPtr _dlopen (string? path, int mode /* this is int32, not nint */);
internal static extern IntPtr _dlopen (string? path, Mode mode /* this is int32, not nint */);

public static IntPtr dlopen (string? path, int mode)
{
return dlopen (path, mode, showWarning: true);
}

public static IntPtr dlopen (string? path, Mode mode)
{
return _dlopen (path, mode);
}

static bool warningShown;
// the linker can eliminate the body of this method (and the above static variable) on release builds
static void WarnOnce ()
Expand All @@ -115,7 +132,7 @@ static void WarnOnce ()

internal static IntPtr dlopen (string? path, int mode, bool showWarning)
{
var x = _dlopen (path, mode);
var x = _dlopen (path, (Mode) mode);
if (x != IntPtr.Zero)
return x;

Expand Down
2 changes: 1 addition & 1 deletion src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ internal struct Trampolines {
internal enum InitializationFlags : int {
IsPartialStaticRegistrar= 0x01,
/* unused = 0x02,*/
DynamicRegistrar = 0x04,
/* unused = 0x04,*/
/* unused = 0x08,*/
IsSimulator = 0x10,
#if NET
Expand Down
7 changes: 6 additions & 1 deletion tests/api-shared/ObjCRuntime/Registrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class RegistrationTestClass : NSObject {}

public static Registrars CurrentRegistrar {
get {
var find_type = typeof (Class).GetMethod ("FindType", BindingFlags.Static | BindingFlags.NonPublic);
#if NET
var types = new Type [] { typeof (NativeHandle), typeof (bool).MakeByRefType () };
#else
var types = new Type [] { typeof (IntPtr), typeof (bool).MakeByRefType () };
#endif
var find_type = typeof (Class).GetMethod ("FindType", BindingFlags.Static | BindingFlags.NonPublic, null, types, null);
var type_to_find = typeof (RegistrationTestClass);
var type = (Type) find_type.Invoke (null, new object [] { Class.GetHandle (type_to_find), false });
var is_static = type_to_find == type;
Expand Down
14 changes: 11 additions & 3 deletions tests/monotouch-test/ObjCRuntime/ToggleRefRetainDeadlockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,17 @@ public void RunTest ()
Thread.Sleep (500);

done.Set ();
gcThread.Join ();
rrThread.Join ();
itThread.Join ();

// If there's a deadlock, we're going to want a native stack trace to debug, so just abort right away.
if (!gcThread.Join (TimeSpan.FromSeconds (30)))
abort ();
if (!rrThread.Join (TimeSpan.FromSeconds (30)))
abort ();
if (!itThread.Join (TimeSpan.FromSeconds (30)))
abort ();
}

[DllImport (Constants.libcLibrary)]
static extern void abort ();
}
}
26 changes: 26 additions & 0 deletions tests/xharness/Jenkins/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Jenkins {
readonly TestVariationsFactory testVariationsFactory;
public JenkinsDeviceLoader DeviceLoader { get; private set; }
readonly ResourceManager resourceManager;
readonly DateTime startTimeUtc = DateTime.UtcNow;

// report writers, do need to be a class instance because the have state.
readonly HtmlReportWriter xamarinStorageHtmlReportWriter;
Expand Down Expand Up @@ -287,6 +288,31 @@ public int Run ()
MainLog.WriteLine ("Unexpected exception: {0}", ex);
Console.WriteLine ("Unexpected exception: {0}", ex);
return 2;
} finally {
CollectCrashReports ();
}
}

// Collect any crash reports that were created during the test run
void CollectCrashReports ()
{
try {
var dir = Path.Combine (Environment.GetEnvironmentVariable ("HOME"), "Library", "Logs", "DiagnosticReports");
var reports = Directory.GetFiles (dir).Select (v => {
(string Path, DateTime LastWriteTimeUtc) rv = (v, File.GetLastWriteTimeUtc (v));
return rv;
}).ToArray ();
MainLog.WriteLine ($"Found {reports.Length} crash reports in {dir} (the ones marked with 'x' occurred during this test run):");
foreach (var report in reports.OrderBy (v => v)) {
MainLog.WriteLine ($" {(report.LastWriteTimeUtc > startTimeUtc ? "x" : " ")} {report.LastWriteTimeUtc.ToString ("u")} {report.Path}");
}
var targetDir = Path.Combine (LogDirectory, "DiagnosticReports");
Directory.CreateDirectory (targetDir);
foreach (var report in reports.Where (v => v.LastWriteTimeUtc >= startTimeUtc)) {
File.Copy (report.Path, Path.Combine (targetDir, Path.GetFileName (report.Path)));
}
} catch (Exception e) {
MainLog.WriteLine ($"Failed to collect crash reports: {e}");
}
}

Expand Down
Loading

5 comments on commit e904e71

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: e904e7100e4e5ff54bfebb041df2ae6bec3c586d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • monotouch-test

Pipeline on Agent
Hash: e904e7100e4e5ff54bfebb041df2ae6bec3c586d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: e904e7100e4e5ff54bfebb041df2ae6bec3c586d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-056.Monterey'
Hash: e904e7100e4e5ff54bfebb041df2ae6bec3c586d [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

🎉 All 0 tests passed 🎉

Failures

❌ bcl tests

🔥 Failed catastrophically on VSTS: simulator tests - bcl (no summary found).

Html Report (VSDrops) Download

❌ cecil tests

🔥 Failed catastrophically on VSTS: simulator tests - cecil (no summary found).

Html Report (VSDrops) Download

❌ dotnettests tests

🔥 Failed catastrophically on VSTS: simulator tests - dotnettests (no summary found).

Html Report (VSDrops) Download

❌ fsharp tests

🔥 Failed catastrophically on VSTS: simulator tests - fsharp (no summary found).

Html Report (VSDrops) Download

❌ framework tests

🔥 Failed catastrophically on VSTS: simulator tests - framework (no summary found).

Html Report (VSDrops) Download

❌ generator tests

🔥 Failed catastrophically on VSTS: simulator tests - generator (no summary found).

Html Report (VSDrops) Download

❌ interdependent_binding_projects tests

🔥 Failed catastrophically on VSTS: simulator tests - interdependent_binding_projects (no summary found).

Html Report (VSDrops) Download

❌ install_source tests

🔥 Failed catastrophically on VSTS: simulator tests - install_source (no summary found).

Html Report (VSDrops) Download

❌ introspection tests

🔥 Failed catastrophically on VSTS: simulator tests - introspection (no summary found).

Html Report (VSDrops) Download

❌ linker tests

🔥 Failed catastrophically on VSTS: simulator tests - linker (no summary found).

Html Report (VSDrops) Download

❌ mac_binding_project tests

🔥 Failed catastrophically on VSTS: simulator tests - mac_binding_project (no summary found).

Html Report (VSDrops) Download

❌ mmp tests

🔥 Failed catastrophically on VSTS: simulator tests - mmp (no summary found).

Html Report (VSDrops) Download

❌ mononative tests

🔥 Failed catastrophically on VSTS: simulator tests - mononative (no summary found).

Html Report (VSDrops) Download

❌ monotouch tests

🔥 Failed catastrophically on VSTS: simulator tests - monotouch (no summary found).

Html Report (VSDrops) Download

❌ msbuild tests

🔥 Failed catastrophically on VSTS: simulator tests - msbuild (no summary found).

Html Report (VSDrops) Download

❌ mtouch tests

🔥 Failed catastrophically on VSTS: simulator tests - mtouch (no summary found).

Html Report (VSDrops) Download

❌ xammac tests

🔥 Failed catastrophically on VSTS: simulator tests - xammac (no summary found).

Html Report (VSDrops) Download

❌ xcframework tests

🔥 Failed catastrophically on VSTS: simulator tests - xcframework (no summary found).

Html Report (VSDrops) Download

❌ xtro tests

🔥 Failed catastrophically on VSTS: simulator tests - xtro (no summary found).

Html Report (VSDrops) Download

Successes

Pipeline on Agent
Hash: [CI build]

Please sign in to comment.