Skip to content

Commit 63484ad

Browse files
committed
fix(tests): resolve the emulator path before killing it
_emulator_process() returned the output of `ps -o comm=`, which on Linux is the bare command name (`kkemu`, truncated to 15 chars), not a path -- only macOS returns an absolute one. _power_cycle() then killed that pid and called Popen([exe], cwd=cwd), and Popen resolves a bare name against PATH, never against cwd. The emulator build directory is not on PATH, so on Linux the emulator was killed and never restarted, leaving every later test in the run talking to a dead port. Resolve a runnable path BEFORE returning -- /proc/<pid>/exe first, then an absolute comm, then cwd-relative, then PATH -- and report "not found" when none works, so _power_cycle() takes its documented skip instead of killing an emulator it cannot bring back.
1 parent bc7eecf commit 63484ad

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

tests/test_msg_session_trust_lifetime.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from __future__ import print_function
4141

4242
import os
43+
import shutil
4344
import subprocess
4445
import time
4546
import unittest
@@ -66,7 +67,9 @@
6667
TEST_KEY_ID = 3
6768
CI_SIGNER_ALIAS = 'CI Test'
6869

69-
AAVE_V3_POOL = bytes.fromhex('7d2768de32b0b80b7a3454c06bdac94a69ddc7a9')
70+
# Aave V3 Pool proxy, matching AAVE_SUPPLY_SELECTOR below. Was the V2
71+
# LendingPool address, which does not expose supply().
72+
AAVE_V3_POOL = bytes.fromhex('87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2')
7073
AAVE_SUPPLY_SELECTOR = bytes.fromhex('617ba037')
7174
PROBE_ARGS = [
7275
{'name': 'protocol', 'format': ARG_FORMAT_STRING, 'value': b'Aave V3'},
@@ -151,7 +154,45 @@ def _emulator_process(port):
151154
for cwd_line in cwd_out.splitlines():
152155
if cwd_line.startswith('n'):
153156
cwd = cwd_line[1:]
154-
return pid, exe, cwd
157+
158+
# Resolve a RUNNABLE path before returning, because the caller
159+
# kills this pid and then re-execs what we hand back.
160+
#
161+
# `ps -o comm=` gives the bare command name on Linux (`kkemu`,
162+
# truncated to 15 chars), not a path -- only macOS returns an
163+
# absolute one. Popen([name]) searches PATH, never cwd, and the
164+
# emulator build directory is not on PATH. So on Linux the old
165+
# code killed the emulator and then failed to restart it, leaving
166+
# every later test in the run talking to a dead port.
167+
#
168+
# If no runnable path can be found, report "not found" so
169+
# _power_cycle() takes its documented skip instead of killing an
170+
# emulator it cannot bring back.
171+
exe_path = _resolve_executable(pid, exe, cwd)
172+
if exe_path is None:
173+
continue
174+
return pid, exe_path, cwd
175+
return None
176+
177+
178+
def _resolve_executable(pid, comm, cwd):
179+
"""An absolute, runnable path for `comm`, or None."""
180+
# Linux: the kernel knows exactly what is running.
181+
try:
182+
link = os.readlink('/proc/%d/exe' % pid)
183+
if os.path.isfile(link) and os.access(link, os.X_OK):
184+
return link
185+
except (OSError, AttributeError):
186+
pass
187+
if os.path.isabs(comm) and os.access(comm, os.X_OK):
188+
return comm
189+
if cwd:
190+
candidate = os.path.join(cwd, comm)
191+
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
192+
return candidate
193+
found = shutil.which(comm)
194+
if found:
195+
return found
155196
return None
156197

157198

0 commit comments

Comments
 (0)