Spotted when running regression tests in KVM. There, initializing a HID device
causes a "could not initialize libusb: -99" warning, but the device is created
nevertheless. Do not crash in _finalize() by trying to call libusb_exit(NULL).
For hardware that has no rate data we use the differences in charge over a time
period to work out the effective rate. Using linear regression this estimation
is much more realistic.
To do this, introduce a simple circular buffer and use an index to calculate
the rate on each update.
Signed-off-by: Richard Hughes <richard@hughsie.com>
Under Linux, regardless of the exit code of /usr/bin/pm-is-supported, it will
always set CanSuspend and CanHibernate to true due to a logic error in
up_backend_supports_sleep_state in src/linux/up-backend.c: The 'ret' variable
is re-used for the return code without being re-initialized to false after the
call to g_spawn_command_line_sync.
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Files might not be there, or in the case of cross-compilation, they most
definitely won't be there (and if they are, they are not the ones you
should be looking for). Instead use the autoconf-defined $host variable to
identify for what system we're building for.
Signed-off-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
Signed-off-by: Richard Hughes <richard@hughsie.com>
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).
This allows session power managers to do different actions depending on whether the user
is suspending or hibernating. This allows the session policy agent to poke other things
(for instance, the screensaver) even if another process initiated the sleep.
This is based on a patch from Phillip Susi <psusi@cfl.rr.com>, many thanks.
In restricted environments such as package builds we do not have a system D-BUS
running. In that case, don't just fail, but use the recently introduced
up_daemon_set_bus_type() to run tests on the session D-BUS instead. Run
up-self-tests under dbus-launch for this if available.
Skip tests which need polkit if there is no system D-BUS, as we can't sensibly
run this on the session bus.
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.
The daemon test in up-self-test instantiates an UpDaemon object, which creates
an UpConfig object. Unlike UpDaemon itself, up_config_new() did not check for
$UPOWER_CONF_FILE_NAME to find the configuration file name.
This had the effect that a make check/distcheck run would always try to use the
system wide configuration file, and fail if --sysconfdir wasn't specified
appropriately.
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.