From 773e580c04242a7fb59eda9fa0b4827cef09eb2d Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Wed, 25 Feb 2026 17:58:02 +0100 Subject: [PATCH] nixosTests.lomiri: Drop OCR to determine terminal startup Instead change the foreground colour to smth unique, and look for it on the screen. --- nixos/tests/lomiri.nix | 53 +++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/nixos/tests/lomiri.nix b/nixos/tests/lomiri.nix index 45b4b59c3103..b548288c62c6 100644 --- a/nixos/tests/lomiri.nix +++ b/nixos/tests/lomiri.nix @@ -9,7 +9,18 @@ let # In case it ever shows up in the VM, we could OCR for it instead wallpaperText = "Lorem ipsum"; - # tmpfiles setup to make OCRing on terminal output more reliable + # setup to make OCRing on terminal output more reliable + terminalTextColour = { + r = 91; + g = 113; + b = 102; + }; + terminalTextColourString = + lib: + let + toHex = component: lib.optionalString (component < 16) "0" + lib.trivial.toHexString component; + in + "#${toHex terminalTextColour.r}${toHex terminalTextColour.g}${toHex terminalTextColour.b}"; terminalOcrTmpfilesSetup = { pkgs, @@ -18,7 +29,7 @@ let }: let white = "255, 255, 255"; - black = "0, 0, 0"; + foreground = "${toString terminalTextColour.r}, ${toString terminalTextColour.g}, ${toString terminalTextColour.b}"; colorSection = color: { Color = color; Bold = true; @@ -27,9 +38,9 @@ let terminalColors = pkgs.writeText "customized.colorscheme" ( lib.generators.toINI { } { Background = colorSection white; - Foreground = colorSection black; - Color2 = colorSection black; - Color2Intense = colorSection black; + Foreground = colorSection foreground; + Color2 = colorSection foreground; + Color2Intense = colorSection foreground; } ); terminalConfig = pkgs.writeText "terminal.ubports.conf" ( @@ -75,7 +86,7 @@ let }; }; - sharedTestFunctions = '' + sharedTestFunctions = lib: '' from collections.abc import Callable import tempfile import subprocess @@ -120,6 +131,17 @@ let ) return check_for_color_continued_presence_retry + def ensure_terminal_running() -> None: + """ + Ensure that lomiri-terminal-app has finished starting up. + """ + + terminalTextColor: str = "${terminalTextColourString lib}" + with machine.nested("Waiting for the screen to have terminalTextColor {} on it:".format(terminalTextColor)): + retry(check_for_color(terminalTextColor)) + with machine.nested("Ensuring terminalTextColor {} stays present on the screen:".format(terminalTextColor)): + retry(fn=check_for_color_continued_presence(terminalTextColor), timeout_seconds=5) + def ensure_lomiri_running() -> None: """ Ensure that Lomiri has finished starting up. @@ -183,7 +205,6 @@ let # Using the keybind has a chance of instantly closing the menu again? Just click the button mouse_click(15, 15) - ''; makeIndicatorTest = @@ -237,7 +258,7 @@ let testScript = { nodes, ... }: - sharedTestFunctions + (sharedTestFunctions lib) + '' start_all() machine.wait_for_unit("multi-user.target") @@ -330,7 +351,7 @@ in testScript = { nodes, ... }: - sharedTestFunctions + (sharedTestFunctions lib) + '' start_all() machine.wait_for_unit("multi-user.target") @@ -451,7 +472,7 @@ in testScript = { nodes, ... }: - sharedTestFunctions + (sharedTestFunctions lib) + '' start_all() machine.wait_for_unit("multi-user.target") @@ -463,7 +484,7 @@ in # Working terminal keybind is good with subtest("terminal keybind works"): machine.send_key("ctrl-alt-t") - wait_for_text(r"(${user}|machine)") + ensure_terminal_running() machine.screenshot("terminal_opens") machine.send_key("alt-f4") @@ -474,7 +495,7 @@ in # Just try the terminal again, we know that it should work machine.send_chars("Terminal\n") - wait_for_text(r"(${user}|machine)") + ensure_terminal_running() machine.send_key("alt-f4") # We want support for X11 apps @@ -598,7 +619,7 @@ in testScript = { nodes, ... }: - sharedTestFunctions + (sharedTestFunctions lib) + '' start_all() machine.wait_for_unit("multi-user.target") @@ -610,7 +631,7 @@ in # Working terminal keybind is good with subtest("terminal keybind works"): machine.send_key("ctrl-alt-t") - wait_for_text(r"(${user}|machine)") + ensure_terminal_running() machine.screenshot("terminal_opens") # for the LSS lomiri-content-hub test to work reliably, we need to kick off peer collecting @@ -744,7 +765,7 @@ in testScript = { nodes, ... }: - sharedTestFunctions + (sharedTestFunctions lib) + '' start_all() machine.wait_for_unit("multi-user.target") @@ -773,7 +794,7 @@ in # Lomiri in desktop mode should use the correct keymap with subtest("lomiri session keymap works"): machine.send_key("ctrl-alt-t") - wait_for_text(r"(${user}|machine)") + ensure_terminal_running() machine.screenshot("terminal_opens") machine.send_chars("touch ${pwInput}\n")