From 349e9c609199d6837b4cc9b7817e2bb7b8cd1184 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 12 Nov 2009 16:21:13 +0200 Subject: libcontextgsubscriber, cust. tests: Making the customer tests more robust: - waiting for started processes instead of just closing them (and continuing) - an unfortunate modification needed: the processes need to be waited for in the opposite creation order --- .../customer-tests/subscription/subscription.py | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/libcontextsubscriber/customer-tests/subscription/subscription.py b/libcontextsubscriber/customer-tests/subscription/subscription.py index e64780b2..4bd95ef5 100755 --- a/libcontextsubscriber/customer-tests/subscription/subscription.py +++ b/libcontextsubscriber/customer-tests/subscription/subscription.py @@ -102,8 +102,11 @@ class Subscription(unittest.TestCase): listen.expect("^key: test.int$"), "Key command returned wrong value") - provider.close() - listen.close() + # Because of a python threading / process / CLTool + # issue, processes need to be waited for in the + # opposite order as they are started. + listen.wait() + provider.wait() def testInfos(self): """ @@ -153,8 +156,8 @@ class Subscription(unittest.TestCase): self.assert_( listen.expect("^type: DOUBLE$"), "type didn't work") - provider.close() - listen.close() + listen.wait() + provider.wait() def testTypes(self): provider = CLTool("context-provide", "--v2", "com.nokia.test", @@ -192,8 +195,8 @@ class Subscription(unittest.TestCase): self.assert_( listen.expect("^type:$")) - provider.close() - listen.close() + listen.wait() + provider.wait() def testProviders(self): provider = CLTool("context-provide", "--v2", "com.nokia.test", @@ -218,8 +221,8 @@ class Subscription(unittest.TestCase): listen.send("providers test.fake") self.assert_( listen.expect("^providers:$")) - provider.close() - listen.close() + listen.wait() + provider.wait() def testAllDataTypes(self): """ @@ -256,8 +259,8 @@ class Subscription(unittest.TestCase): "^test.string = QString:foobar$", "^test.truth = bool:true$"]), "Actual key values pairs do not match expected") - provider.close() - listen.close() + listen.wait() + provider.wait() def testTruthTypePermutations(self): """ @@ -299,8 +302,8 @@ class Subscription(unittest.TestCase): self.assert_( listen.expect("^test.truth = bool:true$"), "setting to true didn't work") - provider.close() - listen.close() + listen.wait() + provider.wait() def testStringTypePermutations(self): """ @@ -342,8 +345,8 @@ class Subscription(unittest.TestCase): listen.expect("^test.string is Unknown$"), "setting to null didn't work") - provider.close() - listen.close() + listen.wait() + provider.wait() class MultipleSubscribers(unittest.TestCase): def setUp(self): @@ -361,12 +364,11 @@ class MultipleSubscribers(unittest.TestCase): self.context_client4 = CLTool("context-listen","test.int","test.double","test.string") def tearDown(self): - self.flexiprovider.send("exit") - self.flexiprovider.close() - self.context_client1.close() - self.context_client2.close() - self.context_client3.close() - self.context_client4.close() + self.context_client4.wait() + self.context_client3.wait() + self.context_client2.wait() + self.context_client1.wait() + self.flexiprovider.wait() os.unlink('./context-provide.context') def testInitialSubscription(self): @@ -497,14 +499,14 @@ class MultipleProviders(unittest.TestCase): self.assert_( listen.expect("^test.truth = bool:false$")) - provider1.close() - provider2.close() - listen.close() + listen.wait() + provider2.wait() + provider1.wait() class SubscriptionPause (unittest.TestCase): def tearDown(self): - self.provider.close() - self.listen.close() + self.listen.wait() + self.provider.wait() os.unlink('context-provide.context') def testPause(self): @@ -620,7 +622,7 @@ class SubscriptionWaitError (unittest.TestCase): self.assert_(context_client.expect("wait finished for test.nonexistent"), "Wait for subscription is probably in a dead state") - context_client.close() + context_client.wait() if __name__ == "__main__": sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) -- cgit v1.2.3 From 31a968682ef7b3c709a1d6bee07ab7f1aed33baa Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 12 Nov 2009 16:24:16 +0200 Subject: Cltool enhancement: print the io log if the stram was closed unexpectedly. --- python/ContextKit/cltool.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/ContextKit/cltool.py b/python/ContextKit/cltool.py index b4d4a990..b13d520f 100644 --- a/python/ContextKit/cltool.py +++ b/python/ContextKit/cltool.py @@ -97,8 +97,12 @@ class CLTool: """Writes STRING to the standard input of the child.""" with self.iolock: self.io.append((time.time(), CLTool.STDIN, string)) - print >>self.process.stdin, string - self.process.stdin.flush() + try: + print >>self.process.stdin, string + self.process.stdin.flush() + except: + self.printio() + raise def _return_event(self, wantdump): with self.iolock: -- cgit v1.2.3 From 65c0df8175d7950c66eca9a3f87792b0a66e6399 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 12 Nov 2009 16:45:10 +0200 Subject: libcontextsubscriber, cust. test: Updating the update-contextkit-providers customer test: the type is now stored only as a QVariant, so, no sense in checking it. --- .../Battery.Charging_KEYTYPE.expected | Bin 19 -> 0 bytes .../customer-tests/update-contextkit-providers/regen.sh | 1 - .../customer-tests/update-contextkit-providers/test.sh | 3 --- 3 files changed, 4 deletions(-) delete mode 100644 libcontextsubscriber/customer-tests/update-contextkit-providers/Battery.Charging_KEYTYPE.expected diff --git a/libcontextsubscriber/customer-tests/update-contextkit-providers/Battery.Charging_KEYTYPE.expected b/libcontextsubscriber/customer-tests/update-contextkit-providers/Battery.Charging_KEYTYPE.expected deleted file mode 100644 index 3815ca9d..00000000 Binary files a/libcontextsubscriber/customer-tests/update-contextkit-providers/Battery.Charging_KEYTYPE.expected and /dev/null differ diff --git a/libcontextsubscriber/customer-tests/update-contextkit-providers/regen.sh b/libcontextsubscriber/customer-tests/update-contextkit-providers/regen.sh index 9f28424d..bcc8fa9a 100755 --- a/libcontextsubscriber/customer-tests/update-contextkit-providers/regen.sh +++ b/libcontextsubscriber/customer-tests/update-contextkit-providers/regen.sh @@ -8,7 +8,6 @@ export CONTEXT_CORE_DECLARATIONS=. ../../update-contextkit-providers/update-contextkit-providers . regendb "KEYS" "KEYS" -regendb "Battery.Charging:KEYTYPE" "Battery.Charging_KEYTYPE" regendb "Battery.Charging:KEYDOC" "Battery.Charging_KEYDOC" regendb "Battery.Charging:PROVIDERS" "Battery.Charging_PROVIDERS" echo "Regen succeeded!" diff --git a/libcontextsubscriber/customer-tests/update-contextkit-providers/test.sh b/libcontextsubscriber/customer-tests/update-contextkit-providers/test.sh index 7f800ce2..ada1b255 100755 --- a/libcontextsubscriber/customer-tests/update-contextkit-providers/test.sh +++ b/libcontextsubscriber/customer-tests/update-contextkit-providers/test.sh @@ -30,9 +30,6 @@ function dotest { querydb "KEYS" "KEYS" compare "KEYS.expected" "KEYS.actual" - querydb "Battery.Charging:KEYTYPE" "Battery.Charging_KEYTYPE" - compare "Battery.Charging_KEYTYPE.expected" "Battery.Charging_KEYTYPE.actual" - querydb "Battery.Charging:KEYDOC" "Battery.Charging_KEYDOC" compare "Battery.Charging_KEYDOC.expected" "Battery.Charging_KEYDOC.actual" -- cgit v1.2.3 From 57c022784611d5df4cb426e5ceaa40836e33086a Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Thu, 12 Nov 2009 16:59:45 +0200 Subject: libcontextsubscriber, customer tests: replacing close() calls with wait() (in the "correct order") and adding wait() calls where there were none. --- .../customer-tests/asynchronicity/asynchronicity.py | 6 +++--- libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py | 4 ++-- .../customer-tests/commander/commander_appearing.py | 4 +++- .../customer-tests/commander/commander_disabled.py | 3 +++ .../customer-tests/commander/commander_nonexistent.py | 3 +++ .../customer-tests/pluginchanging/pluginchanging.py | 1 + libcontextsubscriber/customer-tests/registry/registry.py | 7 +++++-- libcontextsubscriber/customer-tests/subscription/multiprovider.py | 6 +++--- libcontextsubscriber/customer-tests/subscription/multiprovider2.py | 6 +++--- 9 files changed, 26 insertions(+), 14 deletions(-) diff --git a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py index 7eccd1ba..2566ba6f 100755 --- a/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py +++ b/libcontextsubscriber/customer-tests/asynchronicity/asynchronicity.py @@ -93,9 +93,9 @@ class Asynchronous(unittest.TestCase): "The arrival time of the fast and slow property is not far enough from each other") # context_client.printio() - context_client.close() - provider_slow.close() - provider_fast.close() + context_client.wait() + provider_fast.wait() + provider_slow.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(Asynchronous) diff --git a/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py b/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py index 925a1812..f695e91c 100755 --- a/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py +++ b/libcontextsubscriber/customer-tests/asynchronicity/rapidchanges.py @@ -78,8 +78,8 @@ class RapidChanges(unittest.TestCase): self.assertFalse(context_client.expect("test.fast =", wantdump = False, timeout=1), "expected a single valueChanged") - provider_fast.close() - context_client.close() + context_client.wait() + provider_fast.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(RapidChanges) diff --git a/libcontextsubscriber/customer-tests/commander/commander_appearing.py b/libcontextsubscriber/customer-tests/commander/commander_appearing.py index 72eef11b..f74ef60c 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_appearing.py +++ b/libcontextsubscriber/customer-tests/commander/commander_appearing.py @@ -68,10 +68,12 @@ class CommanderAppearing(unittest.TestCase): self.assert_(listen.expect(wanted("test.int", "int", "1235")), "Value after commander has changed it is wrong, wanted 1235") - commander.close() + commander.wait() listen.comment("Commander killed") self.assert_(listen.expect(wanted("test.int", "int", "42")), "Value after killing the commander is wrong, wanted 42") + listen.wait() + provider.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(CommanderAppearing) diff --git a/libcontextsubscriber/customer-tests/commander/commander_disabled.py b/libcontextsubscriber/customer-tests/commander/commander_disabled.py index 87d50d2b..1acf1c65 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_disabled.py +++ b/libcontextsubscriber/customer-tests/commander/commander_disabled.py @@ -48,6 +48,9 @@ class CommanderDisabled(unittest.TestCase): listen = CLTool("context-listen", "test.int") self.assert_(listen.expect(wanted("test.int", "int", "42")), "Provider provided value is wrong") + listen.wait() + commander.wait() + provider.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(CommanderDisabled) diff --git a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py index b90decad..b702cac7 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py +++ b/libcontextsubscriber/customer-tests/commander/commander_nonexistent.py @@ -65,6 +65,9 @@ class CommanderNonExistent(unittest.TestCase): self.assert_(listen.expect(wanted("test.string", "int", "42")), "Non-existent property's type couldn't be overwritten") + commander.wait() + listen.wait() + provider.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(CommanderNonExistent) result = unittest.TextTestRunner(verbosity=2).run(suiteInstallation) diff --git a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py index 322ee5fe..f49b5406 100755 --- a/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py +++ b/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py @@ -62,6 +62,7 @@ class Subscription(unittest.TestCase): # Expect value coming from plugin libcontextsubscribertime2 self.assert_(self.context_client.expect("Test.Time = QString:Time2:")) + self.context_client.wait() if __name__ == "__main__": sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) diff --git a/libcontextsubscriber/customer-tests/registry/registry.py b/libcontextsubscriber/customer-tests/registry/registry.py index 35cefdca..0511a7ce 100755 --- a/libcontextsubscriber/customer-tests/registry/registry.py +++ b/libcontextsubscriber/customer-tests/registry/registry.py @@ -42,7 +42,8 @@ class PrintInfoRunning(unittest.TestCase): returnValue = info_client.wait() self.assertEqual(returnValue, 0, "context-ls exited with return value != 0") - provider.close() + info_client.wait() + provider.wait() class PrintingProperties(unittest.TestCase): def tearDown(self): @@ -66,7 +67,9 @@ class PrintingProperties(unittest.TestCase): "^Documentation: A phony but very flexible property.$"]), "Bad introspection result from context-ls") - provider.close() + info_client.wait() + provider.wait() + def runTests(): suitePrintInfoRunning = unittest.TestLoader().loadTestsFromTestCase(PrintInfoRunning) diff --git a/libcontextsubscriber/customer-tests/subscription/multiprovider.py b/libcontextsubscriber/customer-tests/subscription/multiprovider.py index 1e68c897..47709a2c 100755 --- a/libcontextsubscriber/customer-tests/subscription/multiprovider.py +++ b/libcontextsubscriber/customer-tests/subscription/multiprovider.py @@ -69,14 +69,14 @@ class MultiProvider(unittest.TestCase): provider_y.expect("Setting key") self.assert_(client.expect(wanted("test.prop", "int", "99"))) - provider_y.close() + provider_y.wait() os.unlink("y.context") self.assert_(client.expect(wanted("test.prop", "int", "55"))) - provider_x.close() + provider_x.wait() os.unlink("x.context") self.assert_(client.expect(wantedUnknown("test.prop"))) - client.close() + client.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(MultiProvider) diff --git a/libcontextsubscriber/customer-tests/subscription/multiprovider2.py b/libcontextsubscriber/customer-tests/subscription/multiprovider2.py index fbd731f5..402765f8 100755 --- a/libcontextsubscriber/customer-tests/subscription/multiprovider2.py +++ b/libcontextsubscriber/customer-tests/subscription/multiprovider2.py @@ -71,9 +71,9 @@ class MultiProvider(unittest.TestCase): client.send("value test.prop") self.assert_(client.expect("\nvalue: int:22\n")) - client.close() - provider_x.close() - provider_y.close() + client.wait() + provider_y.wait() + provider_y.wait() def runTests(): suiteInstallation = unittest.TestLoader().loadTestsFromTestCase(MultiProvider) -- cgit v1.2.3 From ec9595e721a92addb227b61cd8d20525ccbedf33 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Fri, 13 Nov 2009 09:30:01 +0200 Subject: Cust tests: redirecting the waitforsilence input (esp. because of "top"), to enable running it on the device inside testrunner. Signed-off-by: Akos PASZTORY --- libcontextsubscriber/customer-tests/waitforsilence | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontextsubscriber/customer-tests/waitforsilence b/libcontextsubscriber/customer-tests/waitforsilence index 6489f557..d96fc4f0 100755 --- a/libcontextsubscriber/customer-tests/waitforsilence +++ b/libcontextsubscriber/customer-tests/waitforsilence @@ -3,7 +3,7 @@ # Wait until the load is below 2, but not more than 2 minutes. Plus, dump # some information for post-mortem troubleshooting. -exec >/tmp/xyzzy.log 2>&1; +exec >/tmp/xyzzy.log 2>&1 Date: Fri, 13 Nov 2009 09:30:09 +0200 Subject: the real cltool fix: make Popen close all unneeded fds Otherwise subsequent children inherit them. And then closing them only in the main process does not cause an EOF in the children (because all fds referring to the pipe end have to be closed for that). --- python/ContextKit/cltool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ContextKit/cltool.py b/python/ContextKit/cltool.py index b13d520f..5901ab25 100644 --- a/python/ContextKit/cltool.py +++ b/python/ContextKit/cltool.py @@ -66,7 +66,7 @@ class CLTool: def __init__(self, *cline): self.process = Popen(cline, stdin=PIPE, stdout=PIPE, stderr=STDOUT, - preexec_fn=self._preexec) + preexec_fn=self._preexec, close_fds=True) self.io = [] self.iolock = Lock() self.reader = Reader(self) -- cgit v1.2.3