Skip to content

Commit

Permalink
Fix 'ctrl-l being missed when too fast
Browse files Browse the repository at this point in the history
This should fix some flaky tests depending on machine execution performance.

Replace all occurences of 'ctrl-l' to clear the screen in a console with
'clear\n' in form of the new helper function 'clear_console()' as 'ctrl-l' is
not buffered in the keybuffer whereas 'clear\n' is executed after the previous
command returns to the prompt.

Tested locally with "console-consoletest_setup" and following on x86_64. No
test of "ha" or similar has been done.

Alternative or complementary to
os-autoinst#923

Related issue:
https://progress.opensuse.org/issues/10138
  • Loading branch information
okurz committed Jan 12, 2016
1 parent 19e9b6c commit 206181c
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 39 deletions.
11 changes: 10 additions & 1 deletion lib/opensusebasetest.pm
Expand Up @@ -5,10 +5,19 @@ use testapi;

# Base class for all openSUSE tests


sub clear_console {
my ($self) = @_;

$testapi::distri->clear_console;
}

# Additional to backend testapi 'clear-console' we do a needle match to ensure
# continuation only after verification
sub clear_and_verify_console {
my ($self) = @_;

send_key "ctrl-l";
$testapi::distri->clear_console;
assert_screen('cleared-console');

}
Expand Down
12 changes: 10 additions & 2 deletions lib/susedistribution.pm
Expand Up @@ -148,7 +148,7 @@ sub ensure_installed {
sub script_sudo($$) {
my ($self, $prog, $wait) = @_;

send_key 'ctrl-l';
$self->clear_console;
type_string "su -c \'$prog\'\n";
if (!get_var("LIVETEST")) {
assert_screen 'password-prompt';
Expand All @@ -158,6 +158,14 @@ sub script_sudo($$) {
wait_idle $wait;
}

# 'ctrl-l' does not get queued up in buffer. If this happens to fast, the
# screen would not be cleared
sub clear_console {
my ($self) = @_;

type_string "clear\n";
}

sub set_standard_prompt {
my ($self, $user) = @_;
$user ||= $testapi::username;
Expand All @@ -178,7 +186,7 @@ sub become_root {
wait_serial("root", 6) || die "Root prompt not there";
type_string "cd /tmp\n";
$self->set_standard_prompt('root');
send_key('ctrl-l');
$self->clear_console;
}

# initialize the consoles needed during our tests
Expand Down
2 changes: 1 addition & 1 deletion tests/autoyast/installation.pm
Expand Up @@ -28,7 +28,7 @@ sub save_logs_and_continue {
type_string "save_y2logs /tmp/y2logs-$name.tar.bz2\n";
upload_logs "/tmp/y2logs-$name.tar.bz2";
save_screenshot;
send_key "ctrl-l";
$testapi::distri->clear_console;
send_key "alt-f7";
wait_idle(5);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/console/consoletest_setup.pm
Expand Up @@ -47,7 +47,7 @@ sub run() {
script_run "exit";

save_screenshot;
send_key "ctrl-l";
$self->clear_console;

script_run("curl -L -v " . autoinst_url('/data') . " > test.data; echo \"curl-\$?\" > /dev/$serialdev");
wait_serial("curl-0", 10) || die 'curl failed';
Expand Down
2 changes: 1 addition & 1 deletion tests/console/installation_snapshots.pm
Expand Up @@ -25,7 +25,7 @@ sub run() {
$pattern = 'single\s*(\|[^|]*){4}\s*\|\s*number\s*\|\s*Initial Status\s*\|\s*important=yes' if get_var('JEOS');
wait_serial($pattern, 5) || die 'installation snapshot test failed';
script_run('exit');
send_key 'ctrl-l';
$self->clear_console;
}

sub test_flags() {
Expand Down
4 changes: 2 additions & 2 deletions tests/console/mozmill_setup.pm
Expand Up @@ -17,7 +17,7 @@ sub run() {
my $self = shift;
script_sudo("zypper -n in gcc python-devel python-pip mercurial curlftpfs");
assert_screen 'test-mozmill_setup-1', 3;
send_key "ctrl-l";
$self->clear_console;

#script_sudo("pip install mozmill mercurial");
script_sudo("pip install mozmill mercurial");
Expand All @@ -26,7 +26,7 @@ sub run() {
sleep 5;
wait_idle 50;
assert_screen 'test-mozmill_setup-2', 3;
send_key "ctrl-l";
$self->clear_console;
script_run("cd /tmp"); # dont use home to not confuse dolphin test
script_run("wget -q openqa.opensuse.org/opensuse/qatests/qa_mozmill_setup.sh");
local $bmwqemu::timesidleneeded = 3;
Expand Down
2 changes: 1 addition & 1 deletion tests/console/sle11_consoletest_setup.pm
Expand Up @@ -46,7 +46,7 @@ sub run() {
script_run "exit";

save_screenshot;
send_key "ctrl-l";
$self->clear_console;

script_run("curl -L -v " . autoinst_url . "/data > test.data; echo \"curl-\$?\" > /dev/$serialdev");
wait_serial("curl-0", 10) || die 'curl failed';
Expand Down
2 changes: 1 addition & 1 deletion tests/console/sntp.pm
Expand Up @@ -18,7 +18,7 @@ sub run() {
script_sudo("perl qa_ntp.pl");
wait_idle 90;
assert_screen 'test-sntp-1', 3;
send_key "ctrl-l"; # clear screen
$self->clear_console;
script_run('echo sntp returned $?');
assert_screen 'test-sntp-2', 3;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/console/upgrade_snapshots.pm
Expand Up @@ -25,7 +25,7 @@ sub run() {
wait_serial('post\s*(\|[^|]*){4}\s*\|\s*number\s*\|\s*after update\s*\|\s*important=yes', 5) || die 'upgrade snapshots test failed';

script_run('exit');
send_key 'ctrl-l';
$self->clear_console;
}

sub test_flags() {
Expand Down
2 changes: 1 addition & 1 deletion tests/console/xorg_vt.pm
Expand Up @@ -14,7 +14,7 @@ use testapi;
sub run() {
my $self = shift;

send_key "ctrl-l";
$self->clear_console;
script_run('ps -ef | grep bin/X');
assert_screen("xorg-tty7"); # suppose used terminal is tty7
}
Expand Down
2 changes: 1 addition & 1 deletion tests/console/yast2_bootloader.pm
Expand Up @@ -23,7 +23,7 @@ sub run() {
my $ret = assert_screen "test-yast2_bootloader-1", 300;
send_key "alt-o"; # OK => Close
assert_screen 'exited-bootloader', 150;
send_key "ctrl-l";
$self->clear_console;
script_run("echo \"EXIT-\$?\" > /dev/$serialdev");
die unless wait_serial "EXIT-0", 2;
script_run('rpm -q hwinfo');
Expand Down
2 changes: 1 addition & 1 deletion tests/console/yast2_i.pm
Expand Up @@ -73,7 +73,7 @@ sub run() {
# yast might take a while on sle11 due to suseconfig
wait_serial("yast2-i-status-0", 60) || die "yast didn't finish";

send_key "ctrl-l"; # clear screen to see that second update does not do any more
$self->clear_console; # clear screen to see that second update does not do any more
assert_script_run("rpm -e $pkgname"); # erase $pkgname
script_run("echo mark yast test"); # avoid zpper needle
script_run("rpm -q $pkgname");
Expand Down
4 changes: 2 additions & 2 deletions tests/console/yast2_lan.pm
Expand Up @@ -59,12 +59,12 @@ sub run() {
send_key "alt-o"; # OK=>Save&Exit
assert_screen 'yast2-lan-exited', 90;

send_key "ctrl-l"; # clear screen
$self->clear_console;
script_run('echo $?');
script_run('hostname');
assert_screen 'test-yast2_lan-2';

send_key "ctrl-l"; # clear screen
$self->clear_console;
script_run('ip -o a s');
script_run('ip r s');
script_run('getent ahosts ' . get_var("OPENQA_HOSTNAME"));
Expand Down
2 changes: 1 addition & 1 deletion tests/console/zypper_in.pm
Expand Up @@ -19,7 +19,7 @@ sub run() {

my $pkgname = get_var("PACKAGETOINSTALL");
assert_script_run("zypper -n in screen $pkgname");
send_key "ctrl-l"; # clear screen to see that second update does not do any more
$self->clear_console; # clear screen to see that second update does not do any more
assert_script_run("rpm -e $pkgname");
script_run("rpm -q $pkgname");
script_run('exit');
Expand Down
2 changes: 1 addition & 1 deletion tests/console/zypper_up.pm
Expand Up @@ -30,7 +30,7 @@ sub run() {

# XXX: does this below make any sense? what if updates got
# published meanwhile?
send_key "ctrl-l"; # clear screen to see that second update does not do any more
$self->clear_console; # clear screen to see that second update does not do any more
assert_script_run("zypper -n -q patch");

script_run('exit');
Expand Down
2 changes: 1 addition & 1 deletion tests/ha/cluster_init.pm
Expand Up @@ -18,7 +18,7 @@ sub run() {
assert_screen 'cluster-init', 60;
type_string "crm status\n";
assert_screen 'cluster-status';
send_key 'ctrl-l';
$self->clear_console;
}

1;
2 changes: 1 addition & 1 deletion tests/ha/cluster_join.pm
Expand Up @@ -28,7 +28,7 @@ sub joincluster() {
upload_logs "/root/hbreport.tar.bz2";
save_screenshot();
}
send_key 'ctrl-l';
$self->clear_console;
}

sub run() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ha/corosync.pm
Expand Up @@ -16,7 +16,7 @@ sub run() {
for my $i (1 .. 3) {
type_string "crm status\n";
assert_screen 'cluster-status';
send_key 'ctrl-l';
$self->clear_console;
send_key 'ctrl-pgdn';
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ha/fencing.pm
Expand Up @@ -20,20 +20,20 @@ sub run() {
type_string "crm status\n";
assert_screen 'cluster-node-down';
sleep 240;
send_key 'ctrl-l';
$self->clear_console;
type_string "crm status\n";
assert_screen 'cluster-node-returned';
send_key 'ctrl-l';
$self->clear_console;
send_key 'ctrl-pgdn';
send_key 'ret';
type_string "ssh 10.0.2.17 -l root\n";
sleep 10;
type_string "nots3cr3t\n";
sleep 10;
send_key 'ctrl-l';
$self->clear_console;
type_string "crm status\n";
assert_screen 'cluster-status';
send_key 'ctrl-l';
$self->clear_console;
send_key 'ctrl-pgup';
}

Expand Down
10 changes: 5 additions & 5 deletions tests/ha/ha_preparation.pm
Expand Up @@ -22,7 +22,7 @@ sub connectssh($) {
type_string "nots3cr3t\n";
sleep 10;
check_screen 'ha-ssh-login', 40; #should be assert
send_key 'ctrl-l';
$self->clear_console;
}

sub startvm($) {
Expand All @@ -32,7 +32,7 @@ sub startvm($) {
sleep 5;
type_string "nots3cr3t\n";
sleep 5;
send_key 'ctrl-l';
$self->clear_console;
}

sub fixvmnetwork($) {
Expand All @@ -52,7 +52,7 @@ sub fixvmnetwork($) {
send_key 'down';
send_key 'ret';
sleep 5;
send_key 'ctrl-l';
$self->clear_console;
}

sub rebootvm($) {
Expand All @@ -68,7 +68,7 @@ sub rebootvm($) {
send_key 'down';
send_key 'ret';
sleep 5;
send_key 'ctrl-l';
$self->clear_console;
}

sub checkboot($) {
Expand All @@ -79,7 +79,7 @@ sub checkboot($) {
send_key 'down';
send_key 'ret';
sleep 5;
send_key 'ctrl-l';
$self->clear_console;
}

sub run() {
Expand Down
4 changes: 2 additions & 2 deletions tests/ha/sle11_cluster_init.pm
Expand Up @@ -19,7 +19,7 @@ sub run() {
assert_screen 'cluster-init', 60;
type_string "crm status\n";
assert_screen 'cluster-status';
send_key 'ctrl-l';
$self->clear_console;
mutex_create('cluster-init');
}
else {
Expand All @@ -40,7 +40,7 @@ sub run() {
type_string "tailf /var/log/messages\n"; # Probably redundant, remove if not needed
save_screenshot();
}
send_key 'ctrl-l';
$self->clear_console;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/installation/post_zdup.pm
Expand Up @@ -14,7 +14,7 @@ use testapi;
use utils;

sub run() {
send_key "ctrl-l", 1;
$testapi::distri->clear_console;

# Print zypper repos
script_run("zypper lr -d");
Expand Down
2 changes: 1 addition & 1 deletion tests/installation/proxy_init.pm
Expand Up @@ -32,7 +32,7 @@ sub createvm($) {
send_key 'f8', 1;
send_key 'down', 1;
send_key 'ret', 1;
send_key 'ctrl-l', 1;
$self->clear_console;
}

sub run() {
Expand Down
2 changes: 1 addition & 1 deletion tests/installation/proxy_start_2nd_stage.pm
Expand Up @@ -31,7 +31,7 @@ sub waitfor2ndstage($) {
send_key 'down', 1;
send_key 'ret', 1;
sleep 5;
send_key 'ctrl-l', 1;
$testapi::distri->clear_console;
}

sub run() {
Expand Down
4 changes: 2 additions & 2 deletions tests/x11/chromium.pm
Expand Up @@ -21,9 +21,9 @@ sub run() {
x11_start_program("chromium");

assert_screen 'chromium-main-window', 50;
send_key "esc"; # get rid of popup
send_key "esc"; # get rid of popup
sleep 1;
send_key "ctrl-l";
send_key "ctrl-l"; # select text in address bar
sleep 1;
type_string "about:\n";
assert_screen 'chromium-about', 15;
Expand Down
4 changes: 2 additions & 2 deletions tests/x11/xterm.pm
Expand Up @@ -17,8 +17,8 @@ sub run() {
x11_start_program("xterm");
sleep 2;
type_string "cd\n";
sleep 1; # go to $HOME (for KDE)
send_key "ctrl-l"; # clear
sleep 1; # go to $HOME (for KDE)
$self->clear_console;
for (1 .. 13) { send_key "ret" }
type_string "echo If you can see this text xterm is working.\n";
sleep 2;
Expand Down

0 comments on commit 206181c

Please sign in to comment.