summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2014-12-22 11:24:41 +0100
committerTobias Koenig <tobias.koenig@kdab.com>2015-01-09 10:58:52 +0100
commit96995db4af6e1f5e9fe313e4c71a41fd939fedf8 (patch)
tree8445e4bec938e15d48fc0d8c77113211abc05aa1 /tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
parentc3e50db19990c5b1d9088c4418e2804560d35582 (diff)
Add POSIX IPC support to QSystemSemaphore and QSharedMemory
This patch is a forward-port from 4.8 branch (d869e1ad4b0007757e97046609de2097cd9e9c5d). Change-Id: I6ae36a5417d1176fbecf775668f6033b1cb22a94 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp')
-rw-r--r--tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
index 7182428f14..bebc23172b 100644
--- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
@@ -174,7 +174,11 @@ void tst_QSharedMemory::cleanup()
#include <private/qsharedmemory_p.h>
#include <sys/types.h>
#include <sys/ipc.h>
+#ifndef QT_POSIX_IPC
#include <sys/shm.h>
+#else
+#include <sys/mman.h>
+#endif // QT_POSIX_IPC
#include <errno.h>
#endif
@@ -189,7 +193,10 @@ QString tst_QSharedMemory::helperBinary()
int tst_QSharedMemory::remove(const QString &key)
{
-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+ Q_UNUSED(key);
+ return 0;
+#else
// On unix the shared memory might exists from a previously failed test
// or segfault, remove it it does
if (key.isEmpty())
@@ -202,6 +209,7 @@ int tst_QSharedMemory::remove(const QString &key)
return -2;
}
+#ifndef QT_POSIX_IPC
int unix_key = ftok(fileName.toLatin1().constData(), 'Q');
if (-1 == unix_key) {
qDebug() << "ftok failed";
@@ -219,11 +227,15 @@ int tst_QSharedMemory::remove(const QString &key)
qDebug() << "shmctl failed";
return -5;
}
- return QFile::remove(fileName);
#else
- Q_UNUSED(key);
- return 0;
-#endif
+ if (shm_unlink(QFile::encodeName(fileName).constData()) == -1) {
+ qDebug() << "shm_unlink failed";
+ return -5;
+ }
+#endif // QT_POSIX_IPC
+
+ return QFile::remove(fileName);
+#endif // Q_OS_WIN
}
/*!