Commit eae9bdd5 authored by Martin Flöser's avatar Martin Flöser

[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
parent 21cfb10c
......@@ -322,7 +322,7 @@ void DebugConsoleTest::testWaylandClient()
QVERIFY(rowsInsertedSpy.isValid());
// create our connection
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
// create the Surface and ShellSurface
using namespace KWayland::Client;
......
......@@ -149,7 +149,7 @@ void DecorationInputTest::initTestCase()
void DecorationInputTest::init()
{
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());
screens()->setCurrent(0);
......
......@@ -71,7 +71,7 @@ void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase()
void DontCrashCancelAnimationFromAnimationEndedTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
}
void DontCrashCancelAnimationFromAnimationEndedTest::cleanup()
......
......@@ -84,7 +84,7 @@ void DontCrashNoBorder::initTestCase()
void DontCrashNoBorder::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0);
Cursor::setPos(QPoint(640, 512));
......
......@@ -84,7 +84,7 @@ void FadeTest::initTestCase()
void FadeTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
// load the translucency effect
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
......
......@@ -94,7 +94,7 @@ void SlidingPopupsTest::initTestCase()
void SlidingPopupsTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
}
void SlidingPopupsTest::cleanup()
......
......@@ -72,7 +72,7 @@ void GlobalShortcutsTest::initTestCase()
void GlobalShortcutsTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512));
}
......
......@@ -83,7 +83,7 @@ void InputStackingOrderTest::initTestCase()
void InputStackingOrderTest::init()
{
using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0);
......
......@@ -183,7 +183,7 @@ void InternalWindowTest::initTestCase()
void InternalWindowTest::init()
{
Cursor::setPos(QPoint(1280, 512));
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandKeyboard());
}
......
......@@ -86,11 +86,10 @@ Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface)
/**
* Creates a Wayland Connection in a dedicated thread and creates various
* 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
* @see destroyWaylandConnection
**/
bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces());
bool setupWaylandConnection(AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces());
/**
* Destroys the Wayland Connection created with @link{setupWaylandConnection}.
......
......@@ -200,7 +200,7 @@ void LockScreenTest::initTestCase()
void LockScreenTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
......
......@@ -76,7 +76,7 @@ void TestMaximized::initTestCase()
void TestMaximized::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(1280, 512));
......
......@@ -98,7 +98,7 @@ void MoveResizeWindowTest::initTestCase()
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());
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
......
......@@ -82,7 +82,7 @@ void PlasmaSurfaceTest::initTestCase()
void PlasmaSurfaceTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell();
m_plasmaShell = Test::waylandPlasmaShell();
......
......@@ -90,7 +90,7 @@ void PlasmaWindowTest::initTestCase()
void PlasmaWindowTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::WindowManagement));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::WindowManagement));
m_windowManagement = Test::waylandWindowManagement();
m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell();
......
......@@ -87,7 +87,7 @@ void TestPointerConstraints::initTestCase()
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());
screens()->setCurrent(0);
......
......@@ -105,7 +105,7 @@ void PointerInputTest::initTestCase()
void PointerInputTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell();
......
......@@ -91,7 +91,7 @@ void QuickTilingTest::initTestCase()
void QuickTilingTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell();
......
......@@ -149,7 +149,7 @@ void SceneQPainterTest::testWindow()
KWin::Cursor::setPos(45, 45);
// this test verifies that a window is rendered correctly
using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
QScopedPointer<Surface> s(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
......@@ -205,7 +205,7 @@ void SceneQPainterTest::testCompositorRestart()
// first create a window
using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
QScopedPointer<Surface> s(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> ss(Test::createShellSurface(type, s.data()));
......
......@@ -57,7 +57,7 @@ void ScreenChangesTest::initTestCase()
void ScreenChangesTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512));
......
......@@ -95,7 +95,7 @@ void TestShellClient::initTestCase()
void TestShellClient::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(1280, 512));
......
......@@ -82,7 +82,7 @@ void StartTest::testCreateWindow()
{
// first we need to connect to the server
using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(shellClientAddedSpy.isValid());
......
......@@ -87,7 +87,7 @@ void StrutsTest::initTestCase()
void StrutsTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
m_compositor = Test::waylandCompositor();
m_plasmaShell = Test::waylandPlasmaShell();
......
......@@ -72,7 +72,7 @@ void TabBoxTest::initTestCase()
void TabBoxTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
screens()->setCurrent(0);
KWin::Cursor::setPos(QPoint(640, 512));
}
......
......@@ -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/surface.h>
#include <KWayland/Client/xdgshell.h>
#include <KWayland/Server/display.h>
//screenlocker
#include <KScreenLocker/KsldApp>
#include <QThread>
// system
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
using namespace KWayland::Client;
namespace KWin
......@@ -63,18 +69,24 @@ static struct {
QThread *thread = nullptr;
} s_waylandConnection;
bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags)
{
if (s_waylandConnection.connection) {
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
s_waylandConnection.connection = new ConnectionThread;
QSignalSpy connectedSpy(s_waylandConnection.connection, &ConnectionThread::connected);
if (!connectedSpy.isValid()) {
return false;
}
s_waylandConnection.connection->setSocketName(socketName);
s_waylandConnection.connection->setSocketFd(sx[1]);
s_waylandConnection.thread = new QThread(kwinApp());
s_waylandConnection.connection->moveToThread(s_waylandConnection.thread);
......
......@@ -74,7 +74,7 @@ void TouchInputTest::initTestCase()
void TouchInputTest::init()
{
using namespace KWayland::Client;
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandTouch());
m_touch = Test::waylandSeat()->createTouch(Test::waylandSeat());
QVERIFY(m_touch);
......
......@@ -58,7 +58,7 @@ void TransientNoInputTest::initTestCase()
void TransientNoInputTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName));
QVERIFY(Test::setupWaylandConnection());
}
void TransientNoInputTest::cleanup()
......
......@@ -86,7 +86,7 @@ void TransientPlacementTest::initTestCase()
void TransientPlacementTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration));
screens()->setCurrent(0);
Cursor::setPos(QPoint(640, 512));
......
......@@ -79,7 +79,7 @@ void TestWindowSelection::initTestCase()
void TestWindowSelection::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
screens()->setCurrent(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment