Changeset View
Changeset View
Standalone View
Standalone View
drkonqi/tests/integration/suite
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
1 | #!/usr/bin/env ruby | ||||
---|---|---|---|---|---|
2 | # | ||||
3 | # Copyright (C) 2017 Harald Sitter <sitter@kde.org> | ||||
4 | # | ||||
5 | # This program is free software; you can redistribute it and/or | ||||
6 | # modify it under the terms of the GNU General Public License as | ||||
7 | # published by the Free Software Foundation; either version 2 of | ||||
8 | # the License or (at your option) version 3 or any later version | ||||
9 | # accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | # by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | # defined in Section 14 of version 3 of the license. | ||||
12 | # | ||||
13 | # This program is distributed in the hope that it will be useful, | ||||
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | # GNU General Public License for more details. | ||||
17 | # | ||||
18 | # You should have received a copy of the GNU General Public License | ||||
19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | | ||||
21 | require 'fileutils' | ||||
22 | require 'tmpdir' | ||||
23 | | ||||
24 | # Isolates GUI via xephyr | ||||
25 | class XephyrIsolator | ||||
26 | def run(cmd) | ||||
27 | ephemeral('Xephyr -screen 1024x768x24+32 :666') do | ||||
28 | ENV['DISPLAY'] = ':666' | ||||
29 | system(cmd) || raise | ||||
30 | end | ||||
31 | end | ||||
32 | | ||||
33 | private | ||||
34 | | ||||
35 | def ephemeral(*args) | ||||
36 | pid = spawn(*args) | ||||
37 | yield | ||||
38 | ensure | ||||
39 | Process.kill('KILL', pid) if pid | ||||
40 | Process.waitpid2(pid) if pid | ||||
41 | end | ||||
42 | end | ||||
43 | | ||||
44 | # Isolates GUI via xvfb-run | ||||
45 | class XvfbIsolator | ||||
46 | def run(cmd) | ||||
47 | system("xvfb-run -a --server-args=\"-screen 0 1024x768x24\" #{cmd}") || raise | ||||
48 | end | ||||
49 | end | ||||
50 | | ||||
51 | ENV['DRKONQI_PATH'] = ARGV.pop || '/usr/lib/x86_64-linux-gnu/libexec/drkonqi' | ||||
52 | | ||||
53 | # Isolate ourselves by forcing into a separate home and unsetting the XDG path | ||||
54 | # variables. Then spin up a suitable virtual X, run a new dbus session bus | ||||
55 | # and our test in that environment. | ||||
56 | Dir.mktmpdir do |tmpdir| | ||||
57 | ENV['HOME'] = tmpdir | ||||
58 | ENV.keys.each { |k| ENV.delete(k) if k.start_with?('XDG_') } | ||||
59 | Dir.glob("#{__dir__}/*_test.rb").each do |test| | ||||
60 | isolator = ENV['XEPHYR'] ? XephyrIsolator.new : XvfbIsolator.new | ||||
61 | isolator.run("dbus-run-session -- ruby #{test} -p") | ||||
62 | end | ||||
63 | sleep 8 # Wait a bit to make sure all children are dead. | ||||
64 | end |