CmvrControlStation/tests/run_touch_integration.py

59 lines
2.2 KiB
Python
Raw Normal View History

"""Link the touch loopback harness against the actual qmake Debug app objects.
Usage: python tests/run_touch_integration.py --build-dir <shadow dir> --qt-bin <Qt bin>
The executable creates its own ephemeral loopback service and never opens hardware.
"""
import argparse
import os
from pathlib import Path
import re
import shlex
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--build-dir", required=True, type=Path)
parser.add_argument("--qt-bin", required=True, type=Path)
options = parser.parse_args()
root = Path(__file__).resolve().parents[1]
build = options.build_dir.resolve()
qt_bin = options.qt_bin.resolve()
makefile = (build / "Makefile.Debug").read_text(encoding="utf-8")
def value(name):
match = re.search(r"^" + name + r"\s*=\s*(.*)$", makefile, re.M)
if not match:
raise RuntimeError(f"Missing {name} in {build / 'Makefile.Debug'}")
return match.group(1).strip()
def arguments(text):
return [word.strip('"') for word in shlex.split(text, posix=False)]
output = root / "bin/debug/touch_integration_test.exe"
obj = build / "touchintegration_test.o"
env = dict(os.environ)
env["PATH"] = str(qt_bin) + os.pathsep + env["PATH"]
compiler = value("CXX")
flags = value("CXXFLAGS").replace("$(DEFINES)", value("DEFINES"))
subprocess.run(
[compiler, "-c", *arguments(flags), *arguments(value("INCPATH")),
"-I" + str(qt_bin.parent / "include/QtTest"),
str(root / "tests/touchintegration_test.cpp"), "-o", str(obj)],
cwd=build, env=env, check=True,
)
objects = (build / "object_script.CmvrControlStation_d.Debug").read_text().splitlines()
objects = [line for line in objects if not line.replace("\\", "/").endswith("/main.o")]
if not any("touchsequencecontroller.o" in line for line in objects):
raise RuntimeError("Build the Debug application with TouchSequenceController before running this harness")
response = build / "touchintegration_objects.rsp"
response.write_text("\n".join(objects), encoding="utf-8")
subprocess.run(
[compiler, "-mthreads", "-o", str(output), str(obj), "@" + str(response),
*arguments(value("LIBS")), str(qt_bin.parent / "lib/libQt5Testd.a")],
cwd=build, env=env, check=True,
)
subprocess.run([str(output)], cwd=output.parent, env=env, check=True, timeout=40)