This file is indexed.

/usr/lib/plainbox-providers-1/checkbox/bin/gpu_test is in plainbox-provider-checkbox 0.3-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/python3
# Copyright 2013 Canonical Ltd.
# Written by:
#   Sylvain Pineau <sylvain.pineau@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Script checking gpu lockups.

Several threads are started to exercise the GPU in ways that can cause gpu
lockups.
Inspired by the workload directory of the xdiagnose package.
"""

import os
import re
import subprocess
import sys
import time
from gi.repository import Gio
from math import cos, sin
from threading import Thread


class GlxThread(Thread):
    """
    Start a thread running glxgears
    """

    def run(self):

        try:
            self.process = subprocess.Popen(
                ["glxgears","-geometry", "400x400"],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT)
            self.process.communicate()
        except (subprocess.CalledProcessError, FileNotFoundError) as er:
            print("WARNING: Unable to start glxgears (%s)" % er)


    def terminate(self):
        if not hasattr(self, 'id'):
            print("WARNING: Attempted to terminate non-existing window.")
        if hasattr(self, 'process'):
            self.process.terminate()


class RotateGlxThread(Thread):
    """
    Start a thread performing glxgears windows rotations
    """

    def __init__(self, id, offset):
        Thread.__init__(self)
        self.id = id
        self.offset = offset
        self.cancel = False

    def run(self):
        while(1):
            for j in range(60):
                x = int(200 * self.offset + 100 * sin(j * 0.2))
                y = int(200 * self.offset + 100 * cos(j * 0.2))
                coords = "%s,%s" % (x, y)
                subprocess.call(
                    'wmctrl -i -r %s -e 0,%s,-1,-1' % (self.id, coords),
                    shell=True
                )
                time.sleep(0.002 * self.offset)
                if self.cancel:
                    return


class ChangeWorkspace(Thread):
    """
    Start a thread performing fast workspace switches
    """

    def __init__(self, hsize, vsize, xsize, ysize):
        Thread.__init__(self)
        self.hsize = hsize
        self.vsize = vsize
        self.xsize = xsize
        self.ysize = ysize
        self.cancel = False

    def run(self):
        while(1):
            for i in range(self.hsize):
                for j in range(self.vsize):
                    subprocess.call(
                        'wmctrl -o %s,%s' % (self.xsize * j, self.ysize * i),
                        shell=True)
                    time.sleep(0.5)
                    if self.cancel:
                        # Switch back to workspace #1
                        subprocess.call('wmctrl -o 0,0', shell=True)
                        return


class Html5VideoThread(Thread):
    """
    Start a thread performing playback of an HTML5 video in firefox
    """

    @property
    def html5_path(self):
        if os.getenv('CHECKBOX_SHARE'):
            return os.path.join(
            os.getenv('CHECKBOX_SHARE'),
            'data/websites/html5_video.html')

    def run(self):
        if self.html5_path and os.path.isfile(self.html5_path):
            subprocess.call(
                'firefox %s' % self.html5_path,
                stdout=open(os.devnull, 'w'),
                stderr=subprocess.STDOUT,
                shell=True)
        else:
            print("WARNING: unable to start html5 video playback.")
            print("WARNING: test results may be invalid.")

    def terminate(self):
            if self.html5_path and os.path.isfile(self.html5_path):
                subprocess.call("pkill firefox", shell=True)


def check_gpu(log=None):
    if not log:
        log = '/var/log/kern.log'
    with open(log, 'rb') as f:
        if re.findall(r'gpu\s+hung', str(f.read()), flags=re.I):
            print("GPU hung Detected")
            return 1


def main():
    if check_gpu():
        return 1
    GlxWindows = []
    GlxRotate = []
    subprocess.call("pkill 'glxgears|firefox'", shell=True)

    Html5Video = Html5VideoThread()
    Html5Video.start()

    source = Gio.SettingsSchemaSource.get_default()

    for i in range(2):
        GlxWindows.append(GlxThread())
        GlxWindows[i].start()
        time.sleep(5)
        try:
            windows = subprocess.check_output(
                        'wmctrl -l | grep glxgears',
                        shell=True)
        except subprocess.CalledProcessError as er:
            print("WARNING: Got an exception %s" % er)
            windows = ""
        for app in sorted(windows.splitlines(), reverse=True):
            if not b'glxgears' in app:
                continue
            GlxWindows[i].id = str(
                re.match(b'^(0x\w+)', app).group(0), 'utf-8')
            break
        if hasattr(GlxWindows[i], "id"):
            rotator = RotateGlxThread(GlxWindows[i].id, i + 1)
            GlxRotate.append(rotator)
            rotator.start()
        else:
            print("WARNING: Window {} not found, not rotating it.".format(i))

    hsize = vsize = 2
    hsize_ori = vsize_ori = None
    if source.lookup("org.compiz.core", True):
        settings = Gio.Settings(
            "org.compiz.core",
            "/org/compiz/profiles/unity/plugins/core/"
        )
        hsize_ori = settings.get_int("hsize")
        vsize_ori = settings.get_int("vsize")
        settings.set_int("hsize", hsize)
        settings.set_int("vsize", vsize)
        time.sleep(5)
    else:
        hsize = int(subprocess.check_output(
            'gconftool --get /apps/compiz-1/general/screen0/options/hsize',
            shell=True))
        vsize = int(subprocess.check_output(
            'gconftool --get /apps/compiz-1/general/screen0/options/vsize',
            shell=True))
    (x_res, y_res) = re.search(
        b'DG:\s+(\d+)x(\d+)',
        subprocess.check_output('wmctrl -d', shell=True)).groups()
    DesktopSwitch = ChangeWorkspace(
        hsize, vsize, int(x_res) // hsize, int(y_res) // vsize)
    DesktopSwitch.start()

    time.sleep(35)

    for i in range(len(GlxRotate)):
        GlxRotate[i].cancel = True
    for i in range(len(GlxWindows)):
        GlxWindows[i].terminate()
    DesktopSwitch.cancel = True
    time.sleep(10)
    Html5Video.terminate()
    if check_gpu() or not Html5Video.html5_path:
        return 1

    if source.lookup("org.compiz.core", True):
        settings = Gio.Settings(
            "org.compiz.core",
            "/org/compiz/profiles/unity/plugins/core/")
        settings.set_int("hsize", hsize_ori)
        settings.set_int("vsize", vsize_ori)
        Gio.Settings.sync()

if __name__ == '__main__':
    sys.exit(main())