Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions test/Sentry.Unity.Editor.Tests/Native/SwitchNativeStubTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using NUnit.Framework;

namespace Sentry.Unity.Editor.Tests.Native;

public class SwitchNativeStubTests
{
[Test]
public void Stub_ContainsEverySwitchNativeBinding()
{
var packageRoot = Path.GetFullPath(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "..", ".."));
var switchAssemblyPath = Path.Combine(packageRoot, "Runtime", "Sentry.Unity.Native.Switch.dll");
var stubPath = Path.Combine(packageRoot, "Plugins", "Switch", "sentry_native_stubs.c");

Assert.That(File.Exists(switchAssemblyPath), Is.True, $"Switch assembly not found at {switchAssemblyPath}");
Assert.That(File.Exists(stubPath), Is.True, $"Switch stubs not found at {stubPath}");

var switchAssembly = Assembly.LoadFrom(switchAssemblyPath);
var entryPoints = switchAssembly
.GetTypes()
.SelectMany(type => type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
.Select(method => (Method: method, Import: method.GetCustomAttribute<DllImportAttribute>()))
.Where(binding => binding.Import?.Value == "__Internal")
.Select(binding => binding.Import!.EntryPoint is { Length: > 0 } entryPoint
? entryPoint
: binding.Method.Name)
.Distinct()
.ToList();

Assert.That(entryPoints, Is.Not.Empty);

var stubContent = File.ReadAllText(stubPath);
foreach (var entryPoint in entryPoints)
{
Assert.That(Regex.IsMatch(stubContent, $@"\b{Regex.Escape(entryPoint)}\s*\("), Is.True,
$"Switch binding '{entryPoint}' not found in {stubPath}");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New test fails against current stubs

Medium Severity

Stub_ContainsEverySwitchNativeBinding requires every Switch __Internal P/Invoke to appear in sentry_native_stubs.c, but the stubs omit bindings that the Switch assembly still exports, including sentry_attach_file, sentry_attach_bytes, sentry_clear_attachments, sentry_options_set_logger_enabled_when_crashed, and sentry_app_hang_pause. The new EditMode test fails immediately.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ec44e82. Configure here.

}
}
Loading