Files
kinect/tools/e2e_linux_validation/run_e2e.py
T
kinect-bot b1638944cb
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python tracker (pytest) (push) Canceled after 0s
feat(e2e-linux): live recorded-video->tracker->synth->OpenNI2 moving-depth proof (wave 7; todo 10 done; +20/21 follow-ups)
2026-11-25 05:34:06 -05:00

140 lines
5.0 KiB
Python

# /// script
# requires-python = ">=3.9"
# ///
# ─── How to run ───
# python3 tools/e2e_linux_validation/run_e2e.py
# ───────────────────
"""Plan todo 10 end-to-end harness: recorded video -> live MediaPipe tracker ->
shared-memory IPC contract -> core/synth-backed OpenNI2 "SynthKinect" driver ->
an independent OpenNI2 consumer reading a sequence of moving depth frames.
Orchestrates (no pytest, no mocks - every step is the real binary/process):
1. generate_dance_video.py: a deterministic recorded video of a real
photographed human panning/zooming across frames (never a live webcam).
2. `cmake --build fallback/linux-openni2/build`: the SynthKinectDriver
(reading the live shared-memory contract via ShmFrameSource) and the
openni2_depth_consumer binary.
3. tracker/.venv's `python -m tracker.tracker` against the recorded video,
publishing real MediaPipe pose+mask frames into the frozen IPC contract.
4. openni2_depth_consumer, which dlopens the driver through OpenNI2 and
reports per-frame body-pixel centroid + in-band depth stats.
Exits non-zero (and the consumer's own FAIL line names the failed check) if
the consumer does not observe >=10 in-band, moving depth frames.
"""
from __future__ import annotations
import os
import shutil
import subprocess
import sys
import time
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SHM_NAME = "virtual_kinect_frames"
SHM_PATH = f"/dev/shm/{SHM_NAME}"
VIDEO_PATH = "/tmp/kinect_e2e/dance.avi"
DRIVER_BUILD_DIR = os.path.join(ROOT, "fallback", "linux-openni2", "build")
TRACKER_VENV_PYTHON = os.path.join(ROOT, "tracker", ".venv", "bin", "python")
GL_LIBS_DIR = os.path.expanduser("~/.cache/kinect/gllibs")
OPENNI2_LIB_DIR = os.path.expanduser("~/.local/openni2-root/usr/lib/x86_64-linux-gnu")
def run(cmd: list[str], **kwargs) -> subprocess.CompletedProcess:
print(f"$ {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True, **kwargs)
print(result.stdout)
if result.stderr:
print(result.stderr, file=sys.stderr)
return result
def generate_video() -> None:
result = run([
TRACKER_VENV_PYTHON,
os.path.join(ROOT, "tools", "e2e_linux_validation", "generate_dance_video.py"),
"--out", VIDEO_PATH,
"--frames", "300",
])
if result.returncode != 0:
raise RuntimeError("generate_dance_video.py failed")
def build_driver() -> None:
configure = run([
"cmake", "-S", os.path.join(ROOT, "fallback", "linux-openni2"), "-B", DRIVER_BUILD_DIR,
])
if configure.returncode != 0:
raise RuntimeError("cmake configure failed")
build = run(["cmake", "--build", DRIVER_BUILD_DIR])
if build.returncode != 0:
raise RuntimeError("cmake build failed")
def wait_for_shm(timeout_s: float) -> bool:
deadline = time.monotonic() + timeout_s
while time.monotonic() < deadline:
if os.path.exists(SHM_PATH):
return True
time.sleep(0.1)
return False
def main() -> int:
if os.path.exists(SHM_PATH):
os.remove(SHM_PATH)
generate_video()
build_driver()
tracker_env = dict(os.environ)
tracker_env["LD_LIBRARY_PATH"] = GL_LIBS_DIR + os.pathsep + tracker_env.get("LD_LIBRARY_PATH", "")
tracker_cmd = [
TRACKER_VENV_PYTHON, "-m", "tracker.tracker",
"--source", VIDEO_PATH,
"--model", "full",
"--target-fps", "15",
"--depth-size", "320x240",
"--color-size", "320x240",
"--shm-name", SHM_NAME,
"--max-seconds", "14",
]
print(f"$ {' '.join(tracker_cmd)} (background)")
tracker_proc = subprocess.Popen(
tracker_cmd, cwd=ROOT, env=tracker_env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
)
try:
if not wait_for_shm(timeout_s=15.0):
raise RuntimeError(f"{SHM_PATH} never appeared - tracker failed to start publishing")
time.sleep(2.0) # bounded grace so several real frames are already published
consumer_path = os.path.join(DRIVER_BUILD_DIR, "openni2_depth_consumer")
consumer_env = dict(os.environ)
consumer_env["LD_LIBRARY_PATH"] = OPENNI2_LIB_DIR + os.pathsep + consumer_env.get("LD_LIBRARY_PATH", "")
consumer = run([consumer_path, "12"], env=consumer_env, timeout=30)
finally:
if tracker_proc.poll() is None:
tracker_proc.terminate()
try:
tracker_stdout, _ = tracker_proc.communicate(timeout=20)
except subprocess.TimeoutExpired:
tracker_proc.kill()
tracker_stdout, _ = tracker_proc.communicate()
print("--- tracker stdout ---")
print(tracker_stdout)
if os.path.exists(SHM_PATH):
os.remove(SHM_PATH)
if consumer.returncode != 0:
print(f"VERDICT: FAIL (consumer exit {consumer.returncode})")
return 1
print("VERDICT: PASS")
return 0
if __name__ == "__main__":
raise SystemExit(main())