~ubuntu-branches/ubuntu/trusty/plainbox-provider-checkbox/trusty

« back to all changes in this revision

Viewing changes to provider_bin/gpu_test

  • Committer: Package Import Robot
  • Author(s): Zygmunt Krynicki
  • Date: 2014-04-07 19:00:31 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140407190031-rf836grml6oilfyt
Tags: 0.4-1
* New upstream release. List of bugfixes:
  https://launchpad.net/plainbox-provider-checkbox/14.04/0.4
* debian/watch: look for new releases on launchpad
* debian/rules: stop using pybuild and use manage.py
  {i18n,build,install,validate} instead. This also drops dependency on
  python3-distutils-extra and replaces that with intltool
* debian/control: drop X-Python3-Version
* debian/control: make plainbox-provider-checkbox depend on python and
  python2.7 (for some scripts) rather than suggesting them.
* debian/upstream/signing-key.asc: Use armoured gpg keys to avoid having to
  keep binary files in Debian packaging. Also, replace that with my key
  since I made the 0.3 release upstream.
* debian/source/lintian-overrides: add an override for warning about no
  source for flash movie with reference to a bug report that discusses that
  issue.
* debian/source/include-binaries: drop (no longer needed)
* debian/patches: drop (no longer needed)
* debian/plainbox-provider-checkbox.lintian-overrides: drop (no longer
  needed)
* Stop being a python3 module, move to from DPMT to PAPT

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
# Copyright 2013 Canonical Ltd.
3
 
# Written by:
4
 
#   Sylvain Pineau <sylvain.pineau@canonical.com>
5
 
#
6
 
# This program is free software: you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License version 3,
8
 
# as published by the Free Software Foundation.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
"""
19
 
Script checking gpu lockups.
20
 
 
21
 
Several threads are started to exercise the GPU in ways that can cause gpu
22
 
lockups.
23
 
Inspired by the workload directory of the xdiagnose package.
24
 
"""
25
 
 
26
 
import os
27
 
import re
28
 
import subprocess
29
 
import sys
30
 
import time
31
 
from gi.repository import Gio
32
 
from math import cos, sin
33
 
from threading import Thread
34
 
 
35
 
 
36
 
class GlxThread(Thread):
37
 
    """
38
 
    Start a thread running glxgears
39
 
    """
40
 
 
41
 
    def run(self):
42
 
 
43
 
        try:
44
 
            self.process = subprocess.Popen(
45
 
                ["glxgears","-geometry", "400x400"],
46
 
                stdout=subprocess.PIPE,
47
 
                stderr=subprocess.STDOUT)
48
 
            self.process.communicate()
49
 
        except (subprocess.CalledProcessError, FileNotFoundError) as er:
50
 
            print("WARNING: Unable to start glxgears (%s)" % er)
51
 
 
52
 
 
53
 
    def terminate(self):
54
 
        if not hasattr(self, 'id'):
55
 
            print("WARNING: Attempted to terminate non-existing window.")
56
 
        if hasattr(self, 'process'):
57
 
            self.process.terminate()
58
 
 
59
 
 
60
 
class RotateGlxThread(Thread):
61
 
    """
62
 
    Start a thread performing glxgears windows rotations
63
 
    """
64
 
 
65
 
    def __init__(self, id, offset):
66
 
        Thread.__init__(self)
67
 
        self.id = id
68
 
        self.offset = offset
69
 
        self.cancel = False
70
 
 
71
 
    def run(self):
72
 
        while(1):
73
 
            for j in range(60):
74
 
                x = int(200 * self.offset + 100 * sin(j * 0.2))
75
 
                y = int(200 * self.offset + 100 * cos(j * 0.2))
76
 
                coords = "%s,%s" % (x, y)
77
 
                subprocess.call(
78
 
                    'wmctrl -i -r %s -e 0,%s,-1,-1' % (self.id, coords),
79
 
                    shell=True
80
 
                )
81
 
                time.sleep(0.002 * self.offset)
82
 
                if self.cancel:
83
 
                    return
84
 
 
85
 
 
86
 
class ChangeWorkspace(Thread):
87
 
    """
88
 
    Start a thread performing fast workspace switches
89
 
    """
90
 
 
91
 
    def __init__(self, hsize, vsize, xsize, ysize):
92
 
        Thread.__init__(self)
93
 
        self.hsize = hsize
94
 
        self.vsize = vsize
95
 
        self.xsize = xsize
96
 
        self.ysize = ysize
97
 
        self.cancel = False
98
 
 
99
 
    def run(self):
100
 
        while(1):
101
 
            for i in range(self.hsize):
102
 
                for j in range(self.vsize):
103
 
                    subprocess.call(
104
 
                        'wmctrl -o %s,%s' % (self.xsize * j, self.ysize * i),
105
 
                        shell=True)
106
 
                    time.sleep(0.5)
107
 
                    if self.cancel:
108
 
                        # Switch back to workspace #1
109
 
                        subprocess.call('wmctrl -o 0,0', shell=True)
110
 
                        return
111
 
 
112
 
 
113
 
class Html5VideoThread(Thread):
114
 
    """
115
 
    Start a thread performing playback of an HTML5 video in firefox
116
 
    """
117
 
 
118
 
    @property
119
 
    def html5_path(self):
120
 
        if os.getenv('CHECKBOX_SHARE'):
121
 
            return os.path.join(
122
 
            os.getenv('CHECKBOX_SHARE'),
123
 
            'data/websites/html5_video.html')
124
 
 
125
 
    def run(self):
126
 
        if self.html5_path and os.path.isfile(self.html5_path):
127
 
            subprocess.call(
128
 
                'firefox %s' % self.html5_path,
129
 
                stdout=open(os.devnull, 'w'),
130
 
                stderr=subprocess.STDOUT,
131
 
                shell=True)
132
 
        else:
133
 
            print("WARNING: unable to start html5 video playback.")
134
 
            print("WARNING: test results may be invalid.")
135
 
 
136
 
    def terminate(self):
137
 
            if self.html5_path and os.path.isfile(self.html5_path):
138
 
                subprocess.call("pkill firefox", shell=True)
139
 
 
140
 
 
141
 
def check_gpu(log=None):
142
 
    if not log:
143
 
        log = '/var/log/kern.log'
144
 
    with open(log, 'rb') as f:
145
 
        if re.findall(r'gpu\s+hung', str(f.read()), flags=re.I):
146
 
            print("GPU hung Detected")
147
 
            return 1
148
 
 
149
 
 
150
 
def main():
151
 
    if check_gpu():
152
 
        return 1
153
 
    GlxWindows = []
154
 
    GlxRotate = []
155
 
    subprocess.call("pkill 'glxgears|firefox'", shell=True)
156
 
 
157
 
    Html5Video = Html5VideoThread()
158
 
    Html5Video.start()
159
 
 
160
 
    source = Gio.SettingsSchemaSource.get_default()
161
 
 
162
 
    for i in range(2):
163
 
        GlxWindows.append(GlxThread())
164
 
        GlxWindows[i].start()
165
 
        time.sleep(5)
166
 
        try:
167
 
            windows = subprocess.check_output(
168
 
                        'wmctrl -l | grep glxgears',
169
 
                        shell=True)
170
 
        except subprocess.CalledProcessError as er:
171
 
            print("WARNING: Got an exception %s" % er)
172
 
            windows = ""
173
 
        for app in sorted(windows.splitlines(), reverse=True):
174
 
            if not b'glxgears' in app:
175
 
                continue
176
 
            GlxWindows[i].id = str(
177
 
                re.match(b'^(0x\w+)', app).group(0), 'utf-8')
178
 
            break
179
 
        if hasattr(GlxWindows[i], "id"):
180
 
            rotator = RotateGlxThread(GlxWindows[i].id, i + 1)
181
 
            GlxRotate.append(rotator)
182
 
            rotator.start()
183
 
        else:
184
 
            print("WARNING: Window {} not found, not rotating it.".format(i))
185
 
 
186
 
    hsize = vsize = 2
187
 
    hsize_ori = vsize_ori = None
188
 
    if source.lookup("org.compiz.core", True):
189
 
        settings = Gio.Settings(
190
 
            "org.compiz.core",
191
 
            "/org/compiz/profiles/unity/plugins/core/"
192
 
        )
193
 
        hsize_ori = settings.get_int("hsize")
194
 
        vsize_ori = settings.get_int("vsize")
195
 
        settings.set_int("hsize", hsize)
196
 
        settings.set_int("vsize", vsize)
197
 
        time.sleep(5)
198
 
    else:
199
 
        hsize = int(subprocess.check_output(
200
 
            'gconftool --get /apps/compiz-1/general/screen0/options/hsize',
201
 
            shell=True))
202
 
        vsize = int(subprocess.check_output(
203
 
            'gconftool --get /apps/compiz-1/general/screen0/options/vsize',
204
 
            shell=True))
205
 
    (x_res, y_res) = re.search(
206
 
        b'DG:\s+(\d+)x(\d+)',
207
 
        subprocess.check_output('wmctrl -d', shell=True)).groups()
208
 
    DesktopSwitch = ChangeWorkspace(
209
 
        hsize, vsize, int(x_res) // hsize, int(y_res) // vsize)
210
 
    DesktopSwitch.start()
211
 
 
212
 
    time.sleep(35)
213
 
 
214
 
    for i in range(len(GlxRotate)):
215
 
        GlxRotate[i].cancel = True
216
 
    for i in range(len(GlxWindows)):
217
 
        GlxWindows[i].terminate()
218
 
    DesktopSwitch.cancel = True
219
 
    time.sleep(10)
220
 
    Html5Video.terminate()
221
 
    if check_gpu() or not Html5Video.html5_path:
222
 
        return 1
223
 
 
224
 
    if source.lookup("org.compiz.core", True):
225
 
        settings = Gio.Settings(
226
 
            "org.compiz.core",
227
 
            "/org/compiz/profiles/unity/plugins/core/")
228
 
        settings.set_int("hsize", hsize_ori)
229
 
        settings.set_int("vsize", vsize_ori)
230
 
        Gio.Settings.sync()
231
 
 
232
 
if __name__ == '__main__':
233
 
    sys.exit(main())