Commit graph

57 commits

Author SHA1 Message Date
Bastien Nocera
5db1bce65f tests: Fix discharge rates in test_battery_state_guessing
up_device_battery_estimate_power() expects a charge/discharge rate of
0.5W to be significant, but the existing code yielded a rate of
-0.000240W.

Fix the units so that the amount of change in energy_now is at least
1W/s converted to µWh.
2023-04-15 12:16:19 +02:00
Bastien Nocera
b3c439ab4a linux: Fix getting properties in assertDevs()
Now that device loop is fixed, we also need to fix the D-Bus object
path for the devices themselves to match what UPower generates so
we can get its properties.

As we iterate over the expected array, the elements are the basenames
of those object paths. Reconstruct the full object paths by prepending
/org/freedesktop/UPower/devices/
2023-04-14 13:50:49 +02:00
Bastien Nocera
32e2cd5eb9 linux: Fix broken assertDevs() device loop
The test uses a generator to get the list of basenames for the devices:
names = (n.split('/')[-1] for n in devs)

Unfortunately, using that "names" varible will consume the generator,
and our array will be lost.

When passing a device dictionary, this code:
print(sorted(names))
print(sorted(names))
will yield:
['battery_hidpp_battery_0']
[]

Save the sorted array, and use that to test for properties equality.
2023-04-14 13:50:19 +02:00
Bastien Nocera
810c1214a5 linux: Test fix for warning when a duplicate device appears
Make the Bluetooth device appear first.
2023-02-28 14:14:59 +01:00
Bastien Nocera
32b0e098a1 linux: Test adding Bluetooth devices after daemon start
As is usually the case in reality, as bluez must be started for
Bluetooth devices to be able to connect.
2023-02-28 14:14:59 +01:00
Bastien Nocera
b6143527ef linux: Fix dbusmock addition of fake battery
We need to send the InterfacesAdded signal in case upower is already
started, so it can properly keep track of the interesting bluez devices.
2023-02-28 13:42:36 +01:00
Bastien Nocera
b7e406d9f9 linux: Add test for Logitech HID++/Bluetooth deduplication
This tests for the device-removed g_warning(), following the Alias
property on bluez devices, and the "Unhandled key" warnings.
2023-02-27 14:39:36 +01:00
Bastien Nocera
3bf5a095ac linux: Fix device paths in tests
add_device() doesn't need the full sysfs path if there's a parent,
otherwise this section of the path will be duplicated.
2023-02-27 14:12:39 +01:00
Bastien Nocera
b2cbf01090 linux: Test for "present" sysfs attribute handling 2023-02-21 15:19:46 +01:00
Maciej S. Szmigiero
dcb4600b33 enumerator-udev: also check for an idevice on "usb" subsystem
Commit 1550d50f ("linux: Remove "usb" subsystem match") broke detection of
some idevices, since it left just the "usbmisc" subsystem match while some
idevice / kernel combinations (at least an iPhone 11 on a 6.0 kernel) don't
present any such udev usbmisc devices.
However, they do present "usb" subsystem ones, so add this match back.

Leave idevice detection also for the "usbmisc" match since that's what the
original (known working) code before aforementioned commit did - it is
possible that it is required for some kernel / idevice combinations.
2022-10-29 15:32:04 +02:00
Bastien Nocera
b1edcc7cbb linux: Test whether BT mice get de-duplicated 2022-09-05 17:47:08 +02:00
Bastien Nocera
7f28aa5525 linux: Make BT mouse export its serial number
As a real mouse would.
2022-09-05 17:47:08 +02:00
Bastien Nocera
3265ce3ca6 linux: Make BT mice use the same address in tests
So we can use, one, the other, or both, and still see a single device.
2022-09-05 17:47:08 +02:00
Benjamin Berg
3c4f902fbd test: Add battery ID changing test for history loading/saving 2022-06-22 18:38:49 +02:00
Benjamin Berg
8817dec73f test: Fix flaky battery aggregation test
It seems that the test was still flaky, the reason for that would be
that we did not explicitly wait for the log line saying that the
aggregate state was calculated.

The only reason that it did not consistently fail appears to be that
searching for the state conflict caused messages to be skipped. That is
wrong, we should account for every "Calculating percentage" message to
ensure that upowerd and the test is in sync.
2022-06-21 13:26:39 +02:00
Benjamin Berg
8ec7362e93 battery: Add full/empty guessing based on capacity
Assuming we have some estimation for the current battery capacity (i.e.
percentage), we can infer a FULL/EMPTY state. Do so if the battery state
is unknown.

Related: #196
2022-06-21 11:16:27 +02:00
Benjamin Berg
14f06728b5 test: Add test for charging/discharging guessing based on rate
See: #196
2022-06-21 11:16:01 +02:00
Benjamin Berg
6fedd0f20a linux: Use new battery class and drop unused code
This makes the switch. There are a few behaviour changes with regard to
estimations (which hopefully got both simpler and more robust at the
same time).
2022-06-21 11:16:01 +02:00
Benjamin Berg
54e396e7ae test: Disable battery polling to make test more stable
Otherwise the fast repolling can get in-between, cause extra logging and
trigger a failure.
2022-06-15 14:09:14 +02:00
Benjamin Berg
4dac45e53a test: Test state guessing for one and two batteries
The state guessing code based on the AC state was not tested well.
Improve the test by testing both 1 and 2 batteries and checking the
reported state in more detail.
2022-06-14 17:51:06 +02:00
Benjamin Berg
a78ee60390 test: Properly wait for idle handler after uevents
The state aggregation test requires an idle handler to run, which can be
a bit unreliable as it may or may not run twice.

Force running it twice and add code to wait for it to complete. Do so
properly by waiting for the correct log messages rather than sleeping so
that everything is ordered nicely while not slowing down the test a lot.

Closes: #193
2022-06-09 12:38:34 +02:00
Benjamin Berg
c6a851d798 test: Add test for mice that have keys
These should not be detected as keyboards.
2022-06-08 12:55:59 +02:00
Benjamin Berg
1587b37707 test: Test all possible inputs for daemon state aggregation
This adds a test that checks all possible inputs for the battery state
aggregation. Not all states are actually tested in this case, as some
states may be handled through state inference and others might not be
well defined.
2022-06-07 16:07:03 +02:00
Benjamin Berg
792fc7bb1b supply: Consistently use 90% threshold to consider a battery full 2022-06-03 10:36:02 +02:00
Benjamin Berg
c330351937 test: Disable systemd v251 sysfs verification
The umockdev code to disable it by setting the variable does not
propagate through python. Set the variable here until there is a more
permament solution available.
2022-05-25 16:57:21 +02:00
Benjamin Berg
66eb9b9d7a test: Stop processes using cleanup function
Using tearDown is brittle, as an assertion will stop it from running
through completely. So move cleanup into a helper that is called via
addCleanup for logind and bluez.
2022-05-20 14:41:52 +02:00
Benjamin Berg
41bceac6ef test: Only assert daemon log is closed if daemon is started 2022-05-20 14:37:23 +02:00
Benjamin Berg
6d947c0532 test: Do not redirect helper stdout
There is no need to do so, so drop the redirection.
2022-05-20 14:37:02 +02:00
Benjamin Berg
f1c00e50c2 test: Allow daemon to take 5 seconds for shutdown
It seems like shutdown can take more than 2 seconds on some slow
systems. So increase to 5 seconds which hopefully is long enough.

Closes: #188
2022-05-20 14:35:23 +02:00
Benjamin Berg
c64b020f99 test: Turn off buffering when executing directly
It can be a bit unepxected if results are not printed immediately, so
turn off buffering. We could possibly also reopen sys.stdout, but this
is good enough in many cases.
2022-05-20 14:35:11 +02:00
Benjamin Berg
267f5ea8d3 linux: Fix exception check when on test daemon shutdown
subprocess.Popen.wait throws subprocess.TimeoutExpired not TimeoutError.

Related: #188
2022-05-19 11:45:55 +02:00
Benjamin Berg
ab08a4188f linux: Add test verifying sibling tracking cleanup works
This tests that the code to track siblings is working correctly and that
it will clean up the entries stored in the cache when a device
disappears.
2022-05-17 10:40:58 +02:00
Benjamin Berg
6db0627aaa linux: Add wacom tests 2022-05-16 16:42:30 +02:00
Benjamin Berg
76a99a7638 linux: Add helper to assert devices and properties
Just to make it a bit nicer to do assertions on devices and properties.
2022-05-16 16:40:00 +02:00
Benjamin Berg
275db91afd linux: Do not create intermediate proxy to fetch properties
There is no need for an intermediate proxy object, adding it just
results in extra overhead that is not needed.
2022-05-16 16:40:00 +02:00
Benjamin Berg
2151d7c0e4 linux: Test that line-power events don't cause battery polling
This verifies that we do not start polling the battery if we got a
spurious event related to a line-power supply.
2022-05-16 09:14:07 +00:00
Benjamin Berg
90c84ea95c linux: Ensure clean shutdown after tests
Instead of just killing upower, try to send SIGTERM for a clean
shut-down. Kill the process if it doesn't quit within two seconds, and
check that the service exits cleanly.
2022-05-12 14:42:35 +02:00
Benjamin Berg
76b4c31ee9 linux: Add non-hid parent to hidpp tests
While not needed currently, there is a discussion to ignore the "hid"
subsystem parents when searching for siblings. Add in appropriate
parents to the tests so that such a change will not result in a failure.
2022-05-12 11:16:42 +02:00
Benjamin Berg
565b3531d6 linux: Test changes after BT HID power_supply subtree move
This causes an add that we ignore, after that we should still see
updates from the device (and the add itself should trigger an update).

Verify that this works by setting the capacity to 20.
2022-05-11 10:16:50 +02:00
Benjamin Berg
3c520fb590 linux: Use OutputChecker to inspect daemon log
This also means the daemon log is stored even when succeeding, making it
a bit easier to inspect tests overall.
2022-05-10 11:06:18 +02:00
Benjamin Berg
b9bf475459 linux: Enable fatal-warnings for most tests 2022-05-10 11:06:18 +02:00
Benjamin Berg
7f846bcee6 linux: Provide temporary history directory in tests
This avoids a warning when history files need to be saved.
2022-05-10 11:06:18 +02:00
Benjamin Berg
f2da5678f3 linux: Create an empty configuration file for every test
This avoids a warning during startup, allowing enabling fatal-warnings
in more cases.
2022-05-10 11:06:18 +02:00
Benjamin Berg
5fd3c9988c linux: Always start logind during test
This avoids a warning on daemon startup and is a step towards turning on
fatal-warnings most of the time.
2022-05-10 11:06:18 +02:00
Benjamin Berg
37f8fa2699 linux: Test fast-polling stops after 5 seconds
In some cases we fast-poll for 5 seconds after a uevent. Check that this
type of fast-polling stops when appropriate.
2022-05-10 11:06:18 +02:00
Benjamin Berg
3243ff2a56 supply: Use new polling infrastructure
This means we do the fast-repoll and normal polling with the same method
(no timeout registrations within the supply code anymore).
2022-05-10 11:06:18 +02:00
Benjamin Berg
1550d50f20 linux: Remove "usb" subsystem match
The hiddev driver has been in the "usbmisc" subsystem since kernel 3.7.0
or so. As such, we can simply drop the "usb" subsystem from our matches
at this point.
2022-04-01 11:47:41 +02:00
Benjamin Berg
d113f62727 history: Delay saving history even on low power
Otherwise we flush out the data much more often than needed. With this
change, we'll also wait up to 5 seconds even on lower power. Loosing 5s
of data shouldn't be too bad, and it may prevent additional disk writes.

But, more importantly, we need to deferre writing the data to a later
main loop iteration. If we did not do this, then we have an
write-amplification scenario where the history is written at least 4
times instead of once.

Closes: #150
2022-01-27 14:48:51 +01:00
Benjamin Berg
94af9d6f3d linux: Make test compatible with older dbusmock versions
The changes from 37b6d4b039 ("linux: Fix Bluetooth tests for
python-dbusmock changes") require a not-yet-released dbusmock version.
Simply catch the error and fall back to adding the properties in order
to be compatible with both old and new dbusmock versions of the bluez
service.
2022-01-27 13:11:45 +01:00
Bastien Nocera
1fdc0824b6 lib: Implement up_client_get_devices_async() 2022-01-23 23:26:33 +01:00