Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // The following set of variables should be set by the caller that | 5 // The following set of variables should be set by the caller that |
| 6 // #sources this file. | 6 // #sources this file. |
| 7 /** Whether to include elapsed time. */ | 7 /** Whether to include elapsed time. */ |
| 8 | 8 |
| 9 part of test_controller; | 9 part of test_controller; |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 if (summarize) { | 121 if (summarize) { |
| 122 printSummary(testfile, passCount, failCount, errorCount); | 122 printSummary(testfile, passCount, failCount, errorCount); |
| 123 } | 123 } |
| 124 notifyDone(failCount > 0 ? -1 : 0); | 124 notifyDone(failCount > 0 ? -1 : 0); |
| 125 } | 125 } |
| 126 | 126 |
| 127 runTextLayoutTest(testNum) { | 127 runTextLayoutTest(testNum) { |
| 128 var url = '$baseUrl?test=$testNum'; | 128 var url = '$baseUrl?test=$testNum'; |
| 129 var stdout = new List(); | 129 var stdout = new List(); |
| 130 start = new Date.now(); | 130 start = new Date.now(); |
| 131 var process = Process.start(drt, [url]); | 131 Process.start(drt, [url]).then((process) { |
| 132 StringInputStream stdoutStringStream = new StringInputStream(process.stdout); | 132 StringInputStream stdoutStringStream = |
| 133 stdoutStringStream.onLine = () { | 133 new StringInputStream(process.stdout); |
| 134 if (stdoutStringStream.closed) return; | 134 stdoutStringStream.onLine = () { |
| 135 var line = stdoutStringStream.readLine(); | 135 if (stdoutStringStream.closed) return; |
| 136 while (null != line) { | 136 var line = stdoutStringStream.readLine(); |
| 137 stdout.add(line); | 137 while (null != line) { |
| 138 line = stdoutStringStream.readLine(); | 138 stdout.add(line); |
| 139 } | 139 line = stdoutStringStream.readLine(); |
| 140 }; | 140 } |
| 141 process.onExit = (exitCode) { | 141 }; |
| 142 process.close(); | 142 process.onExit = (exitCode) { |
| 143 if (stdout.length > 0 && stdout[stdout.length-1].startsWith('#EOF')) { | 143 process.close(); |
| 144 stdout.removeLast(); | 144 if (stdout.length > 0 && stdout[stdout.length-1].startsWith('#EOF')) { |
| 145 } | 145 stdout.removeLast(); |
| 146 var done = false; | 146 } |
| 147 var i = 0; | 147 var done = false; |
| 148 var label = null; | 148 var i = 0; |
| 149 var labelMarker = 'CONSOLE MESSAGE: #TEST '; | 149 var label = null; |
| 150 var contentMarker = 'layer at '; | 150 var labelMarker = 'CONSOLE MESSAGE: #TEST '; |
| 151 while (i < stdout.length) { | 151 var contentMarker = 'layer at '; |
| 152 if (label == null && stdout[i].startsWith(labelMarker)) { | 152 while (i < stdout.length) { |
| 153 label = stdout[i].substring(labelMarker.length); | 153 if (label == null && stdout[i].startsWith(labelMarker)) { |
| 154 if (label == 'NONEXISTENT') { | 154 label = stdout[i].substring(labelMarker.length); |
| 155 complete(); | 155 if (label == 'NONEXISTENT') { |
| 156 } | 156 complete(); |
| 157 } else if (stdout[i].startsWith(contentMarker)) { | |
| 158 if (label == null) { | |
| 159 complete(); | |
| 160 } | |
| 161 var expectedFileName = | |
| 162 '$sourceDir${Platform.pathSeparator}' | |
| 163 '${label.replaceAll("###", "_") | |
| 164 .replaceAll(const RegExp("[^A-Za-z0-9]"),"_")}.txt'; | |
| 165 var expected = new File(expectedFileName); | |
| 166 if (regenerate) { | |
| 167 var ostream = expected.openOutputStream(FileMode.WRITE); | |
| 168 while (i < stdout.length) { | |
| 169 ostream.writeString(stdout[i]); | |
| 170 ostream.writeString('\n'); | |
| 171 i++; | |
| 172 } | 157 } |
| 173 ostream.close(); | 158 } else if (stdout[i].startsWith(contentMarker)) { |
| 174 pass(start, label); | 159 if (label == null) { |
| 175 } else if (!expected.existsSync()) { | 160 complete(); |
| 176 fail(start, label, 'No expectation file'); | 161 } |
| 177 } else { | 162 var expectedFileName = |
| 178 var lines = expected.readAsLinesSync(); | 163 '$sourceDir${Platform.pathSeparator}' |
| 179 var actualLength = stdout.length - i; | 164 '${label.replaceAll("###", "_") |
| 180 var compareCount = min(lines.length, actualLength); | 165 .replaceAll(const RegExp("[^A-Za-z0-9]"),"_")}.txt'; |
|
ricow1
2012/10/11 17:27:34
indentaion seems random
Emily Fortuna
2012/10/11 18:23:08
just -1 space
Mads Ager (google)
2012/10/12 08:44:46
Done. It was off in the original too.
| |
| 181 var match = true; | 166 var expected = new File(expectedFileName); |
| 182 for (var j = 0; j < compareCount; j++) { | 167 if (regenerate) { |
| 183 if (lines[j] != stdout[i + j]) { | 168 var ostream = expected.openOutputStream(FileMode.WRITE); |
| 184 fail(start, label, 'Expectation differs at line ${j + 1}'); | 169 while (i < stdout.length) { |
| 185 match = false; | 170 ostream.writeString(stdout[i]); |
| 186 break; | 171 ostream.writeString('\n'); |
| 172 i++; | |
| 173 } | |
| 174 ostream.close(); | |
| 175 pass(start, label); | |
| 176 } else if (!expected.existsSync()) { | |
| 177 fail(start, label, 'No expectation file'); | |
| 178 } else { | |
| 179 var lines = expected.readAsLinesSync(); | |
| 180 var actualLength = stdout.length - i; | |
| 181 var compareCount = min(lines.length, actualLength); | |
| 182 var match = true; | |
| 183 for (var j = 0; j < compareCount; j++) { | |
| 184 if (lines[j] != stdout[i + j]) { | |
| 185 fail(start, label, 'Expectation differs at line ${j + 1}'); | |
| 186 match = false; | |
| 187 break; | |
| 188 } | |
| 189 } | |
| 190 if (match) { | |
| 191 if (lines.length != actualLength) { | |
| 192 fail(start, label, 'Expectation file has wrong length'); | |
| 193 } else { | |
| 194 pass(start, label); | |
| 195 } | |
| 187 } | 196 } |
| 188 } | 197 } |
| 189 if (match) { | 198 done = true; |
| 190 if (lines.length != actualLength) { | 199 break; |
| 191 fail(start, label, 'Expectation file has wrong length'); | |
| 192 } else { | |
| 193 pass(start, label); | |
| 194 } | |
| 195 } | |
| 196 } | 200 } |
| 197 done = true; | 201 i++; |
| 198 break; | |
| 199 } | 202 } |
| 200 i++; | 203 if (label != null) { |
| 201 } | 204 if (!done) error(start, label, 'Failed to parse output'); |
| 202 if (label != null) { | 205 runTextLayoutTest(testNum + 1); |
| 203 if (!done) error(start, label, 'Failed to parse output'); | 206 } |
| 204 runTextLayoutTest(testNum + 1); | 207 }; |
| 205 } | 208 }); |
| 206 }; | |
| 207 } | 209 } |
| 208 | 210 |
| 209 runPixelLayoutTest(int testNum) { | 211 runPixelLayoutTest(int testNum) { |
| 210 var url = '$baseUrl?test=$testNum'; | 212 var url = '$baseUrl?test=$testNum'; |
| 211 var stdout = new List(); | 213 var stdout = new List(); |
| 212 start = new Date.now(); | 214 start = new Date.now(); |
| 213 var process = Process.start(drt, ["$url'-p"]); | 215 Process.start(drt, ["$url'-p"]).then((process) { |
| 214 ListInputStream stdoutStream = process.stdout; | 216 ListInputStream stdoutStream = process.stdout; |
| 215 stdoutStream.onData = () { | 217 stdoutStream.onData = () { |
| 216 if (!stdoutStream.closed) { | 218 if (!stdoutStream.closed) { |
| 217 var data = stdoutStream.read(); | 219 var data = stdoutStream.read(); |
| 218 stdout.addAll(data); | 220 stdout.addAll(data); |
| 219 } | 221 } |
| 220 }; | 222 }; |
| 221 stdoutStream.onError = (e) { | 223 stdoutStream.onError = (e) { |
| 222 print(e); | 224 print(e); |
| 223 }; | 225 }; |
| 224 process.onExit = (exitCode) { | 226 process.onExit = (exitCode) { |
| 225 stdout.addAll(process.stdout.read()); | 227 stdout.addAll(process.stdout.read()); |
| 226 process.close(); | 228 process.close(); |
| 227 var labelMarker = 'CONSOLE MESSAGE: #TEST '; | 229 var labelMarker = 'CONSOLE MESSAGE: #TEST '; |
| 228 var contentMarker = 'Content-Length: '; | 230 var contentMarker = 'Content-Length: '; |
| 229 var eol = '\n'.charCodeAt(0); | 231 var eol = '\n'.charCodeAt(0); |
| 230 var pos = -1; | 232 var pos = -1; |
| 231 var label = null; | 233 var label = null; |
| 232 var done = false; | 234 var done = false; |
| 233 | 235 |
| 234 while(pos < stdout.length) { | 236 while(pos < stdout.length) { |
| 235 var idx = stdout.indexOf(eol, ++pos); | 237 var idx = stdout.indexOf(eol, ++pos); |
| 236 if (idx < 0) break; | 238 if (idx < 0) break; |
| 237 StringBuffer sb = new StringBuffer(); | 239 StringBuffer sb = new StringBuffer(); |
| 238 for (var i = pos; i < idx; i++) { | 240 for (var i = pos; i < idx; i++) { |
| 239 sb.addCharCode(stdout[i]); | 241 sb.addCharCode(stdout[i]); |
| 242 } | |
| 243 var line = sb.toString(); | |
| 244 | |
| 245 if (label == null && line.startsWith(labelMarker)) { | |
| 246 label = line.substring(labelMarker.length); | |
| 247 if (label == 'NONEXISTENT') { | |
| 248 complete(); | |
| 249 } | |
| 250 } else if (line.startsWith(contentMarker)) { | |
| 251 if (label == null) { | |
| 252 complete(); | |
| 253 } | |
| 254 var len = int.parse(line.substring(contentMarker.length)); | |
| 255 pos = idx + 1; | |
| 256 var expectedFileName = | |
| 257 '$sourceDir${Platform.pathSeparator}' | |
| 258 '${label.replaceAll("###","_"). | |
| 259 replaceAll(const RegExp("[^A-Za-z0-9]"),"_")}.png'; | |
| 260 var expected = new File(expectedFileName); | |
| 261 if (regenerate) { | |
| 262 var ostream = expected.openOutputStream(FileMode.WRITE); | |
| 263 ostream.writeFrom(stdout, pos, len); | |
| 264 ostream.close(); | |
| 265 pass(start, label); | |
| 266 } else if (!expected.existsSync()) { | |
| 267 fail(start, label, 'No expectation file'); | |
| 268 } else { | |
| 269 var bytes = expected.readAsBytesSync(); | |
| 270 if (bytes.length != len) { | |
| 271 fail(start, label, 'Expectation file has wrong length'); | |
| 272 } else { | |
| 273 var match = true; | |
| 274 for (var j = 0; j < len; j++) { | |
| 275 if (bytes[j] != stdout[pos + j]) { | |
| 276 fail(start, label, 'Expectation differs at byte ${j + 1}'); | |
| 277 match = false; | |
| 278 break; | |
| 279 } | |
| 280 } | |
| 281 if (match) pass(start, label); | |
| 282 } | |
| 283 } | |
| 284 done = true; | |
| 285 break; | |
| 286 } | |
| 287 pos = idx; | |
| 240 } | 288 } |
| 241 var line = sb.toString(); | 289 if (label != null) { |
| 242 | 290 if (!done) error(start, label, 'Failed to parse output'); |
| 243 if (label == null && line.startsWith(labelMarker)) { | 291 runPixelLayoutTest(testNum + 1); |
| 244 label = line.substring(labelMarker.length); | |
| 245 if (label == 'NONEXISTENT') { | |
| 246 complete(); | |
| 247 } | |
| 248 } else if (line.startsWith(contentMarker)) { | |
| 249 if (label == null) { | |
| 250 complete(); | |
| 251 } | |
| 252 var len = int.parse(line.substring(contentMarker.length)); | |
| 253 pos = idx + 1; | |
| 254 var expectedFileName = | |
| 255 '$sourceDir${Platform.pathSeparator}' | |
| 256 '${label.replaceAll("###","_"). | |
| 257 replaceAll(const RegExp("[^A-Za-z0-9]"),"_")}.png'; | |
| 258 var expected = new File(expectedFileName); | |
| 259 if (regenerate) { | |
| 260 var ostream = expected.openOutputStream(FileMode.WRITE); | |
| 261 ostream.writeFrom(stdout, pos, len); | |
| 262 ostream.close(); | |
| 263 pass(start, label); | |
| 264 } else if (!expected.existsSync()) { | |
| 265 fail(start, label, 'No expectation file'); | |
| 266 } else { | |
| 267 var bytes = expected.readAsBytesSync(); | |
| 268 if (bytes.length != len) { | |
| 269 fail(start, label, 'Expectation file has wrong length'); | |
| 270 } else { | |
| 271 var match = true; | |
| 272 for (var j = 0; j < len; j++) { | |
| 273 if (bytes[j] != stdout[pos + j]) { | |
| 274 fail(start, label, 'Expectation differs at byte ${j + 1}'); | |
| 275 match = false; | |
| 276 break; | |
| 277 } | |
| 278 } | |
| 279 if (match) pass(start, label); | |
| 280 } | |
| 281 } | |
| 282 done = true; | |
| 283 break; | |
| 284 } | 292 } |
| 285 pos = idx; | 293 }; |
| 286 } | 294 }); |
| 287 if (label != null) { | |
| 288 if (!done) error(start, label, 'Failed to parse output'); | |
| 289 runPixelLayoutTest(testNum + 1); | |
| 290 } | |
| 291 }; | |
| 292 } | 295 } |
| 293 | 296 |
| 294 void init() { | 297 void init() { |
| 295 // Get the name of the directory that has the expectation files | 298 // Get the name of the directory that has the expectation files |
| 296 // (by stripping .dart suffix from test file path). | 299 // (by stripping .dart suffix from test file path). |
| 297 // Create it if it does not exist. | 300 // Create it if it does not exist. |
| 298 sourceDir = testfile.substring(0, testfile.length - 5); | 301 sourceDir = testfile.substring(0, testfile.length - 5); |
| 299 if (regenerate) { | 302 if (regenerate) { |
| 300 var d = new Directory(sourceDir); | 303 var d = new Directory(sourceDir); |
| 301 if (!d.existsSync()) { | 304 if (!d.existsSync()) { |
| 302 d.createSync(); | 305 d.createSync(); |
| 303 } | 306 } |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 | 309 |
| 307 void runPixelLayoutTests() { | 310 void runPixelLayoutTests() { |
| 308 init(); | 311 init(); |
| 309 runPixelLayoutTest(0); | 312 runPixelLayoutTest(0); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void runTextLayoutTests() { | 315 void runTextLayoutTests() { |
| 313 init(); | 316 init(); |
| 314 runTextLayoutTest(0); | 317 runTextLayoutTest(0); |
| 315 } | 318 } |
| OLD | NEW |