Hello,

This patch modify the sim unittest in sim.py to work even when we
receive SIMBusy error on access (by waiting for the ReadyStatus and then
retrying the call)

I assumed that the correct algorithm to call a method that access the
sim was :

- call the dbus method that access the sim
- if we get a SIMBusy error :
-    wait for the ReadyStatus (within 30 seconds)
-    retry the call (a second SIMBusy error will be a real error this
time)

I tried it on origin/stabilization/milestone4 branch.

- Guillaume
From 2e3d3d65bbd22cf9efc606a837c0ddc42803e519 Mon Sep 17 00:00:00 2001
From: Guillaume Chereau <[email protected]>
Date: Fri, 16 Jan 2009 15:39:35 +0800
Subject: [PATCH] tests/sim: wait for ReadyStatus signal when a SIMBusy error is raised

Otherwise the test was failing every time the SIM was not ready at startup.

The solution here assumes that after we receive a ReadyStatus, then we can't get
an other SIMBusy error for the next call.
---
 tests/sim.py |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/tests/sim.py b/tests/sim.py
index 2434d5a..bfa4c5e 100644
--- a/tests/sim.py
+++ b/tests/sim.py
@@ -16,6 +16,30 @@ from dbus.mainloop.glib import DBusGMainLoop
 DBusGMainLoop(set_as_default=True)
 
 import test
+from framework.patterns.tasklet import WaitDBusSignal
+
+def retry_on_sim_not_ready(func):
+    """This decorator will make the test retry if the sim was not ready
+    """
+    @test.taskletTest
+    def ret(*args, **kargs):
+        bus = dbus.SystemBus()
+        gsm = bus.get_object('org.freesmartphone.ogsmd', '/org/freesmartphone/GSM/Device')
+        sim = dbus.Interface(gsm, 'org.freesmartphone.GSM.SIM')
+        try:
+            yield func(*args, **kargs)
+        except dbus.DBusException, ex:
+            if ex.get_dbus_name() == 'org.freesmartphone.GSM.SIM.NotReady':
+                # We give the SIM 30 seconds to get ready
+                yield WaitDBusSignal(sim, 'ReadyStatus', 30)
+                yield func(*args, **kargs)
+            raise           # All other dbus exception are raised
+
+    ret.__dict__ = func.__dict__
+    ret.__name__ = func.__name__
+    ret.__doc__ = func.__doc__
+    return ret
+
 
 class SimTests(unittest.TestCase):
     def setUp(self):
@@ -35,12 +59,14 @@ class SimTests(unittest.TestCase):
         self.usage.ReleaseResource('GSM')
         
     @test.request(("sim.present", True), ("sim.has_contacts", True))
+    @retry_on_sim_not_ready
     def test_get_contacts(self):
         """Try to get the contacts list"""
         contacts = self.sim.RetrievePhonebook('contacts')
         assert(contacts)
     
     @test.request("sim.present", True)
+    @retry_on_sim_not_ready
     def test_add_contact(self):
         """Try to add a new contact"""
         info = self.sim.GetPhonebookInfo('contacts')
-- 
1.5.6.3

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
smartphones-standards mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-standards

Reply via email to