Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GTK][WPE] Unify TestController::platformRunUntil() and honor conditi…
…on flag

https://bugs.webkit.org/show_bug.cgi?id=192855

Reviewed by Michael Catanzaro.

* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::notifyDone): Use the WPE implementation.
(WTR::TestController::platformRunUntil): Use the WPE implementation.
* WebKitTestRunner/wpe/TestControllerWPE.cpp:
(WTR::TestController::platformRunUntil): Honor the condition flag.


Canonical link: https://commits.webkit.org/207446@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aperezdc committed Dec 19, 2018
1 parent e040803 commit 1caedae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
13 changes: 13 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,16 @@
2018-12-19 Adrian Perez de Castro <aperez@igalia.com>

[GTK][WPE] Unify TestController::platformRunUntil() and honor condition flag
https://bugs.webkit.org/show_bug.cgi?id=192855

Reviewed by Michael Catanzaro.

* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::notifyDone): Use the WPE implementation.
(WTR::TestController::platformRunUntil): Use the WPE implementation.
* WebKitTestRunner/wpe/TestControllerWPE.cpp:
(WTR::TestController::platformRunUntil): Honor the condition flag.

2018-12-19 Megan Gardner <megan_gardner@apple.com>

Allow clients to set the navigator platform
Expand Down
53 changes: 24 additions & 29 deletions Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp
Expand Up @@ -37,27 +37,8 @@

namespace WTR {

static GSource* timeoutSource()
{
static GRefPtr<GSource> source = nullptr;
if (!source) {
source = adoptGRef(g_timeout_source_new(0));
g_source_set_ready_time(source.get(), -1);
g_source_set_name(source.get(), "[WTR] Test timeout source");
g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
g_source_set_ready_time(static_cast<GSource*>(userData), -1);
fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
RunLoop::main().stop();
return G_SOURCE_REMOVE;
}, source.get(), nullptr);
g_source_attach(source.get(), nullptr);
}
return source.get();
}

void TestController::notifyDone()
{
g_source_set_ready_time(timeoutSource(), -1);
RunLoop::main().stop();
}

Expand All @@ -74,17 +55,31 @@ void TestController::platformDestroy()
{
}

void TestController::platformRunUntil(bool&, WTF::Seconds timeout)
void TestController::platformRunUntil(bool& done, WTF::Seconds timeout)
{
if (timeout > 0_s) {
// FIXME: This conversion is now repeated in several places, it should be moved to a common place in WTF and used everywhere.
gint64 currentTime = g_get_monotonic_time();
gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, timeout.microsecondsAs<int64_t>());
ASSERT(targetTime >= currentTime);
g_source_set_ready_time(timeoutSource(), targetTime);
} else
g_source_set_ready_time(timeoutSource(), -1);
RunLoop::main().run();
struct TimeoutTimer {
TimeoutTimer()
: timer(RunLoop::main(), this, &TimeoutTimer::fired)
{ }

void fired()
{
timedOut = true;
RunLoop::main().stop();
}

RunLoop::Timer<TimeoutTimer> timer;
bool timedOut { false };
} timeoutTimer;

timeoutTimer.timer.setPriority(G_PRIORITY_DEFAULT_IDLE);
if (timeout >= 0_s)
timeoutTimer.timer.startOneShot(timeout);

while (!done && !timeoutTimer.timedOut)
RunLoop::main().run();

timeoutTimer.timer.stop();
}

static char* getEnvironmentVariableAsUTF8String(const char* variableName)
Expand Down
13 changes: 10 additions & 3 deletions Tools/WebKitTestRunner/wpe/TestControllerWPE.cpp
Expand Up @@ -58,22 +58,29 @@ void TestController::platformInitializeContext()
{
}

void TestController::platformRunUntil(bool& condition, WTF::Seconds timeout)
void TestController::platformRunUntil(bool& done, WTF::Seconds timeout)
{
struct TimeoutTimer {
TimeoutTimer()
: timer(RunLoop::main(), this, &TimeoutTimer::fired)
{ }

void fired() { RunLoop::main().stop(); }
void fired()
{
timedOut = true;
RunLoop::main().stop();
}

RunLoop::Timer<TimeoutTimer> timer;
bool timedOut { false };
} timeoutTimer;

timeoutTimer.timer.setPriority(G_PRIORITY_DEFAULT_IDLE);
if (timeout >= 0_s)
timeoutTimer.timer.startOneShot(timeout);

RunLoop::main().run();
while (!done && !timeoutTimer.timedOut)
RunLoop::main().run();

timeoutTimer.timer.stop();
}
Expand Down

0 comments on commit 1caedae

Please sign in to comment.