Changeset 244723 in webkit


Ignore:
Timestamp:
Apr 27, 2019 3:45:38 PM (5 years ago)
Author:
Chris Dumez
Message:

[WKTR] Move test timeout handling to the UIProcess
https://bugs.webkit.org/show_bug.cgi?id=197333

Reviewed by Darin Adler.

Move test timeout handling in WebKitTestRunner to the UIProcess to play nicely with PSON. Previously,
we'd start the timeout timer in the InjectedBundle, which would fail to account of the time spent in
every WebContent process in the case of swapping.

Also, because of process caching, the timeout timer would sometime fire in a cached process and it
would lead to crashes when firing the timer.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::didReceiveMessageToPage):
(WTR::InjectedBundle::done):

  • WebKitTestRunner/InjectedBundle/InjectedBundle.h:

(WTR::InjectedBundle::shouldDumpPixels const):

  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::TestRunner):
(WTR::TestRunner::waitUntilDone):
(WTR::TestRunner::setWaitUntilDone):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
  • WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:
  • WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp:
  • WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::TestInvocation):
(WTR::TestInvocation::createTestSettingsDictionary):
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
(WTR::TestInvocation::initializeWaitToDumpWatchdogTimerIfNeeded):
(WTR::TestInvocation::invalidateWaitToDumpWatchdogTimer):
(WTR::TestInvocation::waitToDumpWatchdogTimerFired):
(WTR::TestInvocation::setWaitUntilDone):
(WTR::TestInvocation::done):

  • WebKitTestRunner/TestInvocation.h:
Location:
trunk/Tools
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r244711 r244723  
     12019-04-27  Chris Dumez  <cdumez@apple.com>
     2
     3        [WKTR] Move test timeout handling to the UIProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=197333
     5
     6        Reviewed by Darin Adler.
     7
     8        Move test timeout handling in WebKitTestRunner to the UIProcess to play nicely with PSON. Previously,
     9        we'd start the timeout timer in the InjectedBundle, which would fail to account of the time spent in
     10        every WebContent process in the case of swapping.
     11
     12        Also, because of process caching, the timeout timer would sometime fire in a cached process and it
     13        would lead to crashes when firing the timer.
     14
     15        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     16        (WTR::InjectedBundle::didReceiveMessageToPage):
     17        (WTR::InjectedBundle::done):
     18        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     19        (WTR::InjectedBundle::shouldDumpPixels const):
     20        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     21        (WTR::TestRunner::TestRunner):
     22        (WTR::TestRunner::waitUntilDone):
     23        (WTR::TestRunner::setWaitUntilDone):
     24        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     25        * WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
     26        * WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:
     27        * WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp:
     28        * WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp:
     29        * WebKitTestRunner/TestInvocation.cpp:
     30        (WTR::TestInvocation::TestInvocation):
     31        (WTR::TestInvocation::createTestSettingsDictionary):
     32        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
     33        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     34        (WTR::TestInvocation::initializeWaitToDumpWatchdogTimerIfNeeded):
     35        (WTR::TestInvocation::invalidateWaitToDumpWatchdogTimer):
     36        (WTR::TestInvocation::waitToDumpWatchdogTimerFired):
     37        (WTR::TestInvocation::setWaitUntilDone):
     38        (WTR::TestInvocation::done):
     39        * WebKitTestRunner/TestInvocation.h:
     40
    1412019-04-25  Yusuke Suzuki  <ysuzuki@apple.com>
    242
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r244390 r244723  
    209209        m_dumpPixels = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, dumpPixelsKey.get())));
    210210
    211         WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
    212         m_useWaitToDumpWatchdogTimer = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, useWaitToDumpWatchdogTimerKey.get())));
    213 
    214211        WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout"));
    215212        m_timeout = Seconds::fromMilliseconds(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get()))));
     
    544541    setTopLoadingFrame(0);
    545542
    546     m_testRunner->invalidateWaitToDumpWatchdogTimer();
    547 
    548543#if HAVE(ACCESSIBILITY)
    549544    m_accessibilityController->resetToConsistentState();
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r235408 r244723  
    8181
    8282    bool shouldDumpPixels() const { return m_dumpPixels; }
    83     bool useWaitToDumpWatchdogTimer() const { return m_useWaitToDumpWatchdogTimer; }
    8483    bool dumpJSConsoleLogInStdErr() const { return m_dumpJSConsoleLogInStdErr; };
    8584
     
    195194
    196195    bool m_dumpPixels { false };
    197     bool m_useWaitToDumpWatchdogTimer { true };
    198196    bool m_useWorkQueue { false };
    199197    bool m_pixelResultIsPending { false };
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r244614 r244723  
    6767TestRunner::TestRunner()
    6868    : m_userStyleSheetLocation(adoptWK(WKStringCreateWithUTF8CString("")))
    69 #if !PLATFORM(COCOA)
    70     , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestRunner::waitToDumpWatchdogTimerFired)
    71 #endif
    7269{
    7370    platformInitialize();
     
    162159
    163160    setWaitUntilDone(true);
    164     // FIXME: Watchdog timer should be moved to UI process in order to take the elapsed time in anotehr process into account.
    165     if (injectedBundle.useWaitToDumpWatchdogTimer())
    166         initializeWaitToDumpWatchdogTimerIfNeeded();
    167161}
    168162
    169163void TestRunner::setWaitUntilDone(bool value)
    170164{
    171     WKRetainPtr<WKStringRef> messsageName = adoptWK(WKStringCreateWithUTF8CString("SetWaitUntilDone"));
     165    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetWaitUntilDone"));
    172166    WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value));
    173     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messsageName.get(), messageBody.get(), nullptr);
     167    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
    174168}
    175169
     
    181175    ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID());
    182176    return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get());
    183 }
    184 
    185 void TestRunner::waitToDumpWatchdogTimerFired()
    186 {
    187     invalidateWaitToDumpWatchdogTimer();
    188     auto& injectedBundle = InjectedBundle::singleton();
    189 #if PLATFORM(COCOA)
    190     char buffer[1024];
    191     snprintf(buffer, sizeof(buffer), "#PID UNRESPONSIVE - %s (pid %d)\n", getprogname(), getpid());
    192     injectedBundle.outputText(buffer);
    193 #endif
    194     injectedBundle.outputText("FAIL: Timed out waiting for notifyDone to be called\n\n");
    195     injectedBundle.done();
    196177}
    197178
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r244614 r244723  
    3636#include <wtf/Seconds.h>
    3737#include <wtf/text/WTFString.h>
    38 
    39 #if PLATFORM(COCOA)
    40 #include <wtf/RetainPtr.h>
    41 #include <CoreFoundation/CFRunLoop.h>
    42 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
    43 #else
    44 #include <wtf/RunLoop.h>
    45 namespace WTR {
    46 class TestRunner;
    47 typedef RunLoop::Timer<TestRunner> PlatformTimerRef;
    48 }
    49 #endif
    5038
    5139namespace WTR {
     
    234222
    235223    bool shouldWaitUntilDone() const;
    236     void waitToDumpWatchdogTimerFired();
    237     void invalidateWaitToDumpWatchdogTimer();
    238224
    239225    // Downloads
     
    513499
    514500    void platformInitialize();
    515     void initializeWaitToDumpWatchdogTimerIfNeeded();
    516501
    517502    void setDumpPixels(bool);
     
    527512    WKRetainPtr<WKStringRef> m_userStyleSheetLocation;
    528513    WKRetainPtr<WKArrayRef> m_allowedHosts;
    529 
    530     PlatformTimerRef m_waitToDumpWatchdogTimer;
    531514
    532515    double m_databaseDefaultQuota { -1 };
  • trunk/Tools/WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp

    r235399 r244723  
    4040}
    4141
    42 void TestRunner::invalidateWaitToDumpWatchdogTimer()
    43 {
    44     m_waitToDumpWatchdogTimer.stop();
    45 }
    46 
    47 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
    48 {
    49     if (m_waitToDumpWatchdogTimer.isActive())
    50         return;
    51 
    52     m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
    53 }
    54 
    5542JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
    5643{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm

    r241597 r244723  
    3737}
    3838
    39 void TestRunner::invalidateWaitToDumpWatchdogTimer()
    40 {
    41     if (!m_waitToDumpWatchdogTimer)
    42         return;
    43 
    44     CFRunLoopTimerInvalidate(m_waitToDumpWatchdogTimer.get());
    45     m_waitToDumpWatchdogTimer = nullptr;
    46 }
    47 
    48 static void waitUntilDoneWatchdogTimerFired(CFRunLoopTimerRef timer, void* info)
    49 {
    50     InjectedBundle::singleton().testRunner()->waitToDumpWatchdogTimerFired();
    51 }
    52 
    53 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
    54 {
    55     if (m_waitToDumpWatchdogTimer)
    56         return;
    57 
    58     CFTimeInterval interval = m_timeout.seconds();
    59     m_waitToDumpWatchdogTimer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + interval, 0, 0, 0, WTR::waitUntilDoneWatchdogTimerFired, NULL));
    60     CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_waitToDumpWatchdogTimer.get(), kCFRunLoopCommonModes);
    61 }
    62 
    6339JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
    6440{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/win/TestRunnerWin.cpp

    r238098 r244723  
    4141}
    4242
    43 void TestRunner::invalidateWaitToDumpWatchdogTimer()
    44 {
    45     m_waitToDumpWatchdogTimer.stop();
    46 }
    47 
    4843void TestRunner::platformInitialize()
    4944{
    50 }
    51 
    52 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
    53 {
    54     if (!m_waitToDumpWatchdogTimer.isActive())
    55         m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
    5645}
    5746
  • trunk/Tools/WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp

    r235399 r244723  
    4141}
    4242
    43 void TestRunner::invalidateWaitToDumpWatchdogTimer()
    44 {
    45     m_waitToDumpWatchdogTimer.stop();
    46 }
    47 
    4843void TestRunner::platformInitialize()
    4944{
    50 }
    51 
    52 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
    53 {
    54     if (!m_waitToDumpWatchdogTimer.isActive())
    55         m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
    5645}
    5746
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r244614 r244723  
    7070    : m_options(options)
    7171    , m_url(url)
     72    , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestInvocation::waitToDumpWatchdogTimerFired)
    7273{
    7374    WKRetainPtr<WKStringRef> urlString = adoptWK(WKURLCopyString(m_url.get()));
     
    138139    WKRetainPtr<WKBooleanRef> dumpPixelsValue = adoptWK(WKBooleanCreate(m_dumpPixels));
    139140    WKDictionarySetItem(beginTestMessageBody.get(), dumpPixelsKey.get(), dumpPixelsValue.get());
    140 
    141     WKRetainPtr<WKStringRef> useWaitToDumpWatchdogTimerKey = adoptWK(WKStringCreateWithUTF8CString("UseWaitToDumpWatchdogTimer"));
    142     WKRetainPtr<WKBooleanRef> useWaitToDumpWatchdogTimerValue = adoptWK(WKBooleanCreate(TestController::singleton().useWaitToDumpWatchdogTimer()));
    143     WKDictionarySetItem(beginTestMessageBody.get(), useWaitToDumpWatchdogTimerKey.get(), useWaitToDumpWatchdogTimerValue.get());
    144141
    145142    WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout"));
     
    358355        m_audioResult = static_cast<WKDataRef>(WKDictionaryGetItemForKey(messageBodyDictionary, audioResultKey.get()));
    359356
    360         m_gotFinalMessage = true;
    361         TestController::singleton().notifyDone();
     357        done();
    362358        return;
    363359    }
     
    833829    if (WKStringIsEqualToUTF8CString(messageName, "SetWaitUntilDone")) {
    834830        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
    835         m_waitUntilDone = static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody)));
     831        setWaitUntilDone(static_cast<unsigned char>(WKBooleanGetValue(static_cast<WKBooleanRef>(messageBody))));
    836832        return nullptr;
    837833    }
     
    18301826}
    18311827
     1828void TestInvocation::initializeWaitToDumpWatchdogTimerIfNeeded()
     1829{
     1830    if (m_waitToDumpWatchdogTimer.isActive())
     1831        return;
     1832
     1833    m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
     1834}
     1835
     1836void TestInvocation::invalidateWaitToDumpWatchdogTimer()
     1837{
     1838    m_waitToDumpWatchdogTimer.stop();
     1839}
     1840
     1841void TestInvocation::waitToDumpWatchdogTimerFired()
     1842{
     1843    invalidateWaitToDumpWatchdogTimer();
     1844
     1845#if PLATFORM(COCOA)
     1846    char buffer[1024];
     1847    snprintf(buffer, sizeof(buffer), "#PID UNRESPONSIVE - %s (pid %d)\n", getprogname(), getpid());
     1848    outputText(buffer);
     1849#endif
     1850    outputText("FAIL: Timed out waiting for notifyDone to be called\n\n");
     1851    done();
     1852}
     1853
     1854void TestInvocation::setWaitUntilDone(bool waitUntilDone)
     1855{
     1856    m_waitUntilDone = waitUntilDone;
     1857    if (waitUntilDone && TestController::singleton().useWaitToDumpWatchdogTimer())
     1858        initializeWaitToDumpWatchdogTimerIfNeeded();
     1859}
     1860
     1861void TestInvocation::done()
     1862{
     1863    m_gotFinalMessage = true;
     1864    invalidateWaitToDumpWatchdogTimer();
     1865    RunLoop::main().dispatch([] {
     1866        TestController::singleton().notifyDone();
     1867    });
     1868}
     1869
    18321870} // namespace WTR
  • trunk/Tools/WebKitTestRunner/TestInvocation.h

    r244370 r244723  
    3434#include <string>
    3535#include <wtf/Noncopyable.h>
     36#include <wtf/RunLoop.h>
    3637#include <wtf/Seconds.h>
    3738#include <wtf/text/StringBuilder.h>
     
    9495    WKRetainPtr<WKMutableDictionaryRef> createTestSettingsDictionary();
    9596
     97    void waitToDumpWatchdogTimerFired();
     98    void initializeWaitToDumpWatchdogTimerIfNeeded();
     99    void invalidateWaitToDumpWatchdogTimer();
     100
     101    void done();
     102    void setWaitUntilDone(bool);
     103
    96104    void dumpResults();
    97105    static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
     
    120128    WKRetainPtr<WKURLRef> m_url;
    121129    WTF::String m_urlString;
     130    RunLoop::Timer<TestInvocation> m_waitToDumpWatchdogTimer;
    122131
    123132    std::string m_expectedPixelHash;
Note: See TracChangeset for help on using the changeset viewer.