2016-09-07 08:34:54 +00:00
|
|
|
package main_common;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use base 'Exporter';
|
|
|
|
use Exporter;
|
|
|
|
|
|
|
|
use testapi;
|
2016-12-16 17:40:29 +00:00
|
|
|
our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us/;
|
2016-09-07 08:34:54 +00:00
|
|
|
|
|
|
|
sub run_with_error_check {
|
|
|
|
my ($func, $error_screen) = @_;
|
|
|
|
die "Error screen appeared" if (check_screen $error_screen, 5);
|
|
|
|
$func->();
|
|
|
|
die "Error screen appeared" if (check_screen $error_screen, 5);
|
|
|
|
}
|
2016-09-12 17:24:30 +00:00
|
|
|
|
|
|
|
# high-level 'type this string quite safely but reasonably fast'
|
|
|
|
# function whose specific implementation may vary
|
|
|
|
sub type_safely {
|
|
|
|
my $string = shift;
|
2016-10-20 16:12:55 +00:00
|
|
|
type_string($string, wait_screen_change => 3, max_interval => 20);
|
2016-09-12 17:24:30 +00:00
|
|
|
wait_still_screen 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
# high-level 'type this string extremely safely and rather slow'
|
|
|
|
# function whose specific implementation may vary
|
|
|
|
sub type_very_safely {
|
|
|
|
my $string = shift;
|
2016-10-20 16:12:55 +00:00
|
|
|
type_string($string, wait_screen_change => 1, max_interval => 1);
|
2016-09-12 17:24:30 +00:00
|
|
|
wait_still_screen 5;
|
|
|
|
}
|
2016-09-24 19:42:39 +00:00
|
|
|
|
|
|
|
# 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}";
|
|
|
|
}
|
consolidate login waits, use postinstall not entrypoint for base
Summary:
I started out wanting to fix an issue I noticed today where
graphical upgrade tests were failing because they didn't wait
for the graphical login screen properly; the test was sitting
at the 'full Fedora logo' state of plymouth for a long time,
so the current boot_to_login_screen's wait_still_screen was
triggered by it and the function wound up failing on the
assert_screen, because it was still some time before the real
login screen appeared.
So I tweaked the boot_to_login_screen implementation to work
slightly differently (look for a login screen match, *then* -
if we're dealing with a graphical login - wait_still_screen
to defeat the 'old GPU buffer showing login screen' problem
and assert the login screen again). But while working on it,
I figured we really should consolidate all the various places
that handle the bootloader -> login, we were doing it quite
differently in all sorts of different places. And as part of
that, I converted the base tests to use POSTINSTALL (and thus
go through the shared _wait_login tests) instead of handling
boot themselves. As part of *that*, I tweaked main.pm to not
require all POSTINSTALL tests have the _postinstall suffix on
their names, as it really doesn't make sense, and renamed the
tests.
Test Plan: Run all tests, see if they work.
Reviewers: jskladan, garretraziel
Reviewed By: garretraziel
Subscribers: tflink
Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D1015
2016-09-27 18:48:15 +00:00
|
|
|
|
|
|
|
# Wait for login screen to appear. Handle the annoying GPU buffer
|
|
|
|
# problem where we see a stale copy of the login screen from the
|
|
|
|
# previous boot. Will suffer a ~30 second delay if there's a chance
|
|
|
|
# we're *already at* the expected login screen.
|
|
|
|
sub boot_to_login_screen {
|
|
|
|
my %args = @_;
|
|
|
|
$args{timeout} //= 300;
|
|
|
|
# we may start at a screen that matches one of the needles; if so,
|
|
|
|
# wait till we don't (e.g. when rebooting at end of live install,
|
|
|
|
# we match text_console_login until the console disappears)
|
|
|
|
my $count = 5;
|
|
|
|
while (check_screen("login_screen", 3) && $count > 0) {
|
|
|
|
sleep 5;
|
|
|
|
$count -= 1;
|
|
|
|
}
|
|
|
|
assert_screen "login_screen", $args{timeout};
|
|
|
|
if (match_has_tag "graphical_login") {
|
|
|
|
wait_still_screen 10, 30;
|
|
|
|
assert_screen "login_screen";
|
|
|
|
}
|
|
|
|
}
|
redo console_login with multiple matches, move to main_common
Summary:
Since we can match on multiple needles, we can drop the loop
from console_login and instead do it this way, which is simpler
and should work better on ARM (the timeouts will scale and
allow ARM to be slow here). Also move it to main_common as
there's no logical reason for it to be a class method.
Also remove the `check` arg. `check` was only set to 0 by two
tests, _console_shutdown and anacondatest's _post_fail_hook.
For _console_shutdown, I think I just wanted to give it the
best possible chance of succeeding. But we're really not going
to lose anything significant by checking, the only case where
check=>0 would've helped is if the 'good' needle had stopped
matching, and all sorts of other tests will fail in that case.
anacondatest was only using it to save a screenshot of whatever
was on the tty if it didn't reach a root console, which doesn't
seem that useful, and we'll get screenshots from check_screen
and assert_screen anyway.
Test Plan:
Run all tests, check they behave as expected and
none inappropriately fails on console login.
Reviewers: jskladan, garretraziel
Reviewed By: garretraziel
Subscribers: tflink
Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D1016
2016-09-30 15:42:45 +00:00
|
|
|
|
|
|
|
# Switch keyboard layouts at a console
|
|
|
|
sub console_switch_layout {
|
|
|
|
# switcher key combo differs between layouts, for console
|
|
|
|
if (get_var("LANGUAGE", "") eq "russian") {
|
|
|
|
send_key "ctrl-shift";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 16:41:00 +00:00
|
|
|
# switch to 'native' or 'ascii' input method in a graphical desktop
|
|
|
|
# usually switched configs have one mode for inputting ascii-ish
|
|
|
|
# characters (which may be 'us' keyboard layout, or a local layout for
|
|
|
|
# inputting ascii like 'jp') and one mode for inputting native
|
|
|
|
# characters (which may be another keyboard layout, like 'ru', or an
|
|
|
|
# input method for more complex languages)
|
2016-12-16 17:40:29 +00:00
|
|
|
# 'environment' can be a desktop name or 'anaconda' for anaconda
|
|
|
|
# if not set, will use get_var('DESKTOP') or default 'anaconda'
|
|
|
|
sub desktop_switch_layout {
|
|
|
|
my ($layout, $environment) = @_;
|
2016-12-21 16:41:00 +00:00
|
|
|
$layout //= 'ascii';
|
2016-12-16 17:40:29 +00:00
|
|
|
$environment //= get_var("DESKTOP", "anaconda");
|
|
|
|
# if already selected, we're good
|
|
|
|
return if (check_screen "${environment}_layout_${layout}", 3);
|
|
|
|
# otherwise we need to switch
|
|
|
|
my $switcher = "alt-shift"; # anaconda
|
|
|
|
$switcher = "super-spc" if $environment eq 'gnome';
|
|
|
|
# KDE? not used yet
|
|
|
|
send_key $switcher;
|
|
|
|
assert_screen "${environment}_layout_${layout}", 3;
|
|
|
|
}
|
|
|
|
|
redo console_login with multiple matches, move to main_common
Summary:
Since we can match on multiple needles, we can drop the loop
from console_login and instead do it this way, which is simpler
and should work better on ARM (the timeouts will scale and
allow ARM to be slow here). Also move it to main_common as
there's no logical reason for it to be a class method.
Also remove the `check` arg. `check` was only set to 0 by two
tests, _console_shutdown and anacondatest's _post_fail_hook.
For _console_shutdown, I think I just wanted to give it the
best possible chance of succeeding. But we're really not going
to lose anything significant by checking, the only case where
check=>0 would've helped is if the 'good' needle had stopped
matching, and all sorts of other tests will fail in that case.
anacondatest was only using it to save a screenshot of whatever
was on the tty if it didn't reach a root console, which doesn't
seem that useful, and we'll get screenshots from check_screen
and assert_screen anyway.
Test Plan:
Run all tests, check they behave as expected and
none inappropriately fails on console login.
Reviewers: jskladan, garretraziel
Reviewed By: garretraziel
Subscribers: tflink
Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D1016
2016-09-30 15:42:45 +00:00
|
|
|
# this subroutine handles logging in as a root/specified user into console
|
|
|
|
# it requires TTY to be already displayed (handled by the root_console()
|
|
|
|
# method of distribution classes)
|
|
|
|
sub console_login {
|
|
|
|
my %args = (
|
|
|
|
user => "root",
|
|
|
|
password => get_var("ROOT_PASSWORD", "weakpassword"),
|
|
|
|
@_);
|
|
|
|
|
|
|
|
# There's a timing problem when we switch from a logged-in console
|
|
|
|
# to a non-logged in console and immediately call this function;
|
|
|
|
# if the switch lags a bit, this function will match one of the
|
|
|
|
# logged-in needles for the console we switched from, and get out
|
|
|
|
# of sync (e.g. https://openqa.stg.fedoraproject.org/tests/1664 )
|
|
|
|
# To avoid this, we'll sleep a couple of seconds before starting
|
|
|
|
sleep 2;
|
|
|
|
|
|
|
|
my $good = "";
|
|
|
|
my $bad = "";
|
|
|
|
if ($args{user} eq "root") {
|
|
|
|
$good = "root_console";
|
|
|
|
$bad = "user_console";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$good = "user_console";
|
|
|
|
$bad = "root_console";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_screen $bad, 0) {
|
|
|
|
# we don't want to 'wait' for this as it won't return
|
|
|
|
script_run "exit", 0;
|
|
|
|
sleep 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_screen [$good, 'text_console_login'], 10;
|
|
|
|
# if we're already logged in, all is good
|
|
|
|
return if (match_has_tag $good);
|
|
|
|
# if we see the login prompt, type the username
|
|
|
|
type_string("$args{user}\n") if (match_has_tag 'text_console_login');
|
|
|
|
check_screen [$good, 'console_password_required'], 30;
|
|
|
|
# on a live image, just the user name will be enough
|
|
|
|
return if (match_has_tag $good);
|
|
|
|
# otherwise, type the password if we see the prompt
|
|
|
|
if (match_has_tag 'console_password_required') {
|
|
|
|
type_string "$args{password}";
|
|
|
|
if (get_var("SWITCHED_LAYOUT") and $args{user} ne "root") {
|
|
|
|
# see _do_install_and_reboot; when layout is switched
|
|
|
|
# user password is doubled to contain both US and native
|
|
|
|
# chars
|
|
|
|
console_switch_layout;
|
|
|
|
type_string "$args{password}";
|
|
|
|
console_switch_layout;
|
|
|
|
}
|
|
|
|
send_key "ret";
|
|
|
|
}
|
|
|
|
# make sure we reached the console
|
|
|
|
assert_screen($good, 30);
|
|
|
|
}
|
2016-12-08 20:03:26 +00:00
|
|
|
|
|
|
|
# load US layout (from a root console)
|
|
|
|
sub console_loadkeys_us {
|
|
|
|
if (get_var('LANGUAGE') eq 'french') {
|
|
|
|
script_run "loqdkeys us", 0;
|
|
|
|
}
|
|
|
|
}
|