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 /** | 5 /** |
6 * Classes and methods for executing tests. | 6 * Classes and methods for executing tests. |
7 * | 7 * |
8 * This module includes: | 8 * This module includes: |
9 * - Managing parallel execution of tests, including timeout checks. | 9 * - Managing parallel execution of tests, including timeout checks. |
10 * - Evaluating the output of each test as pass/fail/crash/timeout. | 10 * - Evaluating the output of each test as pass/fail/crash/timeout. |
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 */ | 1847 */ |
1848 class RunningProcess { | 1848 class RunningProcess { |
1849 ProcessCommand command; | 1849 ProcessCommand command; |
1850 int timeout; | 1850 int timeout; |
1851 bool timedOut = false; | 1851 bool timedOut = false; |
1852 DateTime startTime; | 1852 DateTime startTime; |
1853 Timer timeoutTimer; | 1853 Timer timeoutTimer; |
1854 int pid; | 1854 int pid; |
1855 OutputLog stdout = new OutputLog(); | 1855 OutputLog stdout = new OutputLog(); |
1856 OutputLog stderr = new OutputLog(); | 1856 OutputLog stderr = new OutputLog(); |
| 1857 List<String> diagnostics = <String>[]; |
1857 bool compilationSkipped = false; | 1858 bool compilationSkipped = false; |
1858 Completer<CommandOutput> completer; | 1859 Completer<CommandOutput> completer; |
1859 | 1860 |
1860 RunningProcess(this.command, this.timeout); | 1861 RunningProcess(this.command, this.timeout); |
1861 | 1862 |
1862 Future<CommandOutput> run() { | 1863 Future<CommandOutput> run() { |
1863 completer = new Completer<CommandOutput>(); | 1864 completer = new Completer<CommandOutput>(); |
1864 startTime = new DateTime.now(); | 1865 startTime = new DateTime.now(); |
1865 _runCommand(); | 1866 _runCommand(); |
1866 return completer.future; | 1867 return completer.future; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 stderrDone = true; | 1911 stderrDone = true; |
1911 | 1912 |
1912 if (stdoutDone && watchdogTimer != null) { | 1913 if (stdoutDone && watchdogTimer != null) { |
1913 watchdogTimer.cancel(); | 1914 watchdogTimer.cancel(); |
1914 } | 1915 } |
1915 } | 1916 } |
1916 } | 1917 } |
1917 | 1918 |
1918 // Close stdin so that tests that try to block on input will fail. | 1919 // Close stdin so that tests that try to block on input will fail. |
1919 process.stdin.close(); | 1920 process.stdin.close(); |
1920 void timeoutHandler() { | 1921 timeoutHandler() async { |
1921 timedOut = true; | 1922 timedOut = true; |
1922 if (process != null) { | 1923 if (process != null) { |
| 1924 var executable, arguments; |
1923 if (io.Platform.isLinux) { | 1925 if (io.Platform.isLinux) { |
1924 // Try to print stack traces of the timed out process. | 1926 executable = 'eu-stack'; |
1925 io.Process.run('eu-stack', ['-p ${process.pid}']) | 1927 arguments = ['-p ${process.pid}']; |
1926 .then((result) { | |
1927 io.stdout.write(result.stdout); | |
1928 io.stderr.write(result.stderr); | |
1929 }) | |
1930 .catchError( | |
1931 (error) => print("Error when printing stack trace: $error")) | |
1932 .whenComplete(() { | |
1933 if (!process.kill()) { | |
1934 DebugLogger.error("Unable to kill ${process.pid}"); | |
1935 } | |
1936 }); | |
1937 } else if (io.Platform.isMacOS) { | 1928 } else if (io.Platform.isMacOS) { |
1938 // Try to print stack traces of the timed out process. | 1929 // Try to print stack traces of the timed out process. |
1939 // `sample` is a sampling profiler but we ask it sample for 1 | 1930 // `sample` is a sampling profiler but we ask it sample for 1 |
1940 // second with a 4 second delay between samples so that we only | 1931 // second with a 4 second delay between samples so that we only |
1941 // sample the threads once. | 1932 // sample the threads once. |
1942 io.Process.run('/usr/bin/sample', | 1933 executable = '/usr/bin/sample'; |
1943 ['${process.pid}', '1', '4000', '-mayDie']) | 1934 arguments = ['${process.pid}', '1', '4000', '-mayDie']; |
1944 .then((result) { | 1935 } |
1945 io.stdout.write(result.stdout); | 1936 |
1946 io.stderr.write(result.stderr); | 1937 if (executable != null) { |
1947 }) | 1938 try { |
1948 .catchError( | 1939 var result = await io.Process.run(executable, arguments); |
1949 (error) => print("Error when printing stack trace: $error")) | 1940 diagnostics.addAll(result.stdout.split('\n')); |
1950 .whenComplete(() { | 1941 diagnostics.addAll(result.stderr.split('\n')); |
1951 if (!process.kill()) { | 1942 } catch (error) { |
1952 DebugLogger.error("Unable to kill ${process.pid}"); | 1943 diagnostics.add("Unable to capture stack traces: $error"); |
1953 } | |
1954 }); | |
1955 } else { | |
1956 if (!process.kill()) { | |
1957 DebugLogger.error("Unable to kill ${process.pid}"); | |
1958 } | 1944 } |
1959 } | 1945 } |
| 1946 |
| 1947 if (!process.kill()) { |
| 1948 diagnostics.add("Unable to kill ${process.pid}"); |
| 1949 } |
1960 } | 1950 } |
1961 } | 1951 } |
1962 | 1952 |
1963 stdoutSubscription.asFuture().then(closeStdout); | 1953 stdoutSubscription.asFuture().then(closeStdout); |
1964 stderrSubscription.asFuture().then(closeStderr); | 1954 stderrSubscription.asFuture().then(closeStderr); |
1965 | 1955 |
1966 process.exitCode.then((exitCode) { | 1956 process.exitCode.then((exitCode) { |
1967 if (!stdoutDone || !stderrDone) { | 1957 if (!stdoutDone || !stderrDone) { |
1968 watchdogTimer = new Timer(MAX_STDIO_DELAY, () { | 1958 watchdogTimer = new Timer(MAX_STDIO_DELAY, () { |
1969 DebugLogger.warning( | 1959 DebugLogger.warning( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 CommandOutput _createCommandOutput(ProcessCommand command, int exitCode) { | 1997 CommandOutput _createCommandOutput(ProcessCommand command, int exitCode) { |
2008 var commandOutput = createCommandOutput( | 1998 var commandOutput = createCommandOutput( |
2009 command, | 1999 command, |
2010 exitCode, | 2000 exitCode, |
2011 timedOut, | 2001 timedOut, |
2012 stdout.toList(), | 2002 stdout.toList(), |
2013 stderr.toList(), | 2003 stderr.toList(), |
2014 new DateTime.now().difference(startTime), | 2004 new DateTime.now().difference(startTime), |
2015 compilationSkipped, | 2005 compilationSkipped, |
2016 pid); | 2006 pid); |
| 2007 commandOutput.diagnostics.addAll(diagnostics); |
2017 return commandOutput; | 2008 return commandOutput; |
2018 } | 2009 } |
2019 | 2010 |
2020 StreamSubscription _drainStream( | 2011 StreamSubscription _drainStream( |
2021 Stream<List<int>> source, OutputLog destination) { | 2012 Stream<List<int>> source, OutputLog destination) { |
2022 return source.listen(destination.add); | 2013 return source.listen(destination.add); |
2023 } | 2014 } |
2024 | 2015 |
2025 Map<String, String> _createProcessEnvironment() { | 2016 Map<String, String> _createProcessEnvironment() { |
2026 var environment = new Map.from(io.Platform.environment); | 2017 var environment = new Map.from(io.Platform.environment); |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3149 } | 3140 } |
3150 } | 3141 } |
3151 | 3142 |
3152 void eventAllTestsDone() { | 3143 void eventAllTestsDone() { |
3153 for (var listener in _eventListener) { | 3144 for (var listener in _eventListener) { |
3154 listener.allDone(); | 3145 listener.allDone(); |
3155 } | 3146 } |
3156 _allDone(); | 3147 _allDone(); |
3157 } | 3148 } |
3158 } | 3149 } |
OLD | NEW |