From ddc91efeff60d58878bab9c4f4cc54c5e591b492 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Sat, 24 Sep 2016 12:42:39 -0700 Subject: [PATCH] detect (rather than guessing) desktop vt use 'ps' output for Xorg and Xwayland. We'd need some new openQA var to get this right by 'guessing', as it's vt1 for Workstation when running live - so long as autologin worked - but vt2 after install. We'd need a var or some other thing to detect which case we're running in. LIVE doesn't do it, it's set even when running a post-install test from a live image. So instead let's just do it a bit more cleverly. This also gives us a bit of insurance against changes in GDM, SDDM etc. behaviour, so long as Xwayland or Xorg is running (and we can add additional processes to the list, like gnome-shell, if needed/appropriate). We assume the *final* listed process - i.e. the most recently-started one - will be the desktop; this covers gdm's behaviour of starting up on vt1 then running the user session on vt2. We can make this function more complex and add args if we ever get to the point where we have multi- user tests running or anything (e.g. allow to pass a username and only look for that user's processes). Landing without review as this broke the live variant of the test on Workstation in production (kinda not sure why it worked in testing, or I didn't notice that it failed, but never mind). I've tested it on staging. --- lib/installedtest.pm | 10 ---------- lib/main_common.pm | 16 +++++++++++++++- tests/desktop_notifications_postinstall.pm | 2 +- tests/desktop_update_graphical_postinstall.pm | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/installedtest.pm b/lib/installedtest.pm index 125c5ce7..b48971d3 100644 --- a/lib/installedtest.pm +++ b/lib/installedtest.pm @@ -101,16 +101,6 @@ sub repo_setup { script_run "cat /etc/yum.repos.d/{fedora,fedora-rawhide}.repo"; } -# switch to the desktop where the VT is -sub desktop_vt { - if (get_var("DESKTOP") eq 'gnome') { - send_key 'ctrl-alt-f2'; - } - else { - send_key 'ctrl-alt-f1'; - } -} - 1; # vim: set sw=4 et: diff --git a/lib/main_common.pm b/lib/main_common.pm index 67faaa49..4c97ea9f 100644 --- a/lib/main_common.pm +++ b/lib/main_common.pm @@ -6,7 +6,7 @@ use base 'Exporter'; use Exporter; use testapi; -our @EXPORT = qw/run_with_error_check check_type_string type_safely type_very_safely/; +our @EXPORT = qw/run_with_error_check check_type_string type_safely type_very_safely desktop_vt/; sub run_with_error_check { my ($func, $error_screen) = @_; @@ -48,3 +48,17 @@ sub type_very_safely { check_type_string($string, size => 1, still => 5, max_interval => 1); wait_still_screen 5; } + +# Figure out what tty the desktop is on, switch to it. Assumes we're +# at a root console +sub desktop_vt { + # use ps to find the tty of Xwayland or Xorg + my $xout; + # don't fail test if we don't find any process, just guess tty1 + eval { $xout = script_output 'ps -C Xwayland,Xorg -o tty --no-headers'; }; + my $tty = 1; # default + while ($xout =~ /tty(\d)/g) { + $tty = $1; # most recent match is probably best + } + send_key "ctrl-alt-f${tty}"; +} diff --git a/tests/desktop_notifications_postinstall.pm b/tests/desktop_notifications_postinstall.pm index 3f328d2f..3512cdcb 100644 --- a/tests/desktop_notifications_postinstall.pm +++ b/tests/desktop_notifications_postinstall.pm @@ -23,7 +23,7 @@ sub run { # just assume we're gonna win $self->root_console(tty=>3); prepare_test_packages; - $self->desktop_vt(); + desktop_vt; # now, WE WAIT. this is just an unconditional wait - rather than # breaking if we see an update notification appear - so we catch # things that crash a few minutes after startup, etc. diff --git a/tests/desktop_update_graphical_postinstall.pm b/tests/desktop_update_graphical_postinstall.pm index 133f7219..9f689998 100644 --- a/tests/desktop_update_graphical_postinstall.pm +++ b/tests/desktop_update_graphical_postinstall.pm @@ -12,7 +12,7 @@ sub run { assert_script_run 'dnf config-manager --set-disabled updates-testing'; prepare_test_packages; # get back to the desktop - $self->desktop_vt(); + desktop_vt; # run the updater if ($desktop eq 'kde') { # KDE team tells me the 'preferred' update method is the