From 5552afde479b227f48660e4e35f7481372eebbcc Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 30 Oct 2012 22:54:17 +0100 Subject: [PATCH] end-to-end: Finally begin with some ofono based End-to-End tests This is not much of a framework yet but it hopefully turns into one over time. Begin with some helpers for using ofono. --- .gitignore | 1 + ofono-end-to-end/README | 1 + ofono-end-to-end/osmocom/__init__.py | 0 ofono-end-to-end/osmocom/modem.py | 53 ++++++++++++++++++++++++++++ ofono-end-to-end/osmocom/sim.py | 26 ++++++++++++++ ofono-end-to-end/osmocom/sms.py | 25 +++++++++++++ ofono-end-to-end/simple_test.py | 34 ++++++++++++++++++ 7 files changed, 140 insertions(+) create mode 100644 ofono-end-to-end/README create mode 100644 ofono-end-to-end/osmocom/__init__.py create mode 100644 ofono-end-to-end/osmocom/modem.py create mode 100644 ofono-end-to-end/osmocom/sim.py create mode 100644 ofono-end-to-end/osmocom/sms.py create mode 100755 ofono-end-to-end/simple_test.py diff --git a/.gitignore b/.gitignore index 45d62d8..b4a472d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.sw? +*.py? diff --git a/ofono-end-to-end/README b/ofono-end-to-end/README new file mode 100644 index 0000000..146244a --- /dev/null +++ b/ofono-end-to-end/README @@ -0,0 +1 @@ +End to End tests for OpenBSC/sysmoBTS diff --git a/ofono-end-to-end/osmocom/__init__.py b/ofono-end-to-end/osmocom/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ofono-end-to-end/osmocom/modem.py b/ofono-end-to-end/osmocom/modem.py new file mode 100644 index 0000000..9d40d78 --- /dev/null +++ b/ofono-end-to-end/osmocom/modem.py @@ -0,0 +1,53 @@ +# Copyright (C) 2012 Holger Hans Peter Freyther +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import dbus + +def get(bus, name): + """ + Find the modem + """ + return dbus.Interface(bus.get_object('org.ofono', name), 'org.ofono.Modem') + +def getmodems(bus): + """ + Find modems... + """ + obj = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager') + return obj.GetModems() + +def enable(modem): + """ + Enable the given modem on the Bus + """ + modem.SetProperty("Powered", dbus.Boolean(1), timeout = 120) + +def disable(modem): + """ + Enable the given modem on the Bus + """ + modem.SetProperty("Powered", dbus.Boolean(0), timeout = 120) + +def online(modem): + """ + Switch-on on the RF Modem + """ + modem.SetProperty("Online", dbus.Boolean(1), timeout = 120) + +def offline(modem): + """ + Switch-off on the RF Modem + """ + modem.SetProperty("Online", dbus.Boolean(0), timeout = 120) diff --git a/ofono-end-to-end/osmocom/sim.py b/ofono-end-to-end/osmocom/sim.py new file mode 100644 index 0000000..8c8d867 --- /dev/null +++ b/ofono-end-to-end/osmocom/sim.py @@ -0,0 +1,26 @@ +# Copyright (C) 2012 Holger Hans Peter Freyther +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import dbus + +def get(bus, path): + """Get the SIM manager""" + return dbus.Interface(bus.get_object('org.ofono', path), 'org.ofono.SimManager') + +def present(sim): + return bool(sim.GetProperties(timeout=120)['Present']) + +def imsi(sim): + return str(sim.GetProperties(timeout=120)['SubscriberIdentity']) diff --git a/ofono-end-to-end/osmocom/sms.py b/ofono-end-to-end/osmocom/sms.py new file mode 100644 index 0000000..37b9802 --- /dev/null +++ b/ofono-end-to-end/osmocom/sms.py @@ -0,0 +1,25 @@ +# Copyright (C) 2012 Holger Hans Peter Freyther +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import dbus + +def get(bus, name): + return dbus.Interface( + bus.get_object('org.ofono', name), + 'org.ofono.MessageManager') + +def send_message(manager, number, text, delivery_report): + manager.SetProperty('UseDeliveryReports', dbus.Boolean(int(delivery_report))) + return manager.SendMessage(number, text) diff --git a/ofono-end-to-end/simple_test.py b/ofono-end-to-end/simple_test.py new file mode 100755 index 0000000..d9ac5fd --- /dev/null +++ b/ofono-end-to-end/simple_test.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Holger Hans Peter Freyther +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import dbus +import dbus.mainloop.glib + +from osmocom import modem, sms, sim + +bus = dbus.SystemBus() +mods = modem.getmodems(bus) +mod = modem.get(bus, "/phonesim") +modem.enable(mod) +modem.online(mod) + +sm = sms.get(bus, "/phonesim") +for i in range(1, 10): + print sms.send_message(sm, '+491234', 'TEST %d' % i, False) + +s = sim.get(bus, "/phonesim") +print sim.present(s) +print sim.imsi(s)