aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber
diff options
context:
space:
mode:
authorGergely Risko <gergely+context@risko.hu>2009-09-11 15:10:36 +0300
committerGergely Risko <gergely+context@risko.hu>2009-09-11 15:10:36 +0300
commitdf3fdba809a6a08b1da653a2bc38c967101537ec (patch)
tree9535ac8fd927d6160d119d6c9dafa1fcf1335b88 /libcontextsubscriber
parente6f867d422722e66b4172d06b9de2f7a411ef8e5 (diff)
parent30cc95d199327da2c539dfc90c337b3c5b9e8f53 (diff)
Merge branch 'customer-check-flush' into bluez-plugin
Conflicts: libcontextsubscriber/customer-tests/runTests.sh libcontextsubscriber/src/Makefile.am
Diffstat (limited to 'libcontextsubscriber')
-rw-r--r--libcontextsubscriber/cli/commandwatcher.cpp11
-rwxr-xr-xlibcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py41
-rw-r--r--libcontextsubscriber/customer-tests/common/cltool.py80
-rwxr-xr-xlibcontextsubscriber/customer-tests/runTests.sh2
4 files changed, 102 insertions, 32 deletions
diff --git a/libcontextsubscriber/cli/commandwatcher.cpp b/libcontextsubscriber/cli/commandwatcher.cpp
index a4841d96..c4b8d11e 100644
--- a/libcontextsubscriber/cli/commandwatcher.cpp
+++ b/libcontextsubscriber/cli/commandwatcher.cpp
@@ -17,7 +17,6 @@
CommandWatcher::CommandWatcher(int commandfd, QMap<QString, ContextProperty*> *properties, QObject *parent) :
QObject(parent), commandfd(commandfd), properties(properties)
{
- fcntl(commandfd, F_SETFL, O_NONBLOCK);
commandNotifier = new QSocketNotifier(commandfd, QSocketNotifier::Read, this);
sconnect(commandNotifier, SIGNAL(activated(int)), this, SLOT(onActivated()));
help();
@@ -29,6 +28,7 @@ void CommandWatcher::onActivated()
static QByteArray commandBuffer = "";
static char buf[1024];
int readSize;
+ fcntl(commandfd, F_SETFL, O_NONBLOCK);
while ((readSize = read(commandfd, &buf, 1024)) > 0)
commandBuffer += QByteArray(buf, readSize);
@@ -61,12 +61,14 @@ void CommandWatcher::help()
qDebug() << " type KEY - get the info()->type for a key";
qDebug() << " plugin KEY - get the info()->plugin for a key";
qDebug() << " constructionstring KEY - get the info()->constructionstring for a key";
+ qDebug() << " flush - write FLUSHED to stderr and stdout";
qDebug() << "Any prefix of a command can be used as an abbreviation";
}
void CommandWatcher::interpret(const QString& command) const
{
QTextStream out(stdout);
+ QTextStream err(stderr);
if (command == "") {
help();
} else {
@@ -74,7 +76,7 @@ void CommandWatcher::interpret(const QString& command) const
QString commandName = args[0];
args.pop_front();
- if (args.size() == 0) {
+ if (args.size() == 0 && !QString("flush").startsWith(commandName)) {
help();
return;
}
@@ -163,6 +165,11 @@ void CommandWatcher::interpret(const QString& command) const
out << "constructionstring: " << properties->value(key)->info()->constructionString() << endl;
else
qDebug() << "no such key:" << key;
+ } else if (QString("flush").startsWith(commandName)) {
+ out << "FLUSHED" << endl;
+ out.flush();
+ err << "FLUSHED" << endl;
+ err.flush();
} else
help();
}
diff --git a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py
index 11180b58..d1de94af 100755
--- a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py
+++ b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py
@@ -32,16 +32,9 @@ import os
import signal
import re
import time
-
import unittest
from subprocess import Popen, PIPE
-
-def timeoutHandler(signum, frame):
- raise Exception('tests has been running for too long')
-
-class Callable:
- def __init__(self, anycallable):
- self.__call__ = anycallable
+from cltool import CLTool
class Asynchronous(unittest.TestCase):
def startProvider(busname, args):
@@ -51,15 +44,7 @@ class Asynchronous(unittest.TestCase):
print >>ret.stdin, "info()"
ret.stdout.readline().rstrip()
return ret
- startProvider = Callable(startProvider)
-
- def wanted(name, type, value):
- return "%s = %s:%s" % (name, type, value)
- wanted = Callable(wanted)
-
- def wantedUnknown(name):
- return "%s is Unknown" % (name)
- wantedUnknown = Callable(wantedUnknown)
+ startProvider = staticmethod(startProvider)
#SetUp
def setUp(self):
@@ -97,20 +82,19 @@ class Asynchronous(unittest.TestCase):
"""
# check the fast property
- self.context_client = Popen(["context-listen", "test.fast", "test.slow"],
- stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ self.context_client = CLTool("context-listen", "test.fast", "test.slow")
- got = self.context_client.stdout.readline().rstrip()
- self.assertEqual(got,
- self.wanted("test.fast", "int", "42"),
- "Bad value for the fast property")
+ self.assert_(self.context_client.expect(CLTool.STDOUT,
+ CLTool.wanted("test.fast", "int", "42"),
+ 1), # timeout == 1 second
+ "Bad value for the fast property, wanted 42, communication:")
fast_time = time.time()
# check the slow property
- got = self.context_client.stdout.readline().rstrip()
- self.assertEqual(got,
- self.wanted("test.slow", "int", "42"),
- "Bad value for the slow property")
+ self.assert_(self.context_client.expect(CLTool.STDOUT,
+ CLTool.wanted("test.slow", "int", "42"),
+ 10), # timeout == 10 second max, but 3 is enough usually
+ "Bad value for the slow property, wanted 42, communication:")
slow_time = time.time()
self.assert_(slow_time - fast_time > 2.0,
@@ -129,9 +113,6 @@ def runTests():
result = unittest.TextTestRunner(verbosity=2).run(suiteInstallation)
return len(result.errors + result.failures)
-
if __name__ == "__main__":
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1)
- signal.signal(signal.SIGALRM, timeoutHandler)
- signal.alarm(10)
sys.exit(runTests())
diff --git a/libcontextsubscriber/customer-tests/common/cltool.py b/libcontextsubscriber/customer-tests/common/cltool.py
new file mode 100644
index 00000000..c80ce355
--- /dev/null
+++ b/libcontextsubscriber/customer-tests/common/cltool.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+##
+## Copyright (C) 2008, 2009 Nokia. All rights reserved.
+##
+## Contact: Marius Vollmer <marius.vollmer@nokia.com>
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public License
+## version 2.1 as published by the Free Software Foundation.
+##
+## This library is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+## 02110-1301 USA
+
+import re
+import time
+from subprocess import Popen, PIPE
+
+class CLTool:
+ STDOUT = 1
+ STDERR = 2
+ def __init__(self, *cline):
+ self.__process = Popen(cline, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ self.__io = []
+
+ def send(self, string):
+ self.__io.append((0, string))
+ print >>self.__process.stdin, string
+
+ def expect(self, fileno, exp_str, timeout):
+ stream = 0
+ if fileno == self.STDOUT: stream = self.__process.stdout
+ if fileno == self.STDERR: stream = self.__process.stderr
+ if stream == 0: return False
+
+ print >>self.__process.stdin, "flush"
+ cur_str = ""
+ start_time = time.time()
+ while True:
+ line = stream.readline().rstrip()
+ if line == "FLUSHED":
+ if re.match(exp_str, cur_str):
+ return True
+ else:
+ time.sleep(0.1)
+ if time.time() - start_time > timeout:
+ self.printio()
+ print "Expected:", exp_str
+ print "Received before the timeout:\n", cur_str
+ return False
+ print >>self.__process.stdin, "flush"
+ else:
+ cur_str += line + "\n"
+ self.__io.append((fileno, line))
+
+ def printio(self):
+ print
+ print '----------------------------------------------------'
+ for line in self.__io:
+ if line[0] == 0:
+ print "[IN] <<<", line[1]
+ if line[0] == 1:
+ print "[OU] >>>", line[1]
+ if line[0] == 2:
+ print "[ER] >>>", line[1]
+ print '----------------------------------------------------'
+
+ def wanted(name, type, value):
+ return "%s = %s:%s$" % (name, type, value)
+ wanted = staticmethod(wanted)
+
+ def wantedUnknown(name):
+ return "%s is Unknown" % (name)
+ wantedUnknown = staticmethod(wantedUnknown)
diff --git a/libcontextsubscriber/customer-tests/runTests.sh b/libcontextsubscriber/customer-tests/runTests.sh
index f0ba2042..aa620a91 100755
--- a/libcontextsubscriber/customer-tests/runTests.sh
+++ b/libcontextsubscriber/customer-tests/runTests.sh
@@ -1,6 +1,8 @@
#!/bin/bash
+cd $(dirname $0)
DIRS="commander subscription asynchronicity registry bluez-plugin2 pluginchanging"
+export PYTHONPATH="`pwd`/common/"
if pkg-config contextprovider-1.0 || [ -e ../../libcontextprovider/src/.libs/libcontextprovider.so ]
then