Changeset 135496 in webkit


Ignore:
Timestamp:
Nov 22, 2012 1:44:45 AM (11 years ago)
Author:
kbalazs@webkit.org
Message:

[Qt][WTR] TestController::platformRunUntil should not do busy waiting
https://bugs.webkit.org/show_bug.cgi?id=101327

Reviewed by Simon Hausmann.

Avoid busy waiting for events in platformRunUntil while making
sure we don't change the behavior of modal event loops.

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::~TestController):

  • WebKitTestRunner/TestController.h:

(TestController):

  • WebKitTestRunner/efl/TestControllerEfl.cpp:

(WTR::TestController::platformDestroy):
(WTR):

  • WebKitTestRunner/gtk/TestControllerGtk.cpp:

(WTR::TestController::platformDestroy):
(WTR):

  • WebKitTestRunner/mac/TestControllerMac.mm:

(WTR::TestController::platformDestroy):
(WTR):

  • WebKitTestRunner/qt/TestControllerQt.cpp:

(TestController::RunLoop): Helper class to handle
the event loop logic
(WTR):
(WTR::TestController::RunLoop::RunLoop):
(WTR::TestController::RunLoop::runUntil): Use QEventLoop to implement
the run loop. This is the appropriate API to push the WaitForMoreEvents
flag to QCoreApplication::processEvents and also being able to exit the
loop if we have timed out.
(WTR::TestController::RunLoop::notifyDone):
(WTR::TestController::RunLoop::timerFired):
(WTR::TestController::RunLoop::runModal):
(WTR::TestController::notifyDone):
(WTR::TestController::platformInitialize):
(WTR::TestController::platformDestroy):
(WTR::TestController::platformRunUntil):
(WTR::TestController::runModal):

  • WebKitTestRunner/win/TestControllerWin.cpp:

(WTR::TestController::platformDestroy):
(WTR):

Location:
trunk/Tools
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r135489 r135496  
     12012-11-22  Balazs Kelemen  <kbalazs@webkit.org>
     2
     3        [Qt][WTR] TestController::platformRunUntil should not do busy waiting
     4        https://bugs.webkit.org/show_bug.cgi?id=101327
     5
     6        Reviewed by Simon Hausmann.
     7
     8        Avoid busy waiting for events in platformRunUntil while making
     9        sure we don't change the behavior of modal event loops.
     10
     11        * WebKitTestRunner/TestController.cpp:
     12        (WTR::TestController::~TestController):
     13        * WebKitTestRunner/TestController.h:
     14        (TestController):
     15        * WebKitTestRunner/efl/TestControllerEfl.cpp:
     16        (WTR::TestController::platformDestroy):
     17        (WTR):
     18        * WebKitTestRunner/gtk/TestControllerGtk.cpp:
     19        (WTR::TestController::platformDestroy):
     20        (WTR):
     21        * WebKitTestRunner/mac/TestControllerMac.mm:
     22        (WTR::TestController::platformDestroy):
     23        (WTR):
     24        * WebKitTestRunner/qt/TestControllerQt.cpp:
     25        (TestController::RunLoop): Helper class to handle
     26        the event loop logic
     27        (WTR):
     28        (WTR::TestController::RunLoop::RunLoop):
     29        (WTR::TestController::RunLoop::runUntil): Use QEventLoop to implement
     30        the run loop. This is the appropriate API to push the WaitForMoreEvents
     31        flag to QCoreApplication::processEvents and also being able to exit the
     32        loop if we have timed out.
     33        (WTR::TestController::RunLoop::notifyDone):
     34        (WTR::TestController::RunLoop::timerFired):
     35        (WTR::TestController::RunLoop::runModal):
     36        (WTR::TestController::notifyDone):
     37        (WTR::TestController::platformInitialize):
     38        (WTR::TestController::platformDestroy):
     39        (WTR::TestController::platformRunUntil):
     40        (WTR::TestController::runModal):
     41        * WebKitTestRunner/win/TestControllerWin.cpp:
     42        (WTR::TestController::platformDestroy):
     43        (WTR):
     44
    1452012-11-22  Sudarsana Nagineni  <sudarsana.nagineni@intel.com>
    246
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r135151 r135496  
    110110TestController::~TestController()
    111111{
     112    platformDestroy();
    112113}
    113114
  • trunk/Tools/WebKitTestRunner/TestController.h

    r133676 r135496  
    9393
    9494    void platformInitialize();
     95    void platformDestroy();
    9596    void platformInitializeContext();
    9697    void platformRunUntil(bool& done, double timeout);
     
    183184#endif
    184185
     186#if PLATFORM(QT)
     187    class RunLoop;
     188    RunLoop* m_runLoop;
     189#endif
     190
    185191    WorkQueueManager m_workQueueManager;
    186192};
  • trunk/Tools/WebKitTestRunner/efl/TestControllerEfl.cpp

    r132338 r135496  
    5858}
    5959
     60void TestController::platformDestroy()
     61{
     62}
     63
    6064void TestController::platformRunUntil(bool& condition, double timeout)
    6165{
  • trunk/Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp

    r110382 r135496  
    5555}
    5656
     57void TestController::platformDestroy()
     58{
     59}
     60
    5761static gboolean timeoutCallback(gpointer)
    5862{
  • trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm

    r134780 r135496  
    4141}
    4242
     43void TestController::platformDestroy()
     44{
     45}
     46
    4347void TestController::initializeInjectedBundlePath()
    4448{
  • trunk/Tools/WebKitTestRunner/qt/TestControllerQt.cpp

    r130623 r135496  
    3333#include <cstdlib>
    3434#include <QCoreApplication>
    35 #include <QElapsedTimer>
    3635#include <QEventLoop>
    3736#include <QFileInfo>
    3837#include <QLibrary>
    3938#include <QObject>
     39#include <QTimer>
     40#include <QtGlobal>
    4041#include <qquickwebview_p.h>
    41 #include <QtGlobal>
    4242#include <wtf/Platform.h>
    4343#include <wtf/text/WTFString.h>
     
    4545namespace WTR {
    4646
     47class TestController::RunLoop : public QObject {
     48    Q_OBJECT
     49public:
     50    RunLoop();
     51
     52    void runUntil(double timeout);
     53    void notifyDone();
     54    void runModal(PlatformWebView*);
     55public Q_SLOTS:
     56    void timerFired();
     57private:
     58    QEventLoop m_runUntilLoop;
     59    QEventLoop m_modalLoop;
     60    QTimer m_runUntilLoopTimer;
     61    bool m_runUntilLoopClosePending;
     62};
     63
     64TestController::RunLoop::RunLoop()
     65    : m_runUntilLoopClosePending(false)
     66{
     67    m_runUntilLoopTimer.setSingleShot(true);
     68    QObject::connect(&m_runUntilLoopTimer, SIGNAL(timeout()), this, SLOT(timerFired()));
     69}
     70
     71void TestController::RunLoop::runUntil(double timeout)
     72{
     73    ASSERT(!m_runUntilLoop.isRunning());
     74    if (timeout) {
     75        const int timeoutInMilliSecs = timeout * 1000;
     76        m_runUntilLoopTimer.start(timeoutInMilliSecs);
     77    }
     78    m_runUntilLoop.exec(QEventLoop::ExcludeUserInputEvents);
     79}
     80
     81void TestController::RunLoop::notifyDone()
     82{
     83    if (m_modalLoop.isRunning()) {
     84        // Wait for the modal loop first. We only kill it if we timeout.
     85        m_runUntilLoopClosePending = true;
     86        return;
     87    }
     88
     89    m_runUntilLoopTimer.stop();
     90    m_runUntilLoop.exit();
     91}
     92
     93void TestController::RunLoop::timerFired()
     94{
     95    if (m_modalLoop.isRunning()) {
     96        m_runUntilLoopClosePending = true;
     97        m_modalLoop.exit();
     98        return;
     99    }
     100
     101    m_runUntilLoop.exit();
     102}
     103
     104void TestController::RunLoop::runModal(PlatformWebView* view)
     105{
     106    ASSERT(!m_modalLoop.isRunning());
     107    view->setModalEventLoop(&m_modalLoop);
     108    m_modalLoop.exec(QEventLoop::ExcludeUserInputEvents);
     109
     110    if (m_runUntilLoopClosePending)
     111        m_runUntilLoop.exit();
     112}
     113
    47114void TestController::notifyDone()
    48115{
     116    m_runLoop->notifyDone();
    49117}
    50118
    51119void TestController::platformInitialize()
    52120{
     121    m_runLoop = new RunLoop;
    53122    QQuickWebView::platformInitialize();
     123}
     124
     125void TestController::platformDestroy()
     126{
     127    delete m_runLoop;
    54128}
    55129
    56130void TestController::platformRunUntil(bool& condition, double timeout)
    57131{
    58     if (qgetenv("QT_WEBKIT2_DEBUG") == "1" || timeout == m_noTimeout) {
    59         // Never timeout if we are debugging or not meant to timeout.
    60         while (!condition)
    61             QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 50);
    62         return;
    63     }
    64 
    65     int timeoutInMSecs = timeout * 1000;
    66     QElapsedTimer timer;
    67     timer.start();
    68     while (!condition) {
    69         if (timer.elapsed() > timeoutInMSecs)
    70             return;
    71         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, timeoutInMSecs - timer.elapsed());
    72     }
     132    UNUSED_PARAM(condition);
     133    const bool shouldTimeout = !(qgetenv("QT_WEBKIT2_DEBUG") == "1" || timeout == m_noTimeout);
     134    m_runLoop->runUntil(shouldTimeout ? timeout : 0);
    73135}
    74136
     
    114176void TestController::runModal(PlatformWebView* view)
    115177{
    116     QEventLoop eventLoop;
    117     view->setModalEventLoop(&eventLoop);
    118     eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
     178    shared().m_runLoop->runModal(view);
    119179}
    120180
     
    125185
    126186} // namespace WTR
     187
     188#include "TestControllerQt.moc"
  • trunk/Tools/WebKitTestRunner/win/TestControllerWin.cpp

    r110382 r135496  
    122122}
    123123
     124void TestController::platformDestroy()
     125{
     126}
     127
    124128void TestController::initializeInjectedBundlePath()
    125129{
Note: See TracChangeset for help on using the changeset viewer.