Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Shinichiro Hamaji | b69bf8a | 2015-06-10 14:52:06 +0900 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2015 Google Inc. All rights reserved |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 16 | |
| 17 | require 'fileutils' |
| 18 | |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 19 | while true |
| 20 | if ARGV[0] == '-s' |
| 21 | test_serialization = true |
| 22 | ARGV.shift |
| 23 | elsif ARGV[0] == '-c' |
| 24 | ckati = true |
| 25 | ARGV.shift |
| 26 | ENV['KATI_VARIANT'] = 'c' |
| 27 | elsif ARGV[0] == '-n' |
| 28 | via_ninja = true |
| 29 | ARGV.shift |
Colin Cross | df11044 | 2015-10-02 11:06:49 -0700 | [diff] [blame] | 30 | ENV['NINJA_STATUS'] = 'NINJACMD: ' |
Shinichiro Hamaji | 8562057 | 2015-10-03 11:25:15 +0900 | [diff] [blame] | 31 | elsif ARGV[0] == '-a' |
| 32 | gen_all_targets = true |
| 33 | ARGV.shift |
Shinichiro Hamaji | 221a16b | 2015-09-10 12:40:14 +0900 | [diff] [blame] | 34 | elsif ARGV[0] == '-v' |
| 35 | show_failing = true |
| 36 | ARGV.shift |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 37 | else |
| 38 | break |
| 39 | end |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 40 | end |
| 41 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 42 | def get_output_filenames |
| 43 | files = Dir.glob('*') |
| 44 | files.delete('Makefile') |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 45 | files.delete('build.ninja') |
| 46 | files.delete('ninja.sh') |
Shinichiro Hamaji | 65489db | 2015-06-29 20:44:26 +0900 | [diff] [blame] | 47 | files.delete('gmon.out') |
Shinichiro Hamaji | 91571ac | 2015-09-07 18:24:00 +0900 | [diff] [blame] | 48 | files.delete('submake') |
Shinichiro Hamaji | b674d58 | 2015-04-28 03:40:57 +0900 | [diff] [blame] | 49 | files.reject!{|f|f =~ /\.json$/} |
Fumitoshi Ukai | 6450d0f | 2015-07-10 16:34:06 +0900 | [diff] [blame] | 50 | files.reject!{|f|f =~ /^kati\.*/} |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 51 | files |
| 52 | end |
| 53 | |
| 54 | def cleanup |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 55 | (get_output_filenames + Dir.glob('.*')).each do |fname| |
| 56 | next if fname == '.' || fname == '..' |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 57 | FileUtils.rm_rf fname |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 58 | end |
| 59 | end |
| 60 | |
Shinichiro Hamaji | 74a6600 | 2015-04-27 16:42:30 +0900 | [diff] [blame] | 61 | def move_circular_dep(l) |
| 62 | # We don't care when circular dependency detection happens. |
| 63 | circ = '' |
| 64 | while l.sub!(/Circular .* dropped\.\n/, '') do |
| 65 | circ += $& |
| 66 | end |
| 67 | circ + l |
| 68 | end |
| 69 | |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 70 | expected_failures = [] |
| 71 | unexpected_passes = [] |
| 72 | failures = [] |
| 73 | passes = [] |
| 74 | |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 75 | if !ARGV.empty? |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 76 | test_files = ARGV.map do |test| |
| 77 | "testcase/#{File.basename(test)}" |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 78 | end |
| 79 | else |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 80 | test_files = Dir.glob('testcase/*.mk').sort |
| 81 | test_files += Dir.glob('testcase/*.sh').sort |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 82 | end |
| 83 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 84 | def run_in_testdir(test_filename) |
| 85 | c = File.read(test_filename) |
| 86 | name = File.basename(test_filename) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 87 | dir = "out/#{name}" |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 88 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 89 | FileUtils.mkdir_p(dir) |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 90 | Dir.glob("#{dir}/*").each do |fname| |
| 91 | FileUtils.rm_rf(fname) |
| 92 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 93 | |
| 94 | Dir.chdir(dir) do |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 95 | yield name |
| 96 | end |
| 97 | end |
| 98 | |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 99 | def normalize_ninja_log(log, mk) |
Colin Cross | df11044 | 2015-10-02 11:06:49 -0700 | [diff] [blame] | 100 | log.gsub!(/^NINJACMD: .*\n/, '') |
Shinichiro Hamaji | cecc358 | 2015-07-28 15:56:59 +0900 | [diff] [blame] | 101 | log.gsub!(/^ninja: no work to do\.\n/, '') |
Fumitoshi Ukai | 786846d | 2015-07-28 18:08:47 +0900 | [diff] [blame] | 102 | log.gsub!(/^ninja: error: (.*, needed by .*),.*/, |
| 103 | '*** No rule to make target \\1.') |
Dan Willemsen | f3a4ced | 2015-08-25 14:22:35 -0700 | [diff] [blame] | 104 | log.gsub!(/^ninja: warning: multiple rules generate (.*)\. builds involving this target will not be correct.*$/, |
Shinichiro Hamaji | 3c60c12 | 2015-10-05 16:26:38 +0900 | [diff] [blame] | 105 | 'ninja: warning: multiple rules generate \\1.') |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 106 | if mk =~ /err_error_in_recipe.mk/ |
| 107 | # This test expects ninja fails. Strip ninja specific error logs. |
| 108 | log.gsub!(/^FAILED: .*\n/, '') |
| 109 | log.gsub!(/^ninja: .*\n/, '') |
| 110 | end |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 111 | log |
| 112 | end |
| 113 | |
Dan Willemsen | f3a4ced | 2015-08-25 14:22:35 -0700 | [diff] [blame] | 114 | def normalize_make_log(expected, mk, via_ninja) |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 115 | expected.gsub!(/^make(?:\[\d+\])?: (Entering|Leaving) directory.*\n/, '') |
| 116 | expected.gsub!(/^make(?:\[\d+\])?: /, '') |
| 117 | expected = move_circular_dep(expected) |
| 118 | |
| 119 | # Normalizations for old/new GNU make. |
| 120 | expected.gsub!(/[`'"]/, '"') |
| 121 | expected.gsub!(/ (?:commands|recipe) for target /, |
| 122 | ' commands for target ') |
| 123 | expected.gsub!(/ (?:commands|recipe) commences /, |
| 124 | ' commands commence ') |
| 125 | expected.gsub!(' (did you mean TAB instead of 8 spaces?)', '') |
| 126 | expected.gsub!('Extraneous text after', 'extraneous text after') |
| 127 | # Not sure if this is useful. |
| 128 | expected.gsub!(/\s+Stop\.$/, '') |
| 129 | # GNU make 4.0 has this output. |
| 130 | expected.gsub!(/Makefile:\d+: commands for target ".*?" failed\n/, '') |
| 131 | # We treat some warnings as errors. |
Shinichiro Hamaji | 3498f34 | 2015-08-11 14:23:12 +0900 | [diff] [blame] | 132 | expected.gsub!(/^\/bin\/sh: line 0: /, '') |
Dan Willemsen | f3a4ced | 2015-08-25 14:22:35 -0700 | [diff] [blame] | 133 | # We print out some ninja warnings in some tests to match what we expect |
| 134 | # ninja to produce. Remove them if we're not testing ninja. |
| 135 | if !via_ninja |
| 136 | expected.gsub!(/^ninja: warning: .*\n/, '') |
| 137 | end |
Shinichiro Hamaji | b7be8f1 | 2015-10-05 16:29:58 +0900 | [diff] [blame^] | 138 | # Normalization for "include foo" with C++ kati. |
| 139 | expected.gsub!(/(: )(\S+): (No such file or directory)\n\*\*\* No rule to make target "\2"./, '\1\2: \3') |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 140 | |
| 141 | expected |
| 142 | end |
| 143 | |
| 144 | def normalize_kati_log(output) |
| 145 | output = move_circular_dep(output) |
| 146 | # kati specific log messages. |
| 147 | output.gsub!(/^\*kati\*.*\n/, '') |
Fumitoshi Ukai | a43b96f | 2015-07-17 19:54:21 +0900 | [diff] [blame] | 148 | output.gsub!(/^c?kati: /, '') |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 149 | output.gsub!(/[`'"]/, '"') |
Fumitoshi Ukai | 08c1e94 | 2015-07-15 16:38:07 +0900 | [diff] [blame] | 150 | output.gsub!(/\/bin\/sh: ([^:]*): command not found/, |
| 151 | "\\1: Command not found") |
Shinichiro Hamaji | a06bee9 | 2015-08-05 17:13:05 +0900 | [diff] [blame] | 152 | output.gsub!(/.*: warning for parse error in an unevaluated line: .*\n/, '') |
Shinichiro Hamaji | 3498f34 | 2015-08-11 14:23:12 +0900 | [diff] [blame] | 153 | output.gsub!(/^FindEmulator: /, '') |
Fumitoshi Ukai | 2c6eff6 | 2015-08-11 17:50:56 +0900 | [diff] [blame] | 154 | output.gsub!(/^\/bin\/sh: line 0: /, '') |
Fumitoshi Ukai | b0ede7d | 2015-07-29 10:19:05 +0900 | [diff] [blame] | 155 | output.gsub!(/ (\.\/+)+kati\.\S+/, '') # kati log files in find_command.mk |
| 156 | output.gsub!(/ (\.\/+)+test\S+.json/, '') # json files in find_command.mk |
Shinichiro Hamaji | b7be8f1 | 2015-10-05 16:29:58 +0900 | [diff] [blame^] | 157 | # Normalization for "include foo" with Go kati. |
| 158 | output.gsub!(/(: )open (\S+): n(o such file or directory)\nNOTE:.*/, |
| 159 | "\\1\\2: N\\3") |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 160 | output |
| 161 | end |
| 162 | |
| 163 | run_make_test = proc do |mk| |
| 164 | c = File.read(mk) |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 165 | expected_failure = false |
Fumitoshi Ukai | bfabe63 | 2015-07-28 15:26:56 +0900 | [diff] [blame] | 166 | if c =~ /\A# TODO(?:\(([-a-z|]+)\))?/ |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 167 | if $1 |
| 168 | todos = $1.split('|') |
| 169 | if todos.include?('go') && !ckati |
| 170 | expected_failure = true |
| 171 | end |
| 172 | if todos.include?('c') && ckati |
| 173 | expected_failure = true |
| 174 | end |
Fumitoshi Ukai | bfabe63 | 2015-07-28 15:26:56 +0900 | [diff] [blame] | 175 | if todos.include?('go-ninja') && !ckati && via_ninja |
| 176 | expected_failure = true |
| 177 | end |
| 178 | if todos.include?('c-ninja') && ckati && via_ninja |
| 179 | expected_failure = true |
| 180 | end |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 181 | if todos.include?('ninja') && via_ninja |
| 182 | expected_failure = true |
| 183 | end |
| 184 | else |
| 185 | expected_failure = true |
Shinichiro Hamaji | e919d00 | 2015-06-26 01:15:55 +0900 | [diff] [blame] | 186 | end |
| 187 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 188 | |
| 189 | run_in_testdir(mk) do |name| |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 190 | File.open("Makefile", 'w') do |ofile| |
| 191 | ofile.print(c) |
| 192 | end |
Shinichiro Hamaji | 91571ac | 2015-09-07 18:24:00 +0900 | [diff] [blame] | 193 | File.symlink('../../testcase/submake', 'submake') |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 194 | |
| 195 | expected = '' |
| 196 | output = '' |
| 197 | |
Shinichiro Hamaji | 491e73f | 2015-04-07 12:41:59 +0900 | [diff] [blame] | 198 | testcases = c.scan(/^test\d*/).sort.uniq |
Shinichiro Hamaji | 497754d | 2015-03-31 02:02:11 +0900 | [diff] [blame] | 199 | if testcases.empty? |
| 200 | testcases = [''] |
| 201 | end |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 202 | |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 203 | is_silent_test = mk =~ /\/submake_/ |
| 204 | |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 205 | cleanup |
| 206 | testcases.each do |tc| |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 207 | cmd = 'make' |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 208 | if via_ninja || is_silent_test |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 209 | cmd += ' -s' |
| 210 | end |
| 211 | cmd += " #{tc} 2>&1" |
| 212 | res = `#{cmd}` |
Dan Willemsen | f3a4ced | 2015-08-25 14:22:35 -0700 | [diff] [blame] | 213 | res = normalize_make_log(res, mk, via_ninja) |
Shinichiro Hamaji | 74a6600 | 2015-04-27 16:42:30 +0900 | [diff] [blame] | 214 | expected += "=== #{tc} ===\n" + res |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 215 | expected_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 216 | expected += "\n=== FILES ===\n#{expected_files * "\n"}\n" |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 217 | end |
| 218 | |
| 219 | cleanup |
| 220 | testcases.each do |tc| |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 221 | json = "#{tc.empty? ? 'test' : tc}" |
Fumitoshi Ukai | 0547db6 | 2015-07-29 16:20:59 +0900 | [diff] [blame] | 222 | cmd = "../../kati -save_json=#{json}.json -log_dir=. --use_find_emulator" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 223 | if ckati |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 224 | cmd = "../../ckati --use_find_emulator" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 225 | end |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 226 | if via_ninja |
| 227 | cmd += ' --ninja' |
| 228 | end |
Shinichiro Hamaji | 8562057 | 2015-10-03 11:25:15 +0900 | [diff] [blame] | 229 | if gen_all_targets |
| 230 | if !ckati || !via_ninja |
| 231 | raise "-a should be used with -c -n" |
| 232 | end |
| 233 | cmd += ' --gen_all_targets' |
| 234 | end |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 235 | if is_silent_test |
| 236 | cmd += ' -s' |
| 237 | end |
Shinichiro Hamaji | 6ff74ce | 2015-10-03 11:58:35 +0900 | [diff] [blame] | 238 | if !gen_all_targets || mk =~ /makecmdgoals/ |
| 239 | cmd += " #{tc}" |
| 240 | end |
| 241 | cmd += " 2>&1" |
Shinichiro Hamaji | b674d58 | 2015-04-28 03:40:57 +0900 | [diff] [blame] | 242 | res = IO.popen(cmd, 'r:binary', &:read) |
Fumitoshi Ukai | 39837dd | 2015-07-28 12:25:56 +0900 | [diff] [blame] | 243 | if via_ninja && File.exist?('build.ninja') && File.exists?('ninja.sh') |
Shinichiro Hamaji | 8562057 | 2015-10-03 11:25:15 +0900 | [diff] [blame] | 244 | cmd = './ninja.sh -j1 -v' |
| 245 | if gen_all_targets |
| 246 | cmd += " #{tc}" |
| 247 | end |
| 248 | cmd += ' 2>&1' |
| 249 | log = IO.popen(cmd, 'r:binary', &:read) |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 250 | res += normalize_ninja_log(log, mk) |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 251 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 252 | res = normalize_kati_log(res) |
Shinichiro Hamaji | 42f42e1 | 2015-04-13 14:26:45 +0900 | [diff] [blame] | 253 | output += "=== #{tc} ===\n" + res |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 254 | output_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 255 | output += "\n=== FILES ===\n#{output_files * "\n"}\n" |
| 256 | end |
| 257 | |
| 258 | File.open('out.make', 'w'){|ofile|ofile.print(expected)} |
| 259 | File.open('out.kati', 'w'){|ofile|ofile.print(output)} |
| 260 | |
Shinichiro Hamaji | 74c832f | 2015-04-09 14:54:39 +0900 | [diff] [blame] | 261 | if expected =~ /FAIL/ |
| 262 | puts %Q(#{name} has a string "FAIL" in its expectation) |
| 263 | exit 1 |
| 264 | end |
| 265 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 266 | if expected != output |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 267 | if expected_failure |
| 268 | puts "#{name}: FAIL (expected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 269 | expected_failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 270 | else |
| 271 | puts "#{name}: FAIL" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 272 | failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 273 | end |
Shinichiro Hamaji | 7f3a870 | 2015-09-11 15:37:02 +0900 | [diff] [blame] | 274 | if !expected_failure || show_failing |
Shinichiro Hamaji | 221a16b | 2015-09-10 12:40:14 +0900 | [diff] [blame] | 275 | puts `diff -u out.make out.kati` |
| 276 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 277 | else |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 278 | if expected_failure |
| 279 | puts "#{name}: PASS (unexpected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 280 | unexpected_passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 281 | else |
| 282 | puts "#{name}: PASS" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 283 | passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 284 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 285 | end |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 286 | |
Shinichiro Hamaji | e666ac8 | 2015-04-28 04:18:13 +0900 | [diff] [blame] | 287 | if name !~ /^err_/ && test_serialization && !expected_failure |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 288 | testcases.each do |tc| |
| 289 | json = "#{tc.empty? ? 'test' : tc}" |
Fumitoshi Ukai | 6450d0f | 2015-07-10 16:34:06 +0900 | [diff] [blame] | 290 | cmd = "../../kati -save_json=#{json}_2.json -load_json=#{json}.json -n -log_dir=. #{tc} 2>&1" |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 291 | res = IO.popen(cmd, 'r:binary', &:read) |
| 292 | if !File.exist?("#{json}.json") || !File.exist?("#{json}_2.json") |
| 293 | puts "#{name}##{json}: Serialize failure (not exist)" |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 294 | puts res |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 295 | else |
| 296 | json1 = File.read("#{json}.json") |
| 297 | json2 = File.read("#{json}_2.json") |
| 298 | if json1 != json2 |
| 299 | puts "#{name}##{json}: Serialize failure" |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 300 | puts res |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 301 | end |
| 302 | end |
| 303 | end |
| 304 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 305 | end |
| 306 | end |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 307 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 308 | run_shell_test = proc do |sh| |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 309 | is_ninja_test = sh =~ /\/ninja_/ |
| 310 | if is_ninja_test && (!ckati || !via_ninja) |
| 311 | next |
| 312 | end |
| 313 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 314 | run_in_testdir(sh) do |name| |
| 315 | cleanup |
| 316 | cmd = "sh ../../#{sh} make" |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 317 | if is_ninja_test |
| 318 | cmd += ' -s' |
| 319 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 320 | expected = IO.popen(cmd, 'r:binary', &:read) |
| 321 | cleanup |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 322 | |
| 323 | if is_ninja_test |
| 324 | if ckati |
Shinichiro Hamaji | a88c1c2 | 2015-07-31 12:29:48 +0900 | [diff] [blame] | 325 | cmd = "sh ../../#{sh} ../../ckati --ninja --regen" |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 326 | else |
| 327 | next |
| 328 | end |
| 329 | else |
| 330 | if ckati |
| 331 | cmd = "sh ../../#{sh} ../../ckati" |
| 332 | else |
| 333 | cmd = "sh ../../#{sh} ../../kati --use_cache -log_dir=." |
| 334 | end |
| 335 | end |
| 336 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 337 | output = IO.popen(cmd, 'r:binary', &:read) |
| 338 | |
Dan Willemsen | f3a4ced | 2015-08-25 14:22:35 -0700 | [diff] [blame] | 339 | expected = normalize_make_log(expected, sh, is_ninja_test) |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 340 | output = normalize_kati_log(output) |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 341 | if is_ninja_test |
| 342 | output = normalize_ninja_log(output, sh) |
Shinichiro Hamaji | 5995660 | 2015-08-11 15:35:55 +0900 | [diff] [blame] | 343 | output.gsub!(/No need to regenerate ninja file\n/, '') |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 344 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 345 | File.open('out.make', 'w'){|ofile|ofile.print(expected)} |
| 346 | File.open('out.kati', 'w'){|ofile|ofile.print(output)} |
| 347 | |
| 348 | if expected != output |
| 349 | puts "#{name}: FAIL" |
Shinichiro Hamaji | 39e6240 | 2015-05-20 19:34:58 +0900 | [diff] [blame] | 350 | puts `diff -u out.make out.kati` |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 351 | failures << name |
| 352 | else |
| 353 | puts "#{name}: PASS" |
| 354 | passes << name |
| 355 | end |
| 356 | end |
| 357 | end |
| 358 | |
| 359 | test_files.each do |test| |
| 360 | if /\.mk$/ =~ test |
| 361 | run_make_test.call(test) |
| 362 | elsif /\.sh$/ =~ test |
| 363 | run_shell_test.call(test) |
| 364 | else |
| 365 | raise "Unknown test type: #{test}" |
| 366 | end |
| 367 | end |
| 368 | |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 369 | puts |
| 370 | |
| 371 | if !expected_failures.empty? |
| 372 | puts "=== Expected failures ===" |
| 373 | expected_failures.each do |n| |
| 374 | puts n |
| 375 | end |
| 376 | end |
| 377 | |
| 378 | if !unexpected_passes.empty? |
| 379 | puts "=== Unexpected passes ===" |
| 380 | unexpected_passes.each do |n| |
| 381 | puts n |
| 382 | end |
| 383 | end |
| 384 | |
| 385 | if !failures.empty? |
| 386 | puts "=== Failures ===" |
| 387 | failures.each do |n| |
| 388 | puts n |
| 389 | end |
| 390 | end |
| 391 | |
| 392 | puts |
| 393 | |
| 394 | if !unexpected_passes.empty? || !failures.empty? |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 395 | puts "FAIL! (#{failures.size + unexpected_passes.size} fails #{passes.size} passes)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 396 | else |
| 397 | puts 'PASS!' |
| 398 | end |