/usr/lib/2013.com.canonical.certification:checkbox/bin/graphics_driver is in plainbox-provider-checkbox 0.4-1.
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | #!/usr/bin/env python3
#========================================================================
#
# based on xlogparse
#
# DESCRIPTION
#
# Parses Xlog.*.log format files and allows looking up data from it
#
# AUTHOR
# Bryce W. Harrington <bryce@canonical.com>
#
# COPYRIGHT
# Copyright (C) 2010-2012 Bryce W. Harrington
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#========================================================================
import re
import sys
import os
from subprocess import Popen, PIPE, check_output, CalledProcessError
class XorgLog(object):
def __init__(self, logfile=None):
self.modules = []
self.errors = []
self.warnings = []
self.info = []
self.notimpl = []
self.notices = []
self.cards = []
self.displays = {}
self.xserver_version = None
self.boot_time = None
self.boot_logfile = None
self.kernel_version = None
self.video_driver = None
self.xorg_conf_path = None
self.logfile = logfile
if logfile:
self.parse(logfile)
def parse(self, filename):
self.displays = {}
display = {}
display_name = "Unknown"
in_file = open(filename, errors='ignore')
gathering_module = False
found_ddx = False
module = None
for line in in_file.readlines():
m = re.search(r'\(..\)', line)
if m:
if gathering_module and module is not None:
self.modules.append(module)
gathering_module = False
module = None
m = re.search(
'\(II\) Loading.*modules\/drivers\/(.+)_drv\.so', line)
if m:
found_ddx = True
m = re.search(r'\(II\) Module (\w+):', line)
if m:
module = {
'name': m.group(1),
'vendor': None,
'version': None,
'class': None,
'abi_name': None,
'abi_version': None,
'ddx': found_ddx,
}
found_ddx = False
gathering_module = True
if gathering_module:
m = re.search(r'vendor="(.*:?)"', line)
if m:
module['vendor'] = m.group(1)
m = re.search(r'module version = (.*)', line)
if m:
module['version'] = m.group(1)
if module['name'] == 'nvidia':
try:
version = check_output(
"nvidia-settings -v",
shell=True,
universal_newlines=True)
m = re.search(r'.*version\s+([0-9\.]+).*', version)
if m:
module['version'] = m.group(1)
except CalledProcessError:
pass
m = re.search(r'class: (.*)', line)
if m:
module['class'] = m.group(1)
m = re.search(r'ABI class:\s+(.*:?), version\s+(.*:?)', line)
if m:
if m.group(1)[:5] == "X.Org":
module['abi_name'] = m.group(1)[6:]
else:
module['abi_name'] = m.group(1)
module['abi_version'] = m.group(2)
continue
# General details
m = re.search(r'Current Operating System: (.*)$', line)
if m:
uname = m.group(1)
self.kernel_version = uname.split()[2]
continue
m = re.search(r'Kernel command line: (.*)$', line)
if m:
self.kernel_command_line = m.group(1)
continue
m = re.search(r'Build Date: (.*)$', line)
if m:
self.kernel_command_line = m.group(1)
continue
m = re.search(r'Log file: "(.*)", Time: (.*)$', line)
if m:
self.boot_logfile = m.group(1)
self.boot_time = m.group(2)
m = re.search(r'xorg-server ([^ ]+) .*$', line)
if m:
self.xserver_version = m.group(1)
continue
m = re.search(r'Using a default monitor configuration.', line)
if m and self.xorg_conf_path is None:
self.xorg_conf_path = 'default'
continue
m = re.search(r'Using config file: "(.*)"', line)
if m:
self.xorg_conf_path = m.group(1)
continue
# EDID and Modelines
# We use this part to determine which driver is in use
# For Intel / RADEON
m = re.search(r'\(II\) (.*)\(\d+\): EDID for output (.*)', line)
if m:
self.displays[display_name] = display
self.video_driver = m.group(1)
display_name = m.group(2)
display = {'Output': display_name}
continue
m = re.search(
r'\(II\) (.*)\(\d+\): Assigned Display Device: (.*)$', line)
if m:
self.displays[display_name] = display
self.video_driver = m.group(1)
display_name = m.group(2)
display = {'Output': display_name}
continue
# For NVIDIA
m = re.search(r'\(II\) (.*)\(\d+\): Setting mode "(.*?):', line)
if m:
self.displays[display_name] = display
self.video_driver = m.group(1)
display_name = m.group(2)
display = {'Output': display_name}
continue
# For 4th Intel on 3.11
m = re.search(
r'\(II\) (.*)\(\d+\): switch to mode .* using (.*),', line)
if m:
self.displays[display_name] = display
self.video_driver = m.group(1)
display_name = m.group(2)
display = {'Output': display_name}
continue
m = re.search(
r'Manufacturer: (.*) *Model: (.*) *Serial#: (.*)', line)
if m:
display['display manufacturer'] = m.group(1)
display['display model'] = m.group(2)
display['display serial no.'] = m.group(3)
m = re.search(r'EDID Version: (.*)', line)
if m:
display['display edid version'] = m.group(1)
m = re.search(r'EDID vendor \"(.*)\", prod id (.*)', line)
if m:
display['vendor'] = m.group(1)
display['product id'] = m.group(2)
m = re.search(
r'Max Image Size \[(.*)\]: *horiz.: (.*) *vert.: (.*)', line)
if m:
display['size max horizontal'] = "%s %s" % (
m.group(2), m.group(1))
display['size max vertical'] = "%s %s" % (
m.group(3), m.group(1))
m = re.search(r'Image Size: *(.*) x (.*) (.*)', line)
if m:
display['size horizontal'] = "%s %s" % (m.group(1), m.group(3))
display['size vertical'] = "%s %s" % (m.group(2), m.group(3))
m = re.search(r'(.*) is preferred mode', line)
if m:
display['mode preferred'] = m.group(1)
m = re.search(r'Modeline \"(\d+)x(\d+)\"x([0-9\.]+) *(.*)$', line)
if m:
key = "mode %sx%s@%s" % (m.group(1), m.group(2), m.group(3))
display[key] = m.group(4)
continue
# Errors and Warnings
m = re.search(r'\(WW\) (.*)$', line)
if m:
self.warnings.append(m.group(1))
continue
m = re.search(r'\(EE\) (.*)$', line)
if m:
self.errors.append(m.group(1))
continue
if display_name not in self.displays.keys():
self.displays[display_name] = display
in_file.close()
def errors_filtered(self):
excludes = set([
'error, (NI) not implemented, (??) unknown.',
'Failed to load module "fglrx" (module does not exist, 0)',
'Failed to load module "nv" (module does not exist, 0)',
])
return [err for err in self.errors if err not in excludes]
def warnings_filtered(self):
excludes = set([
'warning, (EE) error, (NI) not implemented, (??) unknown.',
'The directory "/usr/share/fonts/X11/cyrillic" does not exist.',
'The directory "/usr/share/fonts/X11/100dpi/" does not exist.',
'The directory "/usr/share/fonts/X11/75dpi/" does not exist.',
'The directory "/usr/share/fonts/X11/100dpi" does not exist.',
'The directory "/usr/share/fonts/X11/75dpi" does not exist.',
'Warning, couldn\'t open module nv',
'Warning, couldn\'t open module fglrx',
'Falling back to old probe method for vesa',
'Falling back to old probe method for fbdev',
])
return [err for err in self.warnings if err not in excludes]
def get_driver_info(xlog):
'''Return the running driver and version'''
print('-' * 13, 'VIDEO DRIVER INFORMATION', '-' * 13)
if xlog.video_driver:
for module in xlog.modules:
if module['name'] == xlog.video_driver.lower():
print("Video Driver: %s" % module['name'])
print("Driver Version: %s" % module['version'])
print('\n')
return 0
else:
print("ERROR: No video driver loaded! Possibly in failsafe mode!",
file=sys.stderr)
return 1
def is_laptop():
return os.path.isdir('/proc/acpi/button/lid')
def hybrid_graphics_check(xlog):
'''Check for Hybrid Graphics'''
card_id1 = re.compile('.*0300: *(.+):(.+) \(.+\)')
card_id2 = re.compile('.*0300: *(.+):(.+)')
cards_dict = {'8086': 'Intel', '10de': 'NVIDIA', '1002': 'AMD'}
cards = []
drivers = []
formatted_cards = []
output = Popen(['lspci', '-n'], stdout=PIPE, universal_newlines=True)
card_list = output.communicate()[0].split('\n')
# List of discovered cards
for line in card_list:
m1 = card_id1.match(line)
m2 = card_id2.match(line)
if m1:
id1 = m1.group(1).strip().lower()
id2 = m1.group(2).strip().lower()
id = id1 + ':' + id2
cards.append(id)
elif m2:
id1 = m2.group(1).strip().lower()
id2 = m2.group(2).strip().lower()
id = id1 + ':' + id2
cards.append(id)
print('-' * 13, 'HYBRID GRAPHICS CHECK', '-' * 16)
for card in cards:
formatted_name = cards_dict.get(card.split(':')[0], 'Unknown')
formatted_cards.append(formatted_name)
print('Graphics Chipset: %s (%s)' % (formatted_name, card))
for module in xlog.modules:
if module['ddx'] and module['name'] not in drivers:
drivers.append(module['name'])
print('Loaded DDX Drivers: %s' %
', '.join(drivers))
has_hybrid_graphics = (len(cards) > 1 and is_laptop()
and (cards_dict.get('8086') in formatted_cards
or cards_dict.get('1002') in formatted_cards))
print('Hybrid Graphics: %s' % (has_hybrid_graphics
and 'yes' or 'no'))
return 0
def main():
xlog = XorgLog("/var/log/Xorg.0.log")
results = []
results.append(get_driver_info(xlog))
results.append(hybrid_graphics_check(xlog))
return 1 if 1 in results else 0
if __name__ == "__main__":
sys.exit(main())
|