summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsharedmemory
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qsharedmemory')
-rw-r--r--tests/auto/qsharedmemory/lackey/scripts/producer.js8
-rw-r--r--tests/auto/qsharedmemory/src/qsystemlock_p.h1
-rw-r--r--tests/auto/qsharedmemory/src/qsystemlock_unix.cpp24
-rw-r--r--tests/auto/qsharedmemory/test/test.pro10
-rw-r--r--tests/auto/qsharedmemory/tst_qsharedmemory.cpp32
5 files changed, 69 insertions, 6 deletions
diff --git a/tests/auto/qsharedmemory/lackey/scripts/producer.js b/tests/auto/qsharedmemory/lackey/scripts/producer.js
index 88b2b80..e02cd8b 100644
--- a/tests/auto/qsharedmemory/lackey/scripts/producer.js
+++ b/tests/auto/qsharedmemory/lackey/scripts/producer.js
@@ -15,6 +15,10 @@ if (!producer.create(size)) {
}
//print ("producer created and attached");
+QVERIFY(producer.lock());
+producer.set(0, 'Q');
+QVERIFY(producer.unlock());
+
var i = 0;
while(i < 5) {
QVERIFY(producer.lock(), "lock");
@@ -34,3 +38,7 @@ producer.set(0, 'E');
QVERIFY(producer.unlock());
//print ("producer done");
+
+// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop,
+// because at least in Symbian the shared memory will be destroyed if there are no active handles to it.
+producer.sleep(3000); \ No newline at end of file
diff --git a/tests/auto/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qsharedmemory/src/qsystemlock_p.h
index 66df456..e123bed 100644
--- a/tests/auto/qsharedmemory/src/qsystemlock_p.h
+++ b/tests/auto/qsharedmemory/src/qsystemlock_p.h
@@ -47,6 +47,7 @@
#include "qsystemlock.h"
#include "private/qsharedmemory_p.h"
+#include <sys/types.h>
#define MAX_LOCKS 64
diff --git a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp b/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp
index 1f91e0c..dd7da21 100644
--- a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp
+++ b/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp
@@ -51,6 +51,7 @@
#include <fcntl.h>
#include <errno.h>
#include <sys/shm.h>
+#include <unistd.h>
#include <sys/sem.h>
// We have to define this as on some sem.h will have it
@@ -62,6 +63,25 @@ union qt_semun {
#define tr(x) QT_TRANSLATE_NOOP(QLatin1String("QSystemLock"), (x))
+#if defined(Q_OS_SYMBIAN)
+int createUnixKeyFile(const QString &fileName)
+{
+ if (QFile::exists(fileName))
+ return 0;
+
+ int fd = open(QFile::encodeName(fileName).constData(),
+ O_EXCL | O_CREAT | O_RDWR, 0640);
+ if (-1 == fd) {
+ if (errno == EEXIST)
+ return 0;
+ return -1;
+ } else {
+ close(fd);
+ }
+ return 1;
+}
+#endif
+
QSystemLockPrivate::QSystemLockPrivate() :
semaphore(-1), lockCount(0),
error(QSystemLock::NoError), unix_key(-1), createdFile(false), createdSemaphore(false)
@@ -105,7 +125,11 @@ key_t QSystemLockPrivate::handle()
}
// Create the file needed for ftok
+#if defined(Q_OS_SYMBIAN)
+ int built = createUnixKeyFile(fileName);
+#else
int built = QSharedMemoryPrivate::createUnixKeyFile(fileName);
+#endif
if (-1 == built)
return -1;
createdFile = (1 == built);
diff --git a/tests/auto/qsharedmemory/test/test.pro b/tests/auto/qsharedmemory/test/test.pro
index e294a75..779a942 100644
--- a/tests/auto/qsharedmemory/test/test.pro
+++ b/tests/auto/qsharedmemory/test/test.pro
@@ -17,13 +17,19 @@ TARGET = ../tst_qsharedmemory
}
}
-wince*: {
+wince*:{
QT += gui script
addFiles.sources = ../lackey/lackey.exe ../lackey/scripts
addFiles.path = lackey
DEPLOYMENT += addFiles
DEFINES += SRCDIR=\\\"\\\"
+}else:symbian*{
+QT += gui script
+addFiles.sources = ../lackey/scripts
+addFiles.path = /data/qsharedmemorytemp/lackey
+addBin.sources = lackey.exe
+addBin.path = /sys/bin
+DEPLOYMENT += addFiles addBin
} else {
DEFINES += SRCDIR=\\\"$$PWD/../\\\"
}
-
diff --git a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qsharedmemory/tst_qsharedmemory.cpp
index 1aa1ebb..f02e7a3 100644
--- a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp
+++ b/tests/auto/qsharedmemory/tst_qsharedmemory.cpp
@@ -49,8 +49,11 @@
#define EXISTING_SHARE "existing"
#define EXISTING_SIZE 1024
-Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError);
-Q_DECLARE_METATYPE(QSharedMemory::AccessMode);
+#ifdef Q_OS_SYMBIAN
+#define SRCDIR "c:/data/qsharedmemorytemp/"
+#endif
+Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError)
+Q_DECLARE_METATYPE(QSharedMemory::AccessMode)
class tst_QSharedMemory : public QObject
{
@@ -405,6 +408,9 @@ void tst_QSharedMemory::readOnly()
#ifdef Q_OS_WIN
QSKIP("This test opens a crash dialog on Windows", SkipSingle);
#endif
+#if defined (Q_OS_SYMBIAN)
+ QSKIP("Readonly shared memory is not supported in symbian", SkipAll);
+#endif
QString program = "./lackey/lackey";
QStringList arguments;
rememberKey("readonly_segfault");
@@ -527,7 +533,9 @@ void tst_QSharedMemory::simpleProducerConsumer()
char *get = (char*)consumer.data();
// On Windows CE you always have ReadWrite access. Thus
// ViewMapOfFile returns the same pointer
-#ifndef Q_OS_WINCE
+ // On Symbian, the address will always be same, as
+ // write protection of chunks is not currently supported by Symbian
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
QVERIFY(put != get);
#endif
for (int i = 0; i < size; ++i) {
@@ -629,6 +637,11 @@ public:
QVERIFY(producer.lock());
memory[0] = 'E';
QVERIFY(producer.unlock());
+
+#if defined(Q_OS_SYMBIAN)
+ // Sleep a while to ensure that consumers start properly
+ QTest::qSleep(1000);
+#endif
}
private:
@@ -660,12 +673,18 @@ void tst_QSharedMemory::simpleThreadedProducerConsumer()
#endif
Producer p;
+#if defined(Q_OS_SYMBIAN)
+ p.setStackSize(0x14000);
+#endif
if (producerIsThread)
p.start();
QList<Consumer*> consumers;
for (int i = 0; i < threads; ++i) {
consumers.append(new Consumer());
+#if defined(Q_OS_SYMBIAN)
+ consumers.last()->setStackSize(0x14000);
+#endif
consumers.last()->start();
}
@@ -697,6 +716,9 @@ void tst_QSharedMemory::simpleProcessProducerConsumer_data()
*/
void tst_QSharedMemory::simpleProcessProducerConsumer()
{
+#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
+ QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll);
+#endif
QFETCH(int, processes);
rememberKey("market");
@@ -710,6 +732,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer()
producer.setProcessChannelMode(QProcess::ForwardedChannels);
producer.start("./lackey/lackey", arguments);
producer.waitForStarted();
+ QVERIFY(producer.error() != QProcess::FailedToStart);
QList<QProcess*> consumers;
for (int i = 0; i < processes; ++i) {
@@ -730,7 +753,8 @@ void tst_QSharedMemory::simpleProcessProducerConsumer()
while (!consumers.isEmpty()) {
consumers.first()->waitForFinished(1000);
- if (consumers.first()->exitStatus() != QProcess::NormalExit ||
+ if (consumers.first()->state() == QProcess::Running ||
+ consumers.first()->exitStatus() != QProcess::NormalExit ||
consumers.first()->exitCode() != 0) {
consumerFailed = true;
}