ubuntu-drivers-common-0.2.91.4/0000775000000000000000000000000012322472605013124 5ustar ubuntu-drivers-common-0.2.91.4/ubuntu-drivers0000775000000000000000000001223512322472605016053 0ustar #!/usr/bin/python3 '''Driver package query/installation tool for Ubuntu''' # (C) 2012 Canonical Ltd. # Author: Martin Pitt # # This program 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 2 of the License, or # (at your option) any later version. import argparse import subprocess import sys import os import logging import apt import UbuntuDrivers.detect def parse_args(): '''Parse command line arguments.''' # build help for commands commands = [] command_help = 'Available commands:' for c in globals(): if c.startswith('command_'): name = c.split('_', 1)[1] commands.append(name) command_help += '\n %s: %s' % (name, globals()[c].__doc__) parser = argparse.ArgumentParser(description='List/install driver packages for Ubuntu.', epilog=command_help, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('command', metavar='', choices=commands, help='See below') parser.add_argument('--package-list', metavar='PATH', help='Create file with list of installed packages (in autoinstall mode)') return parser.parse_args() def command_list(args): '''Show all driver packages which apply to the current system.''' packages = UbuntuDrivers.detect.system_driver_packages() print('\n'.join(packages)) return 0 def command_devices(args): '''Show all devices which need drivers, and which packages apply to them.''' drivers = UbuntuDrivers.detect.system_device_drivers() for device, info in drivers.items(): print('== %s ==' % device) for k, v in info.items(): if k == 'drivers': continue print('%-9s: %s' % (k, v)) for pkg, pkginfo in info['drivers'].items(): info_str = '' if pkginfo['from_distro']: info_str += ' distro' else: info_str += ' third-party' if pkginfo['free']: info_str += ' free' else: info_str += ' non-free' if pkginfo.get('builtin'): info_str += ' builtin' if pkginfo.get('recommended'): info_str += ' recommended' print('%-9s: %s -%s' % ('driver', pkg, info_str)) print('') def command_autoinstall(args): '''Install drivers that are appropriate for automatic installation.''' cache = apt.Cache() packages = UbuntuDrivers.detect.system_driver_packages(cache) packages = UbuntuDrivers.detect.auto_install_filter(packages) if not packages: print('No drivers found for automatic installation.') return # ignore packages which are already installed to_install = [] for p in packages: if not cache[p].installed: to_install.append(p) if not packages: print('All drivers for automatic installation are already installed.') return ret = subprocess.call(['apt-get', 'install', '-o', 'DPkg::options::=--force-confnew', '-y'] + to_install) # create package list if ret == 0 and args.package_list: with open(args.package_list, 'a') as f: f.write('\n'.join(to_install)) f.write('\n') return ret def command_debug(args): '''Print all available information and debug data about drivers.''' logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) print('=== log messages from detection ===') aliases = UbuntuDrivers.detect.system_modaliases() cache = apt.Cache() packages = UbuntuDrivers.detect.system_driver_packages(cache) auto_packages = UbuntuDrivers.detect.auto_install_filter(packages) print('=== modaliases in the system ===') for alias in aliases: print(alias) print('=== matching driver packages ===') for package, info in packages.items(): p = cache[package] try: inst = p.installed.version except AttributeError: inst = '' try: cand = p.candidate.version except AttributeError: cand = '' if package in auto_packages: auto = ' (auto-install)' else: auto = '' info_str = '' if info['from_distro']: info_str += ' [distro]' else: info_str += ' [third party]' if info['free']: info_str += ' free' else: info_str += ' non-free' if 'modalias' in info: info_str += ' modalias: ' + info['modalias'] if 'syspath' in info: info_str += ' path: ' + info['syspath'] if 'vendor' in info: info_str += ' vendor: ' + info['vendor'] if 'model' in info: info_str += ' model: ' + info['model'] print('%s: installed: %s available: %s%s%s ' % (package, inst, cand, auto, info_str)) # # main # args = parse_args() # run the function corresponding to the specified command command = globals()['command_' + args.command] sys.exit(command(args)) ubuntu-drivers-common-0.2.91.4/ubiquity/0000775000000000000000000000000012322472605014777 5ustar ubuntu-drivers-common-0.2.91.4/ubiquity/target-config/0000775000000000000000000000000012322472605017530 5ustar ubuntu-drivers-common-0.2.91.4/ubiquity/target-config/31ubuntu_driver_packages0000775000000000000000000000045612322472605024362 0ustar #!/bin/sh set -e # install all packages that "ubuntu-drivers autoinstall" installed into the # live system. Ubiquity calls this with --package-list /run/ubuntu-drivers.autoinstall PKGLIST=/run/ubuntu-drivers.autoinstall [ -e $PKGLIST ] || exit 0 for p in `cat $PKGLIST`; do apt-install $p done ubuntu-drivers-common-0.2.91.4/tests/0000775000000000000000000000000012322472605014266 5ustar ubuntu-drivers-common-0.2.91.4/tests/xorg.conf0000664000000000000000000000007112322472605016112 0ustar Section "Device" Identifier "Test Device" EndSection ubuntu-drivers-common-0.2.91.4/tests/ubuntu_drivers.py0000664000000000000000000022532412322472605017730 0ustar # (C) 2012 Canonical Ltd. # Author: Martin Pitt # # This program 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 2 of the License, or # (at your option) any later version. import os import time import unittest import subprocess import resource import sys import tempfile import shutil import logging from gi.repository import GLib from gi.repository import PackageKitGlib from gi.repository import UMockdev import apt import aptdaemon.test import aptdaemon.pkcompat import UbuntuDrivers.detect import UbuntuDrivers.PackageKit import UbuntuDrivers.kerneldetection import testarchive TEST_DIR = os.path.abspath(os.path.dirname(__file__)) ROOT_DIR = os.path.dirname(TEST_DIR) # show aptdaemon log in test output? APTDAEMON_LOG = False # show aptdaemon debug level messages? APTDAEMON_DEBUG = False dbus_address = None # modalias of an nvidia card covered by our nvidia-* packages modalias_nv = 'pci:v000010DEd000010C3sv00003842sd00002670bc03sc03i00' def gen_fakehw(): '''Generate an UMockdev.Testbed object for testing''' t = UMockdev.Testbed.new() # covered by vanilla.deb t.add_device('pci', 'white', None, ['modalias', 'pci:v00001234d00sv00000001sd00bc00sc00i00'], []) # covered by chocolate.deb t.add_device('usb', 'black', None, ['modalias', 'usb:v9876dABCDsv01sd02bc00sc01i05'], []) # covered by nvidia-*.deb t.add_device('pci', 'graphics', None, ['modalias', modalias_nv], []) # not covered by any driver package t.add_device('pci', 'grey', None, ['modalias', 'pci:vDEADBEEFd00'], []) t.add_device('ssb', 'yellow', None, [], ['MODALIAS', 'pci:vDEADBEEFd00']) return t def gen_fakearchive(): '''Generate a fake archive for testing''' a = testarchive.Archive() a.create_deb('vanilla', extra_tags={'Modaliases': 'vanilla(pci:v00001234d*sv*sd*bc*sc*i*, pci:v0000BEEFd*sv*sd*bc*sc*i*)'}) a.create_deb('chocolate', dependencies={'Depends': 'xserver-xorg-core'}, extra_tags={'Modaliases': 'chocolate(usb:v9876dABCDsv*sd*bc00sc*i*, pci:v0000BEEFd*sv*sd*bc*sc*i00)'}) # packages for testing X.org driver ABI installability a.create_deb('xserver-xorg-core', version='99:1', # higher than system installed one dependencies={'Provides': 'xorg-video-abi-4'}) a.create_deb('nvidia-current', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*, pci:v000010DEd000010C4sv*sd*bc03sc*i*,)'}) a.create_deb('nvidia-old', dependencies={'Depends': 'xorg-video-abi-3'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*, pci:v000010DEd000010C2sv*sd*bc03sc*i*,)'}) # packages not covered by modalises, for testing detection plugins a.create_deb('special') a.create_deb('picky') a.create_deb('special-uninst', dependencies={'Depends': 'xorg-video-abi-3'}) return a class PackageKitTest(aptdaemon.test.AptDaemonTestCase): '''Test the PackageKit plugin and API''' @classmethod def setUpClass(klass): klass.umockdev = gen_fakehw() # find plugin in our source tree os.environ['PYTHONPATH'] = '%s:%s' % (os.getcwd(), os.environ.get('PYTHONPATH', '')) # start a local fake system D-BUS klass.dbus = subprocess.Popen(['dbus-daemon', '--nofork', '--print-address', '--config-file', os.path.join(aptdaemon.test.get_tests_dir(), 'dbus.conf')], stdout=subprocess.PIPE, universal_newlines=True) klass.dbus_address = klass.dbus.stdout.readline().strip() os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = klass.dbus_address klass.archive = gen_fakearchive() # set up a test chroot klass.chroot = aptdaemon.test.Chroot() klass.chroot.setup() klass.chroot.add_test_repository() klass.chroot.add_repository(klass.archive.path, True, False) # initialize apt to the chroot, so that functions which instantiate an # apt.Cache() object get the chroot instead of the system apt.Cache(rootdir=klass.chroot.path) # no custom detection plugins by default klass.plugin_dir = os.path.join(klass.chroot.path, 'detect') os.environ['UBUNTU_DRIVERS_DETECT_DIR'] = klass.plugin_dir # start aptdaemon on fake system D-BUS; this works better than # self.start_session_aptd() as the latter starts/stops aptadaemon on # each test case, which currently fails with the PK compat layer if APTDAEMON_LOG: out = None else: out = subprocess.PIPE argv = ['aptd', '--disable-plugins', '--chroot', klass.chroot.path] if APTDAEMON_DEBUG: argv.insert(1, '--debug') klass.aptdaemon = subprocess.Popen(argv, stderr=out, universal_newlines=True) time.sleep(0.5) @classmethod def tearDownClass(klass): klass.aptdaemon.terminate() klass.aptdaemon.wait() klass.dbus.terminate() klass.dbus.wait() klass.chroot.remove() def setUp(self): self.start_fake_polkitd() time.sleep(0.5) self.pk = PackageKitGlib.Client() def test_modalias(self): '''what-provides MODALIAS''' # type ANY self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.ANY, ['pci:v00001234d00000001sv00sd01bc02sc03i04']), ['vanilla']) # type MODALIAS self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['pci:v00001234d00000001sv00sd01bc02sc03i04']), ['vanilla']) self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['usb:v9876dABCDsv00sd00bc00sc01i01']), ['chocolate']) # chocolate does not match interface type != 00, just vanilla does self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['pci:v0000BEEFd0sv00sd00bc00sc00i01']), ['vanilla']) # no such device self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['fake:DEADBEEF']), []) def test_modalias_multi(self): '''multiple MODALIAS queries in one what-provides call''' res = self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['pci:v00001234d00000001sv00sd01bc02sc03i04', 'usb:v9876dABCDsv00sd00bc00sc01i01']) self.assertEqual(res, ['chocolate', 'vanilla']) self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['pci:v00001234d00000001sv00sd01bc02sc03i04', 'usb:v9876d0000sv00sd00bc00sc01i01']), ['vanilla']) def test_othertype(self): '''does not break query for a different type''' try: self._call(PackageKitGlib.ProvidesEnum.LANGUAGE_SUPPORT, ['language(de)']) except GLib.GError as e: self.assertEqual(e.message, "Query type 'language-support' is not supported") res = self._call(PackageKitGlib.ProvidesEnum.ANY, ['language(de)']) self.assertTrue('vanilla' not in res, res) self.assertTrue('chocolate' not in res, res) def test_modalias_error(self): '''invalid modalias query''' # checks format for MODALIAS type try: self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['pci 1']) self.fail('unexpectedly succeeded with invalid query format') except GLib.GError as e: self.assertTrue('search term is invalid' in e.message, e.message) try: self._call(PackageKitGlib.ProvidesEnum.MODALIAS, ['usb:1', 'pci 1']) self.fail('unexpectedly succeeded with invalid query format') except GLib.GError as e: self.assertTrue('search term is invalid' in e.message, e.message) # for ANY it should just ignore invalid/unknown formats self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.ANY, ['pci 1']), []) def test_modalias_performance_single(self): '''performance of 1000 lookups in a single query''' query = [] for i in range(1000): query.append('usb:v%04Xd0000sv00sd00bc00sc00i99' % i) start = resource.getrusage(resource.RUSAGE_SELF) self._call(PackageKitGlib.ProvidesEnum.MODALIAS, query) stop = resource.getrusage(resource.RUSAGE_SELF) sec = (stop.ru_utime + stop.ru_stime) - (start.ru_utime + start.ru_stime) sys.stderr.write('[%i ms] ' % int(sec * 1000 + 0.5)) self.assertLess(sec, 1.0) def test_hardware_driver(self): '''what-provides HARDWARE_DRIVER''' self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.HARDWARE_DRIVER, ['drivers_for_attached_hardware']), ['chocolate', 'nvidia-current', 'vanilla']) self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.ANY, ['drivers_for_attached_hardware']), ['chocolate', 'nvidia-current', 'vanilla']) def test_hardware_driver_detect_plugins(self): '''what-provides HARDWARE_DRIVER includes custom detection plugins''' try: os.mkdir(self.plugin_dir) with open(os.path.join(self.plugin_dir, 'special.py'), 'w') as f: f.write('def detect(apt): return ["special", "special-uninst", "special-unavail", "picky"]\n') self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.HARDWARE_DRIVER, ['drivers_for_attached_hardware']), ['chocolate', 'nvidia-current', 'picky', 'special', 'vanilla']) finally: shutil.rmtree(self.plugin_dir) def test_hardware_driver_error(self): '''invalid what-provides HARDWARE_DRIVER query''' # checks format for HARDWARE_DRIVER type try: self._call(PackageKitGlib.ProvidesEnum.HARDWARE_DRIVER, ['?']) self.fail('unexpectedly succeeded with invalid query format') except GLib.GError as e: self.assertTrue('search term is invalid' in e.message, e.message) # for ANY it should just ignore invalid/unknown formats self.assertEqual(self._call(PackageKitGlib.ProvidesEnum.ANY, ['?']), []) def _call(self, provides_type, query, expected_res=PackageKitGlib.ExitEnum.SUCCESS): '''Call what_provides() with given query. Return the resulting package list. ''' # PackageKitGlib has a very low activation timeout, which # is too short for slow architectures; loop for a bit until service is # activated. tries = 5 while tries > 0: try: res = self.pk.what_provides(PackageKitGlib.FilterEnum.NONE, provides_type, query, None, lambda p, t, d: True, None) break except GLib.GError as e: if 'org.freedesktop.DBus.Error.ServiceUnknown' in str(e): tries -= 1 time.sleep(1) else: raise else: self.fail('timed out waiting for PackageKit') self.assertEqual(res.get_exit_code(), expected_res) if res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS: return sorted([p.get_id().split(';')[0] for p in res.get_package_array()]) else: return None class DetectTest(unittest.TestCase): '''Test UbuntuDrivers.detect''' def setUp(self): '''Create a fake sysfs''' self.umockdev = gen_fakehw() # no custom detection plugins by default self.plugin_dir = tempfile.mkdtemp() os.environ['UBUNTU_DRIVERS_DETECT_DIR'] = self.plugin_dir def tearDown(self): shutil.rmtree(self.plugin_dir) @unittest.skipUnless(os.path.isdir('/sys/devices'), 'no /sys dir on this system') def test_system_modaliases_system(self): '''system_modaliases() for current system''' del self.umockdev res = UbuntuDrivers.detect.system_modaliases() self.assertGreater(len(res), 3) self.assertTrue(':' in list(res)[0]) def test_system_modalises_fake(self): '''system_modaliases() for fake sysfs''' res = UbuntuDrivers.detect.system_modaliases() self.assertEqual(set(res), set(['pci:v00001234d00sv00000001sd00bc00sc00i00', 'pci:vDEADBEEFd00', 'usb:v9876dABCDsv01sd02bc00sc01i05', modalias_nv])) self.assertEqual(res['pci:vDEADBEEFd00'], '/sys/devices/grey') def test_system_driver_packages_performance(self): '''system_driver_packages() performance for a lot of modaliases''' # add lots of fake devices/modalises for i in range(30): self.umockdev.add_device('pci', 'pcidev%i' % i, None, ['modalias', 'pci:s%04X' % i], []) self.umockdev.add_device('usb', 'usbdev%i' % i, None, ['modalias', 'usb:s%04X' % i], []) start = resource.getrusage(resource.RUSAGE_SELF) UbuntuDrivers.detect.system_driver_packages() stop = resource.getrusage(resource.RUSAGE_SELF) sec = (stop.ru_utime + stop.ru_stime) - (start.ru_utime + start.ru_stime) sys.stderr.write('[%.2f s] ' % sec) self.assertLess(sec, 30.0) @unittest.expectedFailure def test_system_driver_packages_chroot(self): '''system_driver_packages() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() # older applicable driver which is not the recommended one archive.create_deb('nvidia-123', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) # -updates driver which also should not be recommended archive.create_deb('nvidia-current-updates', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) # driver package which supports multiple ABIs archive.create_deb('nvidia-34', dependencies={'Depends': 'xorg-video-abi-3 | xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) res = UbuntuDrivers.detect.system_driver_packages(cache) finally: chroot.remove() self.assertEqual(set(res), set(['chocolate', 'vanilla', 'nvidia-current', 'nvidia-current-updates', 'nvidia-123', 'nvidia-34'])) self.assertEqual(res['vanilla']['modalias'], 'pci:v00001234d00sv00000001sd00bc00sc00i00') self.assertTrue(res['vanilla']['syspath'].endswith('/devices/white')) self.assertFalse(res['vanilla']['from_distro']) self.assertTrue(res['vanilla']['free']) self.assertFalse('vendor' in res['vanilla']) self.assertFalse('model' in res['vanilla']) self.assertFalse('recommended' in res['vanilla']) self.assertTrue(res['chocolate']['syspath'].endswith('/devices/black')) self.assertFalse('vendor' in res['chocolate']) self.assertFalse('model' in res['chocolate']) self.assertFalse('recommended' in res['chocolate']) self.assertEqual(res['nvidia-current']['modalias'], modalias_nv) self.assertTrue('nvidia' in res['nvidia-current']['vendor'].lower(), res['nvidia-current']['vendor']) self.assertTrue('GeForce' in res['nvidia-current']['model'], res['nvidia-current']['model']) self.assertEqual(res['nvidia-current']['recommended'], True) self.assertEqual(res['nvidia-123']['modalias'], modalias_nv) self.assertTrue('nvidia' in res['nvidia-123']['vendor'].lower(), res['nvidia-123']['vendor']) self.assertTrue('GeForce' in res['nvidia-123']['model'], res['nvidia-123']['model']) self.assertEqual(res['nvidia-123']['recommended'], False) self.assertEqual(res['nvidia-current-updates']['modalias'], modalias_nv) self.assertEqual(res['nvidia-current-updates']['recommended'], False) self.assertEqual(res['nvidia-34']['modalias'], modalias_nv) self.assertEqual(res['nvidia-34']['recommended'], False) def test_system_driver_packages_bad_encoding(self): '''system_driver_packages() with badly encoded Packages index''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() # add a package entry with a broken encoding with open(os.path.join(archive.path, 'Packages'), 'ab') as f: f.write(b''' Package: broken Architecture: all Priority: optional Version: 1 Maintainer: Test A\xEBB User Filename: ./vanilla_1_all.deb Description: broken \xEB encoding ''') chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) res = UbuntuDrivers.detect.system_driver_packages(cache) finally: chroot.remove() self.assertEqual(set(res), set(['chocolate', 'vanilla', 'nvidia-current'])) def test_system_driver_packages_detect_plugins(self): '''system_driver_packages() includes custom detection plugins''' with open(os.path.join(self.plugin_dir, 'extra.py'), 'w') as f: f.write('def detect(apt): return ["coreutils", "no_such_package"]\n') res = UbuntuDrivers.detect.system_driver_packages() self.assertTrue('coreutils' in res, list(res.keys())) self.assertEqual(res['coreutils'], {'free': True, 'from_distro': True, 'plugin': 'extra.py'}) def test_system_device_drivers_chroot(self): '''system_device_drivers() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() # older applicable driver which is not the recommended one archive.create_deb('nvidia-123', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) # -updates driver which also should not be recommended archive.create_deb('nvidia-current-updates', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) # -experimental driver which also should not be recommended archive.create_deb('nvidia-experimental', dependencies={'Depends': 'xorg-video-abi-4'}, extra_tags={'Modaliases': 'nv(pci:v000010DEd000010C3sv*sd*bc03sc*i*)'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) res = UbuntuDrivers.detect.system_device_drivers(cache) finally: chroot.remove() white = '/sys/devices/white' black = '/sys/devices/black' graphics = '/sys/devices/graphics' self.assertEqual(len(res), 3) # the three devices above self.assertEqual(res[white], {'modalias': 'pci:v00001234d00sv00000001sd00bc00sc00i00', 'drivers': {'vanilla': {'free': True, 'from_distro': False}} }) self.assertEqual(res[black], {'modalias': 'usb:v9876dABCDsv01sd02bc00sc01i05', 'drivers': {'chocolate': {'free': True, 'from_distro': False}} }) self.assertEqual(res[graphics]['modalias'], modalias_nv) self.assertTrue('nvidia' in res[graphics]['vendor'].lower()) self.assertTrue('GeForce' in res[graphics]['model']) # should contain nouveau driver; note that free is True here because # these come from the fake archive self.assertEqual(res[graphics]['drivers']['nvidia-current'], {'free': True, 'from_distro': False, 'recommended': True}) self.assertEqual(res[graphics]['drivers']['nvidia-current-updates'], {'free': True, 'from_distro': False, 'recommended': False}) self.assertEqual(res[graphics]['drivers']['nvidia-123'], {'free': True, 'from_distro': False, 'recommended': False}) self.assertEqual(res[graphics]['drivers']['nvidia-experimental'], {'free': True, 'from_distro': False, 'recommended': False}) self.assertEqual(res[graphics]['drivers']['xserver-xorg-video-nouveau'], {'free': True, 'from_distro': True, 'recommended': False, 'builtin': True}) self.assertEqual(len(res[graphics]['drivers']), 5, list(res[graphics]['drivers'].keys())) def test_system_device_drivers_detect_plugins(self): '''system_device_drivers() includes custom detection plugins''' with open(os.path.join(self.plugin_dir, 'extra.py'), 'w') as f: f.write('def detect(apt): return ["coreutils", "no_such_package"]\n') res = UbuntuDrivers.detect.system_device_drivers() self.assertTrue('extra.py' in res, list(res.keys())) self.assertEqual(res['extra.py'], {'drivers': {'coreutils': {'free': True, 'from_distro': True}}}) def test_system_device_drivers_manual_install(self): '''system_device_drivers() for a manually installed nvidia driver''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) # add a wrapper modinfo binary with open(os.path.join(chroot.path, 'modinfo'), 'w') as f: f.write('''#!/bin/sh -e if [ "$1" = nvidia ]; then echo "filename: /some/path/nvidia.ko" exit 0 fi exec /sbin/modinfo "$@" ''') os.chmod(os.path.join(chroot.path, 'modinfo'), 0o755) orig_path = os.environ['PATH'] os.environ['PATH'] = '%s:%s' % (chroot.path, os.environ['PATH']) res = UbuntuDrivers.detect.system_device_drivers(cache) finally: chroot.remove() os.environ['PATH'] = orig_path graphics = '/sys/devices/graphics' self.assertEqual(res[graphics]['modalias'], modalias_nv) self.assertTrue(res[graphics]['manual_install']) # should still show the drivers self.assertGreater(len(res[graphics]['drivers']), 1) def test_auto_install_filter(self): '''auto_install_filter()''' self.assertEqual(UbuntuDrivers.detect.auto_install_filter({}), {}) pkgs = {'bcmwl-kernel-source': {}, 'nvidia-current': {}, 'fglrx-updates': {}, 'pvr-omap4-egl': {}} self.assertEqual(set(UbuntuDrivers.detect.auto_install_filter(pkgs)), set(['bcmwl-kernel-source', 'pvr-omap4-egl', 'nvidia-current'])) # should not include non-recommended variants pkgs = {'bcmwl-kernel-source': {}, 'nvidia-current': {'recommended': False}, 'nvidia-173': {'recommended': True}} self.assertEqual(set(UbuntuDrivers.detect.auto_install_filter(pkgs)), set(['bcmwl-kernel-source', 'nvidia-173'])) def test_detect_plugin_packages(self): '''detect_plugin_packages()''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) self.assertEqual(UbuntuDrivers.detect.detect_plugin_packages(cache), {}) self._gen_detect_plugins() # suppress logging the deliberate errors in our test plugins to # stderr logging.getLogger().setLevel(logging.CRITICAL) self.assertEqual(UbuntuDrivers.detect.detect_plugin_packages(cache), {'special.py': ['special']}) os.mkdir(os.path.join(self.umockdev.get_sys_dir(), 'pickyon')) self.assertEqual(UbuntuDrivers.detect.detect_plugin_packages(cache), {'special.py': ['special'], 'picky.py': ['picky']}) finally: logging.getLogger().setLevel(logging.INFO) chroot.remove() def _gen_detect_plugins(self): '''Generate some custom detection plugins in self.plugin_dir.''' with open(os.path.join(self.plugin_dir, 'special.py'), 'w') as f: f.write('def detect(apt): return ["special", "special-uninst", "special-unavail"]\n') with open(os.path.join(self.plugin_dir, 'syntax.py'), 'w') as f: f.write('def detect(apt): a = =\n') with open(os.path.join(self.plugin_dir, 'empty.py'), 'w') as f: f.write('def detect(apt): return []\n') with open(os.path.join(self.plugin_dir, 'badreturn.py'), 'w') as f: f.write('def detect(apt): return "strawberry"\n') with open(os.path.join(self.plugin_dir, 'badreturn2.py'), 'w') as f: f.write('def detect(apt): return 1\n') with open(os.path.join(self.plugin_dir, 'except.py'), 'w') as f: f.write('def detect(apt): 1/0\n') with open(os.path.join(self.plugin_dir, 'nodetect.py'), 'w') as f: f.write('def foo(): assert False\n') with open(os.path.join(self.plugin_dir, 'bogus'), 'w') as f: f.write('I am not a plugin') with open(os.path.join(self.plugin_dir, 'picky.py'), 'w') as f: f.write('''import os, os.path def detect(apt): if os.path.exists("/sys/pickyon"): return ["picky"] ''') def test_get_linux_headers_chroot(self): '''get_linux_headers() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-23-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.2.0-33-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) linux_headers = UbuntuDrivers.detect.get_linux_headers(cache) self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-3.2.0-23-generic', 'linux-image-3.2.0-33-generic', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() linux_headers = UbuntuDrivers.detect.get_linux_headers(cache) self.assertEqual(linux_headers, 'linux-headers-generic-lts-quantal') finally: chroot.remove() def test_get_linux_chroot(self): '''get_linux() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-23-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.2.0-33-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) linux = UbuntuDrivers.detect.get_linux(cache) self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-3.2.0-23-generic', 'linux-image-3.2.0-33-generic', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() linux = UbuntuDrivers.detect.get_linux(cache) self.assertEqual(linux, 'linux-generic-lts-quantal') finally: chroot.remove() class ToolTest(unittest.TestCase): '''Test ubuntu-drivers tool''' @classmethod def setUpClass(klass): klass.archive = gen_fakearchive() klass.archive.create_deb('noalias') klass.archive.create_deb('bcmwl-kernel-source', extra_tags={'Modaliases': 'wl(usb:v9876dABCDsv*sd*bc00sc*i*, pci:v0000BEEFd*sv*sd*bc*sc*i00)'}) # set up a test chroot klass.chroot = aptdaemon.test.Chroot() klass.chroot.setup() klass.chroot.add_test_repository() klass.chroot.add_repository(klass.archive.path, True, False) klass.chroot_apt_conf = os.path.join(klass.chroot.path, 'aptconfig') with open(klass.chroot_apt_conf, 'w') as f: f.write('''Dir "%(root)s"; Dir::State::status "%(root)s/var/lib/dpkg/status"; Debug::NoLocking "true"; DPKG::options:: "--root=%(root)s --log=%(root)s/var/log/dpkg.log"; APT::Get::AllowUnauthenticated "true"; ''' % {'root': klass.chroot.path}) os.environ['APT_CONFIG'] = klass.chroot_apt_conf klass.tool_path = os.path.join(ROOT_DIR, 'ubuntu-drivers') # no custom detection plugins by default klass.plugin_dir = os.path.join(klass.chroot.path, 'detect') os.environ['UBUNTU_DRIVERS_DETECT_DIR'] = klass.plugin_dir @classmethod def tearDownClass(klass): klass.chroot.remove() def setUp(self): '''Create a fake sysfs''' self.umockdev = gen_fakehw() def tearDown(self): # some tests install this package apt = subprocess.Popen(['apt-get', 'purge', '-y', 'bcmwl-kernel-source'], stdout=subprocess.PIPE) apt.communicate() self.assertEqual(apt.returncode, 0) def test_list_chroot(self): '''ubuntu-drivers list for fake sysfs and chroot''' ud = subprocess.Popen([self.tool_path, 'list'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertEqual(set(out.splitlines()), set(['vanilla', 'chocolate', 'bcmwl-kernel-source', 'nvidia-current'])) self.assertEqual(ud.returncode, 0) def test_list_detect_plugins(self): '''ubuntu-drivers list includes custom detection plugins''' os.mkdir(self.plugin_dir) self.addCleanup(shutil.rmtree, self.plugin_dir) with open(os.path.join(self.plugin_dir, 'special.py'), 'w') as f: f.write('def detect(apt): return ["special", "special-uninst", "special-unavail", "picky"]\n') ud = subprocess.Popen([self.tool_path, 'list'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertEqual(set(out.splitlines()), set(['vanilla', 'chocolate', 'bcmwl-kernel-source', 'nvidia-current', 'special', 'picky'])) self.assertEqual(ud.returncode, 0) @unittest.expectedFailure def test_list_system(self): '''ubuntu-drivers list for fake sysfs and system apt''' env = os.environ.copy() del env['APT_CONFIG'] ud = subprocess.Popen([self.tool_path, 'list'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) out, err = ud.communicate() # real system packages should not match our fake modalises self.assertEqual(err, '') self.assertEqual(out, '\n') self.assertEqual(ud.returncode, 0) def test_devices_chroot(self): '''ubuntu-drivers devices for fake sysfs and chroot''' ud = subprocess.Popen([self.tool_path, 'devices'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertTrue('/devices/white ==' in out) self.assertTrue('modalias : pci:v00001234d00sv00000001sd00bc00sc00i00' in out) self.assertTrue('driver : vanilla - third-party free' in out) self.assertTrue('/devices/black ==' in out) self.assertTrue('/devices/graphics ==' in out) self.assertTrue('xserver-xorg-video-nouveau - distro free builtin' in out) self.assertTrue('nvidia-current - third-party free recommended' in out) self.assertEqual(ud.returncode, 0) def test_devices_detect_plugins(self): '''ubuntu-drivers devices includes custom detection plugins''' os.mkdir(self.plugin_dir) self.addCleanup(shutil.rmtree, self.plugin_dir) with open(os.path.join(self.plugin_dir, 'special.py'), 'w') as f: f.write('def detect(apt): return ["special", "special-uninst", "special-unavail", "picky"]\n') ud = subprocess.Popen([self.tool_path, 'devices'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') # only look at the part after special.py special_off = out.find('== special.py ==') self.assertGreaterEqual(special_off, 0, out) out = out[special_off:] self.assertTrue('picky - third-party free' in out, out) self.assertTrue('special - third-party free' in out, out) self.assertEqual(ud.returncode, 0) @unittest.expectedFailure def test_devices_system(self): '''ubuntu-drivers devices for fake sysfs and system apt''' env = os.environ.copy() del env['APT_CONFIG'] ud = subprocess.Popen([self.tool_path, 'devices'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) out, err = ud.communicate() # real system packages should not match our fake modalises self.assertEqual(err, '') self.assertEqual(out, '') self.assertEqual(ud.returncode, 0) def test_auto_install_chroot(self): '''ubuntu-drivers autoinstall for fake sysfs and chroot''' ud = subprocess.Popen([self.tool_path, 'autoinstall'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertTrue('bcmwl-kernel-source' in out, out) self.assertFalse('vanilla' in out, out) self.assertFalse('noalias' in out, out) self.assertEqual(ud.returncode, 0) # now all packages should be installed, so it should not do anything ud = subprocess.Popen([self.tool_path, 'autoinstall'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertFalse('bcmwl-kernel-source' in out, out) self.assertEqual(ud.returncode, 0) def test_auto_install_packagelist(self): '''ubuntu-drivers autoinstall package list creation''' listfile = os.path.join(self.chroot.path, 'pkgs') self.addCleanup(os.unlink, listfile) ud = subprocess.Popen([self.tool_path, 'autoinstall', '--package-list', listfile], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '') self.assertEqual(ud.returncode, 0) with open(listfile) as f: self.assertEqual(f.read(), 'bcmwl-kernel-source\n') @unittest.expectedFailure def test_auto_install_system(self): '''ubuntu-drivers autoinstall for fake sysfs and system apt''' env = os.environ.copy() del env['APT_CONFIG'] ud = subprocess.Popen([self.tool_path, 'autoinstall'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) out, err = ud.communicate() self.assertEqual(err, '') # real system packages should not match our fake modalises self.assertTrue('No drivers found' in out) self.assertEqual(ud.returncode, 0) def test_debug(self): '''ubuntu-drivers debug''' os.mkdir(self.plugin_dir) self.addCleanup(shutil.rmtree, self.plugin_dir) with open(os.path.join(self.plugin_dir, 'special.py'), 'w') as f: f.write('def detect(apt): return ["special", "special-uninst", "special-unavail"]\n') ud = subprocess.Popen([self.tool_path, 'debug'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ud.communicate() self.assertEqual(err, '', err) self.assertEqual(ud.returncode, 0) # shows messages from detection/plugins self.assertTrue('special-uninst is incompatible' in out, out) self.assertTrue('unavailable package special-unavail' in out, out) # shows modaliases self.assertTrue(modalias_nv in out, out) # driver packages self.assertTrue('available: 1 (auto-install) [third party] free modalias:' in out, out) class PluginsTest(unittest.TestCase): '''Test detect-plugins/*''' def test_plugin_errors(self): '''shipped plugins work without errors or crashes''' env = os.environ.copy() env['UBUNTU_DRIVERS_DETECT_DIR'] = os.path.join(ROOT_DIR, 'detect-plugins') ud = subprocess.Popen([os.path.join(ROOT_DIR, 'ubuntu-drivers'), 'debug'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) out, err = ud.communicate() self.assertEqual(err, '') # real system packages should not match our fake modalises self.assertFalse('ERROR' in out, out) self.assertFalse('Traceback' in out, out) self.assertEqual(ud.returncode, 0) class KernelDectionTest(unittest.TestCase): '''Test UbuntuDrivers.kerneldetection''' def setUp(self): '''Create a fake sysfs''' self.umockdev = gen_fakehw() # no custom detection plugins by default self.plugin_dir = tempfile.mkdtemp() os.environ['UBUNTU_DRIVERS_DETECT_DIR'] = self.plugin_dir def tearDown(self): shutil.rmtree(self.plugin_dir) def test_linux_headers_detection_chroot(self): '''get_linux_headers_metapackage() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-23-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.2.0-33-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-3.2.0-23-generic', 'linux-image-3.2.0-33-generic', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-generic-lts-quantal') finally: chroot.remove() def test_linux_headers_detection_names_chroot1(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.2.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-17-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.2.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-17-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-powerpc-smp') finally: chroot.remove() def test_linux_headers_detection_names_chroot2(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.2.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.2.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-powerpc64-smp') finally: chroot.remove() def test_linux_headers_detection_names_chroot3(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.8.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.8.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-omap4') finally: chroot.remove() def test_linux_headers_detection_names_chroot4(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-3-powerpc-e500', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-1-powerpc-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-2-powerpc64-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-powerpc-smp', 'linux-image-3.8.0-3-powerpc-e500', 'linux-image-3.8.0-1-powerpc-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-3.8.0-2-powerpc64-smp', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-powerpc-e500') finally: chroot.remove() def test_linux_headers_detection_names_chroot5(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-36-lowlatency-pae', extra_tags={'Source': 'linux-lowlatency'}) archive.create_deb('linux-image-3.8.0-0-lowlatency', extra_tags={'Source': 'linux-lowlatency'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, '') # Install kernel packages for pkg in ('linux-image-3.2.0-36-lowlatency-pae', 'linux-image-3.8.0-0-lowlatency', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux_headers = kernel_detection.get_linux_headers_metapackage() self.assertEqual(linux_headers, 'linux-headers-lowlatency') finally: chroot.remove() def test_linux_detection_chroot(self): '''get_linux_metapackage() for test package repository''' chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-23-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.2.0-33-generic', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-3.2.0-23-generic', 'linux-image-3.2.0-33-generic', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-generic-lts-quantal') finally: chroot.remove() def test_linux_detection_names_chroot1(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.2.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-17-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.2.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-17-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-powerpc-smp') finally: chroot.remove() def test_linux_detection_names_chroot2(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.2.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.2.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-powerpc64-smp') finally: chroot.remove() def test_linux_detection_names_chroot3(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-nexus7', extra_tags={'Source': 'linux-meta-nexus7'}) archive.create_deb('linux-image-3.1.10-9-nexus7', extra_tags={'Source': 'linux-nexus7'}) archive.create_deb('linux-image-omap4', extra_tags={'Source': 'linux-meta-ti-omap4'}) archive.create_deb('linux-image-3.8.0-1419-omap4', extra_tags={'Source': 'linux-ti-omap4'}) archive.create_deb('linux-image-3.5.0-17-highbank', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-highbank', extra_tags={'Source': 'linux-meta-highbank'}) archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-meta-powerpc-smp'}) archive.create_deb('linux-image-3.5.0-18-powerpc-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-powerpc64-smp', extra_tags={'Source': 'linux-meta-powerpc64-smp'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux'}) archive.create_deb('linux-image-ac100', extra_tags={'Source': 'linux-meta-ac100'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-nexus7', 'linux-image-3.1.10-9-nexus7', 'linux-image-omap4', 'linux-image-3.8.0-1419-omap4', 'linux-image-highbank', 'linux-image-3.5.0-17-highbank', 'linux-image-powerpc-smp', 'linux-image-3.5.0-18-powerpc-smp', 'linux-image-powerpc64-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-ac100', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-omap4') finally: chroot.remove() def test_linux_detection_names_chroot4(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-powerpc-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-3-powerpc-e500', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-1-powerpc-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.5.0-19-powerpc64-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.8.0-2-powerpc64-smp', extra_tags={'Source': 'linux-ppc'}) archive.create_deb('linux-image-3.0.27-1-ac100', extra_tags={'Source': 'linux-ac100'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-powerpc-smp', 'linux-image-3.8.0-3-powerpc-e500', 'linux-image-3.8.0-1-powerpc-smp', 'linux-image-3.5.0-19-powerpc64-smp', 'linux-image-3.8.0-2-powerpc64-smp', 'linux-image-3.0.27-1-ac100'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-powerpc-e500') finally: chroot.remove() def test_linux_detection_names_chroot5(self): chroot = aptdaemon.test.Chroot() try: chroot.setup() chroot.add_test_repository() archive = gen_fakearchive() archive.create_deb('linux-image-3.2.0-36-lowlatency-pae', extra_tags={'Source': 'linux-lowlatency'}) archive.create_deb('linux-image-3.8.0-0-lowlatency', extra_tags={'Source': 'linux-lowlatency'}) archive.create_deb('linux-image-3.5.0-18-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-3.5.0-19-generic', extra_tags={'Source': 'linux-lts-quantal'}) archive.create_deb('linux-image-generic', extra_tags={'Source': 'linux-meta'}) archive.create_deb('linux-image-generic-lts-quantal', extra_tags={'Source': 'linux-meta-lts-quantal'}) chroot.add_repository(archive.path, True, False) cache = apt.Cache(rootdir=chroot.path) kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, '') # Install kernel packages for pkg in ('linux-image-3.2.0-36-lowlatency-pae', 'linux-image-3.8.0-0-lowlatency', 'linux-image-3.5.0-18-generic', 'linux-image-3.5.0-19-generic', 'linux-image-generic', 'linux-image-generic-lts-quantal'): cache[pkg].mark_install() kernel_detection = UbuntuDrivers.kerneldetection.KernelDetection(cache) linux = kernel_detection.get_linux_metapackage() self.assertEqual(linux, 'linux-lowlatency') finally: chroot.remove() if __name__ == '__main__': if 'umockdev' not in os.environ.get('LD_PRELOAD', ''): sys.stderr.write('This test suite needs to be run under umockdev-wrapper\n') sys.exit(1) unittest.main() ubuntu-drivers-common-0.2.91.4/tests/testarchive.py0000664000000000000000000001020112322472605017153 0ustar '''Provide a fake package archive for testing.''' # (C) 2012 Martin Pitt # # This program 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 2 of the License, or # (at your option) any later version. import tempfile import shutil import os import subprocess import atexit class Archive: def __init__(self): '''Construct a local package test archive. The archive is initially empty. You can create new packages with create_deb(). self.path contains the path of the archive, and self.apt_source provides an apt source "deb" line. It is kept in a temporary directory which gets removed when the Archive object gets deleted. ''' self.path = tempfile.mkdtemp() atexit.register(shutil.rmtree, self.path) self.apt_source = 'deb file://%s /' % self.path def create_deb(self, name, version='1', architecture='all', dependencies={}, description='test package', extra_tags={}, files={}, update_index=True): '''Build a deb package and add it to the archive. The only mandatory argument is the package name. You can additionall specify the package version (default '1'), architecture (default 'all'), a dictionary with dependencies (empty by default; for example {'Depends': 'foo, bar', 'Conflicts: baz'}, a short description (default: 'test package'), and arbitrary extra tags. By default the package is empty. It can get files by specifying a path -> contents dictionary in 'files'. Paths must be relative. Example: files={'etc/foo.conf': 'enable=true'} The newly created deb automatically gets added to the "Packages" index, unless update_index is False. Return the path to the newly created deb package, in case you only need the deb itself, not the archive. ''' d = tempfile.mkdtemp() os.mkdir(os.path.join(d, 'DEBIAN')) with open(os.path.join(d, 'DEBIAN', 'control'), 'w') as f: f.write('''Package: %s Maintainer: Test User Version: %s Priority: optional Section: devel Architecture: %s ''' % (name, version, architecture)) for k, v in dependencies.items(): f.write('%s: %s\n' % (k, v)) f.write('''Description: %s Test dummy package. ''' % description) for k, v in extra_tags.items(): f.write('%s: %s\n' % (k, v)) for path, contents in files.items(): if type(contents) == bytes: mode = 'wb' else: mode = 'w' pathdir = os.path.join(d, os.path.dirname(path)) if not os.path.isdir(pathdir): os.makedirs(pathdir) with open(os.path.join(d, path), mode) as f: f.write(contents) debpath = os.path.join(self.path, '%s_%s_%s.deb' % (name, version, architecture)) dpkg = subprocess.Popen(['dpkg', '-b', d, debpath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) dpkg.communicate() assert dpkg.returncode == 0 shutil.rmtree(d) assert os.path.exists(debpath) if update_index: self.update_index() return debpath def update_index(self): '''Update the "Packages" index. This usually gets done automatically by create_deb(), but needs to be done if you manually copy debs into the archive or call create_deb with update_index==False. ''' old_cwd = os.getcwd() try: os.chdir(self.path) with open('Packages', 'w') as f: subprocess.check_call(['apt-ftparchive', 'packages', '.'], stdout=f) finally: os.chdir(old_cwd) #a = Archive() #a.create_deb('vanilla') #a.create_deb('chocolate', dependencies={'Depends': 'foo'}, # extra_tags={'Modaliases': 'pci-1'}, # files={'usr/share/doc/chocolate/README': 'hello'}) #print(a.apt_source) #subprocess.call(['bash', '-i'], cwd=a.path) ubuntu-drivers-common-0.2.91.4/tests/settings.py0000664000000000000000000000020012322472605016470 0ustar import os cwd = os.getcwd() inputFile = os.path.join(cwd, "xorg.conf") outputDir = cwd inputDir = cwd.replace("tests", "quirks")ubuntu-drivers-common-0.2.91.4/tests/run0000775000000000000000000000606012322472605015022 0ustar #!/usr/bin/python3 # -*- coding: UTF-8 -*- '''Run self tests.''' # (c) 2008 Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import unittest, os.path, sys, logging, os, atexit import getopt def usage(): instructionsList = ['The only accepted (optional) parameters are:' '\n -o, --output=', '\tthe directory where the results \n\ \t\t\t\tof the tests are saved.' '\n -i, --input=', '\tthe xorg.conf used for the tests.' '\n -h, --help', '\t\t\thelp page.' ] print(''.join(instructionsList)) def main(): cwd = os.getcwd() inputFile = os.path.join(cwd, 'xorg.conf') outputDir = cwd err = 'Error: parameters not recognised' try: opts, args = getopt.getopt(sys.argv[1:], 'h:o:i:', ['help', 'output=', 'input=']) except getopt.GetoptError as err: # print help information and exit: print(err) # will print something like 'option -a not recognized' usage() sys.exit(2) printonly = None verbose = None for o, a in opts: if o in ('-i', '--input'): inputFile = a elif o in ('-o', '--output'): outputDir = a elif o in ('-h', '--help'): usage() sys.exit() else: assert False, 'unhandled option' settingsFile = open('settings.py', 'w') atexit.register(os.unlink, 'settings.py') if inputFile == os.path.join(cwd, 'xorg.conf') and outputDir == cwd: settingsFile.write('import os\ncwd = os.getcwd()\ninputFile = os.path.join(cwd, "xorg.conf")\noutputDir = cwd\ninputDir = cwd.replace("tests", "quirks")') else: settingsFile.write('inputFile = "%s"\noutputDir = "%s"' % (inputFile, outputDir)) settingsFile.close() # run all tests in our directory suite = unittest.TestLoader().loadTestsFromNames( [t[:-3] for t in os.listdir(os.path.dirname(__file__)) if t.endswith('.py') and t not in ['settings.py', '__init__.py'] and not (t == 'gpu-manager.py' and '86' not in os.uname()[4])]) res = unittest.TextTestRunner(verbosity=2).run(suite) return len(res.errors) + len(res.failures) if __name__ == '__main__': # run ourselves through umockdev-wrapper if 'umockdev' not in os.environ.get('LD_PRELOAD', ''): os.execvp('umockdev-wrapper', ['umockdev-wrapper'] + sys.argv) sys.exit(main()) ubuntu-drivers-common-0.2.91.4/tests/quirkreader-test.py0000664000000000000000000002640112322472605020136 0ustar #!/usr/bin/python3 # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from Quirks import quirkreader, quirkapplier from xkit import xorgparser from xkit.xorgparser import * import sys import unittest import os import logging import settings import tempfile import copy source = settings.inputFile destination = settings.inputDir destinationFile = os.path.join(settings.outputDir, 'quirksreader_test.txt') tempFile = os.path.join(destination, 'tmp') def get_quirks_from_file(quirk_file): '''check all the files in a directory looking for quirks''' # read other blacklist files (which we will not touch, but evaluate) quirk_file = quirkreader.ReadQuirk(quirk_file) return quirk_file.get_quirks() class QuirkReaderTestCase(unittest.TestCase): #def setUp(self): #self.quirk_file = quirkreader.ReadQuirk(quirk_file) #self.quirks = self.quirk_file.get_quirks() def tearDown(self): #self.parser.comments.insert(0, '\n-----' + self.this_function_name + '-----\n') #self.parser.write(destinationFile, test=True) try: os.remove(tempFile) except(OSError, IOError): pass def test_read_quirk1(self): '''1 Matching config file''' self.this_function_name = sys._getframe().f_code.co_name section = 'Screen' identifier = 'Display' option = 'Depth' with open(tempFile, 'w') as confFile: confFile.write(''' Section "Quirk" Identifier "Test Latitude E6530" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "Dell Inc." Match "product_name" "Latitude E6530" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ''') #os.system('cat %s' % tempFile) #loglevel = logging.DEBUG #else: #loglevel = logging.INFO #logging.basicConfig(format='%(levelname)s:%(message)s', level=loglevel) a = quirkapplier.QuirkChecker('nvidia-current', path=destination) # Override DMI a._system_info = {'sys_vendor': 'Dell Inc.', 'bios_vendor': 'American Megatrends Inc.', 'product_version': 'System Version', 'board_name': 'P6T SE', 'bios_date': '01/19/2009', 'bios_version': '0106', 'product_name': 'Latitude E6530', 'board_vendor': 'ASUSTeK Computer INC.'} quirk_found = False quirk_matches = False for quirk in a._quirks: if a._handler.lower() in [x.lower().strip() for x in quirk.handler]: quirk_found = True logging.debug('Processing quirk %s' % quirk.id) #self.assertTrue(a.matches_tags(quirk)) if a.matches_tags(quirk): # Do something here logging.debug('Quirk matches') quirk_matches = True else: logging.debug('Quirk doesn\'t match') self.assertTrue(quirk_found) self.assertTrue(quirk_matches) def test_read_quirk2(self): '''2 Not matching config file''' self.this_function_name = sys._getframe().f_code.co_name section = 'Screen' identifier = 'Display' option = 'Depth' with open(tempFile, 'w') as confFile: confFile.write(''' Section "Quirk" Identifier "Test Latitude E6530" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "Dell Inc." Match "product_name" "Latitude E6530" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ''') #os.system('cat %s' % tempFile) #loglevel = logging.DEBUG #else: #loglevel = logging.INFO #logging.basicConfig(format='%(levelname)s:%(message)s', level=loglevel) a = quirkapplier.QuirkChecker('nvidia-current', path=destination) # Override DMI a._system_info = {'sys_vendor': 'Fake', 'bios_vendor': 'American Megatrends Inc.', 'product_version': 'System Version', 'board_name': 'P6T SE', 'bios_date': '01/19/2009', 'bios_version': '0106', 'product_name': 'Fake product', 'board_vendor': 'ASUSTeK Computer INC.'} quirk_found = False quirk_matches = True for quirk in a._quirks: if a._handler.lower() in [x.lower().strip() for x in quirk.handler]: quirk_found = True logging.debug('Processing quirk %s' % quirk.id) # It doesn't have to match self.assertTrue(not a.matches_tags(quirk)) if a.matches_tags(quirk): # Do something here logging.debug('Quirk matches') else: logging.debug('Quirk doesn\'t match') quirk_matches = False self.assertTrue(quirk_found) self.assertTrue((quirk_matches == False)) def test_read_quirk3(self): '''3 Matching quirk aimed at multiple products''' self.this_function_name = sys._getframe().f_code.co_name section = 'Screen' identifier = 'Display' option = 'Depth' with open(tempFile, 'w') as confFile: confFile.write(''' Section "Quirk" Identifier "Test Latitude E6530" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "Dell Inc." Match "product_name" "Latitude E6530|Latitude E6535" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ''') #os.system('cat %s' % tempFile) #loglevel = logging.DEBUG #else: #loglevel = logging.INFO #logging.basicConfig(format='%(levelname)s:%(message)s', level=loglevel) a = quirkapplier.QuirkChecker('nvidia-current', path=destination) # Override DMI a._system_info = {'sys_vendor': 'Dell Inc.', 'bios_vendor': 'American Megatrends Inc.', 'product_version': 'System Version', 'board_name': 'P6T SE', 'bios_date': '01/19/2009', 'bios_version': '0106', 'product_name': 'Latitude E6535', 'board_vendor': 'ASUSTeK Computer INC.'} quirk_found = False quirk_matches = False for quirk in a._quirks: if a._handler.lower() in [x.lower().strip() for x in quirk.handler]: quirk_found = True logging.debug('Processing quirk %s' % quirk.id) # Let's test only the quirk that matters if quirk.id == "Test Latitude E6530": self.assertTrue(a.matches_tags(quirk)) if a.matches_tags(quirk): # Do something here logging.debug('Quirk matches') quirk_matches = True else: logging.debug('Quirk doesn\'t match') self.assertTrue(quirk_found) self.assertTrue(quirk_matches) def test_read_quirk4(self): '''3 Matching quirk aimed at multiple products only one should match''' self.this_function_name = sys._getframe().f_code.co_name section = 'Screen' identifier = 'Display' option = 'Depth' with open(tempFile, 'w') as confFile: confFile.write(''' Section "Quirk" Identifier "Test Latitude E6530" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "Dell Inc." Match "product_name" "Latitude E6530|Latitude E6535" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ''') #os.system('cat %s' % tempFile) #loglevel = logging.DEBUG #else: #loglevel = logging.INFO #logging.basicConfig(format='%(levelname)s:%(message)s', level=loglevel) a = quirkapplier.QuirkChecker('nvidia-current', path=destination) # Override DMI a._system_info = {'sys_vendor': 'Dell Inc.', 'bios_vendor': 'American Megatrends Inc.', 'product_version': 'System Version', 'board_name': 'P6T SE', 'bios_date': '01/19/2009', 'bios_version': '0106', 'product_name': 'Latitude E6535', 'board_vendor': 'ASUSTeK Computer INC.'} quirk_found = False quirk_matches = False matches_number = 0 for quirk in a._quirks: if a._handler.lower() in [x.lower().strip() for x in quirk.handler]: quirk_found = True logging.debug('Processing quirk %s' % quirk.id) # Let's test only the quirk that matters if quirk.id == "Test Latitude E6530": self.assertTrue(a.matches_tags(quirk)) if a.matches_tags(quirk): # Do something here logging.debug('Quirk matches') quirk_matches = True matches_number += 1 else: logging.debug('Quirk doesn\'t match') self.assertTrue(quirk_found) self.assertTrue(quirk_matches) self.assertTrue(matches_number == 1) def main(): return 0 if __name__ == '__main__': main() ubuntu-drivers-common-0.2.91.4/tests/gpu-manager.py0000664000000000000000000140471412322472605017056 0ustar # Author: Alberto Milone # # Copyright (C) 2014 Canonical Ltd # # This program 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 2 of the License, or # (at your option) any later version. import os import time import unittest import subprocess import resource import sys import tempfile import shutil import logging import re import argparse # Global path to save logs tests_path = None # Global path to use valgrind with_valgrind = False class GpuTest(object): def __init__(self, has_single_card=False, requires_offloading=False, has_intel=False, intel_loaded=False, intel_unloaded=False, has_amd=False, fglrx_loaded=False, fglrx_unloaded=False, radeon_loaded=False, radeon_unloaded=False, has_nvidia=False, nouveau_loaded=False, nouveau_unloaded=False, nvidia_loaded=False, nvidia_unloaded=False, nvidia_enabled=False, fglrx_enabled=False, mesa_enabled=False, prime_enabled=False, pxpress_enabled=False, has_changed=False, has_removed_xorg=False, has_regenerated_xorg=False, has_selected_driver=False, has_not_acted=True, has_skipped_hybrid=False, proprietary_installer=False, matched_quirk=False, loaded_with_args=False): self.has_single_card = has_single_card self.requires_offloading = requires_offloading self.has_intel = has_intel self.intel_loaded = intel_loaded self.intel_unloaded = intel_unloaded self.has_amd = has_amd self.radeon_loaded = radeon_loaded self.radeon_unloaded = radeon_unloaded self.fglrx_loaded = fglrx_loaded self.fglrx_unloaded = fglrx_unloaded self.has_nvidia = has_nvidia self.nouveau_loaded = nouveau_loaded self.nouveau_unloaded = nouveau_unloaded self.nvidia_loaded = nvidia_loaded self.nvidia_unloaded = nvidia_unloaded self.nvidia_enabled = nvidia_enabled self.fglrx_enabled = fglrx_enabled self.mesa_enabled = mesa_enabled self.prime_enabled = prime_enabled self.pxpress_enabled = pxpress_enabled self.has_changed = has_changed self.has_removed_xorg = has_removed_xorg self.has_regenerated_xorg = has_regenerated_xorg self.has_selected_driver = has_selected_driver self.has_not_acted = has_not_acted self.has_skipped_hybrid = has_skipped_hybrid self.proprietary_installer = proprietary_installer self.matched_quirk = matched_quirk self.loaded_with_args = loaded_with_args class GpuManagerTest(unittest.TestCase): @classmethod def setUpClass(klass): klass.last_boot_file = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.last_boot_file.close() klass.new_boot_file = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.new_boot_file.close() klass.xorg_file = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.xorg_file.close() klass.amd_pcsdb_file = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.amd_pcsdb_file.close() klass.fake_lspci = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.fake_lspci.close() klass.fake_modules = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.fake_modules.close() klass.fake_alternatives = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.fake_alternatives.close() klass.fake_dmesg = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.fake_dmesg.close() klass.prime_settings = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.prime_settings.close() klass.bbswitch_path = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.bbswitch_path.close() klass.bbswitch_quirks_path = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.bbswitch_quirks_path.close() klass.dmi_product_version_path = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.dmi_product_version_path.close() klass.log = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.log.close() klass.valgrind_log = tempfile.NamedTemporaryFile(mode='w', dir=tests_path, delete=False) klass.valgrind_log.close() # Patterns klass.is_driver_loaded_pt = re.compile('Is (.+) loaded\? (.+)') klass.is_driver_unloaded_pt = re.compile('Was (.+) unloaded\? (.+)') klass.is_driver_enabled_pt = re.compile('Is (.+) enabled\? (.+)') klass.has_card_pt = re.compile('Has (.+)\? (.+)') klass.single_card_pt = re.compile('Single card detected.*') klass.requires_offloading_pt = re.compile('Does it require offloading\? (.+)') klass.no_change_stop_pt = re.compile('No change - nothing to do') klass.has_changed_pt = re.compile('Has the system changed\? (.+)') klass.selected_driver_pt = re.compile('Selecting (.+)') klass.removed_xorg_pt = re.compile('Removing xorg.conf. Path: .+') klass.regenerated_xorg_pt = re.compile('Regenerating xorg.conf. Path: .+') klass.not_modified_xorg_pt = re.compile('No need to modify xorg.conf. Path .+') klass.no_action_pt = re.compile('Nothing to do') klass.has_skipped_hybrid_pt = re.compile('Lightdm is not the default display manager. Nothing to do') klass.loaded_and_enabled_pt = re.compile('Driver is already loaded and enabled') klass.proprietary_installer_pt = re.compile('Proprietary driver installer detected.*') klass.matched_quirk_pt = re.compile('Found matching quirk.*') klass.loaded_with_args_pt = re.compile('Loading (.+) with \"(.+)\" parameters.*') klass.vendors = {'amd': 0x1002, 'nvidia': 0x10de, 'intel': 0x8086, 'unknown': 0x1016} klass.fake_alternative = '' def setUp(self): ''' self.last_boot_file = open(self.last_boot_file.name, 'w') self.fake_lspci = open(self.fake_lspci.name, 'w') self.fake_modules = open(self.fake_modules.name, 'w') self.fake_alternatives = open(self.fake_alternatives.name, 'w') ''' self.remove_xorg_conf() self.remove_amd_pcsdb_file() def tearDown(self): print(self.this_function_name, 'over') # Remove all the logs self.handle_logs(delete=True) def cp_to_target_dir(self, filename): try: shutil.copy(filename, self.target_dir) except: pass def remove_xorg_conf(self): try: os.unlink(self.xorg_file.name) except: pass def remove_amd_pcsdb_file(self): try: os.unlink(self.amd_pcsdb_file.name) except: pass def remove_prime_files(self): for elem in (self.prime_settings, self.bbswitch_path, self.bbswitch_quirks_path, self.dmi_product_version_path): try: os.unlink(elem.name) except: pass def remove_fake_dmesg(self): try: os.unlink(self.fake_dmesg.name) except: pass def remove_valgrind_log(self): try: os.unlink(self.valgrind_log.name) except: pass def handle_logs(self, delete=False, copy=False): if tests_path: self.target_dir = os.path.join(tests_path, self.this_function_name) try: os.mkdir(self.target_dir) except: pass for file in (self.last_boot_file, self.new_boot_file, self.fake_lspci, self.fake_modules, self.fake_alternatives, self.fake_dmesg, self.prime_settings, self.bbswitch_path, self.bbswitch_quirks_path, self.dmi_product_version_path, self.log, self.xorg_file, self.amd_pcsdb_file, self.valgrind_log): try: file.close() except: pass if copy: # Copy to target dir self.cp_to_target_dir(file.name) if delete: try: # Remove os.unlink(file.name) except: pass def exec_manager(self, requires_offloading=False, uses_lightdm=True): fake_requires_offloading = requires_offloading and '--fake-requires-offloading' or '--fake-no-requires-offloading' if with_valgrind: valgrind = ['valgrind', '--tool=memcheck', '--leak-check=full', '--show-reachable=yes', '--log-file=%s' % self.valgrind_log.name, '--'] else: valgrind = [] command = ['share/hybrid/gpu-manager', '--dry-run', '--last-boot-file', self.last_boot_file.name, '--fake-lspci', self.fake_lspci.name, '--xorg-conf-file', self.xorg_file.name, '--amd-pcsdb-file', self.amd_pcsdb_file.name, '--fake-alternative', self.fake_alternative, '--fake-modules-path', self.fake_modules.name, '--fake-alternatives-path', self.fake_alternatives.name, '--fake-dmesg-path', self.fake_dmesg.name, '--prime-settings', self.prime_settings.name, '--bbswitch-path', self.bbswitch_path.name, '--bbswitch-quirks-path', self.bbswitch_quirks_path.name, '--dmi-product-version-path', self.dmi_product_version_path.name, '--new-boot-file', self.new_boot_file.name, fake_requires_offloading, '--log', self.log.name] if uses_lightdm: command.append('--fake-lightdm') if valgrind: # Prepend the valgrind arguments command[:0] = valgrind #devnull = open('/dev/null', 'w') #p1 = subprocess.Popen(command, stdout=devnull, # stderr=devnull, universal_newlines=True) #print ' '.join(command) os.system(' '.join(command)) #p1 = subprocess.Popen(command, universal_newlines=True) #p = p1.communicate()[0] #devnull.close() if valgrind: self.valgrind_log = open(self.valgrind_log.name, 'r') errors_pt = re.compile('(.+) ERROR SUMMARY: (.+) errors from (.+) ' 'contexts (suppressed: .+ from .+).*') for line in self.valgrind_log.readlines(): errors = errors_pt.match(line) if errors: if errors.group(2) != 0: self.valgrind_log = open(self.valgrind_log.name, 'w') self.valgrind_log.write(''.join(c, '\n')) self.valgrind_log.close() # Copy the logs self.handle_logs(copy=True) return False self.valgrind_log.close() return True def check_vars(self, *args, **kwargs): gpu_test = GpuTest(**kwargs) # Open the log for reading log = open(self.log.name, 'r') # Look for clues in the log for line in log.readlines(): has_card = self.has_card_pt.match(line) is_driver_loaded = self.is_driver_loaded_pt.match(line) is_driver_unloaded = self.is_driver_unloaded_pt.match(line) is_driver_enabled = self.is_driver_enabled_pt.match(line) loaded_and_enabled = self.loaded_and_enabled_pt.match(line) matched_quirk = self.matched_quirk_pt.match(line) loaded_with_args = self.loaded_with_args_pt.match(line) single_card = self.single_card_pt.match(line) offloading = self.requires_offloading_pt.match(line) no_change_stop = self.no_change_stop_pt.match(line) has_changed = self.has_changed_pt.match(line) removed_xorg = self.removed_xorg_pt.match(line) regenerated_xorg = self.regenerated_xorg_pt.match(line) not_modified_xorg = self.not_modified_xorg_pt.match(line) selected_driver = self.selected_driver_pt.match(line) no_action = self.no_action_pt.match(line) has_skipped_hybrid = self.has_skipped_hybrid_pt.match(line) proprietary_installer = self.proprietary_installer_pt.match(line) # Detect the vendor if has_changed: gpu_test.has_changed = (has_changed.group(1).strip().lower() == 'yes') elif has_card: if has_card.group(1).strip().lower() == 'nvidia': gpu_test.has_nvidia = (has_card.group(2).strip().lower() == 'yes') elif has_card.group(1).strip().lower() == 'intel': gpu_test.has_intel = (has_card.group(2).strip().lower() == 'yes') elif has_card.group(1).strip().lower() == 'amd': gpu_test.has_amd = (has_card.group(2).strip().lower() == 'yes') # Detect the kernel modules elif is_driver_loaded: if is_driver_loaded.group(1).strip().lower() == 'nouveau': gpu_test.nouveau_loaded = (is_driver_loaded.group(2).strip().lower() == 'yes') elif is_driver_loaded.group(1).strip().lower() == 'nvidia': gpu_test.nvidia_loaded = (is_driver_loaded.group(2).strip().lower() == 'yes') elif is_driver_loaded.group(1).strip().lower() == 'intel': gpu_test.intel_loaded = (is_driver_loaded.group(2).strip().lower() == 'yes') elif is_driver_loaded.group(1).strip().lower() == 'radeon': gpu_test.radeon_loaded = (is_driver_loaded.group(2).strip().lower() == 'yes') elif is_driver_loaded.group(1).strip().lower() == 'fglrx': gpu_test.fglrx_loaded = (is_driver_loaded.group(2).strip().lower() == 'yes') elif is_driver_unloaded: if is_driver_unloaded.group(1).strip().lower() == 'nouveau': gpu_test.nouveau_unloaded = (is_driver_unloaded.group(2).strip().lower() == 'yes') elif is_driver_unloaded.group(1).strip().lower() == 'nvidia': gpu_test.nvidia_unloaded = (is_driver_unloaded.group(2).strip().lower() == 'yes') elif is_driver_unloaded.group(1).strip().lower() == 'intel': gpu_test.intel_unloaded = (is_driver_unloaded.group(2).strip().lower() == 'yes') elif is_driver_unloaded.group(1).strip().lower() == 'radeon': gpu_test.radeon_unloaded = (is_driver_unloaded.group(2).strip().lower() == 'yes') elif is_driver_unloaded.group(1).strip().lower() == 'fglrx': gpu_test.fglrx_unloaded = (is_driver_unloaded.group(2).strip().lower() == 'yes') # Detect the alternative elif is_driver_enabled: if is_driver_enabled.group(1).strip().lower() == 'nvidia': gpu_test.nvidia_enabled = (is_driver_enabled.group(2).strip().lower() == 'yes') elif is_driver_enabled.group(1).strip().lower() == 'fglrx': gpu_test.fglrx_enabled = (is_driver_enabled.group(2).strip().lower() == 'yes') elif is_driver_enabled.group(1).strip().lower() == 'mesa': gpu_test.mesa_enabled = (is_driver_enabled.group(2).strip().lower() == 'yes') elif is_driver_enabled.group(1).strip().lower() == 'prime': gpu_test.prime_enabled = (is_driver_enabled.group(2).strip().lower() == 'yes') elif is_driver_enabled.group(1).strip().lower() == 'pxpress': gpu_test.pxpress_enabled = (is_driver_enabled.group(2).strip().lower() == 'yes') elif single_card: gpu_test.has_single_card = True elif offloading: gpu_test.requires_offloading = (offloading.group(1).strip().lower() == 'yes') elif no_change_stop: #gpu_test.has_changed = False gpu_test.has_not_acted = True elif no_action: gpu_test.has_not_acted = True elif removed_xorg: gpu_test.has_removed_xorg = True # This is an action gpu_test.has_not_acted = False elif regenerated_xorg: gpu_test.has_regenerated_xorg = True # This is an action gpu_test.has_not_acted = False elif not_modified_xorg: gpu_test.has_removed_xorg = False gpu_test.has_regenerated_xorg = False elif selected_driver: gpu_test.has_selected_driver = True # This is an action gpu_test.has_not_acted = False elif has_skipped_hybrid: gpu_test.has_skipped_hybrid = True gpu_test.has_not_acted = True elif loaded_and_enabled: gpu_test.has_selected_driver = False elif proprietary_installer: gpu_test.proprietary_installer = True elif matched_quirk: gpu_test.matched_quirk = True elif loaded_with_args: if (loaded_with_args.group(1) == 'bbswitch' and loaded_with_args.group(2) != 'no'): gpu_test.loaded_with_args = True # Close the log log.close() # No driver selection and no changes to xorg.conf if (not gpu_test.has_selected_driver and (not gpu_test.has_removed_xorg and not gpu_test.has_regenerated_xorg)): gpu_test.has_not_acted = True # Copy the logs if tests_path: self.handle_logs(copy=True, delete=True) # Remove xorg.conf self.remove_xorg_conf() # Remove fake dmesg self.remove_fake_dmesg() # Remove amd_pcsdb_file self.remove_amd_pcsdb_file() # Remove files for PRIME self.remove_prime_files() # Remove the valgrind log self.remove_valgrind_log() return gpu_test def _add_pci_ids(self, ids): if ids: self.fake_lspci = open(self.fake_lspci.name, 'w') for item in ids: self.fake_lspci.write(item) self.fake_lspci.close() def _add_pci_ids_from_last_boot(self, ids): if ids: self.last_boot_file = open(self.last_boot_file.name, 'w') for item in ids: self.last_boot_file.write(item) self.last_boot_file.close() def _get_cards_from_list(self, cards, bump_boot_vga_device_id=False, bump_discrete_device_id=False): cards_list = [] it = 0 boot_vga_device_id = 0x68d8 discrete_device_id = 0x28e8 for card in cards: card_line = '%04x:%04x;0000:%02d:%02d:0;%d\n' % (self.vendors.get(card), ((it == 0) and (bump_boot_vga_device_id and boot_vga_device_id + 1 or boot_vga_device_id) or (bump_discrete_device_id and discrete_device_id + 1 or discrete_device_id)), (it == 0) and 0 or it, (it == 0) and 1 or 0, (it == 0) and 1 or 0) cards_list.append(card_line) it += 1 return cards_list def set_current_cards(self, cards, bump_boot_vga_device_id=False, bump_discrete_device_id=False): '''Set the current cards in the system cards is a list of cards such as ["intel", "nvidia"]. The first cards on the list gets to be the boot_vga one.''' cards_list = self._get_cards_from_list(cards, bump_boot_vga_device_id, bump_discrete_device_id) self._add_pci_ids(cards_list) def set_cards_from_last_boot(self, cards): '''Set the cards in the system from last boot cards is a list of cards such as ["intel", "nvidia"]. The first cards on the list gets to be the boot_vga one.''' cards_list = self._get_cards_from_list(cards) self._add_pci_ids_from_last_boot(cards_list) def add_kernel_modules(self, modules): if modules: self.fake_modules = open(self.fake_modules.name, 'w') for item in modules: line = '%s 1447330 3 - Live 0x0000000000000000\n' % item self.fake_modules.write(line) self.fake_modules.close() def request_prime_discrete_on(self, is_on=True): '''Request that discrete is switched on or off''' self.prime_settings = open(self.prime_settings.name, 'w') self.prime_settings.write(is_on and 'ON' or 'OFF') self.prime_settings.close() def set_prime_discrete_default_status_on(self, is_on=True): '''Sets the default status of the discrete card in bbswitch''' self.bbswitch_path = open(self.bbswitch_path.name, 'w') self.bbswitch_path.write('0000:01:00.0 %s\n' % (is_on and 'ON' or 'OFF')) self.bbswitch_path.close() def set_dmi_product_version(self, label): '''Set dmi product version''' self.dmi_product_version_path = open(self.dmi_product_version_path.name, 'w') self.dmi_product_version_path.write('%s\n' % label) self.dmi_product_version_path.close() def set_bbswitch_quirks(self): '''Set bbswitch quirks''' self.bbswitch_quirks_path = open(self.bbswitch_quirks_path.name, 'w') self.bbswitch_quirks_path.write(''' "ThinkPad T410" "skip_optimus_dsm=1" "ThinkPad T410s" "skip_optimus_dsm=1" ''') self.bbswitch_quirks_path.close() def set_unloaded_module_in_dmesg(self, module): if module: self.fake_dmesg = open(self.fake_dmesg.name, 'w') if module == 'nvidia': self.fake_dmesg.write('[ 18.017267] nvidia: module license ' '\'NVIDIA\' taints kernel.\n') self.fake_dmesg.write('[ 18.019886] nvidia: module verification ' 'failed: signature and/or required key ' 'missing - tainting kernel\n') self.fake_dmesg.write('[ 18.022845] nvidia 0000:01:00.0: ' 'enabling device (0000 -> 0003)\n') self.fake_dmesg.write('[ 18.689111] [drm] Initialized nvidia-drm ' '0.0.0 20130102 for 0000:01:00.0 on minor 1\n') self.fake_dmesg.write('[ 35.604564] init: Failed to spawn ' 'nvidia-persistenced main process: unable to ' 'execute: No such file or directory\n') elif module == 'fglrx': self.fake_dmesg.write('fglrx: module license \'Proprietary. (C) 2002 - ' 'ATI Technologies, Starnberg, GERMANY\' taints kernel.') self.fake_dmesg.write('[ 23.462986] fglrx_pci 0000:01:00.0: ' 'Max Payload Size 16384, but upstream 0000:00:01.0 ' 'set to 128; if necessary, use "pci=pcie_bus_safe" ' 'and report a bug\n') self.fake_dmesg.write('[ 23.462994] fglrx_pci 0000:01:00.0: no hotplug ' 'settings from platform\n') self.fake_dmesg.write('[ 23.467552] waiting module removal not supported: ' 'please upgrade<6>[fglrx] module unloaded - fglrx ' '13.35.5 [Jan 29 2014]\n') else: self.fake_dmesg.write('[ 23.462972] %s: module license ' '\'Proprietary. (C) blah blah\'\n' % module) self.fake_dmesg.close() def set_params(self, last_boot, current_boot, loaded_modules, available_drivers, enabled_driver, unloaded_module='', proprietary_installer=False, matched_quirk=False, loaded_with_quirk=False, bump_boot_vga_device_id=False, bump_discrete_device_id=False): # Last boot self.set_cards_from_last_boot(last_boot) # Current boot self.set_current_cards(current_boot, bump_boot_vga_device_id, bump_discrete_device_id) # Kernel modules self.add_kernel_modules(loaded_modules) # Optional unloaded kernel module if unloaded_module: self.set_unloaded_module_in_dmesg(unloaded_module) # Available alternatives self.fake_alternatives = open(self.fake_alternatives.name, 'w') if 'mesa' in available_drivers: self.fake_alternatives.write('/usr/lib/x86_64-linux-gnu/mesa/ld.so.conf\n') # Only one of these at a time if 'nvidia' in available_drivers: self.fake_alternatives.write('/usr/lib/nvidia-331-updates-prime/ld.so.conf\n') self.fake_alternatives.write('/usr/lib/nvidia-331-updates/ld.so.conf\n') elif 'fglrx' in available_drivers: self.fake_alternatives.write('/usr/lib/fglrx/ld.so.conf\n') self.fake_alternatives.write('/usr/lib/pxpress/ld.so.conf\n') else: for driver in available_drivers: self.fake_alternatives.write('/usr/lib/x86_64-linux-gnu/%s/ld.so.conf\n' % (driver)) self.fake_alternatives.close() # The selected alternative if enabled_driver == 'mesa': self.fake_alternative = '/usr/lib/x86_64-linux-gnu/mesa/ld.so.conf' elif enabled_driver == 'nvidia': self.fake_alternative = '/usr/lib/nvidia-331-updates/ld.so.conf' elif enabled_driver == 'fglrx': self.fake_alternative = '/usr/lib/fglrx/ld.so.conf' elif enabled_driver == 'prime': self.fake_alternative = '/usr/lib/nvidia-331-updates-prime/ld.so.conf' elif enabled_driver == 'pxpress': self.fake_alternative = '/usr/lib/pxpress/ld.so.conf' else: self.fake_alternative = '/usr/lib/x86_64-linux-gnu/%s/ld.so.conf' % (enabled_driver) def run_manager_and_get_data(self, last_boot, current_boot, loaded_modules, available_drivers, enabled_driver, unloaded_module='', requires_offloading=False, proprietary_installer=False, matched_quirk=False, loaded_with_quirk=False, bump_boot_vga_device_id=False, bump_discrete_device_id=False): self.set_params(last_boot, current_boot, loaded_modules, available_drivers, enabled_driver, unloaded_module, proprietary_installer, matched_quirk, loaded_with_quirk, bump_boot_vga_device_id, bump_discrete_device_id) # Call the program self.exec_manager(requires_offloading=requires_offloading) # Return data return self.check_vars() def test_one_intel_no_change(self): '''intel -> intel''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel'], ['i915-brw'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # No change self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action self.assertTrue(gpu_test.has_not_acted) def test_one_nvidia_binary_no_change(self): '''nvidia -> nvidia''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['nvidia'], ['nvidia'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables self.assertTrue(gpu_test.has_single_card) # Check if laptop self.assertTrue(gpu_test.requires_offloading) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # No open! self.assertFalse(gpu_test.nouveau_loaded) # No change self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action self.assertTrue(gpu_test.has_not_acted) def test_one_nvidia_open_no_change(self): '''nvidia (nouveau) -> nvidia (nouveau)''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['nvidia'], ['nouveau'], ['mesa'], 'mesa') # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nvidia_enabled) # Open driver only! self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.mesa_enabled) # No change self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action self.assertTrue(gpu_test.has_not_acted) def test_one_amd_binary_no_change(self): '''fglrx -> fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) # No radeon self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.nouveau_loaded) # No change self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action self.assertTrue(gpu_test.has_not_acted) # What if the kernel module wasn't built # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) # No radeon self.assertFalse(gpu_test.radeon_loaded) # fglrx is not loaded self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.nouveau_loaded) # No change self.assertFalse(gpu_test.has_changed) # Select fallback and remove xorg.conf self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # Fallback action self.assertFalse(gpu_test.has_not_acted) def test_one_amd_open_no_change(self): '''radeon -> radeon''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['radeon'], ['mesa'], 'mesa') # Check the variables self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) # No fglrx self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.nouveau_loaded) # No change self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action self.assertTrue(gpu_test.has_not_acted) def test_one_intel_to_nvidia_binary(self): '''intel -> nvidia''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['nvidia'], ['nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # We are going to enable nvidia self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # Action is required # We enable nvidia self.assertFalse(gpu_test.has_not_acted) # Let's try again, only this time it's all # already in place gpu_test = self.run_manager_and_get_data(['intel'], ['nvidia'], ['nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # We are going to enable nvidia self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # Action is required # We enable nvidia self.assertFalse(gpu_test.has_not_acted) # What if the driver is enabled but the kernel # module is not there? # # The binary driver is not there # whereas the open driver is blacklisted # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['nvidia'], ['fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) #The open driver is blacklisted self.assertFalse(gpu_test.nouveau_loaded) # No kenrel module self.assertFalse(gpu_test.nvidia_loaded) # The driver is enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We should switch to mesa self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_intel_to_nvidia_open(self): '''intel -> nouveau''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['nvidia'], ['nouveau'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_intel_to_amd_open(self): '''intel -> radeon''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['amd'], ['radeon'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_intel_to_amd_binary(self): '''intel -> fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['amd'], ['fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # We are going to enable fglrx self.assertFalse(gpu_test.fglrx_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # Action is required # We enable fglrx self.assertFalse(gpu_test.has_not_acted) # Let's try again, only this time it's all # already in place # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['amd'], ['fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # We don't need to enable fglrx again self.assertTrue(gpu_test.fglrx_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # Action is not required self.assertFalse(gpu_test.has_not_acted) # What if the driver is enabled but the kernel # module is not there? # # The binary driver is not there # whereas the open driver is blacklisted # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['amd'], ['fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) #The open driver is blacklisted self.assertFalse(gpu_test.radeon_loaded) # No kernel module self.assertFalse(gpu_test.fglrx_loaded) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.fglrx_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # We should switch to mesa self.assertFalse(gpu_test.has_not_acted) def test_one_amd_open_to_intel(self): '''radeon -> intel''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['intel'], ['i915'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # No need to do anything else self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_open_to_nvidia_open(self): '''radeon -> nouveau''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['nouveau'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # No need to do anything else self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_open_to_nvidia_binary(self): '''radeon -> nouveau''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # Let's try again, only this time it's all # already in place # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # No need to do anything else self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # What if the driver is enabled but the kernel # module is not there? # # The binary driver is not there # whereas the open driver is blacklisted # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) #The open driver is blacklisted self.assertFalse(gpu_test.nouveau_loaded) # No kenrel module self.assertFalse(gpu_test.nvidia_loaded) # The driver is enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We should switch to mesa self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_binary_to_intel(self): '''fglrx -> intel''' self.this_function_name = sys._getframe().f_code.co_name # User removed the discrete card without # uninstalling the binary driver and somehow # the kernel module is still loaded # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) # The binary driver is loaded and enabled self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User removed the discrete card without # uninstalling the binary driver # the kernel module is no longer loaded # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['intel'], ['i915'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) # The kernel module of the binary driver # is not loaded self.assertFalse(gpu_test.fglrx_loaded) # The binary driver is still enabled self.assertTrue(gpu_test.fglrx_enabled) # NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_binary_to_nvidia_open(self): '''fglrx -> nouveau''' self.this_function_name = sys._getframe().f_code.co_name # User swapped the discrete card with # a discrete card from another vendor # without uninstalling the binary driver # the kernel module is still loaded # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['nouveau', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) # The binary driver is loaded and enabled self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User swapped the discrete card with # a discrete card from another vendor # without uninstalling the binary driver # the kernel module is no longer loaded # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['nouveau'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) # The kernel module of the binary driver # is not loaded self.assertFalse(gpu_test.fglrx_loaded) # The binary driver is still enabled self.assertTrue(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_binary_to_nvidia_binary(self): '''fglrx -> nvidia''' self.this_function_name = sys._getframe().f_code.co_name # User swapped the discrete card with # a discrete card from another vendor # and installed the new binary driver # however the kernel module wasn't built # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['fake', 'fake_alt'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User swapped the discrete card with # a discrete card from another vendor # and installed the new binary driver # correctly # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['nvidia'], ['fake', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # No need to select the driver self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_open_to_amd_binary(self): '''radeon -> fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fglrx', 'fake_alt'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertFalse(gpu_test.has_selected_driver) self.assertTrue(gpu_test.has_not_acted) # Different card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fglrx', 'fake_alt'], ['mesa', 'fglrx'], 'fglrx', bump_boot_vga_device_id=True) # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) # We remove the xorg.conf self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # What if the module was not built? # Same card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fake', 'fake_alt'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) # Move away xorg.conf if falling back self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver (fallback) self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # Different card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fake', 'fake_alt'], ['mesa', 'fglrx'], 'fglrx', bump_boot_vga_device_id=True) # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) # We remove the xorg.conf self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver (fallback) self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_amd_binary_to_amd_open(self): '''fglrx -> radeon''' self.this_function_name = sys._getframe().f_code.co_name # Same card # Case 1: fglrx is still installed and in use # the user switched to mesa without # uninstalling fglrx # The module was built # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fglrx', 'fake_alt'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver # We switch back to fglrx self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # Different card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['fglrx', 'fake_alt'], ['mesa', 'fglrx'], 'mesa', bump_boot_vga_device_id=True) # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) # We remove the xorg.conf self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # Case 2: fglrx was removed # Same card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['radeon', 'fake_alt'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) # Don't touch xorg.conf self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Nothing to select self.assertFalse(gpu_test.has_selected_driver) self.assertTrue(gpu_test.has_not_acted) # Different card # Collect data gpu_test = self.run_manager_and_get_data(['amd'], ['amd'], ['radeon', 'fake_alt'], ['mesa'], 'mesa', bump_boot_vga_device_id=True) # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) # We remove the xorg.conf self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Nothing to select self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_open_to_intel(self): '''nouveau -> intel''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['intel'], ['i915'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_open_to_amd_open(self): '''nouveau -> radeon''' self.this_function_name = sys._getframe().f_code.co_name # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_open_to_amd_binary(self): '''nouveau -> fglrx''' self.this_function_name = sys._getframe().f_code.co_name # No kernel module # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # What if fglrx is enabled? (no kernel module) # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the fallback self.assertTrue(gpu_test.has_selected_driver) # Action is required self.assertFalse(gpu_test.has_not_acted) # What if kernel module is available and mesa is enabled? # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) # Action is required self.assertFalse(gpu_test.has_not_acted) # What if kernel module is available and fglrx is enabled? # fglrx enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is still enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_binary_to_intel(self): '''nvidia -> intel''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: nvidia loaded and enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # nvidia is still enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # Action is required # We enable mesa self.assertFalse(gpu_test.has_not_acted) # Case 2: nvidia loaded and not enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # nvidia is not enabled self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3: nvidia not loaded and enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) # nvidia is still enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 4: nvidia not loaded and not enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) # nvidia is not enabled self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_binary_to_amd_open(self): '''nvidia -> radeon''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: nvidia loaded and enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # nvidia is still enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # Action is required # We enable mesa self.assertFalse(gpu_test.has_not_acted) # Case 2: nvidia loaded and not enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) # nvidia is not enabled self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3: nvidia not loaded and enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) # nvidia is still enabled self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 4: nvidia not loaded and not enabled # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) #No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) # nvidia is not enabled self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_one_nvidia_binary_to_amd_binary(self): '''nvidia -> fglrx''' self.this_function_name = sys._getframe().f_code.co_name # User swapped the discrete card with # a discrete card from another vendor # and installed the new binary driver # however the kernel module wasn't built # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fake', 'fake_alt'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User swapped the discrete card with # a discrete card from another vendor # and installed the new binary driver # correctly # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['fake', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # No need to select the driver self.assertFalse(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User swapped the discrete card with # a discrete card from another vendor # but did not install the new binary driver # The kernel module is still loaded. # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver (fallback) self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) # User swapped the discrete card with # a discrete card from another vendor # but did not install the new binary driver # The kernel module is no longer loaded. # Collect data gpu_test = self.run_manager_and_get_data(['nvidia'], ['amd'], ['radeon', 'fake_alt'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select the driver (fallback) self.assertTrue(gpu_test.has_selected_driver) self.assertFalse(gpu_test.has_not_acted) def test_laptop_one_intel_one_amd_open(self): '''laptop: intel + radeon''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: the discrete card is now available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'radeon'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2: the discrete card was already available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'radeon'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action is required self.assertTrue(gpu_test.has_not_acted) # Case 3: the discrete card is no longer available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_intel_one_amd_open(self): '''desktop: intel + radeon''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: the discrete card is now available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'radeon'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2: the discrete card was already available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'radeon'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action is required self.assertTrue(gpu_test.has_not_acted) # Case 3: the discrete card is no longer available (BIOS) # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_laptop_one_intel_one_amd_binary(self): '''laptop: intel + fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's create an amdpcsdb file where the discrete # GPU is enabled self.amd_pcsdb_file = open(self.amd_pcsdb_file.name, 'w') self.amd_pcsdb_file.write(''' FAKESETTINGS=BLAH FAKEGPUSETTINGS=BLAHBLAH''') self.amd_pcsdb_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's create an amdpcsdb file where the discrete # GPU is enabled, only this time xorg.conf is wrong self.amd_pcsdb_file = open(self.amd_pcsdb_file.name, 'w') self.amd_pcsdb_file.write(''' FAKESETTINGS=BLAH FAKEGPUSETTINGS=BLAHBLAH''') self.amd_pcsdb_file.close() self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "ServerLayout" Identifier "aticonfig Layout" Screen 0 "aticonfig-Screen[0]-0" 0 0 EndSection Section "Module" EndSection Section "Monitor" Identifier "aticonfig-Monitor[0]-0" Option "VendorName" "ATI Proprietary Driver" Option "ModelName" "Generic Autodetecting Monitor" Option "DPMS" "true" EndSection Section "Device" Identifier "aticonfig-Device[0]-0" Driver "fglrx" BusID "PCI:1:0:0" EndSection Section "Device" Identifier "intel" Driver "intel" Option "AccelMethod" "uxa" EndSection Section "Screen" Identifier "aticonfig-Screen[0]-0" Device "aticonfig-Device[0]-0" Monitor "aticonfig-Monitor[0]-0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 24 EndSubSection EndSection ''') self.xorg_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's create an amdpcsdb file where the discrete # GPU is enabled, only this time xorg.conf is correct self.amd_pcsdb_file = open(self.amd_pcsdb_file.name, 'w') self.amd_pcsdb_file.write(''' FAKESETTINGS=BLAH FAKEGPUSETTINGS=BLAHBLAH''') self.amd_pcsdb_file.close() self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "ServerLayout" Identifier "aticonfig Layout" Screen 0 "aticonfig-Screen[0]-0" 0 0 EndSection Section "Module" EndSection Section "Monitor" Identifier "aticonfig-Monitor[0]-0" Option "VendorName" "ATI Proprietary Driver" Option "ModelName" "Generic Autodetecting Monitor" Option "DPMS" "true" EndSection Section "Device" Identifier "aticonfig-Device[0]-0" Driver "fglrx" BusID "PCI:1:0:0" EndSection Section "Device" Identifier "intel" Driver "intel" Option "AccelMethod" "uxa" BusID "PCI:0@0:1:0" EndSection Section "Screen" Identifier "aticonfig-Screen[0]-0" Device "aticonfig-Device[0]-0" Monitor "aticonfig-Monitor[0]-0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 24 EndSubSection EndSection ''') self.xorg_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Has changed self.assertTrue(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # Let's create an amdpcsdb file where the discrete # GPU is disabled, and xorg.conf is correct self.amd_pcsdb_file = open(self.amd_pcsdb_file.name, 'w') self.amd_pcsdb_file.write(''' FAKESETTINGS=BLAH FAKEGPUSETTINGS=BLAHBLAH PX_GPUDOWN=R00010000''') self.amd_pcsdb_file.close() self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "ServerLayout" Identifier "aticonfig Layout" Screen 0 "aticonfig-Screen[0]-0" 0 0 EndSection Section "Module" EndSection Section "Monitor" Identifier "aticonfig-Monitor[0]-0" Option "VendorName" "ATI Proprietary Driver" Option "ModelName" "Generic Autodetecting Monitor" Option "DPMS" "true" EndSection Section "Device" Identifier "aticonfig-Device[0]-0" Driver "fglrx" BusID "PCI:1:0:0" EndSection Section "Device" Identifier "intel" Driver "intel" Option "AccelMethod" "uxa" BusID "PCI:0@0:1:0" EndSection Section "Screen" Identifier "aticonfig-Screen[0]-0" Device "aticonfig-Device[0]-0" Monitor "aticonfig-Monitor[0]-0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 24 EndSubSection EndSection ''') self.xorg_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Has changed self.assertTrue(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We should select pxpress here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # Let's create a case where the discrete # GPU is disabled, fglrx was unloaded, and xorg.conf # is correct # Only intel should show up self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "ServerLayout" Identifier "aticonfig Layout" Screen 0 "aticonfig-Screen[0]-0" 0 0 EndSection Section "Module" EndSection Section "Monitor" Identifier "aticonfig-Monitor[0]-0" Option "VendorName" "ATI Proprietary Driver" Option "ModelName" "Generic Autodetecting Monitor" Option "DPMS" "true" EndSection Section "Device" Identifier "aticonfig-Device[0]-0" Driver "fglrx" BusID "PCI:1:0:0" EndSection Section "Device" Identifier "intel" Driver "intel" Option "AccelMethod" "uxa" BusID "PCI:0@0:1:0" EndSection Section "Screen" Identifier "aticonfig-Screen[0]-0" Device "aticonfig-Device[0]-0" Monitor "aticonfig-Monitor[0]-0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 24 EndSubSection EndSection ''') self.xorg_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx', unloaded_module='fglrx', requires_offloading=True) # Check that fglrx was unloaded self.assertTrue(gpu_test.fglrx_unloaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.intel_loaded) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We should select pxpress here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # Let's create a case where the discrete # GPU is disabled, fglrx was unloaded, and xorg.conf # is incorrect self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "ServerLayout" Identifier "aticonfig Layout" Screen 0 "aticonfig-Screen[0]-0" 0 0 EndSection Section "Module" EndSection Section "Monitor" Identifier "aticonfig-Monitor[0]-0" Option "VendorName" "ATI Proprietary Driver" Option "ModelName" "Generic Autodetecting Monitor" Option "DPMS" "true" EndSection Section "Device" Identifier "intel" Driver "intel" Option "AccelMethod" "uxa" BusID "PCI:0@0:1:0" EndSection Section "Screen" Identifier "aticonfig-Screen[0]-0" Device "aticonfig-Device[0]-0" Monitor "aticonfig-Monitor[0]-0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 24 EndSubSection EndSection ''') self.xorg_file.close() # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx', unloaded_module='fglrx', requires_offloading=True) # Check that fglrx was unloaded self.assertTrue(gpu_test.fglrx_unloaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.intel_loaded) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select pxpress here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # pxpress is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # Select fglrx, as the discrete GPU # is not disabled # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # pxpress is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # pxpress is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # pxpress is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # pxpress is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # pxpress is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We should select the driver here # but we won't for now self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (BIOS) # pxpress is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # pxpress is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # pxpress is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_intel_one_amd_binary(self): '''desktop: intel + fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # pxpress is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) # Select fglrx, as the discrete GPU # is not disabled self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # pxpress is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # pxpress is not enabled but the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded # Collect data gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel', 'amd'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'amd'], ['intel'], ['i915', 'fglrx'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_laptop_one_intel_one_nvidia_open(self): '''laptop: intel + nouveau''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: the discrete card is now available (BIOS) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nouveau'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2: the discrete card was already available (BIOS) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nouveau'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action is required self.assertTrue(gpu_test.has_not_acted) # Case 3: the discrete card is no longer available (BIOS) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_intel_one_nvidia_open(self): '''laptop: intel + nouveau''' self.this_function_name = sys._getframe().f_code.co_name # Case 1: the discrete card is now available (BIOS) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nouveau'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2: the discrete card was already available (BIOS) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nouveau'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has not changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No action is required self.assertTrue(gpu_test.has_not_acted) # Case 3: the discrete card is no longer available (BIOS) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is still enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_laptop_one_intel_one_nvidia_binary(self): '''laptop: intel + nvidia''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded # Set dmi product version self.set_dmi_product_version('ThinkPad T410s') # Set default quirks self.set_bbswitch_quirks() # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check quirks self.assertTrue(gpu_test.matched_quirk) self.assertTrue(gpu_test.loaded_with_args) # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed # Enable when we support hybrid laptops self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # What if dmi product version is invalid? # Set dmi product version self.set_dmi_product_version('') # Set default quirks self.set_bbswitch_quirks() # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check quirks self.assertFalse(gpu_test.matched_quirk) self.assertTrue(gpu_test.loaded_with_args) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_unloaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # prime is enabled and the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # prime is enabled but the module is not loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Fall back to mesa self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # prime is not enabled but the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed # Enable when we support hybrid laptops self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # prime is enabled and the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # prime is enabled but the module is not loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Fallback self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # prime is not enabled but the module is loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(True) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # Select PRIME self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (bbswitch) # prime is enabled and the module is not loaded # Set default bbswitch status self.set_prime_discrete_default_status_on(False) # Request action from bbswitch self.request_prime_discrete_on(False) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime', unloaded_module='nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (bbswitch) # prime is enabled and the module is not loaded and # we need to select nvidia for better performance # Set default bbswitch status self.set_prime_discrete_default_status_on(False) # Request action from bbswitch self.request_prime_discrete_on(True) gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime', unloaded_module='nvidia', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3g: the discrete card is no longer available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915'], ['mesa', 'nvidia'], 'prime', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3h: the discrete card is no longer available (BIOS) # prime is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_intel_one_nvidia_binary(self): '''desktop: intel + nvidia''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed # Enable when we support hybrid laptops self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed # Enable when we support hybrid laptops self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # prime is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and correct self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and incorrect self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "fglrx" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel', 'nvidia'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # prime is not enabled but the module is loaded # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'fake'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # prime is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['intel', 'nvidia'], ['intel'], ['i915', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # Intel self.assertTrue(gpu_test.has_intel) self.assertTrue(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertFalse(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_two_amd_binary(self): '''Multiple AMD GPUs fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['old_fake', 'fake'], ['mesa', 'nvidia'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and correct self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 0" BusID "PCI:0@0:1:0" EndSection Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx') # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and incorrect self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "fglrx" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx') # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # pxpress is not enabled but the module is loaded # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_laptop_two_amd_binary(self): '''laptop Multiple AMD GPUs fglrx''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and correct self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 0" BusID "PCI:0@0:1:0" EndSection Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and incorrect self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "fglrx" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # pxpress is not enabled but the module is loaded # Case 3a: the discrete card is no longer available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3b: the discrete card is no longer available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'fglrx', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3c: the discrete card is no longer available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3d: the discrete card is no longer available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3e: the discrete card is no longer available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fake_old', 'fake'], ['mesa', 'fglrx'], 'pxpress', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 3f: the discrete card is no longer available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'amd'], ['amd'], ['fglrx', 'fake'], ['mesa', 'fglrx'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertTrue(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_two_amd_open(self): '''Multiple AMD GPUs radeon''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['radeon', 'fake'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # What if radeon is blacklisted gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We'll probably use vesa + llvmpipe self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_laptop_two_amd_open(self): '''laptop Multiple AMD GPUs radeon''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['radeon', 'fake'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # What if radeon is blacklisted gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'amd'], ['fake_old', 'fake'], ['mesa'], 'mesa', requires_offloading=True) # Check the variables # Check if laptop self.assertTrue(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # No NVIDIA self.assertFalse(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) # We'll probably use vesa + llvmpipe self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_amd_open_one_nvidia_binary(self): self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with a good xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # Let's try again with a good xorg.conf # this time with the driver specified self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "nvidia" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" Driver "fglrx" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf # Wrong BusID self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:0@0:1:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with a good xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with a good xorg.conf # this time with the driver specified self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "nvidia" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" Driver "fglrx" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf # Wrong BusID self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:0@0:1:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with a good xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with a good xorg.conf # this time with the driver specified self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "nvidia" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:1@0:0:0" Driver "fglrx" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Let's try again with an incorrect xorg.conf # Wrong BusID self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" BusID "PCI:0@0:1:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # prime is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'nvidia') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertTrue(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # prime is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['radeon', 'nvidia'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertTrue(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # prime is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['radeon', 'fake'], ['mesa', 'nvidia'], 'prime') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertTrue(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertFalse(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertTrue(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) def test_desktop_one_amd_binary_one_nvidia_open(self): '''Multiple AMD GPUs''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1b: the discrete card is now available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fake_old', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1c: the discrete card is now available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # No AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1d: the discrete card is now available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1e: the discrete card is now available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fake_old', 'nouveau'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 1f: the discrete card is now available (BIOS) # pxpress is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertTrue(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2a: the discrete card was already available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and correct self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 0" BusID "PCI:0@0:1:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertTrue(gpu_test.has_not_acted) # See if it still regenerates xorg.conf if the # file is in place and incorrect self.xorg_file = open(self.xorg_file.name, 'w') self.xorg_file.write(''' Section "Device" Identifier "Default Card 1" Driver "fglrx" BusID "PCI:1@0:0:0" EndSection '''); self.xorg_file.close() gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertFalse(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2b: the discrete card was already available (BIOS) # the driver is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fake_old', 'nouveau'], ['mesa', 'fglrx'], 'fglrx') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertTrue(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2c: the discrete card was already available (BIOS) # the driver is not enabled but the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'mesa') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is enabled self.assertTrue(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertFalse(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2d: the discrete card was already available (BIOS) # pxpress is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fglrx', 'nouveau'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertTrue(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertTrue(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2e: the discrete card was already available (BIOS) # pxpress is enabled but the module is not loaded gpu_test = self.run_manager_and_get_data(['amd', 'nvidia'], ['amd', 'nvidia'], ['fake_old', 'nouveau'], ['mesa', 'fglrx'], 'pxpress') # Check the variables # Check if laptop self.assertFalse(gpu_test.requires_offloading) self.assertFalse(gpu_test.has_single_card) # No Intel self.assertFalse(gpu_test.has_intel) self.assertFalse(gpu_test.intel_loaded) # Mesa is not enabled self.assertFalse(gpu_test.mesa_enabled) # AMD self.assertTrue(gpu_test.has_amd) self.assertFalse(gpu_test.radeon_loaded) self.assertFalse(gpu_test.fglrx_loaded) self.assertFalse(gpu_test.fglrx_enabled) self.assertTrue(gpu_test.pxpress_enabled) # NVIDIA self.assertTrue(gpu_test.has_nvidia) self.assertTrue(gpu_test.nouveau_loaded) self.assertFalse(gpu_test.nvidia_loaded) self.assertFalse(gpu_test.nvidia_enabled) self.assertFalse(gpu_test.prime_enabled) # Has changed self.assertFalse(gpu_test.has_changed) self.assertTrue(gpu_test.has_removed_xorg) self.assertFalse(gpu_test.has_regenerated_xorg) self.assertTrue(gpu_test.has_selected_driver) # No further action is required self.assertFalse(gpu_test.has_not_acted) # Case 2f: the discrete card was already available (BIOS) # pxpress is not enabled but the module is loaded def test_proprietary_installer(self): '''detect proprietary installer''' self.this_function_name = sys._getframe().f_code.co_name # Case 1a: the discrete card is now available (BIOS) # the driver is enabled and the module is loaded gpu_test = self.run_manager_and_get_data(['amd',], ['amd', 'nvidia'], ['fglrx', 'fake'], ['mesa'], 'mesa') self.assertTrue(gpu_test.proprietary_installer) # Let try with nvidia gpu_test = self.run_manager_and_get_data(['amd',], ['amd', 'nvidia'], ['nvidia', 'fake'], ['mesa'], 'mesa') self.assertTrue(gpu_test.proprietary_installer) def test_valid_boot_files(self): self.this_function_name = sys._getframe().f_code.co_name # Invalid boot file self.last_boot_file = open(self.last_boot_file.name, 'w') it = 0 while it < 16: item = 'a' * 200 self.last_boot_file.write(item) it += 1 self.last_boot_file.close() # No Kernel modules self.add_kernel_modules([]) # No available alternatives self.fake_alternatives = open(self.fake_alternatives.name, 'w') self.fake_alternatives.write('') self.fake_alternatives.close() # no selected alternative self.fake_alternative = '' self.exec_manager(requires_offloading=False) # Return data gpu_test = self.check_vars() # Has changed self.assertTrue(gpu_test.has_changed) self.assertFalse(gpu_test.has_selected_driver) # What if there are no graphics cards in the system? self.fake_lspci = open(self.fake_lspci.name, 'w') it = 0 while it < 16: item = 'a' * 200 self.fake_lspci.write(item) it += 1 self.fake_lspci.close() # Invalid boot file self.last_boot_file = open(self.last_boot_file.name, 'w') it = 0 while it < 16: item = 'a' * 200 self.last_boot_file.write(item) it += 1 self.last_boot_file.close() # No Kernel modules self.add_kernel_modules([]) # No available alternatives self.fake_alternatives = open(self.fake_alternatives.name, 'w') self.fake_alternatives.write('') self.fake_alternatives.close() # no selected alternative self.fake_alternative = '' self.exec_manager(requires_offloading=False) # Return data gpu_test = self.check_vars() # Has changed self.assertFalse(gpu_test.has_changed) self.assertFalse(gpu_test.has_selected_driver) if __name__ == '__main__': if not '86' in os.uname()[4]: exit(0) # unittest.main() does its own parsing, therefore we # do our own parsing, then we create a copy of sys.argv where # we remove our custom and unsupported arguments, so that # unittest doesn't complain parser = argparse.ArgumentParser() parser.add_argument('--save-logs-to', help='Path to save logs to') parser.add_argument('--with-valgrind', action="store_true", help='Run the app within valgrind') args = parser.parse_args() tests_path = args.save_logs_to with_valgrind = args.with_valgrind new_argv = [] for elem in sys.argv: if ((elem != '--save-logs-to' and elem != args.save_logs_to) and (elem != '--with-valgrind' and elem != args.with_valgrind)): new_argv.append(elem) unittest.main(argv=new_argv) ubuntu-drivers-common-0.2.91.4/tests/__init__.py0000664000000000000000000000000012322472605016365 0ustar ubuntu-drivers-common-0.2.91.4/tests/0-test.py0000664000000000000000000000160212322472605015753 0ustar #!/usr/bin/python3 # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. def main(): return 0 if __name__ == '__main__': main() ubuntu-drivers-common-0.2.91.4/share/0000775000000000000000000000000012322472605014226 5ustar ubuntu-drivers-common-0.2.91.4/share/obsolete0000664000000000000000000000024212322472605015763 0ustar nvidia-glx nvidia-glx-new nvidia-glx-legacy nvidia-glx-envy nvidia-glx-new-envy nvidia-glx-legacy-envy nvidia-glx-177 nvidia-glx-71 nvidia-glx-190 nvidia-glx-195 ubuntu-drivers-common-0.2.91.4/share/hybrid/0000775000000000000000000000000012322472605015507 5ustar ubuntu-drivers-common-0.2.91.4/share/hybrid/gpu-manager.conf0000664000000000000000000000024012322472605020555 0ustar start on (starting lightdm or starting kdm or starting xdm or starting lxdm) task exec gpu-manager --log /var/log/gpu-manager.log ubuntu-drivers-common-0.2.91.4/share/hybrid/gpu-manager.c0000664000000000000000000030662212322472605020067 0ustar /* gpu-manager: * * Detect the available GPUs and deal with any system changes, whether * software or hardware related * * Authored by: * Alberto Milone * * * Copyright (C) 2014 Canonical Ltd * * Based on code from ./hw/xfree86/common/xf86pciBus.c in xorg-server * Also based on hybrid-detect.c in ubuntu-drivers-common. * * Copyright (c) 1997-2003 by The XFree86 Project, Inc. * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. * * Except as contained in this notice, the name of the copyright holder(s) * and author(s) shall not be used in advertising or otherwise to promote * the sale, use or other dealings in this Software without prior written * authorization from the copyright holder(s) and author(s). * * * Build with `gcc -o gpu-manager gpu-manager.c $(pkg-config --cflags --libs pciaccess libdrm)` */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include "xf86drm.h" #include "xf86drmMode.h" #define PCI_CLASS_DISPLAY 0x03 #define PCI_CLASS_DISPLAY_OTHER 0x0380 #define PCIINFOCLASSES(c) \ ( (((c) & 0x00ff0000) \ == (PCI_CLASS_DISPLAY << 16)) ) #define LAST_BOOT "/var/lib/ubuntu-drivers-common/last_gfx_boot" #define OFFLOADING_CONF "/var/lib/ubuntu-drivers-common/requires_offloading" #define XORG_CONF "/etc/X11/xorg.conf" #define KERN_PARAM "nogpumanager" #define AMD 0x1002 #define INTEL 0x8086 #define NVIDIA 0x10de #define MAX_CARDS_N 10 static char *log_file = NULL; static FILE *log_handle = NULL; static char *last_boot_file = NULL; static char *xorg_conf_file = NULL; static char *amd_pcsdb_file = NULL; static int dry_run = 0; static int fake_lightdm = 0; static char *fake_modules_path = NULL; static char *fake_alternatives_path = NULL; static char *fake_dmesg_path = NULL; static char *prime_settings = NULL; static char *bbswitch_path = NULL; static char *bbswitch_quirks_path = NULL; static char *dmi_product_version_path = NULL; static char *main_arch_path = NULL; static char *other_arch_path = NULL; static struct pci_slot_match match = { PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0 }; struct device { int boot_vga; unsigned int vendor_id; unsigned int device_id; /* BusID components */ unsigned int domain; unsigned int bus; unsigned int dev; unsigned int func; }; struct alternatives { /* These are just to * detect the installer */ int nvidia_available; int fglrx_available; int mesa_available; int pxpress_available; int prime_available; /* The ones that may be enabled */ int nvidia_enabled; int fglrx_enabled; int mesa_enabled; int pxpress_enabled; int prime_enabled; char *current; }; /* Case insensitive equivalent of strstr */ static const char *istrstr(const char *str1, const char *str2) { if (!*str2) { return str1; } for (; *str1; ++str1) { /* Look for the 1st character */ if (toupper(*str1) == toupper(*str2)) { /* We have a match. Let's loop through the * remaining characters. * chr1 belongs to str1, whereas chr2 belongs to str2. */ const char *chr1, *chr2; for (chr1 = str1, chr2 = str2; *chr1 && *chr2; ++chr1, ++chr2) { if (toupper(*chr1) != toupper(*chr2)) { break; } } /* If we have matched all of str2 and we have arrived * at NULL termination, then we're done. * Let's return str1. */ if (!*chr2) { return str1; } } } return NULL; } static int exists_not_empty(const char *file) { struct stat stbuf; /* If file doesn't exist */ if (stat(file, &stbuf) == -1) { fprintf(log_handle, "can't access %s\n", file); return 0; } /* If file is empty */ if ((stbuf.st_mode & S_IFMT) && ! stbuf.st_size) { fprintf(log_handle, "%s is empty\n", file); return 0; } return 1; } /* Get parameters we may need to pass to bbswitch */ static char * get_params_from_quirks() { char *dmi_product_version = NULL; FILE *file; char *params = NULL; char line[1035]; size_t len = 0; char *tok; if (!exists_not_empty(dmi_product_version_path)) { fprintf(log_handle, "Error: %s does not exist or is empty.\n", dmi_product_version_path); } if (!exists_not_empty(bbswitch_quirks_path)) { fprintf(log_handle, "Error: %s does not exist or is empty.\n", bbswitch_quirks_path); } /* get dmi product version */ file = fopen(dmi_product_version_path, "r"); if (file == NULL) { fprintf(log_handle, "can't open %s\n", dmi_product_version_path); return NULL; } if (getline(&dmi_product_version, &len, file) == -1) { fprintf(log_handle, "can't get line from %s\n", dmi_product_version_path); return NULL; } fclose(file); if (dmi_product_version) { /* Remove newline */ len = strlen(dmi_product_version); if(dmi_product_version[len-1] == '\n' ) dmi_product_version[len-1] = 0; /* Look for zero-length dmi_product_version */ if (strlen(dmi_product_version) == 0) { fprintf(log_handle, "Invalid dmi_product_version=\"%s\"\n", dmi_product_version); free(dmi_product_version); return params; } fprintf(log_handle, "dmi_product_version=\"%s\"\n", dmi_product_version); file = fopen(bbswitch_quirks_path, "r"); if (file == NULL) { fprintf(log_handle, "can't open %s\n", bbswitch_quirks_path); free(dmi_product_version); return NULL; } while (fgets(line, sizeof(line), file)) { /* Ignore comments */ if (strstr(line, "#") != NULL) { continue; } if (istrstr(line, dmi_product_version) != NULL) { fprintf(log_handle, "Found matching quirk\n"); tok = strtok(line, "\""); while (tok != NULL) { tok = strtok (NULL, "\""); if (tok && (isspace(tok[0]) == 0)) { params = strdup(tok); break; } } break; } } fclose(file); free(dmi_product_version); } return params; } static int act_upon_module_with_params(const char *module, int mode, char *params) { int status = 0; char command[300]; fprintf(log_handle, "%s %s with \"%s\" parameters\n", mode ? "Loading" : "Unloading", module, params ? params : "no"); if (params) { sprintf(command, "%s %s %s", mode ? "/sbin/modprobe" : "/sbin/rmmod", module, params); free(params); } else { sprintf(command, "%s %s", mode ? "/sbin/modprobe" : "/sbin/rmmod", module); } if (dry_run) return 1; status = system(command); return (status == 0); } /* Load a kernel module and pass it parameters */ static int load_module_with_params(const char *module, char *params) { return (act_upon_module_with_params(module, 1, params)); } /* Load a kernel module */ static int load_module(const char *module) { return (load_module_with_params(module, NULL)); } /* Unload a kernel module */ static int unload_module(const char *module) { return (act_upon_module_with_params(module, 0, NULL)); } /* Load bbswitch and pass some parameters */ static int load_bbswitch() { char *params = NULL; char *temp_params = NULL; char basic[] = "load_state=-1 unload_state=1"; temp_params = get_params_from_quirks(); if (!temp_params) { params = strdup(basic); } else { params = malloc(strlen(temp_params) + strlen(basic) + 2); if (!params) return 0; strcpy(params, basic); strcat(params, " "); strcat(params, temp_params); free(temp_params); } return (load_module_with_params("bbswitch", params)); } /* Get the first match from the output of a command */ static char* get_output(char *command, char *pattern, char *ignore) { int len; char buffer[1035]; char *output = NULL; FILE *pfile = NULL; pfile = popen(command, "r"); if (pfile == NULL) { fprintf(stderr, "Failed to run command %s\n", command); return NULL; } while (fgets(buffer, sizeof(buffer), pfile)) { /* If no search pattern was provided, just * return the first non zero legth line */ if (!pattern) { output = strdup(buffer); break; } else { /* Look for the search pattern */ if (ignore && (strstr(buffer, ignore) != NULL)) { /* Skip this line */ continue; } /* Look for the pattern */ if (strstr(buffer, pattern) != NULL) { output = strdup(buffer); break; } } } pclose(pfile); if (output) { /* Remove newline */ len = strlen(output); if(output[len-1] == '\n' ) output[len-1] = 0; } return output; } static void get_architecture_paths(char **main_arch_path, char **other_arch_path) { char *main_arch = NULL; main_arch = get_output("dpkg --print-architecture", NULL, NULL); if (strcmp(main_arch, "amd64") == 0) { *main_arch_path = strdup("x86_64-linux-gnu"); *other_arch_path = strdup("i386-linux-gnu"); } else if (strcmp(main_arch, "i386") == 0) { *main_arch_path = strdup("i386-linux-gnu"); *other_arch_path = strdup("x86_64-linux-gnu"); } free(main_arch); } /* Get the master link of an alternative */ static char* get_alternative_link(char *arch_path, char *pattern) { char *alternative = NULL; char command[300]; FILE *pfile = NULL; if (dry_run && fake_alternatives_path) { pfile = fopen(fake_alternatives_path, "r"); if (pfile == NULL) { fprintf(stderr, "I couldn't open %s for reading.\n", fake_alternatives_path); return NULL; } while (fgets(command, sizeof(command), pfile)) { /* Make sure we don't catch prime by mistake when * looking for nvidia */ if (strcmp(pattern, "nvidia") == 0) { if (strstr(command, pattern) != NULL) { alternative = strdup(command); break; } } else { if (strstr(command, pattern) != NULL) { alternative = strdup(command); break; } } } fclose(pfile); } else { sprintf(command, "update-alternatives --list %s_gl_conf", arch_path); /* Make sure we don't catch prime by mistake when * looking for nvidia */ if (strcmp(pattern, "nvidia") == 0) alternative = get_output(command, pattern, "prime"); else alternative = get_output(command, pattern, NULL); } return alternative; } /* Look for unloaded modules in dmesg */ static int has_unloaded_module(char *module) { int status = 0; char command[100]; if (dry_run && fake_dmesg_path) { /* Make sure the file exists and is not empty */ if (!exists_not_empty(fake_dmesg_path)) { return 0; } sprintf(command, "grep -q \"%s: module\" %s", module, fake_dmesg_path); status = system(command); fprintf(log_handle, "grep fake dmesg status %d\n", status); } else { sprintf(command, "dmesg | grep -q \"%s: module\"", module); status = system(command); fprintf(log_handle, "grep dmesg status %d\n", status); } fprintf(log_handle, "dmesg status %d == 0? %s\n", status, (status == 0) ? "Yes" : "No"); return (status == 0); } static int find_string_in_file(const char *path, const char *pattern) { FILE *pfile = NULL; char *line = NULL; size_t len = 0; size_t read; int found = 0; pfile = fopen(path, "r"); if (pfile == NULL) return found; while ((read = getline(&line, &len, pfile)) != -1) { if (istrstr(line, pattern) != NULL) { found = 1; break; } } fclose(pfile); if (line) free(line); return found; } /* Check if lightdm is the default login manager */ static int is_lightdm_default() { if (dry_run) return fake_lightdm; return (find_string_in_file("/etc/X11/default-display-manager", "lightdm")); } static void detect_available_alternatives(struct alternatives *info, char *pattern) { if (strstr(pattern, "mesa")) { info->mesa_available = 1; } else if (strstr(pattern, "fglrx")) { info->fglrx_available = 1; } else if (strstr(pattern, "pxpress")) { info->pxpress_available = 1; } else if (strstr(pattern, "nvidia")) { if (strstr(pattern, "prime") != NULL) { info->prime_available = 1; } else { info->nvidia_available = 1; } } } static void detect_enabled_alternatives(struct alternatives *info) { if (strstr(info->current, "mesa") != NULL) { info->mesa_enabled = 1; } else if (strstr(info->current, "fglrx") != NULL) { info->fglrx_enabled = 1; } else if (strstr(info->current, "pxpress") != NULL) { info->pxpress_enabled = 1; } else if (strstr(info->current, "nvidia") != NULL) { if (strstr(info->current, "prime") != NULL) { info->prime_enabled = 1; } else { info->nvidia_enabled = 1; } } } static int get_alternatives(struct alternatives *info, const char *master_link) { int len; char command[200]; char buffer[1035]; FILE *pfile = NULL; char *value = NULL; char *other = NULL; const char ch = '/'; /* Test */ if (fake_alternatives_path) { pfile = fopen(fake_alternatives_path, "r"); /* Set the enabled alternatives in the struct */ detect_enabled_alternatives(info); } else { sprintf(command, "/usr/bin/update-alternatives --query %s_gl_conf", master_link); pfile = popen(command, "r"); if (pfile == NULL) { fprintf(stderr, "Failed to run command: %s\n", command); return 0; } } while (fgets(buffer, sizeof(buffer), pfile) != NULL) { if (strstr(buffer, "Value:")) { value = strchr(buffer, ch); if (value != NULL) { /* If info->current is not NULL, then it's a fake * alternative, which we won't override */ if (!info->current) { info->current = strdup(value); /* Remove newline */ len = strlen(info->current); if(info->current[len-1] == '\n' ) info->current[len-1] = 0; } /* Set the enabled alternatives in the struct */ detect_enabled_alternatives(info); } } else if (strstr(buffer, "Alternative:") || fake_alternatives_path) { other = strchr(buffer, ch); if (other != NULL) { /* Set the available alternatives in the struct */ detect_available_alternatives(info, other); } } } pclose(pfile); return 1; } /* Get the master link of an alternative */ static int set_alternative(char *arch_path, char *alternative) { int status = -1; char command[200]; sprintf(command, "/usr/bin/update-alternatives --set %s_gl_conf %s", arch_path, alternative); if (dry_run) { status = 1; fprintf(log_handle, "%s\n", command); } else { fprintf(log_handle, "%s\n", command); status = system(command); fprintf(log_handle, "update-alternatives status %d\n", status); } if (status == -1) return 0; /* call ldconfig */ if (dry_run) { fprintf(log_handle, "Calling ldconfig\n"); } else { fprintf(log_handle, "Calling ldconfig\n"); status = system("/sbin/ldconfig"); fprintf(log_handle, "ldconfig status %d\n", status); } if (status == -1) return 0; return 1; } static int select_driver(char *driver) { int status = 0; char *alternative = NULL; alternative = get_alternative_link(main_arch_path, driver); if (alternative == NULL) { fprintf(log_handle, "Error: no alternative found for %s\n", driver); } else { /* Set the alternative */ status = set_alternative(main_arch_path, alternative); /* Only for amd64 */ if (status && strcmp(main_arch_path, "x86_64-linux-gnu") == 0) { /* Free the alternative */ free(alternative); alternative = NULL; /* Try to get the alternative for the other architecture */ alternative = get_alternative_link(other_arch_path, driver); if (alternative) { /* No need to check its status */ set_alternative(other_arch_path, alternative); /* Free the alternative */ free(alternative); } } else { /* Free the alternative */ free(alternative); } } return status; } static int is_file_empty(const char *file) { struct stat stbuf; if (stat(file, &stbuf) == -1) { fprintf(log_handle, "can't access %s\n", file); return 0; } if ((stbuf.st_mode & S_IFMT) && ! stbuf.st_size) return 1; return 0; } static int has_cmdline_option(const char *option) { return (find_string_in_file("/proc/cmdline", option)); } static int is_disabled_in_cmdline() { return has_cmdline_option(KERN_PARAM); } /* This is just for writing the BusID of the discrete * card */ static int write_to_xorg_conf(struct device **devices, int cards_n, unsigned int vendor_id) { int i; FILE *pfile = NULL; fprintf(log_handle, "Regenerating xorg.conf. Path: %s\n", xorg_conf_file); pfile = fopen(xorg_conf_file, "w"); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for writing.\n", xorg_conf_file); return 0; } for(i = 0; i < cards_n; i++) { if (devices[i]->vendor_id == vendor_id) { fprintf(pfile, "Section \"Device\"\n" " Identifier \"Default Card %d\"\n" " BusID \"PCI:%d@%d:%d:%d\"\n" "EndSection\n\n", i, (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } } fflush(pfile); fclose(pfile); return 1; } static int write_pxpress_xorg_conf(struct device **devices, int cards_n) { int i; FILE *pfile = NULL; fprintf(log_handle, "Regenerating xorg.conf. Path: %s\n", xorg_conf_file); pfile = fopen(xorg_conf_file, "w"); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for writing.\n", xorg_conf_file); return 0; } fprintf(pfile, "Section \"ServerLayout\"\n" " Identifier \"amd-layout\"\n" " Screen 0 \"amd-screen\" 0 0\n" "EndSection\n\n"); for(i = 0; i < cards_n; i++) { if (devices[i]->vendor_id == INTEL) { fprintf(pfile, "Section \"Device\"\n" " Identifier \"intel\"\n" " Driver \"intel\"\n" " Option \"AccelMethod\" \"uxa\"\n" " BusID \"PCI:%d@%d:%d:%d\"\n" "EndSection\n\n", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } else if (devices[i]->vendor_id == AMD) { /* FIXME: fglrx doesn't seem to support * the domain, so we only use * bus, dev, and func */ fprintf(pfile, "Section \"Device\"\n" " Identifier \"amd-device\"\n" " Driver \"fglrx\"\n" /*" BusID \"PCI:%d@%d:%d:%d\"\n" */ " BusID \"PCI:%d:%d:%d\"\n" "EndSection\n\n" "Section \"Monitor\"\n" " Identifier \"amd-monitor\"\n" " Option \"VendorName\" \"ATI Proprietary Driver\"\n" " Option \"ModelName\" \"Generic Autodetecting Monitor\"\n" " Option \"DPMS\" \"true\"\n" "EndSection\n\n" "Section \"Screen\"\n" " Identifier \"amd-screen\"\n" " Device \"amd-device\"\n" " Monitor \"amd-monitor\"\n" " DefaultDepth 24\n" " SubSection \"Display\"\n" " Viewport 0 0\n" " Depth 24\n" " EndSubSection\n" "EndSection\n\n", (int)(devices[i]->bus), /* (int)(devices[i]->domain), */ (int)(devices[i]->dev), (int)(devices[i]->func)); } } fflush(pfile); fclose(pfile); return 1; } /* Check AMD's configuration file is the discrete GPU * is set to be disabled */ static int is_pxpress_dgpu_disabled() { int disabled = 0; /* We don't need a huge buffer */ char line[100]; FILE *file; if (!exists_not_empty(amd_pcsdb_file)) return 0; file = fopen(amd_pcsdb_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", amd_pcsdb_file); return 0; } while (fgets(line, sizeof(line), file)) { /* This means that a GPU has to be disabled */ if (istrstr(line, "PX_GPUDOWN=") != NULL) { disabled = 1; break; } } fclose(file); return disabled; } /* Check if binary drivers are still set in xorg.conf */ static int has_xorg_conf_binary_drivers(struct device **devices, int cards_n) { int found_binary = 0; char line[2048]; FILE *file; if (!exists_not_empty(xorg_conf_file)) return 0; file = fopen(xorg_conf_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", xorg_conf_file); return 0; } while (fgets(line, sizeof(line), file)) { /* Ignore comments */ if (strstr(line, "#") == NULL) { /* Parse drivers here */ if (istrstr(line, "Driver") != NULL) { if ((istrstr(line, "fglrx") != NULL) || (istrstr(line, "nvidia") != NULL)) { found_binary = 1; fprintf(log_handle, "Found binary driver in %s\n", xorg_conf_file); break; } } } } fclose(file); return found_binary; } /* Check xorg.conf to see if it's all properly set */ static int check_prime_xorg_conf(struct device **devices, int cards_n) { int i; int intel_matches = 0; int nvidia_matches = 0; int nvidia_set = 0; int intel_set = 0; int x_options_matches = 0; char line[2048]; char intel_bus_id[100]; char nvidia_bus_id[100]; FILE *file; if (!exists_not_empty(xorg_conf_file)) return 0; file = fopen(xorg_conf_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", xorg_conf_file); return 0; } /* Get the BusIDs of each card. Let's be super paranoid about * the ordering on the bus, although there should be no surprises */ for (i=0; i < cards_n; i++) { if (devices[i]->vendor_id == INTEL) { sprintf(intel_bus_id, "\"PCI:%d@%d:%d:%d\"", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } else if (devices[i]->vendor_id == NVIDIA) { sprintf(nvidia_bus_id, "\"PCI:%d@%d:%d:%d\"", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } } while (fgets(line, sizeof(line), file)) { /* Ignore comments */ if (strstr(line, "#") == NULL) { /* Parse options here */ if (istrstr(line, "Option") != NULL) { if ((istrstr(line, "AllowEmptyInitialConfiguration") != NULL && istrstr(line, "on") != NULL) || (istrstr(line, "ConstrainCursor") != NULL && istrstr(line, "off") != NULL)) { x_options_matches += 1; } } else if (strstr(line, intel_bus_id) != NULL) { intel_matches += 1; } else if (cards_n >1 && strstr(line, nvidia_bus_id) != NULL) { nvidia_matches += 1; } /* The driver has to be either intel or nvidia */ else if (istrstr(line, "Driver") != NULL) { if (istrstr(line, "modesetting") != NULL){ intel_set += 1; } else if (istrstr(line, "nvidia") != NULL) { nvidia_set += 1; } } } } fclose(file); fprintf(log_handle, "intel_matches: %d, nvidia_matches: %d, " "intel_set: %d, nvidia_set: %d " "x_options_matches: %d\n", intel_matches, nvidia_matches, intel_set, nvidia_set, x_options_matches); if (cards_n == 1) { /* The module was probably unloaded when * the card was powered down */ return (intel_matches == 1 && intel_set == 1 && nvidia_set == 1 && x_options_matches > 1); } else { return (intel_matches == 1 && nvidia_matches == 1 && intel_set == 1 && nvidia_set == 1 && x_options_matches > 1); } } /* Check xorg.conf to see if it's all properly set */ static int check_pxpress_xorg_conf(struct device **devices, int cards_n) { int i; int intel_matches = 0; int amd_matches = 0; int fglrx_set = 0; int intel_set = 0; int x_options_matches = 0; char line[2048]; char intel_bus_id[100]; char amd_bus_id[100]; FILE *file; if (!exists_not_empty(xorg_conf_file)) return 0; file = fopen(xorg_conf_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", xorg_conf_file); return 0; } /* Get the BusIDs of each card. Let's be super paranoid about * the ordering on the bus, although there should be no surprises */ for (i=0; i < cards_n; i++) { if (devices[i]->vendor_id == INTEL) { sprintf(intel_bus_id, "\"PCI:%d@%d:%d:%d\"", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } else if (devices[i]->vendor_id == AMD) { /* FIXME: fglrx doesn't seem to support * the domain, so we only use * bus, dev, and func */ /* sprintf(amd_bus_id, "\"PCI:%d@%d:%d:%d\"", */ sprintf(amd_bus_id, "\"PCI:%d:%d:%d\"", (int)(devices[i]->bus), /*(int)(devices[i]->domain),*/ (int)(devices[i]->dev), (int)(devices[i]->func)); } } while (fgets(line, sizeof(line), file)) { /* Ignore comments */ if (strstr(line, "#") == NULL) { /* Parse options here */ if (istrstr(line, "Option") != NULL) { if (istrstr(line, "AccelMethod") != NULL && istrstr(line, "UXA") != NULL) { x_options_matches += 1; } } else if (strstr(line, intel_bus_id) != NULL) { intel_matches += 1; } else if (cards_n >1 && strstr(line, amd_bus_id) != NULL) { amd_matches += 1; } /* The driver has to be either intel or fglrx */ else if (istrstr(line, "Driver") != NULL) { if (istrstr(line, "intel") != NULL){ intel_set += 1; } else if (istrstr(line, "fglrx") != NULL) { fglrx_set += 1; } } } } fclose(file); fprintf(log_handle, "intel_matches: %d, amd_matches: %d, " "intel_set: %d, fglrx_set: %d " "x_options_matches: %d\n", intel_matches, amd_matches, intel_set, fglrx_set, x_options_matches); if (cards_n == 1) { /* The module was probably unloaded when * the card was powered down */ return (intel_matches == 1 && intel_set == 1 && fglrx_set == 1 && x_options_matches > 0); } else { return (intel_matches == 1 && amd_matches == 1 && intel_set == 1 && fglrx_set == 1 && x_options_matches > 0); } } static int check_vendor_bus_id_xorg_conf(struct device **devices, int cards_n, unsigned int vendor_id, char *driver) { int failure = 0; int i; int matches = 0; int expected_matches = 0; char line[4096]; char bus_id[256]; FILE *file; /* If file doesn't exist or is empty */ if (!exists_not_empty(xorg_conf_file)) return 0; file = fopen(xorg_conf_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", xorg_conf_file); return 0; } for (i=0; i < cards_n; i++) { /* BusID \"PCI:%d@%d:%d:%d\" */ if (devices[i]->vendor_id == vendor_id) expected_matches += 1; } while (fgets(line, sizeof(line), file)) { /* Ignore comments */ if (strstr(line, "#") == NULL) { /* If we find a line with the BusId */ if (istrstr(line, "BusID") != NULL) { for (i=0; i < cards_n; i++) { /* BusID \"PCI:%d@%d:%d:%d\" */ if (devices[i]->vendor_id == vendor_id) { sprintf(bus_id, "\"PCI:%d@%d:%d:%d\"", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); if (strstr(line, bus_id) != NULL) { matches += 1; } } } } else if ((istrstr(line, "Driver") != NULL) && (strstr(line, driver) == NULL)) { failure = 1; } } } fclose(file); return (matches == expected_matches && !failure); } static int check_all_bus_ids_xorg_conf(struct device **devices, int cards_n) { /* int status = 0;*/ int i; int matches = 0; char line[4096]; char bus_id[256]; FILE *file; file = fopen(xorg_conf_file, "r"); if (!file) { fprintf(log_handle, "Error: I couldn't open %s for reading.\n", xorg_conf_file); return 0; } while (fgets(line, sizeof(line), file)) { for (i=0; i < cards_n; i++) { /* BusID \"PCI:%d@%d:%d:%d\" */ sprintf(bus_id, "\"PCI:%d@%d:%d:%d\"", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); if (strstr(line, bus_id) != NULL) { matches += 1; } } } fclose(file); return (matches == cards_n); /* return status; */ } static int write_prime_xorg_conf(struct device **devices, int cards_n) { int i; FILE *pfile = NULL; fprintf(log_handle, "Regenerating xorg.conf. Path: %s\n", xorg_conf_file); pfile = fopen(xorg_conf_file, "w"); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for writing.\n", xorg_conf_file); return 0; } fprintf(pfile, "Section \"ServerLayout\"\n" " Identifier \"layout\"\n" " Screen 0 \"nvidia\"\n" " Inactive \"intel\"\n" "EndSection\n\n"); for(i = 0; i < cards_n; i++) { if (devices[i]->vendor_id == INTEL) { fprintf(pfile, "Section \"Device\"\n" " Identifier \"intel\"\n" " Driver \"modesetting\"\n" " BusID \"PCI:%d@%d:%d:%d\"\n" "EndSection\n\n" "Section \"Screen\"\n" " Identifier \"intel\"\n" " Device \"intel\"\n" "EndSection\n\n", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } else if (devices[i]->vendor_id == NVIDIA) { fprintf(pfile, "Section \"Device\"\n" " Identifier \"nvidia\"\n" " Driver \"nvidia\"\n" " BusID \"PCI:%d@%d:%d:%d\"\n" " Option \"ConstrainCursor\" \"off\"\n" "EndSection\n\n" "Section \"Screen\"\n" " Identifier \"nvidia\"\n" " Device \"nvidia\"\n" " Option \"AllowEmptyInitialConfiguration\" \"on\"\n" "EndSection\n\n", (int)(devices[i]->bus), (int)(devices[i]->domain), (int)(devices[i]->dev), (int)(devices[i]->func)); } } fflush(pfile); fclose(pfile); return 1; } /* Open a file and check if it contains "on" * or "off". * * Return 0 if the file doesn't exist or is empty. */ static int check_on_off(const char *path) { int status = 0; char line[100]; FILE *file; file = fopen(path, "r"); if (!file) { fprintf(log_handle, "Error: can't open %s\n", path); return 0; } while (fgets(line, sizeof(line), file)) { if (istrstr(line, "on") != NULL) { status = 1; break; } } fclose(file); return status; } /* Get the current status for PRIME from bbswitch. * * This tells us whether the discrete card is * on or off. */ static int prime_is_discrete_nvidia_on() { return (check_on_off(bbswitch_path)); } /* Get the settings for PRIME. * * This tells us whether the discrete card should be * on or off. */ static int prime_is_action_on() { return (check_on_off(prime_settings)); } static int prime_set_discrete(int mode) { FILE *file; file = fopen(bbswitch_path, "w"); if (!file) return 0; fprintf(file, "%s\n", mode ? "ON" : "OFF"); fclose(file); return 1; } /* Power on the NVIDIA discrete card */ static int prime_enable_discrete() { int status = 0; /* Set bbswitch */ status = prime_set_discrete(1); /* Load the module */ if (status) status = load_module("nvidia"); return status; } /* Power off the NVIDIA discrete card */ static int prime_disable_discrete() { int status = 0; /* Tell nvidia-persistenced the nvidia card is about * to be switched off */ if (!dry_run) system("/sbin/initctl emit nvidia-off"); /* Unload the module */ status = unload_module("nvidia"); /* Set bbswitch */ if (status) status = prime_set_discrete(0); return status; } static void get_boot_vga(struct device **devices, int cards_number, unsigned int *vendor_id, unsigned int *device_id) { int i; for(i = 0; i < cards_number; i++) { if (devices[i]->boot_vga) { *vendor_id = devices[i]->vendor_id; *device_id = devices[i]->device_id; break; } } } static void get_first_discrete(struct device **devices, int cards_number, unsigned int *vendor_id, unsigned int *device_id) { int i; for(i = 0; i < cards_number; i++) { if (!devices[i]->boot_vga) { *vendor_id = devices[i]->vendor_id; *device_id = devices[i]->device_id; break; } } } static int has_system_changed(struct device **old_devices, struct device **new_devices, int old_number, int new_number) { int status = 0; int i; if (old_number != new_number) { fprintf(log_handle, "The number of cards has changed!\n"); return 1; } for (i = 0; i < old_number; i++) { if ((old_devices[i]->boot_vga != new_devices[i]->boot_vga) || (old_devices[i]->vendor_id != new_devices[i]->vendor_id) || (old_devices[i]->device_id != new_devices[i]->device_id) || (old_devices[i]->domain != new_devices[i]->domain) || (old_devices[i]->bus != new_devices[i]->bus) || (old_devices[i]->dev != new_devices[i]->dev) || (old_devices[i]->func != new_devices[i]->func)) { status = 1; break; } } return status; } static int write_data_to_file(struct device **devices, int cards_number, char *filename) { int i; FILE *pfile = NULL; pfile = fopen(filename, "w"); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for writing.\n", filename); return 0; } for(i = 0; i < cards_number; i++) { fprintf(pfile, "%04x:%04x;%04x:%02x:%02x:%d;%d\n", devices[i]->vendor_id, devices[i]->device_id, devices[i]->domain, devices[i]->bus, devices[i]->dev, devices[i]->func, devices[i]->boot_vga); } fflush(pfile); fclose(pfile); return 1; } static int get_vars(const char *line, struct device **devices, int num, int desired_matches) { int status; devices[num] = malloc(sizeof(struct device)); if (!devices[num]) return EOF; status = sscanf(line, "%04x:%04x;%04x:%02x:%02x:%d;%d\n", &devices[num]->vendor_id, &devices[num]->device_id, &devices[num]->domain, &devices[num]->bus, &devices[num]->dev, &devices[num]->func, &devices[num]->boot_vga); /* Make sure that we match "desired_matches" */ if (status == EOF || status != desired_matches) free(devices[num]); return status; } static int read_data_from_file(struct device **devices, int *cards_number, char *filename) { /* Read from last boot gfx */ char line[100]; FILE *pfile = NULL; /* The number of digits we expect to match per line */ int desired_matches = 7; pfile = fopen(filename, "r"); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for reading.\n", filename); /* Create the file for the 1st time */ pfile = fopen(filename, "w"); fprintf(log_handle, "Create %s for the 1st time\n", filename); if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for writing.\n", filename); return 0; } fprintf(pfile, "%04x:%04x;%04x:%02x:%02x:%d;%d\n", 0, 0, 0, 0, 0, 0, 0); fflush(pfile); fclose(pfile); /* Try again */ pfile = fopen(filename, "r"); } if (pfile == NULL) { fprintf(log_handle, "I couldn't open %s for reading.\n", filename); return 0; } else { /* Use fgets so as to limit the buffer length */ while (fgets(line, sizeof(line), pfile) && (*cards_number < MAX_CARDS_N)) { if (strlen(line) > 0) { /* See if we actually get all the desired digits, * as per "desired_matches" */ if (get_vars(line, devices, *cards_number, desired_matches) == desired_matches) { *cards_number += 1; } } } } fclose(pfile); return 1; } /* Find pci id in dmesg stream */ static char * find_pci_pattern(char *line, const char *pattern) { int is_next = 0; char *tok; char *match = NULL; tok = strtok(line, " "); while (tok != NULL) { tok = strtok (NULL, " "); if (is_next) { if (tok && isdigit(tok[0])) { fprintf(log_handle, "Found %s pci id in dmesg: %s.\n", pattern, tok); match = strdup(tok); break; } else { break; } } if (tok) is_next = (strcmp(tok, pattern) == 0); } return match; } /* Parse part of dmesg to extract the PCI BusID */ static int add_gpu_from_stream(FILE *pfile, const char *pattern, struct device **devices, int *num) { int status = EOF; char line[1035]; char *match = NULL; /* The number of digits we expect to match per line */ int desired_matches = 4; if (!pfile) { fprintf(log_handle, "Error: passed invalid stream.\n"); return 0; } devices[*num] = malloc(sizeof(struct device)); if (!devices[*num]) return 0; while (fgets(line, sizeof(line), pfile)) { match = find_pci_pattern(line, pattern); if (match) { /* Extract the data from the string */ status = sscanf(match, "%04x:%02x:%02x.%d\n", &devices[*num]->domain, &devices[*num]->bus, &devices[*num]->dev, &devices[*num]->func); free(match); break; } } /* Check that we actually matched all the desired digits, * as per "desired_matches" */ if (status == EOF || status != desired_matches) { free(devices[*num]); return 0; } if (istrstr(pattern, "nvidia") != NULL) { /* Add fake device and vendor ids */ devices[*num]->vendor_id = NVIDIA; devices[*num]->device_id = 0x68d8; } else if (istrstr(pattern, "fglrx") != NULL){ /* Add fake device and vendor ids */ devices[*num]->vendor_id = AMD; devices[*num]->device_id = 0x68d8; } /* Increment number of cards */ *num += 1; return status; } /* Get the PCI BusID from dmesg */ static int add_gpu_bus_from_dmesg(const char *pattern, struct device **devices, int *cards_number) { int status = 0; char command[100]; FILE *pfile = NULL; if (dry_run && fake_dmesg_path) { /* If file doesn't exist or is empty */ if (!exists_not_empty(fake_dmesg_path)) return 0; sprintf(command, "grep %s %s", pattern, fake_dmesg_path); } else { sprintf(command, "dmesg | grep %s", pattern); } pfile = popen(command, "r"); if (pfile == NULL) { return 1; } /* Extract ID from the stream */ status = add_gpu_from_stream(pfile, pattern, devices, cards_number); pclose(pfile); fprintf(log_handle, "pci bus from dmesg status %d\n", status); return status; } /* Get the PCI BusID from dmesg */ static int add_amd_gpu_bus_from_dmesg(struct device **devices, int *cards_number) { return (add_gpu_bus_from_dmesg("fglrx_pci", devices, cards_number)); } static int add_nvidia_gpu_bus_from_dmesg(struct device **devices, int *cards_number) { return (add_gpu_bus_from_dmesg("nvidia", devices, cards_number)); } static int is_module_loaded(const char *module) { int status = 0; char line[4096]; FILE *file; if (!fake_modules_path) file = fopen("/proc/modules", "r"); else file = fopen(fake_modules_path, "r"); if (!file) { fprintf(log_handle, "Error: can't open /proc/modules"); return 0; } while (fgets(line, sizeof(line), file)) { char *tok; tok = strtok(line, " \t"); if (strstr(tok, module) != NULL) { status = 1; break; } } fclose(file); return status; } static int is_file(char *file) { struct stat stbuf; if (stat(file, &stbuf) == -1) { fprintf(log_handle, "Error: can't access %s\n", file); return 0; } if (stbuf.st_mode & S_IFMT) return 1; return 0; } static int is_dir(char *directory) { struct stat stbuf; if (stat(directory, &stbuf) == -1) { fprintf(log_handle, "Error: can't access %s\n", directory); return 0; } if ((stbuf.st_mode & S_IFMT) == S_IFDIR) return 1; return 0; } static int is_dir_empty(char *directory) { int n = 0; struct dirent *d; DIR *dir = opendir(directory); if (dir == NULL) return 1; while ((d = readdir(dir)) != NULL) { if(++n > 2) break; } closedir(dir); if (n <= 2) return 1; else return 0; } static int is_link(char *file) { struct stat stbuf; if (lstat(file, &stbuf) == -1) { fprintf(log_handle, "Error: can't access %s\n", file); return 0; } if ((stbuf.st_mode & S_IFMT) == S_IFLNK) return 1; return 0; } /* See if the device is bound to a driver */ static int is_device_bound_to_driver(struct pci_device *info) { char sysfs_path[256]; sprintf(sysfs_path, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/driver", info->domain, info->bus, info->dev, info->func); return(is_link(sysfs_path)); } /* Count the number of outputs connected to the card */ int count_connected_outputs(int fd, drmModeResPtr res) { int i; int connected_outputs = 0; drmModeConnectorPtr connector; for (i = 0; i < res->count_connectors; i++) { connector = drmModeGetConnector(fd, res->connectors[i]); if (connector) { switch (connector->connection) { case DRM_MODE_CONNECTED: fprintf(log_handle, "output %d:\n", connected_outputs); connected_outputs += 1; switch (connector->connector_type) { case DRM_MODE_CONNECTOR_Unknown: fprintf(log_handle, "\tunknown connector\n"); break; case DRM_MODE_CONNECTOR_VGA: fprintf(log_handle, "\tVGA connector\n"); break; case DRM_MODE_CONNECTOR_DVII: fprintf(log_handle, "\tDVII connector\n"); break; case DRM_MODE_CONNECTOR_DVID: fprintf(log_handle, "\tDVID connector\n"); break; case DRM_MODE_CONNECTOR_DVIA: fprintf(log_handle, "\tDVIA connector\n"); break; case DRM_MODE_CONNECTOR_Composite: fprintf(log_handle, "\tComposite connector\n"); break; case DRM_MODE_CONNECTOR_SVIDEO: fprintf(log_handle, "\tSVIDEO connector\n"); break; case DRM_MODE_CONNECTOR_LVDS: fprintf(log_handle, "\tLVDS connector\n"); break; case DRM_MODE_CONNECTOR_Component: fprintf(log_handle, "\tComponent connector\n"); break; case DRM_MODE_CONNECTOR_9PinDIN: fprintf(log_handle, "\t9PinDIN connector\n"); break; case DRM_MODE_CONNECTOR_DisplayPort: fprintf(log_handle, "\tDisplayPort connector\n"); break; case DRM_MODE_CONNECTOR_HDMIA: fprintf(log_handle, "\tHDMIA connector\n"); break; case DRM_MODE_CONNECTOR_HDMIB: fprintf(log_handle, "\tHDMIB connector\n"); break; case DRM_MODE_CONNECTOR_TV: fprintf(log_handle, "\tTV connector\n"); break; case DRM_MODE_CONNECTOR_eDP: fprintf(log_handle, "\teDP connector\n"); break; #if 0 case DRM_MODE_CONNECTOR_VIRTUAL: fprintf(log_handle, "VIRTUAL connector\n"); break; case DRM_MODE_CONNECTOR_DSI: fprintf(log_handle, "DSI connector\n"); break; #endif default: break; } break; case DRM_MODE_DISCONNECTED: break; default: break; } drmModeFreeConnector(connector); } } return connected_outputs; } /* See if the drm device created by a driver has any connected outputs. */ static int has_driver_connected_outputs(const char *driver) { char path[20]; int fd = 1; drmModeResPtr res; drmVersionPtr version; int connected_outputs = 0; int driver_match = 0; int it; /* Keep looking until we find the device for the driver */ for (it = 0; fd != -1; it++) { sprintf(path, "/dev/dri/card%d", it); fd = open(path, O_RDWR); if (fd) { if ((version = drmGetVersion(fd))) { /* Let's use strstr to catch the different backported * kernel modules */ if (driver && strstr(version->name, driver) != NULL) { fprintf(log_handle, "Found \"%s\", driven by \"%s\"\n", path, version->name); driver_match = 1; drmFreeVersion(version); break; } else { fprintf(log_handle, "Skipping \"%s\", driven by \"%s\"\n", path, version->name); drmFreeVersion(version); close(fd); } } } else { fprintf(log_handle, "Error: can't open fd for %s\n", path); break; } } if (!driver_match) return 0; res = drmModeGetResources(fd); if (!res) { fprintf(log_handle, "Error: can't get drm resources.\n"); drmClose(fd); return 0; } connected_outputs = count_connected_outputs(fd, res); fprintf(log_handle, "Number of connected outputs for %s: %d\n", path, connected_outputs); drmModeFreeResources(res); close(fd); return (connected_outputs > 0); } /* Check if any outputs are still connected to card0. * * By default we only check cards driver by i915. * If so, then claim support for RandR offloading */ static int requires_offloading(void) { /* Let's check only /dev/dri/card0 and look * for driver i915. We don't want to enable * offloading to any other driver, as results * may be unpredictable */ return(has_driver_connected_outputs("i915")); } /* Set permanent settings for offloading */ static int set_offloading(void) { FILE *file; if (dry_run) return 1; file = fopen(OFFLOADING_CONF, "w"); if (file != NULL) { fprintf(file, "ON\n"); fflush(file); fclose(file); return 1; } return 0; } /* Make a backup and remove xorg.conf */ static int remove_xorg_conf(void) { int status; char backup[200]; char buffer[80]; time_t rawtime; struct tm *info; fprintf(log_handle, "Removing xorg.conf. Path: %s\n", xorg_conf_file); time(&rawtime); info = localtime(&rawtime); strftime(buffer, 80, "%m%d%Y", info); sprintf(backup, "%s.%s", xorg_conf_file, buffer); status = rename(xorg_conf_file, backup); if (!status) { status = unlink(xorg_conf_file); if (!status) return 0; else return 1; } else { fprintf(log_handle, "Moved %s to %s\n", xorg_conf_file, backup); } return 1; } static int enable_mesa() { int status = 0; fprintf(log_handle, "Selecting mesa\n"); status = select_driver("mesa"); /* Remove xorg.conf */ remove_xorg_conf(); return status; } static int enable_nvidia(struct alternatives *alternative, unsigned int vendor_id, struct device **devices, int cards_n) { int status = 0; /* Alternative not in use */ if (!alternative->nvidia_enabled) { /* Select nvidia */ fprintf(log_handle, "Selecting nvidia\n"); status = select_driver("nvidia"); /* select_driver(other_arch_path, "nvidia"); */ } /* Alternative in use */ else { fprintf(log_handle, "Driver is already loaded and enabled\n"); status = 1; } /* See if enabling the driver failed */ if (status) { /* If xorg.conf exists, make sure it contains * the right BusId and NO NOUVEAU or FGLRX. If it doesn't, create a * xorg.conf from scratch */ if (!check_vendor_bus_id_xorg_conf(devices, cards_n, vendor_id, "nvidia")) { fprintf(log_handle, "Check failed\n"); /* Remove xorg.conf */ remove_xorg_conf(); /* Only useful if more than one card is available */ if (cards_n > 1) { /* Write xorg.conf */ write_to_xorg_conf(devices, cards_n, vendor_id); } } else { fprintf(log_handle, "No need to modify xorg.conf. Path: %s\n", xorg_conf_file); } } else { /* For some reason we failed to select the * driver. Let's select Mesa here */ fprintf(log_handle, "Error: failed to enable the driver\n"); enable_mesa(); } return status; } static int enable_prime(const char *prime_settings, int bbswitch_loaded, unsigned int vendor_id, struct alternatives *alternative, struct device **devices, int cards_n) { int status = 0; int prime_discrete_on = 0; int prime_action_on = 0; /* We only support Lightdm at this time */ if (!is_lightdm_default()) { fprintf(log_handle, "Lightdm is not the default display " "manager. Nothing to do\n"); return 0; } /* Check if prime_settings is available * File doesn't exist or empty */ if (!exists_not_empty(prime_settings)) { fprintf(log_handle, "Error: no settings for prime can be found in %s\n", prime_settings); return 0; } if (!bbswitch_loaded) { /* Try to load bbswitch */ /* opts="`/sbin/get-quirk-options`" /sbin/modprobe bbswitch load_state=-1 unload_state=1 "$opts" || true */ status = load_bbswitch(); if (!status) { fprintf(log_handle, "Error: can't load bbswitch\n"); /* Select mesa as a fallback */ enable_mesa(); /* Remove xorg.conf */ remove_xorg_conf(); return 0; } } /* Get the current status from bbswitch */ prime_discrete_on = prime_is_discrete_nvidia_on(); /* Get the current settings for discrete */ prime_action_on = prime_is_action_on(); if (prime_action_on) { if (!alternative->nvidia_enabled) { /* Select nvidia */ enable_nvidia(alternative, vendor_id, devices, cards_n); } if (!check_prime_xorg_conf(devices, cards_n)) { fprintf(log_handle, "Check failed\n"); /* Remove xorg.conf */ remove_xorg_conf(); /* Write xorg.conf */ write_prime_xorg_conf(devices, cards_n); } else { fprintf(log_handle, "No need to modify xorg.conf. Path: %s\n", xorg_conf_file); } } else { if (!alternative->prime_enabled) { /* Select prime */ fprintf(log_handle, "Selecting prime\n"); select_driver("prime"); } /* Remove xorg.conf */ remove_xorg_conf(); } /* This means we need to call bbswitch * to take action */ if (prime_action_on == prime_discrete_on) { fprintf(log_handle, "No need to change the current bbswitch status\n"); return 1; } if (prime_action_on) { fprintf(log_handle, "Powering on the discrete card\n"); prime_enable_discrete(); } else { fprintf(log_handle, "Powering off the discrete card\n"); prime_disable_discrete(); } return 1; } static int enable_fglrx(struct alternatives *alternative, unsigned int vendor_id, struct device **devices, int cards_n) { int status = 0; /* Alternative not in use */ if (!alternative->fglrx_enabled) { /* Select fglrx */ fprintf(log_handle, "Selecting fglrx\n"); status = select_driver("fglrx"); /* select_driver(other_arch_path, "nvidia"); */ } /* Alternative in use */ else { fprintf(log_handle, "Driver is already loaded and enabled\n"); status = 1; } if (status) { /* If xorg.conf exists, make sure it contains * the right BusId and NO NOUVEAU or FGLRX. If it doesn't, create a * xorg.conf from scratch */ if (!check_vendor_bus_id_xorg_conf(devices, cards_n, vendor_id, "fglrx")) { fprintf(log_handle, "Check failed\n"); /* Remove xorg.conf */ remove_xorg_conf(); /* Only useful if more than one card is available */ if (cards_n > 1) { /* Write xorg.conf */ write_to_xorg_conf(devices, cards_n, vendor_id); } } else { fprintf(log_handle, "No need to modify xorg.conf. Path: %s\n", xorg_conf_file); } } else { /* For some reason we failed to select the * driver. Let's select Mesa here */ fprintf(log_handle, "Error: failed to enable the driver\n"); enable_mesa(); } return status; } static int enable_pxpress(struct device **devices, int cards_n) { int status = 0; /* FIXME: check only xorg.conf for now */ if (!check_pxpress_xorg_conf(devices, cards_n)) { fprintf(log_handle, "Check failed\n"); /* Remove xorg.conf */ remove_xorg_conf(); /* Write xorg.conf */ status = write_pxpress_xorg_conf(devices, cards_n); } else { fprintf(log_handle, "No need to modify xorg.conf. Path: %s\n", xorg_conf_file); status = 1; } /* Reenable this when we know more about amdpcsdb */ #if 0 /* See if the discrete GPU is disabled */ if (is_pxpress_dgpu_disabled()) { if (!alternative->pxpress_enabled) { fprintf(log_handle, "Selecting pxpress\n"); status = select_driver("pxpress"); } else { fprintf(log_handle, "Driver is already loaded and enabled\n"); status = 1; } } else { if (!alternative->fglrx_enabled) { fprintf(log_handle, "Selecting fglrx\n"); status = select_driver("fglrx"); } else { fprintf(log_handle, "Driver is already loaded and enabled\n"); status = 1; } } if (status) { /* If xorg.conf exists, make sure it contains * the right BusId and the correct drivers. If it doesn't, create a * xorg.conf from scratch */ if (!check_pxpress_xorg_conf(current_devices, cards_n)) { fprintf(log_handle, "Check failed\n"); /* Remove xorg.conf */ remove_xorg_conf(); /* Write xorg.conf */ write_pxpress_xorg_conf(current_devices, cards_n); } else { fprintf(log_handle, "No need to modify xorg.conf. Path: %s\n", xorg_conf_file); } } else { /* For some reason we failed to select the * driver. Let's select Mesa here */ fprintf(log_handle, "Error: failed to enable the driver\n"); fprintf(log_handle, "Selecting mesa\n"); select_driver("mesa"); /* select_driver(other_arch_path, "mesa"); */ /* Remove xorg.conf */ remove_xorg_conf(); } #endif return status; } int main(int argc, char *argv[]) { int opt, i; char *fake_lspci_file = NULL; char *new_boot_file = NULL; static int fake_offloading = 0; int has_intel = 0, has_amd = 0, has_nvidia = 0; int has_changed = 0; int has_moved_xorg_conf = 0; int nvidia_loaded = 0, fglrx_loaded = 0, intel_loaded = 0, radeon_loaded = 0, nouveau_loaded = 0, bbswitch_loaded = 0; int fglrx_unloaded = 0, nvidia_unloaded = 0; int offloading = 0; int status = 0; /* Vendor and device id (boot vga) */ unsigned int boot_vga_vendor_id = 0, boot_vga_device_id = 0; /* Vendor and device id (discrete) */ unsigned int discrete_vendor_id = 0, discrete_device_id = 0; /* The current number of cards */ int cards_n = 0; /* The number of cards from last boot*/ int last_cards_n = 0; /* Variables for pciaccess */ int pci_init = -1; struct pci_device_iterator *iter = NULL; struct pci_device *info = NULL; /* Store the devices here */ struct device *current_devices[MAX_CARDS_N]; struct device *old_devices[MAX_CARDS_N]; /* Alternatives */ struct alternatives *alternative = NULL; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"dry-run", no_argument, &dry_run, 1}, {"fake-requires-offloading", no_argument, &fake_offloading, 1}, {"fake-no-requires-offloading", no_argument, &fake_offloading, 0}, {"fake-lightdm", no_argument, &fake_lightdm, 1}, /* These options don't set a flag. We distinguish them by their indices. */ {"log", required_argument, 0, 'l'}, {"fake-lspci", required_argument, 0, 'f'}, {"last-boot-file", required_argument, 0, 'b'}, {"new-boot-file", required_argument, 0, 'n'}, {"xorg-conf-file", required_argument, 0, 'x'}, {"amd-pcsdb-file", required_argument, 0, 'd'}, {"fake-alternative", required_argument, 0, 'a'}, {"fake-modules-path", required_argument, 0, 'm'}, {"fake-alternatives-path", required_argument, 0, 'p'}, {"fake-dmesg-path", required_argument, 0, 's'}, {"prime-settings", required_argument, 0, 'z'}, {"bbswitch-path", required_argument, 0, 'y'}, {"bbswitch-quirks-path", required_argument, 0, 'g'}, {"dmi-product-version-path", required_argument, 0, 'h'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; opt = getopt_long (argc, argv, "lbnfxdampzy:::", long_options, &option_index); /* Detect the end of the options. */ if (opt == -1) break; switch (opt) { case 0: if (long_options[option_index].flag != 0) break; printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case 'l': /* printf("option -l with value '%s'\n", optarg); */ log_file = malloc(strlen(optarg) + 1); if (log_file) strcpy(log_file, optarg); else abort(); break; case 'b': /* printf("option -b with value '%s'\n", optarg); */ last_boot_file = malloc(strlen(optarg) + 1); if (last_boot_file) strcpy(last_boot_file, optarg); else abort(); break; case 'n': /* printf("option -n with value '%s'\n", optarg); */ new_boot_file = malloc(strlen(optarg) + 1); if (new_boot_file) strcpy(new_boot_file, optarg); else abort(); break; case 'f': /* printf("option -f with value '%s'\n", optarg); */ fake_lspci_file = malloc(strlen(optarg) + 1); if (fake_lspci_file) strcpy(fake_lspci_file, optarg); else abort(); break; case 'x': /* printf("option -x with value '%s'\n", optarg); */ xorg_conf_file = malloc(strlen(optarg) + 1); if (xorg_conf_file) strcpy(xorg_conf_file, optarg); else abort(); break; case 'd': /* printf("option -x with value '%s'\n", optarg); */ amd_pcsdb_file = malloc(strlen(optarg) + 1); if (amd_pcsdb_file) strcpy(amd_pcsdb_file, optarg); else abort(); break; case 'a': /* printf("option -a with value '%s'\n", optarg); */ alternative = calloc(1, sizeof(struct alternatives)); if (!alternative) { abort(); } else { alternative->current = strdup(optarg); if (!alternative->current) { free(alternative); abort(); } } break; case 'm': /* printf("option -m with value '%s'\n", optarg); */ fake_modules_path = malloc(strlen(optarg) + 1); if (fake_modules_path) strcpy(fake_modules_path, optarg); else abort(); break; case 'p': /* printf("option -p with value '%s'\n", optarg); */ fake_alternatives_path = malloc(strlen(optarg) + 1); if (fake_alternatives_path) strcpy(fake_alternatives_path, optarg); else abort(); break; case 's': /* printf("option -p with value '%s'\n", optarg); */ fake_dmesg_path = malloc(strlen(optarg) + 1); if (fake_dmesg_path) strcpy(fake_dmesg_path, optarg); else abort(); break; case 'z': /* printf("option -p with value '%s'\n", optarg); */ prime_settings = strdup(optarg); if (!prime_settings) abort(); break; case 'y': /* printf("option -p with value '%s'\n", optarg); */ bbswitch_path = strdup(optarg); if (!bbswitch_path) abort(); break; case 'g': /* printf("option -p with value '%s'\n", optarg); */ bbswitch_quirks_path = strdup(optarg); if (!bbswitch_quirks_path) abort(); break; case 'h': /* printf("option -p with value '%s'\n", optarg); */ dmi_product_version_path = strdup(optarg); if (!dmi_product_version_path) abort(); break; case '?': /* getopt_long already printed an error message. */ exit(1); break; default: abort(); } } /* if (dry_run) printf("dry-run flag is set\n"); */ /* Send messages to the log or to stdout */ if (log_file) { log_handle = fopen(log_file, "w"); } else { log_handle = stdout; } if (is_disabled_in_cmdline()) { fprintf(log_handle, "Disabled by kernel parameter \"%s\"\n", KERN_PARAM); goto end; } /* TODO: require arguments and abort if they're not available */ if (log_file) fprintf(log_handle, "log_file: %s\n", log_file); if (!last_boot_file) last_boot_file = strdup(LAST_BOOT); if (last_boot_file) fprintf(log_handle, "last_boot_file: %s\n", last_boot_file); else { fprintf(log_handle, "No last_boot_file!\n"); goto end; } if (!new_boot_file) new_boot_file = strdup(last_boot_file); fprintf(log_handle, "new_boot_file: %s\n", new_boot_file); if (fake_lspci_file) fprintf(log_handle, "fake_lspci_file: %s\n", fake_lspci_file); if (xorg_conf_file) fprintf(log_handle, "xorg.conf file: %s\n", xorg_conf_file); else { xorg_conf_file = strdup(XORG_CONF); if (!xorg_conf_file) { fprintf(log_handle, "Couldn't allocate xorg_conf_file\n"); goto end; } } if (prime_settings) fprintf(log_handle, "prime_settings file: %s\n", prime_settings); else { prime_settings = strdup("/etc/prime-discrete"); if (!prime_settings) { fprintf(log_handle, "Couldn't allocate prime_settings\n"); goto end; } } if (bbswitch_path) fprintf(log_handle, "bbswitch_path file: %s\n", bbswitch_path); else { bbswitch_path = strdup("/proc/acpi/bbswitch"); if (!bbswitch_path) { fprintf(log_handle, "Couldn't allocate bbswitch_path\n"); goto end; } } if (bbswitch_quirks_path) fprintf(log_handle, "bbswitch_quirks_path file: %s\n", bbswitch_quirks_path); else { bbswitch_quirks_path = strdup("/usr/share/nvidia-prime/prime-quirks"); if (!bbswitch_quirks_path) { fprintf(log_handle, "Couldn't allocate bbswitch_quirks_path\n"); goto end; } } if (dmi_product_version_path) fprintf(log_handle, "bbswitch_path file: %s\n", dmi_product_version_path); else { dmi_product_version_path = strdup("/sys/class/dmi/id/product_version"); if (!dmi_product_version_path) { fprintf(log_handle, "Couldn't allocate dmi_product_version_path\n"); goto end; } } if (amd_pcsdb_file) fprintf(log_handle, "amd_pcsdb_file file: %s\n", amd_pcsdb_file); else { amd_pcsdb_file = malloc(strlen("/etc/ati/amdpcsdb") + 1); if (amd_pcsdb_file) { strcpy(amd_pcsdb_file, "/etc/ati/amdpcsdb"); } else { fprintf(log_handle, "Couldn't allocate amd_pcsdb_file\n"); goto end; } } /* Either simulate or check if dealing with a system than requires RandR offloading */ if (fake_lspci_file) offloading = fake_offloading; else offloading = requires_offloading(); fprintf(log_handle, "Does it require offloading? %s\n", (offloading ? "yes" : "no")); /* Remove a file that will tell other apps such as * nvidia-prime if we need to offload rendering. */ if (!offloading && !dry_run) unlink(OFFLOADING_CONF); bbswitch_loaded = is_module_loaded("bbswitch"); nvidia_loaded = is_module_loaded("nvidia"); nvidia_unloaded = has_unloaded_module("nvidia"); fglrx_loaded = is_module_loaded("fglrx"); fglrx_unloaded = has_unloaded_module("fglrx"); intel_loaded = is_module_loaded("i915") || is_module_loaded("i810"); radeon_loaded = is_module_loaded("radeon"); nouveau_loaded = is_module_loaded("nouveau"); fprintf(log_handle, "Is nvidia loaded? %s\n", (nvidia_loaded ? "yes" : "no")); fprintf(log_handle, "Was nvidia unloaded? %s\n", (nvidia_unloaded ? "yes" : "no")); fprintf(log_handle, "Is fglrx loaded? %s\n", (fglrx_loaded ? "yes" : "no")); fprintf(log_handle, "Was fglrx unloaded? %s\n", (fglrx_unloaded ? "yes" : "no")); fprintf(log_handle, "Is intel loaded? %s\n", (intel_loaded ? "yes" : "no")); fprintf(log_handle, "Is radeon loaded? %s\n", (radeon_loaded ? "yes" : "no")); fprintf(log_handle, "Is nouveau loaded? %s\n", (nouveau_loaded ? "yes" : "no")); if (fake_lspci_file) { /* Get the current system data from a file */ status = read_data_from_file(current_devices, &cards_n, fake_lspci_file); if (!status) { fprintf(log_handle, "Error: can't read %s\n", fake_lspci_file); goto end; } /* Set data in the devices structs */ for(i = 0; i < cards_n; i++) { if (current_devices[i]->vendor_id == NVIDIA) { has_nvidia = 1; } else if (current_devices[i]->vendor_id == AMD) { has_amd = 1; } else if (current_devices[i]->vendor_id == INTEL) { has_intel = 1; } } } else { /* Get the current system data */ pci_init = pci_system_init(); if (pci_init != 0) goto end; iter = pci_slot_match_iterator_create(&match); if (!iter) goto end; while ((info = pci_device_next(iter)) != NULL) { if (PCIINFOCLASSES(info->device_class)) { fprintf(log_handle, "Vendor/Device Id: %x:%x\n", info->vendor_id, info->device_id); fprintf(log_handle, "BusID \"PCI:%d@%d:%d:%d\"\n", (int)info->bus, (int)info->domain, (int)info->dev, (int)info->func); fprintf(log_handle, "Is boot vga? %s\n", (pci_device_is_boot_vga(info) ? "yes" : "no")); if (!is_device_bound_to_driver(info)) { fprintf(log_handle, "The device is not bound to any driver. Skipping...\n"); continue; } /* char *driver = NULL; */ if (info->vendor_id == NVIDIA) { has_nvidia = 1; } else if (info->vendor_id == INTEL) { has_intel = 1; } else if (info->vendor_id == AMD) { has_amd = 1; } /* We don't support more than MAX_CARDS_N */ if (cards_n < MAX_CARDS_N) { current_devices[cards_n] = malloc(sizeof(struct device)); if (!current_devices[cards_n]) goto end; current_devices[cards_n]->boot_vga = pci_device_is_boot_vga(info); current_devices[cards_n]->vendor_id = info->vendor_id; current_devices[cards_n]->device_id = info->device_id; current_devices[cards_n]->domain = info->domain; current_devices[cards_n]->bus = info->bus; current_devices[cards_n]->dev = info->dev; current_devices[cards_n]->func = info->func; } else { fprintf(log_handle, "Warning: too many devices %d. " "Max supported %d. Ignoring the rest.\n", cards_n, MAX_CARDS_N); break; } /* else { fprintf(stderr, "No hybrid graphics cards detected\n"); break; } */ cards_n++; } } } /* Read the data from last boot */ status = read_data_from_file(old_devices, &last_cards_n, last_boot_file); if (!status) { fprintf(log_handle, "Can't read %s\n", last_boot_file); goto end; } fprintf(log_handle, "last cards number = %d\n", last_cards_n); /* Write the current data */ status = write_data_to_file(current_devices, cards_n, new_boot_file); if (!status) { fprintf(log_handle, "Error: can't write to %s\n", last_boot_file); goto end; } fprintf(log_handle, "Has amd? %s\n", (has_amd ? "yes" : "no")); fprintf(log_handle, "Has intel? %s\n", (has_intel ? "yes" : "no")); fprintf(log_handle, "Has nvidia? %s\n", (has_nvidia ? "yes" : "no")); fprintf(log_handle, "How many cards? %d\n", cards_n); /* See if the system has changed */ has_changed = has_system_changed(old_devices, current_devices, last_cards_n, cards_n); fprintf(log_handle, "Has the system changed? %s\n", has_changed ? "Yes" : "No"); /* Check alternatives */ get_architecture_paths(&main_arch_path, &other_arch_path); if (!main_arch_path) { fprintf(stderr, "Error: the current architecture is not supported\n"); goto end; } fprintf(log_handle, "main_arch_path %s, other_arch_path %s\n", main_arch_path, other_arch_path); /* If alternative is not NULL, then it's a test */ if (!alternative) alternative = calloc(1, sizeof(struct alternatives)); get_alternatives(alternative, main_arch_path); if (!alternative->current) { fprintf(stderr, "Error: no alternative found\n"); goto end; } fprintf(log_handle, "Current alternative: %s\n", alternative->current); fprintf(log_handle, "Is nvidia enabled? %s\n", alternative->nvidia_enabled ? "yes" : "no"); fprintf(log_handle, "Is fglrx enabled? %s\n", alternative->fglrx_enabled ? "yes" : "no"); fprintf(log_handle, "Is mesa enabled? %s\n", alternative->mesa_enabled ? "yes" : "no"); fprintf(log_handle, "Is pxpress enabled? %s\n", alternative->pxpress_enabled ? "yes" : "no"); fprintf(log_handle, "Is prime enabled? %s\n", alternative->prime_enabled ? "yes" : "no"); fprintf(log_handle, "Is nvidia available? %s\n", alternative->nvidia_available ? "yes" : "no"); fprintf(log_handle, "Is fglrx available? %s\n", alternative->fglrx_available ? "yes" : "no"); fprintf(log_handle, "Is mesa available? %s\n", alternative->mesa_available ? "yes" : "no"); fprintf(log_handle, "Is pxpress available? %s\n", alternative->pxpress_available ? "yes" : "no"); fprintf(log_handle, "Is prime available? %s\n", alternative->prime_available ? "yes" : "no"); /* If the module is loaded but the alternatives are not there * we're probably dealing with a proprietary installer */ if ((fglrx_loaded && !alternative->fglrx_available) || (nvidia_loaded && !alternative->nvidia_available)) { fprintf(log_handle, "Proprietary driver installer detected\n"); fprintf(log_handle, "Nothing to do\n"); goto end; } if (has_changed) fprintf(log_handle, "System configuration has changed\n"); if (cards_n == 1) { fprintf(log_handle, "Single card detected\n"); /* Get data about the boot_vga card */ get_boot_vga(current_devices, cards_n, &boot_vga_vendor_id, &boot_vga_device_id); if (boot_vga_vendor_id == INTEL) { /* AMD PowerXpress */ if (offloading && fglrx_unloaded) { fprintf(log_handle, "PowerXpress detected\n"); /* Get the BusID of the disabled discrete from dmesg */ add_amd_gpu_bus_from_dmesg(current_devices, &cards_n); /* Get data about the first discrete card */ get_first_discrete(current_devices, cards_n, &discrete_vendor_id, &discrete_device_id); enable_pxpress(current_devices, cards_n); /* No further action */ goto end; } else if (offloading && nvidia_unloaded) { /* NVIDIA PRIME */ fprintf(log_handle, "PRIME detected\n"); /* Get the BusID of the disabled discrete from dmesg */ add_nvidia_gpu_bus_from_dmesg(current_devices, &cards_n); /* Get data about the first discrete card */ get_first_discrete(current_devices, cards_n, &discrete_vendor_id, &discrete_device_id); /* Try to enable prime */ enable_prime(prime_settings, bbswitch_loaded, discrete_vendor_id, alternative, current_devices, cards_n); /* Write permanent settings about offloading */ set_offloading(); goto end; } else { if (!alternative->mesa_enabled) { /* Select mesa */ status = enable_mesa(); has_moved_xorg_conf = 1; } else { fprintf(log_handle, "Nothing to do\n"); } } } else if (boot_vga_vendor_id == AMD) { /* if fglrx is loaded enable fglrx alternative */ if (fglrx_loaded && !radeon_loaded) { if (!alternative->fglrx_enabled) { /* Try to enable fglrx */ enable_fglrx(alternative, discrete_vendor_id, current_devices, cards_n); has_moved_xorg_conf = 1; } else { fprintf(log_handle, "Driver is already loaded and enabled\n"); fprintf(log_handle, "Nothing to do\n"); } } else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if (fglrx_loaded && radeon_loaded) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); if (!alternative->mesa_enabled) { status = enable_mesa(); has_moved_xorg_conf = 1; } else { fprintf(log_handle, "Nothing to do\n"); } } } else if (boot_vga_vendor_id == NVIDIA) { /* if nvidia is loaded enable nvidia alternative */ if (nvidia_loaded && !nouveau_loaded) { if (!alternative->nvidia_enabled) { /* Try to enable nvidia */ enable_nvidia(alternative, discrete_vendor_id, current_devices, cards_n); has_moved_xorg_conf = 1; } else { fprintf(log_handle, "Driver is already loaded and enabled\n"); fprintf(log_handle, "Nothing to do\n"); } } else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if (nvidia_loaded && nouveau_loaded) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); if (!alternative->mesa_enabled) { status = enable_mesa(); has_moved_xorg_conf = 1; } else { fprintf(log_handle, "Nothing to do\n"); } } } /* Move away xorg.conf */ if (has_changed) { /* Either a desktop or a muxed laptop */ fprintf(log_handle, "System configuration has changed\n"); if (!has_moved_xorg_conf) { /* Remove xorg.conf */ remove_xorg_conf(); } } else if (!has_moved_xorg_conf) { fprintf(log_handle, "No change - nothing to do\n"); } } else if (cards_n > 1) { /* Get data about the boot_vga card */ get_boot_vga(current_devices, cards_n, &boot_vga_vendor_id, &boot_vga_device_id); /* Get data about the first discrete card */ get_first_discrete(current_devices, cards_n, &discrete_vendor_id, &discrete_device_id); /* Intel + another GPU */ if (boot_vga_vendor_id == INTEL) { fprintf(log_handle, "Intel IGP detected\n"); /* AMD PowerXpress */ if (offloading && intel_loaded && fglrx_loaded && !radeon_loaded) { fprintf(log_handle, "PowerXpress detected\n"); enable_pxpress(current_devices, cards_n); } /* NVIDIA Optimus */ else if (offloading && (intel_loaded && !nouveau_loaded && (alternative->nvidia_available || alternative->prime_available) && nvidia_loaded)) { fprintf(log_handle, "Intel hybrid system\n"); enable_prime(prime_settings, bbswitch_loaded, discrete_vendor_id, alternative, current_devices, cards_n); /* Write permanent settings about offloading */ set_offloading(); goto end; } else { /* Desktop system or Laptop with open drivers only */ fprintf(log_handle, "Desktop system detected\n"); fprintf(log_handle, "or laptop with open drivers\n"); /* TODO: Check the alternative and the module */ /* If open source driver for the discrete card: * i.e. proprietary modules are not loaded and * open drivers are: if proprietary in xorg.conf, * move the file away. */ if (discrete_vendor_id == NVIDIA) { fprintf(log_handle, "Discrete NVIDIA card detected\n"); /* Kernel module is available */ if (nvidia_loaded && !nouveau_loaded) { /* Try to enable nvidia */ enable_nvidia(alternative, discrete_vendor_id, current_devices, cards_n); } /* Kernel module is not available */ else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if (nvidia_loaded && nouveau_loaded) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* See if alternatives are broken */ if (!alternative->mesa_enabled) { /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); status = enable_mesa(); } else { /* If the system has changed or a binary driver is still * in the xorg.conf, then move the xorg.conf away */ if (has_changed || has_xorg_conf_binary_drivers(current_devices, cards_n)) { fprintf(log_handle, "System configuration has changed\n"); /* Remove xorg.conf */ remove_xorg_conf(); } else { fprintf(log_handle, "Driver not enabled or not in use\n"); fprintf(log_handle, "Nothing to do\n"); } } } } else if (discrete_vendor_id == AMD) { fprintf(log_handle, "Discrete AMD card detected\n"); /* Kernel module is available */ if (fglrx_loaded && !radeon_loaded) { /* Try to enable fglrx */ enable_fglrx(alternative, discrete_vendor_id, current_devices, cards_n); } /* Kernel module is not available */ else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if (fglrx_loaded && radeon_loaded) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* See if alternatives are broken */ if (!alternative->mesa_enabled) { /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); status = enable_mesa(); } else { /* If the system has changed or a binary driver is still * in the xorg.conf, then move the xorg.conf away */ if (has_changed || has_xorg_conf_binary_drivers(current_devices, cards_n)) { fprintf(log_handle, "System configuration has changed\n"); /* Remove xorg.conf */ remove_xorg_conf(); } else { fprintf(log_handle, "Driver not enabled or not in use\n"); fprintf(log_handle, "Nothing to do\n"); } } } } else { fprintf(log_handle, "Unsupported discrete card vendor: %x\n", discrete_vendor_id); fprintf(log_handle, "Nothing to do\n"); } } } /* AMD */ else if (boot_vga_vendor_id == AMD) { /* Either AMD+AMD hybrid system or AMD desktop APU + discrete card */ fprintf(log_handle, "AMD IGP detected\n"); if (discrete_vendor_id == AMD) { fprintf(log_handle, "Discrete AMD card detected\n"); /* Kernel module is available */ if (fglrx_loaded && !radeon_loaded) { /* Try to enable fglrx */ enable_fglrx(alternative, discrete_vendor_id, current_devices, cards_n); } /* Kernel module is not available */ else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if (fglrx_loaded && radeon_loaded) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* See if alternatives are broken */ if (!alternative->mesa_enabled) { /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); status = enable_mesa(); } else { /* If the system has changed or a binary driver is still * in the xorg.conf, then move the xorg.conf away */ if (has_changed || has_xorg_conf_binary_drivers(current_devices, cards_n)) { fprintf(log_handle, "System configuration has changed\n"); /* Remove xorg.conf */ remove_xorg_conf(); } else { fprintf(log_handle, "Driver not enabled or not in use\n"); fprintf(log_handle, "Nothing to do\n"); } } } } else if (discrete_vendor_id == NVIDIA) { fprintf(log_handle, "Discrete NVIDIA card detected\n"); /* Kernel module is available */ if (nvidia_loaded && !nouveau_loaded) { /* Try to enable nvidia */ enable_nvidia(alternative, discrete_vendor_id, current_devices, cards_n); } /* Nvidia kernel module is not available */ else { /* See if fglrx is in use */ /* Kernel module is available */ if (fglrx_loaded && !radeon_loaded) { /* Try to enable fglrx */ enable_fglrx(alternative, boot_vga_vendor_id, current_devices, cards_n); } /* Kernel module is not available */ else { /* If both the closed kernel module and the open * kernel module are loaded, then we're in trouble */ if ((fglrx_loaded && radeon_loaded) || (nvidia_loaded && nouveau_loaded)) { /* Fake a system change to trigger * a reconfiguration */ has_changed = 1; } /* See if alternatives are broken */ if (!alternative->mesa_enabled) { /* Select mesa as a fallback */ fprintf(log_handle, "Kernel Module is not loaded\n"); enable_mesa(); } else { /* If the system has changed or a binary driver is still * in the xorg.conf, then move the xorg.conf away */ if (has_changed || has_xorg_conf_binary_drivers(current_devices, cards_n)) { fprintf(log_handle, "System configuration has changed\n"); /* Remove xorg.conf */ remove_xorg_conf(); } else { fprintf(log_handle, "Driver not enabled or not in use\n"); fprintf(log_handle, "Nothing to do\n"); } } } } } else { fprintf(log_handle, "Unsupported discrete card vendor: %x\n", discrete_vendor_id); fprintf(log_handle, "Nothing to do\n"); } } } end: if (pci_init == 0) pci_system_cleanup(); if (iter) free(iter); if (log_file) free(log_file); if (last_boot_file) free(last_boot_file); if (new_boot_file) free(new_boot_file); if (fake_lspci_file) free(fake_lspci_file); if (xorg_conf_file) free(xorg_conf_file); if (amd_pcsdb_file) free(amd_pcsdb_file); if (main_arch_path) free(main_arch_path); if (other_arch_path) free(other_arch_path); if (alternative) { if (alternative->current) free(alternative->current); free(alternative); } if (fake_alternatives_path) free(fake_alternatives_path); if (fake_dmesg_path) free(fake_dmesg_path); if (fake_modules_path) free(fake_modules_path); if (prime_settings) free(prime_settings); if (bbswitch_path) free(bbswitch_path); if (bbswitch_quirks_path) free(bbswitch_quirks_path); if (dmi_product_version_path) free(dmi_product_version_path); /* Free the devices structs */ for(i = 0; i < cards_n; i++) { free(current_devices[i]); } for(i = 0; i < last_cards_n; i++) { free(old_devices[i]); } /* Flush and close the log */ if (log_handle != stdout) { fflush(log_handle); fclose(log_handle); } return 0; } ubuntu-drivers-common-0.2.91.4/share/hybrid/Makefile0000664000000000000000000000036612322472605017154 0ustar #!/usr/bin/make -f PROGRAM = gpu-manager PROGRAM_FILES = gpu-manager.c CC = gcc CFLAGS =-g -Wall $(shell pkg-config --cflags --libs pciaccess libdrm) all: build build: $(CC) -o $(PROGRAM) $(PROGRAM_FILES) $(CFLAGS) clean: @rm -f $(PROGRAM) ubuntu-drivers-common-0.2.91.4/share/fake-devices-wrapper0000775000000000000000000000330512322472605020161 0ustar #!/usr/bin/python3 import sys import os import os.path import subprocess try: from gi.repository import UMockdev except ImportError: print('Please install the gir1.2-umockdev-1.0 and umockdev packages for this', file=sys.stderr) sys.exit(1) if len(sys.argv) < 2: print('Usage: %s [args...]' % sys.argv[0], file=sys.stderr) sys.exit(1) testbed = UMockdev.Testbed.new() # fake an installed kmod? if 'FAKE_INSTALLED_KMOD' in os.environ: with open(os.path.join(testbed.get_root_dir(), 'modinfo'), 'w') as f: f.write('''#!/bin/sh -e if [ "$1" = %(mod)s ]; then echo "filename: /some/path/%(mod)s.ko" exit 0 fi exec /sbin/modinfo "$@" ''' % {'mod': os.environ['FAKE_INSTALLED_KMOD']}) os.chmod(os.path.join(testbed.get_root_dir(), 'modinfo'), 0o755) os.environ['PATH'] = '%s:%s' % (testbed.get_root_dir(), os.environ['PATH']) testbed.add_device('pci', 'nvidiacard', None, ['modalias', 'pci:v000010DEd000010C3sv00sd01bc03sc00i00', 'vendor', '0x10DE', 'device', '0x10C3', ], []) testbed.add_device('pci', 'aticard', None, ['modalias', 'pci:v00001002d00009611sv00sd00bc03sc00i00', 'vendor', '0x1002', 'device', '0x9611', ], []) testbed.add_device('pci', 'bcmwifi', None, ['modalias', 'pci:v000014E4d00004353sv00sd01bc02sc80i00', 'vendor', '0x14E4', 'device', '0x4353', ], []) # skip hybrid system detection os.environ['UBUNTU_DRIVERS_XORG_LOG'] = '/dev/null' # run wrapped program subprocess.call(['umockdev-wrapper'] + sys.argv[1:]) ubuntu-drivers-common-0.2.91.4/setup.py0000775000000000000000000000323612322472605014645 0ustar #!/usr/bin/python3 from setuptools import setup import subprocess, glob, os.path import os extra_data = [] # Build hybrid-detect on x86 if '86' in os.uname()[4]: subprocess.check_call(["make", "-C", "share/hybrid", "all"]) extra_data.append(("/usr/bin/", ["share/hybrid/gpu-manager"])) extra_data.append(("/etc/init/", glob.glob("share/hybrid/gpu-manager.conf"))) # Make the nvidia-installer hooks executable for x in glob.glob("nvidia-installer-hooks/*"): os.chmod(x, 0o755) setup( name="ubuntu-drivers-common", author="Alberto Milone", author_email="albertomilone@alice.it", maintainer="Alberto Milone", maintainer_email="albertomilone@alice.it", url="http://www.albertomilone.com", license="gpl", description="Detect and install additional Ubuntu driver packages", packages=["NvidiaDetector", "Quirks", "UbuntuDrivers"], data_files=[("/usr/share/ubuntu-drivers-common/", ["share/obsolete", "share/fake-devices-wrapper"]), ("/var/lib/ubuntu-drivers-common/", []), ("/etc/", []), ("/usr/share/ubuntu-drivers-common/quirks", glob.glob("quirks/*")), ("/usr/share/ubuntu-drivers-common/detect", glob.glob("detect-plugins/*")), ("/usr/share/doc/ubuntu-drivers-common", ['README']), ("/usr/lib/nvidia/", glob.glob("nvidia-installer-hooks/*")), ("/usr/lib/ubiquity/target-config", glob.glob("ubiquity/target-config/*")), ] + extra_data, scripts=["nvidia-detector", "quirks-handler", "ubuntu-drivers"], entry_points="""[packagekit.apt.plugins] what_provides=UbuntuDrivers.PackageKit:what_provides """, ) ubuntu-drivers-common-0.2.91.4/quirks/0000775000000000000000000000000012322472605014442 5ustar ubuntu-drivers-common-0.2.91.4/quirks/put_your_quirks_here0000664000000000000000000000000012322472605020642 0ustar ubuntu-drivers-common-0.2.91.4/quirks/lenovo_thinkpad0000664000000000000000000000077312322472605017560 0ustar Section "Quirk" Identifier "ThinkPad T420s" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "LENOVO" Match "product_version" "ThinkPad T420s" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ubuntu-drivers-common-0.2.91.4/quirks/dell_latitude0000664000000000000000000000077312322472605017207 0ustar Section "Quirk" Identifier "Latitude E6530" Handler "nvidia-current|nvidia-current-updates" Match "sys_vendor" "Dell Inc." Match "product_name" "Latitude E6530" XorgSnippet Section "Device" Identifier "My Card" Driver "nvidia" Option "NoLogo" "True" EndSection Section "Screen" Identifier "My Screen" Option "RegistryDwords" "EnableBrightnessControl=1" EndSection EndXorgSnippet EndSection ubuntu-drivers-common-0.2.91.4/quirks-handler0000775000000000000000000000462412322472605016011 0ustar #!/usr/bin/python3 # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import optparse import os import sys import logging import Quirks.quirkapplier # Here's where we look for quirks quirks_path = '/usr/share/ubuntu-drivers-common/quirks' def main(options): if options.verbose: loglevel = logging.DEBUG else: loglevel = logging.INFO logging.basicConfig(format='%(levelname)s:%(message)s', level=loglevel) if options.package_enable and options.package_disable: sys.exit(1) elif options.package_enable and not options.package_disable: logging.info('Enable %s' % options.package_enable) quirks = Quirks.quirkapplier.QuirkChecker(options.package_enable, path=quirks_path) quirks.enable_quirks() elif not options.package_enable and options.package_disable: logging.info('Disable %s' % options.package_disable) quirks = Quirks.quirkapplier.QuirkChecker(options.package_disable, path=quirks_path) quirks.disable_quirks() else: print('no args') if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option("-e", "--enable-quirks", dest="package_enable", help="enable quirks for package", metavar="FILE") parser.add_option("-d", "--disable-quirks", dest="package_disable", help="disable quirks for package", metavar="FILE") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="show debug messages") (options, args) = parser.parse_args() operation_status = main(options) #sys.exit(operation_status) ubuntu-drivers-common-0.2.91.4/nvidia-installer-hooks/0000775000000000000000000000000012322472605017512 5ustar ubuntu-drivers-common-0.2.91.4/nvidia-installer-hooks/pre-install0000775000000000000000000000017012322472605021670 0ustar #!/bin/sh # Trigger an error exit status to prevent the installer from overwriting # Ubuntu's nvidia packages. exit 1 ubuntu-drivers-common-0.2.91.4/nvidia-detector0000775000000000000000000000041512322472605016133 0ustar #!/usr/bin/python3 import NvidiaDetector from NvidiaDetector.nvidiadetector import NvidiaDetection, NoDatadirError import sys if __name__ == '__main__': try: a = NvidiaDetection(printonly=True, verbose=False) except NoDatadirError: sys.exit(0) ubuntu-drivers-common-0.2.91.4/nvidia-common0000775000000000000000000000101112322472605015603 0ustar #!/bin/bash -e . /usr/share/debconf/confmodule db_set ubuntu-drivers-common/obsolete-driver false db_input high ubuntu-drivers-common/obsolete-driver || true if [ -x /usr/bin/nvidia-detector ]; then LATEST=$(nvidia-detector) if [ ${LATEST} ] && [ "${LATEST}" != "none" ]; then db_fset ubuntu-drivers-common/obsolete-driver seen false db_subst ubuntu-drivers-common/obsolete-driver latest $LATEST db_input high ubuntu-drivers-common/obsolete-driver || true db_go || true fi fi ubuntu-drivers-common-0.2.91.4/detect-plugins/0000775000000000000000000000000012322472605016053 5ustar ubuntu-drivers-common-0.2.91.4/detect-plugins/sl-modem.py0000664000000000000000000000233112322472605020141 0ustar # ubuntu-drivers-common custom detect plugin for sl-modem # # (C) 2012 Canonical Ltd. # Author: Martin Pitt import re import logging import subprocess modem_re = re.compile('^\s*\d+\s*\[Modem\s*\]') modem_as_subdevice_re = re.compile('^card [0-9].*[mM]odem') pkg = 'sl-modem-daemon' def detect(apt_cache): # Check in /proc/asound/cards try: with open('/proc/asound/cards') as f: for l in f: if modem_re.match(l): return [pkg] except IOError as e: logging.debug('could not open /proc/asound/cards: %s', e) # Check aplay -l try: aplay = subprocess.Popen(['aplay', '-l'], env={}, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (aplay_out, aplay_err) = aplay.communicate() if aplay.returncode != 0: logging.error('aplay -l failed with %i: %s' % (aplay.returncode, aplay_err)) return None except OSError: logging.exception('could not open aplay -l') return None for row in aplay_out.splitlines(): if modem_as_subdevice_re.match(row): return [pkg] return None ubuntu-drivers-common-0.2.91.4/detect-plugins/open-vm-dkms.py0000664000000000000000000000041012322472605020735 0ustar # ubuntu-drivers-common custom detect plugin for open-vm-dkms # # (C) 2012 Canonical Ltd. # Author: Martin Pitt import os.path import os def detect(apt_cache): if os.path.exists('/sys/module/vmxnet'): return ['open-vm-dkms'] ubuntu-drivers-common-0.2.91.4/detect-plugins/arm-gles.py0000664000000000000000000000214612322472605020137 0ustar # ubuntu-drivers-common custom detect plugin for arm GLES drivers # # (C) 2012 Canonical Ltd. # Author: Oliver Grawert # # This plugin detects GLES driver packages based on pattern matching # against the "Hardware" line in /proc/cpuinfo. # # To add a new SoC, simply insert a line into the db variable with the # following format: # # '': '', # import logging db = {'OMAP4 Panda board': 'pvr-omap4', 'OMAP4430 Panda Board': 'pvr-omap4', 'OMAP4430 4430SDP board': 'pvr-omap4', 'cardhu': 'nvidia-tegra', 'ventana': 'nvidia-tegra', 'Toshiba AC100 / Dynabook AZ': 'nvidia-tegra', } def detect(apt_cache): board = '' pkg = None try: with open('/proc/cpuinfo') as file: for line in file: if 'Hardware' in line: board = line.split(':')[1].strip() except IOError as err: logging.debug('could not open /proc/cpuinfo: %s', err) for pattern in db.keys(): if pattern in board: pkg = [db[pattern]] return pkg ubuntu-drivers-common-0.2.91.4/debian/0000775000000000000000000000000012322472605014346 5ustar ubuntu-drivers-common-0.2.91.4/debian/ubuntu-drivers-common.templates0000664000000000000000000000056212322472605022555 0ustar Template: ubuntu-drivers-common/obsolete-driver Type: error _Description: Obsolete NVIDIA Driver version The system has detected an obsolete NVIDIA driver in your system. . Please install ${latest} at the end of the installation with the following command: . sudo apt-get install ${latest} . The removal of other NVIDIA drivers will be dealt with automatically. ubuntu-drivers-common-0.2.91.4/debian/ubuntu-drivers-common.install0000664000000000000000000000001412322472605022215 0ustar etc usr var ubuntu-drivers-common-0.2.91.4/debian/ubuntu-drivers-common.config0000664000000000000000000000031512322472605022020 0ustar #! /bin/sh set -e # Do not remove this file. It's supposed to # get debconf to load the template file # when ubuntu-drivers-common is triggered by kernel # hooks. . /usr/share/debconf/confmodule exit 0 ubuntu-drivers-common-0.2.91.4/debian/ubuntu-drivers-common.apport0000664000000000000000000000041612322472605022062 0ustar # apport package hook for ubuntu-drivers-common # (c) 2012 Canonical Ltdt. # Author: Martin Pitt import apport.hookutils def add_info(report, ui): report['UbuntuDriversDebug'] = apport.hookutils.command_output(['ubuntu-drivers', 'debug']) ubuntu-drivers-common-0.2.91.4/debian/tests/0000775000000000000000000000000012322472605015510 5ustar ubuntu-drivers-common-0.2.91.4/debian/tests/system0000775000000000000000000001366012322472605016770 0ustar #!/usr/bin/python3 import sys import os.path import unittest import subprocess from gi.repository import UMockdev srcdir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) testsdir = os.path.join(srcdir, 'tests') sys.path.append(testsdir) def program_out(argv): '''Return (exitcode, out, err) from a program call.''' prog = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) (out, err) = prog.communicate() return (prog.returncode, out, err) def program_out_success(argv, self): '''Return out from a successful program call.''' (code, out, err) = program_out(argv) self.assertEqual(err, '') self.assertEqual(code, 0) return out class TestSystem(unittest.TestCase): '''Run ubuntu-drivers on the current system. We cannot assume anything about the output here, we just ensure that the program is found and works. ''' def test_list(self): '''ubuntu-drivers list succeeds''' program_out_success(['ubuntu-drivers', 'list'], self) def test_debug(self): '''ubuntu-drivers debug succeeds''' o = program_out_success(['ubuntu-drivers', 'debug'], self) # let's assume we have at least one pci device self.assertTrue('\npci:' in o) # finds detection plugins self.assertTrue('Loading custom detection plugin' in o, o) self.assertTrue('sl-modem' in o, o) self.assertTrue('=== matching driver packages ===' in o, o) class TestUbuntuDrivers(unittest.TestCase): '''Check that we can detect and install the most common drivers''' @classmethod def setUpClass(cls): '''Raise an exception if kernel headers are not installed. It could be a @unittest.skip class method but we want a failure because missing headers would mean a broken test environment. ''' assert os.path.exists('/usr/src/linux-headers-' + os.uname()[2]), \ 'Headers not installed for running kernel (%s)' % os.uname()[2] # disable hybrid detection os.environ['UBUNTU_DRIVERS_XORG_LOG'] = '/nonexisting' def setUp(self): self.testbed = UMockdev.Testbed.new() def test_bcmwl(self): '''bcmwl-kernel-source''' self.do_test_driver('pci:v000014E4d00004353sv00sd01bc02sc80i00', 'bcmwl-kernel-source', 'wl', auto_install=True, allow_errors=True) def test_nvidia_304(self): '''nvidia-304''' # we have two matches here, only install nvidia-current, not -updates self.do_test_driver('pci:v000010DEd000010C3sv00sd01bc03sc00i00', 'nvidia-304', 'nvidia_304', auto_install=False) def test_nvidia_304_updates(self): '''nvidia-304-updates''' self.do_test_driver('pci:v000010DEd000010C3sv00sd01bc03sc00i00', 'nvidia-304-updates', 'nvidia_304_updates', auto_install=False) def test_nvidia_331(self): '''nvidia-331''' # we have two matches here, only install nvidia-current, not -updates self.do_test_driver('pci:v000010DEd000010C3sv00sd01bc03sc00i00', 'nvidia-331', 'nvidia_331', auto_install=False) def test_nvidia_331_updates(self): '''nvidia-331-updates''' self.do_test_driver('pci:v000010DEd000010C3sv00sd01bc03sc00i00', 'nvidia-331-updates', 'nvidia_331_updates', auto_install=False) def test_fglrx(self): '''fglrx''' # we have two matches here, only install fglrx, not -updates self.do_test_driver('pci:v00001002d0000990Fsv00sd00bc03sc00i00', 'fglrx', 'fglrx', auto_install=False) def test_fglrx_updates(self): '''fglrx-updates''' self.do_test_driver('pci:v00001002d0000990Fsv00sd00bc03sc00i00', 'fglrx-updates', 'fglrx_updates', auto_install=False) def test_virtualbox(self): '''virtualbox-dkms''' self.do_test_driver(None, 'virtualbox-dkms', 'vboxdrv', auto_install=False) def do_test_driver(self, alias, package, module, auto_install=True, allow_errors=False): if alias: self.testbed.add_device('pci', 'mydev', None, ['modalias', alias], []) # detection works o = program_out_success(['ubuntu-drivers', 'list'], self) self.assertTrue(package + '\n' in o, o) try: if auto_install: # autoinstall works (c, o, e) = program_out(['ubuntu-drivers', 'autoinstall']) self.assertEqual(c, 0, e) if not allow_errors: self.assertEqual(e, '') else: (c, o, e) = program_out(['apt-get', 'install', '-y', package]) self.assertEqual(c, 0, e) if e: print('\n--- Error output from package installation ---\n%s\n------' % e) self.assertTrue(package in o, o) # package is installed o = program_out_success(['dpkg', '-s', package], self) self.assertTrue('Status: install ok installed' in o) # module is available if module: o = program_out_success(['modinfo', module], self) self.assertTrue('filename:' in o) finally: # clean up program_out(['apt-get', 'purge', '--auto-remove', '-y', package]) if module: (c, o, e) = program_out(['modinfo', module]) self.assertNotEqual(c, 0) self.assertIn('ERROR', e) self.assertIn('not found', e) self.assertEqual(o, '', o) # run ourselves through umockdev-wrapper if 'umockdev' not in os.environ.get('LD_PRELOAD', ''): os.execvp('umockdev-wrapper', ['umockdev-wrapper'] + sys.argv) # for autopkgtest we must write to stdout, not stderr, and have an appropriate # exit code unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)) ubuntu-drivers-common-0.2.91.4/debian/tests/control0000664000000000000000000000026112322472605017112 0ustar Tests: system Depends: ubuntu-drivers-common, apport, python3-gi, gir1.2-umockdev-1.0, umockdev, libgl1-mesa-glx, linux-headers-generic | linux-headers Restrictions: needs-root ubuntu-drivers-common-0.2.91.4/debian/source/0000775000000000000000000000000012322472605015646 5ustar ubuntu-drivers-common-0.2.91.4/debian/source/format0000664000000000000000000000001512322472605017055 0ustar 3.0 (native) ubuntu-drivers-common-0.2.91.4/debian/rules0000775000000000000000000000354512322472605015435 0ustar #!/usr/bin/make -f DEB_VERSION=$(shell dpkg-parsechangelog | grep ^Version | cut -f2 -d\ |cut -f1 -d-) DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH) py3sdo=set -e; $(foreach py, $(shell py3versions -r), $(py) $(1);) %: dh "$@" --with python3,apport override_dh_auto_build: $(call py3sdo, setup.py build) override_dh_auto_install: $(call py3sdo, setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb) override_dh_auto_test: ifeq (, $(findstring nocheck, $(DEB_BUILD_OPTIONS))) $(call py3sdo, setup.py egg_info) set -e; $(foreach py, $(shell py3versions -r), PYTHONPATH=. $(py) -B tests/run || [ "$(DEB_HOST_ARCH)" = powerpc ];) endif override_dh_auto_clean: $(call py3sdo, setup.py clean) override_dh_install: dh_install --fail-missing # build dh_modaliases manpage mkdir -p debian/dh-modaliases/usr/share/man/man1 pod2man -c Debhelper -r "$(DEB_VERSION)" debhelper/dh_modaliases debian/dh-modaliases/usr/share/man/man1/dh_modaliases.1 # clean up old upstart conffile for hybrid-detect if [ ! -e debian/ubuntu-drivers-common/usr/bin/hybrid-detect ]; then \ echo "rm_conffile /etc/init/hybrid-gfx.conf 1:0.2.91~" > debian/ubuntu-drivers-common.maintscript; \ fi # clean up upstart conffile on upgrade on architectures which do not # ship gpu-manager if [ ! -e debian/ubuntu-drivers-common/usr/bin/gpu-manager ]; then \ echo "rm_conffile /etc/init/gpu-manager.conf 1:0.2.91~" >> debian/ubuntu-drivers-common.maintscript; \ fi # Remove fglrx-pxpress' upstart job echo "rm_conffile /etc/init/amd-config.conf 1:0.2.91.1~" >> debian/ubuntu-drivers-common.maintscript override_dh_python3: dh_python3 --shebang=/usr/bin/python3 override_dh_clean: rm -f share/hybrid/hybrid-detect rm -f share/hybrid/gpu-manager rm -f quirksreader_test*.txt rm -rf build rm -rf *.egg-info rm -f debian/ubuntu-drivers-common.maintscript dh_clean ubuntu-drivers-common-0.2.91.4/debian/po/0000775000000000000000000000000012322472605014764 5ustar ubuntu-drivers-common-0.2.91.4/debian/po/templates.pot0000664000000000000000000000252412322472605017511 0ustar # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: Source: ubuntu-drivers-common@packages.debian.org\n" "POT-Creation-Date: 2008-07-10 15:41+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #. Type: error #. Description #: ../ubuntu-drivers-common.templates:1001 msgid "Obsolete NVIDIA Driver version" msgstr "" #. Type: error #. Description #: ../ubuntu-drivers-common.templates:1001 msgid "The system has detected an obsolete NVIDIA driver in your system." msgstr "" #. Type: error #. Description #: ../ubuntu-drivers-common.templates:1001 msgid "" "Please install ${latest} at the end of the installation with the following " "command:" msgstr "" #. Type: error #. Description #: ../ubuntu-drivers-common.templates:1001 msgid "sudo apt-get install ${latest}" msgstr "" #. Type: error #. Description #: ../ubuntu-drivers-common.templates:1001 msgid "The removal of other NVIDIA drivers will be dealt with automatically." msgstr "" ubuntu-drivers-common-0.2.91.4/debian/po/POTFILES.in0000664000000000000000000000007212322472605016540 0ustar [type: gettext/rfc822deb] ubuntu-drivers-common.templates ubuntu-drivers-common-0.2.91.4/debian/dh-modaliases.install0000664000000000000000000000014212322472605020445 0ustar debhelper/dh_modaliases usr/bin debhelper/modaliases.pm usr/share/perl5/Debian/Debhelper/Sequence ubuntu-drivers-common-0.2.91.4/debian/copyright0000664000000000000000000000117212322472605016302 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Files: * Copyright: Copyright (c) 2008 Alberto Milone License: GPL-2+ Files: UbuntuDrivers/* tests/ubuntu_drivers.py ubuntu-drivers Copyright: Copyright (c) 2012 Canonical Ltd. License: GPL-2+ License: GPL-2+ This program 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 2 of the License, or (at your option) any later version. . The full text of the GPL is distributed as in /usr/share/common-licenses/GPL-2 on Debian systems. ubuntu-drivers-common-0.2.91.4/debian/control0000664000000000000000000000727212322472605015761 0ustar Source: ubuntu-drivers-common Section: admin Priority: optional Maintainer: Ubuntu Developers Build-Depends: debhelper (>= 9), po-debconf, dh-apport, python3-all (>= 3.2), python3-setuptools, libpciaccess-dev (>= 0.12.1-2), lib32gcc1 [amd64], libc6-i386 [amd64], linux-libc-dev, pkg-config, python3-xkit (>= 0.5.0), aptdaemon, python3-aptdaemon.pkcompat, python3-aptdaemon.test (>= 0.43+bzr810-0ubuntu2~), python3-gi, gir1.2-glib-2.0, gir1.2-packagekitglib-1.0, gir1.2-umockdev-1.0, umockdev, alsa-utils, apt-utils, dbus, udev, pciutils, libdrm-dev, python3-dbus Standards-Version: 3.9.5 Vcs-Git: git://github.com/tseliot/ubuntu-drivers-common.git Vcs-Browser: https://github.com/tseliot/ubuntu-drivers-common X-Python3-Version: >= 3.2 XS-Testsuite: autopkgtest Package: ubuntu-drivers-common Architecture: any Pre-Depends: dpkg (>= 1.15.7.2) Depends: ${python3:Depends}, ${misc:Depends}, ${shlibs:Depends}, debconf (>= 0.5.00) | debconf-2.0, pciutils, python3-apt, python3-xkit, udev (>= 204-0ubuntu4~), pciutils, usbutils, alsa-utils, kmod | module-init-tools, Suggests: python3-aptdaemon.pkcompat Replaces: nvidia-common (<< 1:0.2.46), jockey-common, jockey-gtk, jockey-kde Conflicts: nvidia-common (<< 1:0.2.46), jockey-common, jockey-gtk, jockey-kde Breaks: nvidia-prime (<< 0.6) Provides: nvidia-common, jockey-common, jockey-gtk, jockey-kde Enhances: packagekit-system-interface Description: Detect and install additional Ubuntu driver packages This package aggregates and abstracts Ubuntu specific logic and knowledge about third-party driver packages. It provides: . - a Python API for detecting driver packages for a particular piece of hardware or the whole system. . - an "ubuntu-drivers" command line tool to list or install driver packages (mostly for integration in installers). . - a PackageKit plugin for WhatProvides() for types MODALIAS and HARDWARE_DRIVER, to do the same queries as above through the PackageKit API (for using in non-distro specific GUIs). This works with aptdaemon's PackageKit compatibility layer (python3-aptdaemon.pkcompat) and with PackageKit's apt backend, but _not_ with the PackageKit aptcc backend. . - some NVidia specific support code to find the most appropriate driver version, as well as setting up the alternatives symlinks that the proprietary NVidia and FGLRX packages use. Package: dh-modaliases Architecture: all Depends: ${perl:Depends}, ${misc:Depends} Enhances: debhelper Description: debhelper extension for scanning kernel module aliases dh_modaliases is useful for packages that ship third-party kernel modules, either in binary form, or as sources (with e. g. DKMS). It extracts the modules' modaliases from either the compile .ko files themselves (for packages which ship them in compiled form, using modinfo), or from a package file debian/packagename.modaliases. . This enables software which is looking for missing driver packages (such as Jockey or the operating system installer) to identify which package(s) will provide a driver for a piece of hardware, identified by its modalias. Package: nvidia-common Section: oldlibs Priority: extra Architecture: i386 amd64 armel armhf Depends: ubuntu-drivers-common, ${misc:Depends} Description: transitional package for ubuntu-drivers-common This is a transitional package for ubuntu-drivers-common. You can remove it after upgrading. Package: fglrx-pxpress Section: oldlibs Priority: extra Architecture: i386 amd64 Depends: ubuntu-drivers-common, ${misc:Depends} Description: transitional package for ubuntu-drivers-common This is a transitional package for ubuntu-drivers-common. You can remove it after upgrading. ubuntu-drivers-common-0.2.91.4/debian/compat0000664000000000000000000000000212322472605015544 0ustar 9 ubuntu-drivers-common-0.2.91.4/debian/changelog0000664000000000000000000014157412322472605016234 0ustar ubuntu-drivers-common (1:0.2.91.4) trusty; urgency=medium * Force removal of jockey on upgrades. It has been replaced with ubuntu-drivers-common two cycles ago, removed from trusty, and now just crashes due to API changes in aptdaemon. (LP: #1216193) -- Martin Pitt Sun, 13 Apr 2014 13:31:11 +0200 ubuntu-drivers-common (1:0.2.91.3) trusty; urgency=medium * gpu-manager.c: - Move away the xorg.conf if mesa is selected as a fallback and binary drivers are still in use in the xorg.conf. This will prevent X from failing when users on hybrid systems uninstall a binary driver. -- Alberto Milone Wed, 09 Apr 2014 17:06:53 +0200 ubuntu-drivers-common (1:0.2.91.2) trusty; urgency=medium * gpu-manager.c: - Always check that devices are bound to a driver. This works better than blacklisting the 0380 class, and should help systems such as the one in LP: #1301839. -- Alberto Milone Mon, 07 Apr 2014 17:52:29 +0200 ubuntu-drivers-common (1:0.2.91.1) trusty; urgency=medium * debian/control, debian/rules: - Obsolete and replace fglrx-pxpress. The gpu-manager already deals with AMD GPUs. -- Alberto Milone Fri, 21 Mar 2014 19:03:20 +0100 ubuntu-drivers-common (1:0.2.91) trusty; urgency=medium * debian/control: - Add build dependency on libdrm-dev. * debian/rules: - Remove /etc/init/hybrid-gfx.conf. - Also remove the current upstart job from the architectures that don't ship gpu-manager. * gpu-manager.c, tests/gpu-manager.py: - Replace laptop specific hack to detect the need to offload rendering to the discrete card with code that opens the available drm devices and checks the connected outputs. If any outputs are connected to the Intel card, then we choose offloading. This also helps when the monitor is still connected to Intel on desktop systems with Intel + NVIDIA systems. - Preliminary work to reduce code duplication in nvidia-prime. * tests/ubuntu_drivers.py: - Do not abort if test_auto_install_system fails. -- Alberto Milone Wed, 19 Mar 2014 14:49:04 +0100 ubuntu-drivers-common (1:0.2.90) trusty; urgency=low * gpu-manager.c, gpu-manager.py: - Match only PCI_CLASS_DISPLAY, except for PCI_CLASS_DISPLAY_OTHER. - Re-enable outputs connected to NVIDIA discrete cards. This only affects Optimus systems (LP: #1290711). - Prevent possible buffer overflow when reading the configuration from last boot. - Clean up and make get_output() more robust (LP: #1290831). -- Alberto Milone Thu, 13 Mar 2014 10:15:06 +0100 ubuntu-drivers-common (1:0.2.89.6) trusty; urgency=low * gpu-manager.c: - Take action if settings don't match the current bbswitch status (LP: #1289420). -- Alberto Milone Sat, 08 Mar 2014 17:07:28 +0100 ubuntu-drivers-common (1:0.2.89.5) trusty; urgency=low * tests/run: - Skip gpu-manager.py on anything other than the x86 family. -- Alberto Milone Sat, 08 Mar 2014 01:26:18 +0100 ubuntu-drivers-common (1:0.2.89.4) trusty; urgency=medium [ Martin Pitt ] * Reenable tests. * Mark the three failing tests as expected failure instead of skipping them entirely, so that we can see what they do on the buildds. [ Alberto Milone ] * tests/gpu-manager.py: - Refactor the test suite by reusing more code and reducing the overall code. - Add test case for zero length dmi product version. * share/hybrid/gpu-manager.c: - Do not try to match quirks if dmi product version has zero length (LP: #1289298). -- Alberto Milone Fri, 07 Mar 2014 22:54:22 +0100 ubuntu-drivers-common (1:0.2.89.3) trusty; urgency=low * debian/rules: - Temporarily disable all tests. We'll switch them back on as soon as we find out the cause of these failures. * tests/gpu-manager.py: - Do not run on anything but x86 family. -- Alberto Milone Thu, 06 Mar 2014 16:30:54 +0100 ubuntu-drivers-common (1:0.2.89.2) trusty; urgency=low * tests/gpu-manager.py: - Fix FTBFS. -- Alberto Milone Thu, 06 Mar 2014 11:45:29 +0100 ubuntu-drivers-common (1:0.2.89.1) trusty; urgency=low * tests/gpu-manager.py: - Remove leftover print that caused tests to fail in -proposed. -- Alberto Milone Thu, 06 Mar 2014 10:47:44 +0100 ubuntu-drivers-common (1:0.2.89) trusty; urgency=low * debian/control: - Breaks: nvidia-prime (<< 0.6). We don't want the gpu-manager to compete with the old nvidia-prime on hybrid systems. * share/hybrid/gpu-manager.c: - Fix memory leaks and complete the different test cases. * tests/gpu-manager.py: - Add test suite for gpu-manager to reproduce different hardware/software scenarios. * UbuntuDrivers/detect.py, tests/ubuntu_drivers.py: - Enable installing graphics drivers on laptops with hybrid graphics (LP: #1126234), and on desktop systems where the BIOS doesn't disable the integrated GPU when a discrete card is available (LP: #1126234). This is now possible thanks to the gpu-manager (now enabled by default). * Replace the deprecated hybrid-detect program with gpu-manager (now enabled by default). In case of problems with the gpu-manager, it can be disabled by passing "nogpumanager" as a boot parameter. -- Alberto Milone Thu, 06 Mar 2014 09:24:54 +0100 ubuntu-drivers-common (1:0.2.88) trusty; urgency=medium * debian/tests/control: Add missing linux-headers test dependency. * Drop python3-aptdaemon.pkcompat recommends to a suggests, to avoid pulling it into Kubuntu. * share/hybrid/gpu-manager.c: - Add the new gpu manager. This will replace hybrid-detect as soon as test coverage is complete. * tests/ubuntu_drivers.py: - Skip test_list_system() and test_devices_system() for now. We need to find a way to pass syspath without the whole APT_CONFIG env var, or the tests will fail if system packages match real system hardware. -- Alberto Milone Thu, 20 Feb 2014 17:13:36 +0100 ubuntu-drivers-common (1:0.2.87) trusty; urgency=low * tests/ubuntu_drivers.py: Reduce the expected system modaliases from > 5 to > 3, as our arm64 builders seem a bit hardware deprived. Fixes FTBFS on arm64. -- Martin Pitt Thu, 05 Dec 2013 10:20:08 +0100 ubuntu-drivers-common (1:0.2.86) trusty; urgency=low * debian/tests/system: nvidia-319 is now a transitional package, update tests to check nvidia-331 instead. -- Martin Pitt Thu, 05 Dec 2013 09:52:58 +0100 ubuntu-drivers-common (1:0.2.85) trusty; urgency=low * Depend on kmod | module-init-tools. Apparently some users manage to uninstall it. (LP: #1087222) * Bump Standards-Version to 3.9.5. No changes necessary. -- Martin Pitt Thu, 05 Dec 2013 07:55:48 +0100 ubuntu-drivers-common (1:0.2.84) trusty; urgency=low * debian/tests/system: Update check of modinfo error message to also work with current kmod. -- Martin Pitt Mon, 04 Nov 2013 10:33:44 +0100 ubuntu-drivers-common (1:0.2.83) saucy; urgency=low * debian/tests/control: Install libgl1-mesa-glx for the tests, so that the fglrx packages don't fail to install. * debian/tests/system: nvidia-{310,313} are now transitional, drop tests and test nvidia-319{,-updates} instead. -- Martin Pitt Fri, 05 Jul 2013 11:13:45 +0200 ubuntu-drivers-common (1:0.2.82) saucy; urgency=low * debian/tests/system: Accept stderr messages from the TestUbuntuDrivers.test_bcmwl() test, as this spits out lots of libkmod errors due to the rather thin umockdev environment. -- Martin Pitt Wed, 19 Jun 2013 07:30:38 +0200 ubuntu-drivers-common (1:0.2.81) saucy; urgency=low * debian/tests/system: Port to umockdev. * share/fake-devices-wrapper: Fix fake bcmwl modalias. -- Martin Pitt Tue, 18 Jun 2013 22:23:14 +0200 ubuntu-drivers-common (1:0.2.80) saucy; urgency=low * Make test failures non-fatal on powerpc. -- Martin Pitt Tue, 18 Jun 2013 17:17:16 +0200 ubuntu-drivers-common (1:0.2.79) saucy; urgency=low * Skip test_system_driver_packages_bad_encoding() on powerpc. It's not obvious why it fails there, and without a porter box there is little we can do. -- Martin Pitt Tue, 18 Jun 2013 14:48:01 +0200 ubuntu-drivers-common (1:0.2.78) saucy; urgency=low * debian/tests/system: Drop usage of fakesys.py, should not actually be necessary. * Drop tests/fakesysfs.py, not used any more and obsolete. * Bump Standards-Version to 3.9.4 (no changes necessary). * UbuntuDrivers/detect.py, system_aliases(): Tone down "Cannot read modalias file" warning into a debug statement; this isn't particularly interesting or an error the user could do something about, and it breaks tests on powerpc. -- Martin Pitt Tue, 18 Jun 2013 13:43:05 +0200 ubuntu-drivers-common (1:0.2.77) saucy; urgency=low * detect.py, _get_db_name(): Call "udevadm hwdb" instead of the old /lib/udev/*-db helpers; the latter don't exist any more. This brings back vendor/product names. Bump udev dependency accordingly. (LP: #1186777) * share/fake-devices-wrapper: Rewrite using umockdev, our fakesys.py does not work any more with current libudev. * Port test suite from fakesys.py to umockdev. Add umockdev build-dependency for this (see MIR LP #1190926) -- Martin Pitt Fri, 14 Jun 2013 14:20:21 +0200 ubuntu-drivers-common (1:0.2.76) raring; urgency=low * debian/tests/system: nvidia-current is now a transitional package, so change tests to test -304. * debian/tests/system: Add tests for nvidia-310 and -313-updates. * debian/tests/system: Drop sl-modem test case. We don't officially support it, and it's broken at the moment. The package build test should move into sl-modem itself if anyone is interested in keeping it alive. -- Martin Pitt Mon, 18 Mar 2013 13:12:14 +0100 ubuntu-drivers-common (1:0.2.75) raring; urgency=low * UbuntuDrivers/detect.py: - Add get_linux() which returns the linux metapackage name. * UbuntuDrivers/kerneldetection.py: - Rely on the source name only for "-lts" packages (a special case). - Add KernelDetection.get_linux_metapackage(). * tests/ubuntu_drivers.py: - Add more tests with different kernel names. - Extend test coverage to both get_linux() and get_linux_headers() from UbuntuDrivers/detect.py. -- Alberto Milone Wed, 30 Jan 2013 12:08:59 +0100 ubuntu-drivers-common (1:0.2.74) raring; urgency=low [ Martin Pitt ] * hybrid-detect.c: Fix detection of i386 architecture. Thanks Dennis Baurichter! (LP: #1096354) [ Alberto Milone ] * NvidiaDetector/nvidiadetector.py: Exclude -current from the recommended flavours. The -current flavour is now a transitional package therefore we should not recommend it any more. * UbuntuDrivers/kerneldetection.py, UbuntuDrivers/detect.py, tests/ubuntu_drivers.py: Add support for checking and suggesting the required linux headers. -- Alberto Milone Tue, 29 Jan 2013 13:30:50 +0100 ubuntu-drivers-common (1:0.2.73) raring; urgency=low * debian/tests/control: Add apport to test dependencies, so that the DKMS hook can generate proper crash files which will help with debugging. * debian/tests/system: In the Broadcom wifi test, use a proper device class and subclass, as the current driver matches on those now. -- Martin Pitt Thu, 13 Dec 2012 16:02:42 +0100 ubuntu-drivers-common (1:0.2.72) raring; urgency=low [ Matthias Klose ] * Build-depend on python3-all. [ Dmitrijs Ledkovs ] * Use /usr/bin/python3 shebang. [ Martin Pitt ] * debian/tests/system: Fix duplicate output of error message for test failures. * tests/ubuntu_drivers.py, test_devices_detect_plugins(): Fix failure if special.py occurs first in the output. This bug was triggered by Python 3.3's new hash randomization behaviour. (LP: #1071997) * UbuntuDrivers/detect.py: Fix UnicodeDecodeError crash when encountering a package with invalid UTF-8 encoding. Just skip those packages instead. Add test to tests/ubuntu_drivers.py. -- Martin Pitt Wed, 07 Nov 2012 15:47:19 +0100 ubuntu-drivers-common (1:0.2.71.1) quantal-proposed; urgency=low * NvidiaDetector/nvidiadetector.py: - Make sure to never recommend experimental drivers (LP: #1070795). -- Alberto Milone Wed, 24 Oct 2012 16:42:19 +0200 ubuntu-drivers-common (1:0.2.71) quantal; urgency=low * tests/ubuntu_drivers.py: When calling PackageKit, retry up to 5 seconds on o.f.d.Error.ServiceUnknown, so that this also works reliably on our slow ARM builders. (LP: #1061748) -- Martin Pitt Fri, 05 Oct 2012 08:25:30 +0200 ubuntu-drivers-common (1:0.2.70) quantal; urgency=low * UbuntuDrivers/detect.py: Never recommend a driver which has "experiment" in the name, unless no other driver is available. -- Martin Pitt Thu, 04 Oct 2012 22:59:33 +0200 ubuntu-drivers-common (1:0.2.69) quantal; urgency=low * Drop share/last_gfx_boot, and stop installing it in setup.py. This file is created and updated at runtime and should not be shipped in the package. (LP: #1045629) * setup.py: Only install the upstart job on platforms where we build hybrid-detect. (LP: #1045193) * debian/rules: On architectures which do not ship hybrid-detect, generate a .maintscript helper to clean up the /etc/init/hybrid-gfx.conf upstart job conffile on upgrade. * tests/ubuntu_drivers.py: Add test for a video driver which supports multiple X.org video ABIs. Reproduces LP #1033222. * UbuntuDrivers/detect.py, _check_video_abi_compat(): Do not only consider the first xorg-video-abi-* dependency, but all of them. (LP: #1033222) -- Martin Pitt Thu, 06 Sep 2012 15:18:26 +0200 ubuntu-drivers-common (1:0.2.68) quantal; urgency=low * setup.py: Fix hybrid_detect installation. (LP: #1026787) -- Jason Conti Fri, 20 Jul 2012 05:45:14 +0200 ubuntu-drivers-common (1:0.2.67) quantal; urgency=low * setup.py: Install hybrid-detect through data_files instead of scripts, as the later stopped working with python 3.2.3-3 (see LP #1026016) -- Martin Pitt Wed, 18 Jul 2012 10:23:05 +0200 ubuntu-drivers-common (1:0.2.66) quantal; urgency=low * UbuntuDrivers/detect.py, system_device_drivers(): Add driver flag "manual_installed" if none of the driver packages are installed, but the corresponding kernel module is available. This usually means that the user installed the driver manually from upstream. (LP: #1025632) * share/fake-devices-wrapper: If $FAKE_INSTALLED_KMOD is set, run the wrapped program with a "modinfo" wrapper in $PATH which claims that the given kernel module name is available. This can be used to test the "manually installed driver" case. -- Martin Pitt Wed, 18 Jul 2012 09:29:59 +0200 ubuntu-drivers-common (1:0.2.65) quantal; urgency=low * UbuntuDrivers/detect.py, system_driver_packages(): Add 'recommended' flag to the nvidia-* and fglrx-* packages, which usually provide more than one package for a particular device. (LP: #1025315) * UbuntuDrivers/detect.py, auto_install_filter(): Filter out non-recommended packages, to avoid installing multiple versions of the NVidia or FGLRX driver. * UbuntuDrivers/detect.py: Change return value of detect_plugin_packages() to a plugin_name → [package, ...] map, so that we retain the plugin names. * UbuntuDrivers/detect.py: Add system_device_drivers() API to get a by-device view of drivers, plus OS builtin free alternatives (such as Nouveau). Add it to README as well. (LP: #1025323) * ubuntu-drivers: Add "device" command to show by-device drivers as reported by system_device_drivers(). -- Martin Pitt Tue, 17 Jul 2012 15:48:44 +0200 ubuntu-drivers-common (1:0.2.64) quantal; urgency=low * debian/control: Add pciutils and usbutilsl build/binary dependencies, so that pci-db and usb-db actually have some data files to work with. -- Martin Pitt Fri, 13 Jul 2012 11:08:02 +0200 ubuntu-drivers-common (1:0.2.63) quantal; urgency=low * debian/control: Add udev build/binary dependency, to ensure we have pci-db and usb-db. -- Martin Pitt Fri, 13 Jul 2012 10:52:46 +0200 ubuntu-drivers-common (1:0.2.62) quantal; urgency=low * debian/control: As the PackageKit apt backend is going away, drop the Conflicts to packagekit-backend-aptcc. Instead, recommend python3-aptdaemon.pkcompat and update the description to point out that the PackageKit API does not work with the aptcc backend. (LP: #1023953) * UbuntuDrivers.detect.py, system_driver_packages(): Add 'vendor' and 'model' fields for the human readable names from pci/usb databases. -- Martin Pitt Fri, 13 Jul 2012 10:41:12 +0200 ubuntu-drivers-common (1:0.2.61) quantal; urgency=low * NvidiaDetector/nvidiadetector.py: Fix crash if there is only one card. (LP: #1021305) * Add share/fake-devices-wrapper: Wrapper script to run a command under a mock sysfs tree which pretends to have an NVidia and ATI graphics card, and a Broadcom wifi card. This can be used for testing the new software-properties or other driver management software. -- Martin Pitt Thu, 12 Jul 2012 16:49:08 +0200 ubuntu-drivers-common (1:0.2.60) quantal; urgency=low * libudev uses $SYSFS_PATH, not $SYSFS. Fix test suite accordingly. * debian/tests/system: Raise a more specific exception if headers for the running kernel are not installed. Thanks to Jean-Baptiste Lallement for the intial patch! (LP: #1021386) -- Martin Pitt Fri, 06 Jul 2012 07:47:09 +0200 ubuntu-drivers-common (1:0.2.59) quantal; urgency=low * UbuntuDrivers/detect.py: Fix crash on non-ASCII characters in Xorg log. Adjust test case to reproduce this. (LP: #1020329). -- Martin Pitt Tue, 03 Jul 2012 12:38:39 +0200 ubuntu-drivers-common (1:0.2.58) quantal; urgency=low * Add detect-plugins/arm-gles.py, thanks Oliver Grawert! (LP: #1016006) * debian/tests/system: Add test for virtualbox-dkms. * debian/tests/system: Add test for sl-modem-dkms. -- Martin Pitt Tue, 26 Jun 2012 07:55:43 +0200 ubuntu-drivers-common (1:0.2.57) quantal; urgency=low * debian/tests/control: Drop undefined "no-build-needed" feature. * debian/tests/system: NVidia and FGLRX drivers produce some stderr output when installing the packages. Don't fail on them, but do show the output in the test suite. -- Martin Pitt Thu, 21 Jun 2012 08:32:59 +0200 ubuntu-drivers-common (1:0.2.56) quantal; urgency=low * UbuntuDrivers/detect.py: Add nvidia-* for automatic installation after discussion with Chris. The proprietary driver is still the better choice (if you click "proprietary 3rd party drivers" in Ubiquity) until Nouveau enables power management. * tests/ubuntu_drivers.py: Update test_auto_install_chroot() for above change, as nvidia now does get installed automatically. * Quirks/quirkapplier.py: Update to current xkit API: Call write(), not writeFile(). (LP: #1014728) * UbuntuDrivers/detect.py: Change system_modaliases() to return an alias → sysfs_path map, instead of just a list of aliases. * UbuntuDrivers/detect.py: Change system_driver_packages() to return a package → info map, instead of just a list of packages. UI can use the info to show which device requested a driver, whether it is free or proprietary, and whether it is a distro or third-party package. (LP: #1013665) * Fix fd leaks from subprocess in the test suite. * Add debian/tests/system and debian/tests/control: Add autopkg test to check that we can detect, install, and remove the nvidia, fglrx, and bcmwl drivers. Due to their nature of being compiled on the client side and depend on matching kernel headers/API, they are inherently a bit brittle and thus we should spot regressions immediately. -- Martin Pitt Wed, 20 Jun 2012 16:54:23 +0200 ubuntu-drivers-common (1:0.2.55) quantal; urgency=low [ Martin Pitt ] * UbuntuDrivers/detect.py: Auto-install virtualbox-guest-dkms. * UbuntuDrivers/PackageKit.py: If packagekit.enums is not available, fall back to aptdaemon.pkenums. This will allow us to move to Python3 without waiting for PackageKit. * Revert Dmitrijs' relative imports and move back to Python3 compatible absolute imports. * quirks-handler, setup.py: Move to Python 3 as well. [ Dmitrijs Ledkovs ] * NvidiaDetector/nvidiadetector.py: Use python3 compatible syntax. * Convert package to python3 only. -- Martin Pitt Thu, 14 Jun 2012 08:05:47 +0200 ubuntu-drivers-common (1:0.2.54) quantal; urgency=low * debian/control: depend on python-xkit (>= 0.5.0). * Quirks/quirkapplier.py, Quirks/quirkreader.py tests/quirkreader-test.py: - Add support for the new python-xkit API. -- Alberto Milone Fri, 08 Jun 2012 16:36:02 +0200 ubuntu-drivers-common (1:0.2.53) quantal; urgency=low * debian/control: Drop hard packagekit/aptdeamon dependencies, and move them to Suggests/Enhances. We do not need them for the core code, just for the PackageKit plugin. * UbuntuDrivers/PackageKit.py: Drop system_driver_packages(), as it is really not that useful: For UIs using the PackageKit API you cannot call it, and for Ubuntu specific UIs you can use the faster UbuntuDrivers.detect API. Instead, provide the functionality through the WhatProvides(HARDWARE_DRIVER, "drivers_for_attached_hardware") call, which is defined in PackageKit. Adjust tests accordingly. * debian/control: Update description. * debian/control: Drop obsolete XB-Python-Version. * debian/control: Move packagekit-backend-aptcc from Breaks to Conflicts, as it is unversioned. * UbuntuDrivers/PackageKit.py: Add pkcon example for HARDWARE_DRIVERS to header comment. * UbuntuDrivers/detect.py, packages_for_modalias(): Avoid returning the same package multiple times. * Add README: Document purpose, interfaces, and detection logic. * Add debian/ubuntu-drivers-common.apport: Apport hook to include the output of "ubutu-drivers debug". Add dh-apport build dependency and enable in debian/rules. * Add dh-modaliases, moved from the obsolete Jockey package: - Add debhelper/dh_modaliases: Debhelper program to produce a ${modaliases} substvar from scanning .ko files or debian/packagename.modaliases. - Add debhelper/modaliases.pm: dh_auto sequencer for dh_modaliases. - Add debian/dh-modaliases.install: Install above files. - debian/control: Add dh-modaliases package. - debian/rules: Create manpage from dh_modaliases POD. * Add debhelper/test_dh_modaliases: Old test script for dh_modaliases from Jockey. This is not integrated into "make check" and uses the snd_hda_intel kernel module from the system; this needs to be run manually for now. * debian/rules: Respect "nocheck" in $DEB_BUILD_OPTIONS. -- Martin Pitt Thu, 31 May 2012 10:35:26 +0200 ubuntu-drivers-common (1:0.2.52) quantal; urgency=low * ubuntu-drivers: Add --package-list option to create a file with the list of installed packages in "autoinstall" mode. * Add ubiquity/target-config/31ubuntu_driver_packages: Ubiquity plugin to install all packages that "ubuntu-drivers autoinstall" installed into the live system. Install it in setup.py. * ubuntu-drivers: Stop meddling with the debconf environment variables. It is wrong (and too late anyway for Ubiquity) to do it here. The complete environment setting is now done in Ubiquity's simple-plugins. -- Martin Pitt Tue, 29 May 2012 16:00:21 +0200 ubuntu-drivers-common (1:0.2.51) quantal; urgency=low * detect-plugins/sl-modem.py: Do not log an exception when /proc/asound/cards does not exist (such as in the buildds), as it causes the test_plugin_errors test to fail. -- Martin Pitt Tue, 29 May 2012 10:24:51 +0200 ubuntu-drivers-common (1:0.2.50) quantal; urgency=low * debian/control: Add alsa-utils build and binary dependency, so that the sl-modem handler can call aplay. -- Martin Pitt Tue, 29 May 2012 09:49:10 +0200 ubuntu-drivers-common (1:0.2.49) quantal; urgency=low * Fix exception, print, and assert syntax to be Python 3 compatible. * Fix octal number and iteration syntax to be Python 3 compatible. * Add .gitignore to ignore built stuff. * tests/run: Clean up generated settings.py file on exit. * Add detect-plugins/sl-modem.py: Custom detect plugin for the sl-modem-daemon special case (formerly handled by Jockey's sl_modem.py handler). * debian/rules: Simplify running the tests. * tests/ubuntu_drivers.py: Fix temporary log level changing. -- Martin Pitt Tue, 29 May 2012 08:36:29 +0200 ubuntu-drivers-common (1:0.2.48) quantal; urgency=low * ubuntu-drivers: Fix duplicate system modalias debug messages. * UbuntuDrivers/detect.py: Disable two debug messages which cause excessive debug log spew and are not very interesting. * ubuntu-drivers autoinstall: Do not reinstall already installed drivers. * Add detect-plugins/open-vm-dkms.py: Custom detect plugin for the open-vm-dkms special case (formerly handled by Jockeys' vmware-client.py handler). * setup.py: Install detect-plugins/*. * tests/ubuntu_drivers.py: Add PluginsTest to check that shipped plugins work without errors or crashes. * UbuntuDrivers/detect.py, _check_video_abi_compat(): Disable NVidia driver if X.org's log shows that the Intel driver is loaded. This prevents breaking hybrid systems as long as the NVidia driver and X.org do not work on those. * debian/ubuntu-drivers-common.templates: Drop trailing whitespace, to stop lintian from complaining. * debian/control: Add missing ${misc:Depends} to transitional package. * debian/control: Add missing ${shlibs:Depends} for hybrid-detect. * debian/control: Set priority of the nividia-common transitional package to "extra" to quiesce lintian. -- Martin Pitt Fri, 25 May 2012 13:58:21 +0200 ubuntu-drivers-common (1:0.2.47) quantal; urgency=low * UbuntuDrivers/detect.py, system_modaliases(): Catch/log IOErrors when trying to open "modalias" files in /sys. On powerpc we get a "No such device" error on some files, causing test failures. * tests/ubuntu_drivers.py, ToolTest: Explicitly set --log in the chroot's DPKG::options::. The buildds seem to have a dpkg configuration which needs that, otherwise it's trying to write into the system log file. -- Martin Pitt Fri, 25 May 2012 06:54:13 +0200 ubuntu-drivers-common (1:0.2.46) quantal; urgency=low * Rename to ubuntu-drivers-common, as this package is already necessary for fglrx as well, and will soon get support for more drivers (replacing Jockey). Update file references and names everywhere, and drop the obsolete debian/README.Debian and debian/nvidia-common.preinst. * debian/control: Fix for current python packaging policy (XS- → X-), and drop obsolete debian/pycompat. * debian/control: Add Vcs-* tags. * setup.py: Move from distutils to setuptools, to get an egg info (needed to provide PackageKit plugins). Add python-setuptools build dependency. * Add tests/fakesysfs.py: Provide a fake sysfs directory for testing. Adapted from upower's integration test suite. * Add tests/testarchive.py: Class for building an apt archive with test packages. * Add UbuntuDrivers/detect.py, tests/ubuntu_drivers.py: Hardware/driver detection functionality. These are borrowed and streamlined from Jockey. * Add aptdaemon/PackageKit (apt backend) plugin for what-provides MODALIAS: - Add UbuntuDrivers/PackageKit.py: The actual plugin, which checks the query against the patterns packages specify in their "Modaliases:" header. Also provides a system_driver_packages() function to get all driver packages applicable for the system. - setup.py: Install the new UbuntuDrivers Python package and register the plugin entry point. - tests/ubuntu_drivers.py: Add tests cases for UbuntuDrivers.PackageKit, using a test aptdaemon instance on a local session bus. - debian/control: Add python-aptdaemon.pkcompat dependency. Also specify packagekit as an alternative, but conflict to packagekit-backend-aptcc for now, as this does not support the MODALIAS what-provides query, nor plugins. This means that you cannot currently install this package together with packagekit as long as the latter hard-depends on the aptcc backend. Also add aptdaemon/dbus build dependencies to be able to run the tests during build time. * tests/run: Exit with a nonzero code if there are failures or errors. * debian/rules: Ensure that our egg-info is built before running the tests, and removed again on clean. * debian/copyright: Rewrite using copyright 1.0 format. * Add ubuntu-drivers: Command line tool to list available driver packages for this system and auto-install them. This replaces the functionality of "jockey-text --auto-install". This does not use any D-BUS communication, so is safe to run in chroots. * debian/control: Switch to Architecture: any, we are already building this package anywhere but powerpc. * setup.py: Remove commented code for updating .mo files. This package is not supposed to show user-visible strings, and if we ever get them it should rather use python-distutils-extra. * setup.py: Only build hybrid-detect on x86 machines. * debian/control: Bump Standards-Version to 3.9.3. -- Martin Pitt Thu, 24 May 2012 18:22:53 +0200 nvidia-common (1:0.2.45) quantal; urgency=low * Don't write to /usr/share for hybrid graphics detection, use /var/lib instead (LP: #976779). -- Alberto Milone Tue, 15 May 2012 14:30:07 +0200 nvidia-common (1:0.2.44) precise; urgency=low [ Ricardo Salveti de Araujo ] * Make it possible to use nvidia-common with arm/gles drivers (LP: #977245). -- Alberto Milone Tue, 10 Apr 2012 11:33:06 +0200 nvidia-common (1:0.2.43) precise; urgency=low * Do not apply multiple quirks when facing multiple values for a tag. This was causing nvidia-common to apply quirks that are not specific to the hardware in use. * Make sure never to add quirks without an id. * Improve test 3 and 4 of the test suite: - Add testcase for matching multiple products at the same time. - Make sure to parse config files in the quirks directory. - Change the name of the handlers used in the tests so that they don't conflict with the ones in the quirks files. -- Alberto Milone Fri, 06 Apr 2012 18:22:23 +0200 nvidia-common (1:0.2.42) precise; urgency=low * Fix broken hybrid-gfx upstart job. -- Stéphane Graber Thu, 22 Mar 2012 16:38:16 -0400 nvidia-common (1:0.2.41) precise; urgency=low * Add a test suite and run it at build time with dh_auto_test. * Work correctly when the pipe symbol is used in "Match" tags. This symbol only worked when used in the "Handler" tag. Both test cases are covered in the test suite. -- Alberto Milone Mon, 12 Mar 2012 12:30:52 +0100 nvidia-common (1:0.2.40) precise; urgency=low * Add quirks to get brightness keys to work on Lenovo T420s (LP: #773710) and on Dell Latitude E6530 (LP: #914069) when using NVIDIA's proprietary driver. -- Alberto Milone Thu, 08 Mar 2012 11:30:56 +0100 nvidia-common (1:0.2.39) precise; urgency=low * Re-enable support for Hybrid Graphics now that the driver packages are fixed. -- Alberto Milone Sat, 18 Feb 2012 09:48:35 +0100 nvidia-common (1:0.2.38) precise; urgency=low * Add support for Hybrid graphics, disabled by default for now. -- Alberto Milone Wed, 15 Feb 2012 18:04:29 +0100 nvidia-common (1:0.2.37) precise; urgency=low * Quirks, quirks-handler: - Add module and script to create quirks for graphics drivers. -- Alberto Milone Fri, 03 Feb 2012 13:57:10 +0100 nvidia-common (1:0.2.36) precise; urgency=low * NvidiaDetector/alternatives.py: - Add optional ignore_pattern argument to get_alternative_by_name. This argument allows ignoring a substring in the name. This is required in the case of fglrx and fglrx-updates which share the same master link name (LP: #873058). -- Alberto Milone Wed, 16 Nov 2011 17:04:21 +0100 nvidia-common (1:0.2.35) oneiric; urgency=low * NvidiaDetector/alternatives.py: - Return the correct alternative when dealing with "updates" driver flavours in get_alternative_by_name(). This allows Jockey to correctly detect the alternatives provided by different drivers (LP: #841462). -- Alberto Milone Wed, 07 Sep 2011 10:59:20 +0200 nvidia-common (1:0.2.34) oneiric; urgency=low * debian/nvidia-common.preinst: - Use dpkg-maintscript-helper to remove conffiles. -- Alberto Milone Thu, 25 Aug 2011 12:36:19 +0200 nvidia-common (1:0.2.33) oneiric; urgency=low * debian/nvidia-common.preinst: - Make sure to remove any leftover kernel hooks from nvidia-common. * debian/nvidia-common.postinst: - Disable the debconf interface. -- Alberto Milone Wed, 17 Aug 2011 16:59:06 +0200 nvidia-common (1:0.2.32) oneiric; urgency=low * NvidiaDetector/alternatives.py: - Remove trailing whitespace. * NvidiaDetector/nvidiadetector.py: - Remove trailing whitespace. - Ignore "-updates" flavours and recommend only stable flavours. This fixes a crash in the nvidia detector. * setup.py: - Disable kernel hooks. -- Alberto Milone Fri, 12 Aug 2011 17:33:04 +0200 nvidia-common (1:0.2.31) oneiric; urgency=low * NvidiaDetector/alternatives.py: - Replace __ with _ for private methods. - Make Alternatives a new-style class. - Add MultiArchUtils class so that Jockey can get the names of multi-arch alternatives (LP: #798049). -- Alberto Milone Fri, 24 Jun 2011 18:11:31 +0200 nvidia-common (1:0.2.30+1) oneiric; urgency=low * Add epoch to override the sync. The packages in Debian and Ubuntu have the same name but different code and scope (LP: #792576). -- Alberto Milone Sat, 04 Jun 2011 12:13:27 +0200 nvidia-common (0.2.30) natty; urgency=low * debian/control: - Set the section to "admin" so that vrms doesn't complain about the package even though it contains only free software (LP: #745904). -- Alberto Milone Wed, 06 Apr 2011 17:15:51 +0200 nvidia-common (0.2.29) natty; urgency=low * NvidiaDetector/nvidiadetector.py: - Strip the architecture from the package name. This makes sure we extract the driver flavour correctly (LP: #752101). -- Alberto Milone Wed, 06 Apr 2011 16:23:15 +0200 nvidia-common (0.2.28) natty; urgency=low * debian/control: Add conflicts/replaces to the old -modalias packages, to clean them up. They are causing unwanted and nonworking driver offerings. (LP: #717776) -- Martin Pitt Mon, 07 Mar 2011 18:59:10 +0100 nvidia-common (0.2.27) natty; urgency=low * nvidia-detector: - Initialise NvidiaDetection() with verbose=False. This should avoid problems when dealing with debconf (LP: #698327). -- Alberto Milone Tue, 18 Jan 2011 18:15:44 +0100 nvidia-common (0.2.26) natty; urgency=low * NvidiaDetector/nvidiadetector.py: Fix __get_value_from_name() to only convert the string to an int if we don't have an explicit override. (LP: #692022) * debian/nvidia-common.postinst: When calling nvidia-detector, only consider the last line, to ignore other messages before the "None". (LP: #692096) * debian/control: Add missing ${misc:Depends}. * debian/control, debian/rules, debian/compat: Move to "dh", compat level 7, and build with dh_python2, which greatly simplifies the build system. * debian/control: Set Maintainer to standard "ubuntu developers". * debian/nvidia-common.config: Add missing set -e, thanks lintian. * debian/nvidia-common.postinst: Drop obsolete upgrade handling. * Use "3.0 (quilt)" source package format. * debian/control: Bump Standards-Version to 3.9.1. -- Martin Pitt Sun, 19 Dec 2010 11:29:51 +0100 nvidia-common (0.2.25) natty; urgency=low * NvidiaDetector/nvidiadetector.py: Drop code to read /usr/share/jockey/modaliases, and scan for "Modaliases:" package headers instead. Add dependency to python-apt. * debian/control: Drop Vcs-Bzr:. That branch is ancient, and we should use lp:ubuntu/nvidia-common now anyway. -- Martin Pitt Sat, 18 Dec 2010 20:27:26 +0100 nvidia-common (0.2.24build1) natty; urgency=low * Rebuild with python 2.7 as the python default. -- Matthias Klose Wed, 08 Dec 2010 13:08:06 +0000 nvidia-common (0.2.24) maverick; urgency=low * NvidiaDetector/alternatives.py: - Call "dpkg --configure -a" after using dpkg-trigger so that the cache is regenerated (LP: #548751). -- Alberto Milone Thu, 23 Sep 2010 15:37:27 +0200 nvidia-common (0.2.23) lucid; urgency=low * Drop unnecessary dependency on fglrx-modaliases. It will be pulled in from jockey's recommends (and be removable then). -- Mario Limonciello Fri, 02 Apr 2010 10:34:06 -0500 nvidia-common (0.2.22) lucid; urgency=low * debian/control: - Add dependency on fglrx-modaliases. * debian/nvidia-common.config: - Put back the config script with only one line to source debconf so that the template file is loaded when nvidia-common is triggered by kernel hooks (LP: #533970). Thanks to Colin Watson for the advice. * NvidiaDetector/alternatives.py: - Add the update_gmenu method and call it in set_alternative so that the gnome menu is updated when we switch between drivers (LP: #548751). - Add the resolve_module_alias method so as to retrieve the module name from the alias (relevant to #547066). -- Alberto Milone Mon, 15 Mar 2010 16:44:17 +0100 nvidia-common (0.2.21) lucid; urgency=low * Make sure that /etc/modprobe.d/lrm-video is removed so that it doesn't interfere with nvidia (LP: #467490). * debian/nvidia-common.postinst: - Remove db_stop as suggested by Colin Watson, as it can do more harm than good there. - Move the debconf part into the postinst and get rid of the config script (which was run before nvidia-common was configured, with unpredictable results). Thanks to Colin Watson for the advice. - Don't test the existence of nvidia-detector. * share/obsolete: - Add nvidia-glx-{190|195} so as to take care of packages from PPAs. -- Alberto Milone Wed, 03 Mar 2010 13:13:51 +0100 nvidia-common (0.2.20) lucid; urgency=low * NvidiaDetector/alternatives.py: - Make sure that the PATH environment variable is set so that subprocess knows where to find binaries in /sbin (LP: #518879). -- Alberto Milone Tue, 16 Feb 2010 16:35:35 +0100 nvidia-common (0.2.19) lucid; urgency=low * NvidiaDetector/alternatives.py: - Call ldconfig after setting an alternative. -- Alberto Milone Thu, 04 Feb 2010 15:10:19 -0800 nvidia-common (0.2.18) lucid; urgency=low * NvidiaDetector/alternatives.py: - Set self.__open_drivers_alternative to 'mesa/ld.so.conf' so as to adapt to the fact that the alternative lives in mesa now. - Do not pass arguments to the list_alternatives method. - Use subprocess.check_call instead of .call so as to get the exit status in addition to the return code. -- Alberto Milone Tue, 19 Jan 2010 17:18:45 +0100 nvidia-common (0.2.17) lucid; urgency=low * setup.py: - Add pre-inst hook for the NVIDIA installer as the latter may interact badly with the Ubuntu packages(LP: #317703). * NvidiaDetector/nvidiadetector.py: - Handle driver flavours which have strings (instead of integers in their name). * NvidiaDetector/alternatives.py: - Alternatives class to get the list of alternatives and to get and set the alternative in use. * nvidia-common: - ${LATEST} should have quotation marks (LP: #505855). -- Alberto Milone Mon, 11 Jan 2010 18:13:11 +0100 nvidia-common (0.2.16) lucid; urgency=low * debian/control:: - Depends on nvidia-current-modaliases since 185 is no longer used. -- Mario Limonciello Sun, 10 Jan 2010 14:45:14 -0800 nvidia-common (0.2.15.1) karmic-proposed; urgency=low * debian/postinst: - remove leftover /etc/modprobe.d/lrm-video (LP: #459829) -- Michael Vogt Tue, 27 Oct 2009 17:09:34 +0100 nvidia-common (0.2.15) karmic; urgency=low * debian/control: - Drop dependency on nvidia-180-modaliases. - Add dependency on nvidia-185-modaliases. -- Alberto Milone Wed, 19 Aug 2009 19:25:51 +0200 nvidia-common (0.2.14) karmic; urgency=low * Revert previous change, -185 is still in NEW. -- Steve Kowalik Wed, 12 Aug 2009 15:37:12 +1000 nvidia-common (0.2.13) karmic; urgency=low * debian/control: - Drop dependency on nvidia-180-modaliases. - Add dependency on nvidia-185-modaliases. -- Alberto Milone Sat, 08 Aug 2009 19:23:16 +0200 nvidia-common (0.2.12) karmic; urgency=low * debian/control: - Drop dependency on nvidia-71-modaliases. * NvidiaDetector/nvidiadetector.py: - Use a text file in /usr/share/nvidia-common/ instead of hardcoding the list of obsolete packages in the program. - Add "obsolete" optional argument to the ctor so as to allow to change the default path to the list of obsolete packages. - Catch IOError if the path to the modalias files does not exist. - Flush stdout before printing (LP: #292606). * nvidia-common: - Prevent the script from failing when $LATEST is null. * setup.py: - Install share/obsolete to /usr/share/nvidia-common. * share/obsolete: - Add nvidia-glx-71. -- Alberto Milone Fri, 24 Jul 2009 17:03:18 +0200 nvidia-common (0.2.11) jaunty; urgency=low * do not sys.exit(0) in NvidiaDetection.__init__() but raise a exception instead (this code is imported by update-manager and the exit(0) exits it) -- Michael Vogt Mon, 20 Apr 2009 10:50:40 +0200 nvidia-common (0.2.10) jaunty; urgency=low * NvidiaDetector/nvidiadetector.py: - Exit without an error exit status in NvidiaDetection.__init__() so as not to break dist-upgrades if the modaliases are not installed (LP: #303825). * debian/rules: - Add "--install-layout=deb" to make sure that nvidia-detector is installed in /usr/bin/ instead of /usr/local/bin. -- Alberto Milone Tue, 14 Apr 2009 15:54:28 +0200 nvidia-common (0.2.9) jaunty; urgency=low * Include the symlinks in the package. -- Matthias Klose Tue, 24 Feb 2009 22:41:02 +0100 nvidia-common (0.2.8) jaunty; urgency=low * debian/rules: add "export DH_PYCENTRAL=nomove" to avoid problems with dist-upgrades. -- Alberto Milone (tseliot) Thu, 19 Feb 2009 14:39:36 +0100 nvidia-common (0.2.7) jaunty; urgency=low * NvidiaDetector/nvidiadetector.py: - add nvidia-glx-177 to the "oldPackages" list since 177 is no longer available in Jaunty. - make sure that drivers which have the modaliases and are in oldPackages are ignored. -- Alberto Milone (tseliot) Wed, 04 Feb 2009 12:09:26 +0100 nvidia-common (0.2.6) jaunty; urgency=low * debian/control: - Drop dependency on nvidia-177-modaliases since it's not compatible with Jaunty's X ABI. - Add Vcs-Bzr -- Alberto Milone (tseliot) Fri, 30 Jan 2009 18:14:19 +0100 nvidia-common (0.2.5) jaunty; urgency=low * debian/control: - Now that the 180 series of drivers is stable, depend on the 180 modaliases. -- Mario Limonciello Thu, 08 Jan 2009 15:18:19 -0600 nvidia-common (0.2.4) intrepid; urgency=low * Do not raise an exception if self.drivers is empty (LP: #272196) -- Alberto Milone (tseliot) Mon, 06 Oct 2008 14:51:17 +0200 nvidia-common (0.2.3) intrepid; urgency=low * Move the hard work in debian/rules to binary-arch now that we're architecture-dependent. -- Colin Watson Wed, 27 Aug 2008 15:37:20 +0100 nvidia-common (0.2.2) intrepid; urgency=low * Set Architecture to i386 amd64 in debian/control * Move Build-Depends-Indep to Build-Depends in debian/control -- Alberto Milone (tseliot) Wed, 27 Aug 2008 15:14:18 +0200 nvidia-common (0.2.1) intrepid; urgency=low * add missing depends on pciutils -- Michael Vogt Fri, 25 Jul 2008 11:12:47 +0200 nvidia-common (0.2) intrepid; urgency=low * Native version -- Alberto Milone (tseliot) Tue, 22 Jul 2008 12:21:25 +0200 nvidia-common (0.1-0ubuntu12) intrepid; urgency=low * Bump for PPA -- Alberto Milone (tseliot) Tue, 15 Jul 2008 15:11:51 +0200 nvidia-common (0.1-0ubuntu11) intrepid; urgency=low * Change the regex pattern so as to make use of the new pattern in the modalias files -- Alberto Milone (tseliot) Tue, 15 Jul 2008 11:48:03 +0200 nvidia-common (0.1-0ubuntu10) intrepid; urgency=low * Drop CDBS in favour of python-central due to a bug in CDBS * Check the existence of /usr/share/jockey/modaliases * See if the modaliases files contain something useful -- Alberto Milone (tseliot) Mon, 14 Jul 2008 17:47:35 +0200 nvidia-common (0.1-0ubuntu9) intrepid; urgency=low * Switch to python-support * nvdia-common and the config file should point to the executable file in /usr/bin -- Alberto Milone (tseliot) Sun, 13 Jul 2008 13:54:20 +0200 nvidia-common (0.1-0ubuntu8) intrepid; urgency=low * Add dependency on the nvidia-VER-modaliases packages -- Alberto Milone (tseliot) Sun, 13 Jul 2008 12:29:53 +0200 nvidia-common (0.1-0ubuntu7) intrepid; urgency=low * Remove makefile -- Alberto Milone (tseliot) Sat, 12 Jul 2008 16:35:06 +0200 nvidia-common (0.1-0ubuntu6) intrepid; urgency=low * Correct DOMAIN in makefile -- Alberto Milone (tseliot) Sat, 12 Jul 2008 15:42:05 +0200 nvidia-common (0.1-0ubuntu5) intrepid; urgency=low * Add build dependency on python2.4 -- Alberto Milone (tseliot) Sat, 12 Jul 2008 15:18:05 +0200 nvidia-common (0.1-0ubuntu4) intrepid; urgency=low * Add missing build dependency on the Python versions -- Alberto Milone (tseliot) Sat, 12 Jul 2008 13:46:14 +0200 nvidia-common (0.1-0ubuntu3) intrepid; urgency=low * Put nvidia-common also in /etc/kernel/postinst.d/ so that it's triggered when a new kernel is installed too. -- Alberto Milone (tseliot) Sat, 12 Jul 2008 13:21:08 +0200 nvidia-common (0.1-0ubuntu2) hardy; urgency=low * Switch to CDBS * Make it possible for nvidiadetector to be imported by other Python applications such as Update-Manager -- Alberto Milone (tseliot) Sat, 12 Jul 2008 12:48:15 +0200 nvidia-common (0.1-0ubuntu1) intrepid; urgency=low * First release. -- Alberto Milone (tseliot) Thu, 10 Jul 2008 15:13:50 +0200 ubuntu-drivers-common-0.2.91.4/debhelper/0000775000000000000000000000000012322472605015056 5ustar ubuntu-drivers-common-0.2.91.4/debhelper/test_dh_modaliases0000775000000000000000000000354212322472605020643 0ustar #!/bin/sh # test dh_modaliases set -e fail() { /bin/echo -e "$1" exit 1 } dh=$(dirname `readlink -f $0`)/dh_modaliases module=`modinfo snd_hda_intel | grep ^filename: | awk '{print $2}'` # build sandbox D=`mktemp -d` trap "rm -r $D" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM cd $D # create test package mkdir -p src/debian cd src cat < debian/control Source: foo Build-Depends: debhelper (>= 7) Maintainer: Joe Tester Package: foo Architecture: any Description: test Depends: \${shlibs:Depends} XB-Modaliases: \${modaliases} EOF cat < debian/rules #!/usr/bin/make -f %: dh \$@ override_dh_install: dh_install install -m 644 -D $module debian/foo/lib/modules/extra/`basename $module` $dh -v EOF cat < debian/changelog foo (1) test; urgency=low * Test -- Joe Tester Thu, 18 Nov 2010 16:15:29 +0100 EOF echo 7 > debian/compat # build it and check the generated headers from the .ko dpkg-buildpackage -us -uc header=`dpkg -I ../foo_1_*.deb` echo "$header" | grep -q '^[[:space:]]*Package: foo$' || fail "No proper Package: header in\n$header" echo "$header" | grep -q '^[[:space:]]*Modaliases: snd_hda_intel(pci:v00001022d\*sv\*sd\*bc04sc03i00\*, pci:.*i\*.*)$' || fail "No proper modalises in\n$header" # now add a manual modalias file cat < debian/foo.modaliases alias ssb:v1234id0000 `basename $module .ko` alias pci:DEADBEEF `basename $module .ko` ignorethispackagename alias pci:98765 testmod EOF # build it and check the generated headers from the .ko dpkg-buildpackage -us -uc header=`dpkg -I ../foo_1_*.deb` echo "$header" | grep -q '^[[:space:]]*Package: foo$' || fail "No proper Package: header in\n$header" echo "$header" | grep -q "^[[:space:]]*Modaliases: `basename $module .ko`(ssb:v1234id0000, pci:DEADBEEF), testmod(pci:98765)$" || fail "No proper modalises in\n$header" echo "PASSED" ubuntu-drivers-common-0.2.91.4/debhelper/modaliases.pm0000664000000000000000000000025112322472605017533 0ustar #!/usr/bin/perl # debhelper sequence file for dh_modaliases use warnings; use strict; use Debian::Debhelper::Dh_Lib; insert_after("dh_install", "dh_modaliases"); 1; ubuntu-drivers-common-0.2.91.4/debhelper/dh_modaliases0000775000000000000000000000703212322472605017602 0ustar #!/usr/bin/perl -w =head1 NAME dh_modaliases - scan kmod modaliases and provide a substvar for them =cut use strict; use File::Find; use Debian::Debhelper::Dh_Lib; =head1 SYNOPSIS B [S>] =head1 DESCRIPTION B is useful for packages that ship third-party kernel modules, either in binary form, or as sources (with e. g. DKMS). It extracts the modules' modaliases from either the compile .ko files themselves (for packages which ship them in compiled form, using B), or from a package file BIB<.modaliases> (see below). I creates a package substitution variable C<${modaliases}> which you should add to C as =over 4 XB-Modaliases: ${modaliases} =back This enables software which is looking for missing driver packages (such as Jockey or the operating system installer) to identify which package(s) will provide a driver for a piece of hardware, identified by its modalias. =head1 PACKAGE MODALIAS FILES If a package ships source code (using DKMS, module-assistant, etc.) instead of compiled binary kernel modules, then B can't figure out the modaliases by scanning the *.ko files, and you have to provide the modalias list manually as a package file BIB<.modaliases>. The format matches the /lib/modules/`uname -r`/modules.alias file from the Linux kernel. Examples: =over 4 alias ssb:v1234id5678 snd_super_booster alias pci:v000010DEd0000004Esv*sd*bc03sc*i* nvidia_current =back You can generate such a list if you locally build and install this module, and then run =over 4 modinfo mymodname | perl -nae 'print "alias $1 mymodname\n" if /^alias:\s+(.*)$/' =back (replacing "mymodname" with the actual module name). =head1 OPTIONS The standard debhelper options are supported. =cut init(); my $aliases; sub modalises_from_ko { my $name = $_; return unless /\.ko$/; return if -l $_ or -d $_; # Skip directories and symlinks # See if we were asked to exclude this file. foreach my $f (@{$dh{EXCLUDE}}) { return if ($File::Find::name =~ m/\Q$f\E/); } my ($modname) = ($name =~ /^(.*)\.ko$/); $modname =~ s/-/_/g; # canonical names are with underscores my @a; open M, '-|', 'modinfo', $name or die "open: $!"; while () { if (/^alias:\s*(.*)$/) { verbose_print("$File::Find::name: module $modname has alias $1"); push @a, $1; } } if ($aliases) { $aliases .= ', '; } $aliases .= $modname . '(' . (join ', ', @a) . ')'; } sub modalises_from_pkgfile { my %module_alias_map = (); open F, $_[0]; while () { next if /^#/; if (/^alias\s*([^[:space:]]+)\s*([^[:space:]]+)/) { verbose_print("package file $_[0]: module $2 has alias $1"); push @{$module_alias_map{$2}}, $1; } else { warning("$_[0]: cannot translate line into modalias: $_"); } } foreach my $m (sort keys %module_alias_map) { if ($aliases) { $aliases .= ', '; } $aliases .= $m . '(' . (join ', ', @{$module_alias_map{$m}}) . ')'; } } foreach my $package (@{$dh{DOPACKAGES}}) { my $tmp = tmpdir($package); delsubstvar($package, 'modaliases'); $aliases = ''; my $manual_list = pkgfile($package, 'modaliases'); if ($manual_list) { modalises_from_pkgfile $manual_list; } else { find(\&modalises_from_ko, tmpdir($package)); } addsubstvar($package, 'modaliases', $aliases); } =head1 SEE ALSO L, L This program is an extension to debhelper. =head1 AUTHOR Martin Pitt =cut ubuntu-drivers-common-0.2.91.4/UbuntuDrivers/0000775000000000000000000000000012322472605015745 5ustar ubuntu-drivers-common-0.2.91.4/UbuntuDrivers/kerneldetection.py0000664000000000000000000001112412322472605021475 0ustar # # kerneldetection.py # # Copyright 2013 Canonical Ltd. # # Author: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import apt import logging import re from subprocess import Popen class KernelDetection(object): def __init__(self, cache=None): if cache: self.apt_cache = cache else: self.apt_cache = apt.Cache() def _is_greater_than(self, term1, term2): # We don't want to take into account # the flavour pattern = re.compile('(.+)-([0-9]+)-(.+)') match1 = pattern.match(term1) match2 = pattern.match(term2) if match1: term1 = '%s-%s' % (match1.group(1), match1.group(2)) term2 = '%s-%s' % (match2.group(1), match2.group(2)) logging.debug('Comparing %s with %s' % (term1, term2)) command = 'dpkg --compare-versions %s gt %s' % \ (term1, term2) process = Popen(command.split(' ')) process.communicate() return not process.returncode def _get_linux_metapackage(self, headers): '''Get the linux headers or linux metapackage''' suffix = headers and '-headers' or '' pattern = re.compile('linux-image-(.+)-([0-9]+)-(.+)') source_pattern = re.compile('linux-(.+)') metapackage = '' version = '' for pkg in self.apt_cache: if ('linux-image' in pkg.name and 'extra' not in pkg.name and self.apt_cache[pkg.name].is_installed or self.apt_cache[pkg.name].marked_install): match = pattern.match(pkg.name) # Here we filter out packages such as # linux-generic-lts-quantal if match: source = self.apt_cache[pkg.name].candidate.\ record['Source'] current_version = '%s-%s' % (match.group(1), match.group(2)) # See if the current version is greater than # the greatest that we've found so far if self._is_greater_than(current_version, version): version = current_version match_source = source_pattern.match(source) # Set the linux-headers metapackage if '-lts-' in source and match_source: # This is the case of packages such as # linux-image-3.5.0-18-generic which # comes from linux-lts-quantal. # Therefore the linux-headers-generic # metapackage would be wrong here and # we should use # linux-headers-generic-lts-quantal # instead metapackage = 'linux%s-%s-%s' % ( suffix, match.group(3), match_source.group(1)) else: # The scheme linux-headers-$flavour works # well here metapackage = 'linux%s-%s' % ( suffix, match.group(3)) return metapackage def get_linux_headers_metapackage(self): '''Get the linux headers for the newest_kernel installed''' return self._get_linux_metapackage(True) def get_linux_metapackage(self): '''Get the linux metapackage for the newest_kernel installed''' return self._get_linux_metapackage(False) ubuntu-drivers-common-0.2.91.4/UbuntuDrivers/detect.py0000664000000000000000000005136312322472605017577 0ustar '''Hardware and driver package detection functionality for Ubuntu systems.''' # (C) 2012 Canonical Ltd. # Author: Martin Pitt # # This program 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 2 of the License, or # (at your option) any later version. import os import logging import fnmatch import subprocess import functools import apt from UbuntuDrivers import kerneldetection system_architecture = apt.apt_pkg.get_architectures()[0] def system_modaliases(): '''Get modaliases present in the system. This ignores devices whose drivers are statically built into the kernel, as you cannot replace them with other driver packages anyway. Return a modalias → sysfs path map. The keys of the returned map are suitable for a PackageKit WhatProvides(MODALIAS) call. ''' aliases = {} for path, dirs, files in os.walk('/sys/devices'): modalias = None # most devices have modalias files if 'modalias' in files: try: with open(os.path.join(path, 'modalias')) as f: modalias = f.read().strip() except IOError as e: logging.debug('system_modaliases(): Cannot read %s/modalias: %s', path, e) continue # devices on SSB bus only mention the modalias in the uevent file (as # of 2.6.24) elif 'ssb' in path and 'uevent' in files: info = {} with open(os.path.join(path, 'uevent')) as f: for l in f: if l.startswith('MODALIAS='): modalias = l.split('=', 1)[1].strip() break if not modalias: continue # ignore drivers which are statically built into the kernel driverlink = os.path.join(path, 'driver') modlink = os.path.join(driverlink, 'module') if os.path.islink(driverlink) and not os.path.islink(modlink): #logging.debug('system_modaliases(): ignoring device %s which has no module (built into kernel)', path) continue aliases[modalias] = path return aliases def _check_video_abi_compat(apt_cache, record): xorg_video_abi = None # determine current X.org video driver ABI try: for p in apt_cache['xserver-xorg-core'].candidate.provides: if p.startswith('xorg-video-abi-'): xorg_video_abi = p #logging.debug('_check_video_abi_compat(): Current X.org video abi: %s', xorg_video_abi) break except (AttributeError, KeyError): logging.debug('_check_video_abi_compat(): xserver-xorg-core not available, cannot check ABI') return True if not xorg_video_abi: return False try: deps = record['Depends'] except KeyError: return True if 'xorg-video-abi-' in deps and xorg_video_abi not in deps: logging.debug('Driver package %s is incompatible with current X.org server ABI %s', record['Package'], xorg_video_abi) return False return True def _apt_cache_modalias_map(apt_cache): '''Build a modalias map from an apt.Cache object. This filters out uninstallable video drivers (i. e. which depend on a video ABI that xserver-xorg-core does not provide). Return a map bus -> modalias -> [package, ...], where "bus" is the prefix of the modalias up to the first ':' (e. g. "pci" or "usb"). ''' result = {} for package in apt_cache: # skip foreign architectures, we usually only want native # driver packages if (not package.candidate or package.candidate.architecture not in ('all', system_architecture)): continue # skip packages without a modalias field try: m = package.candidate.record['Modaliases'] except (KeyError, AttributeError, UnicodeDecodeError): continue # skip incompatible video drivers if not _check_video_abi_compat(apt_cache, package.candidate.record): continue try: for part in m.split(')'): part = part.strip(', ') if not part: continue module, lst = part.split('(') for alias in lst.split(','): alias = alias.strip() bus = alias.split(':', 1)[0] result.setdefault(bus, {}).setdefault(alias, set()).add(package.name) except ValueError: logging.error('Package %s has invalid modalias header: %s' % ( package.name, m)) return result def packages_for_modalias(apt_cache, modalias): '''Search packages which match the given modalias. Return a list of apt.Package objects. ''' pkgs = set() apt_cache_hash = hash(apt_cache) try: cache_map = packages_for_modalias.cache_maps[apt_cache_hash] except KeyError: cache_map = _apt_cache_modalias_map(apt_cache) packages_for_modalias.cache_maps[apt_cache_hash] = cache_map bus_map = cache_map.get(modalias.split(':', 1)[0], {}) for alias in bus_map: if fnmatch.fnmatch(modalias, alias): for p in bus_map[alias]: pkgs.add(p) return [apt_cache[p] for p in pkgs] packages_for_modalias.cache_maps = {} def _is_package_free(pkg): assert pkg.candidate is not None # it would be better to check the actual license, as we do not have # the component for third-party packages; but this is the best we can do # at the moment if pkg.candidate.section.startswith('restricted') or \ pkg.candidate.section.startswith('multiverse'): return False return True def _is_package_from_distro(pkg): if pkg.candidate is None: return False for o in pkg.candidate.origins: if o.origin == 'Ubuntu': return True return False def _pkg_get_module(pkg): '''Determine module name from apt Package object''' try: m = pkg.candidate.record['Modaliases'] except (KeyError, AttributeError): logging.debug('_pkg_get_module %s: package has no Modaliases header, cannot determine module', pkg.name) return None paren = m.find('(') if paren <= 0: logging.warning('_pkg_get_module %s: package has invalid Modaliases header, cannot determine module', pkg.name) return None module = m[:paren] return module def _is_manual_install(pkg): '''Determine if the kernel module from an apt.Package is manually installed.''' if pkg.installed: return False # special case, as our packages suffix the kmod with _version if pkg.name.startswith('nvidia'): module = 'nvidia' elif pkg.name.startswith('fglrx'): module = 'fglrx' else: module = _pkg_get_module(pkg) if not module: return False modinfo = subprocess.Popen(['modinfo', module], stdout=subprocess.PIPE, stderr=subprocess.PIPE) modinfo.communicate() if modinfo.returncode == 0: logging.debug('_is_manual_install %s: builds module %s which is available, manual install', pkg.name, module) return True logging.debug('_is_manual_install %s: builds module %s which is not available, no manual install', pkg.name, module) return False def _get_db_name(syspath, alias): '''Return (vendor, model) names for given device. Values are None if unknown. ''' try: out = subprocess.check_output(['udevadm', 'hwdb', '--test=' + alias], universal_newlines=True) except (OSError, subprocess.CalledProcessError) as e: logging.debug('_get_db_name(%s, %s): udevadm hwdb failed: %s', syspath, alias, str(e)) return (None, None) logging.debug('_get_db_name: output\n%s\n', out) vendor = None model = None for line in out.splitlines(): (k, v) = line.split('=', 1) if '_VENDOR' in k: vendor = v if '_MODEL' in k: model = v logging.debug('_get_db_name(%s, %s): vendor "%s", model "%s"', syspath, alias, vendor, model) return (vendor, model) def system_driver_packages(apt_cache=None): '''Get driver packages that are available for the system. This calls system_modaliases() to determine the system's hardware and then queries apt about which packages provide drivers for those. It also adds available packages from detect_plugin_packages(). If you already have an apt.Cache() object, you should pass it as an argument for efficiency. If not given, this function creates a temporary one by itself. Return a dictionary which maps package names to information about them: driver_package → {'modalias': 'pci:...', ...} Available information keys are: 'modalias': Modalias for the device that needs this driver (not for drivers from detect plugins) 'syspath': sysfs directory for the device that needs this driver (not for drivers from detect plugins) 'plugin': Name of plugin that detected this package (only for drivers from detect plugins) 'free': Boolean flag whether driver is free, i. e. in the "main" or "universe" component. 'from_distro': Boolean flag whether the driver is shipped by the distro; if not, it comes from a (potentially less tested/trusted) third party source. 'vendor': Human readable vendor name, if available. 'model': Human readable product name, if available. 'recommended': Some drivers (nvidia, fglrx) come in multiple variants and versions; these have this flag, where exactly one has recommended == True, and all others False. ''' modaliases = system_modaliases() if not apt_cache: apt_cache = apt.Cache() packages = {} for alias, syspath in modaliases.items(): for p in packages_for_modalias(apt_cache, alias): packages[p.name] = { 'modalias': alias, 'syspath': syspath, 'free': _is_package_free(p), 'from_distro': _is_package_from_distro(p), } (vendor, model) = _get_db_name(syspath, alias) if vendor is not None: packages[p.name]['vendor'] = vendor if model is not None: packages[p.name]['model'] = model # Add "recommended" flags for NVidia alternatives nvidia_packages = [p for p in packages if p.startswith('nvidia-')] if nvidia_packages: nvidia_packages.sort(key=functools.cmp_to_key(_cmp_gfx_alternatives)) recommended = nvidia_packages[-1] for p in nvidia_packages: packages[p]['recommended'] = (p == recommended) # Add "recommended" flags for fglrx alternatives fglrx_packages = [p for p in packages if p.startswith('fglrx-')] if fglrx_packages: fglrx_packages.sort(key=functools.cmp_to_key(_cmp_gfx_alternatives)) recommended = fglrx_packages[-1] for p in fglrx_packages: packages[p]['recommended'] = (p == recommended) # add available packages which need custom detection code for plugin, pkgs in detect_plugin_packages(apt_cache).items(): for p in pkgs: apt_p = apt_cache[p] packages[p] = { 'free': _is_package_free(apt_p), 'from_distro': _is_package_from_distro(apt_p), 'plugin': plugin, } return packages def system_device_drivers(apt_cache=None): '''Get by-device driver packages that are available for the system. This calls system_modaliases() to determine the system's hardware and then queries apt about which packages provide drivers for each of those. It also adds available packages from detect_plugin_packages(), using the name of the detction plugin as device name. If you already have an apt.Cache() object, you should pass it as an argument for efficiency. If not given, this function creates a temporary one by itself. Return a dictionary which maps devices to available drivers: device_name → {'modalias': 'pci:...', , 'drivers': {'pkgname': {}} A key (device name) is either the sysfs path (for drivers detected through modaliases) or the detect plugin name (without the full path). Available keys in : 'modalias': Modalias for the device that needs this driver (not for drivers from detect plugins) 'vendor': Human readable vendor name, if available. 'model': Human readable product name, if available. 'drivers': Driver package map for this device, see below. Installing any of the drivers in that map will make this particular device work. The keys are the package names of the driver packages; note that this can be an already installed default package such as xserver-xorg-video-nouveau which provides a free alternative to the proprietary NVidia driver; these will have the 'builtin' flag set. 'manual_install': None of the driver packages are installed, but the kernel module that it provides is available; this usually means that the user manually installed the driver from upstream. Aavailable keys in : 'builtin': The package is shipped by default in Ubuntu and MUST NOT be uninstalled. This usually applies to free drivers like xserver-xorg-video-nouveau. 'free': Boolean flag whether driver is free, i. e. in the "main" or "universe" component. 'from_distro': Boolean flag whether the driver is shipped by the distro; if not, it comes from a (potentially less tested/trusted) third party source. 'recommended': Some drivers (nvidia, fglrx) come in multiple variants and versions; these have this flag, where exactly one has recommended == True, and all others False. ''' result = {} if not apt_cache: apt_cache = apt.Cache() # copy the system_driver_packages() structure into the by-device structure for pkg, pkginfo in system_driver_packages(apt_cache).items(): if 'syspath' in pkginfo: device_name = pkginfo['syspath'] else: device_name = pkginfo['plugin'] result.setdefault(device_name, {}) for opt_key in ('modalias', 'vendor', 'model'): if opt_key in pkginfo: result[device_name][opt_key] = pkginfo[opt_key] drivers = result[device_name].setdefault('drivers', {}) drivers[pkg] = {'free': pkginfo['free'], 'from_distro': pkginfo['from_distro']} if 'recommended' in pkginfo: drivers[pkg]['recommended'] = pkginfo['recommended'] # now determine the manual_install device flag: this is true iff all driver # packages are "manually installed" for driver, info in result.items(): for pkg in info['drivers']: if not _is_manual_install(apt_cache[pkg]): break else: info['manual_install'] = True # add OS builtin free alternatives to proprietary drivers _add_builtins(result) return result def auto_install_filter(packages): '''Get packages which are appropriate for automatic installation. Return the subset of the given list of packages which are appropriate for automatic installation by the installer. This applies to e. g. the Broadcom Wifi driver (as there is no alternative), but not to the FGLRX proprietary graphics driver (as the free driver works well and FGLRX does not provide KMS). ''' # any package which matches any of those globs will be accepted whitelist = ['bcmwl*', 'pvr-omap*', 'virtualbox-guest*', 'nvidia-*'] allow = [] for pattern in whitelist: allow.extend(fnmatch.filter(packages, pattern)) result = {} for p in allow: if 'recommended' not in packages[p] or packages[p]['recommended']: result[p] = packages[p] return result def detect_plugin_packages(apt_cache=None): '''Get driver packages from custom detection plugins. Some driver packages cannot be identified by modaliases, but need some custom code for determining whether they apply to the system. Read all *.py files in /usr/share/ubuntu-drivers-common/detect/ or $UBUNTU_DRIVERS_DETECT_DIR and call detect(apt_cache) on them. Filter the returned lists for packages which are available for installation, and return the joined results. If you already have an existing apt.Cache() object, you can pass it as an argument for efficiency. Return pluginname -> [package, ...] map. ''' packages = {} plugindir = os.environ.get('UBUNTU_DRIVERS_DETECT_DIR', '/usr/share/ubuntu-drivers-common/detect/') if not os.path.isdir(plugindir): logging.debug('Custom detection plugin directory %s does not exist', plugindir) return packages if apt_cache is None: apt_cache = apt.Cache() for fname in os.listdir(plugindir): if not fname.endswith('.py'): continue plugin = os.path.join(plugindir, fname) logging.debug('Loading custom detection plugin %s', plugin) symb = {} with open(plugin) as f: try: exec(compile(f.read(), plugin, 'exec'), symb) result = symb['detect'](apt_cache) logging.debug('plugin %s return value: %s', plugin, result) except Exception as e: logging.exception('plugin %s failed:', plugin) continue if result is None: continue if type(result) not in (list, set): logging.error('plugin %s returned a bad type %s (must be list or set)', plugin, type(result)) continue for pkg in result: if pkg in apt_cache and apt_cache[pkg].candidate: if _check_video_abi_compat(apt_cache, apt_cache[pkg].candidate.record): packages.setdefault(fname, []).append(pkg) else: logging.debug('Ignoring unavailable package %s from plugin %s', pkg, plugin) return packages def _cmp_gfx_alternatives(x, y): '''Compare two graphics driver names in terms of preference. -updates always sort after non-updates, as we prefer the stable driver and only want to offer -updates when the one from release does not support the card. We never want to recommend -experimental unless it's the only one available, so sort this last. ''' if x.endswith('-updates') and not y.endswith('-updates'): return -1 if not x.endswith('-updates') and y.endswith('-updates'): return 1 if 'experiment' in x and 'experiment' not in y: return -1 if 'experiment' not in x and 'experiment' in y: return 1 if x < y: return -1 if x > y: return 1 assert x == y return 0 def _add_builtins(drivers): '''Add builtin driver alternatives''' for device, info in drivers.items(): for pkg in info['drivers']: # Nouveau is still not good enough, keep recommending the # proprietary driver if pkg.startswith('nvidia'): info['drivers']['xserver-xorg-video-nouveau'] = { 'free': True, 'builtin': True, 'from_distro': True, 'recommended': False} break # These days the free driver is working well enough, so recommend # it if pkg.startswith('fglrx'): for d in info['drivers']: info['drivers'][d]['recommended'] = False info['drivers']['xserver-xorg-video-ati'] = { 'free': True, 'builtin': True, 'from_distro': True, 'recommended': True} break def get_linux_headers(apt_cache): '''Return the linux headers for the system's kernel''' kernel_detection = kerneldetection.KernelDetection(apt_cache) return kernel_detection.get_linux_headers_metapackage() def get_linux(apt_cache): '''Return the linux metapackage for the system's kernel''' kernel_detection = kerneldetection.KernelDetection(apt_cache) return kernel_detection.get_linux_metapackage() ubuntu-drivers-common-0.2.91.4/UbuntuDrivers/__init__.py0000664000000000000000000000000012322472605020044 0ustar ubuntu-drivers-common-0.2.91.4/UbuntuDrivers/PackageKit.py0000664000000000000000000000530012322472605020320 0ustar '''PackageKit WhatProvides() plugin for type MODALIAS and HARDWARE_DRIVER With this you can ask PackageKit about "which package do I need to install to provide a driver for the device pci:v00001234...?" (MODALIAS), or "which driver packages apply to the current system?" (HARDWARE_DRIVER), for example: $ pkcon what-provides "pci:v000010DEd000007E3sv00sd00bc03sc00i00" Available nvidia-current-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library Available nvidia-current-updates-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library $ pkcon what-provides "drivers_for_attached_hardware" Available open-vm-dkms-2011.12.20-562307-0ubuntu1.all Source for VMware guest systems driver (DKMS) ''' # Note that this does not work with PackageKit's "aptcc" backend as that does # not support plugins. You need to use PackageKit's "apt" backend or # python-aptdaemon.pkcompat on Debian/Ubuntu (preferred). # # (C) 2012 Canonical Ltd. # Author: Martin Pitt # # This program 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 2 of the License, or # (at your option) any later version. import re try: from packagekit import enums except ImportError: # try the one from aptdaemon import aptdaemon.pkenums as enums from gi.repository import PackageKitGlib import UbuntuDrivers.detect valid_modalias_re = re.compile('^[a-z0-9]+:') def what_provides(apt_cache, provides_type, search): '''WhatProvides plugin for type MODALIAS and HARDWARE_DRIVER MODALIAS: Get driver packages which match the given modalias in the search. HARDWARE_DRIVER: Get driver packages that are available for the system. The only allowed search query for this is "drivers_for_attached_hardware". ''' if provides_type not in (enums.PROVIDES_MODALIAS, enums.PROVIDES_HARDWARE_DRIVER, enums.PROVIDES_ANY): raise NotImplementedError('cannot handle type ' + str(provides_type)) # MODALIAS if provides_type in (enums.PROVIDES_MODALIAS, enums.PROVIDES_ANY) and \ valid_modalias_re.match(search): return UbuntuDrivers.detect.packages_for_modalias(apt_cache, search) # HARDWARE_DRIVER if provides_type in (enums.PROVIDES_HARDWARE_DRIVER, enums.PROVIDES_ANY) and \ search == 'drivers_for_attached_hardware': pkgs = UbuntuDrivers.detect.system_driver_packages(apt_cache) return [apt_cache[p] for p in pkgs] if provides_type == enums.PROVIDES_ANY: return [] else: raise ValueError('The search term is invalid: %s' % search) ubuntu-drivers-common-0.2.91.4/README0000664000000000000000000001322212322472605014004 0ustar ubuntu-drivers-common ===================== This package aggregates and abstracts Ubuntu specific logic and knowledge about third-party driver packages, and provides APIs for installers and driver configuration GUIs. It also contains some NVidia specific support code to find the most appropriate driver version (as we usually ship several), as well as setting up the alternatives symlinks that the proprietary NVidia and FGLRX packages use. Command line interface ---------------------- The simplest frontend is the "ubuntu-drivers" command line tool. You can use it to show the available driver packages which apply to the current system (ubuntu-drivers list), or to install all drivers which are appropriate for automatic installation (sudo ubuntu-drivers autoinstall), which is mostly useful for integration into installers. Please see "ubuntu-drivers --help" for details. Python API ---------- The UbuntuDrivers.detect Python module provides some functions to detect the system's hardware, matching driver packages, and packages which are eligible for automatic installation. The three main functions are: "Which driver packages apply to this system?" packages = UbuntuDrivers.detect.system_driver_packages() "Which devices need drivers, and which packages do they need?" driver_info = UbuntuDrivers.detect.system_device_drivers() "Which driver package(s) applies to this piece of hardware?" import apt apt_cache = apt.Cache apt_packages = UbuntuDrivers.detect.packages_for_modalias(apt_cache, modalias) These functions only use python-apt. They do not need any other dependencies, root privileges, D-BUS calls, etc. PackageKit API -------------- If you want to integrate driver lookups in software which should not be distribution specific, or is not written in Python, you should use the PackageKit API instead of the UbuntuDrivers.detect Python module. In particular, ubuntu-drivers-common ships PackageKit plugins for the "WhatProvides" PackageKit query for the types "MODALIAS" (corresponding to UbuntuDrivers.detect.packages_for_modalias()), and "HARDWARE_DRIVER" (corresponding to UbuntuDrivers.detect.system_driver_packages()). This also works with aptdaemon's PackageKit compatibility layer (python-aptdaemon.pkcompat), which is the preferred PackageKit API implementation in Ubuntu. Please see http://www.packagekit.org/gtk-doc/PackageKit-pk-client-sync.html#pk-client-what-provides about the WhatProvides() API, and https://gitorious.org/packagekit/packagekit/blobs/master/docs/provides-component-naming.txt for details about the various WhatProvides types. Examples: From Python: >>> from gi.repository import PackageKitGlib >>> pk = PackageKitGlib.Client() >>> res = pk.what_provides(PackageKitGlib.FilterEnum.NONE, PackageKitGlib.ProvidesEnum.MODALIAS, ["pci:v000010DEd000007E3sv00sd00bc03sc00i00"], None, lambda p, t, d: True, None) >>> res.get_exit_code() >>> for p in res.get_package_array(): print p.get_id() nvidia-current;295.53-0ubuntu1;amd64;Ubuntu nvidia-current-updates;295.53-0ubuntu1;amd64;Ubuntu >>> res = pk.what_provides(PackageKitGlib.FilterEnum.NONE, PackageKitGlib.ProvidesEnum.HARDWARE_DRIVER, ["drivers_for_attached_hardware"], None, lambda p, t, d: True, None) >>> res.get_exit_code() >>> for p in res.get_package_array(): print p.get_id() open-vm-dkms;2011.12.20-562307-0ubuntu1;all;Ubuntu Using the pkcon command line tool: $ pkcon what-provides "pci:v000010DEd000007E3sv00sd00bc03sc00i00" Available nvidia-current-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library Available nvidia-current-updates-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library $ pkcon what-provides "drivers_for_attached_hardware" Available open-vm-dkms-2011.12.20-562307-0ubuntu1.all Source for VMware guest systems driver (DKMS) Detection logic --------------- The principal method of mapping hardware to driver packages is to use modalias patterns. Hardware devices export a "modalias" sysfs attribute, for example $ cat /sys/devices/pci0000:00/0000:00:1b.0/modalias pci:v00008086d00003B56sv000017AAsd0000215Ebc04sc03i00 Kernel modules declare which hardware they can handle with modalias patterns (globs), e. g.: $ modinfo snd_hda_intel [...] alias: pci:v00008086d*sv*sd*bc04sc03i00* Driver packages which are not installed by default (e. g. backports of drivers from newer Linux packages, or the proprietary NVidia driver package "nvidia-current") have a "Modaliases:" package header which includes all modalias patterns from all kernel modules that they ship. It is recommended to add these headers to the package with dh_modaliases(1). ubuntu-drivers-common uses these package headers to map a particular piece of hardware (identified by a modalias) to the driver packages which cover that hardware. Custom detection plugins ------------------------ For some kinds of drivers the modalias detection approach does not work. For example, the "sl-modem-daemon" driver requires some checks in /proc/asound/cards and "aplay -l" to decide whether or not it applies to the system. These special cases can be put into a "detection plugin", by adding a small piece of Python code to /usr/share/ubuntu-drivers-common/detect/NAME.py (shipped in ./detect-plugins/ in the ubuntu-drivers-common source). They need to export a method def detect(apt_cache): # do detection logic here return ['driver_package', ...] which can do any kind of detection and then return the resulting set of packages that apply to the current system. Please note that this cannot rely on having root privileges. ubuntu-drivers-common-0.2.91.4/Quirks/0000775000000000000000000000000012322472605014402 5ustar ubuntu-drivers-common-0.2.91.4/Quirks/quirkreader.py0000664000000000000000000001323412322472605017275 0ustar #!/usr/bin/python3 # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import xkit.xutils import xkit.xorgparser import Quirks.quirkinfo import tempfile import os class Quirk: def __init__(self, id=None, handler=[], x_snippet="", match_tags={}): self.id = id self.handler = handler self.x_snippet = x_snippet self.match_tags = {}.fromkeys(Quirks.quirkinfo.dmi_keys, '') class ReadQuirk: def __init__(self, source=None): self.source = source #See if the source is a file or a file object #and act accordingly file = self.source if file == None: lines_list = [] else: if not hasattr(file, 'write'):#it is a file myfile = open(file, 'r') lines_list = myfile.readlines() myfile.close() else:#it is a file object lines_list = file.readlines() inside_quirk = False has_id = False has_handler = False inside_x_snippet = False self._quirks = [] it = 0 for line in lines_list: if line.strip().startswith('#'): continue if inside_quirk: if inside_x_snippet: if line.lower().strip().startswith('endxorgsnippet'): inside_x_snippet = False continue else: self._quirks[it].x_snippet += line else: #not in x_snippet if not has_id and line.lower().strip().startswith('identifier'): has_id = True temp_str = "identifier" id = line[line.lower().rfind(temp_str) + len( temp_str):].strip().replace('"', '') self._quirks[it].id = id del temp_str elif not has_handler and line.lower().strip().startswith('handler'): has_handler = True temp_str = "handler" handler = line[line.lower().rfind(temp_str) + len( temp_str):].strip().replace('"', '') handlers_list = handler.split('|') self._quirks[it].handler = handlers_list del temp_str elif line.lower().strip().startswith('match'): temp_str = "match" temp_bits = line[line.lower().rfind(temp_str) + len(temp_str):].strip().split('"') tag_match = '' tag_value = '' tag_values = [] for elem in temp_bits: if elem.strip(): if not tag_match: tag_match = elem.strip() #tag_values = [] else: tag_value = elem.strip() tag_values = tag_value.split('|') self._quirks[it].match_tags[tag_match] = tag_values break del temp_bits del temp_str del tag_values elif line.lower().strip().startswith('xorgsnippet'): inside_x_snippet = True self._quirks[it].x_snippet = "" continue elif line.lower().strip().startswith('endsection'): #End Quirk inside_quirk = False if not self._quirks[it].id: self._quirks.pop(it) else: it += 1 else: if line.lower().strip().startswith('section') \ and "quirk" in line.lower(): #Begin Quirk inside_quirk = True temp_quirk = Quirk() self._quirks.append(temp_quirk) del temp_quirk continue def get_quirks(self): return self._quirks #if __name__ == "__main__": #quirk_file = ReadQuirk("quirk_snippet.txt") #quirks = quirk_file.get_quirks() #for quirk in quirks: #print 'Quirk id: "%s"' % quirk.id #for tag in quirk.match_tags.keys(): #print 'Matching "%s" with value "%s"' % (tag, quirk.match_tags[tag]) #print quirk.x_snippet #tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False) #tmp_file.write(quirk.x_snippet) #tmp_file.close() #tmp_xkit = xkit.xorgparser.Parser(tmp_file.name) #print tmp_xkit.globaldict #os.unlink(tmp_file.name) ubuntu-drivers-common-0.2.91.4/Quirks/quirkinfo.py0000664000000000000000000000343012322472605016763 0ustar # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os dmi_keys = ('product_name', 'product_version', 'sys_vendor', 'bios_version', 'bios_vendor', 'bios_date', 'board_name', 'board_vendor') class QuirkInfo: def __init__(self): self.sys_dir = '/sys' self._quirk_info = {}.fromkeys(dmi_keys, '') def get_dmi_info(self): '''Return all the dmi info of the system hardware. Some or the whole Dmi info may not be available on some systems. The default implementation queries sysfs. ''' for item in self._quirk_info.keys(): try: value = open(os.path.join(self.sys_dir, 'class', 'dmi', 'id', item)).read().strip() except (OSError, IOError): value = '' self._quirk_info[item] = value return self._quirk_info def main(): a = QuirkInfo() print(a.get_dmi_info()) return 0 #if __name__ == '__main__': #main() ubuntu-drivers-common-0.2.91.4/Quirks/quirkapplier.py0000664000000000000000000001374112322472605017472 0ustar # -*- coding: utf-8 -*- # (c) 2012 Canonical Ltd. # # Authors: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from glob import glob import os import sys import tempfile import logging import xkit.xutils import xkit.xorgparser import Quirks.quirkreader import Quirks.quirkinfo class QuirkChecker: def __init__(self, handler, path='/usr/share/jockey/quirks'): self._handler = handler self.quirks_path = path self._quirks = [] self.get_quirks_from_path() self._system_info = self.get_system_info() self._xorg_conf_d_path = '/usr/share/X11/xorg.conf.d' def get_quirks_from_path(self): '''check all the files in a directory looking for quirks''' self._quirks = [] if os.path.isdir(self.quirks_path): for f in glob(os.path.join(self.quirks_path, '*')): if os.path.isfile(f): logging.debug('Parsing %s' % f) quirks = self.get_quirks_from_file(f) self._quirks += quirks else: logging.debug('%s does not exist' % self.quirks_path) return self._quirks def get_quirks_from_file(self, quirk_file): '''check all the files in a directory looking for quirks''' # read other blacklist files (which we will not touch, but evaluate) quirk_file = Quirks.quirkreader.ReadQuirk(quirk_file) return quirk_file.get_quirks() def get_system_info(self): '''Get system info for the quirk''' quirk_info = Quirks.quirkinfo.QuirkInfo() return quirk_info.get_dmi_info() def matches_tags(self, quirk): '''See if tags match system info''' result = True for tag in quirk.match_tags.keys(): for val in quirk.match_tags[tag]: if (self._system_info.get(tag) and self._system_info.get(tag) != val and len(quirk.match_tags[tag]) <= 1): logging.debug('Failure to match %s with %s' % (self._system_info.get(tag), val)) return False logging.debug('Success') return result def _check_quirks(self, enable=True): '''Process quirks and do something with them''' for quirk in self._quirks: if self._handler.lower() in [x.lower().strip() for x in quirk.handler]: logging.debug('Processing quirk %s' % quirk.id) if self.matches_tags(quirk): # Do something here if enable: logging.info('Applying quirk %s' % quirk.id) self._apply_quirk(quirk) else: logging.info('Unapplying quirk %s' % quirk.id) self._unapply_quirk(quirk) else: logging.debug('Quirk doesn\'t match') def enable_quirks(self): '''Enable all quirks for a handler''' self._check_quirks(True) def disable_quirks(self): '''Disable all quirks for a handler''' self._check_quirks(False) def _get_destination_path(self, quirk): '''Return the path to the X config file''' return '%s/10-%s-%s.conf' % (self._xorg_conf_d_path, self._handler, quirk.id.lower().replace(' ', '-')) def _apply_quirk(self, quirk): '''Get the xorg snippet and apply it''' # Get the relevant x_snippet # Write conf file to /usr/share/X11/xorg.conf.d/file.conf destination = self._get_destination_path(quirk) tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False) tmp_file.write(quirk.x_snippet) tmp_file.close() tmp_xkit = xkit.xorgparser.Parser(tmp_file.name) # TODO: REMOVE THIS logging.debug(tmp_xkit.globaldict) os.unlink(tmp_file.name) try: logging.debug('Creating %s' % destination) tmp_xkit.write(destination) except IOError: logging.exception('Error during write()') return False return True def _unapply_quirk(self, quirk): '''Remove the file with the xorg snippet''' # Get the relevant x_snippet # Write conf file to /usr/share/X11/xorg.conf.d/file.conf destination = self._get_destination_path(quirk) logging.debug('Removing %s ...' % destination) try: os.unlink(destination) except (OSError, IOError): logging.exception('Cannot unlink destination') return False return True def main(): a = QuirkChecker('nvidia', path='/home/alberto/oem/jockey/quirks') a.enable_quirks() a.disable_quirks() print(os.path.abspath( __file__ )) #quirk_file = ReadQuirk("quirk_snippet.txt") #quirks = quirk_file.get_quirks() #for quirk in quirks: #print 'Quirk id: "%s"' % quirk.id #for tag in quirk.match_tags.keys(): #print 'Matching "%s" with value "%s"' % (tag, quirk.match_tags[tag]) #print quirk.x_snippet #tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False) #tmp_file.write(quirk.x_snippet) #tmp_file.close() #tmp_xkit = xkit.xorgparser.Parser(tmp_file.name) #print tmp_xkit.globaldict #os.unlink(tmp_file.name) return 0 #if __name__ == '__main__': #main() ubuntu-drivers-common-0.2.91.4/Quirks/__init__.py0000664000000000000000000000000012322472605016501 0ustar ubuntu-drivers-common-0.2.91.4/PKG-INFO0000664000000000000000000000052012322472605014216 0ustar Metadata-Version: 1.0 Name: ubuntu-drivers-common Version: 0.1 Summary: Detect and install additional Ubuntu driver packages Home-page: http://pyserial.sourceforge.net/ Author: Alberto Milone Author-email: albertomilone@alice.it License: GPLv2 Description: Detect and install additional Ubuntu driver packages Platform: Linux ubuntu-drivers-common-0.2.91.4/NvidiaDetector/0000775000000000000000000000000012322472605016030 5ustar ubuntu-drivers-common-0.2.91.4/NvidiaDetector/nvidiadetector.py0000664000000000000000000004050512322472605021412 0ustar # # nvidiadetector.py # # Copyright 2008 Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import os import re import subprocess from subprocess import Popen, PIPE import sys, logging import apt obsoletePackagesPath = '/usr/share/ubuntu-drivers-common/obsolete' class NoDatadirError(Exception): "Exception thrown when no modaliases dir can be found" class NvidiaDetection(object): ''' A simple class to: * Detect the available graphics cards * See what drivers support them (If they are NVIDIA cards). If more than one card is available, try to find the highest common driver version which supports them all. (READ the comments in the code for further details) * Return the recommended driver version ''' def __init__(self, printonly=None, verbose=None, obsolete=obsoletePackagesPath): ''' printonly = if set to None will make an instance of this class return the selected driver. If set to True it won't return anything. It will simply and print the choice. verbose = if set to True will make the methods print what is happening. ''' # A simple look-up table for drivers whose name is not a digit # "current" is set to 1000 so as to make sure that it always has # the highest priority. self.__driver_aliases = {'current': 1000} self.printonly = printonly self.verbose = verbose self.oldPackages = self.getObsoletePackages(obsolete) self.detection() self.getData() self.getCards() self.removeUnsupported() if printonly == True: self.printSelection() else: self.selectDriver() def __get_name_from_value(self, value): '''Get the name of a driver from its corresponding integer''' for k, v in self.__driver_aliases.items(): if v == value: return k return None def __get_value_from_name(self, name): '''Get the integer associated to the name of a driver''' v = self.__driver_aliases.get(name) if v is None: v = int(name) return v def getObsoletePackages(self, obsolete): '''Read the list of obsolete packages from a file''' tempList = [] try: tempList = [x.strip() for x in open(obsolete).readlines()] tempList = [x for x in tempList if x != ''] except IOError: pass return tempList def detection(self): ''' Detect the models of the graphics cards and store them in self.cards ''' self.cards = [] p1 = Popen(['lspci', '-n'], stdout=PIPE, universal_newlines=True) p = p1.communicate()[0].split('\n') # if you don't have an nvidia card, fake one for debugging #p = ['00:02.0 0300: 10DE:03DE (rev 02)'] indentifier1 = re.compile('.*0300: *(.+):(.+) \(.+\)') indentifier2 = re.compile('.*0300: *(.+):(.+)') for line in p: m1 = indentifier1.match(line) m2 = indentifier2.match(line) if m1: id1 = m1.group(1).strip().lower() id2 = m1.group(2).strip().lower() id = id1 + ':' + id2 self.cards.append(id) elif m2: id1 = m2.group(1).strip().lower() id2 = m2.group(2).strip().lower() id = id1 + ':' + id2 self.cards.append(id) def getData(self): ''' Get the data from the modaliases for each driver and store them in self.drivers ''' self.drivers = {} vendor_product_re = re.compile('pci:v0000(.+)d0000(.+)sv') for package in apt.Cache(): if (not package.name.startswith('nvidia-') or 'updates' in package.name or 'experimental' in package.name or 'current' in package.name): continue try: m = package.candidate.record['Modaliases'] except (KeyError, AttributeError): # that's entirely expected for -vdpau and friends; just for # debugging #logging.warning('Package %s has no modalias header' % package.name) continue # package names can be like "nvidia-173:i386" and we need to # extract the driver flavour from the name e.g. "173" stripped_package_name = package.name.split('-', 1)[1].split(':', 1)[0] driver_version = self.__get_value_from_name(stripped_package_name) try: for part in m.split(')'): part = part.strip() if not part: continue module, lst = part.split('(') for alias in lst.split(','): vp = vendor_product_re.match(alias.lstrip()) if not vp: logging.error('Package %s has unexpected modalias: %s' % ( package.name, alias)) continue vendor = vp.group(1).lower() product = vp.group(2).lower() self.drivers.setdefault(driver_version, []).append( vendor + ':' + product) except ValueError: logging.error('Package %s has invalid modalias header: %s' % ( package.name, m)) # If we didn't find anything useful just print none and exit so as not # to trigger debconf. if len(self.drivers.keys()) == 0: sys.stdout.flush() print('none') #raise ValueError, "modaliases have no useful information" def getCards(self): ''' See if the detected graphics cards are NVIDIA cards. If they are NVIDIA cards, append them to self.nvidiaCards ''' self.driversForCards = {} self.nvidiaCards = [] ''' It is possible to override hardware detection (only for testing purposes) by setting self.cards to one of the following lists: self.cards = ['10de:02e2', '10de:002d', '10de:0296', '10de:087f'] self.cards = ['10de:02e2', '10de:087f'] self.cards = ['10de:02e2', '10de:087f', '10de:fake'] self.cards = ['10de:0288'] # -96 driver only self.cards = ['10de:fake'] ''' for card in self.cards: if card[0: card.find(':')] == '10de': if self.verbose: print('NVIDIA card found (' + card + ')') self.nvidiaCards.append(card) self.orderedList = sorted(self.drivers, reverse=True) ''' See what drivers support each card and fill self.driversForCards so as to have something like the following: self.driversForCards = { 'id_of_card1': [driver1, driver2], 'id_of_card2': [driver2, driver3], } ''' for card in self.nvidiaCards: supported = False for driver in self.orderedList: if card in self.drivers[driver]: supported = True if self.verbose: print('Card %s supported by driver %s' % (card, driver)) self.driversForCards.setdefault(card, []).append(driver) if supported == False: self.driversForCards.setdefault(card, []).append(None) def removeUnsupported(self): ''' Remove unsupported cards from self.nvidiaCards and from self.driversForCards ''' unsupportedCards = [] for card in self.driversForCards: if None in self.driversForCards[card]: unsupportedCards.append(card) for unsupported in unsupportedCards: if self.verbose: print('Removing unsupported card ' + unsupported) self.nvidiaCards.remove(unsupported) del self.driversForCards[unsupported] def selectDriver(self): ''' If more than one card is available, try to get the highest common driver ''' cardsNumber = len(self.nvidiaCards) if cardsNumber > 0:#if a NVIDIA card is available if cardsNumber > 1:#if more than 1 card ''' occurrence stores the number of occurrences (the values of the dictionary) of each driver version (the keys of the dictionary) Example: occurrence = {177: 1, 173: 3} This means that driver 177 supports only 1 card while 173 supports 3 cards. ''' occurrence = {} for card in self.driversForCards: for drv in self.driversForCards[card]: occurrence.setdefault(drv, 0) occurrence[drv] += 1 occurrences = sorted(occurrence, reverse=True) ''' candidates is the list of the likely candidates for the installation ''' candidates = [] for driver in occurrences: if occurrence[driver] == cardsNumber: candidates.append(driver) if len(candidates) > 0: ''' If more than one driver version works for all the available cards then the newest one is selected. USE-CASE: If a user has the following cards: * GeForce 9300 (supported by driver 177 and 173) * GeForce 7300 (supported by driver 177 and 173) * GeForce 6200 (supported by driver 177 and 173) Driver 177 is selected. ''' candidates.sort(reverse=True) choice = candidates[0] if self.verbose and not self.printonly: print('Recommended NVIDIA driver: ' + choice) else: ''' Otherwise, if there is no single driver version which works for all the available cards, the newest one is selected. USE-CASE: If a user has the following cards: * GeForce 9300 (supported by driver 177 and 173) * GeForce 1 (supported by driver 71) * GeForce 2 (supported by driver 71) The most modern card has the highest priority since no common driver can be found. The other 2 cards should use the open source driver ''' choice = occurrences[0] if self.verbose and not self.printonly: print('Recommended NVIDIA driver: ' + choice) else:#just one card ''' The choice is easy if only one card is available and/or supported. The newest driver which supports the card is chosen. ''' choice = self.driversForCards[list(self.driversForCards.keys())[0]][0] if self.verbose and not self.printonly: print('Recommended NVIDIA driver: ' + choice) ''' FIXME: we should use a metapackage for this ''' driver_name = self.__get_name_from_value(choice) if driver_name != None: choice = 'nvidia-' + str(driver_name) else: choice = 'nvidia-' + str(choice) else: ''' If no card is supported ''' if self.verbose: print('No NVIDIA package to install') choice = None return choice def checkpkg(self, pkglist): ''' USAGE: * pkglist is the list of packages you want to check * use lists for one or more packages * use a string if it is only one package * lists will work well in both cases ''' ''' Checks whether all the packages in the list are installed and returns a list of the packages which are not installed ''' lines = [] notinstalled = [] p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE, universal_newlines=True) p = p1.communicate()[0] c = p.split('\n') for line in c: if line.find('\tinstall') != -1:#the relevant lines lines.append(line.split('\t')[0]) if self.isstr(pkglist) == True:#if it is a string try: if lines.index(pkglist): pass except ValueError: notinstalled.append(pkglist) else:#if it is a list for pkg in pkglist: try: if lines.index(pkg): pass except ValueError: notinstalled.append(pkg) return notinstalled def isstr(self, elem): if bytes is str: #Python 2 string_types = basestring else: #Python 3 string_types = str return isinstance(elem, string_types) def islst(self, elem): return isinstance(elem, (tuple, list)) def getDrivers(self): ''' oldPackages = a list of the names of the obsolete drivers notInstalled = a list of the obsolete drivers which are not installed ''' installedPackage = None notInstalled = self.checkpkg(self.oldPackages) for package in self.oldPackages: if package not in notInstalled: installedPackage = package return (len(notInstalled) != len(self.oldPackages)) def printSelection(self): ''' Part for the kernel postinst.d/ hook ''' driver = self.selectDriver() if self.getDrivers():#if an old driver is installed if driver:#if an appropriate driver is found sys.stdout.flush() print(driver) else: sys.stdout.flush() print('none') else: #print driver sys.stdout.flush() print('none') #def usage(): # instructionsList = ['The only accepted parameters are:' # '\n --printonly', '\tprint the suggested driver' # # '\n --verbose', '\t\teach step will be verbose' # ] # print(''.join(instructionsList)) #def main(): # err = 'Error: parameters not recognised' # try: # opts, args = getopt.getopt(sys.argv[1:], 'hp:v', ['help', 'printonly', 'verbose']) # except getopt.GetoptError as err: # # print help information and exit: # print str(err) # will print something like 'option -a not recognized' # usage() # sys.exit(2) # printonly = None # verbose = None # for o, a in opts: # if o in ('-v', '--verbose'): # verbose = True # elif o in ('-p', '--printonly'): # printonly = True # elif o in ('-h', '--help'): # usage() # sys.exit() # else: # assert False, 'unhandled option' # a = NvidiaDetection(printonly=printonly, verbose=verbose) #if __name__ == '__main__': # main() ubuntu-drivers-common-0.2.91.4/NvidiaDetector/alternatives.py0000664000000000000000000001401512322472605021104 0ustar # # alternatives.py # # Copyright 2010 Canonical Services Ltd # Author: Alberto Milone # # This program 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 2 of the License, or # (at your option) any later version. # # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import os import re import subprocess from subprocess import Popen, PIPE, CalledProcessError class MultiArchUtils(object): def __init__(self): # We have 2 alternatives, one for each architecture self._supported_architectures = {'i386': 'i386', 'amd64': 'x86_64'} self._main_arch = self._get_architecture() self._other_arch = list(self._supported_architectures.values())[ int(not list(self._supported_architectures.values()).index(self._main_arch))] # Make sure that the PATH environment variable is set if not os.environ.get('PATH'): os.environ['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin' def _get_architecture(self): dev_null = open('/dev/null', 'w') p1 = Popen(['dpkg', '--print-architecture'], stdout=PIPE, stderr=dev_null, universal_newlines=True) p = p1.communicate()[0] dev_null.close() architecture = p.strip() return self._supported_architectures.get(architecture) def _get_alternative_name_from_arch(self, architecture): alternative = '%s-linux-gnu_gl_conf' % architecture return alternative def get_main_alternative_name(self): return self._get_alternative_name_from_arch(self._main_arch) def get_other_alternative_name(self): return self._get_alternative_name_from_arch(self._other_arch) class Alternatives(object): def __init__(self, master_link): self._open_drivers_alternative = 'mesa/ld.so.conf' self._open_egl_drivers_alternative = 'mesa-egl/ld.so.conf' self._command = 'update-alternatives' self._master_link = master_link # Make sure that the PATH environment variable is set if not os.environ.get('PATH'): os.environ['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin' def list_alternatives(self): '''Get the list of alternatives for the master link''' dev_null = open('/dev/null', 'w') alternatives = [] p1 = Popen([self._command, '--list', self._master_link], stdout=PIPE, stderr=dev_null, universal_newlines=True) p = p1.communicate()[0] dev_null.close() c = p.split('\n') for line in c: line.strip() and alternatives.append(line.strip()) return alternatives def get_current_alternative(self): '''Get the alternative in use''' dev_null = open('/dev/null', 'w') current_alternative = None p1 = Popen([self._command, '--query', self._master_link], stdout=PIPE, stderr=dev_null, universal_newlines=True) p = p1.communicate()[0] dev_null.close() c = p.split('\n') for line in c: if line.strip().startswith('Value:'): return line.replace('Value:', '').strip() return None def get_alternative_by_name(self, name, ignore_pattern=None): '''Get the alternative link by providing the driver name ignore_pattern allows ignoring a substring in the name''' if ignore_pattern: name = name.replace(ignore_pattern, '') alternatives = self.list_alternatives() for alternative in alternatives: if alternative.split('/')[-2] == name: return alternative return None def get_open_drivers_alternative(self): '''Get the alternative link for open drivers''' return self.get_alternative_by_name(self._open_drivers_alternative) def get_open_egl_drivers_alternative(self): '''Get the alternative link for open EGL/GLES drivers''' return self.get_alternative_by_name(self._open_egl_drivers_alternative) def update_gmenu(self): '''Trigger gmenu so that the icons will show up in the menu''' try: subprocess.check_call(['dpkg-trigger', '--by-package=fakepackage', 'gmenucache']) subprocess.check_call(['dpkg', '--configure', '-a']) except (OSError, CalledProcessError): pass def set_alternative(self, path): '''Tries to set an alternative and returns the boolean exit status''' try: subprocess.check_call([self._command, '--set', self._master_link, path]) self.ldconfig() except CalledProcessError: return False self.update_gmenu() return True def ldconfig(self): '''Call ldconfig''' try: subprocess.check_call(['ldconfig']) except CalledProcessError: return False return True def resolve_module_alias(self, alias): '''Get the 1st kernel module name matching an alias''' dev_null = open('/dev/null', 'w') current_alternative = None p1 = Popen(['modprobe', '--resolve-alias', alias], stdout=PIPE, stderr=dev_null, universal_newlines=True) p = p1.communicate()[0] dev_null.close() c = p.split('\n') for line in c: if line.strip().startswith('Usage:'): return None return line.strip() return None ubuntu-drivers-common-0.2.91.4/NvidiaDetector/__init__.py0000664000000000000000000000000012322472605020127 0ustar ubuntu-drivers-common-0.2.91.4/Changes.txt0000664000000000000000000000021112322472605015227 0ustar Version 0.1: This package will find obsolete NVIDIA drivers in use, detect the hardware and recommend the most appropriate driver. ubuntu-drivers-common-0.2.91.4/COPYING0000664000000000000000000004310312322472605014160 0ustar GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program 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 2 of the License, or (at your option) any later version. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.