From e5e9955cd9429a5e9d4e116752f48a5f1687f90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0urda?= Date: Tue, 9 Aug 2022 15:17:48 +0800 Subject: [PATCH] Record telenium/kivy video - add a ffmpeg process to kivy tests if it detects running inside docker - this approach can be reused for other tests that may benefit from a video - it may be possible to do this in bash, outside of python, but that would exacerbate the process synchronisation issues, as outlined here: - X server must be running before ffmpeg starts, otherwise ffmpeg can't record and quits - ffmpeg must end before the X server ends, as otherwise it segfaults and video will be incomplete - ffmpeg must start before the actual tests start and stop after the tests stop, otherwise a part of the tests will be missing from the recording - this approach I chose here avoids most synchronisation issues. If ffmpeg takes more than 2 seconds to start recording (unlikely), a part of the video will be missing. Also if for some reason ffmpeg is too slow, then also we may end up with a truncated video, at the end. - I chose lossless vp9 codec with webm format, this appears to work on firefox and chrome. Safari refuses to show the video even though it should be supported. --- .buildbot/kivy/Dockerfile | 2 +- tests-kivy.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.buildbot/kivy/Dockerfile b/.buildbot/kivy/Dockerfile index 58c2be08..94c0545f 100644 --- a/.buildbot/kivy/Dockerfile +++ b/.buildbot/kivy/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get install -yq \ build-essential libcap-dev libssl-dev \ libmtdev-dev libpq-dev \ python3-dev python3-pip python3-virtualenv \ - xvfb + xvfb ffmpeg RUN ln -sf /usr/bin/python3 /usr/bin/python diff --git a/tests-kivy.py b/tests-kivy.py index 92b10b86..a2d2130d 100644 --- a/tests-kivy.py +++ b/tests-kivy.py @@ -4,6 +4,10 @@ import random # noseq import sys import unittest +from os import environ, mkdir +from subprocess import Popen, TimeoutExpired +from time import sleep + def unittest_discover(): """Explicit test suite creation""" @@ -13,5 +17,27 @@ def unittest_discover(): if __name__ == "__main__": + with open("/proc/self/cgroup", "rt", encoding='ascii', errors='replace') as f: + in_docker = "docker" in f.read() + + if in_docker: + try: + mkdir("../out") + except FileExistsError: # flake8: noqa:F821 + pass + + ffmpeg = Popen([ # pylint: disable=consider-using-with + "ffmpeg", "-y", "-nostdin", "-f", "x11grab", "-video_size", "vga", + "-draw_mouse", "0", "-i", environ['DISPLAY'], + "-codec:v", "libvpx-vp9", "-lossless", "1", "-r", "30", + "../out/test.webm" + ]) + sleep(2) # let ffmpeg start result = unittest.TextTestRunner(verbosity=2).run(unittest_discover()) + if in_docker: + ffmpeg.terminate() + try: + ffmpeg.wait(10) + except TimeoutExpired: + ffmpeg.kill() sys.exit(not result.wasSuccessful())