1#!/usr/bin/env python3 2# 3# Copyright 2020 - Google 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import random 18import time 19from acts.test_decorators import test_tracker_info 20from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest 21from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING 22from acts_contrib.test_utils.tel.tel_message_utils import sms_send_receive_verify 23from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_idle 24from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte_for_subscription 25from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_csfb_for_subscription 26from acts_contrib.test_utils.tel.tel_subscription_utils import set_message_subid 27from acts_contrib.test_utils.tel.tel_subscription_utils import get_subid_on_same_network_of_host_ad 28from acts_contrib.test_utils.tel.tel_test_utils import install_message_apk 29from acts.utils import rand_ascii_str 30from acts.libs.utils.multithread import multithread_func 31 32class TelLiveStressSmsTest(TelephonyBaseTest): 33 def setup_class(self): 34 TelephonyBaseTest.setup_class(self) 35 self.short_sms_cs_4g_cycle = \ 36 self.user_params.get("short_sms_cs_4g_cycle", 1) 37 self.long_sms_cs_4g_cycle = \ 38 self.user_params.get("long_sms_cs_4g_cycle", 1) 39 self.short_sms_ims_cycle = \ 40 self.user_params.get("short_sms_ims_cycle", 1) 41 self.long_sms_ims_cycle = \ 42 self.user_params.get("long_sms_ims_cycle", 1) 43 44 self.message_util = self.user_params.get("message_apk", None) 45 if isinstance(self.message_util, list): 46 self.message_util = self.message_util[0] 47 48 if self.message_util: 49 ads = self.android_devices 50 for ad in ads: 51 install_message_apk(ad, self.message_util) 52 53 def teardown_test(self): 54 ensure_phones_idle(self.log, self.android_devices) 55 56 def sms_test(self, ads, type='short', rat='volte'): 57 if type == 'short': 58 sms_length = random.randint(50, 180) 59 sms_body = rand_ascii_str(sms_length) 60 else: 61 sms_length = random.randint(800, 1600) 62 sms_body = rand_ascii_str(sms_length) 63 64 mo_sub_id, mt_sub_id, _ = get_subid_on_same_network_of_host_ad( 65 ads, host_sub_id=None, type="sms") 66 set_message_subid(ads[1], mt_sub_id) 67 68 if rat == 'volte': 69 phone_setup_func = phone_setup_volte_for_subscription 70 else: 71 phone_setup_func = phone_setup_csfb_for_subscription 72 73 tasks = [(phone_setup_func, (self.log, ads[0], mo_sub_id)), 74 (phone_setup_func, (self.log, ads[1], mt_sub_id))] 75 if not multithread_func(self.log, tasks): 76 self.log.error("Phone Failed to Set Up Properly.") 77 return False 78 79 time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) 80 81 if not sms_send_receive_verify(self.log, ads[0], ads[1], [sms_body]): 82 ads[0].log.warning("SMS of length %s test failed", sms_length) 83 return False 84 85 ads[0].log.info("SMS of length %s test succeeded", sms_length) 86 time.sleep(random.randint(5, 10)) 87 return True 88 89 def calculte_fail_rate(self, result_dict={}): 90 result_list = [] 91 for key in result_dict: 92 if result_dict[key]: 93 result_list.append(True) 94 else: 95 result_list.append(False) 96 97 fail_rate = result_list.count(False)/len(result_list) 98 self.log.info('Test result: %s', result_dict) 99 return fail_rate 100 101 @test_tracker_info(uuid="e54d15bf-db9b-4389-bfe8-c9c5dad7ef33") 102 @TelephonyBaseTest.tel_test_wrap 103 def test_stress_short_sms_ims(self): 104 cycle = self.short_sms_ims_cycle 105 result_dict = {} 106 for attempt in range(cycle): 107 self.log.info( 108 "============> Stress short SMS over IMS test cycle %s <============", 109 attempt+1) 110 result = self.sms_test(self.android_devices, 'short', 'volte') 111 result_dict['cycle_%s' % str(attempt+1)] = result 112 113 fail_rate = self.calculte_fail_rate(result_dict) 114 self.log.info('Fail rate of short SMS over IMS: %s', fail_rate) 115 116 @test_tracker_info(uuid="45858a3c-0c37-4b3d-af4d-60f374d0a2e5") 117 @TelephonyBaseTest.tel_test_wrap 118 def test_stress_long_sms_ims(self): 119 cycle = self.long_sms_ims_cycle 120 result_dict = {} 121 for attempt in range(cycle): 122 self.log.info( 123 "============> Stress long SMS over IMS test cycle %s <============", 124 attempt+1) 125 result = self.sms_test(self.android_devices, 'long', 'volte') 126 result_dict['cycle_%s' % str(attempt+1)] = result 127 128 fail_rate = self.calculte_fail_rate(result_dict) 129 self.log.info('Fail rate of long SMS over IMS: %s', fail_rate) 130 131 @test_tracker_info(uuid="319aec8f-2e04-4420-9f8a-388c092ddd39") 132 @TelephonyBaseTest.tel_test_wrap 133 def test_stress_short_sms_cs_4g(self): 134 cycle = self.short_sms_cs_4g_cycle 135 result_dict = {} 136 for attempt in range(cycle): 137 self.log.info( 138 "============> Stress short CS SMS on LTE test cycle %s <============", 139 attempt+1) 140 result = self.sms_test(self.android_devices, 'short', 'csfb') 141 result_dict['cycle_%s' % str(attempt+1)] = result 142 143 fail_rate = self.calculte_fail_rate(result_dict) 144 self.log.info('Fail rate of short CS SMS on LTE: %s', fail_rate) 145 146 @test_tracker_info(uuid="aa8a2e7a-1ca7-4406-801d-f8e1923d0695") 147 @TelephonyBaseTest.tel_test_wrap 148 def test_stress_long_sms_cs_4g(self): 149 cycle = self.long_sms_cs_4g_cycle 150 result_dict = {} 151 for attempt in range(cycle): 152 self.log.info( 153 "============> Stress long CS SMS on LTE test cycle %s <============", 154 attempt+1) 155 result = self.sms_test(self.android_devices, 'long', 'csfb') 156 result_dict['cycle_%s' % str(attempt+1)] = result 157 158 fail_rate = self.calculte_fail_rate(result_dict) 159 self.log.info('Fail rate of long CS SMS on LTE: %s', fail_rate)