From 9b023a0b06e4c760d47a3860ff1197ace3c20d96 Mon Sep 17 00:00:00 2001 From: Nishanth V Date: Thu, 7 Sep 2017 09:53:20 +0530 Subject: [PATCH] test: added script to test serving cell agent --- Makefile.am | 4 +- test/test-serving-cell-info | 97 +++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 test/test-serving-cell-info diff --git a/Makefile.am b/Makefile.am index fbc4d6d5..c46e85a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -780,7 +780,9 @@ test_scripts = test/backtrace \ test/list-allowed-access-points \ test/enable-throttling \ test/disable-throttling \ - test/set-lte-property + test/set-lte-property \ + test/test-serving-cell-info + if TEST testdir = $(pkglibdir)/test diff --git a/test/test-serving-cell-info b/test/test-serving-cell-info new file mode 100644 index 00000000..498ce88b --- /dev/null +++ b/test/test-serving-cell-info @@ -0,0 +1,97 @@ +#!/usr/bin/python3 + +from gi.repository import GLib + +import sys +import dbus +import dbus.service +import dbus.mainloop.glib + +NETMON_INTERFACE = "org.ofono.NetworkMonitor" +AGENT_INTERFACE = "org.ofono.NetworkMonitorAgent" + +class NetworkMonitorAgent(dbus.service.Object): + @dbus.service.method(AGENT_INTERFACE, + in_signature="", out_signature="") + def Release(self): + print("Agent Released") + mainloop.quit() + + @dbus.service.method(AGENT_INTERFACE, + in_signature="a{sv}", out_signature="") + def ServingCellInformationChanged(self, servingcell): + print("ServingCellInformationChanged notification recieved") + + tech = 'Technology' + mcc = 'MobileCountryCode' + mnc = 'MobileNetworkCode' + lac = 'LocationAreaCode' + cid = 'CellId' + psc = 'PrimaryScramblingCode' + rssi = 'Strength' + ber = 'BitErrorRate' + + if tech in servingcell: + print(" [ Radio Access Technology = %s]" \ + % (servingcell[tech])) + + if mcc in servingcell: + print(" [ Mobile Country Code = %s]" \ + % (servingcell[mcc])) + + if mnc in servingcell: + print(" [ Mobile Network Code = %s]" \ + % (servingcell[mnc])) + + if lac in servingcell: + print(" [ Location Area Code = %d]" \ + % (servingcell[lac])) + + if cid in servingcell: + print(" [ Cell Identity = %d]" \ + % (servingcell[cid])) + + if psc in servingcell: + print(" [ Primary Scrambling Code = %d]" \ + % (servingcell[psc])) + + if rssi in servingcell: + print(" [ Signal Strength = %d]" \ + % (servingcell[rssi])) + + if ber in servingcell: + print(" [ Bit Error Rate = %d]" \ + % (servingcell[ber])) + + print('') + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + if len(sys.argv) < 2: + print("Usage: %s " %\ + (sys.argv[0])) + sys.exit(1) + + bus = dbus.SystemBus() + manager = dbus.Interface(bus.get_object("org.ofono", "/"), + "org.ofono.Manager") + + modems = manager.GetModems() + path = modems[0][0] + nm = dbus.Interface(bus.get_object('org.ofono', path), + NETMON_INTERFACE) + + path = "/test/netmonagent" + agent = NetworkMonitorAgent(bus, path) + + try: + period = int(sys.argv[1]) + except: + print("Error: Invalid argument %s" % (sys.argv[1])) + sys.exit(1) + + nm.RegisterAgent(path, period) + print("Agent registered") + mainloop = GLib.MainLoop() + mainloop.run()