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

Side by Side Diff: content/test/test_launcher.cc

Issue 8825010: Stop running tests if more than 5 time out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/test/test_launcher.h" 5 #include "content/test/test_launcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/common/sandbox_policy.h" 31 #include "content/common/sandbox_policy.h"
32 #include "sandbox/src/dep.h" 32 #include "sandbox/src/dep.h"
33 #include "sandbox/src/sandbox_factory.h" 33 #include "sandbox/src/sandbox_factory.h"
34 #include "sandbox/src/sandbox_types.h" 34 #include "sandbox/src/sandbox_types.h"
35 #elif defined(OS_MACOSX) 35 #elif defined(OS_MACOSX)
36 #include "base/mac/scoped_nsautorelease_pool.h" 36 #include "base/mac/scoped_nsautorelease_pool.h"
37 #endif 37 #endif
38 38
39 namespace test_launcher { 39 namespace test_launcher {
40 40
41 namespace {
42
43 // The environment variable name for the total number of test shards. 41 // The environment variable name for the total number of test shards.
44 static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; 42 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
45 // The environment variable name for the test shard index. 43 // The environment variable name for the test shard index.
46 static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; 44 const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
47 45
48 // The default output file for XML output. 46 // The default output file for XML output.
49 static const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( 47 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL(
50 "test_detail.xml"); 48 "test_detail.xml");
51 49
52 // Name of the empty test below. 50 // Name of the empty test below.
53 static const char kEmptyTestName[] = "InProcessBrowserTest.Empty"; 51 const char kEmptyTestName[] = "InProcessBrowserTest.Empty";
52
53 // Quit test execution after this number of tests has timed out.
54 const int kMaxTimeouts = 5; // 45s timeout * (5 + 1) = 270s max run time.
55
56 namespace {
54 57
55 // An empty test (it starts up and shuts down the browser as part of its 58 // An empty test (it starts up and shuts down the browser as part of its
56 // setup and teardown) used to prefetch all of the browser code into memory. 59 // setup and teardown) used to prefetch all of the browser code into memory.
57 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, Empty) { 60 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, Empty) {
58 } 61
62 } // namespace
59 63
60 // Parses the environment variable var as an Int32. If it is unset, returns 64 // Parses the environment variable var as an Int32. If it is unset, returns
61 // default_val. If it is set, unsets it then converts it to Int32 before 65 // default_val. If it is set, unsets it then converts it to Int32 before
62 // returning it. If unsetting or converting to an Int32 fails, print an 66 // returning it. If unsetting or converting to an Int32 fails, print an
63 // error and exit with failure. 67 // error and exit with failure.
64 int32 Int32FromEnvOrDie(const char* const var, int32 default_val) { 68 int32 Int32FromEnvOrDie(const char* const var, int32 default_val) {
65 scoped_ptr<base::Environment> env(base::Environment::Create()); 69 scoped_ptr<base::Environment> env(base::Environment::Create());
66 std::string str_val; 70 std::string str_val;
67 int32 result; 71 int32 result;
68 if (!env->GetVar(var, &str_val)) 72 if (!env->GetVar(var, &str_val))
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (test_name.find("SLOW_") != std::string::npos) 299 if (test_name.find("SLOW_") != std::string::npos)
296 timeout_ms *= kSlowTestTimeoutMultiplier; 300 timeout_ms *= kSlowTestTimeoutMultiplier;
297 301
298 return timeout_ms; 302 return timeout_ms;
299 } 303 }
300 304
301 // Runs test specified by |test_name| in a child process, 305 // Runs test specified by |test_name| in a child process,
302 // and returns the exit code. 306 // and returns the exit code.
303 int RunTest(TestLauncherDelegate* launcher_delegate, 307 int RunTest(TestLauncherDelegate* launcher_delegate,
304 const std::string& test_name, 308 const std::string& test_name,
305 int default_timeout_ms) { 309 int default_timeout_ms,
310 bool* was_timeout) {
311 if (was_timeout)
312 *was_timeout = false;
313
306 #if defined(OS_MACOSX) 314 #if defined(OS_MACOSX)
307 // Some of the below method calls will leak objects if there is no 315 // Some of the below method calls will leak objects if there is no
308 // autorelease pool in place. 316 // autorelease pool in place.
309 base::mac::ScopedNSAutoreleasePool pool; 317 base::mac::ScopedNSAutoreleasePool pool;
310 #endif 318 #endif
311 319
312 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 320 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
313 CommandLine new_cmd_line(cmd_line->GetProgram()); 321 CommandLine new_cmd_line(cmd_line->GetProgram());
314 CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 322 CommandLine::SwitchMap switches = cmd_line->GetSwitches();
315 323
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 376
369 int timeout_ms = GetTestTerminationTimeout(test_name, 377 int timeout_ms = GetTestTerminationTimeout(test_name,
370 default_timeout_ms); 378 default_timeout_ms);
371 379
372 int exit_code = 0; 380 int exit_code = 0;
373 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, 381 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code,
374 timeout_ms)) { 382 timeout_ms)) {
375 LOG(ERROR) << "Test timeout (" << timeout_ms 383 LOG(ERROR) << "Test timeout (" << timeout_ms
376 << " ms) exceeded for " << test_name; 384 << " ms) exceeded for " << test_name;
377 385
386 if (was_timeout)
387 *was_timeout = true;
378 exit_code = -1; // Set a non-zero exit code to signal a failure. 388 exit_code = -1; // Set a non-zero exit code to signal a failure.
379 389
380 // Ensure that the process terminates. 390 // Ensure that the process terminates.
381 base::KillProcess(process_handle, -1, true); 391 base::KillProcess(process_handle, -1, true);
382 } 392 }
383 393
384 #if defined(OS_POSIX) 394 #if defined(OS_POSIX)
385 if (exit_code != 0) { 395 if (exit_code != 0) {
386 // On POSIX, in case the test does not exit cleanly, either due to a crash 396 // On POSIX, in case the test does not exit cleanly, either due to a crash
387 // or due to it timing out, we need to clean up any child processes that 397 // or due to it timing out, we need to clean up any child processes that
(...skipping 26 matching lines...) Expand all
414 std::string negative_filter = ""; 424 std::string negative_filter = "";
415 size_t dash_pos = filter.find('-'); 425 size_t dash_pos = filter.find('-');
416 if (dash_pos != std::string::npos) { 426 if (dash_pos != std::string::npos) {
417 positive_filter = filter.substr(0, dash_pos); // Everything up to the dash. 427 positive_filter = filter.substr(0, dash_pos); // Everything up to the dash.
418 negative_filter = filter.substr(dash_pos + 1); // Everything after the dash. 428 negative_filter = filter.substr(dash_pos + 1); // Everything after the dash.
419 } 429 }
420 430
421 int num_runnable_tests = 0; 431 int num_runnable_tests = 0;
422 int test_run_count = 0; 432 int test_run_count = 0;
423 int ignored_failure_count = 0; 433 int ignored_failure_count = 0;
434 int timeout_count = 0;
424 std::vector<std::string> failed_tests; 435 std::vector<std::string> failed_tests;
425 436
426 ResultsPrinter printer(*command_line); 437 ResultsPrinter printer(*command_line);
427 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { 438 for (int i = 0; i < unit_test->total_test_case_count(); ++i) {
428 const testing::TestCase* test_case = unit_test->GetTestCase(i); 439 const testing::TestCase* test_case = unit_test->GetTestCase(i);
429 TestCasePrinterHelper helper(printer, test_case->name(), 440 TestCasePrinterHelper helper(printer, test_case->name(),
430 test_case->total_test_count()); 441 test_case->total_test_count());
431 for (int j = 0; j < test_case->total_test_count(); ++j) { 442 for (int j = 0; j < test_case->total_test_count(); ++j) {
432 const testing::TestInfo* test_info = test_case->GetTestInfo(j); 443 const testing::TestInfo* test_info = test_case->GetTestInfo(j);
433 std::string test_name = test_info->test_case_name(); 444 std::string test_name = test_info->test_case_name();
(...skipping 29 matching lines...) Expand all
463 num_runnable_tests); 474 num_runnable_tests);
464 } 475 }
465 num_runnable_tests += 1; 476 num_runnable_tests += 1;
466 // If sharding is enabled and the test should not be run, skip it. 477 // If sharding is enabled and the test should not be run, skip it.
467 if (!should_run) { 478 if (!should_run) {
468 continue; 479 continue;
469 } 480 }
470 481
471 base::Time start_time = base::Time::Now(); 482 base::Time start_time = base::Time::Now();
472 ++test_run_count; 483 ++test_run_count;
484 bool was_timeout = false;
473 int exit_code = RunTest(launcher_delegate, 485 int exit_code = RunTest(launcher_delegate,
474 test_name, 486 test_name,
475 TestTimeouts::action_max_timeout_ms()); 487 TestTimeouts::action_max_timeout_ms(),
488 &was_timeout);
476 if (exit_code == 0) { 489 if (exit_code == 0) {
477 // Test passed. 490 // Test passed.
478 printer.OnTestEnd(test_info->name(), test_case->name(), true, false, 491 printer.OnTestEnd(test_info->name(), test_case->name(), true, false,
479 false, 492 false,
480 (base::Time::Now() - start_time).InMillisecondsF()); 493 (base::Time::Now() - start_time).InMillisecondsF());
481 } else { 494 } else {
482 failed_tests.push_back(test_name); 495 failed_tests.push_back(test_name);
483 496
484 bool ignore_failure = false; 497 bool ignore_failure = false;
485 498
486 // -1 exit code means a crash or hang. Never ignore those failures, 499 // -1 exit code means a crash or hang. Never ignore those failures,
487 // they are serious and should always be visible. 500 // they are serious and should always be visible.
488 if (exit_code != -1) 501 if (exit_code != -1)
489 ignore_failure = base::TestSuite::ShouldIgnoreFailure(*test_info); 502 ignore_failure = base::TestSuite::ShouldIgnoreFailure(*test_info);
490 503
491 printer.OnTestEnd(test_info->name(), test_case->name(), true, true, 504 printer.OnTestEnd(test_info->name(), test_case->name(), true, true,
492 ignore_failure, 505 ignore_failure,
493 (base::Time::Now() - start_time).InMillisecondsF()); 506 (base::Time::Now() - start_time).InMillisecondsF());
494 if (ignore_failure) 507 if (ignore_failure)
495 ++ignored_failure_count; 508 ++ignored_failure_count;
509
510 if (was_timeout)
511 ++timeout_count;
496 } 512 }
513
514 if (timeout_count > kMaxTimeouts) {
515 printf("More than %d timeouts, aborting test case\n", kMaxTimeouts);
516 break;
517 }
518 }
519 if (timeout_count > kMaxTimeouts) {
520 printf("More than %d timeouts, aborting test\n", kMaxTimeouts);
521 break;
497 } 522 }
498 } 523 }
499 524
500 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : ""); 525 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : "");
501 printf("%d test%s failed (%d ignored)\n", 526 printf("%d test%s failed (%d ignored)\n",
502 static_cast<int>(failed_tests.size()), 527 static_cast<int>(failed_tests.size()),
503 failed_tests.size() > 1 ? "s" : "", ignored_failure_count); 528 failed_tests.size() > 1 ? "s" : "", ignored_failure_count);
504 if (failed_tests.size() - ignored_failure_count == 0) 529 if (failed_tests.size() - ignored_failure_count == 0)
505 return true; 530 return true;
506 531
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 633
609 testing::InitGoogleTest(&argc, argv); 634 testing::InitGoogleTest(&argc, argv);
610 TestTimeouts::Initialize(); 635 TestTimeouts::Initialize();
611 636
612 // Make sure the entire browser code is loaded into memory. Reading it 637 // Make sure the entire browser code is loaded into memory. Reading it
613 // from disk may be slow on a busy bot, and can easily exceed the default 638 // from disk may be slow on a busy bot, and can easily exceed the default
614 // timeout causing flaky test failures. Use an empty test that only starts 639 // timeout causing flaky test failures. Use an empty test that only starts
615 // and closes a browser with a long timeout to avoid those problems. 640 // and closes a browser with a long timeout to avoid those problems.
616 int exit_code = RunTest(launcher_delegate, 641 int exit_code = RunTest(launcher_delegate,
617 kEmptyTestName, 642 kEmptyTestName,
618 TestTimeouts::large_test_timeout_ms()); 643 TestTimeouts::large_test_timeout_ms(),
644 NULL);
619 if (exit_code != 0) 645 if (exit_code != 0)
620 return exit_code; 646 return exit_code;
621 647
622 int cycles = 1; 648 int cycles = 1;
623 if (command_line->HasSwitch(kGTestRepeatFlag)) { 649 if (command_line->HasSwitch(kGTestRepeatFlag)) {
624 base::StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag), 650 base::StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag),
625 &cycles); 651 &cycles);
626 } 652 }
627 653
628 while (cycles != 0) { 654 while (cycles != 0) {
629 if (!RunTests(launcher_delegate, 655 if (!RunTests(launcher_delegate,
630 should_shard, 656 should_shard,
631 total_shards, 657 total_shards,
632 shard_index)) { 658 shard_index)) {
633 exit_code = 1; 659 exit_code = 1;
634 break; 660 break;
635 } 661 }
636 662
637 // Special value "-1" means "repeat indefinitely". 663 // Special value "-1" means "repeat indefinitely".
638 if (cycles != -1) 664 if (cycles != -1)
639 cycles--; 665 cycles--;
640 } 666 }
641 return exit_code; 667 return exit_code;
642 } 668 }
643 669
644 } // namespace test_launcher 670 } // namespace test_launcher
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