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
|
|
|
|
|
import tempfile
|
|
|
|
|
import subprocess
|
|
|
|
|
import unittest
|
|
|
|
|
import shutil
|
|
|
|
|
import time
|
|
|
|
|
|
2011-12-05 10:44:35 +01:00
|
|
|
try:
|
|
|
|
|
from gi.repository import GLib
|
|
|
|
|
from gi.repository import Gio
|
|
|
|
|
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:
|
|
|
|
|
from gi.repository import UMockdev
|
|
|
|
|
except ImportError:
|
|
|
|
|
sys.stderr.write('Skipping tests, umockdev not available (https://launchpad.net/umockdev/)\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'
|
|
|
|
|
|
|
|
|
|
(UP_DEVICE_STATE_UNKNOWN,
|
|
|
|
|
UP_DEVICE_STATE_CHARGING,
|
|
|
|
|
UP_DEVICE_STATE_DISCHARGING,
|
|
|
|
|
UP_DEVICE_STATE_EMPTY,
|
|
|
|
|
UP_DEVICE_STATE_FULLY_CHARGED) = (0, 1, 2, 3, 4)
|
|
|
|
|
|
|
|
|
|
class Tests(unittest.TestCase):
|
|
|
|
|
@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', '.')
|
|
|
|
|
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')
|
|
|
|
|
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'
|
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
|
|
|
|
|
GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING|
|
|
|
|
|
GLib.LogLevelFlags.LEVEL_ERROR|
|
|
|
|
|
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()
|
|
|
|
|
del os.environ['DBUS_SESSION_BUS_ADDRESS']
|
|
|
|
|
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)
|
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()
|
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.
|
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
|
|
|
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
|
|
|
|
|
|
|
|
self.proxy = None
|
|
|
|
|
self.log = None
|
|
|
|
|
self.daemon = None
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
# on failures, print daemon log
|
2013-02-20 14:38:25 +01:00
|
|
|
if not self._outcomeForDoCleanups.success 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
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def start_daemon(self):
|
|
|
|
|
'''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()
|
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()
|
2013-02-20 14:59:56 +01:00
|
|
|
self.daemon = subprocess.Popen(['umockdev-wrapper', self.daemon_path, '-v'],
|
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
|
|
|
env=env, stdout=self.log, stderr=subprocess.STDOUT)
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
self.proxy = Gio.DBusProxy.new_sync(self.dbus,
|
|
|
|
|
Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
|
|
|
|
|
UP, '/org/freedesktop/UPower', UP, None)
|
|
|
|
|
|
|
|
|
|
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.'''
|
|
|
|
|
|
|
|
|
|
proxy = Gio.DBusProxy.new_sync(self.dbus,
|
|
|
|
|
Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
|
|
|
|
|
UP, '/org/freedesktop/UPower',
|
|
|
|
|
'org.freedesktop.DBus.Properties', None)
|
|
|
|
|
return proxy.Get('(ss)', UP, name)
|
|
|
|
|
|
|
|
|
|
def get_dbus_dev_property(self, device, name):
|
|
|
|
|
'''Get property value from an upower device D-Bus path.'''
|
|
|
|
|
|
|
|
|
|
proxy = Gio.DBusProxy.new_sync(self.dbus,
|
|
|
|
|
Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
|
|
|
|
|
UP, device, 'org.freedesktop.DBus.Properties', None)
|
|
|
|
|
return proxy.Get('(ss)', UP + '.Device', name)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# 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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
|
|
|
|
|
def test_battery_ac(self):
|
|
|
|
|
'''battery properties with and without AC'''
|
|
|
|
|
|
|
|
|
|
# without any devices we should assume AC
|
|
|
|
|
self.start_daemon()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# online AC
|
2013-02-20 14:38:25 +01:00
|
|
|
ac = self.testbed.add_device('power_supply', 'AC', None,
|
|
|
|
|
['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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'NativePath'), ac)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# offline AC
|
2013-02-20 14:38:25 +01:00
|
|
|
self.testbed.set_attribute(ac, '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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(ac_up, 'Online'), False)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# offline AC + discharging battery
|
2013-02-20 14:38:25 +01:00
|
|
|
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'], [])
|
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)
|
|
|
|
|
if devs[0] == ac_up:
|
|
|
|
|
bat0_up = devs[1]
|
|
|
|
|
else:
|
|
|
|
|
bat0_up = devs[0]
|
|
|
|
|
# we don't have any known online power device now, but still no battery
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'NativePath'), bat0)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '48000000',
|
|
|
|
|
'voltage_now', '12000000'], [])
|
|
|
|
|
|
|
|
|
|
bat1 = self.testbed.add_device('power_supply', 'BAT1', None,
|
|
|
|
|
['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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
def test_unknown_battery_status(self):
|
|
|
|
|
'''Unknown battery charge status'''
|
|
|
|
|
|
2013-02-20 14:38:25 +01:00
|
|
|
bat0 = 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'], [])
|
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()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# However, if we have an AC, we can infer
|
2013-02-20 14:38:25 +01:00
|
|
|
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()
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnBattery'), True)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2011-05-14 13:20:32 +02:00
|
|
|
def test_battery_charge(self):
|
|
|
|
|
'''battery which reports charge instead of energy
|
|
|
|
|
|
|
|
|
|
energy_* is in uWh, while charge_* is in uAh.
|
|
|
|
|
'''
|
2013-02-20 14:38:25 +01:00
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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.assertEqual(self.get_dbus_dev_property(bat0_up, 'NativePath'), bat0)
|
|
|
|
|
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-02-20 14:38:25 +01:00
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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, 'NativePath'), bat0)
|
|
|
|
|
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'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', 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), 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)
|
|
|
|
|
self.assertEqual(self.get_dbus_dev_property(bat0_up, 'NativePath'), bat0)
|
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-08-23 08:45:14 +02:00
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
2013-08-23 08:31:20 +02:00
|
|
|
self.stop_daemon()
|
|
|
|
|
|
2013-08-23 08:52:45 +02:00
|
|
|
def test_battery_temperature(self):
|
|
|
|
|
'''battery which reports temperature'''
|
|
|
|
|
|
|
|
|
|
bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
|
|
|
|
|
['type', 'Battery',
|
|
|
|
|
'present', '1',
|
|
|
|
|
'status', 'Discharging',
|
|
|
|
|
'temp', '254',
|
|
|
|
|
'energy_full', '60000000',
|
|
|
|
|
'energy_full_design', '80000000',
|
|
|
|
|
'energy_now', '1500000',
|
|
|
|
|
'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, '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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
|
|
|
|
|
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
|
|
|
def test_ups_ac(self):
|
|
|
|
|
'''UPS properties with and without AC'''
|
|
|
|
|
|
|
|
|
|
# add a charging UPS
|
2013-02-20 14:38:25 +01:00
|
|
|
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', '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]
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
|
|
|
|
# now 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,
|
|
|
|
|
['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), 2)
|
|
|
|
|
if devs[0] == ups0_up:
|
|
|
|
|
ac_up = devs[1]
|
|
|
|
|
else:
|
|
|
|
|
ac_up = devs[0]
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
|
|
|
|
|
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)
|
|
|
|
|
self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
|
|
|
|
|
self.stop_daemon()
|
|
|
|
|
|
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,
|
|
|
|
|
['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. ☢',
|
|
|
|
|
], [])
|
|
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
|
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__':
|
|
|
|
|
unittest.main()
|