1# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging, os, subprocess 6import dbus 7 8from autotest_lib.client.bin import test 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.cros.cellular import sms, mmtest 11 12class network_ModemManagerSMS(test.test): 13 version = 1 14 15 def setup(self): 16 self.job.setup_dep(['fakegudev', 'fakemodem']) 17 18 def run_sms_test(self, testfunc, *args, **kwargs): 19 paths = [os.path.join(self.srcdir, 'fake-gsm'), 20 os.path.join(self.srcdir, 'fake-icera')] 21 22 with mmtest.ModemManagerTest(self.autodir, paths) as mmt: 23 smsstore = sms.SmsStore(mmt.fakemodem) 24 gsmsms = mmt.mm.GsmSms(mmt.modem_object_path) 25 smstest = sms.SmsTest(gsmsms) 26 27 testfunc(smsstore, smstest, *args, **kwargs) 28 29 def test_sms_zero(self, smsstore, smstest): 30 # leave smsstore empty 31 smstest.test_has_none() 32 33 def test_sms_one(self, smsstore, smstest): 34 testsms = sms.sample 35 smsstore.sms_insert(1, testsms['pdu']) 36 smstest.test_has_one(testsms['parsed']) 37 smsstore.sms_remove(1) 38 smstest.test_has_none() 39 40 def test_sms_arrive(self, smsstore, smstest): 41 smstest.test_has_none() 42 testsms = sms.sample 43 smsstore.sms_receive(1, testsms['pdu']) 44 # Note: this test doesn't check for the DBus signals that 45 # are supposed to be sent when a new message arrives. 46 # See network_ModemManagerSMSSignal for that. 47 smstest.test_has_one(testsms['parsed']) 48 smsstore.sms_remove(1) 49 smstest.test_has_none() 50 51 def test_sms_multipart_existing(self, smsstore, smstest): 52 testsms = sms.sample_multipart 53 smsstore.sms_insert(1, testsms['pdu'][0]) 54 smsstore.sms_insert(2, testsms['pdu'][1]) 55 smstest.test_has_one(testsms['parsed']) 56 smsstore.sms_remove(1) 57 smsstore.sms_remove(2) 58 smstest.test_has_none() 59 60 def test_sms_multipart_receive(self, smsstore, smstest): 61 smstest.test_has_none() 62 testsms = sms.sample_multipart 63 smsstore.sms_receive(1, testsms['pdu'][0]) 64 # Can't use test_has_none() here because it will delete the 65 # partial message 66 smstest.test_list([]) 67 smstest.test_get(1, None) 68 smsstore.sms_receive(2, testsms['pdu'][1]) 69 smstest.test_has_one(testsms['parsed']) 70 smsstore.sms_remove(1) 71 smsstore.sms_remove(2) 72 smstest.test_has_none() 73 74 def test_sms_multipart_reverse(self, smsstore, smstest): 75 smstest.test_has_none() 76 testsms = sms.sample_multipart 77 smsstore.sms_receive(1, testsms['pdu'][1]) 78 # Can't use test_sms_has_none() here because it will delete the 79 # partial message 80 smstest.test_list([]) 81 smstest.test_get(1, None) 82 smsstore.sms_receive(2, testsms['pdu'][0]) 83 smstest.test_has_one(testsms['parsed']) 84 smsstore.sms_remove(1) 85 smsstore.sms_remove(2) 86 smstest.test_has_none() 87 88 def run_once(self): 89 self.job.install_pkg('fakegudev', 'dep', 90 os.path.join(self.autodir, 'deps', 'fakegudev')) 91 self.job.install_pkg('fakemodem', 'dep', 92 os.path.join(self.autodir, 'deps', 'fakemodem')) 93 94 subprocess.check_call(["modprobe", "tun"]) 95 subprocess.check_call(["initctl", "stop", "modemmanager"]) 96 97 try: 98 self.run_sms_test(self.test_sms_zero) 99 self.run_sms_test(self.test_sms_one) 100 self.run_sms_test(self.test_sms_arrive) 101 self.run_sms_test(self.test_sms_multipart_existing) 102 self.run_sms_test(self.test_sms_multipart_receive) 103 self.run_sms_test(self.test_sms_multipart_reverse) 104 105 finally: 106 subprocess.check_call(["initctl", "start", "modemmanager"]) 107 subprocess.check_call(["rmmod", "tun"]) 108