aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcontextsubscriber/multithreading-tests/stress-test/.gitignore4
-rw-r--r--libcontextsubscriber/multithreading-tests/stress-test/1provider.cdbbin0 -> 2727 bytes
-rw-r--r--libcontextsubscriber/multithreading-tests/stress-test/2providers.cdbbin0 -> 3423 bytes
-rw-r--r--libcontextsubscriber/multithreading-tests/stress-test/main.cpp9
-rwxr-xr-xlibcontextsubscriber/multithreading-tests/stress-test/provider.py42
-rwxr-xr-xlibcontextsubscriber/multithreading-tests/stress-test/runme.sh6
-rw-r--r--libcontextsubscriber/multithreading-tests/stress-test/thread.h45
7 files changed, 84 insertions, 22 deletions
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/.gitignore b/libcontextsubscriber/multithreading-tests/stress-test/.gitignore
new file mode 100644
index 00000000..0196a864
--- /dev/null
+++ b/libcontextsubscriber/multithreading-tests/stress-test/.gitignore
@@ -0,0 +1,4 @@
+stress-test
+moc_*
+*.o
+cache.cdb
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/1provider.cdb b/libcontextsubscriber/multithreading-tests/stress-test/1provider.cdb
new file mode 100644
index 00000000..58655ef3
--- /dev/null
+++ b/libcontextsubscriber/multithreading-tests/stress-test/1provider.cdb
Binary files differ
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/2providers.cdb b/libcontextsubscriber/multithreading-tests/stress-test/2providers.cdb
new file mode 100644
index 00000000..98324d4c
--- /dev/null
+++ b/libcontextsubscriber/multithreading-tests/stress-test/2providers.cdb
Binary files differ
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/main.cpp b/libcontextsubscriber/multithreading-tests/stress-test/main.cpp
index 6259fccb..c3e8940e 100644
--- a/libcontextsubscriber/multithreading-tests/stress-test/main.cpp
+++ b/libcontextsubscriber/multithreading-tests/stress-test/main.cpp
@@ -5,11 +5,16 @@ int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
- int maxTasks = 1;
- if (argc == 2 && atoi(argv[1]) > 0)
+ int maxTasks = 0;
+ int maxTasks2 = 0;
+
+ if (argc > 1 && atoi(argv[1]) > 0)
maxTasks = atoi(argv[1]);
+ if (argc > 2 && atoi(argv[2]) > 0)
+ maxTasks2 = atoi(argv[2]);
TestRunner tests(maxTasks, "test.int");
+ TestRunner tests2(maxTasks2, "test2.int");
return app.exec();
}
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/provider.py b/libcontextsubscriber/multithreading-tests/stress-test/provider.py
new file mode 100755
index 00000000..919862f6
--- /dev/null
+++ b/libcontextsubscriber/multithreading-tests/stress-test/provider.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+"""A test provider for the stress testing."""
+
+
+# change registry this often [msec]
+registryChangeTimeout = 2017
+
+
+from ContextKit.flexiprovider import *
+import gobject
+import time
+import os
+
+def update():
+ t = time.time()
+ dt = int(1000*(t - round(t)))
+ gobject.timeout_add(1000 - dt, update)
+ v = int(round(t))
+ fp.set('test.int', v)
+ fp.set('test.int2', v)
+ print t
+ return False
+
+pcnt = 0
+def chgRegistry():
+ global pcnt
+ pcnt += 1
+ if pcnt % 2:
+ print "1 provider"
+ os.system('cp 1provider.cdb cache.cdb')
+ else:
+ print "2 providers"
+ os.system('cp 2providers.cdb cache.cdb')
+ return True
+
+
+gobject.timeout_add(1000, update)
+# uncoment this to see the "Bus error" XXX
+gobject.timeout_add(registryChangeTimeout, chgRegistry)
+
+fp = Flexiprovider([INT('test.int'), INT('test.int2')], 'my.test.provider', 'session')
+fp.run()
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/runme.sh b/libcontextsubscriber/multithreading-tests/stress-test/runme.sh
index 435830e3..dc7f2e2f 100755
--- a/libcontextsubscriber/multithreading-tests/stress-test/runme.sh
+++ b/libcontextsubscriber/multithreading-tests/stress-test/runme.sh
@@ -1,2 +1,4 @@
-xterm -e 'rlwrap ../../../python/context-provide my.test.provider int test.int 1' &
-CONTEXT_PROVIDERS=. ./stress-test 5
+#xterm -e 'rlwrap ../../../python/context-provide my.test.provider int test.int 0 int test.int2 0' &
+#xterm -e 'rlwrap ../../../python/context-provide my.test2.provider int test2.int 0 int test2.int2 0' &
+xterm -e './provider.py' &
+CONTEXT_PROVIDERS=../stress-test/ ./stress-test 3 3
diff --git a/libcontextsubscriber/multithreading-tests/stress-test/thread.h b/libcontextsubscriber/multithreading-tests/stress-test/thread.h
index e9485a82..facb54f7 100644
--- a/libcontextsubscriber/multithreading-tests/stress-test/thread.h
+++ b/libcontextsubscriber/multithreading-tests/stress-test/thread.h
@@ -3,12 +3,11 @@
#include <contextproperty.h>
+#include <time.h>
#include <QThread>
#include <QDebug>
-#include <QTimer>
-
-#define NUM_TESTS 6
+#define NUM_TESTS 8
class ValueChecker : public QObject
{
@@ -33,17 +32,21 @@ class Thread : public QThread
Q_OBJECT
public:
- Thread(const int task, const QString& name) : task(task), name(name) {};
- static int value1;
+ Thread(const int task, const QString& propertyName) : task(task), propertyName(propertyName) {};
protected:
void run() {
// create property do something and delete it
- ContextProperty* cp = new ContextProperty(name);
+ ContextProperty* cp = new ContextProperty(propertyName);
+ int value, realValue;
+
switch (task) {
- case 1: // get value
+ case 1: // check value
cp->waitForSubscription();
- qDebug() << "** value =" << cp->value();
+ value = cp->value().toInt();
+ realValue = time(0);
+ if (value != realValue && value != 0)
+ qDebug() << "*** value mismatch:" << propertyName << value << realValue;
break;
case 2: // wait 0-2000 msec before deleting
@@ -64,22 +67,33 @@ protected:
cp->subscribe();
break;
- case 6: // unsubscribe, wait a bit then subscribe
+ case 6: // unsubscribe, wait a bit then subscribe and wait some more
cp->unsubscribe();
msleep(qrand()%2000);
cp->subscribe();
msleep(qrand()%2000);
break;
+ case 7: // subscribe
+ cp->subscribe();
+ break;
+
+ case 8: // subscribe
+ msleep(qrand()%100);
+ cp->subscribe();
+ msleep(qrand()%100);
+ break;
+
default:; // just create and delete
}
+
delete(cp);
exit();
}
private:
int task;
- QString name;
+ QString propertyName;
};
@@ -97,13 +111,13 @@ private:
public:
TestRunner(const int maxThreads, const QString& propertyName) :
maxThreads(maxThreads), propertyName(propertyName), count(0) {
-// QTimer::singleShot(100, this, SLOT(start()));
- start();
+ for (int i = 0; i < maxThreads; i++)
+ addThread();
}
void addThread() {
int task = qrand() % NUM_TESTS;
- qDebug() << "** starting task: " << task << "/" << ++count;
+ qDebug() << "** starting" << propertyName << task << "/" << ++count;
Thread* t = new Thread(task, propertyName);
QObject::connect(t, SIGNAL(finished()), this, SLOT(onThreadFinished()));
threads.insert(t);
@@ -111,11 +125,6 @@ public:
}
public slots:
- void start() {
- for (int i = 0; i < maxThreads; i++)
- addThread();
- }
-
void onThreadFinished() {
Thread* t = (Thread*) QObject::sender();
if (threads.remove(t)) {