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

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: 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";
54 52
53 // Quit test execution after this number of tests has timed out.
54 const int kMaxTimeouts = 5; // 45s timeout * 10 = 450s max run time.
55
56 namespace {
Avi (use Gerrit) 2011/12/06 23:01:00 \n after this line
55 // An empty test (it starts up and shuts down the browser as part of its 57 // 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. 58 // setup and teardown) used to prefetch all of the browser code into memory.
57 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, Empty) { 59 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, Empty) {
58 } 60 }
59 61
60 // Parses the environment variable var as an Int32. If it is unset, returns 62 // 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 63 // 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 64 // returning it. If unsetting or converting to an Int32 fails, print an
63 // error and exit with failure. 65 // error and exit with failure.
64 int32 Int32FromEnvOrDie(const char* const var, int32 default_val) { 66 int32 Int32FromEnvOrDie(const char* const var, int32 default_val) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 if (test_name.find("SLOW_") != std::string::npos) 297 if (test_name.find("SLOW_") != std::string::npos)
296 timeout_ms *= kSlowTestTimeoutMultiplier; 298 timeout_ms *= kSlowTestTimeoutMultiplier;
297 299
298 return timeout_ms; 300 return timeout_ms;
299 } 301 }
300 302
301 // Runs test specified by |test_name| in a child process, 303 // Runs test specified by |test_name| in a child process,
302 // and returns the exit code. 304 // and returns the exit code.
303 int RunTest(TestLauncherDelegate* launcher_delegate, 305 int RunTest(TestLauncherDelegate* launcher_delegate,
304 const std::string& test_name, 306 const std::string& test_name,
305 int default_timeout_ms) { 307 int default_timeout_ms,
308 bool* was_timeout) {
309 if (was_timeout)
310 *was_timeout = false;
311
306 #if defined(OS_MACOSX) 312 #if defined(OS_MACOSX)
307 // Some of the below method calls will leak objects if there is no 313 // Some of the below method calls will leak objects if there is no
308 // autorelease pool in place. 314 // autorelease pool in place.
309 base::mac::ScopedNSAutoreleasePool pool; 315 base::mac::ScopedNSAutoreleasePool pool;
310 #endif 316 #endif
311 317
312 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 318 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
313 CommandLine new_cmd_line(cmd_line->GetProgram()); 319 CommandLine new_cmd_line(cmd_line->GetProgram());
314 CommandLine::SwitchMap switches = cmd_line->GetSwitches(); 320 CommandLine::SwitchMap switches = cmd_line->GetSwitches();
315 321
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 374
369 int timeout_ms = GetTestTerminationTimeout(test_name, 375 int timeout_ms = GetTestTerminationTimeout(test_name,
370 default_timeout_ms); 376 default_timeout_ms);
371 377
372 int exit_code = 0; 378 int exit_code = 0;
373 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code, 379 if (!base::WaitForExitCodeWithTimeout(process_handle, &exit_code,
374 timeout_ms)) { 380 timeout_ms)) {
375 LOG(ERROR) << "Test timeout (" << timeout_ms 381 LOG(ERROR) << "Test timeout (" << timeout_ms
376 << " ms) exceeded for " << test_name; 382 << " ms) exceeded for " << test_name;
377 383
384 if (was_timeout)
385 *was_timeout = true;
378 exit_code = -1; // Set a non-zero exit code to signal a failure. 386 exit_code = -1; // Set a non-zero exit code to signal a failure.
379 387
380 // Ensure that the process terminates. 388 // Ensure that the process terminates.
381 base::KillProcess(process_handle, -1, true); 389 base::KillProcess(process_handle, -1, true);
382 } 390 }
383 391
384 #if defined(OS_POSIX) 392 #if defined(OS_POSIX)
385 if (exit_code != 0) { 393 if (exit_code != 0) {
386 // On POSIX, in case the test does not exit cleanly, either due to a crash 394 // 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 395 // 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 = ""; 422 std::string negative_filter = "";
415 size_t dash_pos = filter.find('-'); 423 size_t dash_pos = filter.find('-');
416 if (dash_pos != std::string::npos) { 424 if (dash_pos != std::string::npos) {
417 positive_filter = filter.substr(0, dash_pos); // Everything up to the dash. 425 positive_filter = filter.substr(0, dash_pos); // Everything up to the dash.
418 negative_filter = filter.substr(dash_pos + 1); // Everything after the dash. 426 negative_filter = filter.substr(dash_pos + 1); // Everything after the dash.
419 } 427 }
420 428
421 int num_runnable_tests = 0; 429 int num_runnable_tests = 0;
422 int test_run_count = 0; 430 int test_run_count = 0;
423 int ignored_failure_count = 0; 431 int ignored_failure_count = 0;
432 int timeout_count = 0;
424 std::vector<std::string> failed_tests; 433 std::vector<std::string> failed_tests;
425 434
426 ResultsPrinter printer(*command_line); 435 ResultsPrinter printer(*command_line);
427 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { 436 for (int i = 0; i < unit_test->total_test_case_count(); ++i) {
428 const testing::TestCase* test_case = unit_test->GetTestCase(i); 437 const testing::TestCase* test_case = unit_test->GetTestCase(i);
429 TestCasePrinterHelper helper(printer, test_case->name(), 438 TestCasePrinterHelper helper(printer, test_case->name(),
430 test_case->total_test_count()); 439 test_case->total_test_count());
431 for (int j = 0; j < test_case->total_test_count(); ++j) { 440 for (int j = 0; j < test_case->total_test_count(); ++j) {
432 const testing::TestInfo* test_info = test_case->GetTestInfo(j); 441 const testing::TestInfo* test_info = test_case->GetTestInfo(j);
433 std::string test_name = test_info->test_case_name(); 442 std::string test_name = test_info->test_case_name();
(...skipping 29 matching lines...) Expand all
463 num_runnable_tests); 472 num_runnable_tests);
464 } 473 }
465 num_runnable_tests += 1; 474 num_runnable_tests += 1;
466 // If sharding is enabled and the test should not be run, skip it. 475 // If sharding is enabled and the test should not be run, skip it.
467 if (!should_run) { 476 if (!should_run) {
468 continue; 477 continue;
469 } 478 }
470 479
471 base::Time start_time = base::Time::Now(); 480 base::Time start_time = base::Time::Now();
472 ++test_run_count; 481 ++test_run_count;
482 bool was_timeout = false;
473 int exit_code = RunTest(launcher_delegate, 483 int exit_code = RunTest(launcher_delegate,
474 test_name, 484 test_name,
475 TestTimeouts::action_max_timeout_ms()); 485 TestTimeouts::action_max_timeout_ms(),
486 &was_timeout);
476 if (exit_code == 0) { 487 if (exit_code == 0) {
477 // Test passed. 488 // Test passed.
478 printer.OnTestEnd(test_info->name(), test_case->name(), true, false, 489 printer.OnTestEnd(test_info->name(), test_case->name(), true, false,
479 false, 490 false,
480 (base::Time::Now() - start_time).InMillisecondsF()); 491 (base::Time::Now() - start_time).InMillisecondsF());
481 } else { 492 } else {
482 failed_tests.push_back(test_name); 493 failed_tests.push_back(test_name);
483 494
484 bool ignore_failure = false; 495 bool ignore_failure = false;
485 496
486 // -1 exit code means a crash or hang. Never ignore those failures, 497 // -1 exit code means a crash or hang. Never ignore those failures,
487 // they are serious and should always be visible. 498 // they are serious and should always be visible.
488 if (exit_code != -1) 499 if (exit_code != -1)
489 ignore_failure = base::TestSuite::ShouldIgnoreFailure(*test_info); 500 ignore_failure = base::TestSuite::ShouldIgnoreFailure(*test_info);
490 501
491 printer.OnTestEnd(test_info->name(), test_case->name(), true, true, 502 printer.OnTestEnd(test_info->name(), test_case->name(), true, true,
492 ignore_failure, 503 ignore_failure,
493 (base::Time::Now() - start_time).InMillisecondsF()); 504 (base::Time::Now() - start_time).InMillisecondsF());
494 if (ignore_failure) 505 if (ignore_failure)
495 ++ignored_failure_count; 506 ++ignored_failure_count;
507
508 if (was_timeout)
509 ++timeout_count;
496 } 510 }
511
512 if (timeout_count > kMaxTimeouts) {
513 printf("More than %d timeouts, aborting test case\n", kMaxTimeouts);
514 break;
515 }
516 }
517 if (timeout_count > kMaxTimeouts) {
518 printf("More than %d timeouts, aborting test\n", kMaxTimeouts);
519 break;
497 } 520 }
498 } 521 }
499 522
500 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : ""); 523 printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : "");
501 printf("%d test%s failed (%d ignored)\n", 524 printf("%d test%s failed (%d ignored)\n",
502 static_cast<int>(failed_tests.size()), 525 static_cast<int>(failed_tests.size()),
503 failed_tests.size() > 1 ? "s" : "", ignored_failure_count); 526 failed_tests.size() > 1 ? "s" : "", ignored_failure_count);
504 if (failed_tests.size() - ignored_failure_count == 0) 527 if (failed_tests.size() - ignored_failure_count == 0)
505 return true; 528 return true;
506 529
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 631
609 testing::InitGoogleTest(&argc, argv); 632 testing::InitGoogleTest(&argc, argv);
610 TestTimeouts::Initialize(); 633 TestTimeouts::Initialize();
611 634
612 // Make sure the entire browser code is loaded into memory. Reading it 635 // 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 636 // 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 637 // 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. 638 // and closes a browser with a long timeout to avoid those problems.
616 int exit_code = RunTest(launcher_delegate, 639 int exit_code = RunTest(launcher_delegate,
617 kEmptyTestName, 640 kEmptyTestName,
618 TestTimeouts::large_test_timeout_ms()); 641 TestTimeouts::large_test_timeout_ms(),
642 NULL);
619 if (exit_code != 0) 643 if (exit_code != 0)
620 return exit_code; 644 return exit_code;
621 645
622 int cycles = 1; 646 int cycles = 1;
623 if (command_line->HasSwitch(kGTestRepeatFlag)) { 647 if (command_line->HasSwitch(kGTestRepeatFlag)) {
624 base::StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag), 648 base::StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag),
625 &cycles); 649 &cycles);
626 } 650 }
627 651
628 while (cycles != 0) { 652 while (cycles != 0) {
629 if (!RunTests(launcher_delegate, 653 if (!RunTests(launcher_delegate,
630 should_shard, 654 should_shard,
631 total_shards, 655 total_shards,
632 shard_index)) { 656 shard_index)) {
633 exit_code = 1; 657 exit_code = 1;
634 break; 658 break;
635 } 659 }
636 660
637 // Special value "-1" means "repeat indefinitely". 661 // Special value "-1" means "repeat indefinitely".
638 if (cycles != -1) 662 if (cycles != -1)
639 cycles--; 663 cycles--;
640 } 664 }
641 return exit_code; 665 return exit_code;
642 } 666 }
643 667
644 } // namespace test_launcher 668 } // 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