2020-08-28 08:11:09 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2020-07-20 07:44:13 +00:00
|
|
|
|
2020-08-28 08:11:09 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2020-07-20 07:44:13 +00:00
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
2020-10-14 15:04:57 +00:00
|
|
|
#include "composite.h"
|
2020-07-20 07:44:13 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "platform.h"
|
2020-10-14 15:04:57 +00:00
|
|
|
#include "scene.h"
|
2020-07-20 07:44:13 +00:00
|
|
|
#include "screens.h"
|
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "x11client.h"
|
|
|
|
#include "xwl/xwayland_interface.h"
|
|
|
|
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
struct XcbConnectionDeleter
|
|
|
|
{
|
|
|
|
static inline void cleanup(xcb_connection_t *pointer)
|
|
|
|
{
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_server_crash-0");
|
2020-07-20 07:44:13 +00:00
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
class XwaylandServerCrashTest : public QObject
|
2020-07-20 07:44:13 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void testCrash();
|
|
|
|
};
|
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
void XwaylandServerCrashTest::initTestCase()
|
2020-07-20 07:44:13 +00:00
|
|
|
{
|
|
|
|
qRegisterMetaType<Unmanaged *>();
|
|
|
|
qRegisterMetaType<X11Client *>();
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2020-07-20 07:44:13 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup xwaylandGroup = config->group("Xwayland");
|
|
|
|
xwaylandGroup.writeEntry(QStringLiteral("XwaylandCrashPolicy"), QStringLiteral("Stop"));
|
|
|
|
xwaylandGroup.sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
2020-07-20 07:44:13 +00:00
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
|
|
QCOMPARE(screens()->count(), 2);
|
|
|
|
QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024));
|
|
|
|
waylandServer()->initWorkspace();
|
|
|
|
}
|
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
void XwaylandServerCrashTest::testCrash()
|
2020-07-20 07:44:13 +00:00
|
|
|
{
|
|
|
|
// This test verifies that all connected X11 clients get destroyed when Xwayland crashes.
|
|
|
|
|
|
|
|
// Create a normal window.
|
|
|
|
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.data()));
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
|
|
|
xcb_window_t window1 = xcb_generate_id(c.data());
|
|
|
|
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, window1, rootWindow(),
|
|
|
|
windowGeometry.x(),
|
|
|
|
windowGeometry.y(),
|
|
|
|
windowGeometry.width(),
|
|
|
|
windowGeometry.height(),
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
xcb_icccm_size_hints_set_min_size(&hints, windowGeometry.width(), windowGeometry.height());
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.data(), window1, &hints);
|
|
|
|
xcb_map_window(c.data(), window1);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
|
|
|
QPointer<X11Client> client = windowCreatedSpy.last().first().value<X11Client *>();
|
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(client->isDecorated());
|
|
|
|
|
|
|
|
// Create an override-redirect window.
|
|
|
|
xcb_window_t window2 = xcb_generate_id(c.data());
|
|
|
|
const uint32_t values[] = { true };
|
|
|
|
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, window2, rootWindow(),
|
|
|
|
windowGeometry.x(), windowGeometry.y(),
|
|
|
|
windowGeometry.width(), windowGeometry.height(), 0,
|
|
|
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
|
|
|
|
XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
xcb_map_window(c.data(), window2);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
|
|
|
QSignalSpy unmanagedAddedSpy(workspace(), &Workspace::unmanagedAdded);
|
|
|
|
QVERIFY(unmanagedAddedSpy.isValid());
|
|
|
|
QVERIFY(unmanagedAddedSpy.wait());
|
|
|
|
QPointer<Unmanaged> unmanaged = unmanagedAddedSpy.last().first().value<Unmanaged *>();
|
|
|
|
QVERIFY(unmanaged);
|
|
|
|
|
|
|
|
// Let's pretend that the Xwayland process has crashed.
|
|
|
|
QSignalSpy x11ConnectionChangedSpy(kwinApp(), &Application::x11ConnectionChanged);
|
|
|
|
QVERIFY(x11ConnectionChangedSpy.isValid());
|
|
|
|
xwayland()->process()->terminate();
|
|
|
|
QVERIFY(x11ConnectionChangedSpy.wait());
|
|
|
|
|
|
|
|
// When Xwayland crashes, the compositor should tear down the XCB connection and destroy
|
|
|
|
// all connected X11 clients.
|
|
|
|
QTRY_VERIFY(!client);
|
|
|
|
QTRY_VERIFY(!unmanaged);
|
|
|
|
QCOMPARE(kwinApp()->x11Connection(), nullptr);
|
2020-07-28 07:58:35 +00:00
|
|
|
QCOMPARE(kwinApp()->x11DefaultScreen(), nullptr);
|
2020-07-20 07:44:13 +00:00
|
|
|
QCOMPARE(kwinApp()->x11RootWindow(), XCB_WINDOW_NONE);
|
|
|
|
QCOMPARE(kwinApp()->x11ScreenNumber(), -1);
|
2020-10-14 15:04:57 +00:00
|
|
|
|
|
|
|
// Render a frame to ensure that the compositor doesn't crash.
|
|
|
|
Compositor::self()->addRepaintFull();
|
|
|
|
QSignalSpy frameRenderedSpy(Compositor::self()->scene(), &Scene::frameRendered);
|
|
|
|
QVERIFY(frameRenderedSpy.wait());
|
2020-07-20 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
2020-08-27 09:05:28 +00:00
|
|
|
WAYLANDTEST_MAIN(KWin::XwaylandServerCrashTest)
|
|
|
|
#include "xwaylandserver_crash_test.moc"
|