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