From 659cab24195430546b1fc216ad6f742b91e76516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 1 Dec 2014 10:52:19 +0100 Subject: [PATCH] [autotests] Use -displayfd as argument to start Xephyr Makes the test more reliable, our side blocks till the server is fully started. --- autotests/test_xrandr_screens.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/autotests/test_xrandr_screens.cpp b/autotests/test_xrandr_screens.cpp index c76bdd9852..9d8630ea02 100644 --- a/autotests/test_xrandr_screens.cpp +++ b/autotests/test_xrandr_screens.cpp @@ -23,6 +23,8 @@ along with this program. If not, see . #include "mock_workspace.h" // Qt #include +// system +#include Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") @@ -66,19 +68,28 @@ void TestXRandRScreens::initTestCase() s_rootWindow = XCB_WINDOW_NONE; // start X Server m_xserver.reset(new QProcess); - // randomize the display id in [1, 98] - // 0 is not used because it conflicts with "normal" X server - // 99 is not used because it's used by KDE's CI infrastructure - const QString id = QStringLiteral(":") + QString::number((qrand() % 98) + 1); + // use pipe to pass fd to Xephyr to get back the display id + int pipeFds[2]; + QVERIFY(pipe(pipeFds) == 0); // using Xephyr as Xvfb doesn't support render extension - m_xserver->start(QStringLiteral("Xephyr"), QStringList() << id); + m_xserver->start(QStringLiteral("Xephyr"), QStringList({ QStringLiteral("-displayfd"), QString::number(pipeFds[1]) })); QVERIFY(m_xserver->waitForStarted()); QCOMPARE(m_xserver->state(), QProcess::Running); - // give it some time before we open the X Display - QTest::qWait(500); + + // reads from pipe, closes write side + close(pipeFds[1]); + + QFile readPipe; + QVERIFY(readPipe.open(pipeFds[0], QIODevice::ReadOnly, QFileDevice::AutoCloseHandle)); + QByteArray displayNumber = readPipe.readLine(); + readPipe.close(); + + displayNumber.prepend(QByteArray(":")); + displayNumber.remove(displayNumber.size() -1, 1); + // create X connection int screen = 0; - s_connection = xcb_connect(qPrintable(id), &screen); + s_connection = xcb_connect(displayNumber.constData(), &screen); QVERIFY(s_connection); // set root window