File Coverage

consoles/console.pm
Criterion Covered Total %
statement 61 66 92.4
total 61 66 92.4


line stmt code
1   # Copyright 2009-2013 Bernhard M. Wiedemann
2   # Copyright 2012-2020 SUSE LLC
3   # SPDX-License-Identifier: GPL-2.0-or-later
4    
5   =head2 consoles::console
6    
7   Base class for consoles. That is, 'user' interfaces between os-autoinst and
8   the SUT which are independent of the backend (e.g. QEMU, IPMI). Consoles are
9   used to match needles against the GUI and send key presses (e.g. VNC) or
10   communicate with the shell using text (e.g. virtio_terminal).
11    
12   Consoles should implement disable and reset if necessary as well as a number
13   of other functions. See vnc_base and virtio_terminal to see how this works.
14    
15   =cut
16    
17    
18   use Mojo::Base -base, -signatures;
19 42 use autodie ':all';
  42  
  42  
20 42  
  42  
  42  
21   require IPC::System::Simple;
22    
23   has 'backend';
24    
25   my $self = bless({class => $class}, $class);
26 84 $self->{testapi_console} = $testapi_console;
  84  
  84  
  84  
  84  
27 84 $self->{args} = $args;
28 84 $self->{activated} = 0;
29 84 $self->init;
30 84 return $self;
31 84 }
32 84  
33   # Special keys like Ctrl-Alt-Fx are not passed to the VM by xfreerdp.
34   # That means switch from graphical to console is not possible on Hyper-V.
35 84 $self->{console_hotkey} = ($bmwqemu::vars{VIRSH_VMM_FAMILY} // '') eq 'hyperv' ? 'alt-f' : 'ctrl-alt-f';
  84  
  84  
36   }
37    
38 84 # SUT was e.g. rebooted
39   $self->{activated} = 0;
40   return;
41   }
42 2  
  2  
  2  
43 2 die "screen needs to be implemented in subclasses - $self->{class} does not\n";
44 2 return;
45   }
46    
47 0 # to be overloaded
  0  
  0  
48 0  
49 0 my $activated;
50   if (!$self->{activated}) {
51   my $ret = $self->activate;
52   # undef on success
53 5 return $ret if $ret;
  5  
54   $self->{activated} = 1;
55 8 $activated = 1;
  8  
  8  
56 8 }
57 8 $self->trigger_select;
58 8 return $activated;
59   }
60 7  
61 5  
62 5  
63   my $my_args = $self->{args};
64 5 $self->{args}->{$_} = $args{$_} for (keys %args);
65 5 # no need to send changes to right process; console proxy already takes care
66   # that this method is called in the right process
67   }
68 9  
  9  
69   $self->{args}->{tty} = $tty;
70 7 # no need to send changes to right process; console proxy already takes care
  7  
  7  
  7  
71   # that this method is called in the right process
72 1 }
  1  
  1  
  1  
73 1  
74 1 return undef unless $self->{console_hotkey} && $self->{args}->{tty};
75   return $self->{console_hotkey} . $self->{args}->{tty};
76   }
77    
78   1;