-
Notifications
You must be signed in to change notification settings - Fork 2
/
findflake.rb
executable file
·100 lines (87 loc) · 2.91 KB
/
findflake.rb
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
#!/usr/bin/env ruby
# Some funky metaprogramming to find a high performance JSON library.
# Once one is find bind a callable to its parse / load method
# If none of the custom ones is found use the stdlib json gem which is actually pretty okay.
jsonlibs = %w[simdjson oj]
json_parser = nil
begin
while lib = jsonlibs.shift
require lib
json_parser = case lib
when "simdjson"
Simdjson.method :parse
when "oj"
Oj.method :load
end
break
end
rescue LoadError
retry
end
if json_parser.nil?
require "json"
json_parser = JSON.method :load
end
require "open-uri"
require "optparse"
require "ostruct"
require "zlib"
options = OpenStruct.new
optparser = OptionParser.new do |o|
o.banner = "Usage: #{$0} [-d DOMAIN_NAME] [-j JOB_NAME] PATTERN .."
o.on "-d", "--domain DOMAIN_NAME", "The domain name of the test service. Probably ci.ros2.org or build.osrfoundation.org" do |domain|
options.domain = domain
end
o.on "-j", "--job JOB_NAME", "The job name to search" do |job|
options.job = job
end
end
optparser.parse!(ARGV)
options.pattern = Regexp.union *ARGV
TESTDB_DIR = ENV['TESTDB_DIR'] || File.join(ENV['HOME'], 'osrf', 'testdb')
unless Dir.exist? File.join(TESTDB_DIR, options.domain)
STDERR.puts "Unable to find test data for #{options.domain}"
exit(1)
end
unless Dir.exist? File.join(TESTDB_DIR, options.domain, options.job)
STDERR.puts "Unable to find test data for #{options.domain}/#{options.job}"
exit(1)
end
total_runs = 0
matching_failed_cases = Hash.new {|hash, key| hash[key] = [] }
job_dir = File.join(TESTDB_DIR, options.domain, options.job)
Dir.each_child(job_dir).sort_by{|build_id| build_id.to_i}.reverse.each do |build_dir|
build_id = build_dir.to_i
filename = File.join(job_dir, build_dir, "testreport.json.gz")
unless File.exist? filename
#STDERR.puts "Result file missing for #{build_id}"
next
end
gzfile = Zlib::GzipReader.open(filename)
begin
report = json_parser.call(gzfile.read)
rescue => e
STDERR.puts("ERROR parsing #{build_id}: #{e}")
next
end
total_runs += 1
gzfile.close
report["suites"].each do |suite|
suite["cases"].each do |testcase|
next if %[PASSED FIXED SKIPPED].include? testcase["status"]
complete_fail_name = testcase["className"] + "." + testcase["name"]
if options.pattern.match complete_fail_name then
matching_failed_cases[build_id] << complete_fail_name
end
end
end
end
matching_failed_cases.keys.sort.reverse.each do |build_id|
puts "Matching failures in #{options.domain}/#{options.job}##{build_id}"
matching_failed_cases[build_id].each do |name|
puts "\t" + name
end
end
puts("Total amount of builds checked: #{total_runs}")
puts("Total amount of builds matching pattern: #{matching_failed_cases.size}")
puts("Flakyness percentage: #{(matching_failed_cases.size.to_f/total_runs)*100.0}")