Unit testing CTRE on a Mac crashes

I was trying out unit testing on a robot with CTRE Talons/Victors, and am getting strange crashes as the test winds up, that do not happen with other motor types. Not sure if it’s a CTRE thing or a Mac thing, hoping some people can try this out for me.

My repo is https://github.com/swalberg/ctretest and you can switch between Talons and SparkMAXes in the https://github.com/swalberg/ctretest/blob/main/src/test/java/frc/robot/subsystems/MotorTest.java file. If I run the test with a Talon, I get

> Task :test FAILED
HAL Extensions: No extensions found

frc.robot.subsystems.MotorTest > dosomething PASSED
libc++abi: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Process 'Gradle Test Executor 3' finished with non-zero exit value 134
  This problem might be caused by incorrect test process configuration.
  Please refer to the test execution section in the User Manual at https://docs.gradle.org/7.3.3/userguide/java_testing.html#sec:test_execution

If I use the REV motor:

> Task :test
HAL Extensions: No extensions found

frc.robot.subsystems.MotorTest > dosomething PASSED

BUILD SUCCESSFUL in 1s
4 actionable tasks: 2 executed, 2 up-to-date

Hoping I can get someone to try it on Windows and Mac, since all I have here is the Mac.

Thanks,

Sean

Are you on an Intel Mac, or an Apple Silicon Mac? I know a lot of the FRC software stack doesn’t support Apple Silicon Mac’s quite yet.

Are you on an Intel Mac, or an Apple Silicon Mac? I know a lot of the FRC software stack doesn’t support Apple Silicon Mac’s quite yet.

It’s an Intel (2017 MBP)

Here’s the output from a machine running Ubuntu 20.04:

./gradlew test

> Task :test
HAL Extensions: No extensions found

frc.robot.subsystems.MotorTest > dosomething PASSED
[phoenix-diagnostics] Server shutdown cleanly. (dur:10|0)
        
[phoenix] Library shutdown cleanly
        

BUILD SUCCESSFUL in 3s
4 actionable tasks: 2 executed, 2 up-to-date
1 Like

This type of failure is not uncommon on Mac and is unique to Mac. The root cause is typically a thread that uses a global mutex, and on program shutdown, the mutex getting destroyed (since it’s a global) prior to the thread exiting, resulting in the thread attempting to lock or unlock a destroyed mutex. On other operating systems, this is ignored, but Mac’s libc throws an exception.

This exact failure mechanism is why I wrote the SafeThread class in wpiutil, which sets things up to avoid the mutex destruction race (and also avoids shutdown deadlocks).

2 Likes

Probably should send an email to CTRE support, or open a GitHub issue. Probably could open one here? https://github.com/CrossTheRoadElec/Phoenix-Releases

Yes, this is a known issue with the CTRE libraries on OSX (https://github.com/robotpy/robotpy-ctre/issues/151), and I reported it to them in March (but, you should annoy them too :smiling_imp: ).

Thanks, folks. I’ve emailed their support about this!

1 Like

They sent me a dev build this morning which fixed the problem. No word on when that gets released.

2 Likes

The dev build Sean is referring to is available here:
https://maven.ctr-electronics.com/development/com/ctre/phoenix/frcjson/5.21.2-50-gdb9e910/frcjson-5.21.2-50-gdb9e910.json

It’ll also be available in the next full release, but there’s no ETA on when we’ll cut a new release.
Anyone is able to use the dev build in the meantime, however.

2 Likes