[autotests/integration] Use socketpair for Wayland connection

Summary:
This is a preparation step for no longer creating a socket in the tests
and slightly simplifies the init test code.

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D3575
This commit is contained in:
Martin Gräßlin 2016-12-03 14:31:14 +01:00
parent 21cfb10c4f
commit eae9bdd50a
29 changed files with 43 additions and 32 deletions

View file

@ -322,7 +322,7 @@ void DebugConsoleTest::testWaylandClient()
QVERIFY(rowsInsertedSpy.isValid()); QVERIFY(rowsInsertedSpy.isValid());
// create our connection // create our connection
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
// create the Surface and ShellSurface // create the Surface and ShellSurface
using namespace KWayland::Client; using namespace KWayland::Client;

View file

@ -149,7 +149,7 @@ void DecorationInputTest::initTestCase()
void DecorationInputTest::init() void DecorationInputTest::init()
{ {
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0); screens()->setCurrent(0);

View file

@ -71,7 +71,7 @@ void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase()
void DontCrashCancelAnimationFromAnimationEndedTest::init() void DontCrashCancelAnimationFromAnimationEndedTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
} }
void DontCrashCancelAnimationFromAnimationEndedTest::cleanup() void DontCrashCancelAnimationFromAnimationEndedTest::cleanup()

View file

@ -84,7 +84,7 @@ void DontCrashNoBorder::initTestCase()
void DontCrashNoBorder::init() void DontCrashNoBorder::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0); screens()->setCurrent(0);
Cursor::setPos(QPoint(640, 512)); Cursor::setPos(QPoint(640, 512));

View file

@ -84,7 +84,7 @@ void FadeTest::initTestCase()
void FadeTest::init() void FadeTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
// load the translucency effect // load the translucency effect
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects); EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);

View file

@ -94,7 +94,7 @@ void SlidingPopupsTest::initTestCase()
void SlidingPopupsTest::init() void SlidingPopupsTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
} }
void SlidingPopupsTest::cleanup() void SlidingPopupsTest::cleanup()

View file

@ -72,7 +72,7 @@ void GlobalShortcutsTest::initTestCase()
void GlobalShortcutsTest::init() void GlobalShortcutsTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0); screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512)); KWin::Cursor::setPos(QPoint(640, 512));
} }

View file

@ -83,7 +83,7 @@ void InputStackingOrderTest::initTestCase()
void InputStackingOrderTest::init() void InputStackingOrderTest::init()
{ {
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0); screens()->setCurrent(0);

View file

@ -183,7 +183,7 @@ void InternalWindowTest::initTestCase()
void InternalWindowTest::init() void InternalWindowTest::init()
{ {
Cursor::setPos(QPoint(1280, 512)); Cursor::setPos(QPoint(1280, 512));
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandKeyboard()); QVERIFY(Test::waitForWaylandKeyboard());
} }

View file

@ -86,11 +86,10 @@ Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface)
/** /**
* Creates a Wayland Connection in a dedicated thread and creates various * Creates a Wayland Connection in a dedicated thread and creates various
* client side objects which can be used to create windows. * client side objects which can be used to create windows.
* @param socketName The name of the Wayland socket to connect to.
* @returns @c true if created successfully, @c false if there was an error * @returns @c true if created successfully, @c false if there was an error
* @see destroyWaylandConnection * @see destroyWaylandConnection
**/ **/
bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces()); bool setupWaylandConnection(AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces());
/** /**
* Destroys the Wayland Connection created with @link{setupWaylandConnection}. * Destroys the Wayland Connection created with @link{setupWaylandConnection}.

View file

@ -200,7 +200,7 @@ void LockScreenTest::initTestCase()
void LockScreenTest::init() void LockScreenTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
m_connection = Test::waylandConnection(); m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();

View file

@ -76,7 +76,7 @@ void TestMaximized::initTestCase()
void TestMaximized::init() void TestMaximized::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0); screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(1280, 512)); KWin::Cursor::setPos(QPoint(1280, 512));

View file

@ -98,7 +98,7 @@ void MoveResizeWindowTest::initTestCase()
void MoveResizeWindowTest::init() void MoveResizeWindowTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
m_connection = Test::waylandConnection(); m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();

View file

@ -82,7 +82,7 @@ void PlasmaSurfaceTest::initTestCase()
void PlasmaSurfaceTest::init() void PlasmaSurfaceTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell(); m_shell = Test::waylandShell();
m_plasmaShell = Test::waylandPlasmaShell(); m_plasmaShell = Test::waylandPlasmaShell();

View file

@ -90,7 +90,7 @@ void PlasmaWindowTest::initTestCase()
void PlasmaWindowTest::init() void PlasmaWindowTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::WindowManagement)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::WindowManagement));
m_windowManagement = Test::waylandWindowManagement(); m_windowManagement = Test::waylandWindowManagement();
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell(); m_shell = Test::waylandShell();

View file

@ -87,7 +87,7 @@ void TestPointerConstraints::initTestCase()
void TestPointerConstraints::init() void TestPointerConstraints::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::PointerConstraints)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::PointerConstraints));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0); screens()->setCurrent(0);

View file

@ -105,7 +105,7 @@ void PointerInputTest::initTestCase()
void PointerInputTest::init() void PointerInputTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell(); m_shell = Test::waylandShell();

View file

@ -91,7 +91,7 @@ void QuickTilingTest::initTestCase()
void QuickTilingTest::init() void QuickTilingTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
m_connection = Test::waylandConnection(); m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell(); m_shell = Test::waylandShell();

View file

@ -149,7 +149,7 @@ void SceneQPainterTest::testWindow()
KWin::Cursor::setPos(45, 45); KWin::Cursor::setPos(45, 45);
// this test verifies that a window is rendered correctly // this test verifies that a window is rendered correctly
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
QScopedPointer<Surface> s(Test::createSurface()); QScopedPointer<Surface> s(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type); QFETCH(Test::ShellSurfaceType, type);
@ -205,7 +205,7 @@ void SceneQPainterTest::testCompositorRestart()
// first create a window // first create a window
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
QScopedPointer<Surface> s(Test::createSurface()); QScopedPointer<Surface> s(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type); QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> ss(Test::createShellSurface(type, s.data())); QScopedPointer<QObject> ss(Test::createShellSurface(type, s.data()));

View file

@ -57,7 +57,7 @@ void ScreenChangesTest::initTestCase()
void ScreenChangesTest::init() void ScreenChangesTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0); screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512)); KWin::Cursor::setPos(QPoint(640, 512));

View file

@ -95,7 +95,7 @@ void TestShellClient::initTestCase()
void TestShellClient::init() void TestShellClient::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0); screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(1280, 512)); KWin::Cursor::setPos(QPoint(1280, 512));

View file

@ -82,7 +82,7 @@ void StartTest::testCreateWindow()
{ {
// first we need to connect to the server // first we need to connect to the server
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(shellClientAddedSpy.isValid()); QVERIFY(shellClientAddedSpy.isValid());

View file

@ -87,7 +87,7 @@ void StrutsTest::initTestCase()
void StrutsTest::init() void StrutsTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
m_compositor = Test::waylandCompositor(); m_compositor = Test::waylandCompositor();
m_plasmaShell = Test::waylandPlasmaShell(); m_plasmaShell = Test::waylandPlasmaShell();

View file

@ -72,7 +72,7 @@ void TabBoxTest::initTestCase()
void TabBoxTest::init() void TabBoxTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0); screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512)); KWin::Cursor::setPos(QPoint(640, 512));
} }

View file

@ -35,12 +35,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/shm_pool.h> #include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgshell.h> #include <KWayland/Client/xdgshell.h>
#include <KWayland/Server/display.h>
//screenlocker //screenlocker
#include <KScreenLocker/KsldApp> #include <KScreenLocker/KsldApp>
#include <QThread> #include <QThread>
// system
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
using namespace KWayland::Client; using namespace KWayland::Client;
namespace KWin namespace KWin
@ -63,18 +69,24 @@ static struct {
QThread *thread = nullptr; QThread *thread = nullptr;
} s_waylandConnection; } s_waylandConnection;
bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags) bool setupWaylandConnection(AdditionalWaylandInterfaces flags)
{ {
if (s_waylandConnection.connection) { if (s_waylandConnection.connection) {
return false; return false;
} }
int sx[2];
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) {
return false;
}
KWin::waylandServer()->display()->createClient(sx[0]);
// setup connection // setup connection
s_waylandConnection.connection = new ConnectionThread; s_waylandConnection.connection = new ConnectionThread;
QSignalSpy connectedSpy(s_waylandConnection.connection, &ConnectionThread::connected); QSignalSpy connectedSpy(s_waylandConnection.connection, &ConnectionThread::connected);
if (!connectedSpy.isValid()) { if (!connectedSpy.isValid()) {
return false; return false;
} }
s_waylandConnection.connection->setSocketName(socketName); s_waylandConnection.connection->setSocketFd(sx[1]);
s_waylandConnection.thread = new QThread(kwinApp()); s_waylandConnection.thread = new QThread(kwinApp());
s_waylandConnection.connection->moveToThread(s_waylandConnection.thread); s_waylandConnection.connection->moveToThread(s_waylandConnection.thread);

View file

@ -74,7 +74,7 @@ void TouchInputTest::initTestCase()
void TouchInputTest::init() void TouchInputTest::init()
{ {
using namespace KWayland::Client; using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandTouch()); QVERIFY(Test::waitForWaylandTouch());
m_touch = Test::waylandSeat()->createTouch(Test::waylandSeat()); m_touch = Test::waylandSeat()->createTouch(Test::waylandSeat());
QVERIFY(m_touch); QVERIFY(m_touch);

View file

@ -58,7 +58,7 @@ void TransientNoInputTest::initTestCase()
void TransientNoInputTest::init() void TransientNoInputTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName)); QVERIFY(Test::setupWaylandConnection());
} }
void TransientNoInputTest::cleanup() void TransientNoInputTest::cleanup()

View file

@ -86,7 +86,7 @@ void TransientPlacementTest::initTestCase()
void TransientPlacementTest::init() void TransientPlacementTest::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0); screens()->setCurrent(0);
Cursor::setPos(QPoint(640, 512)); Cursor::setPos(QPoint(640, 512));

View file

@ -79,7 +79,7 @@ void TestWindowSelection::initTestCase()
void TestWindowSelection::init() void TestWindowSelection::init()
{ {
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer()); QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0); screens()->setCurrent(0);