os-autoinst-distri-rocky/lib/main_common.pm
Adam Williamson e1ec1997af try to be safer when typing in X: slower, more checks
Summary:
the main thing this does is try and type slower in X - this
should cover nearly everywhere we type anything in X, and make
it type slower. We also add a bit more safety checking to some
old tests which didn't have it (mainly _do_install_and_reboot)
- wait_still_screen after typing to make sure all the keypresses
were registered before continuing.

This is an attempt to mitigate the problems we've seen where
the wrong text gets typed into the wrong places and the tests
break.

This branch is live on staging atm. It still has *some* issues,
but I do think it's an improvement.

Test Plan:
run the tests (probably several times), compare to
runs without the change, see if it's better or worse...

Reviewers: jskladan, garretraziel

Reviewed By: garretraziel

Subscribers: tflink

Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D993
2016-09-12 10:24:30 -07:00

51 lines
1.6 KiB
Perl

package main_common;
use strict;
use base 'Exporter';
use Exporter;
use testapi;
our @EXPORT = qw/run_with_error_check check_type_string type_safely type_very_safely/;
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);
}
# type the string in sets of characters at a time (default 3), waiting
# for a screen change after each set. Intended to be safer when the VM
# is busy and regular type_string may overload the input buffer. Args
# passed along to `type_string`. Accepts additional args:
# `size` - size of character groups (default 3) - set to 1 for extreme
# safety (but slower and more screenshotting)
sub check_type_string {
my ($string, %args) = @_;
$args{size} //= 3;
# split string into an array of pieces of specified size
# https://stackoverflow.com/questions/372370
my @pieces = unpack("(a$args{size})*", $string);
for my $piece (@pieces) {
wait_screen_change { type_string($piece, %args); };
}
}
# high-level 'type this string quite safely but reasonably fast'
# function whose specific implementation may vary
sub type_safely {
my $string = shift;
check_type_string($string, max_interval => 20);
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;
check_type_string($string, size => 1, still => 5, max_interval => 1);
wait_still_screen 5;
}