| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/hash_tables.h" |
| 10 #include "base/linked_ptr.h" | 11 #include "base/linked_ptr.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/mac/scoped_nsautorelease_pool.h" | 13 #include "base/mac/scoped_nsautorelease_pool.h" |
| 13 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 15 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 #include "base/test/test_suite.h" | 19 #include "base/test/test_suite.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/test/unit/chrome_test_suite.h" | 22 #include "chrome/test/unit/chrome_test_suite.h" |
| 22 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 26 #include "base/base_switches.h" | 27 #include "base/base_switches.h" |
| 27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/sandbox_policy.h" | 29 #include "chrome/common/sandbox_policy.h" |
| 29 #include "sandbox/src/dep.h" | 30 #include "sandbox/src/dep.h" |
| 30 #include "sandbox/src/sandbox_factory.h" | 31 #include "sandbox/src/sandbox_factory.h" |
| 31 #include "sandbox/src/sandbox_types.h" | 32 #include "sandbox/src/sandbox_types.h" |
| 32 #endif // defined(OS_WIN) | 33 #endif // defined(OS_WIN) |
| 33 | 34 |
| 34 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 35 // The entry point signature of chrome.dll. | 36 // The entry point signature of chrome.dll. |
| 36 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); | 37 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); |
| 37 #endif // defined(OS_WIN) | 38 #endif // defined(OS_WIN) |
| 38 | 39 |
| 40 // Allows a specific test to increase its timeout. This should be used very |
| 41 // sparingly, i.e. when a "test" is a really a collection of sub tests and it's |
| 42 // not possible to break them up. An example is PDFBrowserTest.Loading, which |
| 43 // loads all the files it can find in a directory. |
| 44 base::hash_map<std::string, int> g_test_timeout_overrides; |
| 45 |
| 39 namespace { | 46 namespace { |
| 40 | 47 |
| 41 const char kGTestFilterFlag[] = "gtest_filter"; | 48 const char kGTestFilterFlag[] = "gtest_filter"; |
| 42 const char kGTestHelpFlag[] = "gtest_help"; | 49 const char kGTestHelpFlag[] = "gtest_help"; |
| 43 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 50 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
| 44 const char kGTestRepeatFlag[] = "gtest_repeat"; | 51 const char kGTestRepeatFlag[] = "gtest_repeat"; |
| 45 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; | 52 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; |
| 46 const char kGTestOutputFlag[] = "gtest_output"; | 53 const char kGTestOutputFlag[] = "gtest_output"; |
| 47 | 54 |
| 48 const char kSingleProcessTestsFlag[] = "single_process"; | 55 const char kSingleProcessTestsFlag[] = "single_process"; |
| 49 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; | 56 const char kSingleProcessTestsAndChromeFlag[] = "single-process"; |
| 50 // The following is kept for historical reasons (so people that are used to | 57 // The following is kept for historical reasons (so people that are used to |
| 51 // using it don't get surprised). | 58 // using it don't get surprised). |
| 52 const char kChildProcessFlag[] = "child"; | 59 const char kChildProcessFlag[] = "child"; |
| 53 | 60 |
| 54 const char kHelpFlag[] = "help"; | 61 const char kHelpFlag[] = "help"; |
| 55 | 62 |
| 56 const char kTestTerminateTimeoutFlag[] = "test-terminate-timeout"; | 63 const char kTestTerminateTimeoutFlag[] = "test-terminate-timeout"; |
| 57 | 64 |
| 58 // How long we wait for the subprocess to exit (with a success/failure code). | 65 // How long we wait for the subprocess to exit (with a success/failure code). |
| 59 // See http://crbug.com/43862 for some discussion of the value. | 66 // See http://crbug.com/43862 for some discussion of the value. |
| 60 const int64 kDefaultTestTimeoutMs = 20000; | 67 const int kDefaultTestTimeoutMs = 20000; |
| 61 | 68 |
| 62 // The default output file for XML output. | 69 // The default output file for XML output. |
| 63 static const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 70 static const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
| 64 "test_detail.xml"); | 71 "test_detail.xml"); |
| 65 | 72 |
| 66 // A helper class to output results. | 73 // A helper class to output results. |
| 67 // Note: as currently XML is the only supported format by gtest, we don't | 74 // Note: as currently XML is the only supported format by gtest, we don't |
| 68 // check output format (e.g. "xml:" prefix) here and output an XML file | 75 // check output format (e.g. "xml:" prefix) here and output an XML file |
| 69 // unconditionally. | 76 // unconditionally. |
| 70 // Note: we don't output per-test-case or total summary info like | 77 // Note: we don't output per-test-case or total summary info like |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 base::file_handle_mapping_vector no_files; | 300 base::file_handle_mapping_vector no_files; |
| 294 if (!base::LaunchAppInNewProcessGroup(new_cmd_line.argv(), no_env, no_files, | 301 if (!base::LaunchAppInNewProcessGroup(new_cmd_line.argv(), no_env, no_files, |
| 295 false, &process_handle)) | 302 false, &process_handle)) |
| 296 return false; | 303 return false; |
| 297 #else | 304 #else |
| 298 if (!base::LaunchApp(new_cmd_line, false, false, &process_handle)) | 305 if (!base::LaunchApp(new_cmd_line, false, false, &process_handle)) |
| 299 return false; | 306 return false; |
| 300 #endif | 307 #endif |
| 301 | 308 |
| 302 int test_terminate_timeout_ms = kDefaultTestTimeoutMs; | 309 int test_terminate_timeout_ms = kDefaultTestTimeoutMs; |
| 310 if (g_test_timeout_overrides.count(test_name)) |
| 311 test_terminate_timeout_ms = g_test_timeout_overrides[test_name]; |
| 303 if (cmd_line->HasSwitch(kTestTerminateTimeoutFlag)) { | 312 if (cmd_line->HasSwitch(kTestTerminateTimeoutFlag)) { |
| 304 std::string timeout_str = | 313 std::string timeout_str = |
| 305 cmd_line->GetSwitchValueASCII(kTestTerminateTimeoutFlag); | 314 cmd_line->GetSwitchValueASCII(kTestTerminateTimeoutFlag); |
| 306 int timeout; | 315 int timeout; |
| 307 base::StringToInt(timeout_str, &timeout); | 316 base::StringToInt(timeout_str, &timeout); |
| 308 test_terminate_timeout_ms = std::max(test_terminate_timeout_ms, timeout); | 317 test_terminate_timeout_ms = std::max(test_terminate_timeout_ms, timeout); |
| 309 } | 318 } |
| 310 | 319 |
| 311 int exit_code = 0; | 320 int exit_code = 0; |
| 312 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, | 321 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 exit_code = 1; | 518 exit_code = 1; |
| 510 break; | 519 break; |
| 511 } | 520 } |
| 512 | 521 |
| 513 // Special value "-1" means "repeat indefinitely". | 522 // Special value "-1" means "repeat indefinitely". |
| 514 if (cycles != -1) | 523 if (cycles != -1) |
| 515 cycles--; | 524 cycles--; |
| 516 } | 525 } |
| 517 return exit_code; | 526 return exit_code; |
| 518 } | 527 } |
| OLD | NEW |