2020-08-27 09:05:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2020-08-27 09:05:28 +00:00
|
|
|
#include "main.h"
|
2022-12-18 21:56:41 +00:00
|
|
|
#include "scene/workspacescene.h"
|
2020-08-27 09:05:28 +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-08-27 09:05:28 +00:00
|
|
|
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_server_restart-0");
|
|
|
|
|
|
|
|
class XwaylandServerRestartTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void testRestart();
|
|
|
|
};
|
|
|
|
|
|
|
|
void XwaylandServerRestartTest::initTestCase()
|
|
|
|
{
|
|
|
|
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-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("Restart"));
|
|
|
|
xwaylandGroup.sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kwin_safe_kill(QProcess *process)
|
|
|
|
{
|
|
|
|
// The SIGKILL signal must be sent when the event loop is spinning.
|
|
|
|
QTimer::singleShot(1, process, &QProcess::kill);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XwaylandServerRestartTest::testRestart()
|
|
|
|
{
|
|
|
|
// This test verifies that the Xwayland server will be restarted after a crash.
|
|
|
|
|
2022-08-03 10:31:27 +00:00
|
|
|
Xwl::Xwayland *xwayland = static_cast<Xwl::Xwayland *>(kwinApp()->xwayland());
|
2020-08-27 09:05:28 +00:00
|
|
|
|
|
|
|
QSignalSpy startedSpy(xwayland, &Xwl::Xwayland::started);
|
2023-01-27 12:29:32 +00:00
|
|
|
QSignalSpy stoppedSpy(xwayland, &Xwl::Xwayland::errorOccurred);
|
|
|
|
|
|
|
|
Test::createX11Connection(); // trigger an X11 start
|
|
|
|
QTRY_COMPARE(startedSpy.count(), 1);
|
|
|
|
|
|
|
|
// Pretend that the Xwayland process has crashed by sending a SIGKILL to it.
|
2022-03-12 14:09:57 +00:00
|
|
|
kwin_safe_kill(xwayland->xwaylandLauncher()->process());
|
2023-01-27 12:29:32 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(stoppedSpy.count(), 1);
|
2020-08-27 09:05:28 +00:00
|
|
|
|
|
|
|
// Check that the compositor still accepts new X11 clients.
|
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()));
|
2023-01-27 12:29:32 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(startedSpy.count(), 2);
|
2020-08-27 09:05:28 +00:00
|
|
|
const QRect rect(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-08-27 09:05:28 +00:00
|
|
|
rect.x(), rect.y(), rect.width(), rect.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, rect.x(), rect.y());
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, rect.width(), rect.height());
|
|
|
|
xcb_icccm_size_hints_set_min_size(&hints, rect.width(), rect.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2020-08-27 09:05:28 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-08-27 09:05:28 +00:00
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-08-27 09:05:28 +00:00
|
|
|
|
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-08-27 09:05:28 +00:00
|
|
|
// Destroy the test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
xcb_flush(c.get());
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(window));
|
2020-08-27 09:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::XwaylandServerRestartTest)
|
|
|
|
#include "xwaylandserver_restart_test.moc"
|