Hi Alfonso, On 06/09/2014 03:22 AM, Alfonso Sanchez-Beato wrote: > Some tests scripts were not ready to handle situations with more than > one modem present. This change fixes some of these scripts. > --- I think this is useful, thanks for doing this. > test/activate-context | 61 +++++++++++++++++++++++++---------------- > test/create-multiparty | 12 ++++---- > test/deactivate-context | 73 +++++++++++++++++++++++++++++-------------------- > test/hangup-active | 10 +++++-- > test/private-chat | 17 ++++++------ > test/release-and-answer | 29 ++++++++++++++------ > test/release-and-swap | 29 ++++++++++++++------ > 7 files changed, 144 insertions(+), 87 deletions(-) > It might be easier to separate the changes into multiple patches next time. That way I can take the non-controversial ones right away. > diff --git a/test/activate-context b/test/activate-context > index 22ad173..816de86 100755 > --- a/test/activate-context > +++ b/test/activate-context > @@ -5,36 +5,49 @@ import dbus > > bus = dbus.SystemBus() > > -manager = dbus.Interface(bus.get_object('org.ofono', '/'), > - 'org.ofono.Manager') > +manager = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager') > > -modems = manager.GetModems() > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + modem = modems[0][0] > + context_idx = 0 Can you preserve the current behavior for this case? e.g. with no arguments we find the first modem with the ConnectionManager interface and activate the context. > +elif (len(sys.argv) == 2): > + modems = manager.GetModems() > + modem = modems[0][0] > + context_idx = int(sys.argv[1]) - 1 > +elif (len(sys.argv) == 3): > + modem = sys.argv[1] > + context_idx = int(sys.argv[2]) - 1 > +else: > + print("Usage: %s [modem] [context_number]" % (sys.argv[0])) > + sys.exit(1) > > -for path, properties in modems: > - if "org.ofono.ConnectionManager" not in properties["Interfaces"]: > - continue > +modemapi = dbus.Interface(bus.get_object('org.ofono', modem), 'org.ofono.Modem') > +properties = modemapi.GetProperties() > > - connman = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.ConnectionManager') > +if "org.ofono.ConnectionManager" not in properties["Interfaces"]: > + print("org.ofono.ConnectionManager not found") > + exit(2) > > - contexts = connman.GetContexts() > +connman = dbus.Interface(bus.get_object('org.ofono', modem), > + 'org.ofono.ConnectionManager') > > - if (len(contexts) == 0): > - print("No context available") > - sys.exit(1) > +contexts = connman.GetContexts() > > - connman.SetProperty("Powered", dbus.Boolean(1)) > +if (len(contexts) == 0): > + print("No context available") > + sys.exit(1) > > - if len(sys.argv) > 1: > - path = contexts[int(sys.argv[1])][0] > - else: > - path = contexts[0][0] > +connman.SetProperty("Powered", dbus.Boolean(1)) > > - context = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.ConnectionContext') > +path = contexts[context_idx][0] > + > +context = dbus.Interface(bus.get_object('org.ofono', path), > + 'org.ofono.ConnectionContext') > + > +try: > + context.SetProperty("Active", dbus.Boolean(1), timeout = 100) > +except dbus.DBusException as e: > + print("Error activating %s: %s" % (path, str(e))) > + exit(2) > > - try: > - context.SetProperty("Active", dbus.Boolean(1), timeout = 100) > - except dbus.DBusException as e: > - print("Error activating %s: %s" % (path, str(e))) > - exit(2) > diff --git a/test/create-multiparty b/test/create-multiparty > index b6395e8..1b76010 100755 > --- a/test/create-multiparty > +++ b/test/create-multiparty > @@ -8,12 +8,14 @@ bus = dbus.SystemBus() > manager = dbus.Interface(bus.get_object('org.ofono', '/'), > 'org.ofono.Manager') > > -modems = manager.GetModems() > - > -path = modems[0][0] > - > -if (len(sys.argv) == 2): > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + path = modems[0][0] > +elif (len(sys.argv) == 2): > path = sys.argv[1] > +else: > + print("Usage: %s [modem]" % (sys.argv[0])) > + sys.exit(1) > This part looks fine to me > manager = dbus.Interface(bus.get_object('org.ofono', path), > 'org.ofono.VoiceCallManager') > diff --git a/test/deactivate-context b/test/deactivate-context > index bc2ffd3..6a5164a 100755 > --- a/test/deactivate-context > +++ b/test/deactivate-context > @@ -5,34 +5,47 @@ import dbus > > bus = dbus.SystemBus() > > -manager = dbus.Interface(bus.get_object('org.ofono', '/'), > - 'org.ofono.Manager') > +manager = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager') > + > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + modem = modems[0][0] > + context_idx = 0 Same as above, can we preserve the current behavior here? > +elif (len(sys.argv) == 2): > + modems = manager.GetModems() > + modem = modems[0][0] > + context_idx = int(sys.argv[1]) - 1 > +elif (len(sys.argv) == 3): > + modem = sys.argv[1] > + context_idx = int(sys.argv[2]) - 1 > +else: > + print("Usage: %s [modem] [context_number]" % (sys.argv[0])) > + sys.exit(1) > + > +modemapi = dbus.Interface(bus.get_object('org.ofono', modem), 'org.ofono.Modem') > +properties = modemapi.GetProperties() > + > +if "org.ofono.ConnectionManager" not in properties["Interfaces"]: > + print("org.ofono.ConnectionManager not found") > + exit(2) > + > +connman = dbus.Interface(bus.get_object('org.ofono', modem), > + 'org.ofono.ConnectionManager') > + > +contexts = connman.GetContexts() > + > +if (len(contexts) == 0): > + print("No context available") > + sys.exit(1) > + > +path = contexts[context_idx][0] > + > +context = dbus.Interface(bus.get_object('org.ofono', path), > + 'org.ofono.ConnectionContext') > + > +try: > + context.SetProperty("Active", dbus.Boolean(0)) > +except dbus.DBusException as e: > + print("Error deactivating %s: %s" % (path, str(e))) > + exit(2) > > -modems = manager.GetModems() > - > -for path, properties in modems: > - if "org.ofono.ConnectionManager" not in properties["Interfaces"]: > - continue > - > - connman = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.ConnectionManager') > - > - contexts = connman.GetContexts() > - > - if (len(contexts) == 0): > - print("No context available") > - sys.exit(1) > - > - if len(sys.argv) > 1: > - path = contexts[int(sys.argv[1])][0] > - else: > - path = contexts[0][0] > - > - context = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.ConnectionContext') > - > - try: > - context.SetProperty("Active", dbus.Boolean(0)) > - except dbus.DBusException as e: > - print("Error activating %s: %s" % (path, str(e))) > - exit(2) > diff --git a/test/hangup-active b/test/hangup-active > index 8e65bc4..82e0eb0 100755 > --- a/test/hangup-active > +++ b/test/hangup-active > @@ -8,8 +8,14 @@ bus = dbus.SystemBus() > manager = dbus.Interface(bus.get_object('org.ofono', '/'), > 'org.ofono.Manager') > > -modems = manager.GetModems() > -path = modems[0][0] > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + path = modems[0][0] > +elif (len(sys.argv) == 2): > + path = sys.argv[1] > +else: > + print("Usage: %s [modem]" % (sys.argv[0])) > + sys.exit(1) > This looks fine... > manager = dbus.Interface(bus.get_object('org.ofono', path), > 'org.ofono.VoiceCallManager') > diff --git a/test/private-chat b/test/private-chat > index 17d17d0..e7e5406 100755 > --- a/test/private-chat > +++ b/test/private-chat > @@ -3,24 +3,23 @@ > import sys > import dbus > > +if (len(sys.argv) != 2): > + print("Usage: %s [voicecall_path]" % (sys.argv[0])) > + exit(1) > + > bus = dbus.SystemBus() > > manager = dbus.Interface(bus.get_object('org.ofono', '/'), > 'org.ofono.Manager') > > -modems = manager.GetModems() > -path = modems[0][0] > - > -if (len(sys.argv) == 3): > - path = sys.argv[1] > - callid = sys.argv[2] > -else: > - callid = sys.argv[1] > +call = sys.argv[1] > +sep = call.find("/", 1) > +path = call[0:sep] > > manager = dbus.Interface(bus.get_object('org.ofono', path), > 'org.ofono.VoiceCallManager') > > -mpty = manager.PrivateChat(callid, timeout=100) > +mpty = manager.PrivateChat(call, timeout=100) > ditto > for path in mpty: > print(path) > diff --git a/test/release-and-answer b/test/release-and-answer > index 62eaa79..a8a9319 100755 > --- a/test/release-and-answer > +++ b/test/release-and-answer > @@ -1,5 +1,6 @@ > #!/usr/bin/python3 > > +import sys > import dbus > > bus = dbus.SystemBus() > @@ -9,14 +10,26 @@ manager = dbus.Interface(bus.get_object('org.ofono', '/'), > > modems = manager.GetModems() > > -for path, properties in modems: > - print("[ %s ]" % (path)) > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + path = modems[0][0] Again, can we preserve the current behavior ? > +elif (len(sys.argv) == 2): > + path = sys.argv[1] > +else: > + print("Usage: %s [modem]" % (sys.argv[0])) > + exit(1) > > - if "org.ofono.VoiceCallManager" not in properties["Interfaces"]: > - continue > +modemapi = dbus.Interface(bus.get_object('org.ofono', path), 'org.ofono.Modem') > +properties = modemapi.GetProperties() > > - mgr = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.VoiceCallManager') > +if "org.ofono.VoiceCallManager" not in properties["Interfaces"]: > + print("org.ofono.VoiceCallManager not found") > + exit(2) > + > +print("[ %s ]" % (path)) > + > +mgr = dbus.Interface(bus.get_object('org.ofono', path), > + 'org.ofono.VoiceCallManager') > + > +mgr.ReleaseAndAnswer() > > - mgr.ReleaseAndAnswer() > - break > diff --git a/test/release-and-swap b/test/release-and-swap > index b4c0af1..3276bf5 100755 > --- a/test/release-and-swap > +++ b/test/release-and-swap > @@ -1,5 +1,6 @@ > #!/usr/bin/python3 > > +import sys > import dbus > > bus = dbus.SystemBus() > @@ -7,16 +8,26 @@ bus = dbus.SystemBus() > manager = dbus.Interface(bus.get_object('org.ofono', '/'), > 'org.ofono.Manager') > > -modems = manager.GetModems() > +if (len(sys.argv) == 1): > + modems = manager.GetModems() > + modem = modems[0][0] ditto > +elif (len(sys.argv) == 2): > + modem = sys.argv[1] > +else: > + print("Usage: %s [modem]" % (sys.argv[0])) > + exit(1) > > -for path, properties in modems: > - print("[ %s ]" % (path)) > +modemapi = dbus.Interface(bus.get_object('org.ofono', modem), 'org.ofono.Modem') > +properties = modemapi.GetProperties() > > - if "org.ofono.VoiceCallManager" not in properties["Interfaces"]: > - continue > +if "org.ofono.VoiceCallManager" not in properties["Interfaces"]: > + print("org.ofono.VoiceCallManager not found") > + exit(2) > > - mgr = dbus.Interface(bus.get_object('org.ofono', path), > - 'org.ofono.VoiceCallManager') > +print("[ %s ]" % (modem)) > + > +mgr = dbus.Interface(bus.get_object('org.ofono', modem), > + 'org.ofono.VoiceCallManager') > + > +mgr.ReleaseAndSwap() > > - mgr.ReleaseAndSwap() > - break > Regards, -Denis