From eae9bdd50adec22d3a27bb1a45d75c33a727af05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 3 Dec 2016 14:31:14 +0100 Subject: [PATCH] [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 --- autotests/integration/debug_console_test.cpp | 2 +- autotests/integration/decoration_input_test.cpp | 2 +- .../integration/dont_crash_cancel_animation.cpp | 2 +- autotests/integration/dont_crash_no_border.cpp | 2 +- autotests/integration/effects/fade_test.cpp | 2 +- .../integration/effects/slidingpopups_test.cpp | 2 +- autotests/integration/globalshortcuts_test.cpp | 2 +- autotests/integration/input_stacking_order.cpp | 2 +- autotests/integration/internal_window.cpp | 2 +- autotests/integration/kwin_wayland_test.h | 3 +-- autotests/integration/lockscreen.cpp | 2 +- autotests/integration/maximize_test.cpp | 2 +- .../integration/move_resize_window_test.cpp | 2 +- autotests/integration/plasma_surface_test.cpp | 2 +- autotests/integration/plasmawindow_test.cpp | 2 +- .../integration/pointer_constraints_test.cpp | 2 +- autotests/integration/pointer_input.cpp | 2 +- autotests/integration/quick_tiling_test.cpp | 2 +- autotests/integration/scene_qpainter_test.cpp | 4 ++-- autotests/integration/screen_changes_test.cpp | 2 +- autotests/integration/shell_client_test.cpp | 2 +- autotests/integration/start_test.cpp | 2 +- autotests/integration/struts_test.cpp | 2 +- autotests/integration/tabbox_test.cpp | 2 +- autotests/integration/test_helpers.cpp | 16 ++++++++++++++-- autotests/integration/touch_input_test.cpp | 2 +- .../integration/transient_no_input_test.cpp | 2 +- autotests/integration/transient_placement.cpp | 2 +- autotests/integration/window_selection_test.cpp | 2 +- 29 files changed, 43 insertions(+), 32 deletions(-) diff --git a/autotests/integration/debug_console_test.cpp b/autotests/integration/debug_console_test.cpp index bff8195290..3272abc476 100644 --- a/autotests/integration/debug_console_test.cpp +++ b/autotests/integration/debug_console_test.cpp @@ -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; diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp index 72c205235b..83020d3a36 100644 --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -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); diff --git a/autotests/integration/dont_crash_cancel_animation.cpp b/autotests/integration/dont_crash_cancel_animation.cpp index 9a73319374..9fe7c82946 100644 --- a/autotests/integration/dont_crash_cancel_animation.cpp +++ b/autotests/integration/dont_crash_cancel_animation.cpp @@ -71,7 +71,7 @@ void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase() void DontCrashCancelAnimationFromAnimationEndedTest::init() { - QVERIFY(Test::setupWaylandConnection(s_socketName)); + QVERIFY(Test::setupWaylandConnection()); } void DontCrashCancelAnimationFromAnimationEndedTest::cleanup() diff --git a/autotests/integration/dont_crash_no_border.cpp b/autotests/integration/dont_crash_no_border.cpp index 5b9c8ef7d8..359baf2fa2 100644 --- a/autotests/integration/dont_crash_no_border.cpp +++ b/autotests/integration/dont_crash_no_border.cpp @@ -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)); diff --git a/autotests/integration/effects/fade_test.cpp b/autotests/integration/effects/fade_test.cpp index a7ef8a8eb9..53c730108f 100644 --- a/autotests/integration/effects/fade_test.cpp +++ b/autotests/integration/effects/fade_test.cpp @@ -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(effects); diff --git a/autotests/integration/effects/slidingpopups_test.cpp b/autotests/integration/effects/slidingpopups_test.cpp index b5d59d5a18..254a00e409 100644 --- a/autotests/integration/effects/slidingpopups_test.cpp +++ b/autotests/integration/effects/slidingpopups_test.cpp @@ -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() diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index 441822e27d..ada7316490 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -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)); } diff --git a/autotests/integration/input_stacking_order.cpp b/autotests/integration/input_stacking_order.cpp index c6ccb68332..7acc98e1c4 100644 --- a/autotests/integration/input_stacking_order.cpp +++ b/autotests/integration/input_stacking_order.cpp @@ -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); diff --git a/autotests/integration/internal_window.cpp b/autotests/integration/internal_window.cpp index 58deadc454..6c2a670d02 100644 --- a/autotests/integration/internal_window.cpp +++ b/autotests/integration/internal_window.cpp @@ -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()); } diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 2d68ae44c6..716b0c2b87 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -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}. diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp index e35ecb49cc..0f645fdb41 100644 --- a/autotests/integration/lockscreen.cpp +++ b/autotests/integration/lockscreen.cpp @@ -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(); diff --git a/autotests/integration/maximize_test.cpp b/autotests/integration/maximize_test.cpp index a13f0fc547..530a0c6a3f 100644 --- a/autotests/integration/maximize_test.cpp +++ b/autotests/integration/maximize_test.cpp @@ -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)); diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index 9720a7113b..54023c7ab8 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -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(); diff --git a/autotests/integration/plasma_surface_test.cpp b/autotests/integration/plasma_surface_test.cpp index 05436c88c9..7f58936b0a 100644 --- a/autotests/integration/plasma_surface_test.cpp +++ b/autotests/integration/plasma_surface_test.cpp @@ -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(); diff --git a/autotests/integration/plasmawindow_test.cpp b/autotests/integration/plasmawindow_test.cpp index 45345afb00..80b57ea367 100644 --- a/autotests/integration/plasmawindow_test.cpp +++ b/autotests/integration/plasmawindow_test.cpp @@ -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(); diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp index 547572da57..848dc66723 100644 --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -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); diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index 37f0a401b6..0026c1edc4 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -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(); diff --git a/autotests/integration/quick_tiling_test.cpp b/autotests/integration/quick_tiling_test.cpp index 94544331b4..9456ee655f 100644 --- a/autotests/integration/quick_tiling_test.cpp +++ b/autotests/integration/quick_tiling_test.cpp @@ -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(); diff --git a/autotests/integration/scene_qpainter_test.cpp b/autotests/integration/scene_qpainter_test.cpp index 73158b3f2c..680c8864be 100644 --- a/autotests/integration/scene_qpainter_test.cpp +++ b/autotests/integration/scene_qpainter_test.cpp @@ -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 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 s(Test::createSurface()); QFETCH(Test::ShellSurfaceType, type); QScopedPointer ss(Test::createShellSurface(type, s.data())); diff --git a/autotests/integration/screen_changes_test.cpp b/autotests/integration/screen_changes_test.cpp index 46b1e33ab2..bf33d6c31f 100644 --- a/autotests/integration/screen_changes_test.cpp +++ b/autotests/integration/screen_changes_test.cpp @@ -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)); diff --git a/autotests/integration/shell_client_test.cpp b/autotests/integration/shell_client_test.cpp index db480c3b7f..2513728120 100644 --- a/autotests/integration/shell_client_test.cpp +++ b/autotests/integration/shell_client_test.cpp @@ -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)); diff --git a/autotests/integration/start_test.cpp b/autotests/integration/start_test.cpp index a0503d829c..5e4befef83 100644 --- a/autotests/integration/start_test.cpp +++ b/autotests/integration/start_test.cpp @@ -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()); diff --git a/autotests/integration/struts_test.cpp b/autotests/integration/struts_test.cpp index 1f4b22c004..92e0672bef 100644 --- a/autotests/integration/struts_test.cpp +++ b/autotests/integration/struts_test.cpp @@ -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(); diff --git a/autotests/integration/tabbox_test.cpp b/autotests/integration/tabbox_test.cpp index 5577d3bc1a..627447f04a 100644 --- a/autotests/integration/tabbox_test.cpp +++ b/autotests/integration/tabbox_test.cpp @@ -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)); } diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 7d95b6cf41..703ea46797 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -35,12 +35,18 @@ along with this program. If not, see . #include #include #include +#include //screenlocker #include #include +// system +#include +#include +#include + 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); diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp index f4406757b4..b3acf04310 100644 --- a/autotests/integration/touch_input_test.cpp +++ b/autotests/integration/touch_input_test.cpp @@ -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); diff --git a/autotests/integration/transient_no_input_test.cpp b/autotests/integration/transient_no_input_test.cpp index b6e0d7a856..62c58d5acc 100644 --- a/autotests/integration/transient_no_input_test.cpp +++ b/autotests/integration/transient_no_input_test.cpp @@ -58,7 +58,7 @@ void TransientNoInputTest::initTestCase() void TransientNoInputTest::init() { - QVERIFY(Test::setupWaylandConnection(s_socketName)); + QVERIFY(Test::setupWaylandConnection()); } void TransientNoInputTest::cleanup() diff --git a/autotests/integration/transient_placement.cpp b/autotests/integration/transient_placement.cpp index a41e35aa3b..f51082c029 100644 --- a/autotests/integration/transient_placement.cpp +++ b/autotests/integration/transient_placement.cpp @@ -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)); diff --git a/autotests/integration/window_selection_test.cpp b/autotests/integration/window_selection_test.cpp index 18472f6dfa..3796da5ce0 100644 --- a/autotests/integration/window_selection_test.cpp +++ b/autotests/integration/window_selection_test.cpp @@ -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);