From d71f8ff86f8929e4f3886bc285a29c5bd158bc76 Mon Sep 17 00:00:00 2001 From: "kustermann@google.com" Date: Fri, 18 Jan 2013 16:45:20 +0000 Subject: [PATCH] Added DebugLogger to testing scripts. Review URL: https://codereview.chromium.org//11962042 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17291 260f80e4-7a28-3924-810f-c04153c831b5 --- .gitignore | 1 + tools/bots/compiler.py | 5 ++-- tools/test-runtime.dart | 4 +-- tools/test.dart | 13 +++++++-- tools/testing/dart/test_options.dart | 14 ++++++++-- tools/testing/dart/test_runner.dart | 3 +- tools/testing/dart/test_suite.dart | 4 +++ tools/testing/dart/utils.dart | 42 ++++++++++++++++++++++++++++ 8 files changed, 75 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 7562384e050..72b2e8cd1e4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /out /xcodebuild /.flaky.log +/.debug.log /*.Makefile /*.opensdf /*.pyc diff --git a/tools/bots/compiler.py b/tools/bots/compiler.py index 7e60dddaf75..02d6ecb6b12 100644 --- a/tools/bots/compiler.py +++ b/tools/bots/compiler.py @@ -121,7 +121,8 @@ def TestStep(name, mode, system, compiler, runtime, targets, flags): '--runtime=' + runtime, '--time', '--use-sdk', - '--report']) + '--report', + '--write-debug-log']) # TODO(ricow/kustermann): Issue 7339 if runtime == "safari": @@ -136,7 +137,7 @@ def TestStep(name, mode, system, compiler, runtime, targets, flags): if IsFirstTestStepCall: IsFirstTestStepCall = False else: - cmd.append('--append_flaky_log') + cmd.append('--append_logs') if flags: cmd.extend(flags) diff --git a/tools/test-runtime.dart b/tools/test-runtime.dart index e5aed57f071..a959f23424f 100755 --- a/tools/test-runtime.dart +++ b/tools/test-runtime.dart @@ -50,8 +50,8 @@ main() { var verbose = firstConf['verbose']; var printTiming = firstConf['time']; var listTests = firstConf['list']; - - if (!firstConf['append_flaky_log']) { + + if (!firstConf['append_logs']) { var file = new File(TestUtils.flakyFileName()); if (file.existsSync()) { file.deleteSync(); diff --git a/tools/test.dart b/tools/test.dart index 2dc3aaa917d..b1ce5678990 100755 --- a/tools/test.dart +++ b/tools/test.dart @@ -30,6 +30,7 @@ import "testing/dart/test_options.dart"; import "testing/dart/test_suite.dart"; import "testing/dart/test_progress.dart"; import "testing/dart/http_server.dart"; +import "testing/dart/utils.dart"; import "../compiler/tests/dartc/test_config.dart"; import "../runtime/tests/vm/test_config.dart"; @@ -82,13 +83,16 @@ main() { var printTiming = firstConf['time']; var listTests = firstConf['list']; - if (!firstConf['append_flaky_log']) { + if (!firstConf['append_logs']) { var file = new File(TestUtils.flakyFileName()); if (file.existsSync()) { file.deleteSync(); } } + DebugLogger.init(firstConf['write_debug_log'] ? + TestUtils.debugLogfile() : null, append: firstConf['append_logs']); + // Print the configurations being run by this execution of // test.dart. However, don't do it if the silent progress indicator // is used. This is only needed because of the junit tests. @@ -146,13 +150,18 @@ main() { } } + void allTestsFinished() { + TestingServerRunner.terminateHttpServers(); + DebugLogger.close(); + } + // Start process queue. new ProcessQueue(maxProcesses, progressIndicator, startTime, printTiming, testSuites, - () => TestingServerRunner.terminateHttpServers(), + allTestsFinished, verbose, listTests); } diff --git a/tools/testing/dart/test_options.dart b/tools/testing/dart/test_options.dart index fa2edd53c1c..55ac05c08ac 100644 --- a/tools/testing/dart/test_options.dart +++ b/tools/testing/dart/test_options.dart @@ -270,9 +270,17 @@ Note: currently only implemented for dart2js.''', false, 'bool'), new _TestOptionSpecification( - 'append_flaky_log', - 'Do not delete the old flaky log but rather append to it.', - ['--append_flaky_log'], + 'append_logs', + 'Do not delete old logs but rather append to them.', + ['--append_logs'], + [], + false, + 'bool' + ), + new _TestOptionSpecification( + 'write_debug_log', + 'Don\'t write debug messages to stdout but rather to a logfile.', + ['--write-debug-log'], [], false, 'bool' diff --git a/tools/testing/dart/test_runner.dart b/tools/testing/dart/test_runner.dart index c745eb62567..297d8d29f85 100644 --- a/tools/testing/dart/test_runner.dart +++ b/tools/testing/dart/test_runner.dart @@ -1490,9 +1490,8 @@ class ProcessQueue { _allDone(); if (browserUsed != '' && _seleniumServer != null) { _seleniumServer.kill(); - } else { - _progress.allDone(); } + _progress.allDone(); } void _checkDone() { diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart index 96299ae2c4c..2b3075f3390 100644 --- a/tools/testing/dart/test_suite.dart +++ b/tools/testing/dart/test_suite.dart @@ -1714,6 +1714,10 @@ class TestUtils { return completer.future; } + static Path debugLogfile() { + return new Path(".debug.log"); + } + static String flakyFileName() { // If a flaky test did fail, infos about it (i.e. test name, stdin, stdout) // will be written to this file. This is useful for the debugging of diff --git a/tools/testing/dart/utils.dart b/tools/testing/dart/utils.dart index 280140c90a5..7c2bbf7ba1b 100644 --- a/tools/testing/dart/utils.dart +++ b/tools/testing/dart/utils.dart @@ -4,8 +4,50 @@ library utils; +import 'dart:io'; import 'dart:utf' as utf; +class DebugLogger { + static OutputStream _stream; + + /** + * If [path] was null, the DebugLogger will write messages to stdout. + */ + static init(Path path, {append: false}) { + if (path != null) { + var mode = append ? FileMode.APPEND : FileMode.WRITE; + _stream = new File.fromPath(path).openOutputStream(mode); + } + } + + static void close() { + if (_stream != null) { + _stream.close(); + _stream = null; + } + } + + static void info(String msg) { + _print("Info: $msg"); + } + + static void warning(String msg) { + _print("Warning: $msg"); + } + + static void error(String msg) { + _print("Error: $msg"); + } + + static void _print(String msg) { + if (_stream != null) { + _stream.write(encodeUtf8(msg)); + _stream.write([0x0a]); + } else { + print(msg); + } + } +} List encodeUtf8(String string) { return utf.encodeUtf8(string);