From 6ecb9a352f046013b8d81053678017705a150559 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Wed, 19 May 2021 14:22:52 +0200 Subject: nixos/tests/vscodium-wayland: init --- nixos/tests/common/wayland-cage.nix | 14 ++++++++++ nixos/tests/vscodium-wayland.nix | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 nixos/tests/common/wayland-cage.nix create mode 100644 nixos/tests/vscodium-wayland.nix (limited to 'nixos') diff --git a/nixos/tests/common/wayland-cage.nix b/nixos/tests/common/wayland-cage.nix new file mode 100644 index 0000000000000..55aeb858d7a42 --- /dev/null +++ b/nixos/tests/common/wayland-cage.nix @@ -0,0 +1,14 @@ +{ ... }: + +{ + imports = [ ./user-account.nix ]; + services.cage = { + enable = true; + user = "alice"; + }; + + virtualisation = { + memorySize = 1024; + qemu.options = [ "-vga virtio" ]; + }; +} diff --git a/nixos/tests/vscodium-wayland.nix b/nixos/tests/vscodium-wayland.nix new file mode 100644 index 0000000000000..1321c8b98274b --- /dev/null +++ b/nixos/tests/vscodium-wayland.nix @@ -0,0 +1,54 @@ +import ./make-test-python.nix ({ pkgs, ...} : + +{ + name = "vscodium-wayland"; + meta = with pkgs.lib.maintainers; { + maintainers = [ synthetica ]; + }; + + machine = { ... }: + + { + imports = [ + ./common/wayland-cage.nix + ]; + + services.cage.program = '' + ${pkgs.vscodium}/bin/codium \ + --enable-features=UseOzonePlatform \ + --ozone-platform=wayland + ''; + + fonts.fonts = with pkgs; [ + dejavu_fonts + ]; + }; + + enableOCR = true; + + testScript = { nodes, ... }: '' + start_all() + machine.wait_for_unit('graphical.target') + machine.wait_until_succeeds('pgrep -x codium') + + machine.wait_for_text('VSCodium') + machine.screenshot('start_screen') + + test_string = 'testfile' + + machine.send_key('ctrl-n') + machine.wait_for_text('Untitled') + machine.screenshot('empty_editor') + + machine.send_chars(test_string) + machine.wait_for_text(test_string) + machine.screenshot('editor') + + machine.send_key('ctrl-s') + machine.wait_for_text('Save') + machine.screenshot('save_window') + + machine.send_key('ret') + machine.wait_for_file(f'/home/alice/{test_string}') + ''; +}) -- cgit 1.4.1 From 7ed2f6e55d9b145169b9e2c020daceb15996c3a2 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Fri, 19 Nov 2021 21:21:20 +0100 Subject: nixos/tests/vscodium{,-wayland}: merge tests --- nixos/tests/all-tests.nix | 2 +- nixos/tests/vscodium-wayland.nix | 54 ------------------------ nixos/tests/vscodium.nix | 88 +++++++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 92 deletions(-) delete mode 100644 nixos/tests/vscodium-wayland.nix (limited to 'nixos') diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index cd13183ed0a32..b8219416dc42a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -489,7 +489,7 @@ in victoriametrics = handleTest ./victoriametrics.nix {}; vikunja = handleTest ./vikunja.nix {}; virtualbox = handleTestOn ["x86_64-linux"] ./virtualbox.nix {}; - vscodium = handleTest ./vscodium.nix {}; + vscodium = discoverTests (import ./vscodium.nix); wasabibackend = handleTest ./wasabibackend.nix {}; wiki-js = handleTest ./wiki-js.nix {}; wireguard = handleTest ./wireguard {}; diff --git a/nixos/tests/vscodium-wayland.nix b/nixos/tests/vscodium-wayland.nix deleted file mode 100644 index 1321c8b98274b..0000000000000 --- a/nixos/tests/vscodium-wayland.nix +++ /dev/null @@ -1,54 +0,0 @@ -import ./make-test-python.nix ({ pkgs, ...} : - -{ - name = "vscodium-wayland"; - meta = with pkgs.lib.maintainers; { - maintainers = [ synthetica ]; - }; - - machine = { ... }: - - { - imports = [ - ./common/wayland-cage.nix - ]; - - services.cage.program = '' - ${pkgs.vscodium}/bin/codium \ - --enable-features=UseOzonePlatform \ - --ozone-platform=wayland - ''; - - fonts.fonts = with pkgs; [ - dejavu_fonts - ]; - }; - - enableOCR = true; - - testScript = { nodes, ... }: '' - start_all() - machine.wait_for_unit('graphical.target') - machine.wait_until_succeeds('pgrep -x codium') - - machine.wait_for_text('VSCodium') - machine.screenshot('start_screen') - - test_string = 'testfile' - - machine.send_key('ctrl-n') - machine.wait_for_text('Untitled') - machine.screenshot('empty_editor') - - machine.send_chars(test_string) - machine.wait_for_text(test_string) - machine.screenshot('editor') - - machine.send_key('ctrl-s') - machine.wait_for_text('Save') - machine.screenshot('save_window') - - machine.send_key('ret') - machine.wait_for_file(f'/home/alice/{test_string}') - ''; -}) diff --git a/nixos/tests/vscodium.nix b/nixos/tests/vscodium.nix index 033090aa0e3d1..e217c1ec80f9e 100644 --- a/nixos/tests/vscodium.nix +++ b/nixos/tests/vscodium.nix @@ -1,47 +1,61 @@ -import ./make-test-python.nix ({ pkgs, ...} : - -{ - name = "vscodium"; - meta = with pkgs.lib.maintainers; { - maintainers = [ turion ]; +let + tests = { + vscodium-wayland = { pkgs, ... }: { + imports = [ ./common/wayland-cage.nix ]; + + services.cage.program = '' + ${pkgs.vscodium}/bin/codium \ + --enable-features=UseOzonePlatform \ + --ozone-platform=wayland + ''; + + fonts.fonts = with pkgs; [ dejavu_fonts ]; + }; + vscodium-xorg = { pkgs, ... }: { + imports = [ ./common/user-account.nix ./common/x11.nix ]; + + virtualisation.memorySize = 2047; + services.xserver.enable = true; + services.xserver.displayManager.sessionCommands = '' + ${pkgs.vscodium}/bin/codium + ''; + test-support.displayManager.auto.user = "alice"; + }; }; - machine = { ... }: - - { - imports = [ - ./common/user-account.nix - ./common/x11.nix - ]; + mkTest = name: machine: + import ./make-test-python.nix ({ pkgs, ... }: { + inherit name machine; + meta = with pkgs.lib.maintainers; { + maintainers = [ synthetica turion ]; + }; + enableOCR = true; + testScript = '' + start_all() - virtualisation.memorySize = 2047; - services.xserver.enable = true; - test-support.displayManager.auto.user = "alice"; - environment.systemPackages = with pkgs; [ - vscodium - ]; - }; + machine.wait_for_unit('graphical.target') + machine.wait_until_succeeds('pgrep -x codium') - enableOCR = true; + machine.wait_for_text('VSCodium') + machine.screenshot('start_screen') - testScript = { nodes, ... }: '' - # Start up X - start_all() - machine.wait_for_x() + test_string = 'testfile' - # Start VSCodium with a file that doesn't exist yet - machine.fail("ls /home/alice/foo.txt") - machine.succeed("su - alice -c 'codium foo.txt' >&2 &") + machine.send_key('ctrl-n') + machine.wait_for_text('Untitled') + machine.screenshot('empty_editor') - # Wait for the window to appear - machine.wait_for_text("VSCodium") + machine.send_chars(test_string) + machine.wait_for_text(test_string) + machine.screenshot('editor') - # Save file - machine.send_key("ctrl-s") + machine.send_key('ctrl-s') + machine.wait_for_text('Save') + machine.screenshot('save_window') - # Wait until the file has been saved - machine.wait_for_file("/home/alice/foo.txt") + machine.send_key('ret') + machine.wait_for_file(f'/home/alice/{test_string}') + ''; + }); - machine.screenshot("VSCodium") - ''; -}) +in builtins.mapAttrs (k: v: mkTest k v { }) tests -- cgit 1.4.1 From a8f693ed48e64fd5d4b6ae2304962e387227bbd4 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Fri, 19 Nov 2021 22:28:32 +0100 Subject: test-driver.py: fix weird non-pythonism --- nixos/lib/test-driver/test-driver.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'nixos') diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index a7c0484060f2f..4b9da55cc273d 100755 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -1183,9 +1183,7 @@ class Driver: serial_stdout_on=self.serial_stdout_on, Machine=Machine, # for typing ) - machine_symbols = { - m.name: self.machines[idx] for idx, m in enumerate(self.machines) - } + machine_symbols = {m.name: m for m in self.machines} vlan_symbols = { f"vlan{v.nr}": self.vlans[idx] for idx, v in enumerate(self.vlans) } -- cgit 1.4.1 From 9e71014edecba9d9c78531ebc2861e28c931ff6f Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Fri, 19 Nov 2021 23:02:30 +0100 Subject: test-driver.py: always export single machine as 'machine' --- nixos/lib/test-driver/test-driver.py | 4 ++++ nixos/lib/testing-python.nix | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index 4b9da55cc273d..e415993174f86 100755 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -1184,6 +1184,10 @@ class Driver: Machine=Machine, # for typing ) machine_symbols = {m.name: m for m in self.machines} + # If there's exactly one machine, make it available under the name + # "machine", even if it's not called that. + if len(self.machines) == 1: + (machine_symbols["machine"],) = self.machines vlan_symbols = { f"vlan{v.nr}": self.vlans[idx] for idx, v in enumerate(self.vlans) } diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index cce017a6441db..4306d102b2d64 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -134,7 +134,9 @@ rec { vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes); vms = map (m: m.config.system.build.vm) (lib.attrValues nodes); - nodeHostNames = map (c: c.config.system.name) (lib.attrValues nodes); + nodeHostNames = let + nodesList = map (c: c.config.system.name) (lib.attrValues nodes); + in nodesList ++ lib.optional (lib.length nodesList == 1) "machine"; # TODO: This is an implementation error and needs fixing # the testing famework cannot legitimately restrict hostnames further -- cgit 1.4.1 From 2a04ae8b125285ed980722614e75e220ee9847c8 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Fri, 19 Nov 2021 23:04:26 +0100 Subject: nixosTests.vscodium: rename machines --- nixos/tests/vscodium.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'nixos') diff --git a/nixos/tests/vscodium.nix b/nixos/tests/vscodium.nix index e217c1ec80f9e..565296a5a738a 100644 --- a/nixos/tests/vscodium.nix +++ b/nixos/tests/vscodium.nix @@ -1,6 +1,6 @@ let tests = { - vscodium-wayland = { pkgs, ... }: { + wayland = { pkgs, ... }: { imports = [ ./common/wayland-cage.nix ]; services.cage.program = '' @@ -11,7 +11,7 @@ let fonts.fonts = with pkgs; [ dejavu_fonts ]; }; - vscodium-xorg = { pkgs, ... }: { + xorg = { pkgs, ... }: { imports = [ ./common/user-account.nix ./common/x11.nix ]; virtualisation.memorySize = 2047; @@ -25,7 +25,10 @@ let mkTest = name: machine: import ./make-test-python.nix ({ pkgs, ... }: { - inherit name machine; + inherit name; + + nodes = { "${name}" = machine; }; + meta = with pkgs.lib.maintainers; { maintainers = [ synthetica turion ]; }; -- cgit 1.4.1 From 7201052de20144b11c4ef1eec7c29cb562257cb3 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Fri, 19 Nov 2021 23:04:53 +0100 Subject: nixosTests.vscodium: wait for different text --- nixos/tests/vscodium.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/tests/vscodium.nix b/nixos/tests/vscodium.nix index 565296a5a738a..a572181b88e6e 100644 --- a/nixos/tests/vscodium.nix +++ b/nixos/tests/vscodium.nix @@ -39,7 +39,7 @@ let machine.wait_for_unit('graphical.target') machine.wait_until_succeeds('pgrep -x codium') - machine.wait_for_text('VSCodium') + machine.wait_for_text('File') machine.screenshot('start_screen') test_string = 'testfile' -- cgit 1.4.1 From 1334a62539d86d9bcf43c286568c20227615ce90 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Sat, 20 Nov 2021 01:37:08 +0100 Subject: test-driver.py: directly import pathlib.Path --- nixos/lib/test-driver/test-driver.py | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'nixos') diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py index e415993174f86..643446f313e3a 100755 --- a/nixos/lib/test-driver/test-driver.py +++ b/nixos/lib/test-driver/test-driver.py @@ -4,6 +4,7 @@ from queue import Queue, Empty from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List, Iterable from xml.sax.saxutils import XMLGenerator from colorama import Style +from pathlib import Path import queue import io import threading @@ -11,7 +12,6 @@ import argparse import base64 import codecs import os -import pathlib import ptpython.repl import pty import re @@ -239,8 +239,8 @@ class StartCommand: def cmd( self, - monitor_socket_path: pathlib.Path, - shell_socket_path: pathlib.Path, + monitor_socket_path: Path, + shell_socket_path: Path, allow_reboot: bool = False, # TODO: unused, legacy? ) -> str: display_opts = "" @@ -272,8 +272,8 @@ class StartCommand: @staticmethod def build_environment( - state_dir: pathlib.Path, - shared_dir: pathlib.Path, + state_dir: Path, + shared_dir: Path, ) -> dict: # We make a copy to not update the current environment env = dict(os.environ) @@ -288,10 +288,10 @@ class StartCommand: def run( self, - state_dir: pathlib.Path, - shared_dir: pathlib.Path, - monitor_socket_path: pathlib.Path, - shell_socket_path: pathlib.Path, + state_dir: Path, + shared_dir: Path, + monitor_socket_path: Path, + shell_socket_path: Path, ) -> subprocess.Popen: return subprocess.Popen( self.cmd(monitor_socket_path, shell_socket_path), @@ -334,7 +334,7 @@ class LegacyStartCommand(StartCommand): self, netBackendArgs: Optional[str] = None, netFrontendArgs: Optional[str] = None, - hda: Optional[Tuple[pathlib.Path, str]] = None, + hda: Optional[Tuple[Path, str]] = None, cdrom: Optional[str] = None, usb: Optional[str] = None, bios: Optional[str] = None, @@ -394,11 +394,11 @@ class Machine: the machine lifecycle with the help of a start script / command.""" name: str - tmp_dir: pathlib.Path - shared_dir: pathlib.Path - state_dir: pathlib.Path - monitor_path: pathlib.Path - shell_path: pathlib.Path + tmp_dir: Path + shared_dir: Path + state_dir: Path + monitor_path: Path + shell_path: Path start_command: StartCommand keep_vm_state: bool @@ -421,7 +421,7 @@ class Machine: def __init__( self, - tmp_dir: pathlib.Path, + tmp_dir: Path, start_command: StartCommand, name: str = "machine", keep_vm_state: bool = False, @@ -463,7 +463,7 @@ class Machine: hda = None if args.get("hda"): hda_arg: str = args.get("hda", "") - hda_arg_path: pathlib.Path = pathlib.Path(hda_arg) + hda_arg_path: Path = Path(hda_arg) hda = (hda_arg_path, args.get("hdaInterface", "")) return LegacyStartCommand( netBackendArgs=args.get("netBackendArgs"), @@ -814,12 +814,12 @@ class Machine: """Copy a file from the host into the guest via the `shared_dir` shared among all the VMs (using a temporary directory). """ - host_src = pathlib.Path(source) - vm_target = pathlib.Path(target) + host_src = Path(source) + vm_target = Path(target) with tempfile.TemporaryDirectory(dir=self.shared_dir) as shared_td: - shared_temp = pathlib.Path(shared_td) + shared_temp = Path(shared_td) host_intermediate = shared_temp / host_src.name - vm_shared_temp = pathlib.Path("/tmp/shared") / shared_temp.name + vm_shared_temp = Path("/tmp/shared") / shared_temp.name vm_intermediate = vm_shared_temp / host_src.name self.succeed(make_command(["mkdir", "-p", vm_shared_temp])) @@ -836,11 +836,11 @@ class Machine: all the VMs (using a temporary directory). """ # Compute the source, target, and intermediate shared file names - out_dir = pathlib.Path(os.environ.get("out", os.getcwd())) - vm_src = pathlib.Path(source) + out_dir = Path(os.environ.get("out", os.getcwd())) + vm_src = Path(source) with tempfile.TemporaryDirectory(dir=self.shared_dir) as shared_td: - shared_temp = pathlib.Path(shared_td) - vm_shared_temp = pathlib.Path("/tmp/shared") / shared_temp.name + shared_temp = Path(shared_td) + vm_shared_temp = Path("/tmp/shared") / shared_temp.name vm_intermediate = vm_shared_temp / vm_src.name intermediate = shared_temp / vm_src.name # Copy the file to the shared directory inside VM @@ -911,12 +911,12 @@ class Machine: self.log("starting vm") - def clear(path: pathlib.Path) -> pathlib.Path: + def clear(path: Path) -> Path: if path.exists(): path.unlink() return path - def create_socket(path: pathlib.Path) -> socket.socket: + def create_socket(path: Path) -> socket.socket: s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM) s.bind(str(path)) s.listen(1) @@ -1061,7 +1061,7 @@ class VLan: """ nr: int - socket_dir: pathlib.Path + socket_dir: Path process: subprocess.Popen pid: int @@ -1070,7 +1070,7 @@ class VLan: def __repr__(self) -> str: return f"" - def __init__(self, nr: int, tmp_dir: pathlib.Path): + def __init__(self, nr: int, tmp_dir: Path): self.nr = nr self.socket_dir = tmp_dir / f"vde{self.nr}.ctl" @@ -1123,7 +1123,7 @@ class Driver: ): self.tests = tests - tmp_dir = pathlib.Path(os.environ.get("TMPDIR", tempfile.gettempdir())) + tmp_dir = Path(os.environ.get("TMPDIR", tempfile.gettempdir())) tmp_dir.mkdir(mode=0o700, exist_ok=True) with rootlog.nested("start all VLans"): @@ -1232,7 +1232,7 @@ class Driver: "Using legacy create_machine(), please instantiate the" "Machine class directly, instead" ) - tmp_dir = pathlib.Path(os.environ.get("TMPDIR", tempfile.gettempdir())) + tmp_dir = Path(os.environ.get("TMPDIR", tempfile.gettempdir())) tmp_dir.mkdir(mode=0o700, exist_ok=True) if args.get("startCommand"): @@ -1318,7 +1318,7 @@ if __name__ == "__main__": action=EnvDefault, envvar="testScript", help="the test script to run", - type=pathlib.Path, + type=Path, ) args = arg_parser.parse_args() -- cgit 1.4.1 From 6b9977942adb40518d74eead610d5e92b7067863 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Sat, 20 Nov 2021 11:26:30 +0100 Subject: nixosTests.vscodium: add comments --- nixos/tests/vscodium.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/tests/vscodium.nix b/nixos/tests/vscodium.nix index a572181b88e6e..43a0d61c856f5 100644 --- a/nixos/tests/vscodium.nix +++ b/nixos/tests/vscodium.nix @@ -39,24 +39,29 @@ let machine.wait_for_unit('graphical.target') machine.wait_until_succeeds('pgrep -x codium') + # Wait until vscodium is visible. "File" is in the menu bar. machine.wait_for_text('File') machine.screenshot('start_screen') test_string = 'testfile' + # Create a new file machine.send_key('ctrl-n') machine.wait_for_text('Untitled') machine.screenshot('empty_editor') + # Type a string machine.send_chars(test_string) machine.wait_for_text(test_string) machine.screenshot('editor') + # Save the file machine.send_key('ctrl-s') machine.wait_for_text('Save') machine.screenshot('save_window') - machine.send_key('ret') + + # (the default filename is the first line of the file) machine.wait_for_file(f'/home/alice/{test_string}') ''; }); -- cgit 1.4.1