1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#!/usr/bin/ruby
require 'optparse'
require 'fileutils'
require 'stringio'
class Logger
attr_reader :output
def initialize
@output = StringIO.new
@start = Time.now.to_i
end
def string
output.string
end
def puts(str)
ts = Time.now.to_i - @start
output.puts("#{ts}s #{str}")
end
def msg(str)
self.puts "autopkgtest [%s]: %s\n" % [Time.now.strftime('%H:%M:%S'), str]
end
end
log = Logger.new
now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
log.msg "starting date and time: #{now}"
log.puts "command line arguments: #{ARGV.inspect}"
pkg = nil
outdir = nil
optparse = OptionParser.new do |opts|
opts.banner = "Usage: test-package --output-dir OUTPUTDIR [AUTOPKGTEST-ARGS] PACKAGE"
opts.separator "Options:"
opts.on('--output-dir OUTPUTDIR') do |arg|
outdir = arg
end
opts.on('--shell-fail', '-s') do |arg|
true
end
# options with arguments
%w[
--user
--trigger
--add-apt-source
--add-apt-release
--pin-packages
--copy
].each do |ign|
opts.on("#{ign} IGNORED") do |arg|
log.puts "Ignored option/argument: #{ign}=#{arg}"
end
end
# options without arguments
['--apt-upgrade'].each do |ign|
opts.on(ign) do
log.puts "Ignored option:# {ign}"
end
end
end
optparse.parse!
if ARGV.length != 1 || outdir.nil?
log.puts optparse
puts log.string
exit(1)
end
pkg = ARGV.first
FileUtils.mkdir_p(outdir)
if ENV["DEBCI_FAKE_DEPS"]
File.open(File.join(outdir, 'foo0t-mytest-packages'), 'w') do |f|
ENV["DEBCI_FAKE_DEPS"].split('|').each do |line|
f.puts line.gsub(" ", "\t")
end
end
end
suite = ENV['debci_suite'] || 'unstable'
version = `(apt-cache showsrc --only-source #{pkg} | awk '{if($1=="Version:"){print($2)}}' | sort -V | tail -n1) 2>/dev/null`.strip
if version == ''
version = `date +0.0.0-1~%Y%m%d`.strip
end
File.open(File.join(outdir, 'testpkg-version'), 'w') { |f| f.puts "#{pkg} #{version}" }
log.msg("@@@@@@@@@@@@@@@@@@@@ test bed setup")
log.msg("test fake-test: preparing testbed")
if ENV["DEBCI_FAKE_COMMAND"]
io = IO.popen(ENV["DEBCI_FAKE_COMMAND"])
log.puts [ "$ #{ENV['DEBCI_FAKE_COMMAND']}", io.read]
io.close
rc = $?.exitstatus
if rc != 0
rc = 4
end
else
log.msg("test fake-test: [-----------------------")
log.puts "Not really running anything .."
log.puts "This has 70% chance of passing, 10% of all skipped, 10% of failing, and 10% of tmpfailing"
result = ENV.fetch('DEBCI_FAKE_RESULT', nil)
r = case result
when 'pass'
0
when 'neutral'
7
when 'fail'
8
when 'tmpfail'
9
else
rand(10)
end
case r
when 0..6
log.puts "Passed :-)"
result = 'pass'
rc = 0
when 7
log.puts "Neutral :-|"
result = 'neutral'
rc = 8
when 8
log.puts "Failed :-("
result = 'fail'
rc = 4
when 9
log.puts "Some error occurred"
result = 'tmpfail'
rc = 16
end
log.msg("test fake-test: -----------------------]")
log.msg("test smoke-test: - - - - - - - - - - results - - - - - - - - - -")
log.puts("fake-test #{result.upcase}")
end
if ENV["DEBCI_FAKE_KILLPARENT"]
# find our parent which is the t
p = Process.pid
while p > 1
File.open("/proc/#{p}/stat") do |f|
stat = f.gets.split()
if stat[1].include? ENV["DEBCI_FAKE_KILLPARENT"]
# got it, kill that
Process.kill('FPE', p)
p = -1
else
p = Integer(stat[3])
end
end
end
end
# this will produce values larger than 3600 (1h, the threshold for "slow
# running tests") ~6% of the time, with most values being small
duration = (50000/((1+rand(50))**2)).round - 20
log.puts "autopkgtest [%s]: finished\n" % (Time.now + duration).strftime('%Y-%m-%d %H:%M:%S')
File.open(File.join(outdir, 'duration.in'), 'w') do |f|
f.puts(duration)
end
File.open(File.join(outdir, 'log'), 'w') do |f|
f.puts log.string
end
File.open(File.join(outdir, 'exitcode'), 'w') do |f|
f.puts rc
end
File.open(File.join(outdir, 'worker'), 'w') do |f|
f.puts `hostname -s`.strip
end
puts log.string
exit rc
|