Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
mobilitydb-ref: master
build-libmeos: "true"

# The committed generated tree is what a consumer of this repository
# compiles, and every step below overwrites it, so whether it still holds
# together is decided HERE or nowhere. Drift against a freshly derived
# catalog is ordinary — MobilityDB master moves independently of this
# binding — but a snapshot declaring a function MEOS no longer exports
# reaches that consumer as an EntryPointNotFoundException at run time.
- name: Resolve the COMMITTED snapshot against MEOS
run: |
dotnet build MEOS.NET.sln -c Release
dotnet test MEOS.NET.sln -c Release --no-build \
--filter "FullyQualifiedName~NativeSymbolTests"
env:
LD_LIBRARY_PATH: ${{ steps.provision.outputs.libmeos-prefix }}/lib

- name: Regenerate bindings
run: python3 tools/codegen.py "${{ steps.provision.outputs.catalog-path }}"

Expand Down
64 changes: 64 additions & 0 deletions MEOS.NET.Tests/NativeSymbolTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Reflection;
using System.Runtime.InteropServices;

using MEOS.NET.Functions;

namespace MEOS.NET.Tests
{
/// <summary>
/// Every function this binding declares must be a symbol the MEOS it loads
/// exports.
///
/// A P/Invoke binds by name at the first call, so a function MEOS renames or
/// drops is invisible to the compiler and reaches a caller as an
/// <see cref="EntryPointNotFoundException"/> at run time. Resolving every
/// declared entry point against the loaded library turns that into one named
/// failure here.
/// </summary>
[TestClass]
public class NativeSymbolTests : MeosTest
{
[TestMethod]
public void EveryDeclaredEntryPointResolvesInTheLoadedMeos()
{
string[] entryPoints = DeclaredEntryPoints();

// A parity check that read no declaration would pass over anything.
Assert.IsTrue(entryPoints.Length > 1000,
$"only {entryPoints.Length} entry points were read from the binding");

IntPtr meos = NativeLibrary.Load("meos", typeof(Meos).Assembly, null);
List<string> missing = entryPoints
.Where(name => !NativeLibrary.TryGetExport(meos, name, out _))
.ToList();

Assert.AreEqual(0, missing.Count,
$"MEOS exports none of: {string.Join(", ", missing.Take(20))}");
}

[TestMethod]
public void ASymbolMeosDoesNotExportIsSeenAsMissing()
{
IntPtr meos = NativeLibrary.Load("meos", typeof(Meos).Assembly, null);

Assert.IsFalse(NativeLibrary.TryGetExport(meos, "meos_no_such_function", out _));
Assert.IsTrue(NativeLibrary.TryGetExport(meos, "meos_initialize", out _));
}

/// <summary>The entry point of every native declaration the binding carries.</summary>
private static string[] DeclaredEntryPoints()
{
Type native = typeof(Meos).GetNestedType("Native", BindingFlags.NonPublic)
?? throw new InvalidOperationException("the binding declares no Native class");

return native
.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic
| BindingFlags.DeclaredOnly)
.Select(method => method.GetCustomAttribute<LibraryImportAttribute>())
.Where(attribute => attribute is not null)
.Select(attribute => attribute!.EntryPoint!)
.Distinct()
.ToArray();
}
}
}
Loading
Loading