Skip to content

Commit

Permalink
[d16-6][corefoundation] Fix TypeInitializationException in OSLog (#7962
Browse files Browse the repository at this point in the history
…) (#7977)

`Default` property was using a nil-handle which is incorrect since
* we don't allow that (this is generally a bad sign)
* it does not map to `OS_LOG_DEFAULT`

Since `Default` was assigned in the type (static) constructor then
the whole type became unusable :(

Header `log.h` shows that the right definition requires us to load a
field and use it.

```
define OS_LOG_DEFAULT OS_OBJECT_GLOBAL_OBJECT(os_log_t, _os_log_default)
```

While `NULL` can actually be used for disabled (not exposed) by this
contradicting (nullability-wise) macro

```
define OS_LOG_DISABLED ((os_log_t _Nonnull)NULL)
```

Also adds unit tests. A more general tests for `.cctor` will be added
to introspection tests in a separate PR.

Fixes #7959
  • Loading branch information
spouliot authored Feb 25, 2020
1 parent ef273a5 commit 514991e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/CoreFoundation/OSLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ namespace CoreFoundation {
[Mac (10,12), iOS (10,0), Watch (3,0), TV (10,0)]
[Introduced (PlatformName.MacCatalyst, 13, 0)]
public sealed class OSLog : NativeObject {
public static OSLog Default { get; } = new OSLog (IntPtr.Zero, false);

static OSLog _default;

public static OSLog Default {
get {
if (_default == null) {
var h = Dlfcn.dlsym (Libraries.System.Handle, "_os_log_default");
if (h == IntPtr.Zero)
throw new NotSupportedException ("Feature not available on this OS version");
_default = new OSLog (h, false);
}
return _default;
}
}

protected override void Retain ()
{
Expand Down
40 changes: 40 additions & 0 deletions tests/monotouch-test/CoreFoundation/OSLogTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

using CoreFoundation;
using Foundation;
using ObjCRuntime;

using NUnit.Framework;

namespace MonoTouchFixtures.CoreFoundation {

[TestFixture]
[Preserve (AllMembers = true)]
public class OSLogTest {

[TestFixtureSetUp]
public void SetUp ()
{
TestRuntime.AssertXcodeVersion (8,0);
}

[Test]
public void Default ()
{
OSLog.Default.Log (OSLogLevel.Default, "monotouch-test / Default / Default");
// this will show in the application output (e.g. inside VSfM)
}

[Test]
public void Custom ()
{
using (var log = new OSLog ("subsystem", "category")) {
log.Log (OSLogLevel.Error, "monotouch-test / custom / Debug");
// this will show in the application output (e.g. inside VSfM)
// and also inside Console.app under the simulator/device
}
}
}
}

11 comments on commit 514991e

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🚧 Experimental DDFun pipeline

🔥 Device tests completed (Failed) on iOS-DDFun on Azure DevOps(iOS-DDFun) 🔥

Test results

8 tests failed, 142 tests passed.

Failed tests

  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/Debug: Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug (interpreter): TimedOut
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/Release: Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (release): Failed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on iOS on Azure DevOps(iOS): Html Report 🔥

Test results

8 tests failed, 142 tests passed.

Failed tests

  • mscorlib Part 3/iOS Unified 64-bits - device/Debug: Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • [NUnit] Mono BCL tests group 2/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (release): Failed
  • mscorlib Part 3/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • mscorlib Part 3/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • mscorlib Part 3/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (release): Failed
  • mscorlib Part 3/iOS Unified 64-bits - device/Debug: SGenConc: Failed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on TvOS on Azure DevOps(TvOS): Html Report 🔥

Test results

1 tests failed, 149 tests passed.

Failed tests

  • [xUnit] Mono BCL tests group 3/tvOS - device/AssemblyBuildTarget: SDK framework (release): TimedOut

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Test run, Test run' 🔥

Build succeeded
✅ Packages:

API Diff (from stable)
API Diff (from PR only) (no change)
Generator Diff (no change)
🔥 Test run failed 🔥

Test results

4 tests failed, 179 tests passed.

Failed tests

  • xammac tests/Mac Modern/Debug: TimedOut (Execution timed out after 1200 seconds.)
  • xammac tests/Mac Modern/Debug: TimedOut (Execution timed out after 1200 seconds.)
  • xammac tests/Mac Modern/Release: TimedOut (Execution timed out after 1200 seconds.)
  • xammac tests/Mac Modern/Release: TimedOut (Execution timed out after 1200 seconds.)

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Checkout' 🔥 : org.jenkinsci.plugins.workflow.steps.FlowInterruptedException

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🚧 Experimental DDFun pipeline

🔥 Device tests completed (Failed) on iOS-DDFun on Azure DevOps(iOS-DDFun) 🔥

Test results

14 tests failed, 136 tests passed.

Failed tests

  • monotouch-test/iOS Unified 64-bits - device/Debug: Failed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • monotouch-test/iOS Unified 64-bits - device/Release: Failed
  • monotouch-test/iOS Unified 64-bits - device/AssemblyBuildTarget: SDK framework (release): Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug (dynamic registrar): Failed
  • monotouch-test/iOS Unified 64-bits - device/Release (all optimizations): Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug (all optimizations): Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug: SGenConc: Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug (interpreter): Failed
  • monotouch-test/iOS Unified 64-bits - device/Debug (interpreter -mscorlib): Failed
  • monotouch-test/iOS Unified 64-bits - device/Release (interpreter -mscorlib): Failed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ Device tests passed on iOS on Azure DevOps(iOS): Html Report

🎉 All 150 tests passed 🎉

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on iOS32b on Azure DevOps(iOS32b): Html Report 🔥

Test results

20 tests failed, 141 tests passed.

Failed tests

  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/Debug: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Debug: Failed
  • dont link/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): Crashed
  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - device/Release: UseThumb: TimedOut
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: UseThumb: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): BuildFailure
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Release: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Release: UseThumb: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Debug: SGenConc: Failed

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on TvOS on Azure DevOps(TvOS): Html Report 🔥

Test results

14 tests failed, 136 tests passed.

Failed tests

  • monotouch-test/tvOS - device/Debug: TimedOut
  • monotouch-test/tvOS - device/AssemblyBuildTarget: dylib (debug): TimedOut
  • monotouch-test/tvOS - device/AssemblyBuildTarget: SDK framework (debug): TimedOut
  • monotouch-test/tvOS - device/AssemblyBuildTarget: dylib (debug, profiling): TimedOut
  • monotouch-test/tvOS - device/AssemblyBuildTarget: SDK framework (debug, profiling): TimedOut
  • monotouch-test/tvOS - device/Release: TimedOut
  • monotouch-test/tvOS - device/AssemblyBuildTarget: SDK framework (release): TimedOut
  • monotouch-test/tvOS - device/Debug (dynamic registrar): TimedOut
  • monotouch-test/tvOS - device/Release (all optimizations): TimedOut
  • monotouch-test/tvOS - device/Debug (all optimizations): TimedOut
  • monotouch-test/tvOS - device/Debug: SGenConc: TimedOut
  • monotouch-test/tvOS - device/Debug (interpreter): TimedOut
  • monotouch-test/tvOS - device/Debug (interpreter -mscorlib): TimedOut
  • monotouch-test/tvOS - device/Release (interpreter -mscorlib): TimedOut

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Device tests completed (Failed) on iOS32b on Azure DevOps(iOS32b): Html Report 🔥

Test results

# Test run in progress: Running: 1, RunQueued: 26, Succeeded: 111, Failed: 14, Ignored: 1100, Crashed: 1, TimedOut: 5, BuildFailure: 3

Failed tests

  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/Debug: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Debug: Failed
  • dont link/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): Crashed
  • [NUnit] Mono BCL tests group 2/iOS Unified 32-bits - device/Release: UseThumb: TimedOut
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • [xUnit] Mono BCL tests group 4/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): TimedOut
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/Release: UseThumb: BuildFailure
  • mscorlib Part 1/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): BuildFailure
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: dylib (debug, profiling): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (debug, profiling): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Release: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Release: UseThumb: Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/AssemblyBuildTarget: SDK framework (release): Failed
  • mscorlib Part 2/iOS Unified 32-bits - device/Debug: SGenConc: Failed

Please sign in to comment.