WPIUtilJNI.now() vs HALUtil.getFPGATime() vs unit tests

hi all,

I think this is @calcmogul or @Peter_Johnson code? Does anybody know the principle behind the WPIUtil vs HALUtil notions of time? They seem different, so in a unit test I can use SimHooks.stepTiming in one case and WPIUtilJNI.setMockTime in the other case. Am I supposed to use one sometimes and the other sometimes? Are they the same under the hood?

In simulation, the wpiutil now() function is configured to call the HAL (simulated) “FPGA time”. This matches the behavior on the Rio, where both calls read the FPGA clock. In general, robot code tests should use the HAL sim functions to adjust FPGA time, as this will then be reflected in both time paths. Calling the wpiutil setMockTime will actually decouple the two clocks and have less predictable behavior.

The reason there is a separate setMockTime() function for wpiutil is to enable mock time testing in cases where there is no HAL (e.g. desktop tools which use wpimath/wpiutil but not the HAL).

ok, thanks.

is there a way to stop the FPGA timer in tests? The mock timer is convenient because it doesn’t tick on its own, where as the simulated timer does, so the test behavior is not deterministic.

SimHooks.pauseTiming() will stop the FPGA clock, SimHooks.stepTiming() will step it, etc.

1 Like