Changeset 235399 in webkit


Ignore:
Timestamp:
Aug 27, 2018, 2:11:22 PM (7 years ago)
Author:
Simon Fraser
Message:

Convert timeout values in WebKitTestRunner to WTF::Seconds
https://bugs.webkit.org/show_bug.cgi?id=188987

Reviewed by Ryosuke Niwa.

Replace various 'int' timeout values with WTF::Seconds. The timeout argument
comes in as milliseconds, so convert on input. When sending messages to the InjectedBundle
using integers, convert to and from milliseconds.

Also do some #pragma once, and initializer cleanup.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::didReceiveMessageToPage):
(WTR::InjectedBundle::beginTesting):
(WTR::InjectedBundle::InjectedBundle): Deleted.

  • WebKitTestRunner/InjectedBundle/InjectedBundle.h:
  • WebKitTestRunner/InjectedBundle/TestRunner.h:

(WTR::TestRunner::timeout):
(WTR::TestRunner::setCustomTimeout):

  • WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:

(WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):

  • WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:

(WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
(WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):

  • WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp:

(WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::TestController):
(WTR::parseInputLine):
(WTR::TestController::runTest):
(WTR::TestController::runUntil):
(WTR::TestController::didReceiveMessageFromInjectedBundle):

  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::shortTimeout const):
(WTR::TestInvocation::createTestSettingsDictionary):

  • WebKitTestRunner/TestInvocation.h:
  • WebKitTestRunner/TestOptions.h:
  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::TestController::platformRunUntil):

  • WebKitTestRunner/gtk/TestControllerGtk.cpp:

(WTR::TestController::platformRunUntil):

  • WebKitTestRunner/wpe/TestControllerWPE.cpp:

(WTR::TestController::platformRunUntil):

Location:
trunk/Tools
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r235397 r235399  
     12018-08-27  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Convert timeout values in WebKitTestRunner to WTF::Seconds
     4        https://bugs.webkit.org/show_bug.cgi?id=188987
     5
     6        Reviewed by Ryosuke Niwa.
     7       
     8        Replace various 'int' timeout values with WTF::Seconds. The timeout argument
     9        comes in as milliseconds, so convert on input. When sending messages to the InjectedBundle
     10        using integers, convert to and from milliseconds.
     11       
     12        Also do some #pragma once, and initializer cleanup.
     13
     14        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     15        (WTR::InjectedBundle::didReceiveMessageToPage):
     16        (WTR::InjectedBundle::beginTesting):
     17        (WTR::InjectedBundle::InjectedBundle): Deleted.
     18        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     19        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     20        (WTR::TestRunner::timeout):
     21        (WTR::TestRunner::setCustomTimeout):
     22        * WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
     23        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     24        * WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:
     25        (WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
     26        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     27        * WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp:
     28        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     29        * WebKitTestRunner/TestController.cpp:
     30        (WTR::TestController::TestController):
     31        (WTR::parseInputLine):
     32        (WTR::TestController::runTest):
     33        (WTR::TestController::runUntil):
     34        (WTR::TestController::didReceiveMessageFromInjectedBundle):
     35        * WebKitTestRunner/TestController.h:
     36        * WebKitTestRunner/TestInvocation.cpp:
     37        (WTR::TestInvocation::shortTimeout const):
     38        (WTR::TestInvocation::createTestSettingsDictionary):
     39        * WebKitTestRunner/TestInvocation.h:
     40        * WebKitTestRunner/TestOptions.h:
     41        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     42        (WTR::TestController::platformRunUntil):
     43        * WebKitTestRunner/gtk/TestControllerGtk.cpp:
     44        (WTR::TestController::platformRunUntil):
     45        * WebKitTestRunner/wpe/TestControllerWPE.cpp:
     46        (WTR::TestController::platformRunUntil):
     47
     482018-08-27  Simon Fraser  <simon.fraser@apple.com>
     49
     50        Convert timeout values in WebKitTestRunner to WTF::Seconds
     51        https://bugs.webkit.org/show_bug.cgi?id=188987
     52
     53        Reviewed by Ryosuke Niwa.
     54       
     55        Replace various 'int' timeout values with WTF::Seconds. The timeout argument
     56        comes in as milliseconds, so convert on input. When sending messages to the InjectedBundle
     57        using integers, convert to and from milliseconds.
     58       
     59        Also do some #pragma once, and initializer cleanup.
     60
     61        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     62        (WTR::InjectedBundle::didReceiveMessageToPage):
     63        (WTR::InjectedBundle::beginTesting):
     64        (WTR::InjectedBundle::InjectedBundle): Deleted.
     65        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     66        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     67        (WTR::TestRunner::timeout):
     68        (WTR::TestRunner::setCustomTimeout):
     69        * WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
     70        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     71        * WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm:
     72        (WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
     73        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     74        * WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp:
     75        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
     76        * WebKitTestRunner/TestController.cpp:
     77        (WTR::TestController::TestController):
     78        (WTR::parseInputLine):
     79        (WTR::TestController::runTest):
     80        (WTR::TestController::runUntil):
     81        (WTR::TestController::didReceiveMessageFromInjectedBundle):
     82        * WebKitTestRunner/TestController.h:
     83        * WebKitTestRunner/TestInvocation.cpp:
     84        (WTR::TestInvocation::shortTimeout const):
     85        (WTR::TestInvocation::createTestSettingsDictionary):
     86        * WebKitTestRunner/TestInvocation.h:
     87        * WebKitTestRunner/TestOptions.h:
     88        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     89        (WTR::TestController::platformRunUntil):
     90        * WebKitTestRunner/gtk/TestControllerGtk.cpp:
     91        (WTR::TestController::platformRunUntil):
     92        * WebKitTestRunner/wpe/TestControllerWPE.cpp:
     93        (WTR::TestController::platformRunUntil):
     94
    1952018-08-27  Alex Christensen  <achristensen@webkit.org>
    296
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r235125 r235399  
    3333    void waitUntilDone();
    3434    void notifyDone();
    35     double preciseTime();
    36     readonly attribute double timeout;
     35    double preciseTime(); // seconds since the epoch
     36    readonly attribute double timeout; // milliseconds
    3737
    3838    // Downloads.
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r234440 r235399  
    6565}
    6666
    67 InjectedBundle::InjectedBundle()
    68     : m_bundle(0)
    69     , m_topLoadingFrame(0)
    70     , m_state(Idle)
    71     , m_dumpPixels(false)
    72     , m_useWaitToDumpWatchdogTimer(true)
    73     , m_useWorkQueue(false)
    74     , m_timeout(0)
    75 {
    76 }
    77 
    7867void InjectedBundle::didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo)
    7968{
     
    206195
    207196        WKRetainPtr<WKStringRef> timeoutKey(AdoptWK, WKStringCreateWithUTF8CString("Timeout"));
    208         m_timeout = (int)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get())));
     197        m_timeout = Seconds::fromMilliseconds(WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, timeoutKey.get()))));
    209198
    210199        WKRetainPtr<WKStringRef> dumpJSConsoleLogInStdErrKey(AdoptWK, WKStringCreateWithUTF8CString("DumpJSConsoleLogInStdErr"));
     
    232221        WKRetainPtr<WKStringRef> shouldGCKey(AdoptWK, WKStringCreateWithUTF8CString("ShouldGC"));
    233222        bool shouldGC = WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(messageBodyDictionary, shouldGCKey.get())));
    234 
    235223        if (shouldGC)
    236224            WKBundleGarbageCollectJavaScriptObjects(m_bundle);
     
    488476    m_testRunner->clearTestRunnerCallbacks();
    489477
    490     if (m_timeout > 0)
     478    if (m_timeout > 0_s)
    491479        m_testRunner->setCustomTimeout(m_timeout);
    492480
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r233782 r235399  
    146146
    147147private:
    148     InjectedBundle();
     148    InjectedBundle() = default;
    149149    ~InjectedBundle();
    150150
     
    171171    bool booleanForKey(WKDictionaryRef, const char* key);
    172172
    173     WKBundleRef m_bundle;
    174     WKBundlePageGroupRef m_pageGroup;
     173    WKBundleRef m_bundle { nullptr };
     174    WKBundlePageGroupRef m_pageGroup { nullptr };
    175175    Vector<std::unique_ptr<InjectedBundlePage>> m_pages;
    176176
     
    183183    RefPtr<TextInputController> m_textInputController;
    184184
    185     WKBundleFrameRef m_topLoadingFrame;
     185    WKBundleFrameRef m_topLoadingFrame { nullptr };
    186186
    187187    enum State {
     
    190190        Stopping
    191191    };
    192     State m_state;
    193 
    194     bool m_dumpPixels;
    195     bool m_useWaitToDumpWatchdogTimer;
    196     bool m_useWorkQueue;
    197     int m_timeout;
     192    State m_state { Idle };
     193
     194    bool m_dumpPixels { false };
     195    bool m_useWaitToDumpWatchdogTimer { true };
     196    bool m_useWorkQueue { false };
    198197    bool m_pixelResultIsPending { false };
    199198    bool m_dumpJSConsoleLogInStdErr { false };
     199
     200    WTF::Seconds m_timeout;
    200201
    201202    WKRetainPtr<WKDataRef> m_audioResult;
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r235125 r235399  
    3434#include <string>
    3535#include <wtf/Ref.h>
     36#include <wtf/Seconds.h>
    3637#include <wtf/text/WTFString.h>
    3738
     
    7273    void notifyDone();
    7374    double preciseTime();
    74     double timeout() { return m_timeout; }
     75    double timeout() { return m_timeout.milliseconds(); }
    7576
    7677    // Other dumping.
     
    316317    bool callShouldCloseOnWebView();
    317318
    318     void setCustomTimeout(int duration) { m_timeout = duration; }
     319    void setCustomTimeout(WTF::Seconds duration) { m_timeout = duration; }
    319320
    320321    // Work queue.
     
    513514    bool m_customFullScreenBehavior;
    514515
    515     int m_timeout;
     516    WTF::Seconds m_timeout;
    516517
    517518    double m_databaseDefaultQuota;
  • trunk/Tools/WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp

    r232832 r235399  
    5050        return;
    5151
    52     m_waitToDumpWatchdogTimer.startOneShot(1_ms * m_timeout);
     52    m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
    5353}
    5454
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/TestRunnerMac.mm

    r225641 r235399  
    4949
    5050    CFRunLoopTimerInvalidate(m_waitToDumpWatchdogTimer.get());
    51     m_waitToDumpWatchdogTimer = 0;
     51    m_waitToDumpWatchdogTimer = nullptr;
    5252}
    5353
     
    6262        return;
    6363
    64     CFTimeInterval interval = m_timeout / 1000.0;
     64    CFTimeInterval interval = m_timeout.seconds();
    6565    m_waitToDumpWatchdogTimer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + interval, 0, 0, 0, WTR::waitUntilDoneWatchdogTimerFired, NULL));
    6666    CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_waitToDumpWatchdogTimer.get(), kCFRunLoopCommonModes);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/wpe/TestRunnerWPE.cpp

    r229256 r235399  
    5353{
    5454    if (!m_waitToDumpWatchdogTimer.isActive())
    55         m_waitToDumpWatchdogTimer.startOneShot(1_ms * m_timeout);
     55        m_waitToDumpWatchdogTimer.startOneShot(m_timeout);
    5656}
    5757
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r235125 r235399  
    9595const unsigned TestController::w3cSVGViewHeight = 360;
    9696
    97 const double TestController::defaultShortTimeout = 5.0;
    98 
    99 const double TestController::noTimeout = -1;
     97const WTF::Seconds TestController::defaultShortTimeout = 5_s;
     98const WTF::Seconds TestController::noTimeout = -1_s;
    10099
    101100static WKURLRef blankURL()
     
    130129    controller = this;
    131130    run();
    132     controller = 0;
     131    controller = nullptr;
    133132}
    134133
     
    12531252        if (arg == std::string("--timeout")) {
    12541253            std::string timeoutToken = tokenizer.next();
    1255             result.timeout = atoi(timeoutToken.c_str());
     1254            result.timeout = Seconds::fromMilliseconds(atoi(timeoutToken.c_str()));
    12561255        } else if (arg == std::string("-p") || arg == std::string("--pixel-test")) {
    12571256            result.shouldDumpPixels = true;
     
    12841283    if (command.shouldDumpPixels || m_shouldDumpPixelsForAllTests)
    12851284        m_currentInvocation->setIsPixelTest(command.expectedPixelHash);
    1286     if (command.timeout > 0)
     1285
     1286    if (command.timeout > 0_s)
    12871287        m_currentInvocation->setCustomTimeout(command.timeout);
     1288
    12881289    m_currentInvocation->setDumpJSConsoleLogInStdErr(command.dumpJSConsoleLogInStdErr || options.dumpJSConsoleLogInStdErr);
    12891290
     
    13241325}
    13251326
    1326 void TestController::runUntil(bool& done, double timeout)
     1327void TestController::runUntil(bool& done, WTF::Seconds timeout)
    13271328{
    13281329    if (m_forceNoTimeout)
     
    14151416        if (WKStringIsEqualToUTF8CString(subMessageName, "KeyDown")) {
    14161417            didReceiveKeyDownMessageFromInjectedBundle(messageBodyDictionary, false);
    1417 
    14181418            return;
    14191419        }
  • trunk/Tools/WebKitTestRunner/TestController.h

    r235125 r235399  
    2424 */
    2525
    26 #ifndef TestController_h
    27 #define TestController_h
     26#pragma once
    2827
    2928#include "GeolocationProviderMock.h"
     
    3534#include <vector>
    3635#include <wtf/HashMap.h>
     36#include <wtf/Seconds.h>
    3737#include <wtf/Vector.h>
    3838#include <wtf/text/StringHash.h>
     
    6060    static const unsigned w3cSVGViewHeight;
    6161
    62     static const double defaultShortTimeout;
    63     static const double noTimeout;
     62    static const WTF::Seconds defaultShortTimeout;
     63    static const WTF::Seconds noTimeout;
    6464
    6565    TestController(int argc, const char* argv[]);
     
    8080    // Runs the run loop until `done` is true or the timeout elapses.
    8181    bool useWaitToDumpWatchdogTimer() { return m_useWaitToDumpWatchdogTimer; }
    82     void runUntil(bool& done, double timeoutSeconds);
     82    void runUntil(bool& done, WTF::Seconds timeout);
    8383    void notifyDone();
    8484
     
    248248    void platformConfigureViewForTest(const TestInvocation&);
    249249    void platformWillRunTest(const TestInvocation&);
    250     void platformRunUntil(bool& done, double timeout);
     250    void platformRunUntil(bool& done, WTF::Seconds timeout);
    251251    void platformDidCommitLoadForFrame(WKPageRef, WKFrameRef);
    252252    WKContextRef platformContext();
     
    292292    void didFinishNavigation(WKPageRef, WKNavigationRef);
    293293
    294    
    295294    // WKContextDownloadClient
    296295    static void downloadDidStart(WKContextRef, WKDownloadRef, const void*);
     
    451450    std::string pathOrURL;
    452451    std::string absolutePath;
     452    std::string expectedPixelHash;
     453    WTF::Seconds timeout;
    453454    bool shouldDumpPixels { false };
    454     std::string expectedPixelHash;
    455     int timeout { 0 };
    456455    bool dumpJSConsoleLogInStdErr { false };
    457456};
    458457
    459458} // namespace WTR
    460 
    461 #endif // TestController_h
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r235243 r235399  
    102102}
    103103
    104 double TestInvocation::shortTimeout() const
     104WTF::Seconds TestInvocation::shortTimeout() const
    105105{
    106106    if (!m_timeout) {
     
    113113    // for each test individually.
    114114    // But there shouldn't be any observable negative consequences from this.
    115     return m_timeout / 1000. / 4;
     115    return m_timeout / 4;
    116116}
    117117
     
    138138
    139139    WKRetainPtr<WKStringRef> timeoutKey = adoptWK(WKStringCreateWithUTF8CString("Timeout"));
    140     WKRetainPtr<WKUInt64Ref> timeoutValue = adoptWK(WKUInt64Create(m_timeout));
     140    WKRetainPtr<WKUInt64Ref> timeoutValue = adoptWK(WKUInt64Create(m_timeout.milliseconds()));
    141141    WKDictionarySetItem(beginTestMessageBody.get(), timeoutKey.get(), timeoutValue.get());
    142142
  • trunk/Tools/WebKitTestRunner/TestInvocation.h

    r234440 r235399  
    3434#include <string>
    3535#include <wtf/Noncopyable.h>
     36#include <wtf/Seconds.h>
    3637#include <wtf/text/StringBuilder.h>
    3738
     
    5152    void setIsPixelTest(const std::string& expectedPixelHash);
    5253
    53     // Milliseconds
    54     void setCustomTimeout(int duration) { m_timeout = duration; }
     54    void setCustomTimeout(WTF::Seconds duration) { m_timeout = duration; }
    5555    void setDumpJSConsoleLogInStdErr(bool value) { m_dumpJSConsoleLogInStdErr = value; }
    5656
    57     // Seconds
    58     double shortTimeout() const;
     57    WTF::Seconds shortTimeout() const;
    5958
    6059    void invoke();
     
    117116    std::string m_expectedPixelHash;
    118117
    119     int m_timeout { 0 };
     118    WTF::Seconds m_timeout;
    120119    bool m_dumpJSConsoleLogInStdErr { false };
    121120
  • trunk/Tools/WebKitTestRunner/TestOptions.h

    r233897 r235399  
    2424 */
    2525
    26 #ifndef TestOptions_h
    27 #define TestOptions_h
     26#pragma once
    2827
    2928#include <wtf/Vector.h>
     
    112111
    113112}
    114 
    115 #endif // TestOptions_h
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r234440 r235399  
    197197}
    198198
    199 void TestController::platformRunUntil(bool& done, double timeout)
    200 {
    201     NSDate *endDate = (timeout > 0) ? [NSDate dateWithTimeIntervalSinceNow:timeout] : [NSDate distantFuture];
     199void TestController::platformRunUntil(bool& done, WTF::Seconds timeout)
     200{
     201    NSDate *endDate = (timeout > 0_s) ? [NSDate dateWithTimeIntervalSinceNow:timeout.seconds()] : [NSDate distantFuture];
    202202
    203203    while (!done && [endDate compare:[NSDate date]] == NSOrderedDescending)
  • trunk/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp

    r226349 r235399  
    7575}
    7676
    77 void TestController::platformRunUntil(bool&, double timeout)
     77void TestController::platformRunUntil(bool&, WTF::Seconds timeout)
    7878{
    79     if (timeout > 0) {
     79    if (timeout > 0_s) {
    8080        // FIXME: This conversion is now repeated in several places, it should be moved to a common place in WTF and used everywhere.
    81         auto timeoutDuration = Seconds { timeout };
    8281        gint64 currentTime = g_get_monotonic_time();
    83         gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, timeoutDuration.microsecondsAs<int64_t>());
     82        gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, timeout.microsecondsAs<int64_t>());
    8483        ASSERT(targetTime >= currentTime);
    8584        g_source_set_ready_time(timeoutSource(), targetTime);
  • trunk/Tools/WebKitTestRunner/wpe/TestControllerWPE.cpp

    r229256 r235399  
    5959}
    6060
    61 void TestController::platformRunUntil(bool& condition, double timeout)
     61void TestController::platformRunUntil(bool& condition, WTF::Seconds timeout)
    6262{
    6363    struct TimeoutTimer {
     
    7171
    7272    timeoutTimer.timer.setPriority(G_PRIORITY_DEFAULT_IDLE);
    73     if (timeout >= 0)
    74         timeoutTimer.timer.startOneShot(Seconds(timeout));
     73    if (timeout >= 0_s)
     74        timeoutTimer.timer.startOneShot(timeout);
    7575
    7676    RunLoop::main().run();
Note: See TracChangeset for help on using the changeset viewer.