Skip to content

A test case for randomly generated input events (New) #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jul 25, 2025

Conversation

GabrielChenCC
Copy link
Contributor

@GabrielChenCC GabrielChenCC commented Mar 6, 2025

Description

We discovered this problem during last year's testing: https://bugs.launchpad.net/sutton/+bug/2045249 . We found this bug by manually coordinating the random use of the mouse and keyboard during screen rotation. Now I use this C code to implement the random automatic behavior of the mouse and keyboard. It can be used in conjunction with another PR #1576 submitted by my colleague Hanhsuan to complete the random movement of the mouse and keyboard at different resolutions while rotating the screen.

Note: The keyboard and mouse random C code needs to execute via 'sudo'. We have also tried to use Python's uinput to avoid using sudo permissions, but by looking up the document https://python-evdev.readthedocs.io/en/latest/tutorial.html#injecting-input, Python cannot avoid sudo either, and C code is available for the rotation test case without introducing external dependence. So I choose C code, it is more suitable for the rotation test case.

Resolved issues

https://warthogs.atlassian.net/browse/OEMQA-5102
https://bugs.launchpad.net/sutton/+bug/2045249

Documentation

Tests

$ providers/base/bin/mouse_keyboard.py
The demo file works as design

Run the test case mouse_keyboard.py without any errors

@GabrielChenCC GabrielChenCC changed the title A test case for randomly generate input events A test case for randomly generate input events (New) Mar 6, 2025
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

Attention: Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.

Project coverage is 50.39%. Comparing base (7817ae2) to head (f43ebab).
Report is 181 commits behind head on main.

Files with missing lines Patch % Lines
providers/base/bin/mouse_keyboard.py 98.14% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1775      +/-   ##
==========================================
+ Coverage   49.63%   50.39%   +0.75%     
==========================================
  Files         377      382       +5     
  Lines       40630    40960     +330     
  Branches     6830     7497     +667     
==========================================
+ Hits        20168    20641     +473     
+ Misses      19740    19588     -152     
- Partials      722      731       +9     
Flag Coverage Δ
checkbox-ng 70.70% <ø> (+0.81%) ⬆️
provider-base 26.27% <98.14%> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@pieqq pieqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some comments in the code of the script.

Other than that, please also update the packaging for the snaps and the debian package recipes to pull python3-evdev. Hopefully this works on Xenial (I just checked and there is a python3-evdev package there, albeit a very old one, so fingers crossed!)

@pieqq
Copy link
Collaborator

pieqq commented May 6, 2025

(side comment: I didn't really understand the connection between what's explained in the description about gnome-randr and this script, could you provide more information?)

@GabrielChenCC
Copy link
Contributor Author

(side comment: I didn't really understand the connection between what's explained in the description about gnome-randr and this script, could you provide more information?)

Hi Pierre, I have updated the description and all story text. I guess it could fix your concern. Thanks.

Copy link
Collaborator

@pieqq pieqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and the python3-evdev package should be available everywhere we need it, so it's good. That said, you need to add the packaging information for Debian and Snaps (for all the series. See for instance the snapcraft.yaml for series24; you would probably need to add this dependency in the stage-packages section of the base provider).

I saw that in 7031c05 you added this for Debian, but then you removed it in b9b3606. Not sure why?

Other than that, I tried running the script with $ ./mouse_keyboard.py on my 24.04 laptop. Out of 5 runs, it failed twice with the following error:

Traceback (most recent call last):
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 159, in <module>
    main()
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 150, in main
    rand_mouse_moves(device)  # Simulate mouse movement
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 134, in rand_mouse_moves
    rest_x = x % steps
             ~~^~~~~~~
ZeroDivisionError: integer modulo by zero

Can you look into that?

@GabrielChenCC
Copy link
Contributor Author

I checked and the python3-evdev package should be available everywhere we need it, so it's good. That said, you need to add the packaging information for Debian and Snaps (for all the series. See for instance the snapcraft.yaml for series24; you would probably need to add this dependency in the stage-packages section of the base provider).

I saw that in 7031c05 you added this for Debian, but then you removed it in b9b3606. Not sure why?
I saw this dependency had been introduced by other test cases before, so It was not needed there.

Other than that, I tried running the script with $ ./mouse_keyboard.py on my 24.04 laptop. Out of 5 runs, it failed twice with the following error:

Traceback (most recent call last):
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 159, in <module>
    main()
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 150, in main
    rand_mouse_moves(device)  # Simulate mouse movement
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pieq/dev/work/checkbox/providers/base/bin/./mouse_keyboard.py", line 134, in rand_mouse_moves
    rest_x = x % steps
             ~~^~~~~~~
ZeroDivisionError: integer modulo by zero

Can you look into that?
Fixed in the latest commit.

@GabrielChenCC GabrielChenCC requested a review from pieqq July 11, 2025 07:47
@GabrielChenCC
Copy link
Contributor Author

52ca2d0 add the package;
f43ebab remove the package name in wrong file.
The above two commits can fix the compilation failure and the compilation problem of Debian package. For snap packages, python3-evdev has been added to each series a long time ago. So I think this PR coud be now complete. Thanks.

@zongminl zongminl changed the title A test case for randomly generate input events (New) A test case for randomly generated input events (New) Jul 25, 2025
Copy link
Collaborator

@pieqq pieqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pieqq pieqq merged commit 3d69695 into canonical:main Jul 25, 2025
53 of 55 checks passed
stanley31huang pushed a commit that referenced this pull request Aug 14, 2025
Use python3-evdev to generate random input events (mouse movements, keyboard typing) in order to detect potential issues during screen rotation testing.

Fix OEMQA-5102
Fix lp:2045249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants