summaryrefslogtreecommitdiff
path: root/scripts/dev/segfault_test.py
blob: aaf495fc1642b0aa75b86d4fc6256fb0fc4ebd7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:

# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.

"""Tester for Qt segfaults with different harfbuzz engines."""

import os
import os.path
import signal
import sys
import subprocess

sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
                                os.pardir))

from scripts import utils


SCRIPT = """
import sys

from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebView

def on_load_finished(ok):
    if ok:
        app.exit(0)
    else:
        app.exit(1)

app = QApplication([])
wv = QWebView()
wv.loadFinished.connect(on_load_finished)
wv.load(QUrl(sys.argv[1]))
#wv.show()
app.exec_()
"""


def print_ret(ret):
    """Print information about an exit status."""
    if ret == 0:
        utils.print_col("success", 'green')
    elif ret == -signal.SIGSEGV:
        utils.print_col("segfault", 'red')
    else:
        utils.print_col("error {}".format(ret), 'yellow')
    print()


def main():
    retvals = []
    if len(sys.argv) < 2:
        # pages which previously caused problems
        pages = [
            # ANGLE, https://bugreports.qt.io/browse/QTBUG-39723
            ('http://www.binpress.com/', False),
            ('http://david.li/flow/', False),
            ('https://imzdl.com/', False),
            # not reproducible
            # https://bugreports.qt.io/browse/QTBUG-39847
            ('http://www.20min.ch/', True),
            # HarfBuzz, https://bugreports.qt.io/browse/QTBUG-39278
            ('http://www.the-compiler.org/', True),
            ('http://phoronix.com', True),
            ('http://twitter.com', True),
            # HarfBuzz #2, https://bugreports.qt.io/browse/QTBUG-36099
            ('http://lenta.ru/', True),
            # Unknown, https://bugreports.qt.io/browse/QTBUG-41360
            ('http://salt.readthedocs.org/en/latest/topics/pillar/', True),
        ]
    else:
        pages = [(e, True) for e in sys.argv[1:]]
    for page, test_harfbuzz in pages:
        utils.print_bold("==== {} ====".format(page))
        if test_harfbuzz:
            print("With system harfbuzz:")
        ret = subprocess.run([sys.executable, '-c', SCRIPT, page]).returncode
        print_ret(ret)
        retvals.append(ret)
        if test_harfbuzz:
            print("With QT_HARFBUZZ=old:")
            env = dict(os.environ)
            env['QT_HARFBUZZ'] = 'old'
            ret = subprocess.run([sys.executable, '-c', SCRIPT, page],
                                 env=env).returncode
            print_ret(ret)
            retvals.append(ret)
            print("With QT_HARFBUZZ=new:")
            env = dict(os.environ)
            env['QT_HARFBUZZ'] = 'new'
            ret = subprocess.run([sys.executable, '-c', SCRIPT, page],
                                 env=env).returncode
            print_ret(ret)
            retvals.append(ret)
    if all(r == 0 for r in retvals):
        sys.exit(0)
    else:
        sys.exit(1)


if __name__ == '__main__':
    main()