From 8be1bd53d3c471b641d3e8ef24811f5305760860 Mon Sep 17 00:00:00 2001 From: teutat3s Date: Sat, 4 Jun 2022 23:45:06 +0200 Subject: [PATCH] wip: first PubSolarOS iso test using the NixOS test suite: https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests --- .drone.yml | 21 ++++++++++- flake.nix | 6 ++- tests/first-test.nix | 87 +++++++++++++++++++++++++++++++++++++++++++ tests/second-test.nix | 14 +++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 tests/first-test.nix create mode 100644 tests/second-test.nix diff --git a/.drone.yml b/.drone.yml index f54bd8f9..57a0aa1c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -103,10 +103,29 @@ steps: NIX_FLAGS: "--print-build-logs --verbose" commands: - 'echo DEBUG: Using NIX_FLAGS: $NIX_FLAGS' - - nix $$NIX_FLAGS flake check - nix $$NIX_FLAGS build ".#nixosConfigurations.PubSolarOS.config.system.build.toplevel" - nix $$NIX_FLAGS develop --command echo OK +--- +kind: pipeline +type: exec +name: Tests + +steps: + - name: "Tests" + when: + event: + - pull_request + - tag + environment: + NIX_FLAGS: "--print-build-logs --verbose" + commands: + - 'echo DEBUG: Using NIX_FLAGS: $NIX_FLAGS' + - nix $$NIX_FLAGS build ".#checks.x86_64-linux.customTestFor-PubSolarOS-firstTest" + #- nix $$NIX_FLAGS flake check + #- nix $$NIX_FLAGS develop --command echo OK + #- nix $$NIX_FLAGS develop --command bud --help + --- kind: pipeline type: docker diff --git a/flake.nix b/flake.nix index bf050b2e..b4335a8d 100644 --- a/flake.nix +++ b/flake.nix @@ -102,7 +102,11 @@ imports = [ (digga.lib.importHosts ./hosts) ]; hosts = { /* set host specific properties here */ - PubSolarOS = { }; + PubSolarOS = { + tests = [ + (import ./tests/first-test.nix { pkgs = nixos.legacyPackages.x86_64-linux; lib = nixos.lib; }) + ]; + }; }; importables = rec { profiles = digga.lib.rakeLeaves ./profiles // { diff --git a/tests/first-test.nix b/tests/first-test.nix new file mode 100644 index 00000000..251779a1 --- /dev/null +++ b/tests/first-test.nix @@ -0,0 +1,87 @@ +{ pkgs, lib, ... }: +{ + name = "firstTest"; + + nodes.test-machine = { suites ? null, ... }: { + imports = suites.iso; + + home-manager.users.pub-solar.programs.zsh.shellAliases = { + test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok"; + test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok"; + }; + + # source: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/tests/sway.nix + environment = { + # For glinfo and wayland-info: + systemPackages = with pkgs; [ mesa-demos wayland-utils alacritty ]; + # Use a fixed SWAYSOCK path (for swaymsg): + variables = { + "SWAYSOCK" = "/tmp/sway-ipc.sock"; + # TODO: Investigate if we can get hardware acceleration to work (via + # virtio-gpu and Virgil). We currently have to use the Pixman software + # renderer since the GLES2 renderer doesn't work inside the VM (even + # with WLR_RENDERER_ALLOW_SOFTWARE): + # "WLR_RENDERER_ALLOW_SOFTWARE" = "1"; + "WLR_RENDERER" = "pixman"; + }; + + # To help with OCR: + etc."xdg/foot/foot.ini".text = lib.generators.toINI { } { + main = { + font = "inconsolata:size=14"; + }; + colors = rec { + foreground = "000000"; + background = "ffffff"; + regular2 = foreground; + }; + }; + }; + + fonts.fonts = [ pkgs.inconsolata ]; + + # Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch: + virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ]; + virtualisation.cores = 4; + virtualisation.memorySize = 2048; + }; + + enableOCR = true; + + testScript = '' + import shlex + def swaymsg(command: str, succeed=True): + with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)): + (machine.succeed if succeed else machine.execute)( + f"su - pub-solar -c {shlex.quote('swaymsg -- ' + command)}" + ) + + + machine.wait_for_unit("multi-user.target") + + # To check the version: + print(machine.succeed("sway --version")) + + # Wait for Sway to complete startup: + machine.wait_for_file("/run/user/1000/wayland-1") + machine.wait_for_file("/tmp/sway-ipc.sock") + + # Start a terminal (foot) on workspace 3: + machine.wait_for_text("1") + machine.send_key("meta_l-3") + machine.sleep(3) + machine.send_key("meta_l-ret") + machine.sleep(10) + machine.send_chars("whoami\n") + machine.sleep(3) + machine.wait_for_text("pub-solar") + machine.send_chars("test-wayland\n") + machine.wait_for_file("/tmp/test-wayland-exit-ok") + print(machine.succeed("cat /tmp/test-wayland.out")) + machine.copy_from_vm("/tmp/test-wayland.out") + machine.sleep(3) + machine.screenshot("foot_wayland_info") + machine.send_key("meta_l-shift-q") + machine.wait_until_fails("pgrep foot") + ''; +} diff --git a/tests/second-test.nix b/tests/second-test.nix new file mode 100644 index 00000000..d6409820 --- /dev/null +++ b/tests/second-test.nix @@ -0,0 +1,14 @@ +{ }: +{ + name = "secondTest"; + + nodes.test-machine2 = { suites ? null, ... }: { + imports = [ + suites.iso + ]; + }; + + testScript = '' + machines[0].systemctl("is-system-running --wait") + ''; +}