So far the test cases only covered drivers which reported energy (µWh). Add
checks that the Energy* properties are correct, and add a test case for drivers
which report charge (µAh).
With nested Makefiles we can't depend on a generated file in a different
directory (breaks "make clean && make check"). Thus move the call of the Linux
integration test suite into src/Makefile.am, and only run it if we build the
Linux backend.
Implement get_{on,low}_battery() methods on HID devices for Linux. This will
treat discharging UPSes like batteries and set the "on-battery" and
"on-low-battery" properties accordingly.
This also fixes the test_ups_ac() case in the Linux integration tests.
Stop querying the global "on-battery" property when trying to guess the status
of a battery which reports as "unknown", as "on-battery" is itself defined in
terms of the states of the individual batteries. Instead, guess the state based
on whether we have any AC available; if so, we can reasonably assume
charging/discharging based on whether any AC is online. If no AC is present,
assume discharging (as we did before), but only if we have only one battery.
Stop guessing for the case where we don't have any AC device, "unknown" battery
state, and multiple batteries, as then we can't know which battery is currently
discharging.
https://bugs.freedesktop.org/show_bug.cgi?id=24371
If possible, run the tests under dbus-launch to ensure that there is a private
D-BUS session bus. This allows the tests to work in e. g. a clean package build
environment, and also avoids messing with the real user session bus.
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.
If a HID device is marked with the UPOWER_FAKE_DEVICE udev property, don't send
ioctl commands to it, but instead read status and percentage from udev
properties as well (UPOWER_FAKE_HID_CHARGING and UPOWER_FAKE_HID_PERCENTAGE).
This allows developers or a test suite to test the behaviour of UPSes without
actually having one.
More cleanly support batteries that report both energy and charge,
but do not report power_now. One battery driver in drivers/power
(bq20z75) supports reporting energy and charge natively from the
fuel gauge, but does not report power_now. The previous legacy behavior
would ignore the existence of charge and treat current_now as
being in units of power.
Signed-off-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Richard Hughes <richard@hughsie.com>
Annoyingly, the device used in the Watts Up Pro device seems to be a generic
USB->serial adaptor, which means it doesn't have a unique vendor and product
ID. If we try to probe for the WUP device, we can actually upset other devices
that are not expecing to be probed. This fixes#33846 although we actually
still need to be more strict in detecting a true WUP device.
The GUdev API was declared stable in udev release 147.
Bump the version in the configure check and drop the
G_UDEV_API_IS_SUBJECT_TO_CHANGE defines.
Signed-off-by: Richard Hughes <richard@hughsie.com>
In up_input_coldplug(), some checks are done on the input device found in order
to detect if it's a lid switch or not.
The following one is problematic :
/* convert to a bitmask */
num_bits = up_input_str_to_bitmask (contents, bitmask, sizeof (bitmask));
if (num_bits != 1) {
g_debug ("not one bitmask entry for %s", native_path);
ret = FALSE;
goto out;
}
Checking if there's only 1 bit set is wrong. It's nice if you have a x86 with
acpi using 1 input device for the lid switch but it's not always nice.
One can create input devices with gpios-keys like this:
static struct gpio_keys_button keys[] = {
{
.code = SW_LID,
.gpio = ...,
.type = EV_SW,
.desc = "Lid Switch",
},
{
.code = SW_RFKILL_ALL,
.gpio = ...,
.type = EV_SW,
.desc = "rfkill",
},
};
The resulting SW bitmap will be 9 and thus there are 2 bits sets and due to the
mentionned check, the device is ignored by upower.
As a fix, I'm checking if the number of bits is between 0 and SW_CNT
bits.
Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>
Signed-off-by: Richard Hughes <richard@hughsie.com>
Include <stdint.h> so that <linux/fs.h> can use uint64_t. Arguably a bug in the
kernel headers, but it costs us nothing to safeguard against it.
CC libupshared_la-up-device-idevice.lo
In file included from sysfs-utils.c:39:0:
/usr/include/linux/fs.h:37:2: error: expected specifier-qualifier-list before ‘uint64_t’
When a full battery starts to discharge, but reports its status as 'Unknown',
it takes a few minutes before g-p-m notices any change.
upowerd guesses the battery is fully charged as long as it has over 90% charge.
I see no reason to delay the reporting of discharging of the battery.
Let's remove this heuristic.
Signed-off-by: Richard Hughes <richard@hughsie.com>
Commmit fc7c6e003 had a thinko, UP_DAEMON_WATERLINE specifies (active
memory)/(available swap), not the other way around. So replace it with 99%
instead.
Also update the documentation of up_backend_get_used_swap() to explain what the
returned percentage actually means.
In linux backend, g_object_set was called with wrong
argument types for time-to-empty,time-to-full and percentage
properties. This patch uses explicit casts in the same way as freebsd
backend.
Signed-off-by: Mariusz Ceier <mceier@gmail.com>
pm-is-supported does all the work upower was duplicating, and it handles more
use cases than the old upower code did. No point in duplicating functionality.
Signed-off-by: Richard Hughes <richard@hughsie.com>
up_daemon_check_swap_space uses the Active: line from /proc/meminfo to
determine the amount of swap the system needs to be able to suspend. However,
because Active: includes both anonymous and file-backed pages, this greatly
overestimates the amount of swap needed. File-backed pages can be written back
to disk and so do not consume swap.
Instead, up_daemon_check_swap_space should use Active(anon): from /proc/meminfo
because only anonymous pages need to be written out to swap during a suspend.
Signed-off-by: Richard Hughes <richard@hughsie.com>
The backends [linux/freebsd/dummy] no longer require
libdevkit-power-gobject, so
- remove -I$(top_srcdir)/devkit-power-gobject from the include path
- don't link the backends against libdevkit-power-gobject but upowerd
(which unfortunately still needs it).
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>