jnr / jnr-ffi

Java Abstracted Foreign Function Layer
Other
1.26k stars 157 forks source link

Support for LoongArch64 #308

Closed Panxuefeng-loongson closed 2 years ago

Panxuefeng-loongson commented 2 years ago

After watching https://github.com/jnr/jnr-posix/issues/135,

I realized that I still need to port jnr-ffi and jnr-posix. I ported jnr-ffi support for loongarch,

When I use . /mvnw test command to test the function, The following error occurred:

[INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running jnr.ffi.ArrayTest [ERROR] Tests run: 11, Failures: 0, Errors: 11, Skipped: 0, Time elapsed: 0.205 s <<< FAILURE! - in jnr.ffi.ArrayTest [ERROR] shortByReference Time elapsed: 0.047 s <<< ERROR! java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider at jnr.ffi.ArrayTest.setUpClass(ArrayTest.java:115) Caused by: java.lang.UnsatisfiedLinkError: could not get native definition for type POINTER, original error message follows: cannot determine CPU at jnr.ffi.ArrayTest.setUpClass(ArrayTest.java:115)

By the way, I would like to put jffi's pr link here for your convenience: https://github.com/jnr/jffi/pull/125

headius commented 2 years ago

@Panxuefeng-loongson Did you run that test with the updated build of jffi that supports LoongArch?

Panxuefeng-loongson commented 2 years ago

@Panxuefeng-loongson Did you run that test with the updated build of jffi that supports LoongArch?

I haven't had time to fix the build failure, I'll fix the remaining issues soon

Panxuefeng-loongson commented 2 years ago

Hi: I tested and got the following error [ERROR] closureNullWithNull Time elapsed: 0.003 s <<< ERROR! java.lang.UnsatisfiedLinkError: could not load FFI provider jnr.ffi.provider.jffi.Provider at jnr.ffi.DelegateTest.setUpClass(DelegateTest.java:57) Caused by: java.lang.UnsatisfiedLinkError: could not get native definition for typePOINTER`, original error message follows: cannot determine CPU at jnr.ffi.DelegateTest.setUpClass(DelegateTest.java:57)

[INFO] [INFO] Results: [INFO] [ERROR] Errors: [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.pinnedByteByReference:247 » UnsatisfiedLink could not load FFI provi... [ERROR] ArrayTest.pinnedByteReadingFaster:276 » UnsatisfiedLink could not load FFI pro... [ERROR] ArrayTest.pinnedIntByReference:259 » UnsatisfiedLink could not load FFI provid... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] ArrayTest.setUpClass:115 » UnsatisfiedLink could not load FFI provider jnr.ffi... [ERROR] BufferTest.setUpClass:81 » UnsatisfiedLink could not load FFI provider jnr.ffi... ` Is this error caused by me not updating jffi? I don't know how to update jffi. Please let me know, thanks.

headius commented 2 years ago

I apologize for losing track of this PR. What is the current status?

Panxuefeng-loongson commented 2 years ago

I apologize for losing track of this PR. What is the current status? Hi:

I'm so sorry I was busy with other things a while ago. Recently, I plan to finish porting jnr-ffi and jruby to LoongArch. If there is any progress, I will sync it to pr.

Thanks

Panxuefeng-loongson commented 2 years ago

After I rebase the code to latest, but some tests failed. I'm going to take a moment to fix these issues

Panxuefeng-loongson commented 2 years ago

@Panxuefeng-loongson Did you run that test with the updated build of jffi that supports LoongArch?

I'm not quite sure how to do it, Could you please tell me how to run that test with the updated build of jffi?

headius commented 2 years ago

Could you please tell me how to run that test with the updated build of jffi?

You can mvn install the jffi binary locally, and then use that SNAPSHOT version number in the build of jnr-ffi.

Panxuefeng-loongson commented 2 years ago

Could you please tell me how to run that test with the updated build of jffi?

You can mvn install the jffi binary locally, and then use that SNAPSHOT version number in the build of jnr-ffi.

Thanks for your reminder. Now two more tests fail, as follows:

[ERROR] Failures: 
[ERROR]   PlatformTest.testDefaultLocateLibraryLowerCustomVersion:195 expected: not equal but was: </tmp/1666270121547-0>
[ERROR]   PlatformTest.testDefaultLocateLibraryNoCustomVersion:210 expected: not equal but was: </tmp/1666270121327-0>
[INFO] 
[ERROR] Tests run: 450, Failures: 2, Errors: 0, Skipped: 4

I don't know the reason for the error, do you know the reason?

Thanks

Panxuefeng-loongson commented 2 years ago

Could you please tell me how to run that test with the updated build of jffi?

You can mvn install the jffi binary locally, and then use that SNAPSHOT version number in the build of jnr-ffi.

Thanks for your reminder. Now two more tests fail, as follows:

[ERROR] Failures: 
[ERROR]   PlatformTest.testDefaultLocateLibraryLowerCustomVersion:195 expected: not equal but was: </tmp/1666270121547-0>
[ERROR]   PlatformTest.testDefaultLocateLibraryNoCustomVersion:210 expected: not equal but was: </tmp/1666270121327-0>
[INFO] 
[ERROR] Tests run: 450, Failures: 2, Errors: 0, Skipped: 4

I don't know the reason for the error, do you know the reason?

Thanks

These two tests don't seem to be very critical, can we add these two tests to the whitelist and skip the test?

Panxuefeng-loongson commented 2 years ago

Could you please tell me how to run that test with the updated build of jffi?

You can mvn install the jffi binary locally, and then use that SNAPSHOT version number in the build of jnr-ffi.

Thanks for your reminder. Now two more tests fail, as follows:

[ERROR] Failures: 
[ERROR]   PlatformTest.testDefaultLocateLibraryLowerCustomVersion:195 expected: not equal but was: </tmp/1666270121547-0>
[ERROR]   PlatformTest.testDefaultLocateLibraryNoCustomVersion:210 expected: not equal but was: </tmp/1666270121327-0>
[INFO] 
[ERROR] Tests run: 450, Failures: 2, Errors: 0, Skipped: 4

I don't know the reason for the error, do you know the reason? Thanks

These two tests don't seem to be very critical, can we add these two tests to the whitelist and skip the test?

These two test failures are caused by my machine environment, and now the tests can all pass:

[INFO] 
[INFO] Results:
[INFO] 
[WARNING] Tests run: 450, Failures: 0, Errors: 0, Skipped: 4
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:58 min
[INFO] Finished at: 2022-10-21T14:30:09+08:00
[INFO] Final Memory: 28M/2235M
[INFO] ------------------------------------------------------------------------
Panxuefeng-loongson commented 2 years ago

RFR @headius

headius commented 2 years ago

Great news! I will review.

I need to figure out how to build the jffi native binary so I can have it done as part of our CI process. You can see a build I have been trying to make work with the available Debian/LoongArch image, but I have been unsucessful:

https://github.com/jnr/jffi/pull/126

Can't seem to figure out the right docker commands to get it to run like the other platforms.

headius commented 2 years ago

I pushed a snapshot to the snapshots repo so that these can pass. The macos/aarch64 builds are caching the failed lookup, but I'm not concerned about them.

This will not really be a true CI test until we can run the tests on LoongArch but I can merge your changes before that happens. We still need a binary to include in jffi, though, and I need to be able to build it myself.

Panxuefeng-loongson commented 2 years ago

I pushed a snapshot to the snapshots repo so that these can pass. The macos/aarch64 builds are caching the failed lookup, but I'm not concerned about them.

This will not really be a true CI test until we can run the tests on LoongArch but I can merge your changes before that happens. We still need a binary to include in jffi, though, and I need to be able to build it myself.

Is there anything I need to do to move this thing forward?

headius commented 2 years ago

Is there anything I need to do to move this thing forward?

I need a way to access a LoongArch64 machine, either physical hardware or something in the cloud, so that I can create binary builds of the jffi stub.

Currently I am trying to get a docker build working with qemu 7.1's preliminary LoongArch support, but it may not be successful. Real hardware would be better.

Panxuefeng-loongson commented 2 years ago

Is there anything I need to do to move this thing forward?

I need a way to access a LoongArch64 machine, either physical hardware or something in the cloud, so that I can create binary builds of the jffi stub.

Currently I am trying to get a docker build working with qemu 7.1's preliminary LoongArch support, but it may not be successful. Real hardware would be better.

We have Loongarch machines in the GCC compile farm, see: https://cfarm.tetaneutral.net/machines/list/. I think you can build the Loongarch port code with it.

Panxuefeng-loongson commented 2 years ago

Is there anything I need to do to move this thing forward?

I need a way to access a LoongArch64 machine, either physical hardware or something in the cloud, so that I can create binary builds of the jffi stub.

Currently I am trying to get a docker build working with qemu 7.1's preliminary LoongArch support, but it may not be successful. Real hardware would be better.

If compiled natively, jnr-ffi requires a loongarch machine executable jdk. I can provide it to you, either by e-mail or otherwise.

Thanks

headius commented 2 years ago

I will try to get set up with the GCC compile farm this week or early next. If you can provide a link to a pre-built LoongArch JDK that would speed things up.

Panxuefeng-loongson commented 2 years ago

I will try to get set up with the GCC compile farm this week or early next. If you can provide a link to a pre-built LoongArch JDK that would speed things up.

I have sent you the jdk binary via email.

headius commented 2 years ago

I have received the JDK, activated my gcc compile farm account, updated my ssh key there and waited for it to propagate... but now it seems the two LoongArch machines are not available! They show as red in the compile farm list, and although I can connect it does not have my public key and I can't log in.

Panxuefeng-loongson commented 2 years ago

I have received the JDK, activated my gcc compile farm account, updated my ssh key there and waited for it to propagate... but now it seems the two LoongArch machines are not available! They show as red in the compile farm list, and although I can connect it does not have my public key and I can't log in.

I confirmed with my colleague that the machine is still online.

Panxuefeng-loongson commented 2 years ago

I have received the JDK, activated my gcc compile farm account, updated my ssh key there and waited for it to propagate... but now it seems the two LoongArch machines are not available! They show as red in the compile farm list, and although I can connect it does not have my public key and I can't log in.

The machine on the gcc farm is already showing fine, please try again.

headius commented 2 years ago

I made another attempt to connect, but it seems my key still did not propagate. Now that they are not red, I have resubmitted my key. Once it syncs, I will make another attempt.

headius commented 2 years ago

I am still unable to log into the machine. I am able to log into machines other than the two LoongArch machines. I can try to open a ticket, or you can just pass this information on to the maintainers. Hopefully I am not doing something wrong!

headius commented 2 years ago

I am on the machine and getting everything built and released now.

Panxuefeng-loongson commented 2 years ago

I am on the machine and getting everything built and released now.

Good news!

headius commented 2 years ago

@Panxuefeng-loongson I have built and deployed a snapshot of jffi with loongarch64 support! You should be able to run the tests in this PR on a loongarch64 machine.

I see two failures and then the test suite hangs during NumberTest (or is so slow it did not seem to make progress):

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running jnr.ffi.ObjectReferenceManagerTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.33 s - in jnr.ffi.ObjectReferenceManagerTest
[INFO] Running jnr.ffi.StringArrayTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.827 s - in jnr.ffi.StringArrayTest
[INFO] Running jnr.ffi.byref.AddressByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.703 s - in jnr.ffi.byref.AddressByReferenceTest
[INFO] Running jnr.ffi.byref.IntByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.67 s - in jnr.ffi.byref.IntByReferenceTest
[INFO] Running jnr.ffi.byref.PointerByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.766 s - in jnr.ffi.byref.PointerByReferenceTest
[INFO] Running jnr.ffi.byref.ByteByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.679 s - in jnr.ffi.byref.ByteByReferenceTest
[INFO] Running jnr.ffi.PointerTest
[INFO] Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.893 s - in jnr.ffi.PointerTest
[INFO] Running jnr.ffi.TypeDefinitionTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.623 s - in jnr.ffi.TypeDefinitionTest
[INFO] Running jnr.ffi.PlatformTest
[ERROR] Tests run: 14, Failures: 2, Errors: 0, Skipped: 1, Time elapsed: 0.655 s <<< FAILURE! - in jnr.ffi.PlatformTest
[ERROR] testDefaultLocateLibraryNoCustomVersion  Time elapsed: 0.03 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: not equal but was: </tmp/1667971786724-0>
    at jnr.ffi.PlatformTest.testDefaultLocateLibraryNoCustomVersion(PlatformTest.java:208)

[ERROR] testDefaultLocateLibraryLowerCustomVersion  Time elapsed: 0.008 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: not equal but was: </tmp/1667971787118-0>
    at jnr.ffi.PlatformTest.testDefaultLocateLibraryLowerCustomVersion(PlatformTest.java:193)

[INFO] Running jnr.ffi.VarargsTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.695 s - in jnr.ffi.VarargsTest
[INFO] Running jnr.ffi.numeric.EnumTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.705 s - in jnr.ffi.numeric.EnumTest
[INFO] Running jnr.ffi.numeric.NativeLongTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.194 s - in jnr.ffi.numeric.NativeLongTest
[INFO] Running jnr.ffi.numeric.NumberTest
(hang)

Perhaps you can look into the test suite now and make sure everything passes?

Panxuefeng-loongson commented 2 years ago

@Panxuefeng-loongson I have built and deployed a snapshot of jffi with loongarch64 support! You should be able to run the tests in this PR on a loongarch64 machine.

I see two failures and then the test suite hangs during NumberTest (or is so slow it did not seem to make progress):

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running jnr.ffi.ObjectReferenceManagerTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.33 s - in jnr.ffi.ObjectReferenceManagerTest
[INFO] Running jnr.ffi.StringArrayTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.827 s - in jnr.ffi.StringArrayTest
[INFO] Running jnr.ffi.byref.AddressByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.703 s - in jnr.ffi.byref.AddressByReferenceTest
[INFO] Running jnr.ffi.byref.IntByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.67 s - in jnr.ffi.byref.IntByReferenceTest
[INFO] Running jnr.ffi.byref.PointerByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.766 s - in jnr.ffi.byref.PointerByReferenceTest
[INFO] Running jnr.ffi.byref.ByteByReferenceTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.679 s - in jnr.ffi.byref.ByteByReferenceTest
[INFO] Running jnr.ffi.PointerTest
[INFO] Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.893 s - in jnr.ffi.PointerTest
[INFO] Running jnr.ffi.TypeDefinitionTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.623 s - in jnr.ffi.TypeDefinitionTest
[INFO] Running jnr.ffi.PlatformTest
[ERROR] Tests run: 14, Failures: 2, Errors: 0, Skipped: 1, Time elapsed: 0.655 s <<< FAILURE! - in jnr.ffi.PlatformTest
[ERROR] testDefaultLocateLibraryNoCustomVersion  Time elapsed: 0.03 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: not equal but was: </tmp/1667971786724-0>
  at jnr.ffi.PlatformTest.testDefaultLocateLibraryNoCustomVersion(PlatformTest.java:208)

[ERROR] testDefaultLocateLibraryLowerCustomVersion  Time elapsed: 0.008 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: not equal but was: </tmp/1667971787118-0>
  at jnr.ffi.PlatformTest.testDefaultLocateLibraryLowerCustomVersion(PlatformTest.java:193)

[INFO] Running jnr.ffi.VarargsTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.695 s - in jnr.ffi.VarargsTest
[INFO] Running jnr.ffi.numeric.EnumTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.705 s - in jnr.ffi.numeric.EnumTest
[INFO] Running jnr.ffi.numeric.NativeLongTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.194 s - in jnr.ffi.numeric.NativeLongTest
[INFO] Running jnr.ffi.numeric.NumberTest
(hang)

Perhaps you can look into the test suite now and make sure everything passes?

I I have also encountered this problem, I think it is an environmental problem. Please check if you have the following soft link information. On my machine, after creating the soft link, the test passed

[chenglulu@174 ~]$ ls /usr/lib/libc.so.6 -la
lrwxrwxrwx 1 root root 15 Oct 21 14:15 /usr/lib/libc.so.6 -> ./lib64/libc.so
headius commented 2 years ago

The 401 machine I had been using appears to be down now. 😭

However, since you say it passes for you with that symlink in place, I'm willing to push forward and merge this in for release.

Panxuefeng-loongson commented 2 years ago

The 401 machine I had been using appears to be down now. sob

However, since you say it passes for you with that symlink in place, I'm willing to push forward and merge this in for release.

Is there anything I can do to move the release forward?I am more than happy to help.

Panxuefeng-loongson commented 2 years ago

I gave feedback to my colleague about the machine going offline. We apologize for the delay in the release due to external reasons.

headius commented 2 years ago

Release 1.3.10 of jffi and 2.2.13 of jnr-ffi have been released with LoongArch64 support!

In order to release the rest of the libraries, we need to generate constants for jnr-constants and make sure tests pass for jnr-enxio, jnr-unixsocket, jnr-posix, and perhaps jnr-process (though few people use that one).

Panxuefeng-loongson commented 2 years ago

Release 1.3.10 of jffi and 2.2.13 of jnr-ffi have been released with LoongArch64 support!

In order to release the rest of the libraries, we need to generate constants for jnr-constants and make sure tests pass for jnr-enxio, jnr-unixsocket, jnr-posix, and perhaps jnr-process (though few people use that one).

My colleague seems to have submitted code to support the jnr-constants Loongson architecture, see: https://github.com/jnr/jnr-constants/pull/98.

Panxuefeng-loongson commented 2 years ago

@headius I don't know much about the jnr project, what other jnr repo might require architecture-related support? I can try it.

Panxuefeng-loongson commented 2 years ago

Release 1.3.10 of jffi and 2.2.13 of jnr-ffi have been released with LoongArch64 support!

In order to release the rest of the libraries, we need to generate constants for jnr-constants and make sure tests pass for jnr-enxio, jnr-unixsocket, jnr-posix, and perhaps jnr-process (though few people use that one).

How do I test those code(jnr-enxio, jnr-unixsocket, jnr-posix, and jnr-process)? I did not find a useful document.

headius commented 2 years ago

FYI @Panxuefeng-loongson, although the two GCC compile farm machines were done yesterday, I went ahead with releasing the rest of the JNR stack. All libraries are now up-to-date with all the LoongArch patches you and your colleagues have contributed.

Thanks for your help!

If you are able to test these other libraries, it should be a simple matter of running mvn test in each. The jnr-enxio and jnr-unixsocket libraries do not have many tests, but jnr-posix has many.

Panxuefeng-loongson commented 2 years ago

jnr-enxio tests all passed, jnr-unixsocket has some failed caused by time out, I think this is due to the network. But jnr-posix may need to add loongarch code.

Tests in error:
  clientWritesAndServerReads[jnr.unixsocket.TcpSocketsApiSocketPair$1@6eceb130](jnr.unixsocket.SocketInteropTest): test timed out after 5 seconds
  concurrentReadAndWrite[jnr.unixsocket.TcpSocketsApiSocketPair$1@6eceb130](jnr.unixsocket.SocketInteropTest): test timed out after 5 seconds
  serverWritesAndClientReads[jnr.unixsocket.TcpSocketsApiSocketPair$1@6eceb130](jnr.unixsocket.SocketInteropTest): test timed out after 5 seconds
  clientWritesAndServerReads[jnr.unixsocket.TcpChannelsApiSocketPair$1@10a035a0](jnr.unixsocket.SocketInteropTest): test timed out after 5 seconds
  serverWritesAndClientReads[jnr.unixsocket.TcpChannelsApiSocketPair$1@10a035a0](jnr.unixsocket.SocketInteropTest): test timed out after 5 seconds

Tests run: 44, Failures: 0, Errors: 5, Skipped: 3
Panxuefeng-loongson commented 2 years ago

I have submited a pr: https://github.com/jnr/jnr-posix/pull/179, I would like you confirm the change. @headius