summaryrefslogtreecommitdiffstats
path: root/tests/auto/other
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-06-05 16:44:07 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-12 17:54:11 +0200
commit3ccfc351fdcbb117e2872229382e45a929dac62a (patch)
tree6c27d337f53b4ec7cd9913a33ba107e5d17358c1 /tests/auto/other
parent6ca3ab626a04c3b05e6b3fde9a48457cf89c2889 (diff)
QProcess: Handle spurious socket notifications for stdout and stderr
On Unix systems where the GUI event dispatcher uses a notification system for socket notifiers that is out of band compared to select(), it's possible for the QSocketNotifier to activate after the pipe has been read from. When that happened, the ioctl(2) call with FIONREAD might return 0 bytes available, which we interpreted to mean EOF. Instead of doing that, always try to read at least one byte and examine the returned byte count from read(2). If it returns 0, that's a real EOF; if it returns -1 EWOULDBLOCK, we simply ignore the situation. That's the case on OS X: the Cocoa event dispatcher uses CFSocket to get notifications and those use kevent (and, apparently, an auxiliary thread) instead of an in-thread select() or poll(). That means the event loop would activate the QSocketNotifier even though there is nothing to be read. Task-number: QTBUG-39488 Change-Id: I1a58b5b1db7a47034fb36a78a005ebff96290efb Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'tests/auto/other')
-rw-r--r--tests/auto/other/other.pro3
-rw-r--r--tests/auto/other/qprocess_and_guieventloop/qprocess_and_guieventloop.pro4
-rw-r--r--tests/auto/other/qprocess_and_guieventloop/test.pro5
-rw-r--r--tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp89
-rw-r--r--tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp58
-rw-r--r--tests/auto/other/qprocess_and_guieventloop/write-read-write/write-read-write.pro4
6 files changed, 163 insertions, 0 deletions
diff --git a/tests/auto/other/other.pro b/tests/auto/other/other.pro
index e6017168d0..407237e519 100644
--- a/tests/auto/other/other.pro
+++ b/tests/auto/other/other.pro
@@ -23,6 +23,7 @@ SUBDIRS=\
qobjectperformance \
qobjectrace \
qsharedpointer_and_qwidget \
+ qprocess_and_guieventloop \
qtokenautomaton \
windowsmobile \
@@ -71,3 +72,5 @@ wince*|!contains(QT_CONFIG, accessibility): SUBDIRS -= qaccessibility
!embedded|wince*: SUBDIRS -= \
qdirectpainter
+winrt: SUBDIRS -= \
+ qprocess_and_guieventloop
diff --git a/tests/auto/other/qprocess_and_guieventloop/qprocess_and_guieventloop.pro b/tests/auto/other/qprocess_and_guieventloop/qprocess_and_guieventloop.pro
new file mode 100644
index 0000000000..e349fe5b11
--- /dev/null
+++ b/tests/auto/other/qprocess_and_guieventloop/qprocess_and_guieventloop.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ write-read-write
+SUBDIRS += test.pro
diff --git a/tests/auto/other/qprocess_and_guieventloop/test.pro b/tests/auto/other/qprocess_and_guieventloop/test.pro
new file mode 100644
index 0000000000..54d6f194b0
--- /dev/null
+++ b/tests/auto/other/qprocess_and_guieventloop/test.pro
@@ -0,0 +1,5 @@
+CONFIG += testcase
+CONFIG += parallel_test
+QT = core gui testlib
+SOURCES = tst_qprocess_and_guieventloop.cpp
+TARGET = tst_qprocess_and_guieventloop
diff --git a/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp
new file mode 100644
index 0000000000..42153c6c80
--- /dev/null
+++ b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Intel Corporation
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QGuiApplication>
+#include <QtTest/QtTest>
+#include <QtCore/QProcess>
+
+class tst_QProcess_and_GuiEventLoop : public QObject
+{
+ Q_OBJECT
+private slots:
+ void waitForAndEventLoop();
+};
+
+
+void tst_QProcess_and_GuiEventLoop::waitForAndEventLoop()
+{
+ // based on testcase provided in QTBUG-39488
+ QByteArray msg = "Hello World";
+
+ QProcess process;
+ process.start("write-read-write/write-read-write", QStringList() << msg);
+ QVERIFY(process.waitForStarted(5000));
+ QVERIFY(process.waitForReadyRead(5000));
+ QCOMPARE(process.readAll().trimmed(), msg);
+
+ // run the GUI event dispatcher once
+ QSignalSpy spy(&process, SIGNAL(readyRead()));
+ qApp->processEvents(QEventLoop::AllEvents, 100);
+
+ // we mustn't have read anything in the event loop
+ QCOMPARE(spy.count(), 0);
+
+ // ensure the process hasn't died
+ QVERIFY(!process.waitForFinished(250));
+
+ // we mustn't have read anything during waitForFinished either
+ QCOMPARE(spy.count(), 0);
+
+ // release the child for the second write
+ process.write("\n");
+ QVERIFY(process.waitForFinished(5000));
+ QCOMPARE(int(process.exitStatus()), int(QProcess::NormalExit));
+ QCOMPARE(process.exitCode(), 0);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(process.readAll().trimmed(), msg);
+}
+
+QTEST_MAIN(tst_QProcess_and_GuiEventLoop)
+
+#include "tst_qprocess_and_guieventloop.moc"
diff --git a/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp b/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp
new file mode 100644
index 0000000000..e8fc3b5cff
--- /dev/null
+++ b/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Intel Corporation
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ const char *msg = argv[1];
+ char buf[2];
+
+ puts(msg);
+ fflush(stdout);
+
+ // wait for a newline
+ fgets(buf, sizeof buf, stdin);
+
+ puts(msg);
+ fflush(stdout);
+ return 0;
+}
diff --git a/tests/auto/other/qprocess_and_guieventloop/write-read-write/write-read-write.pro b/tests/auto/other/qprocess_and_guieventloop/write-read-write/write-read-write.pro
new file mode 100644
index 0000000000..e236e05c7d
--- /dev/null
+++ b/tests/auto/other/qprocess_and_guieventloop/write-read-write/write-read-write.pro
@@ -0,0 +1,4 @@
+SOURCES = main.cpp
+CONFIG -= qt app_bundle
+CONFIG += console
+DESTDIR = ./