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"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2020-10-14 15:04:57 +00:00
|
|
|
#include "composite.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2020-07-20 07:44:13 +00:00
|
|
|
#include "main.h"
|
2022-12-18 21:56:41 +00:00
|
|
|
#include "scene/workspacescene.h"
|
2020-07-20 07:44:13 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2022-04-22 10:09:02 +00:00
|
|
|
#include "xwayland/xwayland.h"
|
|
|
|
#include "xwayland/xwaylandlauncher.h"
|
2020-07-20 07:44:13 +00:00
|
|
|
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
2022-04-22 17:54:31 +00:00
|
|
|
qRegisterMetaType<X11Window *>();
|
2020-07-20 07:44:13 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
2020-07-20 07:44:13 +00:00
|
|
|
|
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());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2020-07-20 07:44:13 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2023-02-03 13:29:21 +00:00
|
|
|
Test::XcbConnectionPtr c = Test::createX11Connection();
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-07-20 07:44:13 +00:00
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId1 = xcb_generate_id(c.get());
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId1, rootWindow(),
|
2020-07-20 07:44:13 +00:00
|
|
|
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());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId1, &hints);
|
|
|
|
xcb_map_window(c.get(), windowId1);
|
|
|
|
xcb_flush(c.get());
|
2020-07-20 07:44:13 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-07-20 07:44:13 +00:00
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
QPointer<X11Window> window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-07-20 07:44:13 +00:00
|
|
|
|
|
|
|
// Create an override-redirect window.
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId2 = xcb_generate_id(c.get());
|
2022-03-23 10:13:38 +00:00
|
|
|
const uint32_t values[] = {true};
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId2, rootWindow(),
|
2020-07-20 07:44:13 +00:00
|
|
|
windowGeometry.x(), windowGeometry.y(),
|
|
|
|
windowGeometry.width(), windowGeometry.height(), 0,
|
|
|
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
|
|
|
|
XCB_CW_OVERRIDE_REDIRECT, values);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_map_window(c.get(), windowId2);
|
|
|
|
xcb_flush(c.get());
|
2020-07-20 07:44:13 +00:00
|
|
|
|
2023-03-13 11:54:38 +00:00
|
|
|
QSignalSpy unmanagedAddedSpy(workspace(), &Workspace::windowAdded);
|
2020-07-20 07:44:13 +00:00
|
|
|
QVERIFY(unmanagedAddedSpy.wait());
|
2023-03-28 11:38:19 +00:00
|
|
|
QPointer<X11Window> unmanaged = unmanagedAddedSpy.last().first().value<X11Window *>();
|
2020-07-20 07:44:13 +00:00
|
|
|
QVERIFY(unmanaged);
|
|
|
|
|
|
|
|
// Let's pretend that the Xwayland process has crashed.
|
|
|
|
QSignalSpy x11ConnectionChangedSpy(kwinApp(), &Application::x11ConnectionChanged);
|
2022-08-03 10:31:27 +00:00
|
|
|
Xwl::Xwayland *xwayland = static_cast<Xwl::Xwayland *>(kwinApp()->xwayland());
|
2022-03-12 14:09:57 +00:00
|
|
|
xwayland->xwaylandLauncher()->process()->terminate();
|
2020-07-20 07:44:13 +00:00
|
|
|
QVERIFY(x11ConnectionChangedSpy.wait());
|
|
|
|
|
|
|
|
// When Xwayland crashes, the compositor should tear down the XCB connection and destroy
|
|
|
|
// all connected X11 clients.
|
2022-04-23 19:51:16 +00:00
|
|
|
QTRY_VERIFY(!window);
|
2020-07-20 07:44:13 +00:00
|
|
|
QTRY_VERIFY(!unmanaged);
|
|
|
|
QCOMPARE(kwinApp()->x11Connection(), nullptr);
|
|
|
|
QCOMPARE(kwinApp()->x11RootWindow(), XCB_WINDOW_NONE);
|
2020-10-14 15:04:57 +00:00
|
|
|
|
|
|
|
// Render a frame to ensure that the compositor doesn't crash.
|
2021-11-09 10:36:24 +00:00
|
|
|
Compositor::self()->scene()->addRepaintFull();
|
2022-12-18 21:56:41 +00:00
|
|
|
QSignalSpy frameRenderedSpy(Compositor::self()->scene(), &WorkspaceScene::frameRendered);
|
2020-10-14 15:04:57 +00:00
|
|
|
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"
|