Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | require 'fileutils' |
| 4 | |
| 5 | FileUtils.mkdir_p('repo') |
| 6 | Dir.chdir('repo') |
| 7 | |
| 8 | def check_command(cmd) |
| 9 | puts cmd |
| 10 | if !system(cmd) |
| 11 | puts "#{cmd} failed" |
| 12 | exit 1 |
| 13 | end |
| 14 | end |
| 15 | |
| 16 | class 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 Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 27 | def normalize_log(log, out) |
Shinichiro Hamaji | 0c8acad | 2015-04-13 01:16:31 +0900 | [diff] [blame] | 28 | # TODO: Fix. |
| 29 | if @name == 'android' |
| 30 | log = log.gsub(/[ \t]+/, ' ') |
Shinichiro Hamaji | b9d22f0 | 2015-04-14 15:36:56 +0900 | [diff] [blame] | 31 | 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 Hamaji | 0c8acad | 2015-04-13 01:16:31 +0900 | [diff] [blame] | 37 | end |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 38 | File.open(out, 'w') do |of| |
| 39 | of.print log |
| 40 | end |
| 41 | log |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 42 | end |
| 43 | |
| 44 | def run |
| 45 | @checkout.call(self) |
| 46 | |
| 47 | Dir.chdir(@name) do |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 48 | @prepare.call(self) |
| 49 | |
Shinichiro Hamaji | a2574f4 | 2015-04-09 22:50:25 +0900 | [diff] [blame] | 50 | [['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 Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 59 | |
| 60 | make_log = File.read('make.log') |
| 61 | kati_log = File.read('kati.log') |
| 62 | kati_log.gsub!(/^\*kati\*.*\n/, '') |
| 63 | |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 64 | make_log = normalize_log(make_log, 'make-normalized.log') |
| 65 | kati_log = normalize_log(kati_log, 'kati-normalized.log') |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 66 | 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 |
| 75 | end |
| 76 | |
| 77 | class 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 |
| 90 | end |
| 91 | |
Shinichiro Hamaji | b40f4a0 | 2015-04-09 18:33:52 +0900 | [diff] [blame] | 92 | class AndroidTestCase < TestCase |
| 93 | def initialize |
| 94 | name = 'android' |
| 95 | checkout = Proc.new{|tc| |
| 96 | FileUtils.mkdir_p(@name) |
Shinichiro Hamaji | 9f25a3b | 2015-04-11 14:47:06 +0900 | [diff] [blame] | 97 | 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 Hamaji | b40f4a0 | 2015-04-09 18:33:52 +0900 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | super(name, checkout, DO_NOTHING, DO_NOTHING, 'dump-products') |
| 116 | end |
| 117 | end |
| 118 | |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 119 | DO_NOTHING = Proc.new{|tc|} |
| 120 | MAKE_CLEAN = Proc.new{|tc| |
| 121 | check_command("make clean > /dev/null") |
| 122 | } |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 123 | CONFIGURE = Proc.new{|tc| |
| 124 | check_command("./configure > /dev/null") |
| 125 | } |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 126 | |
| 127 | TESTS = [ |
| 128 | GitTestCase.new('maloader', |
| 129 | 'https://github.com/shinh/maloader.git', |
| 130 | '5d125933bc6c141bed05c309c2dc0e14ada6f5c7', |
| 131 | DO_NOTHING, |
| 132 | MAKE_CLEAN, |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 133 | ''), |
| 134 | GitTestCase.new('glog', |
| 135 | 'https://github.com/google/glog', |
| 136 | '1b0b08c8dda1659027677966b03a3ff3c488e549', |
| 137 | CONFIGURE, |
| 138 | MAKE_CLEAN, |
| 139 | ''), |
Shinichiro Hamaji | b40f4a0 | 2015-04-09 18:33:52 +0900 | [diff] [blame] | 140 | AndroidTestCase.new(), |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 141 | ] |
| 142 | |
| 143 | fails = [] |
| 144 | TESTS.each do |tc| |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 145 | if !ARGV.empty? |
| 146 | if !ARGV.include?(tc.name) |
| 147 | next |
| 148 | end |
| 149 | end |
| 150 | |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 151 | if !tc.run |
| 152 | fails << tc.name |
| 153 | end |
| 154 | end |
| 155 | |
| 156 | puts |
| 157 | |
| 158 | if fails.empty? |
| 159 | puts "PASS!" |
| 160 | else |
| 161 | puts "=== Failures ===" |
| 162 | fails.each do |n| |
| 163 | puts n |
| 164 | end |
Shinichiro Hamaji | 6990b73 | 2015-04-02 04:02:50 +0900 | [diff] [blame] | 165 | puts |
Shinichiro Hamaji | 21b3d2b | 2015-04-02 03:38:32 +0900 | [diff] [blame] | 166 | |
| 167 | puts "FAIL!" |
| 168 | end |