[hal,tests] Use waitForProgramStart in tests (#8429)

Change setProgramStarted to accept a boolean so it can be set back to
false by tests. This allows properly waiting for program start in tests.
This commit is contained in:
Peter Johnson
2025-11-29 10:10:01 -08:00
committed by GitHub
parent 32d3ec0218
commit a4aad63dd4
23 changed files with 84 additions and 49 deletions

View File

@@ -138,13 +138,13 @@ Java_org_wpilib_hardware_hal_simulation_SimulatorJNI_waitForProgramStart
/*
* Class: org_wpilib_hardware_hal_simulation_SimulatorJNI
* Method: setProgramStarted
* Signature: ()V
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_org_wpilib_hardware_hal_simulation_SimulatorJNI_setProgramStarted
(JNIEnv*, jclass)
(JNIEnv*, jclass, jboolean started)
{
HALSIM_SetProgramStarted();
HALSIM_SetProgramStarted(started);
}
/*

View File

@@ -10,7 +10,7 @@
extern "C" {
void HALSIM_SetRuntimeType(HAL_RuntimeType type);
void HALSIM_WaitForProgramStart(void);
void HALSIM_SetProgramStarted(void);
void HALSIM_SetProgramStarted(HAL_Bool started);
HAL_Bool HALSIM_GetProgramStarted(void);
void HALSIM_RestartTiming(void);
void HALSIM_PauseTiming(void);

View File

@@ -22,7 +22,6 @@
#include "wpi/hal/cpp/fpga_clock.h"
#include "wpi/hal/simulation/MockHooks.h"
#include "wpi/util/EventVector.hpp"
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
static wpi::util::mutex msgMutex;
@@ -368,7 +367,7 @@ int32_t HAL_GetMatchInfo(HAL_MatchInfo* info) {
}
void HAL_ObserveUserProgramStarting(void) {
HALSIM_SetProgramStarted();
HALSIM_SetProgramStarted(true);
}
void HAL_ObserveUserProgramDisabled(void) {

View File

@@ -68,8 +68,8 @@ double GetFPGATimestamp() {
return GetFPGATime() * 1.0e-6;
}
void SetProgramStarted() {
programStarted = true;
void SetProgramStarted(bool started) {
programStarted = started;
}
bool GetProgramStarted() {
return programStarted;
@@ -83,13 +83,15 @@ void HALSIM_WaitForProgramStart(void) {
int count = 0;
while (!programStarted) {
count++;
wpi::util::print("Waiting for program start signal: {}\n", count);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if (count % 10 == 0) {
wpi::util::print("Waiting for program start signal: {}\n", count);
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
void HALSIM_SetProgramStarted(void) {
SetProgramStarted();
void HALSIM_SetProgramStarted(HAL_Bool started) {
SetProgramStarted(started);
}
HAL_Bool HALSIM_GetProgramStarted(void) {

View File

@@ -10,7 +10,7 @@ void HALSIM_SetRuntimeType(HAL_RuntimeType type) {}
void HALSIM_WaitForProgramStart(void) {}
void HALSIM_SetProgramStarted(void) {}
void HALSIM_SetProgramStarted(HAL_Bool started) {}
HAL_Bool HALSIM_GetProgramStarted(void) {
return false;