diff options
author | Tails developers <amnesia@boum.org> | 2014-12-19 00:40:08 +0100 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2014-12-21 09:45:40 +0100 |
commit | 51680b6ebb645d37ebdfcd122ca163b3a638aefa (patch) | |
tree | 337e128d2eac3cbc89ecbacf38851bfa33469cd5 /features/support/helpers/display_helper.rb | |
parent | 44bab3c86ca3d95837f4c50cc535206352385a46 (diff) | |
download | jenkins.debian.net-51680b6ebb645d37ebdfcd122ca163b3a638aefa.tar.xz |
files copied from https://git-tails.immerda.ch/tails - many thanks to the tails developers for their nice work and documentation of it - these files have been released under the GNU General Public License version 3 or (at your option) any later version
features/images has been omitted
Diffstat (limited to 'features/support/helpers/display_helper.rb')
-rw-r--r-- | features/support/helpers/display_helper.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/features/support/helpers/display_helper.rb b/features/support/helpers/display_helper.rb new file mode 100644 index 00000000..354935f0 --- /dev/null +++ b/features/support/helpers/display_helper.rb @@ -0,0 +1,51 @@ + +class Display + + def initialize(domain, x_display) + @domain = domain + @x_display = x_display + end + + def start + start_virtviewer(@domain) + # We wait for the display to be active to not lose actions + # (e.g. key presses via sikuli) that come immediately after + # starting (or restoring) a vm + try_for(20, { :delay => 0.1, :msg => "virt-viewer failed to start"}) { + active? + } + end + + def stop + stop_virtviewer + end + + def restart + stop_virtviewer + start_virtviewer(@domain) + end + + def start_virtviewer(domain) + # virt-viewer forks, so we cannot (easily) get the child pid + # and use it in active? and stop_virtviewer below... + IO.popen(["virt-viewer", "-d", + "-f", + "-r", + "-c", "qemu:///system", + ["--display=", @x_display].join(''), + domain, + "&"].join(' ')) + end + + def active? + p = IO.popen("xprop -display #{@x_display} " + + "-name '#{@domain} (1) - Virt Viewer' 2>/dev/null") + Process.wait(p.pid) + p.close + $? == 0 + end + + def stop_virtviewer + system("killall virt-viewer") + end +end |