CmvrControlStation/tests/run_tcp_integration.py

43 lines
2.0 KiB
Python
Raw Normal View History

"""Link a loopback integration harness against an already-built qmake Debug app.
Usage: python tests/run_tcp_integration.py --build-dir <qmake shadow dir> --qt-bin <Qt bin>
Uses the app's actual objects/libraries; never executes the normal app or connects to hardware.
"""
import argparse
import os
from pathlib import Path
import re
import shlex
import subprocess
p = argparse.ArgumentParser()
p.add_argument('--build-dir', required=True, type=Path)
p.add_argument('--qt-bin', required=True, type=Path)
a = p.parse_args()
root = Path(__file__).resolve().parents[1]
build = a.build_dir.resolve()
makefile = (build / 'Makefile.Debug').read_text(encoding='utf-8')
def value(name):
return re.search(r'^' + name + r'\s*=\s*(.*)$', makefile, re.M).group(1).strip()
def args(text):
return [word.strip('"') for word in shlex.split(text, posix=False)]
output = root / 'bin/debug/tcp_integration_test.exe'
obj = build / 'tcpintegration_test.o'
env = dict(os.environ)
env['PATH'] = str(a.qt_bin.resolve()) + os.pathsep + env['PATH']
env['QT_QPA_PLATFORM'] = 'offscreen'
env['QT_QPA_FONTDIR'] = 'C:/Windows/Fonts'
compiler = value('CXX')
flags = value('CXXFLAGS').replace('$(DEFINES)', value('DEFINES'))
subprocess.run([compiler, '-c', *args(flags), *args(value('INCPATH')),
'-I' + str(a.qt_bin.resolve().parent / 'include/QtTest'),
str(root / 'tests/tcpintegration_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')]
response = build / 'tcpintegration_objects.rsp'
response.write_text('\n'.join(objects), encoding='utf-8')
subprocess.run([compiler, '-mthreads', '-o', str(output), str(obj), '@' + str(response),
*args(value('LIBS')), str(a.qt_bin.resolve().parent / 'lib/libQt5Testd.a')],
cwd=build, env=env, check=True)
subprocess.run([str(output)], cwd=output.parent, env=env, check=True, timeout=40)