-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
nixosTests/cosmic: move core logic into a dedicated script #519448
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
Open
thefossguy
wants to merge
4
commits into
NixOS:master
Choose a base branch
from
thefossguy:cosmic-test-improvement
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+529
−151
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
267d1f4
nixosTests/cosmic: move test into a dedicated directory
thefossguy f3ace50
empty-pdf: init
thefossguy 91bd21e
nixosTests/cosmic: move core testing logic into a dedicated script
thefossguy 1e52b74
nixosTests/cosmic: add test for polkit authentication
thefossguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| testName, | ||
| enableAutologin, | ||
| enableXWayland, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
| user = config.nodes.machine.users.users.alice; | ||
| logFilePath = "/home/${user.name}/${testName}"; | ||
| # Use `writeShellScriptBin` instead of `writeShellScript` so that the | ||
| # process name in the journald log appears as 'cosmicTest[$pid]' | ||
| cosmicTest = config.node.pkgs.writeShellScriptBin "cosmicTest" '' | ||
| exec ${lib.getExe config.node.pkgs.python3Minimal} ${./test-script.py} \ | ||
| --log-file-path ${logFilePath} \ | ||
| --cosmic-reader-pdf ${config.node.pkgs.empty-pdf} \ | ||
| --polkit-agent-helper-path ${config.node.pkgs.polkit.out}/lib/polkit-1/polkit-agent-helper-1 \ | ||
| --root-user-password ${user.password} \ | ||
| --ydotool-drv-store-path ${config.node.pkgs.ydotool} | ||
| ''; | ||
| cosmicTestDesktop = config.node.pkgs.makeDesktopItem { | ||
| name = "cosmicTest"; | ||
| desktopName = "COSMIC NixOS VM test (${testName})"; | ||
| exec = "cosmicTest"; | ||
| }; | ||
| cosmicTestAutostartItem = config.node.pkgs.makeAutostartItem { | ||
| name = "cosmicTest"; | ||
| package = cosmicTestDesktop; | ||
| }; | ||
| in | ||
|
|
||
| { | ||
| name = testName; | ||
|
|
||
| meta.maintainers = lib.teams.cosmic.members; | ||
|
|
||
| nodes.machine = { | ||
| imports = [ ../common/user-account.nix ]; | ||
|
|
||
| services = { | ||
| # For `cosmic-store` to be added to `environment.systemPackages` | ||
| # and for it to work correctly because Flatpak is a runtime | ||
| # dependency of `cosmic-store`. | ||
| flatpak.enable = true; | ||
|
|
||
| displayManager.cosmic-greeter.enable = true; | ||
| desktopManager.cosmic = { | ||
| enable = true; | ||
| xwayland.enable = enableXWayland; | ||
| }; | ||
| }; | ||
|
|
||
| services.displayManager.autoLogin = lib.mkIf enableAutologin { | ||
| enable = true; | ||
| user = user.name; | ||
| }; | ||
|
|
||
| users.users = { | ||
| alice.extraGroups = [ | ||
| "uinput" # for ydotoold | ||
| ]; | ||
|
|
||
| root.password = user.password; | ||
| root.hashedPasswordFile = lib.mkForce null; | ||
| }; | ||
|
|
||
| hardware.uinput.enable = true; | ||
|
|
||
| environment.systemPackages = with config.node.pkgs; [ | ||
| cosmicTest | ||
| cosmicTestAutostartItem | ||
|
|
||
| # These two packages are used to check if a window was opened | ||
| # under the COSMIC session or not. Kinda important. | ||
| # TODO: Move the check from the test module to | ||
| # `nixos/lib/test-driver/src/test_driver/machine.py` so more | ||
| # Wayland-only testing can be done using the existing testing | ||
| # infrastructure. | ||
| jq | ||
| lswt | ||
| ]; | ||
|
|
||
| # So far, all COSMIC tests launch a few GUI applications. In doing | ||
| # so, the default allocated memory to the guest of 1024M quickly | ||
| # poses a very high risk of an OOM-shutdown which is worse than an | ||
| # OOM-kill. Because now, the test failed, but not for a genuine | ||
| # reason, but an OOM-shutdown. That's an inconclusive failure | ||
| # which might possibly mask an actual failure. Not enabling | ||
| # systemd-oomd because we need said applications running for a | ||
| # few seconds. So instead, bump the allocated memory to the guest | ||
| # from 1024M to 4x; 4096M. | ||
| virtualisation.memorySize = 4096; | ||
| }; | ||
|
|
||
| testScript = | ||
| { nodes, ... }: | ||
| '' | ||
| #testName: ${testName} | ||
| import sys | ||
| '' | ||
| + ( | ||
| if enableAutologin then | ||
| '' | ||
| with subtest("cosmic-greeter initialisation"): | ||
| machine.wait_for_unit("graphical.target", timeout=120) | ||
| '' | ||
| else | ||
| '' | ||
| from time import sleep | ||
|
|
||
| machine.wait_for_unit("graphical.target", timeout=120) | ||
| machine.wait_until_succeeds("pgrep --uid ${config.nodes.machine.users.users.cosmic-greeter.name} --full cosmic-greeter", timeout=30) | ||
| # Sleep for 10 seconds for ensuring that `greetd` loads the | ||
| # password prompt for the login screen properly. | ||
| sleep(10) | ||
|
|
||
| with subtest("cosmic-session login"): | ||
| machine.send_chars("${user.password}\n", delay=0.2) | ||
| '' | ||
| ) | ||
| + '' | ||
| with subtest("xdg autostart support in cosmic"): | ||
| # When checking the status of our `cosmicTest` package with: | ||
| # `machine.wait_for_unit("app-cosmicTest@autostart.service", user="${user.name}")` | ||
| # We are immediately greeted with the error: | ||
| # ``` | ||
| # subtest: xdg autostart support in cosmic | ||
| # machine: waiting for unit app-cosmicTest@autostart.service with user alice | ||
| # machine # [ 26.497516] cosmic-comp[1352]: [EGL] 0x3008 (BAD_DISPLAY) eglCreateSync: _eglCreateSync | ||
| # machine # [ 26.511706] su[1416]: Successful su for alice by root | ||
| # machine # [ 26.528190] su[1416]: pam_unix(su:session): session opened for user alice(uid=1000) by (uid=0) | ||
| # machine # Failed to connect to user scope bus via local transport: No such file or directory | ||
| # machine # [ 26.599563] su[1416]: pam_unix(su:session): session closed for user alice | ||
| # !!! Test "xdg autostart support in cosmic" failed with error: "retrieving systemctl property "ActiveState" for unit "app-cosmicTest@autostart.service" under user "alice" failed with exit code 1" | ||
| # ``` | ||
| # Meaning, our session is extremely new and the D-Bus user | ||
| # session socket does not yet exist. Instead, lets poll for | ||
| # the log file that the test is guaranteed to write to, as | ||
| # soon as it starts. | ||
| machine.wait_for_file("${logFilePath}.log", timeout=120) | ||
|
|
||
| exit_code = 0 | ||
| try: | ||
| machine.wait_for_file("${logFilePath}.done", timeout=700) | ||
| except Exception: | ||
| exit_code = 1 | ||
|
|
||
| # The log file is created in the very beginning of the test | ||
| # script's execution. If we are here, it means that the | ||
| # `wait_for_unit`'s "guard" on the test script's autostart unit | ||
| # plus the 630 second combined timeout of other two | ||
| # `wait_for_file`s, make it extremely likely for the log file to | ||
| # be present. | ||
| machine.copy_from_machine("${logFilePath}.log") | ||
|
|
||
| machine.shutdown() | ||
|
|
||
| with open(f"{machine.out_dir}/${testName}.log") as test_log_file: | ||
| contents = test_log_file.read() | ||
| print(contents) | ||
| if any("Z [ERROR] [L:" in line for line in contents.splitlines()): | ||
| exit_code = 1 | ||
|
|
||
| sys.exit(exit_code) | ||
| ''; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.