2011-11-11 15:19:04 +01:00
|
|
|
#!/usr/bin/python3
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# upower integration test suite
|
|
|
|
|
#
|
|
|
|
|
# Run in built tree to test local built binaries, or from anywhere else to test
|
|
|
|
|
# system installed binaries.
|
|
|
|
|
#
|
|
|
|
|
# Copyright: (C) 2011 Martin Pitt <martin.pitt@ubuntu.com>
|
|
|
|
|
#
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2017-10-19 17:54:07 +02:00
|
|
|
import dbus
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
import tempfile
|
|
|
|
|
import subprocess
|
|
|
|
|
import unittest
|
|
|
|
|
import time
|
|
|
|
|
|
2011-12-05 10:44:35 +01:00
|
|
|
try:
|
2015-09-23 16:14:40 +02:00
|
|
|
import gi
|
2011-12-05 10:44:35 +01:00
|
|
|
from gi.repository import GLib
|
|
|
|
|
from gi.repository import Gio
|
2015-09-23 16:14:40 +02:00
|
|
|
gi.require_version('UPowerGlib', '1.0')
|
2013-10-08 16:38:57 +02:00
|
|
|
from gi.repository import UPowerGlib
|
2011-12-05 10:44:35 +01:00
|
|
|
except ImportError as e:
|
|
|
|
|
sys.stderr.write('Skipping tests, PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
|
|
|
|
|
sys.exit(0)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-02-20 14:38:25 +01:00
|
|
|
try:
|
2015-09-23 16:14:40 +02:00
|
|
|
gi.require_version('UMockdev', '1.0')
|
2013-02-20 14:38:25 +01:00
|
|
|
from gi.repository import UMockdev
|
|
|
|
|
except ImportError:
|
|
|
|
|
sys.stderr.write('Skipping tests, umockdev not available (https://launchpad.net/umockdev/)\n')
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2017-03-21 15:59:21 +00:00
|
|
|
try:
|
|
|
|
|
import dbusmock
|
|
|
|
|
except ImportError:
|
|
|
|
|
sys.stderr.write('Skipping tests, python-dbusmock not available (http://pypi.python.org/pypi/python-dbusmock).\n')
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
UP = 'org.freedesktop.UPower'
|
2013-10-18 16:58:48 +02:00
|
|
|
UP_DEVICE = 'org.freedesktop.UPower.Device'
|
|
|
|
|
UP_DISPLAY_OBJECT_PATH = '/org/freedesktop/UPower/devices/DisplayDevice'
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2017-10-19 17:54:07 +02:00
|
|
|
DEVICE_IFACE = 'org.bluez.Device1'
|
|
|
|
|
BATTERY_IFACE = 'org.bluez.Battery1'
|
|
|
|
|
|
2013-10-08 17:19:27 +02:00
|
|
|
(UP_DEVICE_STATE_UNKNOWN,
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
UP_DEVICE_STATE_CHARGING,
|
|
|
|
|
UP_DEVICE_STATE_DISCHARGING,
|
|
|
|
|
UP_DEVICE_STATE_EMPTY,
|
2018-11-02 09:49:33 -07:00
|
|
|
UP_DEVICE_STATE_FULLY_CHARGED,
|
|
|
|
|
UP_DEVICE_STATE_PENDING_CHARGE,
|
|
|
|
|
UP_DEVICE_STATE_PENDING_DISCHARGE) = (0, 1, 2, 3, 4, 5, 6)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-10-18 16:58:48 +02:00
|
|
|
(UP_DEVICE_LEVEL_UNKNOWN,
|
|
|
|
|
UP_DEVICE_LEVEL_NONE,
|
|
|
|
|
UP_DEVICE_LEVEL_DISCHARGING,
|
|
|
|
|
UP_DEVICE_LEVEL_LOW,
|
|
|
|
|
UP_DEVICE_LEVEL_CRITICAL,
|
2017-04-04 18:16:10 +02:00
|
|
|
UP_DEVICE_LEVEL_ACTION,
|
|
|
|
|
UP_DEVICE_LEVEL_NORMAL,
|
|
|
|
|
UP_DEVICE_LEVEL_HIGH,
|
|
|
|
|
UP_DEVICE_LEVEL_FULL) = (0, 1, 2, 3, 4, 5, 6, 7, 8)
|
2013-10-08 17:19:27 +02:00
|
|
|
|
2017-03-24 17:03:36 +01:00
|
|
|
(UP_DEVICE_KIND_UNKNOWN,
|
|
|
|
|
UP_DEVICE_KIND_LINE_POWER,
|
|
|
|
|
UP_DEVICE_KIND_BATTERY,
|
|
|
|
|
UP_DEVICE_KIND_UPS,
|
|
|
|
|
UP_DEVICE_KIND_MONITOR,
|
|
|
|
|
UP_DEVICE_KIND_MOUSE,
|
|
|
|
|
UP_DEVICE_KIND_KEYBOARD,
|
|
|
|
|
UP_DEVICE_KIND_PDA,
|
|
|
|
|
UP_DEVICE_KIND_PHONE,
|
|
|
|
|
UP_DEVICE_KIND_MEDIA_PLAYER,
|
|
|
|
|
UP_DEVICE_KIND_TABLET,
|
2019-05-09 11:14:07 +02:00
|
|
|
UP_DEVICE_KIND_COMPUTER,
|
|
|
|
|
UP_DEVICE_KIND_GAMING_INPUT) = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
|
2017-03-24 17:03:36 +01:00
|
|
|
|
2017-03-21 15:59:21 +00:00
|
|
|
class Tests(dbusmock.DBusTestCase):
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
|
|
|
|
# run from local build tree if we are in one, otherwise use system instance
|
2011-04-20 01:07:58 +02:00
|
|
|
builddir = os.getenv('top_builddir', '.')
|
2013-10-08 17:19:27 +02:00
|
|
|
if os.access(os.path.join(builddir, 'src', 'upowerd'), os.X_OK):
|
2013-02-20 14:59:56 +01:00
|
|
|
cls.daemon_path = os.path.join(builddir, 'src', 'upowerd')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
print('Testing binaries from local build tree')
|
2017-01-24 17:08:57 +01:00
|
|
|
cls.local_daemon = True
|
2017-03-21 18:07:41 +00:00
|
|
|
elif os.environ.get('UNDER_JHBUILD', False):
|
|
|
|
|
jhbuild_prefix = os.environ['JHBUILD_PREFIX']
|
|
|
|
|
cls.daemon_path = os.path.join(jhbuild_prefix, 'libexec', 'upowerd')
|
|
|
|
|
print('Testing binaries from JHBuild')
|
|
|
|
|
cls.local_daemon = False
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
else:
|
|
|
|
|
print('Testing installed system binaries')
|
2013-02-20 14:59:56 +01:00
|
|
|
cls.daemon_path = None
|
2011-11-11 15:19:04 +01:00
|
|
|
with open('/usr/share/dbus-1/system-services/org.freedesktop.UPower.service') as f:
|
|
|
|
|
for line in f:
|
|
|
|
|
if line.startswith('Exec='):
|
2013-02-20 14:59:56 +01:00
|
|
|
cls.daemon_path = line.split('=', 1)[1].strip()
|
2011-11-11 15:19:04 +01:00
|
|
|
break
|
2013-02-20 14:59:56 +01:00
|
|
|
assert cls.daemon_path, 'could not determine daemon path from D-BUS .service file'
|
2017-01-24 17:08:57 +01:00
|
|
|
cls.local_daemon = False
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2012-06-14 13:07:30 +02:00
|
|
|
# fail on CRITICALs on client side
|
2013-10-08 17:19:27 +02:00
|
|
|
GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING |
|
|
|
|
|
GLib.LogLevelFlags.LEVEL_ERROR |
|
2012-06-14 13:07:30 +02:00
|
|
|
GLib.LogLevelFlags.LEVEL_CRITICAL)
|
|
|
|
|
|
2013-02-20 14:59:56 +01:00
|
|
|
# set up a fake system D-BUS
|
|
|
|
|
cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
|
|
|
|
|
cls.test_bus.up()
|
2014-09-02 15:57:09 +02:00
|
|
|
try:
|
|
|
|
|
del os.environ['DBUS_SESSION_BUS_ADDRESS']
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
2013-02-20 14:59:56 +01:00
|
|
|
os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = cls.test_bus.get_bus_address()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-02-20 14:59:56 +01:00
|
|
|
cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
2017-10-19 17:54:07 +02:00
|
|
|
cls.dbus_con = cls.get_dbus(True)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-02-20 14:59:56 +01:00
|
|
|
@classmethod
|
|
|
|
|
def tearDownClass(cls):
|
|
|
|
|
cls.test_bus.down()
|
2017-03-21 15:59:21 +00:00
|
|
|
dbusmock.DBusTestCase.tearDownClass()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2013-02-20 14:38:25 +01:00
|
|
|
'''Set up a local umockdev testbed.
|
2013-10-08 17:19:27 +02:00
|
|
|
|
2013-02-20 14:38:25 +01:00
|
|
|
The testbed is initially empty.
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
'''
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed = UMockdev.Testbed.new()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-10-08 17:19:27 +02:00
|
|
|
self.proxy = None
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.log = None
|
|
|
|
|
self.daemon = None
|
2017-03-21 15:59:21 +00:00
|
|
|
self.logind = None
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
def tearDown(self):
|
2013-02-20 14:38:25 +01:00
|
|
|
del self.testbed
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-03-21 15:59:21 +00:00
|
|
|
if self.logind:
|
|
|
|
|
self.logind.stdout.close()
|
|
|
|
|
self.logind.terminate()
|
|
|
|
|
self.logind.wait()
|
|
|
|
|
|
2017-10-19 17:54:07 +02:00
|
|
|
try:
|
|
|
|
|
if self.bluez:
|
|
|
|
|
self.bluez.stdout.close()
|
|
|
|
|
self.bluez.terminate()
|
|
|
|
|
self.bluez.wait()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
# on failures, print daemon log
|
2014-09-02 17:19:08 +02:00
|
|
|
errors = [x[1] for x in self._outcome.errors if x[1]]
|
|
|
|
|
if errors and self.log:
|
2011-12-05 10:30:14 +01:00
|
|
|
with open(self.log.name) as f:
|
|
|
|
|
sys.stderr.write('\n-------------- daemon log: ----------------\n')
|
|
|
|
|
sys.stderr.write(f.read())
|
|
|
|
|
sys.stderr.write('------------------------------\n')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Daemon control and D-BUS I/O
|
|
|
|
|
#
|
|
|
|
|
|
2017-03-24 19:05:17 +01:00
|
|
|
def start_daemon(self, cfgfile=None):
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
'''Start daemon and create DBus proxy.
|
|
|
|
|
|
|
|
|
|
Do this after adding the devices you want to test with. At the moment
|
|
|
|
|
this only works with coldplugging, as we do not currently have a way to
|
|
|
|
|
inject simulated uevents.
|
|
|
|
|
|
|
|
|
|
When done, this sets self.proxy a the Gio.DBusProxy for upowerd.
|
|
|
|
|
'''
|
|
|
|
|
env = os.environ.copy()
|
2017-03-24 19:05:17 +01:00
|
|
|
if cfgfile is not None:
|
|
|
|
|
env['UPOWER_CONF_FILE_NAME'] = cfgfile
|
2012-06-14 13:07:30 +02:00
|
|
|
env['G_DEBUG'] = 'fatal-criticals'
|
2013-02-20 14:38:25 +01:00
|
|
|
# note: Python doesn't propagate the setenv from Testbed.new(), so we
|
|
|
|
|
# have to do that ourselves
|
|
|
|
|
env['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.log = tempfile.NamedTemporaryFile()
|
2017-01-24 17:08:57 +01:00
|
|
|
if os.getenv('VALGRIND') != None:
|
|
|
|
|
if self.local_daemon:
|
|
|
|
|
daemon_path = ['libtool', '--mode=execute', 'valgrind', self.daemon_path, '-v']
|
|
|
|
|
else:
|
|
|
|
|
daemon_path = ['valgrind', self.daemon_path, '-v']
|
|
|
|
|
else:
|
|
|
|
|
daemon_path = [self.daemon_path, '-v']
|
|
|
|
|
self.daemon = subprocess.Popen(daemon_path,
|
2013-10-08 17:19:27 +02:00
|
|
|
env=env, stdout=self.log,
|
|
|
|
|
stderr=subprocess.STDOUT)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# wait until the daemon gets online
|
2012-06-14 13:07:30 +02:00
|
|
|
timeout = 100
|
|
|
|
|
while timeout > 0:
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
time.sleep(0.1)
|
2012-06-14 13:07:30 +02:00
|
|
|
timeout -= 1
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
try:
|
|
|
|
|
self.get_dbus_property('DaemonVersion')
|
|
|
|
|
break
|
2011-09-05 14:38:31 +02:00
|
|
|
except GLib.GError:
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
pass
|
2012-06-14 13:07:30 +02:00
|
|
|
else:
|
|
|
|
|
self.fail('daemon did not start in 10 seconds')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-10-08 17:19:27 +02:00
|
|
|
self.proxy = Gio.DBusProxy.new_sync(
|
|
|
|
|
self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, UP,
|
|
|
|
|
'/org/freedesktop/UPower', UP, None)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.assertEqual(self.daemon.poll(), None, 'daemon crashed')
|
|
|
|
|
|
|
|
|
|
def stop_daemon(self):
|
|
|
|
|
'''Stop the daemon if it is running.'''
|
|
|
|
|
|
|
|
|
|
if self.daemon:
|
|
|
|
|
try:
|
|
|
|
|
self.daemon.kill()
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
self.daemon.wait()
|
|
|
|
|
self.daemon = None
|
|
|
|
|
self.proxy = None
|
|
|
|
|
|
|
|
|
|
def get_dbus_property(self, name):
|
|
|
|
|
'''Get property value from daemon D-Bus interface.'''
|
|
|
|
|
|
2013-10-08 17:19:27 +02:00
|
|
|
proxy = Gio.DBusProxy.new_sync(
|
|
|
|
|
self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, UP,
|
|
|
|
|
'/org/freedesktop/UPower', 'org.freedesktop.DBus.Properties', None)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
return proxy.Get('(ss)', UP, name)
|
|
|
|
|
|
2013-10-18 17:36:00 +02:00
|
|
|
def get_dbus_display_property(self, name):
|
|
|
|
|
'''Get property value from display device D-Bus interface.'''
|
|
|
|
|
|
|
|
|
|
proxy = Gio.DBusProxy.new_sync(
|
|
|
|
|
self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, UP,
|
|
|
|
|
UP_DISPLAY_OBJECT_PATH, 'org.freedesktop.DBus.Properties', None)
|
2015-05-30 18:55:37 -07:00
|
|
|
return proxy.Get('(ss)', UP + '.Device', name)
|
2013-10-18 17:36:00 +02:00
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
def get_dbus_dev_property(self, device, name):
|
|
|
|
|
'''Get property value from an upower device D-Bus path.'''
|
|
|
|
|
|
2013-10-08 17:19:27 +02:00
|
|
|
proxy = Gio.DBusProxy.new_sync(
|
|
|
|
|
self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, UP, device,
|
|
|
|
|
'org.freedesktop.DBus.Properties', None)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
return proxy.Get('(ss)', UP + '.Device', name)
|
|
|
|
|
|
2017-03-21 15:59:21 +00:00
|
|
|
def start_logind(self, parameters=None):
|
|
|
|
|
self.logind, self.logind_obj = self.spawn_server_template('logind',
|
|
|
|
|
parameters or {},
|
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
|
|
2017-10-19 17:54:07 +02:00
|
|
|
def start_bluez(self, parameters=None):
|
|
|
|
|
self.bluez, self.bluez_obj = self.spawn_server_template('bluez5',
|
|
|
|
|
parameters or {},
|
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
|
|
2017-03-21 17:16:01 +00:00
|
|
|
def have_text_in_log(self, text):
|
2017-04-18 00:54:42 +02:00
|
|
|
return self.count_text_in_log(text) > 0
|
|
|
|
|
|
|
|
|
|
def count_text_in_log(self, text):
|
2017-03-21 17:16:01 +00:00
|
|
|
with open(self.log.name) as f:
|
2017-04-18 00:54:42 +02:00
|
|
|
return f.read().count(text)
|
2017-03-21 17:16:01 +00:00
|
|
|
|
|
|
|
|
def assertEventually(self, condition, message=None, timeout=50):
|
|
|
|
|
'''Assert that condition function eventually returns True.
|
|
|
|
|
|
|
|
|
|
Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
|
|
|
|
|
printed on failure.
|
|
|
|
|
'''
|
|
|
|
|
while timeout >= 0:
|
|
|
|
|
context = GLib.MainContext.default()
|
|
|
|
|
while context.iteration(False):
|
|
|
|
|
pass
|
|
|
|
|
if condition():
|
|
|
|
|
break
|
|
|
|
|
timeout -= 1
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
else:
|
|
|
|
|
self.fail(message or 'timed out waiting for ' + str(condition))
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
#
|
|
|
|
|
# Actual test cases
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def test_daemon_version(self):
|
|
|
|
|
'''DaemonVersion property'''
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.proxy.EnumerateDevices(), [])
|
2011-11-11 15:19:04 +01:00
|
|
|
self.assertRegex(self.get_dbus_property('DaemonVersion'), '^[0-9.]+$')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# without any devices we should assume AC
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_no_devices(self):
|
|
|
|
|
'''no devices'''
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# without any devices we should assume AC
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_props_online_ac(self):
|
|
|
|
|
'''properties with online AC'''
|
|
|
|
|
|
2013-02-20 14:38:25 +01:00
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Mains', 'online', '1'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
ac_up = devs[0]
|
|
|
|
|
self.assertTrue('line_power_AC' in ac_up)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'PowerSupply'), True)
|
2013-09-03 10:17:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'Type'), 1)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'Online'), True)
|
2013-09-27 08:26:58 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'NativePath'), 'AC')
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_props_offline_ac(self):
|
|
|
|
|
'''properties with offline AC'''
|
|
|
|
|
|
|
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
|
|
|
|
['type', 'Mains', 'online', '0'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
# we don't have any known online power device now, but still no battery
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2014-09-02 18:43:33 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(devs[0], 'Online'), False)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2018-06-19 14:00:07 +02:00
|
|
|
def test_macbook_uevent(self):
|
|
|
|
|
'''MacBooks sent uevent 5 seconds before battery updates'''
|
|
|
|
|
|
|
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
|
|
|
|
['type', 'Mains', 'online', '0'], [])
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
self.testbed.add_device('virtual', 'virtual/dmi', None,
|
|
|
|
|
['id/product_name', 'MacBookAir7,2'], [])
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
if 'BAT' in devs[0] == ac_up:
|
|
|
|
|
(bat0_up, ac_up) = devs
|
|
|
|
|
else:
|
|
|
|
|
(ac_up, bat0_up) = devs
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
|
|
|
|
|
self.testbed.set_attribute(ac, 'online', '1')
|
|
|
|
|
self.testbed.uevent(ac, 'change')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
time.sleep(3)
|
|
|
|
|
self.testbed.set_attribute(bat0, 'status', 'Charging')
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_CHARGING)
|
|
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_battery_ac(self):
|
|
|
|
|
'''properties with dynamic battery/AC'''
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
# offline AC + discharging battery
|
2014-09-02 18:43:33 +02:00
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
|
|
|
|
['type', 'Mains', 'online', '0'], [])
|
2013-02-20 14:38:25 +01:00
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
2014-09-02 18:43:33 +02:00
|
|
|
if 'BAT' in devs[0] == ac_up:
|
|
|
|
|
(bat0_up, ac_up) = devs
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
else:
|
2014-09-02 18:43:33 +02:00
|
|
|
(ac_up, bat0_up) = devs
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
# we don't have any known online power device now, but still no battery
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 80.0)
|
2011-05-14 13:20:32 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 48.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 60.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 80.0)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0)
|
2013-09-27 08:26:58 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'NativePath'), 'BAT0')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# offline AC + discharging low battery
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '1500000')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_CRITICAL)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 2.5)
|
2013-09-03 09:35:04 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'PowerSupply'), True)
|
2013-09-03 10:17:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Type'), 2)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# now connect AC again
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(ac, 'online', '1')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
# we don't have any known online power device now, but still no battery
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'Online'), True)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
def test_multiple_batteries(self):
|
|
|
|
|
'''Multiple batteries'''
|
|
|
|
|
|
|
|
|
|
# one well charged, one low
|
2013-02-20 14:38:25 +01:00
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2013-02-20 14:38:25 +01:00
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT1', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '1500000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
|
|
|
|
|
# as we have one which is well-charged, the summary state is "not low
|
|
|
|
|
# battery"
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# now set both to low
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '1500000')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_CRITICAL)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_unknown_battery_status_no_ac(self):
|
|
|
|
|
'''Unknown battery charge status, no AC'''
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'unknown',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# with no other power sources, the OnBattery value here is really
|
|
|
|
|
# arbitrary, so don't test it. The only thing we know for sure is that
|
|
|
|
|
# we aren't on low battery
|
|
|
|
|
self.start_daemon()
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_unknown_battery_status_with_ac(self):
|
|
|
|
|
'''Unknown battery charge status, with AC'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'unknown',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2013-02-20 14:38:25 +01:00
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Mains', 'online', '0'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(ac, 'online', '1')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2018-11-02 09:55:22 -07:00
|
|
|
def test_display_pending_charge_one_battery(self):
|
|
|
|
|
'''One battery pending-charge'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Not charging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('State'), UP_DEVICE_STATE_PENDING_CHARGE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
def test_display_pending_charge_other_battery_discharging(self):
|
|
|
|
|
'''One battery pending-charge and another one discharging'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Not charging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT1', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
def test_display_pending_charge_other_battery_charging(self):
|
|
|
|
|
'''One battery pending-charge and another one charging'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Not charging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT1', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Charging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('State'), UP_DEVICE_STATE_CHARGING)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2018-11-26 13:13:00 -08:00
|
|
|
def test_map_pending_charge_to_fully_charged(self):
|
|
|
|
|
'''Map pending-charge to fully-charged'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Not charging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '100',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_FULLY_CHARGED)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# and make sure we still return pending-charge below 100%
|
|
|
|
|
self.testbed.set_attribute(bat0, 'capacity', '99')
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_PENDING_CHARGE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2011-05-14 13:20:32 +02:00
|
|
|
def test_battery_charge(self):
|
|
|
|
|
'''battery which reports charge instead of energy
|
2013-10-08 17:19:27 +02:00
|
|
|
|
2011-05-14 13:20:32 +02:00
|
|
|
energy_* is in uWh, while charge_* is in uAh.
|
|
|
|
|
'''
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'charge_now', '7875000',
|
|
|
|
|
'current_now', '787000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2011-05-14 13:20:32 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2011-05-14 13:20:32 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 75.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 94.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 126.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0)
|
2013-08-23 08:52:45 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Temperature'), 0.0)
|
2011-05-14 13:20:32 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-01-31 10:23:15 +01:00
|
|
|
def test_battery_energy_charge_mixed(self):
|
|
|
|
|
'''battery which reports current energy, but full charge'''
|
|
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'energy_now', '50400000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2013-01-31 10:23:15 +01:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2013-01-31 10:23:15 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 50.4)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 126.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 40.0)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-08-23 08:31:20 +02:00
|
|
|
def test_battery_capacity_and_charge(self):
|
|
|
|
|
'''battery which reports capacity and charge_full'''
|
|
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'charge_full', '10500000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '40',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2013-08-23 08:31:20 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 40.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 50.4)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 126.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0)
|
2013-09-03 09:35:04 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'PowerSupply'), True)
|
2013-09-03 10:17:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Type'), 2)
|
2013-08-23 08:31:20 +02:00
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2013-08-23 08:31:20 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-10-22 10:02:51 +02:00
|
|
|
def test_battery_overfull(self):
|
|
|
|
|
'''battery which reports a > 100% percentage for a full battery'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Full',
|
2017-04-04 18:20:27 +02:00
|
|
|
'capacity_level', 'Normal\n',
|
2013-10-22 10:02:51 +02:00
|
|
|
'current_now', '1000',
|
|
|
|
|
'charge_now', '11000000',
|
|
|
|
|
'charge_full', '10000000',
|
|
|
|
|
'charge_full_design', '11000000',
|
|
|
|
|
'capacity', '110',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
# should clamp percentage
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 100.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'State'),
|
|
|
|
|
UP_DEVICE_STATE_FULLY_CHARGED)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 132.0)
|
|
|
|
|
# should adjust EnergyFull to reality, not what the battery claims
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 132.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFullDesign'), 132.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Voltage'), 12.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'PowerSupply'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Type'), 2)
|
2017-04-04 18:20:27 +02:00
|
|
|
# capacity_level is unused because a 'capacity' attribute is present and used instead
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_NONE)
|
2013-10-22 10:02:51 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-08-23 08:52:45 +02:00
|
|
|
def test_battery_temperature(self):
|
|
|
|
|
'''battery which reports temperature'''
|
|
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'temp', '254',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '1500000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
2013-08-23 08:52:45 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Temperature'), 25.4)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Percentage'), 2.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 1.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_CRITICAL)
|
2013-08-23 08:52:45 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-09-08 17:54:48 +02:00
|
|
|
def test_battery_broken_name(self):
|
|
|
|
|
'''Battery with funky kernel name'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'bq24735@5-0009', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'unknown',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('IsPresent'), True)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_ups_no_ac(self):
|
|
|
|
|
'''UPS properties without AC'''
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
# add a charging UPS
|
2013-02-20 14:38:25 +01:00
|
|
|
ups0 = self.testbed.add_device('usb', 'hiddev0', None, [],
|
2013-10-08 17:19:27 +02:00
|
|
|
['DEVNAME', 'null', 'UPOWER_VENDOR', 'APC',
|
|
|
|
|
'UPOWER_BATTERY_TYPE', 'ups',
|
|
|
|
|
'UPOWER_FAKE_DEVICE', '1',
|
|
|
|
|
'UPOWER_FAKE_HID_CHARGING', '1',
|
|
|
|
|
'UPOWER_FAKE_HID_PERCENTAGE', '70'])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
ups0_up = devs[0]
|
|
|
|
|
|
2013-10-18 18:43:50 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Vendor'), 'APC')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Percentage'), 70.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'State'), UP_DEVICE_STATE_CHARGING)
|
2013-09-03 09:35:04 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'PowerSupply'), True)
|
2013-09-03 10:17:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Type'), 3)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# now switch to discharging UPS
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_property(ups0, 'UPOWER_FAKE_HID_CHARGING', '0')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
self.assertEqual(devs[0], ups0_up)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'IsPresent'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Percentage'), 70.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 18:43:50 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_DISCHARGING)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# low UPS charge
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_property(ups0, 'UPOWER_FAKE_HID_PERCENTAGE', '2')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Percentage'), 2.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 18:43:50 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
|
2014-09-02 18:43:33 +02:00
|
|
|
def test_ups_offline_ac(self):
|
|
|
|
|
'''UPS properties with offline AC'''
|
|
|
|
|
|
|
|
|
|
# add low charge UPS
|
|
|
|
|
ups0 = self.testbed.add_device('usb', 'hiddev0', None, [],
|
|
|
|
|
['DEVNAME', 'null', 'UPOWER_VENDOR', 'APC',
|
|
|
|
|
'UPOWER_BATTERY_TYPE', 'ups',
|
|
|
|
|
'UPOWER_FAKE_DEVICE', '1',
|
|
|
|
|
'UPOWER_FAKE_HID_CHARGING', '0',
|
|
|
|
|
'UPOWER_FAKE_HID_PERCENTAGE', '2'])
|
|
|
|
|
# add an offline AC, should still be on battery
|
2013-02-20 14:38:25 +01:00
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Mains', 'online', '0'], [])
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
2014-09-02 18:43:33 +02:00
|
|
|
if 'AC' in devs[0]:
|
|
|
|
|
ups0_up = devs[1]
|
|
|
|
|
else:
|
|
|
|
|
ups0_up = devs[0]
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.assertEqual(len(devs), 2)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Percentage'), 2.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ups0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
2013-10-18 18:43:50 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# now plug in the AC, should switch to OnBattery=False
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(ac, 'online', '1')
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 18:43:50 +02:00
|
|
|
# FIXME this is completely wrong
|
|
|
|
|
# The AC status doesn't change anything, the AC is what powers the UPS
|
|
|
|
|
# and the UPS powers the desktop
|
|
|
|
|
#
|
|
|
|
|
# A plugged in UPS is always the one supplying the computer
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-03-21 17:16:01 +00:00
|
|
|
def test_refresh_after_sleep(self):
|
|
|
|
|
'''sleep/wake cycle to check we properly refresh the batteries'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
self.start_logind()
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
|
|
|
|
|
self.logind_obj.EmitSignal('', 'PrepareForSleep', 'b', [True])
|
|
|
|
|
self.assertEventually(lambda: self.have_text_in_log("Poll paused"), timeout=10)
|
|
|
|
|
|
|
|
|
|
# simulate some battery drain during sleep for which we then
|
|
|
|
|
# can check after we 'woke up'
|
|
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '40000000')
|
|
|
|
|
|
|
|
|
|
self.logind_obj.EmitSignal('', 'PrepareForSleep', 'b', [False])
|
|
|
|
|
self.assertEventually(lambda: self.have_text_in_log("Poll resumed"), timeout=10)
|
|
|
|
|
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 40.0)
|
|
|
|
|
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-04-18 00:54:42 +02:00
|
|
|
def test_critical_action_is_taken_repeatedly(self):
|
|
|
|
|
'''check that critical action works repeatedly (eg. after resume)'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '50000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
config = tempfile.NamedTemporaryFile(delete=False, mode='w')
|
|
|
|
|
config.write("[UPower]\n")
|
|
|
|
|
config.write("UsePercentageForPolicy=true\n")
|
|
|
|
|
config.write("PercentageAction=5\n")
|
|
|
|
|
config.write("CriticalPowerAction=Hibernate\n")
|
|
|
|
|
config.close()
|
|
|
|
|
|
|
|
|
|
self.start_logind()
|
|
|
|
|
self.start_daemon(cfgfile=config.name)
|
|
|
|
|
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
# simulate that battery has 1% (less than PercentageAction)
|
|
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '600000')
|
|
|
|
|
self.testbed.uevent(bat0, 'change')
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
|
|
|
|
|
|
|
|
|
time.sleep(20.5) # wait for UP_DAEMON_ACTION_DELAY
|
|
|
|
|
self.assertEqual(self.count_text_in_log("About to call logind method Hibernate"), 1)
|
|
|
|
|
|
|
|
|
|
# simulate that battery was charged to 100% during sleep
|
|
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '60000000')
|
|
|
|
|
self.testbed.uevent(bat0, 'change')
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
|
|
|
|
|
# simulate that battery was drained to 1% again
|
|
|
|
|
self.testbed.set_attribute(bat0, 'energy_now', '600000')
|
|
|
|
|
self.testbed.uevent(bat0, 'change')
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
|
|
|
|
|
|
|
|
|
time.sleep(20.5) # wait for UP_DAEMON_ACTION_DELAY
|
|
|
|
|
self.assertEqual(self.count_text_in_log("About to call logind method Hibernate"), 2)
|
|
|
|
|
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
os.unlink(config.name)
|
|
|
|
|
|
2017-03-24 19:05:17 +01:00
|
|
|
def test_no_poll_batteries(self):
|
|
|
|
|
''' setting NoPollBatteries option should disable polling'''
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
config = tempfile.NamedTemporaryFile(delete=False, mode='w')
|
|
|
|
|
config.write("[UPower]\n")
|
|
|
|
|
config.write("NoPollBatteries=true\n")
|
|
|
|
|
config.close()
|
|
|
|
|
|
|
|
|
|
self.start_logind()
|
|
|
|
|
self.start_daemon(cfgfile=config.name)
|
|
|
|
|
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
|
|
|
|
|
self.logind_obj.EmitSignal('', 'PrepareForSleep', 'b', [True])
|
|
|
|
|
self.assertEventually(lambda: self.have_text_in_log("Polling will be paused"), timeout=10)
|
|
|
|
|
|
|
|
|
|
self.logind_obj.EmitSignal('', 'PrepareForSleep', 'b', [False])
|
|
|
|
|
self.assertEventually(lambda: self.have_text_in_log("Polling will be resumed"), timeout=10)
|
|
|
|
|
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# Now make sure we don't have any actual polling setup for the battery
|
|
|
|
|
self.assertFalse(self.have_text_in_log("Setup poll for"))
|
|
|
|
|
self.assertFalse(self.have_text_in_log("Poll paused for"))
|
|
|
|
|
self.assertFalse(self.have_text_in_log("Poll resumed for"))
|
|
|
|
|
|
|
|
|
|
os.unlink(config.name)
|
|
|
|
|
|
2013-09-03 09:21:12 +02:00
|
|
|
def test_vendor_strings(self):
|
|
|
|
|
'''manufacturer/model_name/serial_number with valid and invalid strings'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
2013-10-08 17:19:27 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '1500000',
|
|
|
|
|
'voltage_now', '12000000',
|
|
|
|
|
# valid ASCII string
|
|
|
|
|
'serial_number', '123ABC',
|
|
|
|
|
# valid UTF-8 string
|
|
|
|
|
'manufacturer', '⍾ Batt Inc. ☢'],
|
|
|
|
|
[])
|
2013-09-03 09:21:12 +02:00
|
|
|
|
|
|
|
|
# string with invalid chars
|
|
|
|
|
self.testbed.set_attribute_binary(bat0, 'model_name', b'AB\xFFC12\x013')
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Serial'), '123ABC')
|
2013-09-03 14:43:04 +08:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Vendor'), '⍾ Batt Inc. ☢')
|
2013-09-03 09:21:12 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Model'), 'ABC123')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'Energy'), 1.5)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-09-20 11:36:26 -05:00
|
|
|
def _add_bt_mouse(self):
|
|
|
|
|
'''Add a bluetooth mouse to testbed'''
|
2013-09-04 15:14:20 +02:00
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device('bluetooth',
|
|
|
|
|
'usb1/bluetooth/hci0/hci0:01',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
2013-09-04 15:14:20 +02:00
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device(
|
2013-09-04 15:14:20 +02:00
|
|
|
'input',
|
|
|
|
|
'usb1/bluetooth/hci0/hci0:01/input2/mouse3',
|
|
|
|
|
None,
|
|
|
|
|
[], ['DEVNAME', 'input/mouse3', 'ID_INPUT_MOUSE', '1'])
|
|
|
|
|
|
|
|
|
|
mousebat0 = self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
2013-09-20 11:36:26 -05:00
|
|
|
'usb1/bluetooth/hci0/hci0:01/1/power_supply/hid-00:11:22:33:44:55-battery',
|
2013-09-04 15:14:20 +02:00
|
|
|
None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '30',
|
2013-10-08 17:19:27 +02:00
|
|
|
'model_name', 'Fancy BT mouse'],
|
2013-09-04 15:14:20 +02:00
|
|
|
[])
|
|
|
|
|
|
2013-09-20 11:36:26 -05:00
|
|
|
return mousebat0
|
|
|
|
|
|
|
|
|
|
def test_bluetooth_mouse(self):
|
|
|
|
|
'''bluetooth mouse battery'''
|
|
|
|
|
|
|
|
|
|
self._add_bt_mouse()
|
|
|
|
|
|
2013-09-04 15:14:20 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Fancy BT mouse')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 30)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
2017-03-24 17:03:36 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), UP_DEVICE_KIND_MOUSE)
|
2013-09-04 15:14:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2013-09-04 15:14:20 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-01-26 11:35:34 +01:00
|
|
|
def test_bluetooth_mouse_reconnect(self):
|
2013-09-20 11:36:26 -05:00
|
|
|
'''bluetooth mouse powerdown/reconnect'''
|
|
|
|
|
|
|
|
|
|
mb = self._add_bt_mouse()
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs_before = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs_before), 1)
|
|
|
|
|
|
|
|
|
|
self.testbed.uevent(mb, 'remove')
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
self.assertEqual(self.proxy.EnumerateDevices(), [])
|
|
|
|
|
self.testbed.uevent(mb, 'add')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
devs_after = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(devs_before, devs_after)
|
|
|
|
|
|
|
|
|
|
# second add, which should be treated as change
|
|
|
|
|
self.testbed.uevent(mb, 'add')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
devs_after = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(devs_before, devs_after)
|
|
|
|
|
|
|
|
|
|
# with BT devices, original devices don't get removed on powerdown, but
|
|
|
|
|
# on wakeup we'll get a new one which ought to replace the previous;
|
|
|
|
|
# emulate that kernel bug
|
|
|
|
|
os.unlink(os.path.join(self.testbed.get_sys_dir(), 'class',
|
|
|
|
|
'power_supply', 'hid-00:11:22:33:44:55-battery'))
|
|
|
|
|
mb1 = self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'usb1/bluetooth/hci0/hci0:01/2/power_supply/hid-00:11:22:33:44:55-battery',
|
|
|
|
|
None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '30',
|
2013-10-08 17:19:27 +02:00
|
|
|
'model_name', 'Fancy BT mouse'],
|
2013-09-20 11:36:26 -05:00
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.testbed.uevent(mb1, 'add')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
devs_after = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(devs_before, devs_after)
|
|
|
|
|
|
|
|
|
|
mb1_up = devs_after[0]
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mb1_up, 'Model'), 'Fancy BT mouse')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mb1_up, 'Percentage'), 30)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mb1_up, 'PowerSupply'), False)
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
2013-09-20 11:36:26 -05:00
|
|
|
|
2017-01-24 17:48:47 +01:00
|
|
|
def test_hidpp_mouse(self):
|
|
|
|
|
'''HID++ mouse battery'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device('hid',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/input/input22',
|
|
|
|
|
parent,
|
2017-03-23 18:04:33 +01:00
|
|
|
[], ['DEVNAME', 'input/mouse3', 'ID_INPUT_MOUSE', '1'])
|
2017-01-24 17:48:47 +01:00
|
|
|
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/power_supply/hidpp_battery_3',
|
|
|
|
|
parent,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '30',
|
2017-01-24 18:08:24 +01:00
|
|
|
'serial_number', '123456',
|
2017-01-24 17:48:47 +01:00
|
|
|
'model_name', 'Fancy Logitech mouse'],
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Fancy Logitech mouse')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 30)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
2017-03-24 17:03:36 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), UP_DEVICE_KIND_MOUSE)
|
2017-01-24 18:08:24 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Serial'), '123456')
|
2017-01-24 17:48:47 +01:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-08-31 15:25:45 +02:00
|
|
|
def test_usb_joypad(self):
|
|
|
|
|
'''DualShock 4 joypad connected via USB'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device('usb',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-9',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9:1.3/0003:054C:09CC.0007/input/input51',
|
|
|
|
|
parent,
|
2017-08-31 16:16:18 +02:00
|
|
|
['name', 'Sony Interactive Entertainment Wireless Controller',
|
|
|
|
|
'uniq', 'ff:ff:ff:ff:ff:ff'],
|
|
|
|
|
['ID_INPUT', '1',
|
|
|
|
|
'ID_INPUT_JOYSTICK', '1'])
|
2017-08-31 15:25:45 +02:00
|
|
|
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9:1.3/0003:054C:09CC.0007/power_supply/sony_controller_battery_ff:ff:ff:ff:ff:ff',
|
|
|
|
|
parent,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Charging',
|
|
|
|
|
'capacity', '20',],
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
joypadbat0_up = devs[0]
|
|
|
|
|
|
2017-08-31 16:16:18 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(joypadbat0_up, 'Model'), 'Sony Interactive Entertainment Wireless Controller')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(joypadbat0_up, 'Serial'), 'ff:ff:ff:ff:ff:ff')
|
2017-08-31 15:25:45 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(joypadbat0_up, 'PowerSupply'), False)
|
2017-08-31 15:42:41 +02:00
|
|
|
# 12 == gaming input
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(joypadbat0_up, 'Type'), 12)
|
2017-08-31 15:25:45 +02:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
|
2019-05-07 13:29:55 +02:00
|
|
|
def test_hidpp_touchpad_race(self):
|
|
|
|
|
'''HID++ touchpad with input node that appears later'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device('hid',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
batt_dev = self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/power_supply/hidpp_battery_3',
|
|
|
|
|
parent,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity_level', 'Full\n',
|
|
|
|
|
'serial_number', '123456',
|
|
|
|
|
'model_name', 'Logitech T650'],
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Logitech T650')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
|
|
|
|
# 2 == battery
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), 2)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Serial'), '123456')
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
|
|
|
|
|
# Now test all the levels
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 100)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_FULL)
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/input/input22',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['DEVNAME', 'input/mouse3', 'ID_INPUT_TOUCHPAD', '1'])
|
|
|
|
|
self.testbed.uevent(batt_dev, 'change')
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 5 == mouse
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), 5)
|
|
|
|
|
|
2017-03-23 18:38:33 +01:00
|
|
|
def test_hidpp_touchpad(self):
|
|
|
|
|
'''HID++ touchpad battery with 5 capacity levels'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device('hid',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/input/input22',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['DEVNAME', 'input/mouse3', 'ID_INPUT_TOUCHPAD', '1'])
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.2/0003:046D:C52B.0009/0003:046D:4101.000A/power_supply/hidpp_battery_3',
|
|
|
|
|
parent,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity_level', 'Full\n',
|
|
|
|
|
'serial_number', '123456',
|
|
|
|
|
'model_name', 'Logitech T650'],
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Logitech T650')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
|
|
|
|
# 5 == mouse
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), 5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Serial'), '123456')
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
|
|
|
|
|
# Now test all the levels
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 100)
|
2017-04-04 18:20:27 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_FULL)
|
2017-03-23 18:38:33 +01:00
|
|
|
|
|
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'Critical\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 5)
|
2017-04-04 18:20:27 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_CRITICAL)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'WarningLevel'), UP_DEVICE_LEVEL_CRITICAL)
|
2017-03-23 18:38:33 +01:00
|
|
|
|
|
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'Low\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 10)
|
2017-04-04 18:20:27 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_LOW)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'WarningLevel'), UP_DEVICE_LEVEL_LOW)
|
2017-03-23 18:38:33 +01:00
|
|
|
|
|
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'High\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 70)
|
2017-04-04 18:20:27 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_HIGH)
|
2017-03-23 18:38:33 +01:00
|
|
|
|
|
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'Normal\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 55)
|
2017-04-04 18:20:27 +02:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_NORMAL)
|
2017-03-23 18:38:33 +01:00
|
|
|
|
2018-04-18 17:42:17 +02:00
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'Unknown\n')
|
|
|
|
|
self.testbed.set_attribute(dev, 'status', 'Charging\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 50.0)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_UNKNOWN)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'State'), UP_DEVICE_STATE_CHARGING)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'IconName'), 'battery-good-charging-symbolic')
|
|
|
|
|
|
|
|
|
|
self.testbed.set_attribute(dev, 'capacity_level', 'Full\n')
|
|
|
|
|
self.testbed.set_attribute(dev, 'status', 'Full\n')
|
|
|
|
|
self.testbed.uevent(dev, 'change')
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 100)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'BatteryLevel'), UP_DEVICE_LEVEL_FULL)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'State'), UP_DEVICE_STATE_FULLY_CHARGED)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'IconName'), 'battery-full-charged-symbolic')
|
|
|
|
|
|
2017-03-23 18:38:33 +01:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2015-05-04 19:31:31 -04:00
|
|
|
def test_bluetooth_hid_mouse(self):
|
|
|
|
|
'''bluetooth HID mouse battery'''
|
|
|
|
|
|
2017-01-24 14:14:36 +01:00
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'bluetooth',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/bluetooth/hci0',
|
2015-05-04 19:31:31 -04:00
|
|
|
None,
|
2017-01-24 14:14:36 +01:00
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'bluetooth',
|
|
|
|
|
'hci0:256',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['DEVTYPE', 'link'])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'hid',
|
|
|
|
|
'0005:046D:B00D.0002',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['HID_NAME', 'Fancy BT Mouse'])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
2015-05-04 19:31:31 -04:00
|
|
|
self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
2017-01-24 14:14:36 +01:00
|
|
|
'power_supply/hid-00:1f:20:96:33:47-battery',
|
|
|
|
|
parent,
|
2015-05-04 19:31:31 -04:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '30',
|
|
|
|
|
'model_name', 'Fancy BT mouse'],
|
|
|
|
|
[])
|
|
|
|
|
|
2017-01-24 14:14:36 +01:00
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'input/input22',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['ID_INPUT_MOUSE', '1'])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'mouse1',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['ID_INPUT_MOUSE', '1'])
|
|
|
|
|
|
2015-05-04 19:31:31 -04:00
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Fancy BT mouse')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 30)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
2017-03-24 17:03:36 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), UP_DEVICE_KIND_MOUSE)
|
2017-01-24 15:52:48 +01:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-03-24 17:16:32 +01:00
|
|
|
def test_virtual_unparented_device(self):
|
|
|
|
|
'''Unparented virtual input device'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'input',
|
2017-04-03 12:22:28 +02:00
|
|
|
'virtual/input/input18',
|
2017-03-24 17:16:32 +01:00
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
acpi = self.testbed.add_device('acpi', 'PNP0C0A:00', None, [], [])
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', acpi,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
# Generated a critical in older versions of upower
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-01-24 15:52:48 +01:00
|
|
|
def test_bluetooth_hid_mouse_no_legacy_subdevice(self):
|
|
|
|
|
'''bluetooth HID mouse battery'''
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'bluetooth',
|
|
|
|
|
'/devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/bluetooth/hci0',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'bluetooth',
|
|
|
|
|
'hci0:256',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['DEVTYPE', 'link'])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
dev = self.testbed.add_device(
|
|
|
|
|
'hid',
|
|
|
|
|
'0005:046D:B00D.0002',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['HID_NAME', 'Fancy BT Mouse'])
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'power_supply',
|
|
|
|
|
'power_supply/hid-00:1f:20:96:33:47-battery',
|
|
|
|
|
parent,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '30',
|
|
|
|
|
'model_name', 'Fancy BT mouse'],
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'input/input22',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['ID_INPUT_MOUSE', '1'])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mousebat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Model'), 'Fancy BT mouse')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Percentage'), 30)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'PowerSupply'), False)
|
2017-03-24 17:03:36 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(mousebat0_up, 'Type'), UP_DEVICE_KIND_MOUSE)
|
2015-05-04 19:31:31 -04:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-09-04 15:14:20 +02:00
|
|
|
def test_bluetooth_keyboard(self):
|
|
|
|
|
'''bluetooth keyboard battery'''
|
|
|
|
|
|
2017-01-24 16:17:52 +01:00
|
|
|
dev = self.testbed.add_device('bluetooth',
|
|
|
|
|
'usb2/bluetooth/hci0/hci0:1',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
2013-09-04 15:14:20 +02:00
|
|
|
|
2017-01-24 16:17:52 +01:00
|
|
|
parent = dev
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device(
|
2013-09-04 15:14:20 +02:00
|
|
|
'input',
|
2017-01-24 16:17:52 +01:00
|
|
|
'input3/event4',
|
|
|
|
|
parent,
|
2013-09-04 15:14:20 +02:00
|
|
|
[], ['DEVNAME', 'input/event4', 'ID_INPUT_KEYBOARD', '1'])
|
|
|
|
|
|
2013-10-08 17:13:06 +02:00
|
|
|
self.testbed.add_device(
|
2013-09-04 15:14:20 +02:00
|
|
|
'power_supply',
|
2017-01-24 16:17:52 +01:00
|
|
|
'power_supply/hid-00:22:33:44:55:66-battery',
|
|
|
|
|
parent,
|
2013-09-04 15:14:20 +02:00
|
|
|
['type', 'Battery',
|
|
|
|
|
'scope', 'Device',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'online', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'capacity', '40',
|
2013-10-08 17:19:27 +02:00
|
|
|
'model_name', 'Monster Typist'],
|
2013-09-04 15:14:20 +02:00
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
kbdbat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(kbdbat0_up, 'Model'), 'Monster Typist')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(kbdbat0_up, 'Percentage'), 40)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(kbdbat0_up, 'PowerSupply'), False)
|
2017-03-24 17:03:36 +01:00
|
|
|
self.assertEqual(self.get_dbus_dev_property(kbdbat0_up, 'Type'), UP_DEVICE_KIND_KEYBOARD)
|
2013-09-04 15:14:20 +02:00
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
2013-10-18 17:49:07 +02:00
|
|
|
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_NONE)
|
2013-09-04 15:14:20 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2017-10-19 17:54:07 +02:00
|
|
|
def test_bluetooth_le_mouse(self):
|
|
|
|
|
'''Bluetooth LE mouse'''
|
|
|
|
|
|
|
|
|
|
self.start_bluez()
|
|
|
|
|
|
|
|
|
|
# Add an adapter to both bluez and udev
|
|
|
|
|
adapter_name = 'hci0'
|
|
|
|
|
path = self.bluez_obj.AddAdapter(adapter_name, 'my-computer')
|
|
|
|
|
self.assertEqual(path, '/org/bluez/' + adapter_name)
|
|
|
|
|
|
|
|
|
|
dev = self.testbed.add_device('bluetooth',
|
|
|
|
|
'usb2/bluetooth/hci0/hci0:1',
|
|
|
|
|
None,
|
|
|
|
|
[], [])
|
|
|
|
|
|
|
|
|
|
# Add a device to both bluez and udev
|
|
|
|
|
address = '11:22:33:44:55:66'
|
|
|
|
|
alias = 'Arc Touch Mouse SE'
|
|
|
|
|
|
|
|
|
|
path = self.bluez_obj.AddDevice(adapter_name, address, alias)
|
|
|
|
|
|
|
|
|
|
device = self.dbus_con.get_object('org.bluez', path)
|
|
|
|
|
device.AddProperties(DEVICE_IFACE, { 'Appearance': dbus.UInt16(0x03c2, variant_level=1) })
|
|
|
|
|
|
|
|
|
|
properties = {
|
|
|
|
|
'Percentage': dbus.Byte(99, variant_level=1),
|
|
|
|
|
}
|
|
|
|
|
device.AddProperties(BATTERY_IFACE, properties)
|
|
|
|
|
|
|
|
|
|
parent = dev
|
|
|
|
|
self.testbed.add_device(
|
|
|
|
|
'input',
|
|
|
|
|
'input3/event4',
|
|
|
|
|
parent,
|
|
|
|
|
[], ['DEVNAME', 'input/event4', 'ID_INPUT_MOUSE', '1'])
|
|
|
|
|
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
|
|
|
|
|
# process = subprocess.Popen(['gdbus', 'introspect', '--system', '--dest', 'org.bluez', '--object-path', '/org/bluez/hci0/dev_11_22_33_44_55_66'])
|
|
|
|
|
|
|
|
|
|
# Wait for UPower to process the new device
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
devs = self.proxy.EnumerateDevices()
|
|
|
|
|
self.assertEqual(len(devs), 1)
|
|
|
|
|
mouse_bat0_up = devs[0]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mouse_bat0_up, 'Model'), 'Arc Touch Mouse SE')
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mouse_bat0_up, 'Percentage'), 99)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mouse_bat0_up, 'PowerSupply'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(mouse_bat0_up, 'Type'), UP_DEVICE_KIND_MOUSE)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-10-08 16:38:57 +02:00
|
|
|
#
|
|
|
|
|
# libupower-glib tests (through introspection)
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def test_lib_daemon_properties(self):
|
|
|
|
|
'''library GI: daemon properties'''
|
|
|
|
|
|
2017-03-21 16:01:15 +00:00
|
|
|
self.start_logind(parameters={'CanHybridSleep': 'yes'})
|
2013-10-08 16:38:57 +02:00
|
|
|
self.start_daemon()
|
|
|
|
|
client = UPowerGlib.Client.new()
|
|
|
|
|
self.assertRegex(client.get_daemon_version(), '^[0-9.]+$')
|
|
|
|
|
self.assertIn(client.get_lid_is_present(), [False, True])
|
|
|
|
|
self.assertIn(client.get_lid_is_closed(), [False, True])
|
|
|
|
|
self.assertEqual(client.get_on_battery(), False)
|
2017-03-21 16:01:15 +00:00
|
|
|
self.assertEqual(client.get_critical_action(), 'HybridSleep')
|
2017-01-24 17:38:21 +01:00
|
|
|
self.stop_daemon()
|
2013-10-08 16:38:57 +02:00
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
#
|
|
|
|
|
# Helper methods
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def _props_to_str(cls, properties):
|
|
|
|
|
'''Convert a properties dictionary to uevent text representation.'''
|
|
|
|
|
|
|
|
|
|
prop_str = ''
|
|
|
|
|
if properties:
|
|
|
|
|
for k, v in properties.items():
|
|
|
|
|
prop_str += '%s=%s\n' % (k, v)
|
|
|
|
|
return prop_str
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-09-20 11:57:01 -05:00
|
|
|
# run ourselves under umockdev
|
|
|
|
|
if 'umockdev' not in os.environ.get('LD_PRELOAD', ''):
|
|
|
|
|
os.execvp('umockdev-wrapper', ['umockdev-wrapper'] + sys.argv)
|
|
|
|
|
|
Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.
As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.
However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.
If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.
With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-15 19:44:47 +02:00
|
|
|
unittest.main()
|