新增原生 gRPC 画面与数据接收器
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
"""Smoke check the distributed EXE using the native Windows Qt platform."""
|
||||
import os
|
||||
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
|
||||
import json
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
import grpc
|
||||
from PySide6.QtGui import QFontDatabase
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from check_window import make_jpeg
|
||||
import fusion_input_pb2 as pb
|
||||
import fusion_input_pb2_grpc as rpc
|
||||
|
||||
|
||||
def main():
|
||||
app = QApplication([])
|
||||
for font in ['msyh.ttc', 'consola.ttf']:
|
||||
QFontDatabase.addApplicationFont('C:/Windows/Fonts/'+font)
|
||||
image = make_jpeg()
|
||||
with socket.socket() as sock:
|
||||
sock.bind(('127.0.0.1', 0))
|
||||
port = sock.getsockname()[1]
|
||||
folder = ROOT/'artifacts'
|
||||
status_path = folder/'packaged-status.json'
|
||||
shot_path = folder/'packaged-native-window.png'
|
||||
child_env = os.environ.copy()
|
||||
child_env.pop('QT_QPA_PLATFORM', None)
|
||||
child_env.pop('QT_PLUGIN_PATH', None)
|
||||
child_env.pop('QT_QPA_PLATFORM_PLUGIN_PATH', None)
|
||||
command = [str(ROOT/'dist/FusionInputReceiver/FusionInputReceiver.exe'), '--port', str(port),
|
||||
'--status-file', str(status_path), '--screenshot-after', '6.5',
|
||||
'--screenshot-path', str(shot_path), '--quit-after', '8']
|
||||
process = subprocess.Popen(command, env=child_env)
|
||||
try:
|
||||
with grpc.insecure_channel(f'127.0.0.1:{port}') as channel:
|
||||
grpc.channel_ready_future(channel).result(timeout=12)
|
||||
stub = rpc.FusionInputServiceStub(channel)
|
||||
start = time.perf_counter()
|
||||
for i in range(300):
|
||||
time.sleep(max(0, start+i/60-time.perf_counter()))
|
||||
now = time.time_ns()//1000000
|
||||
meta = dict(schemaVersion=1, equipmentId='package-check', equipmentCode='独立软件验证',
|
||||
sourceEndpointId='isolated-test-source', frameId=f'{i:016x}',
|
||||
trialId='package-test', trialIds=['package-test'], sourceTime=now,
|
||||
receivedTime=now, upload=dict(frameId=f'{i:016x}', time=now, reused=False))
|
||||
data = dict(meta, kind='DATA', messageId=f'data/{i}', data={'values':{
|
||||
'sampleIndex':i, 'temperature':23.5, 'status':'模拟测试 / 非现场数据'}})
|
||||
picture = dict(meta, kind='IMAGE', messageId=f'image/{i}', imageBytes=len(image), imageContentType='image/jpeg')
|
||||
stub.Push(iter([pb.FusionInput(json=json.dumps(data,ensure_ascii=False)),
|
||||
pb.FusionInput(json=json.dumps(picture,ensure_ascii=False), image=image)]), timeout=3)
|
||||
assert process.wait(timeout=15) == 0, 'Executable exited abnormally'
|
||||
status = json.loads(status_path.read_text(encoding='utf-8'))
|
||||
assert status['data'] == status['images'] == 300, status
|
||||
assert status['displayed'] >= 200, status
|
||||
assert status['decode_errors'] == status['invalid'] == 0, status
|
||||
assert status['displayed_frame_id'] == f'{299:016x}', status
|
||||
assert status['decoded_size'][0] <= 960 and status['decoded_size'][1] <= 540, status
|
||||
assert status['display_quality'] == 'low_latency', status
|
||||
assert shot_path.is_file()
|
||||
result = dict(passed=True, executable=str(command[0]), synthetic=True,
|
||||
native_windows_platform=True, test_fps=60, test_resolution=[1920,1080], **status)
|
||||
(folder/'packaged-check-result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8')
|
||||
print(json.dumps(result,ensure_ascii=True,indent=2))
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
process.terminate()
|
||||
process.wait(timeout=5)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user