Warning, /plasma/drkonqi/src/tests/integration/suite is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env ruby 0002 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 # SPDX-FileCopyrightText: 2017 Harald Sitter <sitter@kde.org> 0004 0005 0006 require 'fileutils' 0007 require 'optparse' 0008 require 'tmpdir' 0009 0010 STDOUT.sync = true # force immediate flushing without internal caching 0011 0012 class Isolator 0013 def mangle_env(tmpdir) 0014 ENV['HOME'] = tmpdir 0015 ENV.keys.each { |k| ENV.delete(k) if k.start_with?('XDG_') } 0016 end 0017 0018 private 0019 0020 def dbus_run(cmd) 0021 warn dbus_run_cmd(cmd) 0022 system(dbus_run_cmd(cmd)) 0023 end 0024 0025 def dbus_run_cmd(cmd) 0026 "dbus-run-session -- #{cmd}" 0027 end 0028 end 0029 0030 # Isolates GUI via xephyr 0031 class XephyrIsolator < Isolator 0032 def run(cmd) 0033 ephemeral('Xephyr -screen 1024x768x24+32 :666') do 0034 ENV['DISPLAY'] = ':666' 0035 dbus_run(cmd) || raise 0036 end 0037 end 0038 0039 private 0040 0041 def ephemeral(*args) 0042 pid = spawn(*args) 0043 yield 0044 ensure 0045 Process.kill('KILL', pid) if pid 0046 Process.waitpid2(pid) if pid 0047 end 0048 end 0049 0050 # Isolates GUI via xvfb-run 0051 class XvfbIsolator < Isolator 0052 def run(cmd) 0053 warn "xvfb-run -a --server-args=\"-screen 0 1024x768x24\" #{dbus_run_cmd(cmd)}" 0054 system("xvfb-run -a --server-args=\"-screen 0 1024x768x24\" #{dbus_run_cmd(cmd)}") || raise 0055 end 0056 end 0057 0058 class NoIsolator < Isolator 0059 def mangle_env(*) 0060 # noop without isolation 0061 end 0062 0063 def run(cmd) 0064 # No X11 and no DBus isolation. 0065 warn cmd.to_s 0066 system(cmd) || raise 0067 end 0068 end 0069 0070 def new_isolator 0071 return NoIsolator.new if ENV['JENKINS_SERVER_COOKIE'] || ENV['NO_ISOLATOR'] 0072 return XephyrIsolator.new if ENV['XEPHYR'] 0073 XvfbIsolator.new 0074 end 0075 0076 OptionParser.new do |opts| 0077 opts.banner = "Usage: #{$0} ARGS" 0078 0079 opts.separator('') 0080 0081 opts.on('--drkonqi PATH', 'Path to drkonqi bin to test.') do |v| 0082 ENV['DRKONQI_PATH'] = v 0083 end 0084 0085 opts.on('--at-spi-bus-launcher PATH', 0086 'Path to --at-spi-bus-launcher bin to use for testing.') do |v| 0087 ENV['AT_SPI_BUS_LAUNCHER_PATH'] = v 0088 end 0089 0090 opts.on('--at-spi-registryd PATH', 0091 'Path to registry bin to use for testing.') do |v| 0092 ENV['AT_SPI_REGISTRY_PATH'] = v 0093 end 0094 end.parse! 0095 0096 ENV['DRKONQI_PATH'] ||= '/usr/lib/x86_64-linux-gnu/libexec/drkonqi' 0097 ENV['AT_SPI_BUS_LAUNCHER_PATH'] ||= '/usr/lib/at-spi2-core/at-spi-bus-launcher' 0098 ENV['AT_SPI_REGISTRY_PATH'] ||= '/usr/lib/at-spi2-core/at-spi2-registryd' 0099 ENV['KIO_DISABLE_CACHE_CLEANER'] = '1' # do not start the cleaner, it'll dangle 0100 ENV['DRKONQI_IGNORE_QUALITY'] = '1' 0101 0102 # Isolate ourselves by forcing into a separate home and unsetting the XDG path 0103 # variables. Then spin up a suitable virtual X, run a new dbus session bus 0104 # and our test in that environment. 0105 Dir.mktmpdir do |tmpdir| 0106 Dir.glob("#{__dir__}/*_test.rb").each do |test| 0107 isolator = new_isolator 0108 isolator.mangle_env(tmpdir) 0109 isolator.run("ruby '#{test}' -p") 0110 end 0111 sleep 2 # Wait a bit to make sure all children are dead. 0112 end 0113 0114 warn 'all done' 0115 system 'ps -ejH' 0116 exit 0