blob: 41c843701ba405e3ceac5cae2262ba9ee9a86e2e [file] [log] [blame]
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +09001#!/usr/bin/env ruby
2
3require 'fileutils'
4
5FileUtils.mkdir_p('repo')
6Dir.chdir('repo')
7
8def check_command(cmd)
9 puts cmd
10 if !system(cmd)
11 puts "#{cmd} failed"
12 exit 1
13 end
14end
15
16class TestCase
17 attr_reader :name
18
19 def initialize(name, checkout, prepare, clean, target)
20 @name = name
21 @checkout = checkout
22 @prepare = prepare
23 @clean = clean
24 @target = target
25 end
26
Shinichiro Hamaji6990b732015-04-02 04:02:50 +090027 def normalize_log(log, out)
Shinichiro Hamaji0c8acad2015-04-13 01:16:31 +090028 # TODO: Fix.
29 if @name == 'android'
30 log = log.gsub(/[ \t]+/, ' ')
Shinichiro Hamajib9d22f02015-04-14 15:36:56 +090031 log = log.split("\n").sort.join("\n").sub(/ Stop\.$/, '')
32 # This is a completely sane warning from kati for Android.
33 log.sub!(%r(build/core/product_config.mk:152: warning: Unmatched parens: .*\n), '')
34 # Not sure why the order can be inconsistent, but this would be OK.
35 # TODO: Inevestigate.
36 log.gsub!(/(\.mk\.PRODUCT_COPY_FILES := )(.*)/){$1 + $2.split.sort * ' '}
Shinichiro Hamaji0c8acad2015-04-13 01:16:31 +090037 end
Shinichiro Hamaji6990b732015-04-02 04:02:50 +090038 File.open(out, 'w') do |of|
39 of.print log
40 end
41 log
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +090042 end
43
44 def run
45 @checkout.call(self)
46
47 Dir.chdir(@name) do
Shinichiro Hamaji6990b732015-04-02 04:02:50 +090048 @prepare.call(self)
49
Shinichiro Hamajia2574f42015-04-09 22:50:25 +090050 [['make', 'make'], ['kati', '../../kati']].each do |n, cmd|
51 @clean.call(self)
52 print "Running #{n} for #{@name}..."
53 STDOUT.flush
54 started = Time.now
55 system("#{cmd} #{@target} > #{n}.log 2>&1")
56 elapsed = Time.now - started
57 puts " %.2f secs" % elapsed
58 end
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +090059
60 make_log = File.read('make.log')
61 kati_log = File.read('kati.log')
62 kati_log.gsub!(/^\*kati\*.*\n/, '')
63
Shinichiro Hamaji6990b732015-04-02 04:02:50 +090064 make_log = normalize_log(make_log, 'make-normalized.log')
65 kati_log = normalize_log(kati_log, 'kati-normalized.log')
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +090066 if make_log == kati_log
67 puts "#{@name}: OK"
68 return true
69 else
70 puts "#{@name}: FAIL"
71 return false
72 end
73 end
74 end
75end
76
77class GitTestCase < TestCase
78 def initialize(name, repo, rev, prepare, clean, target)
79 checkout = Proc.new{|tc|
80 if !File.exist?(@name)
81 check_command("git clone #{repo}")
82 end
83 Dir.chdir(@name) {
84 check_command("git checkout #{rev}")
85 }
86 }
87
88 super(name, checkout, prepare, clean, target)
89 end
90end
91
Shinichiro Hamajib40f4a02015-04-09 18:33:52 +090092class AndroidTestCase < TestCase
93 def initialize
94 name = 'android'
95 checkout = Proc.new{|tc|
96 FileUtils.mkdir_p(@name)
Shinichiro Hamaji9f25a3b2015-04-11 14:47:06 +090097 md5 = `md5sum android.tgz`
98 need_update = true
99 if File.exist?("#{@name}/STAMP")
100 stamp = File.read("#{@name}/STAMP")
101 if md5 == stamp
102 need_update = false
103 end
104 end
105
106 if need_update
107 check_command("tar -xzf android.tgz")
108 File.open("#{@name}/STAMP.tmp", 'w') do |ofile|
109 ofile.print(md5)
110 end
111 File.rename("#{@name}/STAMP.tmp", "#{@name}/STAMP")
112 end
Shinichiro Hamajib40f4a02015-04-09 18:33:52 +0900113 }
114
115 super(name, checkout, DO_NOTHING, DO_NOTHING, 'dump-products')
116 end
117end
118
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +0900119DO_NOTHING = Proc.new{|tc|}
120MAKE_CLEAN = Proc.new{|tc|
121 check_command("make clean > /dev/null")
122}
Shinichiro Hamaji6990b732015-04-02 04:02:50 +0900123CONFIGURE = Proc.new{|tc|
124 check_command("./configure > /dev/null")
125}
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +0900126
127TESTS = [
128 GitTestCase.new('maloader',
129 'https://github.com/shinh/maloader.git',
130 '5d125933bc6c141bed05c309c2dc0e14ada6f5c7',
131 DO_NOTHING,
132 MAKE_CLEAN,
Shinichiro Hamaji6990b732015-04-02 04:02:50 +0900133 ''),
134 GitTestCase.new('glog',
135 'https://github.com/google/glog',
136 '1b0b08c8dda1659027677966b03a3ff3c488e549',
137 CONFIGURE,
138 MAKE_CLEAN,
139 ''),
Shinichiro Hamajib40f4a02015-04-09 18:33:52 +0900140 AndroidTestCase.new(),
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +0900141]
142
143fails = []
144TESTS.each do |tc|
Shinichiro Hamaji6990b732015-04-02 04:02:50 +0900145 if !ARGV.empty?
146 if !ARGV.include?(tc.name)
147 next
148 end
149 end
150
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +0900151 if !tc.run
152 fails << tc.name
153 end
154end
155
156puts
157
158if fails.empty?
159 puts "PASS!"
160else
161 puts "=== Failures ==="
162 fails.each do |n|
163 puts n
164 end
Shinichiro Hamaji6990b732015-04-02 04:02:50 +0900165 puts
Shinichiro Hamaji21b3d2b2015-04-02 03:38:32 +0900166
167 puts "FAIL!"
168end