libs-base icon indicating copy to clipboard operation
libs-base copied to clipboard

Add unit tests for GSFFIInvocation

Open qmfrederik opened this issue 1 year ago • 14 comments
trafficstars

Selector forwarding from one object to another seems to be broken when using libobjc2 on Windows (see also: https://github.com/gnustep/plugins-themes-WinUXTheme/pull/7#issuecomment-2480839795).

This PR contains two tests which both pass on Linux, pass on Windows when using the GCC runtime, and fail on Windows when using libobjc2 to demonstrate the problem (and verify a fix).

qmfrederik avatar Nov 16 '24 23:11 qmfrederik

Thank you for this test case, this seems very interesting. What I don't understand is, why only one of the tests seems to fail. Shouldn't both behave the same? Sorry, my bad, they both fail, so having just one test case would be enough.

fredkiefer avatar Nov 17 '24 11:11 fredkiefer

@davidchisnall could you please have a look at this issue? The most likely cause seems to be a difference in the bevahiour of libobjc2 on Windows.

fredkiefer avatar Nov 17 '24 11:11 fredkiefer

Thanks @fredkiefer , I made the changes you requested.

You are correct: both tests fail. We can probably keep the GSFakeNSString test and do away with the GSFakeNSMenuItem test. There's a subtle difference in both tests -- in the GSFakeNSString case, selectors are forwarded to a type which is defined in another module; in the GSFakeNSMenuItem both types are defined in the same module. I don't think it matters, though, so one test is probably enough.

qmfrederik avatar Nov 17 '24 12:11 qmfrederik

For completeness: If, in GSFFInvocation.m, in the load method, I comment out the objc_proxy_lookup = gs_objc_proxy_lookup; line, everything works as expected.

qmfrederik avatar Nov 17 '24 12:11 qmfrederik

You most likely also get a working result if you don't implement the method -forwardingTargetForSelector:, which is a speed up for libobjc2.

fredkiefer avatar Nov 17 '24 13:11 fredkiefer

You most likely also get a working result if you don't implement the method -forwardingTargetForSelector:, which is a speed up for libobjc2.

That's correct; I split the test in two -- one which implements forwardingTargetForSelector and another which implements forwardInvocation and methodSignatureForSelector.

qmfrederik avatar Nov 17 '24 15:11 qmfrederik

This has been fixed in libobjc2 (https://github.com/gnustep/libobjc2/pull/313) and the fix is being backported to MSYS (https://github.com/msys2/MINGW-packages/pull/22538). I suggest we wait for MSYS to get the libobjc2 fix, after which CI should be green(er) again.

qmfrederik avatar Nov 19 '24 08:11 qmfrederik

Thanks for adding these tests @qmfrederik. Did MSYS already get the libobjc2 fix so this could be merged?

triplef avatar Jan 21 '25 09:01 triplef

@triplef I don't think these fixes made it to MSYS yet. We could backport this fix to MSYS. The last libobjc2 release was in March, and there have been a bunch of fixes since, so perhaps it's time to cut a new libobjc2 release instead?

qmfrederik avatar Jan 21 '25 09:01 qmfrederik

Thanks for the update. Either way, I think it’s fine to wait too or alternatively we could mark the test as hopeful on MSYS to unblock merging this.

triplef avatar Jan 21 '25 10:01 triplef

@triplef The MSYS2 PR has been merged (https://github.com/msys2/MINGW-packages/pull/22538), the package is now sitting in the queue: https://packages.msys2.org/queue

qmfrederik avatar Jan 24 '25 08:01 qmfrederik

It looks like the libobjc2 MinGW package was updated to libobjc2-2.2.1-2 (from libobjc2-2.2.1-1), and now this test is failing in CI – any idea?

base/Functions/runtime.m:
runtime.m:131 ... class_respondsToSelector() works for class method
runtime.m:133 ... class_respondsToSelector() works for superclass method

triplef avatar Jan 27 '25 07:01 triplef

FYI @gcasa marked these runtime tests as hopeful on Windows in https://github.com/gnustep/libs-base/commit/e8181d35fd0aa3cdae86f3c6caafab4dbb2378e9. It’s passing on MSVC though.

triplef avatar Jan 28 '25 10:01 triplef

FYI @gcasa marked these runtime tests as hopeful on Windows in e8181d3. It’s passing on MSVC though.

These tests NEED to pass. I marked them as hopeful so that CI would be useful for detecting other issues. There is no reason why it should always be RED. Can we please either get it to the point where these pass?

gcasa avatar Jan 28 '25 18:01 gcasa