From 65a610c3bff143417e33429968314e641e95d516 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 3 Jul 2020 11:41:56 +0200 Subject: [PATCH] tests: Widen disable-bpf-sandbox argument This should fix tests with newer kernels/glibc's with Qt versions before 5.14.1. --- .github/workflows/ci.yml | 14 ++++---- .travis.yml | 11 ------- tests/conftest.py | 12 +++---- tests/end2end/fixtures/quteprocess.py | 9 +++--- tests/end2end/test_invocations.py | 9 +++--- tests/helpers/utils.py | 46 +++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2175840bb..e5bb9638f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,19 +74,17 @@ jobs: os: ubuntu-20.04 python: 3.6 ### PyQt 5.11 (Python 3.7) - # FIXME: seccomp-bpf failure in syscall 0230 - # - testenv: py37-pyqt511 - # os: ubuntu-20.04 - # python: 3.7 + - testenv: py37-pyqt511 + os: ubuntu-20.04 + python: 3.7 ### PyQt 5.12 (Python 3.8) - testenv: py38-pyqt512 os: ubuntu-20.04 python: 3.8 ### PyQt 5.13 (Python 3.8) - # FIXME: seccomp-bpf failure in syscall 0230 - # - testenv: py38-pyqt513 - # os: ubuntu-20.04 - # python: 3.8 + - testenv: py38-pyqt513 + os: ubuntu-20.04 + python: 3.8 ### PyQt 5.14 (Python 3.8) - testenv: py38-pyqt514 os: ubuntu-20.04 diff --git a/.travis.yml b/.travis.yml index 8eefed7ab..e485c6d63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,17 +12,6 @@ matrix: env: TESTENV=py35-pyqt57 dist: xenial - ### PyQt 5.11 (Python 3.7) - - python: 3.7 - env: TESTENV=py37-pyqt511 - - ### PyQt 5.13 (Python 3.8) - - env: TESTENV=py38-pyqt513 - addons: - apt: - packages: - - libxkbcommon-x11-0 - ### PyQt 5.15 (Python 3.8, with coverage) - env: TESTENV=py38-pyqt515-cov addons: diff --git a/tests/conftest.py b/tests/conftest.py index cd0e9ce2d..32a3144c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,7 +28,7 @@ import pathlib import pytest import hypothesis -from PyQt5.QtCore import qVersion, PYQT_VERSION +from PyQt5.QtCore import PYQT_VERSION pytest.register_assert_rewrite('helpers') @@ -197,12 +197,10 @@ def pytest_ignore_collect(path): @pytest.fixture(scope='session') def qapp_args(): - """Make QtWebEngine unit tests run on Qt 5.7.1. - - See https://github.com/qutebrowser/qutebrowser/issues/3163 - """ - if qVersion() == '5.7.1': - return [sys.argv[0], '--disable-seccomp-filter-sandbox'] + """Make QtWebEngine unit tests run on older Qt versions + newer kernels.""" + seccomp_args = testutils.seccomp_args(qt_flag=False) + if seccomp_args: + return [sys.argv[0]] + seccomp_args return [] diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 4ff9dc21d..edaeb2ccc 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -33,7 +33,7 @@ import json import yaml import pytest -from PyQt5.QtCore import pyqtSignal, QUrl, qVersion +from PyQt5.QtCore import pyqtSignal, QUrl from qutebrowser.misc import ipc from qutebrowser.utils import log, utils, javascript, qtutils @@ -544,9 +544,10 @@ class QuteProc(testprocess.Process): '--json-logging', '--loglevel', 'vdebug', '--backend', backend, '--debug-flag', 'no-sql-history', '--debug-flag', 'werror'] - if qVersion() == '5.7.1': - # https://github.com/qutebrowser/qutebrowser/issues/3163 - args += ['--qt-flag', 'disable-seccomp-filter-sandbox'] + + if self.request.config.webengine: + args += testutils.seccomp_args(qt_flag=True) + args.append('about:blank') return args diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 375ced814..92dec6311 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -26,7 +26,7 @@ import logging import re import pytest -from PyQt5.QtCore import QProcess, qVersion +from PyQt5.QtCore import QProcess from helpers import utils @@ -43,9 +43,10 @@ def _base_args(config): args += ['--backend', 'webengine'] else: args += ['--backend', 'webkit'] - if qVersion() == '5.7.1': - # https://github.com/qutebrowser/qutebrowser/issues/3163 - args += ['--qt-flag', 'disable-seccomp-filter-sandbox'] + + if config.webengine: + args += utils.seccomp_args(qt_flag=True) + args.append('about:blank') return args diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 70a10436c..2022985d2 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -29,6 +29,12 @@ import pathlib import pytest +from PyQt5.QtCore import qVersion +try: + from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION_STR +except ImportError: + PYQT_WEBENGINE_VERSION_STR = None + from qutebrowser.utils import qtutils, log ON_CI = 'CI' in os.environ @@ -211,3 +217,43 @@ def ignore_bs4_warning(): def blocked_hosts(): path = os.path.join(abs_datapath(), 'blocked-hosts.gz') yield from io.TextIOWrapper(gzip.open(path), encoding='utf-8') + + +def seccomp_args(qt_flag): + """Get necessary flags to disable the seccomp BPF sandbox. + + This is needed for some QtWebEngine setups, with older Qt versions but + newer kernels. + + Args: + qt_flag: Add a '--qt-flag' argument. + """ + affected_versions = set() + for base, patch_range in [ + ## seccomp-bpf failure in syscall 0281 + ## https://github.com/qutebrowser/qutebrowser/issues/3163 + # 5.7.1 + ('5.7', [1]), + + ## seccomp-bpf failure in syscall 0281 (clock_nanosleep) + ## https://bugreports.qt.io/browse/QTBUG-81313 + # 5.11.0 to 5.11.3 (inclusive) + ('5.11', range(0, 4)), + # 5.12.0 to 5.12.7 (inclusive) + ('5.12', range(0, 8)), + # 5.13.0 to 5.13.2 (inclusive) + ('5.13', range(0, 3)), + # 5.14.0 + ('5.14', [0]), + ]: + for patch in patch_range: + affected_versions.add('{}.{}'.format(base, patch)) + + version = (PYQT_WEBENGINE_VERSION_STR + if PYQT_WEBENGINE_VERSION_STR is not None + else qVersion()) + if version in affected_versions: + disable_arg = 'disable-seccomp-filter-sandbox' + return ['--qt-flag', disable_arg] if qt_flag else ['--' + disable_arg] + + return []