Skip to content

Commit

Permalink
Switch testing agents to use SIGINT
Browse files Browse the repository at this point in the history
and unblock parser from trying to grab data when acq is stopped
  • Loading branch information
jlashner committed Jan 15, 2025
1 parent ca3b190 commit 57f51ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
8 changes: 7 additions & 1 deletion socs/agents/hwp_encoder/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def __init__(self, beaglebone_port=8080, read_chunk_size=8196):
# Will be continually updated with unix in seconds
self.current_time = 0

# If True, will stop trying to read data from socket
self.stop = False

# Creates a UDP socket to connect to the Beaglebone
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# This helps with testing and rebinding to the same port after reset...
Expand Down Expand Up @@ -306,7 +309,9 @@ def grab_and_parse_data(self):
Error 2: data length is shorter than the IRIG info
even though the IRIG packet header is found.
"""
while True:
self.stop = False

while not self.stop: # This can be toggled by encoder agent to unblock
# If there is data from the socket attached to the beaglebone then
# ready[0] = true
# If not then continue checking for 2 seconds and if there is still no data
Expand Down Expand Up @@ -717,6 +722,7 @@ def _stop_acq(self, session, params=None):
"""
if self.take_data:
self.take_data = False
self.parser.stop = True
return True, 'requested to stop taking data.'

return False, 'acq is not currently running.'
Expand Down
27 changes: 2 additions & 25 deletions tests/integration/test_hwp_supervisor_agent_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,9 @@ def hwp_em() -> Generator[HWPEmulator, None, None]:
em.shutdown()


def _shutdown_agent_runner(runner: _AgentRunner) -> None:
"""
Shutdown the agent process using SIGKILL.
"""
# don't send SIGINT if we've already sent SIGKILL
if not runner._timedout:
runner.proc.send_signal(signal.SIGKILL)
runner._timer.cancel()

try:
runner.proc.communicate(timeout=SIGINT_TIMEOUT)
except subprocess.TimeoutExpired:
runner._raise_subprocess(
"Agent did not terminate within " f"{SIGINT_TIMEOUT} seconds on SIGINT."
)

if runner._timedout:
stdout, stderr = runner.proc.communicate(timeout=SIGINT_TIMEOUT)
print(f"Here is stdout from {runner.agent_name}:\n{stdout}")
print(f"Here is stderr from {runner.agent_name}:\n{stderr}")
raise RuntimeError("Agent timed out.")


def _cleanup_runner(runner: _AgentRunner, cov) -> None:
_shutdown_agent_runner(runner)
# report coverage
runner.shutdown()
agentcov = coverage.data.CoverageData(
basename=f".coverage.agent.{runner.agent_name}"
)
Expand Down Expand Up @@ -93,7 +70,7 @@ def encoder_agent(
wait_for_crossbar, hwp_em: HWPEmulator, cov
) -> Generator[None, None, None]:
agent_path = "../socs/agents/hwp_encoder/agent.py"
agent_name = "pid"
agent_name = "encoder"
timeout = 60
args = [
"--log-dir",
Expand Down

0 comments on commit 57f51ed

Please sign in to comment.