From 9888b30924db834a10bba1136a832229d91b45ec Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Wed, 6 Nov 2019 21:50:23 -0500 Subject: [PATCH 1/2] nixosTests.gnome3: port to python --- nixos/tests/gnome3.nix | 64 +++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/nixos/tests/gnome3.nix b/nixos/tests/gnome3.nix index ab363efb6a1..37e4f1680b7 100644 --- a/nixos/tests/gnome3.nix +++ b/nixos/tests/gnome3.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +import ./make-test-python.nix ({ pkgs, ...} : { name = "gnome3"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = pkgs.gnome3.maintainers; @@ -24,41 +24,53 @@ import ./make-test.nix ({ pkgs, ...} : { virtualisation.memorySize = 1024; }; - testScript = let + testScript = { nodes, ... }: let # Keep line widths somewhat managable - bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"; + user = nodes.machine.config.users.users.alice; + uid = toString user.uid; + bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus"; gdbus = "${bus} gdbus"; + su = command: "su - ${user.name} -c '${command}'"; + # Call javascript in gnome shell, returns a tuple (success, output), where # `success` is true if the dbus call was successful and output is what the # javascript evaluates to. eval = "call --session -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval"; + # False when startup is done - startingUp = "${gdbus} ${eval} Main.layoutManager._startingUp"; + startingUp = su "${gdbus} ${eval} Main.layoutManager._startingUp"; + + # Start gnome-terminal + gnomeTerminalCommand = su "${bus} gnome-terminal"; + # Hopefully gnome-terminal's wm class - wmClass = "${gdbus} ${eval} global.display.focus_window.wm_class"; + wmClass = su "${gdbus} ${eval} global.display.focus_window.wm_class"; in '' - # wait for gdm to start - $machine->waitForUnit("display-manager.service"); + with subtest("Login to GNOME with GDM"): + # wait for gdm to start + machine.wait_for_unit("display-manager.service") + # wait for alice to be logged in + machine.wait_for_unit("default.target", "${user.name}") + # check that logging in has given the user ownership of devices + assert "alice" in machine.succeed("getfacl -p /dev/snd/timer") - # wait for alice to be logged in - $machine->waitForUnit("default.target","alice"); + with subtest("Wait for GNOME Shell"): + # wait for the wayland server + machine.wait_for_file("/run/user/${uid}/wayland-0") + # correct output should be (true, 'false') + machine.wait_until_succeeds( + "${startingUp} | grep -q 'true,..false'" + ) - # Check that logging in has given the user ownership of devices. - $machine->succeed("getfacl -p /dev/snd/timer | grep -q alice"); - - # Wait for the wayland server - $machine->waitForFile("/run/user/1000/wayland-0"); - - # Wait for gnome shell, correct output should be "(true, 'false')" - $machine->waitUntilSucceeds("su - alice -c '${startingUp} | grep -q true,..false'"); - - # open a terminal - $machine->succeed("su - alice -c '${bus} gnome-terminal'"); - # and check it's there - $machine->waitUntilSucceeds("su - alice -c '${wmClass} | grep -q gnome-terminal-server'"); - - # wait to get a nice screenshot - $machine->sleep(20); - $machine->screenshot("screen"); + with subtest("Open Gnome Terminal"): + machine.succeed( + "${gnomeTerminalCommand}" + ) + # correct output should be (true, '"gnome-terminal-server"') + machine.wait_until_succeeds( + "${wmClass} | grep -q 'gnome-terminal-server'" + ) + machine.sleep(20) + machine.screenshot("screen") ''; }) From 7651fcfe48c79c3bff7cfcc2063b54abf5d7fc1c Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Thu, 30 Jan 2020 06:14:22 -0500 Subject: [PATCH 2/2] nixosTests.gnome3: wait_for_wayland at login This prevents the default.target check from just failing. Blaming it on using systemctl in wait_for_unit (and it's particularly buggy for user units). --- nixos/tests/gnome3.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/tests/gnome3.nix b/nixos/tests/gnome3.nix index 37e4f1680b7..486c146d8dc 100644 --- a/nixos/tests/gnome3.nix +++ b/nixos/tests/gnome3.nix @@ -49,14 +49,14 @@ import ./make-test-python.nix ({ pkgs, ...} : { with subtest("Login to GNOME with GDM"): # wait for gdm to start machine.wait_for_unit("display-manager.service") + # wait for the wayland server + machine.wait_for_file("/run/user/${uid}/wayland-0") # wait for alice to be logged in machine.wait_for_unit("default.target", "${user.name}") # check that logging in has given the user ownership of devices assert "alice" in machine.succeed("getfacl -p /dev/snd/timer") with subtest("Wait for GNOME Shell"): - # wait for the wayland server - machine.wait_for_file("/run/user/${uid}/wayland-0") # correct output should be (true, 'false') machine.wait_until_succeeds( "${startingUp} | grep -q 'true,..false'"