Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 9087011: Clean up test.dart by merging dartium and chromium test case generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Restore getHtmlName for client tests. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #library("test_suite"); 5 #library("test_suite");
6 6
7 #import("status_file_parser.dart"); 7 #import("status_file_parser.dart");
8 #import("test_runner.dart"); 8 #import("test_runner.dart");
9 #import("multitest.dart"); 9 #import("multitest.dart");
10 10
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 start = filename.indexOf(directoryPath); 244 start = filename.indexOf(directoryPath);
245 testName = filename.substring(start + directoryPath.length + 1, 245 testName = filename.substring(start + directoryPath.length + 1,
246 filename.length); 246 filename.length);
247 if (configuration['component'] != 'dartc') { 247 if (configuration['component'] != 'dartc') {
248 if (testName.endsWith('.dart')) { 248 if (testName.endsWith('.dart')) {
249 testName = testName.substring(0, testName.length - 5); 249 testName = testName.substring(0, testName.length - 5);
250 } 250 }
251 } 251 }
252 } 252 }
253 Set<String> expectations = testExpectations.expectations(testName); 253 Set<String> expectations = testExpectations.expectations(testName);
254 if (configuration["report"]) { 254 if (configuration['report']) {
255 // Tests with multiple VMOptions are counted more than once. 255 // Tests with multiple VMOptions are counted more than once.
256 for (var dummy in optionsFromFile["vmOptions"]) { 256 for (var dummy in optionsFromFile["vmOptions"]) {
257 SummaryReport.add(expectations); 257 SummaryReport.add(expectations);
258 } 258 }
259 } 259 }
260 if (expectations.contains(SKIP)) return; 260 if (expectations.contains(SKIP)) return;
261 261
262 switch (configuration['component']) { 262 switch (configuration['component']) {
263 case 'dartium': 263 case 'dartium':
264 enqueueDartiumTest(filename, testName, optionsFromFile,
265 expectations, isNegative);
266 break;
267 case 'chromium': 264 case 'chromium':
268 case 'frogium': 265 case 'frogium':
269 enqueueChromiumTest(filename, testName, optionsFromFile, 266 enqueueBrowserTest(filename, testName,optionsFromFile,
Bill Hesse 2012/01/05 09:28:18 Oops - missing space.
270 expectations, isNegative); 267 expectations, isNegative);
271 break; 268 break;
272 default: 269 default:
273 // Only dartc supports fatal type errors. Enable fatal type 270 // Only dartc supports fatal type errors. Enable fatal type
274 // errors with a flag and treat tests that have fatal type 271 // errors with a flag and treat tests that have fatal type
275 // errors as negative. 272 // errors as negative.
276 var enableFatalTypeErrors = 273 var enableFatalTypeErrors =
277 (info.hasFatalTypeErrors && configuration['component'] == 'dartc'); 274 (info.hasFatalTypeErrors && configuration['component'] == 'dartc');
278 var argumentLists = argumentListsFromFile(filename, 275 var argumentLists = argumentListsFromFile(filename,
279 optionsFromFile, 276 optionsFromFile,
280 enableFatalTypeErrors); 277 enableFatalTypeErrors);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 DoMultitest(filename, 323 DoMultitest(filename,
327 TestUtils.outputDir(configuration), 324 TestUtils.outputDir(configuration),
328 directoryPath, 325 directoryPath,
329 createTestCase, 326 createTestCase,
330 testGeneratorDone); 327 testGeneratorDone);
331 } else { 328 } else {
332 createTestCase(filename, optionsFromFile['isNegative']); 329 createTestCase(filename, optionsFromFile['isNegative']);
333 } 330 }
334 } 331 }
335 332
336 333 void enqueueBrowserTest(String filename,
337 void enqueueDartiumTest(String filename,
338 String testName, 334 String testName,
339 Map optionsFromFile, 335 Map optionsFromFile,
340 Set<String> expectations, 336 Set<String> expectations,
341 bool isNegative) { 337 bool isNegative) {
342 // TODO(whesse): Merge with enqueueChromiumTest, using mainly
343 // enqueueChromiumTest's code and design.
344 if (optionsFromFile['isMultitest']) return; 338 if (optionsFromFile['isMultitest']) return;
345 bool isWebTest = optionsFromFile['containsDomImport']; 339 bool isWebTest = optionsFromFile['containsDomImport'];
346 bool isLibraryDefinition = optionsFromFile['isLibraryDefinition']; 340 bool isLibraryDefinition = optionsFromFile['isLibraryDefinition'];
347 if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) {
348 print('Warning for $filename: Browser tests require #library ' +
349 'in any file that uses #import or #source');
350 }
351
352 String tempDirTemplate = '${TestUtils.buildDir(configuration)}/tmp';
353 Directory tempDir = new Directory(tempDirTemplate);
354 tempDir.createTempSync();
355
356 String dartTestFilename = new File(filename).fullPathSync();
357 String dartWrapperFilename;
358 String scriptPath;
359 if (isWebTest) {
360 scriptPath = 'file://$dartTestFilename';
361 } else {
362 dartWrapperFilename = '${tempDir.path}/test.dart';
363 scriptPath = '../../../$dartWrapperFilename';
364 // test.dart will import the dart test directly, if it is a library,
365 // or indirectly through test_as_library.dart, if it is not.
366 String dartLibraryFilename;
367 if (isLibraryDefinition) {
368 dartLibraryFilename = dartTestFilename;
369 } else {
370 dartLibraryFilename = 'test_as_library.dart';
371 File file = new File('${tempDir.path}/$dartLibraryFilename');
372 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE);
373 dartLibrary.writeStringSync(WrapDartTestInLibrary(dartTestFilename));
374 dartLibrary.closeSync();
375 }
376
377 File file = new File(dartWrapperFilename);
378 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE);
379 dartWrapper.writeStringSync(DartTestWrapper(
380 'dart:dom',
381 '../../../tests/isolate/src/TestFramework.dart',
382 dartLibraryFilename));
383 dartWrapper.closeSync();
384 }
385 // Create the HTML file for the test.
386 // NOTE: This must be 3 directories below the dart root, due to test
387 // client/samples/dartcombat containing a relative path to its .css file.
388 File htmlTestBase = new File('${tempDir.path}/${getHtmlName(filename)}');
389 RandomAccessFile htmlTest = htmlTestBase.openSync(FileMode.WRITE);
390 htmlTest.writeStringSync(GetHtmlContents(
391 filename,
392 '../../../client/testing/unittest/test_controller.js',
393 scriptType,
394 scriptPath));
395 htmlTest.closeSync();
396
397 for (var vmOptions in optionsFromFile["vmOptions"]) {
398 var drtFlags = ['--no-timeout'];
399 var dartFlags = ['--enable_asserts', '--enable_type_checks'];
400 dartFlags.addAll(vmOptions);
401 drtFlags.add('--dart-flags=${Strings.join(dartFlags, " ")}');
402 var args = drtFlags;
403 args.add(htmlTestBase.fullPathSync());
404
405 // Create BrowserTestCase and queue it.
406 var testCase = new BrowserTestCase(
407 testName,
408 null,
409 null,
410 dumpRenderTreeFilename,
411 args,
412 configuration,
413 completeHandler,
414 expectations, optionsFromFile['isNegative']);
415 doTest(testCase);
416 }
417 }
418
419 void enqueueChromiumTest(String filename,
420 String testName,
421 Map optionsFromFile,
422 Set<String> expectations,
423 bool isNegative) {
424 if (optionsFromFile['isMultitest']) return;
425 bool isWebTest = optionsFromFile['containsDomImport'];
426 bool isLibraryDefinition = optionsFromFile['isLibraryDefinition'];
427 if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) { 341 if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) {
428 print('Warning for $filename: Browser tests require #library ' + 342 print('Warning for $filename: Browser tests require #library ' +
429 'in any file that uses #import or #source'); 343 'in any file that uses #import or #source');
430 } 344 }
431 345
346 final String component = configuration['component'];
347 final String testPath = new File(filename).fullPathSync();
432 String dartDir = new File('.').fullPathSync(); 348 String dartDir = new File('.').fullPathSync();
433 String buildDir = TestUtils.buildDir(configuration); 349 if (!testPath.startsWith(dartDir)) {
434 String testPath = new File(filename).fullPathSync(); 350 dartDir = new File('..').fullPathSync();
435 String outputDirBase = '$dartDir/$buildDir/generated_tests/chromium'; 351 if (!testPath.startsWith(dartDir)) {
436 352 print('Run test.dart from the dart directory or' +
437 Expect.isTrue(testPath.startsWith(dartDir)); 353 ' an immediate subdirectory only.');
438 String testRelativePath = testPath.substring(dartDir.length + 1); 354 Expect.fail('Could not find top level dart directory.');
439 String testNameBase; 355 }
440 String testRelativeDir;
441 String testRelativeDirFlattened;
442
443 int start = testRelativePath.lastIndexOf('src' + pathSeparator);
444 if (start != -1) {
445 Expect.isTrue(testRelativePath.endsWith('.dart'));
446 testNameBase =
447 testRelativePath.substring(start + 4, testRelativePath.length - 5);
448 testRelativeDir = testRelativePath.substring(0, start - 1);
449 testRelativeDirFlattened = testRelativeDir.replaceAll('/', '_');
450 } else {
451 Expect.isTrue(testRelativePath.endsWith('_tests.dart'));
452 start = testRelativePath.lastIndexOf(pathSeparator);
453 testNameBase =
454 testRelativePath.substring(start + 1, testRelativePath.length - 11);
455 } 356 }
456 357
457 if (!new Directory('$dartDir/$buildDir/generated_tests').existsSync()) { 358 // Create a directory for the generated test. Drop the path to the
458 new Directory('$dartDir/$buildDir/generated_tests').createSync(); 359 // dart checkout and the final ".dart" from the test path, and replace
459 } 360 // all path separators with underscores.
460 if (!new Directory(outputDirBase).existsSync()) { 361 // All variables are block local, except tempDir.
Mads Ager (google) 2012/01/04 22:03:23 I'm not sure there is value in the extra scope her
Bill Hesse 2012/01/05 09:28:18 Moved to a separate function. On 2012/01/04 22:03
461 new Directory(outputDirBase).createSync(); 362 Directory tempDir;
462 } 363 {
463 Directory tempDir = new Directory( 364 String testUniqueName =
464 '$outputDirBase/${testRelativeDirFlattened}_$testNameBase'); 365 testPath.substring(dartDir.length + 1, testPath.length - 5);
465 if (!tempDir.existsSync()) { 366 testUniqueName = testUniqueName.replaceAll('/', '_');
466 tempDir.createSync(); 367 // Create '[build dir]/generated_tests/$component/$testUniqueName',
368 // including any intermediate directories that don't exist.
369 var generatedTestPath = ['generated_tests',
370 component,
371 testUniqueName];
372 String tempDirPath =
373 new File(TestUtils.buildDir(configuration)).fullPathSync();
374 for (String subdirectory in generatedTestPath) {
375 tempDirPath = '$tempDirPath/$subdirectory';
376 tempDir = new Directory(tempDirPath);
377 if (!tempDir.existsSync()) {
378 tempDir.createSync();
379 }
380 }
467 } 381 }
468 382
469 String dartWrapperFilename = '${tempDir.path}/test.dart'; 383 String dartWrapperFilename = '${tempDir.path}/test.dart';
470 String compiledDartWrapperFilename = '${tempDir.path}/test.js'; 384 String compiledDartWrapperFilename = '${tempDir.path}/test.js';
471 String domLibraryImport = 'dart:dom'; 385 String domLibraryImport = (component == 'chromium') ?
472 if (configuration['component'] == 'chromium') { 386 '$dartDir/client/testing/unittest/dom_for_unittest.dart' : 'dart:dom';
473 domLibraryImport =
474 '$dartDir/client/testing/unittest/dom_for_unittest.dart';
475 }
476 387
477 File htmlTestBase; 388 String htmlPath = '${tempDir.path}/test.html';
478 if (!isWebTest) { 389 if (!isWebTest) {
479 // test.dart will import the dart test directly, if it is a library, 390 // test.dart will import the dart test directly, if it is a library,
480 // or indirectly through test_as_library.dart, if it is not. 391 // or indirectly through test_as_library.dart, if it is not.
481 String dartLibraryFilename; 392 String dartLibraryFilename;
482 if (isLibraryDefinition) { 393 if (isLibraryDefinition) {
483 dartLibraryFilename = testPath; 394 dartLibraryFilename = testPath;
484 } else { 395 } else {
485 dartLibraryFilename = 'test_as_library.dart'; 396 dartLibraryFilename = 'test_as_library.dart';
486 File file = new File('${tempDir.path}/$dartLibraryFilename'); 397 File file = new File('${tempDir.path}/$dartLibraryFilename');
487 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE); 398 RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE);
488 dartLibrary.writeStringSync(WrapDartTestInLibrary(testPath)); 399 dartLibrary.writeStringSync(WrapDartTestInLibrary(testPath));
489 dartLibrary.closeSync(); 400 dartLibrary.closeSync();
490 } 401 }
491 402
492 File file = new File(dartWrapperFilename); 403 File file = new File(dartWrapperFilename);
493 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE); 404 RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE);
494 dartWrapper.writeStringSync(DartTestWrapper( 405 dartWrapper.writeStringSync(DartTestWrapper(
495 domLibraryImport, 406 domLibraryImport,
496 '$dartDir/tests/isolate/src/TestFramework.dart', 407 '$dartDir/tests/isolate/src/TestFramework.dart',
497 dartLibraryFilename)); 408 dartLibraryFilename));
498 dartWrapper.closeSync(); 409 dartWrapper.closeSync();
499 htmlTestBase = new File('${tempDir.path}/${getHtmlName(filename)}');
500 } else { 410 } else {
501 dartWrapperFilename = testPath; 411 dartWrapperFilename = testPath;
502 // TODO(whesse): Once test.py is retired, adjust the relative path in 412 // TODO(whesse): Once test.py is retired, adjust the relative path in
503 // the client/samples/dartcombat test to its css file, remove the 413 // the client/samples/dartcombat test to its css file, remove the
504 // "../../" from this path, and move this out of the isWebTest guard. 414 // "../../" from this path, and move this out of the isWebTest guard.
505 htmlTestBase = new File('${tempDir.path}/../../${getHtmlName(filename)}'); 415 // Also remove getHtmlName, and just use test.html.
416 htmlPath = '${tempDir.path}/../../${getHtmlName(filename)}';
506 } 417 }
418 final String scriptPath = (component == 'dartium') ?
419 dartWrapperFilename : compiledDartWrapperFilename;
507 // Create the HTML file for the test. 420 // Create the HTML file for the test.
508 RandomAccessFile htmlTest = htmlTestBase.openSync(FileMode.WRITE); 421 RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE);
509 htmlTest.writeStringSync(GetHtmlContents( 422 htmlTest.writeStringSync(GetHtmlContents(
510 filename, 423 filename,
511 '$dartDir/client/testing/unittest/test_controller.js', 424 '$dartDir/client/testing/unittest/test_controller.js',
512 scriptType, 425 scriptType,
513 compiledDartWrapperFilename)); 426 scriptPath));
514 htmlTest.closeSync(); 427 htmlTest.closeSync();
515 428
516 for (var vmOptions in optionsFromFile["vmOptions"]) { 429 for (var vmOptions in optionsFromFile['vmOptions']) {
517 List<String> compilerArgs; 430 List<String> compilerArgs;
518 String compilerExecutable = TestUtils.compilerPath(configuration); 431 String compilerExecutable = TestUtils.compilerPath(configuration);
519 switch (configuration['component']) { 432 switch (component) {
520 case 'chromium': 433 case 'chromium':
521 compilerArgs = ['--work', tempDir.path]; 434 compilerArgs = ['--work', tempDir.path];
522 if (configuration['mode'] == 'release') { 435 if (configuration['mode'] == 'release') {
523 compilerArgs.add('--optimize'); 436 compilerArgs.add('--optimize');
524 } 437 }
525 compilerArgs.addAll(vmOptions); 438 compilerArgs.addAll(vmOptions);
526 compilerArgs.add('--ignore-unrecognized-flags'); 439 compilerArgs.add('--ignore-unrecognized-flags');
527 compilerArgs.add('--out'); 440 compilerArgs.add('--out');
528 compilerArgs.add(compiledDartWrapperFilename); 441 compilerArgs.add(compiledDartWrapperFilename);
529 compilerArgs.add(dartWrapperFilename); 442 compilerArgs.add(dartWrapperFilename);
530 // TODO(whesse): Add --fatal-type-errors if needed. 443 // TODO(whesse): Add --fatal-type-errors if needed.
531 break; 444 break;
532 case 'frogium': 445 case 'frogium':
533 compilerArgs = ['--libdir=$dartDir/frog/lib', 446 compilerArgs = ['--libdir=$dartDir/frog/lib',
534 '--compile-only', 447 '--compile-only',
535 '--out=$compiledDartWrapperFilename']; 448 '--out=$compiledDartWrapperFilename'];
536 compilerArgs.addAll(vmOptions); 449 compilerArgs.addAll(vmOptions);
537 compilerArgs.add(dartWrapperFilename); 450 compilerArgs.add(dartWrapperFilename);
538 break; 451 break;
452 case 'dartium':
453 // No compilation phase.
454 compilerExecutable = null;
455 compilerArgs = null;
456 break;
539 default: 457 default:
540 Expect.fail('unimplemented component ${configuration['component']}'); 458 Expect.fail('unimplemented component $component');
541 } 459 }
542 460
543 var args = ['--no-timeout']; 461 var args = ['--no-timeout'];
544 args.add(htmlTestBase.fullPathSync()); 462 if (component == 'dartium') {
463 var dartFlags = ['--enable_asserts', '--enable_type_checks'];
464 dartFlags.addAll(vmOptions);
465 args.add('--dart-flags=${Strings.join(dartFlags, " ")}');
466 }
467 args.add(htmlPath);
545 468
546 // Create BrowserTestCase and queue it. 469 // Create BrowserTestCase and queue it.
547 var testCase = new BrowserTestCase( 470 var testCase = new BrowserTestCase(
548 testName, 471 testName,
549 compilerExecutable, 472 compilerExecutable,
550 compilerArgs, 473 compilerArgs,
551 dumpRenderTreeFilename, 474 getFilename(dumpRenderTreeFilename),
552 args, 475 args,
553 configuration, 476 configuration,
554 completeHandler, 477 completeHandler,
555 expectations, 478 expectations,
556 optionsFromFile['isNegative']); 479 optionsFromFile['isNegative']);
557 doTest(testCase); 480 doTest(testCase);
558 } 481 }
559 } 482 }
560 483
561 String get scriptType() { 484 String get scriptType() {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 863
941 static String dartShellFileName(Map configuration) { 864 static String dartShellFileName(Map configuration) {
942 var name = '${buildDir(configuration)}/${executableName(configuration)}'; 865 var name = '${buildDir(configuration)}/${executableName(configuration)}';
943 if (!(new File(name)).existsSync()) { 866 if (!(new File(name)).existsSync()) {
944 throw "Executable '$name' does not exist"; 867 throw "Executable '$name' does not exist";
945 } 868 }
946 return name; 869 return name;
947 } 870 }
948 871
949 static String compilerPath(Map configuration) { 872 static String compilerPath(Map configuration) {
873 if (configuration['component'] == 'dartium') {
874 return null; // No separate compiler for dartium tests.
875 }
950 var name = '${buildDir(configuration)}/${compilerName(configuration)}'; 876 var name = '${buildDir(configuration)}/${compilerName(configuration)}';
951 if (!(new File(name)).existsSync()) { 877 if (!(new File(name)).existsSync()) {
952 throw "Executable '$name' does not exist"; 878 throw "Executable '$name' does not exist";
953 } 879 }
954 return name; 880 return name;
955 } 881 }
956 882
957 static String outputDir(Map configuration) { 883 static String outputDir(Map configuration) {
958 var outputDir = ''; 884 var outputDir = '';
959 var system = configuration['system']; 885 var system = configuration['system'];
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 * $noCrash tests are expected to be flaky but not crash 962 * $noCrash tests are expected to be flaky but not crash
1037 * $pass tests are expected to pass 963 * $pass tests are expected to pass
1038 * $failOk tests are expected to fail that we won't fix 964 * $failOk tests are expected to fail that we won't fix
1039 * $fail tests are expected to fail that we should fix 965 * $fail tests are expected to fail that we should fix
1040 * $crash tests are expected to crash that we should fix 966 * $crash tests are expected to crash that we should fix
1041 * $timeout tests are allowed to timeout\ 967 * $timeout tests are allowed to timeout\
1042 """; 968 """;
1043 print(report); 969 print(report);
1044 } 970 }
1045 } 971 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698