[autotests] Fix race condition in ShellClient::testUnresponsiveWindow

Summary:
The test executable "kill" freezes itself after 1ms, supposedly after
showing a window.

However showing a window is not syncronous on wayland, it's illegal to
map a buffer before getting a configure event from the server.

This patch removes any potential for a race by having the server tell
our test executable when to freeze.

Test Plan: Test still passed

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D19406
icc-effect-5.17.5
David Edmundson 2019-02-28 02:09:16 +00:00
parent 6ddf50a77b
commit 768e5fb7f4
2 changed files with 13 additions and 6 deletions

View File

@ -3,6 +3,7 @@ KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 David Edmundson <davidedmundson@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QWidget>
#include <unistd.h>
#include <signal.h>
int main(int argc, char *argv[])
{
qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("wayland"));
@ -31,14 +34,13 @@ int main(int argc, char *argv[])
w.setGeometry(QRect(0, 0, 100, 200));
w.show();
//after showing the window block the main thread
//1 as we want it to come after the singleshots in qApp construction
QTimer::singleShot(1, []() {
//block
auto freezeHandler = [](int) {
while(true) {
sleep(100000);
sleep(10000);
}
});
};
signal(SIGUSR1, freezeHandler);
return app.exec();
}

View File

@ -3,6 +3,7 @@ KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 David Edmundson <davidedmundson@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -48,6 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <signal.h>
using namespace KWin;
using namespace KWayland::Client;
@ -1133,7 +1135,10 @@ void TestShellClient::testUnresponsiveWindow()
if (shellClientAddedSpy.isEmpty()) {
QVERIFY(shellClientAddedSpy.wait());
}
::kill(process->processId(), SIGUSR1); // send a signal to freeze the process
killClient = shellClientAddedSpy.first().first().value<AbstractClient*>();
QVERIFY(killClient);
QSignalSpy unresponsiveSpy(killClient, &AbstractClient::unresponsiveChanged);
QSignalSpy killedSpy(process.data(), static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished));
QSignalSpy deletedSpy(killClient, &QObject::destroyed);