summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 20:40:22 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 20:40:22 +0000
commita5ab5b4330347700eb68669dc326adff9694214f (patch)
tree6039fbb9d85350b8e254bdf98c54c7bbadb9919f
parentb71ffc6c2a90e8dcf670fd7c7b6df8dca4ca50c3 (diff)
downloadchromium_src-a5ab5b4330347700eb68669dc326adff9694214f.zip
chromium_src-a5ab5b4330347700eb68669dc326adff9694214f.tar.gz
chromium_src-a5ab5b4330347700eb68669dc326adff9694214f.tar.bz2
implement a watchdog timeout for the layout tests
Review URL: http://codereview.chromium.org/6393 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3125 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm71
1 files changed, 69 insertions, 2 deletions
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index 55e09d4..55e4f90 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/debug_on_start.h"
+#include "base/debug_util.h"
#include "base/file_util.h"
#include "base/gfx/bitmap_platform_device.h"
#include "base/gfx/png_encoder.h"
@@ -294,6 +295,61 @@ void TestShell::TestFinished() {
MessageLoop::current()->Quit();
}
+// A class to be the target/selector of the "watchdog" thread that ensures
+// pages timeout if they take too long and tells the test harness via stdout.
+@interface WatchDogTarget : NSObject {
+ @private
+ NSTimeInterval timeout_;
+}
+// |timeout| is in seconds
+- (id)initWithTimeout:(NSTimeInterval)timeout;
+// serves as the "run" method of a NSThread.
+- (void)run:(id)sender;
+@end
+
+@implementation WatchDogTarget
+
+- (id)initWithTimeout:(NSTimeInterval)timeout {
+ if ((self = [super init])) {
+ timeout_ = timeout;
+ }
+ return self;
+}
+
+- (void)run:(id)ignore {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ // check for debugger, just bail if so. We don't want the timeouts hitting
+ // when we're trying to track down an issue.
+ if (DebugUtil::BeingDebugged())
+ return;
+
+ NSThread* currentThread = [NSThread currentThread];
+
+ // Wait to be cancelled. If we are that means the test finished. If it hasn't,
+ // then we need to tell the layout script we timed out and start again.
+ NSDate* limitDate = [NSDate dateWithTimeIntervalSinceNow:timeout_];
+ while ([(NSDate*)[NSDate date] compare:limitDate] == NSOrderedAscending &&
+ ![currentThread isCancelled]) {
+ // sleep for a small increment then check again
+ NSDate* incrementDate = [NSDate dateWithTimeIntervalSinceNow:1.0];
+ [NSThread sleepUntilDate:incrementDate];
+ }
+ if (![currentThread isCancelled]) {
+ // Print a warning to be caught by the layout-test script.
+ // Note: the layout test driver may or may not recognize
+ // this as a timeout.
+ puts("#TEST_TIMED_OUT\n");
+ puts("#EOF\n");
+ fflush(stdout);
+ [[NSApplication sharedApplication] terminate:self];
+ }
+
+ [pool release];
+}
+
+@end
+
void TestShell::WaitTestFinished() {
DCHECK(!test_is_pending_) << "cannot be used recursively";
@@ -305,13 +361,24 @@ void TestShell::WaitTestFinished() {
// message loop. If the watchdog is what catches a
// timeout, it can't do anything except terminate the test
// shell, which is unfortunate.
-
- // TODO(port): implement this
+ // Why multiply the timeout by 2.5? Who knows. That's what windows does.
+ NSTimeInterval timeout_seconds = GetFileTestTimeout() * 2.5 / 1000;
+ WatchDogTarget* watchdog = [[[WatchDogTarget alloc]
+ initWithTimeout:timeout_seconds] autorelease];
+ NSThread* thread = [[NSThread alloc] initWithTarget:watchdog
+ selector:@selector(run:)
+ object:nil];
+ [thread start];
// TestFinished() will post a quit message to break this loop when the page
// finishes loading.
while (test_is_pending_)
MessageLoop::current()->Run();
+
+ // Tell the watchdog that we're finished. No point waiting to re-join, it'll
+ // die on its own.
+ [thread cancel];
+ [thread release];
}
void TestShell::Show(WebView* webview, WindowOpenDisposition disposition) {