• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2016 - The Android Open Source Project
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"""
17    Test Script for Telephony Pre Check In Sanity
18"""
19
20import math
21import time
22from acts.test_decorators import test_tracker_info
23from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
24from acts.controllers.anritsu_lib.md8475a import CTCHSetup
25from acts.controllers.anritsu_lib.md8475a import BtsBandwidth
26from acts.controllers.anritsu_lib.md8475a import BtsPacketRate
27from acts.controllers.anritsu_lib.md8475a import BtsServiceState
28from acts.controllers.anritsu_lib.md8475a import MD8475A
29from acts.controllers.anritsu_lib.mg3710a import MG3710A
30from acts.test_utils.tel.anritsu_utils import LTE_BAND_2
31from acts.test_utils.tel.anritsu_utils import set_system_model_gsm
32from acts.test_utils.tel.anritsu_utils import set_system_model_lte
33from acts.test_utils.tel.anritsu_utils import set_system_model_lte_lte
34from acts.test_utils.tel.anritsu_utils import set_system_model_lte_wcdma
35from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma
36from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma_gsm
37from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma_wcdma
38from acts.test_utils.tel.anritsu_utils import set_usim_parameters
39from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
40from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
41from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
42from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
43from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
44from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM
45from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE
46from acts.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
47from acts.test_utils.tel.tel_test_utils import ensure_network_rat
48from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
49from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
50from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
51from acts.controllers.anritsu_lib.cell_configurations import \
52    gsm_band850_ch128_fr869_cid58_cell
53from acts.controllers.anritsu_lib.cell_configurations import \
54    gsm_band850_ch251_fr893_cid59_cell
55from acts.controllers.anritsu_lib.cell_configurations import \
56    gsm_band1900_ch512_fr1930_cid51_cell
57from acts.controllers.anritsu_lib.cell_configurations import \
58    gsm_band1900_ch512_fr1930_cid52_cell
59from acts.controllers.anritsu_lib.cell_configurations import \
60    gsm_band1900_ch512_fr1930_cid53_cell
61from acts.controllers.anritsu_lib.cell_configurations import \
62    gsm_band1900_ch512_fr1930_cid54_cell
63from acts.controllers.anritsu_lib.cell_configurations import \
64    gsm_band1900_ch640_fr1955_cid56_cell
65from acts.controllers.anritsu_lib.cell_configurations import \
66    gsm_band1900_ch750_fr1977_cid57_cell
67from acts.controllers.anritsu_lib.cell_configurations import \
68    lte_band2_ch900_fr1960_pcid9_cell
69from acts.controllers.anritsu_lib.cell_configurations import \
70    lte_band4_ch2000_fr2115_pcid1_cell
71from acts.controllers.anritsu_lib.cell_configurations import \
72    lte_band4_ch2000_fr2115_pcid2_cell
73from acts.controllers.anritsu_lib.cell_configurations import \
74    lte_band4_ch2000_fr2115_pcid3_cell
75from acts.controllers.anritsu_lib.cell_configurations import \
76    lte_band4_ch2000_fr2115_pcid4_cell
77from acts.controllers.anritsu_lib.cell_configurations import \
78    lte_band4_ch2050_fr2120_pcid7_cell
79from acts.controllers.anritsu_lib.cell_configurations import \
80    lte_band4_ch2050_fr2120_pcid7_cell
81from acts.controllers.anritsu_lib.cell_configurations import \
82    lte_band4_ch2250_fr2140_pcid8_cell
83from acts.controllers.anritsu_lib.cell_configurations import \
84    lte_band12_ch5095_fr737_pcid10_cell
85from acts.controllers.anritsu_lib.cell_configurations import \
86    wcdma_band1_ch10700_fr2140_cid31_cell
87from acts.controllers.anritsu_lib.cell_configurations import \
88    wcdma_band1_ch10700_fr2140_cid32_cell
89from acts.controllers.anritsu_lib.cell_configurations import \
90    wcdma_band1_ch10700_fr2140_cid33_cell
91from acts.controllers.anritsu_lib.cell_configurations import \
92    wcdma_band1_ch10700_fr2140_cid34_cell
93from acts.controllers.anritsu_lib.cell_configurations import \
94    wcdma_band1_ch10575_fr2115_cid36_cell
95from acts.controllers.anritsu_lib.cell_configurations import \
96    wcdma_band1_ch10800_fr2160_cid37_cell
97from acts.controllers.anritsu_lib.cell_configurations import \
98    wcdma_band2_ch9800_fr1960_cid38_cell
99from acts.controllers.anritsu_lib.cell_configurations import \
100    wcdma_band2_ch9900_fr1980_cid39_cell
101
102
103class TelLabNeighborCellTest(TelephonyBaseTest):
104
105    # This is the default offset between CallBox Power Level and Phone measure
106    # Power Level.
107    # TODO: Probably need to further tune those values.
108    _LTE_RSSI_OFFSET = -39
109    _WCDMA_RSSI_OFFSET = -31
110    _GSM_RSSI_OFFSET = -30
111
112    _ANRITSU_SETTLING_TIME = 15
113    _SETTLING_TIME = 75
114    _LTE_MCS_DL = 5
115    _LTE_MCS_UL = 5
116    _NRB_DL = 50
117    _NRB_UL = 50
118    _CELL_PARAM_FILE = 'C:\\MX847570\\CellParam\\NEIGHBOR_CELL_TEST_TMO.wnscp'
119
120    # Below are keys should be included in expected cell info.
121    # TARGET_RSSI: This is expected RSSI.
122    TARGET_RSSI = 'target_rssi'
123    # MAX_ERROR_RSSI: This is max error between 'each sample of reported RSSI'
124    # and 'expected RSSI'
125    MAX_ERROR_RSSI = 'max_error_rssi'
126    # MAX_ERROR_AVERAGE_RSSI: This is max error between
127    # 'average value of reported RSSI' and 'expected RSSI'
128    MAX_ERROR_AVERAGE_RSSI = 'max_error_average_rssi'
129    # REPORT_RATE: expected report rate for neighbor cell.
130    REPORT_RATE = 'report_rate'
131    # RAT: expected network rat.
132    RAT = 'rat'
133    # IS_REGISTERED: is the cell registered.
134    # For serving cell, this value should be True; for neighbor cell, should be
135    # False
136    IS_REGISTERED = 'registered'
137    # CID: cell CID info.
138    CID = 'cid'
139    # PCID: cell PCID info.
140    PCID = 'pcid'
141    # PSC: cell PSC info.
142    PSC = 'psc'
143
144    # Keys for calculate average RSSI. Only used in _verify_cell_info
145    RSSI = 'rssi'
146    COUNT = 'count'
147
148    # Pre-defined invalid value. If this value is reported in cell info, just
149    # discard this value. E.g. if in reported cell info, cid is reported as
150    # 0x7fffffff, need to discard this value when calculating unique_id
151    INVALID_VALUE = 0x7fffffff
152
153    def __init__(self, controllers):
154        TelephonyBaseTest.__init__(self, controllers)
155        self.ad = self.android_devices[0]
156        self.ad.sim_card = getattr(self.ad, "sim_card", None)
157        self.md8475a_ip_address = self.user_params[
158            "anritsu_md8475a_ip_address"]
159        self.mg3710a_ip_address = self.user_params[
160            "anritsu_mg3710a_ip_address"]
161        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
162        self.md8475_version = self.user_params.get("md8475", "A")
163
164        if "lte_rssi_offset" in self.user_params:
165            self._LTE_RSSI_OFFSET = int(self.user_params["lte_rssi_offset"])
166        if "wcdma_rssi_offset" in self.user_params:
167            self._WCDMA_RSSI_OFFSET = int(self.user_params[
168                "wcdma_rssi_offset"])
169        if "gsm_rssi_offset" in self.user_params:
170            self._GSM_RSSI_OFFSET = int(self.user_params["gsm_rssi_offset"])
171
172    def setup_class(self):
173        self.md8475a = None
174        self.mg3710a = None
175        try:
176            self.md8475a = MD8475A(self.md8475a_ip_address, self.log,
177                                   self.wlan_option, self.md8475_version)
178        except AnritsuError as e:
179            self.log.error("Error in connecting to Anritsu MD8475A:{}".format(
180                e))
181            return False
182
183        try:
184            self.mg3710a = MG3710A(self.mg3710a_ip_address, self.log)
185        except AnritsuError as e:
186            self.log.error("Error in connecting to Anritsu MG3710A :{}".format(
187                e))
188            return False
189        return True
190
191    def setup_test(self):
192        self.turn_off_3710a_sg(1)
193        self.turn_off_3710a_sg(2)
194        self.mg3710a.set_arb_pattern_aorb_state("A", "OFF", 1)
195        self.mg3710a.set_arb_pattern_aorb_state("B", "OFF", 1)
196        self.mg3710a.set_arb_pattern_aorb_state("A", "OFF", 2)
197        self.mg3710a.set_arb_pattern_aorb_state("B", "OFF", 2)
198        self.mg3710a.set_freq_relative_display_status("OFF", 1)
199        self.mg3710a.set_freq_relative_display_status("OFF", 2)
200        self.ad.droid.telephonySetPreferredNetworkTypes(
201            NETWORK_MODE_LTE_GSM_WCDMA)
202        ensure_phones_idle(self.log, self.android_devices)
203        toggle_airplane_mode(self.log, self.ad, True)
204        self.ad.droid.telephonyToggleDataConnection(True)
205        self.ad.adb.shell("setprop net.lte.ims.volte.provisioned 1",
206                          ignore_status=True)
207        return True
208
209    def teardown_test(self):
210        toggle_airplane_mode(self.log, self.ad, True)
211        self.turn_off_3710a_sg(1)
212        self.turn_off_3710a_sg(2)
213        self.log.info("Stopping Simulation")
214        self.md8475a.stop_simulation()
215        return True
216
217    def teardown_class(self):
218        if self.md8475a is not None:
219            self.md8475a.disconnect()
220        if self.mg3710a is not None:
221            self.mg3710a.disconnect()
222        return True
223
224    def _setup_lte_serving_cell(self, bts, dl_power, cell_id, physical_cellid):
225        bts.output_level = dl_power
226        bts.bandwidth = BtsBandwidth.LTE_BANDWIDTH_10MHz
227        bts.packet_rate = BtsPacketRate.LTE_MANUAL
228        bts.lte_mcs_dl = self._LTE_MCS_DL
229        bts.lte_mcs_ul = self._LTE_MCS_UL
230        bts.nrb_dl = self._NRB_DL
231        bts.nrb_ul = self._NRB_UL
232        bts.cell_id = cell_id
233        bts.physical_cellid = physical_cellid
234        bts.neighbor_cell_mode = "DEFAULT"
235
236    def _setup_lte_neighbhor_cell_md8475a(self, bts, band, dl_power, cell_id,
237                                          physical_cellid):
238        bts.output_level = dl_power
239        bts.band = band
240        bts.bandwidth = BtsBandwidth.LTE_BANDWIDTH_10MHz
241        bts.cell_id = cell_id
242        bts.physical_cellid = physical_cellid
243        bts.neighbor_cell_mode = "DEFAULT"
244        bts.packet_rate = BtsPacketRate.LTE_MANUAL
245        bts.lte_mcs_dl = self._LTE_MCS_DL
246        bts.lte_mcs_ul = self._LTE_MCS_UL
247        bts.nrb_dl = self._NRB_DL
248        bts.nrb_ul = self._NRB_UL
249
250    def _setup_wcdma_serving_cell(self, bts, dl_power, cell_id):
251        bts.output_level = dl_power
252        bts.cell_id = cell_id
253        bts.neighbor_cell_mode = "DEFAULT"
254
255    def _setup_wcdma_neighbhor_cell_md8475a(self, bts, band, dl_power,
256                                            cell_id):
257        bts.output_level = dl_power
258        bts.band = band
259        bts.cell_id = cell_id
260        bts.neighbor_cell_mode = "DEFAULT"
261
262    def _setup_lte_cell_md8475a(self, bts, params, dl_power):
263        bts.output_level = dl_power
264        bts.band = params['band']
265        bts.bandwidth = params['bandwidth']
266        bts.cell_id = params['cid']
267        bts.physical_cellid = params['pcid']
268        bts.mcc = params['mcc']
269        bts.mnc = params['mnc']
270        bts.tac = params['tac']
271        bts.neighbor_cell_mode = "DEFAULT"
272        bts.dl_channel = params['channel']
273        bts.packet_rate = BtsPacketRate.LTE_MANUAL
274        bts.lte_mcs_dl = self._LTE_MCS_DL
275        bts.lte_mcs_ul = self._LTE_MCS_UL
276        bts.nrb_dl = self._NRB_DL
277        bts.nrb_ul = self._NRB_UL
278
279    def _setup_wcdma_cell_md8475a(self, bts, params, dl_power):
280        bts.output_level = dl_power
281        bts.band = params['band']
282        bts.cell_id = params['cid']
283        bts.mcc = params['mcc']
284        bts.mnc = params['mnc']
285        bts.lac = params['lac']
286        bts.rac = params['rac']
287        bts.neighbor_cell_mode = "DEFAULT"
288        bts.primary_scrambling_code = params['psc']
289        bts.dl_channel = params['channel']
290
291    def _setup_gsm_cell_md8475a(self, bts, params, dl_power):
292        bts.output_level = params['power']
293        bts.band = params['band']
294        bts.cell_id = params['cid']
295        bts.mcc = params['mcc']
296        bts.mnc = params['mnc']
297        bts.lac = params['lac']
298        bts.rac = params['rac']
299        bts.neighbor_cell_mode = "DEFAULT"
300
301    def setup_3710a_waveform(self, sg_number, memory, frequency, power_level,
302                             wave_package_name, wave_pattern_name):
303        self.mg3710a.set_frequency(frequency, sg_number)
304        self.mg3710a.set_arb_state("ON", sg_number)
305        self.mg3710a.set_arb_combination_mode("EDIT", sg_number)
306        self.mg3710a.select_waveform(wave_package_name, wave_pattern_name,
307                                     memory, sg_number)
308        self.mg3710a.set_arb_pattern_aorb_state(memory, "ON", sg_number)
309        self.mg3710a.set_arb_level_aorb(memory, power_level, sg_number)
310
311    def turn_on_3710a_sg(self, sg_number):
312        self.mg3710a.set_modulation_state("ON", sg_number)
313        self.mg3710a.set_rf_output_state("ON", sg_number)
314
315    def turn_off_3710a_sg(self, sg_number):
316        self.mg3710a.set_modulation_state("OFF", sg_number)
317        self.mg3710a.set_rf_output_state("OFF", sg_number)
318
319    def _is_matching_cell(self, expected_cell_info, input_cell_info):
320        """Return if 'input_cell_info' matches 'expected_cell_info'.
321
322        Args:
323            expected_cell_info: expected cell info. (dictionary)
324            input_cell_info: input cell info to test. (dictionary)
325
326        Returns:
327            True if:
328                for each key in key_list, if key exist in expected_cell_info,
329                it should also exist in input_cell_info, and the values should
330                equal in expected_cell_info and input_cell_info
331            False otherwise.
332        """
333        for key in [
334                self.CID, self.PCID, self.RAT, self.PSC, self.IS_REGISTERED
335        ]:
336            if key in expected_cell_info:
337                if key not in input_cell_info:
338                    return False
339                if input_cell_info[key] != expected_cell_info[key]:
340                    return False
341        return True
342
343    def _unique_cell_id(self, input_cell_info):
344        """Get the unique id for cell_info, based on cid, pcid, rat, psc and
345        is_registered.
346
347        Args:
348            input_cell_info: cell info to get unique id.
349
350        Returns:
351            unique id (string)
352        """
353        unique_id = ""
354        for key in [
355                self.CID, self.PCID, self.RAT, self.PSC, self.IS_REGISTERED
356        ]:
357            if key in input_cell_info:
358                if input_cell_info[key] != self.INVALID_VALUE:
359                    unique_id += key + ":" + str(input_cell_info[key]) + ":"
360        return unique_id
361
362    def _get_rssi_from_cell_info(self, cell_info):
363        """Return the RSSI value reported in cell_info.
364
365        Args:
366            cell_info: cell info to get RSSI.
367
368        Returns:
369            RSSI reported in this cell info.
370        """
371        rat_to_rssi_tbl = {
372            'lte': 'rsrp',
373            'wcdma': 'signal_strength',
374            'gsm': 'signal_strength'
375        }
376        try:
377            return cell_info[rat_to_rssi_tbl[cell_info[self.RAT]]]
378        except KeyError:
379            return None
380
381    def _is_rssi_in_expected_range(self, actual_rssi, expected_rssi,
382                                   max_error):
383        """Return if actual_rssi is within expected range.
384
385        Args:
386            actual_rssi: the rssi value to test.
387            expected_rssi: expected rssi value.
388            max_error: max error.
389
390        Returns:
391            if the difference between actual_rssi and expected_rssi is within
392            max_error, return True. Otherwise False.
393        """
394        if abs(actual_rssi - expected_rssi) > max_error:
395            self.log.error(
396                "Expected RSSI: {}, max error: {}, reported RSSI: {}".format(
397                    expected_rssi, max_error, actual_rssi))
398            return False
399        else:
400            return True
401
402    def _verify_cell_info(self,
403                          ad,
404                          expected_cell_info_stats,
405                          number_of_sample=10,
406                          delay_each_sample=5):
407        """Return if reported cell info from ad matches expected_cell_info_stats
408        or not.
409
410        Args:
411            ad: android device object.
412            expected_cell_info_stats: expected cell info list.
413            number_of_sample: number of sample to take from DUT.
414            delay_each_sample: time delay between each sample.
415
416        Returns:
417            True if reported cell info matches with expected_cell_info_stats.
418            False otherwise.
419
420        """
421
422        cell_info_stats = {}
423
424        for index in range(number_of_sample):
425            info_list = ad.droid.telephonyGetAllCellInfo()
426
427            self.log.info("Received Cell Info List: {}".format(info_list))
428
429            for sample in info_list:
430                rssi = self._get_rssi_from_cell_info(sample)
431                unique_id = self._unique_cell_id(sample)
432
433                # check cell logic
434                if not unique_id in expected_cell_info_stats:
435                    self.log.error("Found unexpected cell!")
436                    return False
437                elif not self._is_matching_cell(
438                        expected_cell_info_stats[unique_id], sample):
439                    self.log.error("Mismatched Cell Info")
440                    return False
441
442                # Check RSSI within expected range
443                if not self._is_rssi_in_expected_range(
444                        self._get_rssi_from_cell_info(sample),
445                        expected_cell_info_stats[unique_id][self.TARGET_RSSI],
446                        expected_cell_info_stats[unique_id][
447                            self.MAX_ERROR_RSSI]):
448                    self.log.error("Cell Info: {}. Cell RSSI not" +
449                                   " in expected range".format(sample))
450                    return False
451                if unique_id not in cell_info_stats:
452                    cell_info_stats[unique_id] = {self.RSSI: 0, self.COUNT: 0}
453                cell_info_stats[unique_id][self.RSSI] += rssi
454                cell_info_stats[unique_id][self.COUNT] += 1
455
456            time.sleep(delay_each_sample)
457
458        try:
459            for unique_id in expected_cell_info_stats.keys():
460                expected_cell_info = expected_cell_info_stats[unique_id]
461
462                expected_number_of_sample_reported = math.floor(
463                    expected_cell_info[self.REPORT_RATE] * number_of_sample)
464
465                if cell_info_stats[unique_id][
466                        self.COUNT] < expected_number_of_sample_reported:
467                    self.log.error(
468                        "Insufficient reports {}/{} for {}, expected: {}",
469                        expected_cell_info[unique_id][self.COUNT],
470                        number_of_sample, expected_cell_info,
471                        expected_number_of_sample_reported)
472                    return False
473
474                average_rssi = cell_info_stats[unique_id][self.RSSI] / \
475                               cell_info_stats[unique_id][self.COUNT]
476
477                # Check Average RSSI within expected range
478                if not self._is_rssi_in_expected_range(
479                        average_rssi, expected_cell_info[self.TARGET_RSSI],
480                        expected_cell_info[self.MAX_ERROR_AVERAGE_RSSI]):
481                    self.log.error("Cell Average RSSI not in expected range.")
482                    return False
483        except KeyError as unique_id:
484            self.log.error("Failed to find key {}".format(unique_id))
485            self.log.error("Expected cell info not reported {}.".format(
486                expected_cell_info))
487            return False
488
489        return True
490
491    def lte_intra_freq_ncell(self,
492                             ad,
493                             pcid_list,
494                             init_pwr,
495                             power_seq,
496                             interval=3,
497                             err_margin=1):
498        """Return True if UE measured RSSI follows the powers in BTS simulator
499
500        Args:
501            ad: android device object.
502            pcid: list of PCID of LTE BTS
503            init_pwr: initial downlinl power in dBm for serving and neighbor cell
504            power_seq: power change sequence in dB.
505            interval: time delay in seocnd between each power change.
506            error_margin: error margin in dB to determine measurement pass or fail
507
508        Returns:
509            True if all measurments are within margin.
510            False otherwise.
511
512        """
513        bts = set_system_model_lte_lte(self.md8475a, self.user_params,
514                                       self.ad.sim_card)
515
516        self._setup_lte_serving_cell(bts[0], init_pwr, pcid_list[0],
517                                     pcid_list[0])
518        self._setup_lte_neighbhor_cell_md8475a(bts[1], LTE_BAND_2, init_pwr,
519                                               pcid_list[1], pcid_list[1])
520        set_usim_parameters(self.md8475a, self.ad.sim_card)
521        self.md8475a.send_command("IMSSTARTVN 1")
522        self.md8475a.start_simulation()
523        bts[1].service_state = BtsServiceState.SERVICE_STATE_OUT
524        self.ad.droid.telephonyToggleDataConnection(True)
525        if not ensure_network_rat(
526                self.log,
527                self.ad,
528                NETWORK_MODE_LTE_GSM_WCDMA,
529                RAT_FAMILY_LTE,
530                toggle_apm_after_setting=True):
531            self.log.error("Failed to set rat family {}, preferred network:{}".
532                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
533            return False
534        self.md8475a.wait_for_registration_state()
535        time.sleep(1)
536        bts[1].service_state = BtsServiceState.SERVICE_STATE_IN
537
538        n_bts = len(pcid_list)  # number of total BTS
539        if n_bts >= 3:
540            self.setup_3710a_waveform("1", "A", "1960MHZ", init_pwr, "LTE",
541                                      "10M_B1_CID2")
542            self.turn_on_3710a_sg(1)
543        if n_bts == 4:
544            self.setup_3710a_waveform("1", "B", "1960MHZ", init_pwr, "LTE",
545                                      "10M_B1_CID3")
546        self.log.info("Wait for {} seconds to settle".format(
547            self._ANRITSU_SETTLING_TIME))
548        time.sleep(self._ANRITSU_SETTLING_TIME)
549        cell_list = ad.droid.telephonyGetAllCellInfo()
550        self.log.info("Received Cell Info List: {}".format(cell_list))
551        init_rsrp_list = []
552        for pcid in pcid_list:
553            for cell in cell_list:
554                if cell['pcid'] == pcid:
555                    init_rsrp_list.append(cell['rsrp'])
556                    break
557        self.log.info("init_rsrp_list = {}".format(init_rsrp_list))
558        error_seq = []
559        for power in power_seq:
560            self.log.info("power = {}".format(power))
561            for i in range(2):
562                bts[i].output_level = init_pwr + power[i]
563            if n_bts >= 3:
564                self.mg3710a.set_arb_level_aorb("A", init_pwr + power[2], "1")
565            if n_bts == 4:
566                self.mg3710a.set_arb_level_aorb("B", init_pwr + power[2], "1")
567            time.sleep(interval)
568            cell_list = ad.droid.telephonyGetAllCellInfo()
569            delta = []
570            error = []
571            for pcid, init_rsrp, pwr in zip(pcid_list, init_rsrp_list, power):
572                found = False
573                for cell in cell_list:
574                    if cell['pcid'] == pcid:
575                        found = True
576                        self.log.info("pcid {}, rsrp = {}".format(pcid, cell[
577                            'rsrp']))
578                        delta.append(cell['rsrp'] - init_rsrp)
579                        error.append(cell['rsrp'] - init_rsrp - pwr)
580                if not found:
581                    self.log.info("pcid {} not found!".format(pcid))
582                    delta.append(-99)
583                    error.append(-99)
584            self.log.info("delta = {}".format(delta))
585            self.log.info("error = {}".format(error))
586            error_seq.append(error)
587        self.log.info("error_seq = {}".format(error_seq))
588        for error in error_seq:
589            for err in error:
590                if err != -99 and abs(err) > err_margin:
591                    self.log.error(
592                        "Test failed! Measured power error is greater than margin."
593                    )
594                    return False
595        return True
596
597    """ Tests Begin """
598
599    @test_tracker_info(uuid="17a42861-abb5-480b-9139-89219fa304b2")
600    @TelephonyBaseTest.tel_test_wrap
601    def test_2lte_intra_freq_ncell_away_close(self):
602        """ Test phone moving away from Neighbor Intra Freq cell then
603        close back while serving cell stays the same power
604
605        Setup a two LTE cell configuration on MD8475A
606        Make Sure Phone is in LTE mode
607        Verify the reported RSSI follows the DL power change in MD8475A
608
609        Returns:
610            True if pass; False if fail
611        """
612        pcid = [0, 1]
613        init_pwr = -30  # initial DL power for all cells
614        power_seq = [
615            [0, -1],  # power change sequence reference to init_pwr
616            [0, -2],
617            [0, -3],
618            [0, -4],
619            [0, -3],
620            [0, -2],
621            [0, -1],
622            [0, 0],
623            [0, 1],
624            [0, 3],
625            [0, 4],
626            [0, 5],
627            [0, 6],
628            [0, 7],
629            [0, 8],
630            [0, 9],
631            [0, 10],
632            [0, 9],
633            [0, 8],
634            [0, 7],
635            [0, 6],
636            [0, 5],
637            [0, 4],
638            [0, 3],
639            [0, 2],
640            [0, 1],
641            [0, 0]
642        ]
643
644        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
645
646    @test_tracker_info(uuid="117f404b-fb78-474a-86ba-209e6a54c9a8")
647    @TelephonyBaseTest.tel_test_wrap
648    def test_2lte_intra_freq_scell_away_close(self):
649        """ Test phone moving away from serving cell then close back while
650        neighbor Intra Freq cell stays the same power
651
652        Setup a two LTE cell configuration on MD8475A
653        Make Sure Phone is in LTE mode
654        Verify the reported RSSI follows the DL power change in MD8475A
655
656        Returns:
657            True if pass; False if fail
658        """
659        pcid = [0, 1]
660        init_pwr = -30  # initial DL power for all cells
661        power_seq = [
662            [-1, 0],  # power change sequence reference to init_pwr
663            [-2, 0],
664            [-3, 0],
665            [-4, 0],
666            [-5, 0],
667            [-6, 0],
668            [-7, 0],
669            [-8, 0],
670            [-9, 0],
671            [-10, 0],
672            [-9, 0],
673            [-8, 0],
674            [-7, 0],
675            [-6, 0],
676            [-5, 0],
677            [-4, 0],
678            [-3, 0],
679            [-2, 0],
680            [-1, 0],
681            [0, 0],
682            [1, 0],
683            [2, 0],
684            [3, 0],
685            [4, 0],
686            [3, 0],
687            [2, 0],
688            [1, 0],
689            [0, 0]
690        ]
691
692        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
693
694    @test_tracker_info(uuid="d1eec95f-40e9-4099-a669-9a88e56049ca")
695    @TelephonyBaseTest.tel_test_wrap
696    def test_2lte_intra_freq_ncell_away_close_2(self):
697        """ Test phone moving away from serving cell and close to neighbor
698        Intra Freq cell, then back and forth
699
700        Setup a two LTE cell configuration on MD8475A
701        Make Sure Phone is in LTE mode
702        Verify the reported RSSI follows the DL power change in MD8475A
703
704        Returns:
705            True if pass; False if fail
706        """
707        pcid = [0, 1]
708        init_pwr = -30  # initial DL power for all cells
709        power_seq = [
710            [-1, 1],  # power change sequence reference to init_pwr
711            [-2, 2],
712            [-3, 3],
713            [-4, 4],
714            [-5, 5],
715            [-4, 4],
716            [-3, 3],
717            [-2, 2],
718            [-1, 1],
719            [-0, 0],
720            [1, -1],
721            [2, -2],
722            [1, -1],
723            [0, 0]
724        ]
725
726        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
727
728    @test_tracker_info(uuid="c642a85b-4970-429c-81c4-f635392879be")
729    @TelephonyBaseTest.tel_test_wrap
730    def test_2lte_intra_freq_2cell_synced(self):
731        """ Test phone moving away and back to both serving cell and neighbor
732        Intra Freq cell
733
734        Setup a two LTE cell configuration on MD8475A
735        Make Sure Phone is in LTE mode
736        Verify the reported RSSI follows the DL power change in MD8475A and MG3710A
737
738        Returns:
739            True if pass; False if fail
740        """
741        pcid = [0, 1]
742        init_pwr = -30  # initial DL power for all cells
743        power_seq = [
744            [-1, -1],  # power change sequence reference to init_pwr
745            [-3, -3],
746            [-5, -5],
747            [-7, -7],
748            [-5, -5],
749            [-3, -3],
750            [-1, -1],
751            [1, 1],
752            [3, 3],
753            [5, 5],
754            [7, 7],
755            [3, 3],
756            [0, 0]
757        ]
758
759        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
760
761    @test_tracker_info(uuid="9144fab6-c7e1-4de2-a01d-7a15c117ec70")
762    @TelephonyBaseTest.tel_test_wrap
763    def test_3lte_intra_freq_scell_reversed(self):
764        """ Test phone moving away and back between 2 neighbor cells while maintain
765        same rssi with serving cell
766
767        Setup a two LTE cell configuration on MD8475A
768        Make Sure Phone is in LTE mode
769        Verify the reported RSSI follows the DL power change in MD8475A and MG3710A
770
771        Returns:
772            True if pass; False if fail
773        """
774        pcid = [0, 1, 2]
775        init_pwr = -30  # initial DL power for all cells
776        power_seq = [
777            [0, 1, -1],  # power change sequence reference to init_pwr
778            [0, 2, -2],
779            [0, 3, -3],
780            [0, 4, -4],
781            [0, 3, -3],
782            [0, 2, -2],
783            [0, 1, -1],
784            [0, 0, 0],
785            [0, -1, 1],
786            [0, -2, 2],
787            [0, -3, 3],
788            [0, -4, 4],
789            [0, -3, 3],
790            [0, -2, 2],
791            [0, -1, 1],
792            [0, 0, 0]
793        ]
794
795        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
796
797    @test_tracker_info(uuid="7bfbea72-e6fa-45ae-bf7e-b9b42063abe7")
798    @TelephonyBaseTest.tel_test_wrap
799    def test_3lte_intra_freq_3cell_synced(self):
800        """ Test phone moving away and back to both serving cell and neighbor
801        Intra Freq cell
802
803        Setup a two LTE cell configuration on MD8475A
804        Make Sure Phone is in LTE mode
805        Verify the reported RSSI follows the DL power change in MD8475A
806
807        Returns:
808            True if pass; False if fail
809        """
810        pcid = [0, 1, 2]
811        init_pwr = -30  # initial DL power for all cells
812        power_seq = [
813            [-1, -1, -1],  # power change sequence reference to init_pwr
814            [-3, -3, -3],
815            [-5, -5, -5],
816            [-7, -7, -7],
817            [-5, -5, -5],
818            [-3, -3, -3],
819            [-1, -1, -1],
820            [1, 1, 1],
821            [3, 3, 3],
822            [5, 5, 5],
823            [7, 7, 7],
824            [3, 3, 3],
825            [0, 0, 0]
826        ]
827
828        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
829
830    @test_tracker_info(uuid="b4577ae1-6435-4a15-9449-e02013dfb032")
831    @TelephonyBaseTest.tel_test_wrap
832    def test_ncells_intra_lte_0_cells(self):
833        """ Test Number of neighbor cells reported by Phone when no neighbor
834        cells are present (Phone camped on LTE)
835
836        Setup a single LTE cell configuration on MD8475A
837        Make Sure Phone is in LTE mode
838        Verify the number of neighbor cells reported by Phone
839
840        Returns:
841            True if pass; False if fail
842        """
843        serving_cell_cid = 11
844        serving_cell_pcid = 11
845        serving_cell_dlpower = -20
846        expected_cell_info_list = [
847            # Serving Cell
848            {
849                self.CID: serving_cell_cid,
850                self.PCID: serving_cell_pcid,
851                self.REPORT_RATE: 1,
852                self.IS_REGISTERED: True,
853                self.RAT: 'lte',
854                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
855                self.MAX_ERROR_RSSI: 3,
856                self.MAX_ERROR_AVERAGE_RSSI: 3
857            }
858        ]
859        expected_cell_info_stats = {}
860        for sample in expected_cell_info_list:
861            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
862
863        [bts1] = set_system_model_lte(self.md8475a, self.user_params,
864                                      self.ad.sim_card)
865        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
866                                     serving_cell_cid, serving_cell_pcid)
867        set_usim_parameters(self.md8475a, self.ad.sim_card)
868        self.md8475a.start_simulation()
869
870        if not ensure_network_rat(
871                self.log,
872                self.ad,
873                NETWORK_MODE_LTE_GSM_WCDMA,
874                RAT_FAMILY_LTE,
875                toggle_apm_after_setting=True):
876            self.log.error("Failed to set rat family {}, preferred network:{}".
877                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
878            return False
879        self.md8475a.wait_for_registration_state()
880        time.sleep(self._SETTLING_TIME)
881        return self._verify_cell_info(self.ad, expected_cell_info_stats)
882
883    @test_tracker_info(uuid="fe2cc07b-9676-41ab-b7ff-112d3ef84980")
884    @TelephonyBaseTest.tel_test_wrap
885    def test_ncells_intra_lte_1_cells(self):
886        """ Test Number of neighbor cells reported by Phone when one neighbor
887        cell is present (Phone camped on LTE)
888
889        Setup a two LTE cell configuration on MD8475A
890        Make Sure Phone is in LTE mode
891        Verify the number of neighbor cells reported by Phone
892
893        Returns:
894            True if pass; False if fail
895        """
896        serving_cell_cid = 11
897        serving_cell_pcid = 11
898        neigh_cell_cid = 22
899        neigh_cell_pcid = 22
900        serving_cell_dlpower = -20
901        neigh_cell_dlpower = -24
902
903        expected_cell_info_list = [
904            # Serving Cell
905            {
906                self.CID: serving_cell_cid,
907                self.PCID: serving_cell_pcid,
908                self.REPORT_RATE: 1,
909                self.IS_REGISTERED: True,
910                self.RAT: 'lte',
911                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
912                self.MAX_ERROR_RSSI: 3,
913                self.MAX_ERROR_AVERAGE_RSSI: 3
914            },
915            # Neighbor Cells
916            {
917                self.PCID: neigh_cell_pcid,
918                self.REPORT_RATE: 0.1,
919                self.IS_REGISTERED: False,
920                self.RAT: 'lte',
921                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_dlpower,
922                self.MAX_ERROR_RSSI: 4,
923                self.MAX_ERROR_AVERAGE_RSSI: 3
924            }
925        ]
926        expected_cell_info_stats = {}
927        for sample in expected_cell_info_list:
928            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
929
930        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
931                                                self.ad.sim_card)
932
933        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
934                                     serving_cell_cid, serving_cell_pcid)
935        self._setup_lte_neighbhor_cell_md8475a(bts2, LTE_BAND_2,
936                                               neigh_cell_dlpower,
937                                               neigh_cell_cid, neigh_cell_pcid)
938        set_usim_parameters(self.md8475a, self.ad.sim_card)
939        self.md8475a.send_command("IMSSTARTVN 1")
940        self.md8475a.start_simulation()
941        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
942
943        if not ensure_network_rat(
944                self.log,
945                self.ad,
946                NETWORK_MODE_LTE_GSM_WCDMA,
947                RAT_FAMILY_LTE,
948                toggle_apm_after_setting=True):
949            self.log.error("Failed to set rat family {}, preferred network:{}".
950                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
951            return False
952        self.md8475a.wait_for_registration_state()
953        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
954        self.log.info("Wait for {} seconds to settle".format(
955            self._SETTLING_TIME))
956        time.sleep(self._SETTLING_TIME)
957        return self._verify_cell_info(self.ad, expected_cell_info_stats)
958
959    @test_tracker_info(uuid="8abc7903-4ea7-407a-946b-455d7f767c3e")
960    @TelephonyBaseTest.tel_test_wrap
961    def test_ncells_intra_lte_2_cells(self):
962        """ Test Number of neighbor cells reported by Phone when two neighbor
963        cells are present (Phone camped on LTE)
964
965        Setup a two LTE cell configuration on MD8475A
966        Setup one waveform on MG3710A
967        Make Sure Phone is in LTE mode
968        Verify the number of neighbor cells reported by Phone
969
970        Returns:
971            True if pass; False if fail
972        """
973        serving_cell_cid = 11
974        serving_cell_pcid = 11
975        neigh_cell_1_cid = 22
976        neigh_cell_1_pcid = 22
977        neigh_cell_2_cid = 1
978        neigh_cell_2_pcid = 1
979        serving_cell_dlpower = -20
980        neigh_cell_1_dlpower = -24
981        neigh_cell_2_dlpower = -23
982
983        expected_cell_info_list = [
984            # Serving Cell
985            {
986                self.CID: serving_cell_cid,
987                self.PCID: serving_cell_pcid,
988                self.REPORT_RATE: 1,
989                self.IS_REGISTERED: True,
990                self.RAT: 'lte',
991                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
992                self.MAX_ERROR_RSSI: 3,
993                self.MAX_ERROR_AVERAGE_RSSI: 3
994            },
995            # Neighbor Cells
996            {
997                self.PCID: neigh_cell_1_pcid,
998                self.REPORT_RATE: 0.1,
999                self.IS_REGISTERED: False,
1000                self.RAT: 'lte',
1001                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1002                self.MAX_ERROR_RSSI: 4,
1003                self.MAX_ERROR_AVERAGE_RSSI: 3
1004            },
1005            {
1006                self.PCID: neigh_cell_2_pcid,
1007                self.REPORT_RATE: 0.1,
1008                self.IS_REGISTERED: False,
1009                self.RAT: 'lte',
1010                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1011                self.MAX_ERROR_RSSI: 4,
1012                self.MAX_ERROR_AVERAGE_RSSI: 3
1013            }
1014        ]
1015        expected_cell_info_stats = {}
1016        for sample in expected_cell_info_list:
1017            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1018
1019        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1020                                                self.ad.sim_card)
1021
1022        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1023                                     serving_cell_cid, serving_cell_pcid)
1024        self._setup_lte_neighbhor_cell_md8475a(
1025            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1026            neigh_cell_1_pcid)
1027        set_usim_parameters(self.md8475a, self.ad.sim_card)
1028        self.md8475a.start_simulation()
1029        if not ensure_network_rat(
1030                self.log,
1031                self.ad,
1032                NETWORK_MODE_LTE_GSM_WCDMA,
1033                RAT_FAMILY_LTE,
1034                toggle_apm_after_setting=True):
1035            self.log.error("Failed to set rat family {}, preferred network:{}".
1036                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1037            return False
1038        self.md8475a.wait_for_registration_state()
1039
1040        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1041                                  "LTE", "10M_B1_CID1")
1042        self.turn_on_3710a_sg(1)
1043        time.sleep(self._SETTLING_TIME)
1044        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1045
1046    @test_tracker_info(uuid="623b3d16-bc48-4353-abc3-054ca6351a97")
1047    @TelephonyBaseTest.tel_test_wrap
1048    def test_ncells_intra_lte_3_cells(self):
1049        """ Test Number of neighbor cells reported by Phone when three neighbor
1050        cells are present (Phone camped on LTE)
1051
1052        Setup two LTE cell configuration on MD8475A
1053        Setup two waveform on MG3710A
1054        Make Sure Phone is in LTE mode
1055        Verify the number of neighbor cells reported by Phone
1056
1057        Returns:
1058            True if pass; False if fail
1059        """
1060        serving_cell_cid = 11
1061        serving_cell_pcid = 11
1062        neigh_cell_1_cid = 1
1063        neigh_cell_1_pcid = 1
1064        neigh_cell_2_cid = 2
1065        neigh_cell_2_pcid = 2
1066        neigh_cell_3_cid = 3
1067        neigh_cell_3_pcid = 3
1068        serving_cell_dlpower = -20
1069        neigh_cell_1_dlpower = -24
1070        neigh_cell_2_dlpower = -22
1071        neigh_cell_3_dlpower = -23
1072
1073        expected_cell_info_list = [
1074            # Serving Cell
1075            {
1076                self.CID: serving_cell_cid,
1077                self.PCID: serving_cell_pcid,
1078                self.REPORT_RATE: 1,
1079                self.IS_REGISTERED: True,
1080                self.RAT: 'lte',
1081                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
1082                self.MAX_ERROR_RSSI: 3,
1083                self.MAX_ERROR_AVERAGE_RSSI: 3
1084            },
1085            # Neighbor Cells
1086            {
1087                self.PCID: neigh_cell_1_pcid,
1088                self.REPORT_RATE: 0.1,
1089                self.IS_REGISTERED: False,
1090                self.RAT: 'lte',
1091                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1092                self.MAX_ERROR_RSSI: 4,
1093                self.MAX_ERROR_AVERAGE_RSSI: 3
1094            },
1095            {
1096                self.PCID: neigh_cell_2_pcid,
1097                self.REPORT_RATE: 0.1,
1098                self.IS_REGISTERED: False,
1099                self.RAT: 'lte',
1100                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1101                self.MAX_ERROR_RSSI: 4,
1102                self.MAX_ERROR_AVERAGE_RSSI: 3
1103            },
1104            {
1105                self.PCID: neigh_cell_3_pcid,
1106                self.REPORT_RATE: 0.1,
1107                self.IS_REGISTERED: False,
1108                self.RAT: 'lte',
1109                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_3_dlpower,
1110                self.MAX_ERROR_RSSI: 4,
1111                self.MAX_ERROR_AVERAGE_RSSI: 3
1112            }
1113        ]
1114        expected_cell_info_stats = {}
1115        for sample in expected_cell_info_list:
1116            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1117        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1118                                                self.ad.sim_card)
1119        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1120                                     serving_cell_cid, serving_cell_pcid)
1121
1122        self._setup_lte_neighbhor_cell_md8475a(
1123            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1124            neigh_cell_1_pcid)
1125        set_usim_parameters(self.md8475a, self.ad.sim_card)
1126        self.md8475a.start_simulation()
1127        if not ensure_network_rat(
1128                self.log,
1129                self.ad,
1130                NETWORK_MODE_LTE_GSM_WCDMA,
1131                RAT_FAMILY_LTE,
1132                toggle_apm_after_setting=True):
1133            self.log.error("Failed to set rat family {}, preferred network:{}".
1134                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1135            return False
1136        self.md8475a.wait_for_registration_state()
1137
1138        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1139                                  "LTE", "10M_B1_CID2")
1140
1141        self.setup_3710a_waveform("1", "B", "1960MHZ", neigh_cell_3_dlpower,
1142                                  "LTE", "10M_B1_CID3")
1143        self.turn_on_3710a_sg(1)
1144        time.sleep(self._SETTLING_TIME)
1145        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1146
1147    @test_tracker_info(uuid="3e094e3d-e7b7-447a-9a7a-8060c5b17e88")
1148    @TelephonyBaseTest.tel_test_wrap
1149    def test_ncells_intra_lte_4_cells(self):
1150        """ Test Number of neighbor cells reported by Phone when four neighbor
1151        cells are present (Phone camped on LTE)
1152
1153        Setup two LTE cell configuration on MD8475A
1154        Setup three waveform on MG3710A
1155        Make Sure Phone is in LTE mode
1156        Verify the number of neighbor cells reported by Phone
1157
1158        Returns:
1159            True if pass; False if fail
1160        """
1161        serving_cell_cid = 11
1162        serving_cell_pcid = 11
1163        neigh_cell_1_cid = 1
1164        neigh_cell_1_pcid = 1
1165        neigh_cell_2_cid = 2
1166        neigh_cell_2_pcid = 2
1167        neigh_cell_3_cid = 3
1168        neigh_cell_3_pcid = 3
1169        neigh_cell_4_cid = 5
1170        neigh_cell_4_pcid = 5
1171        serving_cell_dlpower = -20
1172        neigh_cell_1_dlpower = -24
1173        neigh_cell_2_dlpower = -22
1174        neigh_cell_3_dlpower = -24
1175        neigh_cell_4_dlpower = -22
1176
1177        expected_cell_info_list = [
1178            # Serving Cell
1179            {
1180                self.CID: serving_cell_cid,
1181                self.PCID: serving_cell_pcid,
1182                self.REPORT_RATE: 1,
1183                self.IS_REGISTERED: True,
1184                self.RAT: 'lte',
1185                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
1186                self.MAX_ERROR_RSSI: 3,
1187                self.MAX_ERROR_AVERAGE_RSSI: 3
1188            },
1189            # Neighbor Cells
1190            {
1191                self.PCID: neigh_cell_1_pcid,
1192                self.REPORT_RATE: 0.1,
1193                self.IS_REGISTERED: False,
1194                self.RAT: 'lte',
1195                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1196                self.MAX_ERROR_RSSI: 4,
1197                self.MAX_ERROR_AVERAGE_RSSI: 3
1198            },
1199            {
1200                self.PCID: neigh_cell_2_pcid,
1201                self.REPORT_RATE: 0.1,
1202                self.IS_REGISTERED: False,
1203                self.RAT: 'lte',
1204                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1205                self.MAX_ERROR_RSSI: 4,
1206                self.MAX_ERROR_AVERAGE_RSSI: 3
1207            },
1208            {
1209                self.PCID: neigh_cell_3_pcid,
1210                self.REPORT_RATE: 0.1,
1211                self.IS_REGISTERED: False,
1212                self.RAT: 'lte',
1213                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_3_dlpower,
1214                self.MAX_ERROR_RSSI: 4,
1215                self.MAX_ERROR_AVERAGE_RSSI: 3
1216            },
1217            {
1218                self.PCID: neigh_cell_4_pcid,
1219                self.REPORT_RATE: 0.1,
1220                self.IS_REGISTERED: False,
1221                self.RAT: 'lte',
1222                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_4_dlpower,
1223                self.MAX_ERROR_RSSI: 4,
1224                self.MAX_ERROR_AVERAGE_RSSI: 3
1225            }
1226        ]
1227        expected_cell_info_stats = {}
1228        for sample in expected_cell_info_list:
1229            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1230
1231        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1232                                                self.ad.sim_card)
1233        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1234                                     serving_cell_cid, serving_cell_pcid)
1235
1236        self._setup_lte_neighbhor_cell_md8475a(
1237            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1238            neigh_cell_1_pcid)
1239        set_usim_parameters(self.md8475a, self.ad.sim_card)
1240        self.md8475a.start_simulation()
1241
1242        if not ensure_network_rat(
1243                self.log,
1244                self.ad,
1245                NETWORK_MODE_LTE_GSM_WCDMA,
1246                RAT_FAMILY_LTE,
1247                toggle_apm_after_setting=True):
1248            self.log.error("Failed to set rat family {}, preferred network:{}".
1249                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1250            return False
1251        self.md8475a.wait_for_registration_state()
1252
1253        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1254                                  "LTE", "10M_B1_CID2")
1255
1256        self.setup_3710a_waveform("1", "B", "1960MHZ", neigh_cell_3_dlpower,
1257                                  "LTE", "10M_B1_CID3")
1258
1259        self.setup_3710a_waveform("2", "A", "1960MHZ", neigh_cell_4_dlpower,
1260                                  "LTE", "10M_B1_CID5")
1261        self.turn_on_3710a_sg(1)
1262        self.turn_on_3710a_sg(2)
1263        time.sleep(self._SETTLING_TIME)
1264
1265        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1266
1267    @test_tracker_info(uuid="7e9a9c30-9284-4440-b85e-f94b83e0373f")
1268    @TelephonyBaseTest.tel_test_wrap
1269    def test_neighbor_cell_reporting_lte_intrafreq_0_tmo(self):
1270        """ Test Number of neighbor cells reported by Phone when no neighbor
1271        cells are present (Phone camped on LTE)
1272
1273        Setup a single LTE cell configuration on MD8475A
1274        Make Sure Phone is in LTE mode
1275        Verify the number of neighbor cells reported by Phone
1276
1277        Returns:
1278            True if pass; False if fail
1279        """
1280        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1281        serving_cell['power'] = -20
1282
1283        expected_cell_info_list = [
1284            # Serving Cell
1285            {
1286                self.CID: serving_cell[self.CID],
1287                self.PCID: serving_cell[self.PCID],
1288                self.REPORT_RATE: 1,
1289                self.IS_REGISTERED: True,
1290                self.RAT: 'lte',
1291                self.TARGET_RSSI:
1292                self._LTE_RSSI_OFFSET + serving_cell['power'],
1293                self.MAX_ERROR_RSSI: 3,
1294                self.MAX_ERROR_AVERAGE_RSSI: 3
1295            }
1296        ]
1297
1298        expected_cell_info_stats = {}
1299        for sample in expected_cell_info_list:
1300            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1301
1302        [bts1] = set_system_model_lte(self.md8475a, self.user_params,
1303                                      self.ad.sim_card)
1304        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1305        set_usim_parameters(self.md8475a, self.ad.sim_card)
1306        self.md8475a.start_simulation()
1307
1308        if not ensure_network_rat(
1309                self.log,
1310                self.ad,
1311                NETWORK_MODE_LTE_GSM_WCDMA,
1312                RAT_FAMILY_LTE,
1313                toggle_apm_after_setting=True):
1314            self.log.error("Failed to set rat family {}, preferred network:{}".
1315                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1316            return False
1317        self.md8475a.wait_for_registration_state()
1318        time.sleep(self._SETTLING_TIME)
1319        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1320
1321    @test_tracker_info(uuid="13bd7000-5a45-43f5-9e54-001e0aa09262")
1322    @TelephonyBaseTest.tel_test_wrap
1323    def test_neighbor_cell_reporting_lte_intrafreq_1_tmo(self):
1324        """ Test Number of neighbor cells reported by Phone when one neighbor
1325        cell is present (Phone camped on LTE)
1326
1327        Setup a two LTE cell configuration on MD8475A
1328        Make Sure Phone is in LTE mode
1329        Verify the number of neighbor cells reported by Phone
1330
1331        Returns:
1332            True if pass; False if fail
1333        """
1334        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1335        neighbor_cell = lte_band4_ch2000_fr2115_pcid2_cell
1336        serving_cell['power'] = -20
1337        neighbor_cell['power'] = -24
1338        expected_cell_info_list = [
1339            # Serving Cell
1340            {
1341                self.CID: serving_cell[self.CID],
1342                self.PCID: serving_cell[self.PCID],
1343                self.REPORT_RATE: 1,
1344                self.IS_REGISTERED: True,
1345                self.RAT: 'lte',
1346                self.TARGET_RSSI:
1347                self._LTE_RSSI_OFFSET + serving_cell['power'],
1348                self.MAX_ERROR_RSSI: 3,
1349                self.MAX_ERROR_AVERAGE_RSSI: 3
1350            },
1351            # Neighbor Cells
1352            {
1353                self.PCID: neighbor_cell[self.PCID],
1354                self.REPORT_RATE: 0.1,
1355                self.IS_REGISTERED: False,
1356                self.RAT: 'lte',
1357                self.TARGET_RSSI:
1358                self._LTE_RSSI_OFFSET + neighbor_cell['power'],
1359                self.MAX_ERROR_RSSI: 4,
1360                self.MAX_ERROR_AVERAGE_RSSI: 3
1361            }
1362        ]
1363        expected_cell_info_stats = {}
1364        for sample in expected_cell_info_list:
1365            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1366
1367        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1368        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1369                                                self.ad.sim_card)
1370        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1371        self._setup_lte_cell_md8475a(bts2, neighbor_cell,
1372                                     neighbor_cell['power'])
1373        bts1.neighbor_cell_mode = "USERDATA"
1374        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1375        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1376        set_usim_parameters(self.md8475a, self.ad.sim_card)
1377        self.md8475a.start_simulation()
1378        # To make sure phone camps on BTS1
1379        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1380
1381        if not ensure_network_rat(
1382                self.log,
1383                self.ad,
1384                NETWORK_MODE_LTE_GSM_WCDMA,
1385                RAT_FAMILY_LTE,
1386                toggle_apm_after_setting=True):
1387            self.log.error("Failed to set rat family {}, preferred network:{}".
1388                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1389            return False
1390        self.md8475a.wait_for_registration_state()
1391        time.sleep(self._ANRITSU_SETTLING_TIME)
1392        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1393        time.sleep(self._SETTLING_TIME)
1394        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1395
1396    @test_tracker_info(uuid="5dca3a16-73a0-448a-a35d-22ebd253a570")
1397    @TelephonyBaseTest.tel_test_wrap
1398    def test_neighbor_cell_reporting_lte_intrafreq_2_tmo(self):
1399        """ Test Number of neighbor cells reported by Phone when two neighbor
1400        cells are present (Phone camped on LTE)
1401
1402        Setup one LTE cell configuration on MD8475A
1403        Setup two waveform on MG3710A
1404        Make Sure Phone is in LTE mode
1405        Verify the number of neighbor cells reported by Phone
1406
1407        Returns:
1408            True if pass; False if fail
1409        """
1410        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1411        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid2_cell
1412        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid3_cell
1413        serving_cell['power'] = -20
1414        neighbor_cell_1['power'] = -24
1415        neighbor_cell_2['power'] = -23
1416
1417        expected_cell_info_list = [
1418            # Serving Cell
1419            {
1420                self.CID: serving_cell[self.CID],
1421                self.PCID: serving_cell[self.PCID],
1422                self.REPORT_RATE: 1,
1423                self.IS_REGISTERED: True,
1424                self.RAT: 'lte',
1425                self.TARGET_RSSI:
1426                self._LTE_RSSI_OFFSET + serving_cell['power'],
1427                self.MAX_ERROR_RSSI: 3,
1428                self.MAX_ERROR_AVERAGE_RSSI: 3
1429            },
1430            # Neighbor Cells
1431            {
1432                self.PCID: neighbor_cell_1[self.PCID],
1433                self.REPORT_RATE: 0.1,
1434                self.IS_REGISTERED: False,
1435                self.RAT: 'lte',
1436                self.TARGET_RSSI:
1437                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1438                self.MAX_ERROR_RSSI: 4,
1439                self.MAX_ERROR_AVERAGE_RSSI: 3
1440            },
1441            {
1442                self.PCID: neighbor_cell_2[self.PCID],
1443                self.REPORT_RATE: 0.1,
1444                self.IS_REGISTERED: False,
1445                self.RAT: 'lte',
1446                self.TARGET_RSSI:
1447                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1448                self.MAX_ERROR_RSSI: 4,
1449                self.MAX_ERROR_AVERAGE_RSSI: 3
1450            }
1451        ]
1452        expected_cell_info_stats = {}
1453        for sample in expected_cell_info_list:
1454            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1455
1456        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1457        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1458                                                self.ad.sim_card)
1459        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1460        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1461                                     neighbor_cell_1['power'])
1462        bts1.neighbor_cell_mode = "USERDATA"
1463        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1464        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1465        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1466        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2000_F2115_PCID3")
1467        set_usim_parameters(self.md8475a, self.ad.sim_card)
1468        self.md8475a.start_simulation()
1469        # To make sure phone camps on BTS1
1470        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1471
1472        if not ensure_network_rat(
1473                self.log,
1474                self.ad,
1475                NETWORK_MODE_LTE_GSM_WCDMA,
1476                RAT_FAMILY_LTE,
1477                toggle_apm_after_setting=True):
1478            self.log.error("Failed to set rat family {}, preferred network:{}".
1479                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1480            return False
1481        self.md8475a.wait_for_registration_state()
1482        time.sleep(self._ANRITSU_SETTLING_TIME)
1483        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1484        self.setup_3710a_waveform("1", "A", "2115MHz",
1485                                  neighbor_cell_2['power'], "LTE",
1486                                  "lte_4_ch2000_pcid3")
1487        self.turn_on_3710a_sg(1)
1488        time.sleep(self._SETTLING_TIME)
1489        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1490
1491    @test_tracker_info(uuid="860152de-8aa0-422e-b5b0-28bf244076f4")
1492    @TelephonyBaseTest.tel_test_wrap
1493    def test_neighbor_cell_reporting_lte_intrafreq_3_tmo(self):
1494        """ Test Number of neighbor cells reported by Phone when three neighbor
1495        cells are present (Phone camped on LTE)
1496
1497        Setup a one LTE cell configuration on MD8475A
1498        Setup three waveforms on MG3710A
1499        Make Sure Phone is in LTE mode
1500        Verify the number of neighbor cells reported by Phone
1501
1502        Returns:
1503            True if pass; False if fail
1504        """
1505        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1506        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid2_cell
1507        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid3_cell
1508        neighbor_cell_3 = lte_band4_ch2000_fr2115_pcid4_cell
1509        serving_cell['power'] = -20
1510        neighbor_cell_1['power'] = -24
1511        neighbor_cell_2['power'] = -23
1512        neighbor_cell_3['power'] = -22
1513
1514        expected_cell_info_list = [
1515            # Serving Cell
1516            {
1517                self.CID: serving_cell[self.CID],
1518                self.PCID: serving_cell[self.PCID],
1519                self.REPORT_RATE: 1,
1520                self.IS_REGISTERED: True,
1521                self.RAT: 'lte',
1522                self.TARGET_RSSI:
1523                self._LTE_RSSI_OFFSET + serving_cell['power'],
1524                self.MAX_ERROR_RSSI: 3,
1525                self.MAX_ERROR_AVERAGE_RSSI: 3
1526            },
1527            # Neighbor Cells
1528            {
1529                self.PCID: neighbor_cell_1[self.PCID],
1530                self.REPORT_RATE: 0.1,
1531                self.IS_REGISTERED: False,
1532                self.RAT: 'lte',
1533                self.TARGET_RSSI:
1534                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1535                self.MAX_ERROR_RSSI: 4,
1536                self.MAX_ERROR_AVERAGE_RSSI: 3
1537            },
1538            {
1539                self.PCID: neighbor_cell_2[self.PCID],
1540                self.REPORT_RATE: 0.1,
1541                self.IS_REGISTERED: False,
1542                self.RAT: 'lte',
1543                self.TARGET_RSSI:
1544                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1545                self.MAX_ERROR_RSSI: 4,
1546                self.MAX_ERROR_AVERAGE_RSSI: 3
1547            },
1548            {
1549                self.PCID: neighbor_cell_3[self.PCID],
1550                self.REPORT_RATE: 0.1,
1551                self.IS_REGISTERED: False,
1552                self.RAT: 'lte',
1553                self.TARGET_RSSI:
1554                self._LTE_RSSI_OFFSET + neighbor_cell_3['power'],
1555                self.MAX_ERROR_RSSI: 4,
1556                self.MAX_ERROR_AVERAGE_RSSI: 3
1557            }
1558        ]
1559        expected_cell_info_stats = {}
1560        for sample in expected_cell_info_list:
1561            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1562
1563        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1564        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1565                                                self.ad.sim_card)
1566        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1567        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1568                                     neighbor_cell_1['power'])
1569        bts1.neighbor_cell_mode = "USERDATA"
1570        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1571        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1572        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1573        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2000_F2115_PCID3")
1574        bts1.set_neighbor_cell_type("LTE", 3, "CELLNAME")
1575        bts1.set_neighbor_cell_name("LTE", 3, "LTE_4_C2000_F2115_PCID4")
1576        set_usim_parameters(self.md8475a, self.ad.sim_card)
1577        self.md8475a.start_simulation()
1578        # To make sure phone camps on BTS1
1579        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1580
1581        if not ensure_network_rat(
1582                self.log,
1583                self.ad,
1584                NETWORK_MODE_LTE_GSM_WCDMA,
1585                RAT_FAMILY_LTE,
1586                toggle_apm_after_setting=True):
1587            self.log.error("Failed to set rat family {}, preferred network:{}".
1588                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1589            return False
1590        self.md8475a.wait_for_registration_state()
1591        time.sleep(self._ANRITSU_SETTLING_TIME)
1592        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1593        self.setup_3710a_waveform("1", "A", "2115MHz",
1594                                  neighbor_cell_2['power'], "LTE",
1595                                  "lte_4_ch2000_pcid3")
1596
1597        self.setup_3710a_waveform("1", "B", "2115MHz",
1598                                  neighbor_cell_3['power'], "LTE",
1599                                  "lte_4_ch2000_pcid4")
1600        self.turn_on_3710a_sg(1)
1601        time.sleep(self._SETTLING_TIME)
1602        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1603
1604    @test_tracker_info(uuid="8c5b63ba-1322-47b6-adce-5224cbc0995a")
1605    @TelephonyBaseTest.tel_test_wrap
1606    def test_neighbor_cell_reporting_lte_interfreq_1_tmo(self):
1607        """ Test Number of neighbor cells reported by Phone when two neighbor
1608        cells(inter frequency) are present (Phone camped on LTE)
1609
1610        Setup a a LTE cell configuration on MD8475A
1611        Setup two LTE waveforms(inter frequency) on MG3710A
1612        Make Sure Phone is in LTE mode
1613        Verify the number of neighbor cells reported by Phone
1614
1615        Returns:
1616            True if pass; False if fail
1617        """
1618        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1619        neighbor_cell_1 = lte_band4_ch2050_fr2120_pcid7_cell
1620        serving_cell['power'] = -20
1621        neighbor_cell_1['power'] = -23
1622        expected_cell_info_list = [
1623            # Serving Cell
1624            {
1625                self.CID: serving_cell[self.CID],
1626                self.PCID: serving_cell[self.PCID],
1627                self.REPORT_RATE: 1,
1628                self.IS_REGISTERED: True,
1629                self.RAT: 'lte',
1630                self.TARGET_RSSI:
1631                self._LTE_RSSI_OFFSET + serving_cell['power'],
1632                self.MAX_ERROR_RSSI: 3,
1633                self.MAX_ERROR_AVERAGE_RSSI: 3
1634            },
1635            # Neighbor Cells
1636            {
1637                self.PCID: neighbor_cell_1[self.PCID],
1638                self.REPORT_RATE: 0.1,
1639                self.IS_REGISTERED: False,
1640                self.RAT: 'lte',
1641                self.TARGET_RSSI:
1642                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1643                self.MAX_ERROR_RSSI: 4,
1644                self.MAX_ERROR_AVERAGE_RSSI: 3
1645            }
1646        ]
1647        expected_cell_info_stats = {}
1648        for sample in expected_cell_info_list:
1649            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1650
1651        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1652        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1653                                                self.ad.sim_card)
1654        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1655        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1656                                     neighbor_cell_1['power'])
1657        bts1.neighbor_cell_mode = "USERDATA"
1658        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1659        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2050_F2120_PCID7")
1660        set_usim_parameters(self.md8475a, self.ad.sim_card)
1661        self.md8475a.start_simulation()
1662        # To make sure phone camps on BTS1
1663        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1664
1665        self.ad.droid.telephonyToggleDataConnection(False)
1666        if not ensure_network_rat(
1667                self.log,
1668                self.ad,
1669                NETWORK_MODE_LTE_GSM_WCDMA,
1670                RAT_FAMILY_LTE,
1671                toggle_apm_after_setting=True):
1672            self.log.error("Failed to set rat family {}, preferred network:{}".
1673                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1674            return False
1675        self.md8475a.wait_for_registration_state()
1676        time.sleep(self._ANRITSU_SETTLING_TIME)
1677        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1678        time.sleep(self._ANRITSU_SETTLING_TIME)
1679        self.md8475a.set_packet_preservation()
1680        time.sleep(self._SETTLING_TIME)
1681        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1682
1683    @test_tracker_info(uuid="97853501-a328-4706-bb3f-c5e708b1ccb8")
1684    @TelephonyBaseTest.tel_test_wrap
1685    def test_neighbor_cell_reporting_lte_interfreq_2_tmo(self):
1686        """ Test Number of neighbor cells reported by Phone when two neighbor
1687        cells(inter frequency) are present (Phone camped on LTE)
1688
1689        Setup a a LTE cell configuration on MD8475A
1690        Setup two LTE waveforms(inter frequency) on MG3710A
1691        Make Sure Phone is in LTE mode
1692        Verify the number of neighbor cells reported by Phone
1693
1694        Returns:
1695            True if pass; False if fail
1696        """
1697        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1698        neighbor_cell_1 = lte_band4_ch2050_fr2120_pcid7_cell
1699        neighbor_cell_2 = lte_band4_ch2250_fr2140_pcid8_cell
1700        serving_cell['power'] = -20
1701        neighbor_cell_1['power'] = -23
1702        neighbor_cell_2['power'] = -22
1703
1704        expected_cell_info_list = [
1705            # Serving Cell
1706            {
1707                self.CID: serving_cell[self.CID],
1708                self.PCID: serving_cell[self.PCID],
1709                self.REPORT_RATE: 1,
1710                self.IS_REGISTERED: True,
1711                self.RAT: 'lte',
1712                self.TARGET_RSSI:
1713                self._LTE_RSSI_OFFSET + serving_cell['power'],
1714                self.MAX_ERROR_RSSI: 3,
1715                self.MAX_ERROR_AVERAGE_RSSI: 3
1716            },
1717            # Neighbor Cells
1718            {
1719                self.PCID: neighbor_cell_1[self.PCID],
1720                self.REPORT_RATE: 0.1,
1721                self.IS_REGISTERED: False,
1722                self.RAT: 'lte',
1723                self.TARGET_RSSI:
1724                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1725                self.MAX_ERROR_RSSI: 4,
1726                self.MAX_ERROR_AVERAGE_RSSI: 3
1727            },
1728            {
1729                self.PCID: neighbor_cell_2[self.PCID],
1730                self.REPORT_RATE: 0.1,
1731                self.IS_REGISTERED: False,
1732                self.RAT: 'lte',
1733                self.TARGET_RSSI:
1734                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1735                self.MAX_ERROR_RSSI: 4,
1736                self.MAX_ERROR_AVERAGE_RSSI: 3
1737            }
1738        ]
1739        expected_cell_info_stats = {}
1740        for sample in expected_cell_info_list:
1741            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1742
1743        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1744        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1745                                                self.ad.sim_card)
1746        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1747        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1748                                     neighbor_cell_1['power'])
1749        bts1.neighbor_cell_mode = "USERDATA"
1750        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1751        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2050_F2120_PCID7")
1752        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1753        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2250_F2140_PCID8")
1754        set_usim_parameters(self.md8475a, self.ad.sim_card)
1755        self.md8475a.start_simulation()
1756        # To make sure phone camps on BTS1
1757        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1758
1759        self.ad.droid.telephonyToggleDataConnection(False)
1760        if not ensure_network_rat(
1761                self.log,
1762                self.ad,
1763                NETWORK_MODE_LTE_GSM_WCDMA,
1764                RAT_FAMILY_LTE,
1765                toggle_apm_after_setting=True):
1766            self.log.error("Failed to set rat family {}, preferred network:{}".
1767                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1768            return False
1769        self.md8475a.wait_for_registration_state()
1770        time.sleep(self._ANRITSU_SETTLING_TIME)
1771        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1772        time.sleep(self._ANRITSU_SETTLING_TIME)
1773        self.setup_3710a_waveform("1", "A", "2140MHz",
1774                                  neighbor_cell_2['power'], "LTE",
1775                                  "lte_4_ch2250_pcid8")
1776
1777        self.turn_on_3710a_sg(1)
1778        self.md8475a.set_packet_preservation()
1779        time.sleep(self._SETTLING_TIME)
1780        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1781
1782    @test_tracker_info(uuid="74bd528c-e1c5-476d-9ee0-ebfc7bbc5de1")
1783    @TelephonyBaseTest.tel_test_wrap
1784    def test_neighbor_cell_reporting_lte_interband_2_tmo(self):
1785        """ Test Number of neighbor cells reported by Phone when two neighbor
1786        cells(inter band) are present (Phone camped on LTE)
1787
1788        Setup one LTE cell configuration on MD8475A
1789        Setup two LTE waveforms((inter band)) on MG3710A
1790        Make Sure Phone is in LTE mode
1791        Verify the number of neighbor cells reported by Phone
1792
1793        Returns:
1794            True if pass; False if fail
1795        """
1796        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1797        neighbor_cell_1 = lte_band2_ch900_fr1960_pcid9_cell
1798        neighbor_cell_2 = lte_band12_ch5095_fr737_pcid10_cell
1799        serving_cell['power'] = -20
1800        neighbor_cell_1['power'] = -24
1801        neighbor_cell_2['power'] = -22
1802
1803        expected_cell_info_list = [
1804            # Serving Cell
1805            {
1806                self.CID: serving_cell[self.CID],
1807                self.PCID: serving_cell[self.PCID],
1808                self.REPORT_RATE: 1,
1809                self.IS_REGISTERED: True,
1810                self.RAT: 'lte',
1811                self.TARGET_RSSI:
1812                self._LTE_RSSI_OFFSET + serving_cell['power'],
1813                self.MAX_ERROR_RSSI: 3,
1814                self.MAX_ERROR_AVERAGE_RSSI: 3
1815            },
1816            # Neighbor Cells
1817            {
1818                self.PCID: neighbor_cell_1[self.PCID],
1819                self.REPORT_RATE: 0.1,
1820                self.IS_REGISTERED: False,
1821                self.RAT: 'lte',
1822                self.TARGET_RSSI:
1823                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1824                self.MAX_ERROR_RSSI: 4,
1825                self.MAX_ERROR_AVERAGE_RSSI: 3
1826            },
1827            {
1828                self.PCID: neighbor_cell_2[self.PCID],
1829                self.REPORT_RATE: 0.1,
1830                self.IS_REGISTERED: False,
1831                self.RAT: 'lte',
1832                self.TARGET_RSSI:
1833                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1834                self.MAX_ERROR_RSSI: 4,
1835                self.MAX_ERROR_AVERAGE_RSSI: 3
1836            }
1837        ]
1838        expected_cell_info_stats = {}
1839        for sample in expected_cell_info_list:
1840            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1841
1842        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1843        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1844                                                self.ad.sim_card)
1845        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1846        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1847                                     neighbor_cell_1['power'])
1848        bts1.neighbor_cell_mode = "USERDATA"
1849        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1850        bts1.set_neighbor_cell_name("LTE", 1, "LTE_2_C900_F1960_PCID9")
1851        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1852        bts1.set_neighbor_cell_name("LTE", 2, "LTE_12_C5095_F737_PCID10")
1853        set_usim_parameters(self.md8475a, self.ad.sim_card)
1854        self.md8475a.start_simulation()
1855        # To make sure phone camps on BTS1
1856        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1857
1858        self.ad.droid.telephonyToggleDataConnection(False)
1859        if not ensure_network_rat(
1860                self.log,
1861                self.ad,
1862                NETWORK_MODE_LTE_GSM_WCDMA,
1863                RAT_FAMILY_LTE,
1864                toggle_apm_after_setting=True):
1865            self.log.error("Failed to set rat family {}, preferred network:{}".
1866                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1867            return False
1868        self.md8475a.wait_for_registration_state()
1869        time.sleep(self._ANRITSU_SETTLING_TIME)
1870        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1871        self.setup_3710a_waveform("1", "A", "737.5MHz",
1872                                  neighbor_cell_2['power'], "LTE",
1873                                  "lte_12_ch5095_pcid10")
1874        self.turn_on_3710a_sg(1)
1875        time.sleep(self._ANRITSU_SETTLING_TIME)
1876        self.md8475a.set_packet_preservation()
1877        time.sleep(self._SETTLING_TIME)
1878        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1879
1880    @test_tracker_info(uuid="6289e3e4-9316-4b82-bd0b-dde53f26da0d")
1881    @TelephonyBaseTest.tel_test_wrap
1882    def test_neighbor_cell_reporting_lte_interrat_1_tmo(self):
1883        """ Test Number of neighbor cells reported by Phone when two neighbor
1884        cells(inter RAT) are present (Phone camped on LTE)
1885
1886        Setup one LTE and one WCDMA cell configuration on MD8475A
1887        Setup one GSM waveform on MG3710A
1888        Make Sure Phone is in LTE mode
1889        Verify the number of neighbor cells reported by Phone
1890
1891        Returns:
1892            True if pass; False if fail
1893        """
1894        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1895        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid31_cell
1896        serving_cell['power'] = -20
1897        neighbor_cell_1['power'] = -24
1898
1899        expected_cell_info_list = [
1900            # Serving Cell
1901            {
1902                self.CID: serving_cell[self.CID],
1903                self.PCID: serving_cell[self.PCID],
1904                self.REPORT_RATE: 1,
1905                self.IS_REGISTERED: True,
1906                self.RAT: 'lte',
1907                self.TARGET_RSSI:
1908                self._LTE_RSSI_OFFSET + serving_cell['power'],
1909                self.MAX_ERROR_RSSI: 3,
1910                self.MAX_ERROR_AVERAGE_RSSI: 3
1911            },
1912            # Neighbor Cells
1913            {
1914                self.PSC: neighbor_cell_1[self.PSC],
1915                self.REPORT_RATE: 0.1,
1916                self.IS_REGISTERED: False,
1917                self.RAT: 'wcdma',
1918                self.TARGET_RSSI:
1919                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
1920                self.MAX_ERROR_RSSI: 4,
1921                self.MAX_ERROR_AVERAGE_RSSI: 3
1922            }
1923        ]
1924        expected_cell_info_stats = {}
1925        for sample in expected_cell_info_list:
1926            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1927
1928        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1929        [bts1, bts2] = set_system_model_lte_wcdma(
1930            self.md8475a, self.user_params, self.ad.sim_card)
1931        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1932        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
1933                                       neighbor_cell_1['power'])
1934        bts1.neighbor_cell_mode = "USERDATA"
1935        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
1936        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID31")
1937        set_usim_parameters(self.md8475a, self.ad.sim_card)
1938        self.md8475a.start_simulation()
1939        # To make sure phone camps on BTS1
1940        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1941
1942        self.ad.droid.telephonyToggleDataConnection(False)
1943        if not ensure_network_rat(
1944                self.log,
1945                self.ad,
1946                NETWORK_MODE_LTE_GSM_WCDMA,
1947                RAT_FAMILY_LTE,
1948                toggle_apm_after_setting=True):
1949            self.log.error("Failed to set rat family {}, preferred network:{}".
1950                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1951            return False
1952        self.md8475a.wait_for_registration_state()
1953        time.sleep(self._ANRITSU_SETTLING_TIME)
1954        self.md8475a.set_packet_preservation()
1955        time.sleep(self._SETTLING_TIME)
1956        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1957
1958    @test_tracker_info(uuid="9be4e4a8-f79a-4283-9a85-371a9bddfa5d")
1959    @TelephonyBaseTest.tel_test_wrap
1960    def test_neighbor_cell_reporting_lte_interrat_2_tmo(self):
1961        """ Test Number of neighbor cells reported by Phone when two neighbor
1962        cells(inter RAT) are present (Phone camped on LTE)
1963
1964        Setup one LTE and one WCDMA cell configuration on MD8475A
1965        Setup one GSM waveform on MG3710A
1966        Make Sure Phone is in LTE mode
1967        Verify the number of neighbor cells reported by Phone
1968
1969        Returns:
1970            True if pass; False if fail
1971        """
1972        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1973        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid31_cell
1974        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid51_cell
1975        serving_cell['power'] = -20
1976        neighbor_cell_1['power'] = -24
1977        neighbor_cell_2['power'] = -22
1978        expected_cell_info_list = [
1979            # Serving Cell
1980            {
1981                self.CID: serving_cell[self.CID],
1982                self.PCID: serving_cell[self.PCID],
1983                self.REPORT_RATE: 1,
1984                self.IS_REGISTERED: True,
1985                self.RAT: 'lte',
1986                self.TARGET_RSSI:
1987                self._LTE_RSSI_OFFSET + serving_cell['power'],
1988                self.MAX_ERROR_RSSI: 3,
1989                self.MAX_ERROR_AVERAGE_RSSI: 3
1990            },
1991            # Neighbor Cells
1992            {
1993                self.PSC: neighbor_cell_1[self.PSC],
1994                self.REPORT_RATE: 0.1,
1995                self.IS_REGISTERED: False,
1996                self.RAT: 'wcdma',
1997                self.TARGET_RSSI:
1998                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
1999                self.MAX_ERROR_RSSI: 4,
2000                self.MAX_ERROR_AVERAGE_RSSI: 3
2001            },
2002            {
2003                self.CID: neighbor_cell_2[self.CID],
2004                self.REPORT_RATE: 0.1,
2005                self.IS_REGISTERED: False,
2006                self.RAT: 'gsm',
2007                self.TARGET_RSSI:
2008                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
2009                self.MAX_ERROR_RSSI: 4,
2010                self.MAX_ERROR_AVERAGE_RSSI: 3
2011            }
2012        ]
2013        expected_cell_info_stats = {}
2014        for sample in expected_cell_info_list:
2015            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2016
2017        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2018        [bts1, bts2] = set_system_model_lte_wcdma(
2019            self.md8475a, self.user_params, self.ad.sim_card)
2020        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2021        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2022                                       neighbor_cell_1['power'])
2023        bts1.neighbor_cell_mode = "USERDATA"
2024        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2025        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID31")
2026        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2027        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID51")
2028        set_usim_parameters(self.md8475a, self.ad.sim_card)
2029        self.md8475a.start_simulation()
2030        # To make sure phone camps on BTS1
2031        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2032
2033        self.ad.droid.telephonyToggleDataConnection(False)
2034        if not ensure_network_rat(
2035                self.log,
2036                self.ad,
2037                NETWORK_MODE_LTE_GSM_WCDMA,
2038                RAT_FAMILY_LTE,
2039                toggle_apm_after_setting=True):
2040            self.log.error("Failed to set rat family {}, preferred network:{}".
2041                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
2042            return False
2043        self.md8475a.wait_for_registration_state()
2044        time.sleep(self._ANRITSU_SETTLING_TIME)
2045        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2046        self.setup_3710a_waveform("1", "A", "1930.2MHz",
2047                                  neighbor_cell_2['power'], "GSM",
2048                                  "gsm_lac51_cid51")
2049        self.turn_on_3710a_sg(1)
2050        time.sleep(self._ANRITSU_SETTLING_TIME)
2051        self.md8475a.set_packet_preservation()
2052        time.sleep(self._SETTLING_TIME)
2053        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2054
2055    @test_tracker_info(uuid="14db7a3d-b18b-4b87-9d84-fb0c00d3971e")
2056    @TelephonyBaseTest.tel_test_wrap
2057    def test_neighbor_cell_reporting_wcdma_intrafreq_0_tmo(self):
2058        """ Test Number of neighbor cells reported by Phone when no neighbor
2059        cells are present (Phone camped on WCDMA)
2060
2061        Setup a single WCDMA cell configuration on MD8475A
2062        Make Sure Phone camped on WCDMA
2063        Verify the number of neighbor cells reported by Phone
2064
2065        Returns:
2066            True if pass; False if fail
2067        """
2068        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2069        serving_cell['power'] = -20
2070        expected_cell_info_list = [
2071            # Serving Cell
2072            {
2073                self.CID: serving_cell[self.CID],
2074                self.PSC: serving_cell[self.PSC],
2075                self.REPORT_RATE: 1,
2076                self.IS_REGISTERED: True,
2077                self.RAT: 'wcdma',
2078                self.TARGET_RSSI:
2079                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2080                self.MAX_ERROR_RSSI: 3,
2081                self.MAX_ERROR_AVERAGE_RSSI: 3
2082            }
2083        ]
2084        expected_cell_info_stats = {}
2085        for sample in expected_cell_info_list:
2086            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2087
2088        [bts1] = set_system_model_wcdma(self.md8475a, self.user_params,
2089                                        self.ad.sim_card)
2090        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2091                                       serving_cell['power'])
2092        set_usim_parameters(self.md8475a, self.ad.sim_card)
2093        self.md8475a.start_simulation()
2094
2095        if not ensure_network_rat(
2096                self.log,
2097                self.ad,
2098                NETWORK_MODE_GSM_UMTS,
2099                RAT_FAMILY_UMTS,
2100                toggle_apm_after_setting=True):
2101            self.log.error("Failed to set rat family {}, preferred network:{}".
2102                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2103            return False
2104        self.md8475a.wait_for_registration_state()
2105        time.sleep(self._SETTLING_TIME)
2106        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2107
2108    @test_tracker_info(uuid="1a227d1e-9991-4646-b51a-8156f24485da")
2109    @TelephonyBaseTest.tel_test_wrap
2110    def test_neighbor_cell_reporting_wcdma_intrafreq_1_tmo(self):
2111        """ Test Number of neighbor cells reported by Phone when one neighbor
2112        cells is present (Phone camped on WCDMA)
2113
2114        Setup two WCDMA cell configuration on MD8475A
2115        Make Sure Phone camped on WCDMA
2116        Verify the number of neighbor cells reported by Phone
2117
2118        Returns:
2119            True if pass; False if fail
2120        """
2121        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2122        neighbor_cell = wcdma_band1_ch10700_fr2140_cid34_cell
2123        serving_cell['power'] = -20
2124        neighbor_cell['power'] = -24
2125        expected_cell_info_list = [
2126            # Serving Cell
2127            {
2128                self.CID: serving_cell[self.CID],
2129                self.PSC: serving_cell[self.PSC],
2130                self.REPORT_RATE: 1,
2131                self.IS_REGISTERED: True,
2132                self.RAT: 'wcdma',
2133                self.TARGET_RSSI:
2134                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2135                self.MAX_ERROR_RSSI: 3,
2136                self.MAX_ERROR_AVERAGE_RSSI: 3
2137            },
2138            # Neighbor Cells
2139            {
2140                self.PSC: neighbor_cell[self.PSC],
2141                self.REPORT_RATE: 0.1,
2142                self.IS_REGISTERED: False,
2143                self.RAT: 'wcdma',
2144                self.TARGET_RSSI:
2145                self._WCDMA_RSSI_OFFSET + neighbor_cell['power'],
2146                self.MAX_ERROR_RSSI: 4,
2147                self.MAX_ERROR_AVERAGE_RSSI: 3
2148            }
2149        ]
2150        expected_cell_info_stats = {}
2151        for sample in expected_cell_info_list:
2152            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2153
2154        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2155        [bts1, bts2] = set_system_model_wcdma_wcdma(
2156            self.md8475a, self.user_params, self.ad.sim_card)
2157        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2158                                       serving_cell['power'])
2159        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell,
2160                                       neighbor_cell['power'])
2161        bts1.neighbor_cell_mode = "USERDATA"
2162        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2163        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID34")
2164        set_usim_parameters(self.md8475a, self.ad.sim_card)
2165        self.md8475a.start_simulation()
2166        # To make sure phone camps on BTS1
2167        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2168
2169        if not ensure_network_rat(
2170                self.log,
2171                self.ad,
2172                NETWORK_MODE_GSM_UMTS,
2173                RAT_FAMILY_UMTS,
2174                toggle_apm_after_setting=True):
2175            self.log.error("Failed to set rat family {}, preferred network:{}".
2176                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2177            return False
2178        self.md8475a.wait_for_registration_state()
2179        time.sleep(self._ANRITSU_SETTLING_TIME)
2180        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2181        time.sleep(self._SETTLING_TIME)
2182        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2183
2184    @test_tracker_info(uuid="170689a0-0db1-4a14-8b87-5a1b6c9b8581")
2185    @TelephonyBaseTest.tel_test_wrap
2186    def test_neighbor_cell_reporting_wcdma_intrafreq_2_tmo(self):
2187        """ Test Number of neighbor cells reported by Phone when two neighbor
2188        cells are present (Phone camped on WCDMA)
2189
2190        Setup two WCDMA cell configuration on MD8475A
2191        Setup one WCDMA waveform on MG3710A
2192        Make Sure Phone camped on WCDMA
2193        Verify the number of neighbor cells reported by Phone
2194
2195        Returns:
2196            True if pass; False if fail
2197        """
2198        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2199        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid32_cell
2200        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid33_cell
2201        serving_cell['power'] = -20
2202        neighbor_cell_1['power'] = -24
2203        neighbor_cell_2['power'] = -22
2204        expected_cell_info_list = [
2205            # Serving Cell
2206            {
2207                self.CID: serving_cell[self.CID],
2208                self.PSC: serving_cell[self.PSC],
2209                self.REPORT_RATE: 1,
2210                self.IS_REGISTERED: True,
2211                self.RAT: 'wcdma',
2212                self.TARGET_RSSI:
2213                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2214                self.MAX_ERROR_RSSI: 3,
2215                self.MAX_ERROR_AVERAGE_RSSI: 3
2216            },
2217            # Neighbor Cells
2218            {
2219                self.PSC: neighbor_cell_1[self.PSC],
2220                self.REPORT_RATE: 0.1,
2221                self.IS_REGISTERED: False,
2222                self.RAT: 'wcdma',
2223                self.TARGET_RSSI:
2224                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2225                self.MAX_ERROR_RSSI: 4,
2226                self.MAX_ERROR_AVERAGE_RSSI: 3
2227            },
2228            {
2229                self.PSC: neighbor_cell_2[self.PSC],
2230                self.REPORT_RATE: 0.1,
2231                self.IS_REGISTERED: False,
2232                self.RAT: 'wcdma',
2233                self.TARGET_RSSI:
2234                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2235                self.MAX_ERROR_RSSI: 4,
2236                self.MAX_ERROR_AVERAGE_RSSI: 3
2237            }
2238        ]
2239        expected_cell_info_stats = {}
2240        for sample in expected_cell_info_list:
2241            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2242
2243        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2244        [bts1, bts2] = set_system_model_wcdma_wcdma(
2245            self.md8475a, self.user_params, self.ad.sim_card)
2246        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2247                                       serving_cell['power'])
2248        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2249                                       neighbor_cell_1['power'])
2250        bts1.neighbor_cell_mode = "USERDATA"
2251        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2252        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID32")
2253        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2254        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID33")
2255        set_usim_parameters(self.md8475a, self.ad.sim_card)
2256        self.md8475a.start_simulation()
2257        # To make sure phone camps on BTS1
2258        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2259
2260        if not ensure_network_rat(
2261                self.log,
2262                self.ad,
2263                NETWORK_MODE_GSM_UMTS,
2264                RAT_FAMILY_UMTS,
2265                toggle_apm_after_setting=True):
2266            self.log.error("Failed to set rat family {}, preferred network:{}".
2267                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2268            return False
2269        self.md8475a.wait_for_registration_state()
2270        time.sleep(self._ANRITSU_SETTLING_TIME)
2271        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2272        self.setup_3710a_waveform("1", "A", "2140MHz",
2273                                  neighbor_cell_2['power'], "WCDMA",
2274                                  "wcdma_1_psc33_cid33")
2275        self.turn_on_3710a_sg(1)
2276        time.sleep(self._SETTLING_TIME)
2277        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2278
2279    @test_tracker_info(uuid="3ec77512-4d5b-40c9-b733-cf358f999e15")
2280    @TelephonyBaseTest.tel_test_wrap
2281    def test_neighbor_cell_reporting_wcdma_intrafreq_3_tmo(self):
2282        """ Test Number of neighbor cells reported by Phone when three neighbor
2283        cells are present (Phone camped on WCDMA)
2284
2285        Setup two WCDMA cell configuration on MD8475A
2286        Setup two WCDMA waveform on MG3710A
2287        Make Sure Phone camped on WCDMA
2288        Verify the number of neighbor cells reported by Phone
2289
2290        Returns:
2291            True if pass; False if fail
2292        """
2293        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2294        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid32_cell
2295        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid33_cell
2296        neighbor_cell_3 = wcdma_band1_ch10700_fr2140_cid34_cell
2297        serving_cell['power'] = -20
2298        neighbor_cell_1['power'] = -24
2299        neighbor_cell_2['power'] = -23
2300        neighbor_cell_3['power'] = -22
2301
2302        expected_cell_info_list = [
2303            # Serving Cell
2304            {
2305                self.CID: serving_cell[self.CID],
2306                self.PSC: serving_cell[self.PSC],
2307                self.REPORT_RATE: 1,
2308                self.IS_REGISTERED: True,
2309                self.RAT: 'wcdma',
2310                self.TARGET_RSSI:
2311                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2312                self.MAX_ERROR_RSSI: 3,
2313                self.MAX_ERROR_AVERAGE_RSSI: 3
2314            },
2315            # Neighbor Cells
2316            {
2317                self.PSC: neighbor_cell_1[self.PSC],
2318                self.REPORT_RATE: 0.1,
2319                self.IS_REGISTERED: False,
2320                self.RAT: 'wcdma',
2321                self.TARGET_RSSI:
2322                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2323                self.MAX_ERROR_RSSI: 4,
2324                self.MAX_ERROR_AVERAGE_RSSI: 3
2325            },
2326            {
2327                self.PSC: neighbor_cell_2[self.PSC],
2328                self.REPORT_RATE: 0.1,
2329                self.IS_REGISTERED: False,
2330                self.RAT: 'wcdma',
2331                self.TARGET_RSSI:
2332                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2333                self.MAX_ERROR_RSSI: 4,
2334                self.MAX_ERROR_AVERAGE_RSSI: 3
2335            },
2336            {
2337                self.PSC: neighbor_cell_3[self.PSC],
2338                self.REPORT_RATE: 0.1,
2339                self.IS_REGISTERED: False,
2340                self.RAT: 'wcdma',
2341                self.TARGET_RSSI:
2342                self._WCDMA_RSSI_OFFSET + neighbor_cell_3['power'],
2343                self.MAX_ERROR_RSSI: 4,
2344                self.MAX_ERROR_AVERAGE_RSSI: 3
2345            }
2346        ]
2347        expected_cell_info_stats = {}
2348        for sample in expected_cell_info_list:
2349            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2350
2351        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2352        [bts1, bts2] = set_system_model_wcdma_wcdma(
2353            self.md8475a, self.user_params, self.ad.sim_card)
2354        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2355                                       serving_cell['power'])
2356        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2357                                       neighbor_cell_1['power'])
2358        bts1.neighbor_cell_mode = "USERDATA"
2359        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2360        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID32")
2361        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2362        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID33")
2363        bts1.set_neighbor_cell_type("WCDMA", 3, "CELLNAME")
2364        bts1.set_neighbor_cell_name("WCDMA", 3, "WCDM_1_C10700_F2140_CID34")
2365        set_usim_parameters(self.md8475a, self.ad.sim_card)
2366        self.md8475a.start_simulation()
2367        # To make sure phone camps on BTS1
2368        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2369
2370        if not ensure_network_rat(
2371                self.log,
2372                self.ad,
2373                NETWORK_MODE_GSM_UMTS,
2374                RAT_FAMILY_UMTS,
2375                toggle_apm_after_setting=True):
2376            self.log.error("Failed to set rat family {}, preferred network:{}".
2377                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2378            return False
2379        self.md8475a.wait_for_registration_state()
2380        time.sleep(self._ANRITSU_SETTLING_TIME)
2381        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2382        self.setup_3710a_waveform("1", "A", "2140MHz",
2383                                  neighbor_cell_2['power'], "WCDMA",
2384                                  "wcdma_1_psc33_cid33")
2385
2386        self.setup_3710a_waveform("2", "A", "2140MHz",
2387                                  neighbor_cell_3['power'], "WCDMA",
2388                                  "wcdma_1_psc34_cid34")
2389        self.turn_on_3710a_sg(1)
2390        self.turn_on_3710a_sg(2)
2391        time.sleep(self._SETTLING_TIME)
2392        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2393
2394    @test_tracker_info(uuid="6f39e4a5-81da-4f47-8022-f22d82ff6f31")
2395    @TelephonyBaseTest.tel_test_wrap
2396    def test_neighbor_cell_reporting_wcdma_interfreq_1_tmo(self):
2397        """ Test Number of neighbor cells reported by Phone when two neighbor
2398        cells(inter frequency) are present (Phone camped on WCDMA)
2399
2400        Setup a two WCDMA cell configuration on MD8475A
2401        Setup one WCDMA waveform on MG3710A
2402        Make Sure Phone camped on WCDMA
2403        Verify the number of neighbor cells reported by Phonene
2404
2405        Returns:
2406            True if pass; False if fail
2407        """
2408        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2409        neighbor_cell_1 = wcdma_band1_ch10800_fr2160_cid37_cell
2410        serving_cell['power'] = -20
2411        neighbor_cell_1['power'] = -24
2412
2413        expected_cell_info_list = [
2414            # Serving Cell
2415            {
2416                self.CID: serving_cell[self.CID],
2417                self.PSC: serving_cell[self.PSC],
2418                self.REPORT_RATE: 1,
2419                self.IS_REGISTERED: True,
2420                self.RAT: 'wcdma',
2421                self.TARGET_RSSI:
2422                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2423                self.MAX_ERROR_RSSI: 3,
2424                self.MAX_ERROR_AVERAGE_RSSI: 3
2425            },
2426            # Neighbor Cells
2427            {
2428                self.PSC: neighbor_cell_1[self.PSC],
2429                self.REPORT_RATE: 0.1,
2430                self.IS_REGISTERED: False,
2431                self.RAT: 'wcdma',
2432                self.TARGET_RSSI:
2433                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2434                self.MAX_ERROR_RSSI: 4,
2435                self.MAX_ERROR_AVERAGE_RSSI: 3
2436            }
2437        ]
2438        expected_cell_info_stats = {}
2439        for sample in expected_cell_info_list:
2440            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2441
2442        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2443        [bts1, bts2] = set_system_model_wcdma_wcdma(
2444            self.md8475a, self.user_params, self.ad.sim_card)
2445        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2446                                       serving_cell['power'])
2447        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2448                                       neighbor_cell_1['power'])
2449        bts1.neighbor_cell_mode = "USERDATA"
2450        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2451        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10800_F2160_CID37")
2452        set_usim_parameters(self.md8475a, self.ad.sim_card)
2453        self.md8475a.start_simulation()
2454        #To make sure phone camps on BTS1
2455        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2456
2457        self.ad.droid.telephonyToggleDataConnection(False)
2458        if not ensure_network_rat(
2459                self.log,
2460                self.ad,
2461                NETWORK_MODE_GSM_UMTS,
2462                RAT_FAMILY_UMTS,
2463                toggle_apm_after_setting=True):
2464            self.log.error("Failed to set rat family {}, preferred network:{}".
2465                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2466            return False
2467        self.md8475a.wait_for_registration_state()
2468        time.sleep(self._ANRITSU_SETTLING_TIME)
2469        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2470        time.sleep(self._SETTLING_TIME)
2471        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2472
2473    @test_tracker_info(uuid="992d9ffb-2538-447b-b7e8-f40061063686")
2474    @TelephonyBaseTest.tel_test_wrap
2475    def test_neighbor_cell_reporting_wcdma_interfreq_2_tmo(self):
2476        """ Test Number of neighbor cells reported by Phone when two neighbor
2477        cells(inter frequency) are present (Phone camped on WCDMA)
2478
2479        Setup a two WCDMA cell configuration on MD8475A
2480        Setup one WCDMA waveform on MG3710A
2481        Make Sure Phone camped on WCDMA
2482        Verify the number of neighbor cells reported by Phonene
2483
2484        Returns:
2485            True if pass; False if fail
2486        """
2487        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2488        neighbor_cell_1 = wcdma_band1_ch10575_fr2115_cid36_cell
2489        neighbor_cell_2 = wcdma_band1_ch10800_fr2160_cid37_cell
2490        serving_cell['power'] = -20
2491        neighbor_cell_1['power'] = -24
2492        neighbor_cell_2['power'] = -23
2493        expected_cell_info_list = [
2494            # Serving Cell
2495            {
2496                self.CID: serving_cell[self.CID],
2497                self.PSC: serving_cell[self.PSC],
2498                self.REPORT_RATE: 1,
2499                self.IS_REGISTERED: True,
2500                self.RAT: 'wcdma',
2501                self.TARGET_RSSI:
2502                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2503                self.MAX_ERROR_RSSI: 3,
2504                self.MAX_ERROR_AVERAGE_RSSI: 3
2505            },
2506            # Neighbor Cells
2507            {
2508                self.PSC: neighbor_cell_1[self.PSC],
2509                self.REPORT_RATE: 0.1,
2510                self.IS_REGISTERED: False,
2511                self.RAT: 'wcdma',
2512                self.TARGET_RSSI:
2513                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2514                self.MAX_ERROR_RSSI: 4,
2515                self.MAX_ERROR_AVERAGE_RSSI: 3
2516            },
2517            {
2518                self.PSC: neighbor_cell_2[self.PSC],
2519                self.REPORT_RATE: 0.1,
2520                self.IS_REGISTERED: False,
2521                self.RAT: 'wcdma',
2522                self.TARGET_RSSI:
2523                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2524                self.MAX_ERROR_RSSI: 4,
2525                self.MAX_ERROR_AVERAGE_RSSI: 3
2526            }
2527        ]
2528        expected_cell_info_stats = {}
2529        for sample in expected_cell_info_list:
2530            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2531
2532        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2533        [bts1, bts2] = set_system_model_wcdma_wcdma(
2534            self.md8475a, self.user_params, self.ad.sim_card)
2535        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2536                                       serving_cell['power'])
2537        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2538                                       neighbor_cell_1['power'])
2539        bts1.neighbor_cell_mode = "USERDATA"
2540        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2541        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10575_F2115_CID36")
2542        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2543        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10800_F2160_CID37")
2544        set_usim_parameters(self.md8475a, self.ad.sim_card)
2545        self.md8475a.start_simulation()
2546        # To make sure phone camps on BTS1
2547        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2548
2549        self.ad.droid.telephonyToggleDataConnection(False)
2550        if not ensure_network_rat(
2551                self.log,
2552                self.ad,
2553                NETWORK_MODE_GSM_UMTS,
2554                RAT_FAMILY_UMTS,
2555                toggle_apm_after_setting=True):
2556            self.log.error("Failed to set rat family {}, preferred network:{}".
2557                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2558            return False
2559        self.md8475a.wait_for_registration_state()
2560        time.sleep(self._ANRITSU_SETTLING_TIME)
2561        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2562        self.setup_3710a_waveform("1", "A", "2160MHz",
2563                                  neighbor_cell_2['power'], "WCDMA",
2564                                  "wcdma_1_psc37_cid37")
2565        self.turn_on_3710a_sg(1)
2566        time.sleep(self._SETTLING_TIME)
2567        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2568
2569    @test_tracker_info(uuid="60cb8c15-3cb3-4ead-9e59-a8aee819e9ef")
2570    @TelephonyBaseTest.tel_test_wrap
2571    def test_neighbor_cell_reporting_wcdma_interband_2_tmo(self):
2572        """ Test Number of neighbor cells reported by Phone when two neighbor
2573        cells(inter band) are present (Phone camped on WCDMA)
2574
2575        Setup a two WCDMA cell configuration on MD8475A
2576        Setup one WCDMA waveform on MG3710A
2577        Make Sure Phone camped on WCDMA
2578        Verify the number of neighbor cells reported by Phone
2579
2580        Returns:
2581            True if pass; False if fail
2582        """
2583        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2584        neighbor_cell_1 = wcdma_band2_ch9800_fr1960_cid38_cell
2585        neighbor_cell_2 = wcdma_band2_ch9900_fr1980_cid39_cell
2586        serving_cell['power'] = -20
2587        neighbor_cell_1['power'] = -23
2588        neighbor_cell_2['power'] = -22
2589
2590        expected_cell_info_list = [
2591            # Serving Cell
2592            {
2593                self.CID: serving_cell[self.CID],
2594                self.PSC: serving_cell[self.PSC],
2595                self.REPORT_RATE: 1,
2596                self.IS_REGISTERED: True,
2597                self.RAT: 'wcdma',
2598                self.TARGET_RSSI:
2599                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2600                self.MAX_ERROR_RSSI: 3,
2601                self.MAX_ERROR_AVERAGE_RSSI: 3
2602            },
2603            # Neighbor Cells
2604            {
2605                self.PSC: neighbor_cell_1[self.PSC],
2606                self.REPORT_RATE: 0.1,
2607                self.IS_REGISTERED: False,
2608                self.RAT: 'wcdma',
2609                self.TARGET_RSSI:
2610                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2611                self.MAX_ERROR_RSSI: 4,
2612                self.MAX_ERROR_AVERAGE_RSSI: 3
2613            },
2614            {
2615                self.PSC: neighbor_cell_2[self.PSC],
2616                self.REPORT_RATE: 0.1,
2617                self.IS_REGISTERED: False,
2618                self.RAT: 'wcdma',
2619                self.TARGET_RSSI:
2620                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2621                self.MAX_ERROR_RSSI: 4,
2622                self.MAX_ERROR_AVERAGE_RSSI: 3
2623            }
2624        ]
2625        expected_cell_info_stats = {}
2626        for sample in expected_cell_info_list:
2627            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2628
2629        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2630        [bts1, bts2] = set_system_model_wcdma_wcdma(
2631            self.md8475a, self.user_params, self.ad.sim_card)
2632        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2633                                       serving_cell['power'])
2634        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2635                                       neighbor_cell_1['power'])
2636        bts1.neighbor_cell_mode = "USERDATA"
2637        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2638        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_2_C9800_F1960_CID38")
2639        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2640        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_2_C9900_F1980_CID39")
2641        set_usim_parameters(self.md8475a, self.ad.sim_card)
2642        self.md8475a.start_simulation()
2643        # To make sure phone camps on BTS1
2644        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2645
2646        self.ad.droid.telephonyToggleDataConnection(False)
2647        if not ensure_network_rat(
2648                self.log,
2649                self.ad,
2650                NETWORK_MODE_GSM_UMTS,
2651                RAT_FAMILY_UMTS,
2652                toggle_apm_after_setting=True):
2653            self.log.error("Failed to set rat family {}, preferred network:{}".
2654                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2655            return False
2656        self.md8475a.wait_for_registration_state()
2657        time.sleep(self._ANRITSU_SETTLING_TIME)
2658        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2659        self.setup_3710a_waveform("1", "A", "1980MHz",
2660                                  neighbor_cell_2['power'], "WCDMA",
2661                                  "wcdma_2_psc39_cid39")
2662        self.turn_on_3710a_sg(1)
2663        time.sleep(self._SETTLING_TIME)
2664        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2665
2666    @test_tracker_info(uuid="daa29f27-f67b-47ee-9a30-1c9572eedf2f")
2667    @TelephonyBaseTest.tel_test_wrap
2668    def test_neighbor_cell_reporting_wcdma_interrat_1_tmo(self):
2669        """ Test Number of neighbor cells reported by Phone when two neighbor
2670        cells are present (Phone camped on WCDMA)
2671
2672        Setup a two WCDMA cell configuration on MD8475A
2673        Setup one WCDMA waveform on MG3710A
2674        Make Sure Phone camped on WCDMA
2675        Verify the number of neighbor cells reported by Phone
2676
2677        Returns:
2678            True if pass; False if fail
2679        """
2680        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2681        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid51_cell
2682        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid1_cell
2683        serving_cell['power'] = -20
2684        neighbor_cell_1['power'] = -23
2685        neighbor_cell_2['power'] = -22
2686
2687        expected_cell_info_list = [
2688            # Serving Cell
2689            {
2690                self.CID: serving_cell[self.CID],
2691                self.PSC: serving_cell[self.PSC],
2692                self.REPORT_RATE: 1,
2693                self.IS_REGISTERED: True,
2694                self.RAT: 'wcdma',
2695                self.TARGET_RSSI:
2696                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2697                self.MAX_ERROR_RSSI: 3,
2698                self.MAX_ERROR_AVERAGE_RSSI: 3
2699            },
2700            # Neighbor Cells
2701            {
2702                self.CID: neighbor_cell_1[self.CID],
2703                self.REPORT_RATE: 0.1,
2704                self.IS_REGISTERED: False,
2705                self.RAT: 'gsm',
2706                self.TARGET_RSSI:
2707                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2708                self.MAX_ERROR_RSSI: 4,
2709                self.MAX_ERROR_AVERAGE_RSSI: 3
2710            },
2711            {
2712                self.PCID: neighbor_cell_2[self.PCID],
2713                self.REPORT_RATE: 0.1,
2714                self.IS_REGISTERED: False,
2715                self.RAT: 'lte',
2716                self.TARGET_RSSI:
2717                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
2718                self.MAX_ERROR_RSSI: 4,
2719                self.MAX_ERROR_AVERAGE_RSSI: 3
2720            }
2721        ]
2722        expected_cell_info_stats = {}
2723        for sample in expected_cell_info_list:
2724            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2725
2726        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2727        [bts1, bts2] = set_system_model_lte_wcdma(
2728            self.md8475a, self.user_params, self.ad.sim_card)
2729        self._setup_wcdma_cell_md8475a(bts2, serving_cell,
2730                                       serving_cell['power'])
2731        self._setup_lte_cell_md8475a(bts1, neighbor_cell_2,
2732                                     neighbor_cell_2['power'])
2733        bts2.neighbor_cell_mode = "USERDATA"
2734        bts2.set_neighbor_cell_type("LTE", 1, "CELLNAME")
2735        bts2.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
2736        set_usim_parameters(self.md8475a, self.ad.sim_card)
2737        self.md8475a.start_simulation()
2738        # To make sure phone camps on BTS1
2739        bts1.service_state = BtsServiceState.SERVICE_STATE_OUT
2740
2741        self.ad.droid.telephonyToggleDataConnection(False)
2742        if not ensure_network_rat(
2743                self.log,
2744                self.ad,
2745                NETWORK_MODE_GSM_UMTS,
2746                RAT_FAMILY_UMTS,
2747                toggle_apm_after_setting=True):
2748            self.log.error("Failed to set rat family {}, preferred network:{}".
2749                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2750            return False
2751        self.md8475a.wait_for_registration_state()
2752        time.sleep(self._ANRITSU_SETTLING_TIME)
2753        bts1.service_state = BtsServiceState.SERVICE_STATE_IN
2754        time.sleep(self._SETTLING_TIME)
2755        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2756
2757    @test_tracker_info(uuid="08e5d666-fae6-48a3-b03b-de7b7b3f5982")
2758    @TelephonyBaseTest.tel_test_wrap
2759    def test_neighbor_cell_reporting_wcdma_interrat_2_tmo(self):
2760        """ Test Number of neighbor cells reported by Phone when two neighbor
2761        cells are present (Phone camped on WCDMA)
2762
2763        Setup a two WCDMA cell configuration on MD8475A
2764        Setup one WCDMA waveform on MG3710A
2765        Make Sure Phone camped on WCDMA
2766        Verify the number of neighbor cells reported by Phone
2767
2768        Returns:
2769            True if pass; False if fail
2770        """
2771        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2772        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid51_cell
2773        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid1_cell
2774        serving_cell['power'] = -20
2775        neighbor_cell_1['power'] = -23
2776        neighbor_cell_2['power'] = -22
2777
2778        expected_cell_info_list = [
2779            # Serving Cell
2780            {
2781                self.CID: serving_cell[self.CID],
2782                self.PSC: serving_cell[self.PSC],
2783                self.REPORT_RATE: 1,
2784                self.IS_REGISTERED: True,
2785                self.RAT: 'wcdma',
2786                self.TARGET_RSSI:
2787                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2788                self.MAX_ERROR_RSSI: 3,
2789                self.MAX_ERROR_AVERAGE_RSSI: 3
2790            },
2791            # Neighbor Cells
2792            {
2793                self.CID: neighbor_cell_1[self.CID],
2794                self.REPORT_RATE: 0.1,
2795                self.IS_REGISTERED: False,
2796                self.RAT: 'gsm',
2797                self.TARGET_RSSI:
2798                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2799                self.MAX_ERROR_RSSI: 4,
2800                self.MAX_ERROR_AVERAGE_RSSI: 3
2801            },
2802            {
2803                self.PCID: neighbor_cell_2[self.PCID],
2804                self.REPORT_RATE: 0.1,
2805                self.IS_REGISTERED: False,
2806                self.RAT: 'lte',
2807                self.TARGET_RSSI:
2808                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
2809                self.MAX_ERROR_RSSI: 4,
2810                self.MAX_ERROR_AVERAGE_RSSI: 3
2811            }
2812        ]
2813        expected_cell_info_stats = {}
2814        for sample in expected_cell_info_list:
2815            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2816
2817        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2818        [bts1, bts2] = set_system_model_wcdma_gsm(
2819            self.md8475a, self.user_params, self.ad.sim_card)
2820        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2821                                       serving_cell['power'])
2822        self._setup_gsm_cell_md8475a(bts2, neighbor_cell_1,
2823                                     neighbor_cell_1['power'])
2824        bts1.neighbor_cell_mode = "USERDATA"
2825        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2826        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID51")
2827        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
2828        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
2829        set_usim_parameters(self.md8475a, self.ad.sim_card)
2830        self.md8475a.start_simulation()
2831        # To make sure phone camps on BTS1
2832        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2833
2834        self.ad.droid.telephonyToggleDataConnection(False)
2835        if not ensure_network_rat(
2836                self.log,
2837                self.ad,
2838                NETWORK_MODE_GSM_UMTS,
2839                RAT_FAMILY_UMTS,
2840                toggle_apm_after_setting=True):
2841            self.log.error("Failed to set rat family {}, preferred network:{}".
2842                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2843            return False
2844        self.md8475a.wait_for_registration_state()
2845        time.sleep(self._ANRITSU_SETTLING_TIME)
2846        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2847        self.setup_3710a_waveform("1", "A", "2115MHz",
2848                                  neighbor_cell_2['power'], "LTE",
2849                                  "lte_4_ch2000_pcid1")
2850        self.turn_on_3710a_sg(1)
2851        time.sleep(self._SETTLING_TIME)
2852        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2853
2854    @test_tracker_info(uuid="bebbe764-4c8c-4aaf-81b9-c61509a9695e")
2855    @TelephonyBaseTest.tel_test_wrap
2856    def test_neighbor_cell_reporting_gsm_intrafreq_0_tmo(self):
2857        """ Test Number of neighbor cells reported by Phone when no neighbor
2858        cells are present (Phone camped on GSM)
2859
2860        Setup one GSM cell configuration on MD8475A
2861        Make Sure Phone camped on GSM
2862        Verify the number of neighbor cells reported by Phone
2863
2864        Returns:
2865            True if pass; False if fail
2866        """
2867        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2868        serving_cell['power'] = -30
2869
2870        expected_cell_info_list = [
2871            # Serving Cell
2872            {
2873                self.CID: serving_cell[self.CID],
2874                self.REPORT_RATE: 1,
2875                self.IS_REGISTERED: True,
2876                self.RAT: 'gsm',
2877                self.TARGET_RSSI:
2878                self._GSM_RSSI_OFFSET + serving_cell['power'],
2879                self.MAX_ERROR_RSSI: 3,
2880                self.MAX_ERROR_AVERAGE_RSSI: 3
2881            }
2882        ]
2883        expected_cell_info_stats = {}
2884        for sample in expected_cell_info_list:
2885            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2886
2887        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
2888                                      self.ad.sim_card)
2889        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2890        set_usim_parameters(self.md8475a, self.ad.sim_card)
2891        self.md8475a.start_simulation()
2892        if not ensure_network_rat(
2893                self.log,
2894                self.ad,
2895                NETWORK_MODE_GSM_ONLY,
2896                RAT_FAMILY_GSM,
2897                toggle_apm_after_setting=True):
2898            self.log.error("Failed to set rat family {}, preferred network:{}".
2899                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
2900            return False
2901        self.md8475a.wait_for_registration_state()
2902        time.sleep(self._SETTLING_TIME)
2903        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2904
2905    @test_tracker_info(uuid="861dd399-d6f6-4e9f-9e8d-0718966ea45a")
2906    @TelephonyBaseTest.tel_test_wrap
2907    def test_neighbor_cell_reporting_gsm_intrafreq_1_tmo(self):
2908        """ Test Number of neighbor cells reported by Phone when one neighbor
2909        cell is present (Phone camped on GSM)
2910
2911        Setup one GSM cell configuration on MD8475A
2912        Make Sure Phone camped on GSM
2913        Verify the number of neighbor cells reported by Phone
2914
2915        Returns:
2916            True if pass; False if fail
2917        """
2918        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2919        neighbor_cell = gsm_band1900_ch512_fr1930_cid52_cell
2920        serving_cell['power'] = -20
2921        neighbor_cell['power'] = -22
2922
2923        expected_cell_info_list = [
2924            # Serving Cell
2925            {
2926                self.CID: serving_cell[self.CID],
2927                self.REPORT_RATE: 1,
2928                self.IS_REGISTERED: True,
2929                self.RAT: 'gsm',
2930                self.TARGET_RSSI:
2931                self._GSM_RSSI_OFFSET + serving_cell['power'],
2932                self.MAX_ERROR_RSSI: 3,
2933                self.MAX_ERROR_AVERAGE_RSSI: 3
2934            },
2935            # Neighbor Cells
2936            {
2937                self.CID: neighbor_cell_1[self.CID],
2938                self.REPORT_RATE: 0.1,
2939                self.IS_REGISTERED: False,
2940                self.RAT: 'gsm',
2941                self.TARGET_RSSI:
2942                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2943                self.MAX_ERROR_RSSI: 4,
2944                self.MAX_ERROR_AVERAGE_RSSI: 3
2945            }
2946        ]
2947        expected_cell_info_stats = {}
2948        for sample in expected_cell_info_list:
2949            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2950
2951        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2952        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
2953                                      self.ad.sim_card)
2954        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2955        bts1.neighbor_cell_mode = "USERDATA"
2956        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2957        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
2958        set_usim_parameters(self.md8475a, self.ad.sim_card)
2959        self.md8475a.start_simulation()
2960
2961        if not ensure_network_rat(
2962                self.log,
2963                self.ad,
2964                NETWORK_MODE_GSM_ONLY,
2965                RAT_FAMILY_GSM,
2966                toggle_apm_after_setting=True):
2967            self.log.error("Failed to set rat family {}, preferred network:{}".
2968                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
2969            return False
2970        self.md8475a.wait_for_registration_state()
2971        time.sleep(self._ANRITSU_SETTLING_TIME)
2972        self.setup_3710a_waveform("1", "A", "1930.2MHz",
2973                                  neighbor_cell['power'], "GSM",
2974                                  "gsm_lac52_cid52")
2975
2976        self.turn_on_3710a_sg(1)
2977        time.sleep(self._SETTLING_TIME)
2978        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2979
2980    @test_tracker_info(uuid="58627a33-45bd-436d-85b2-1ca711f56794")
2981    @TelephonyBaseTest.tel_test_wrap
2982    def test_neighbor_cell_reporting_gsm_intrafreq_2_tmo(self):
2983        """ Test Number of neighbor cells reported by Phone when two neighbor
2984        cells are present (Phone camped on GSM)
2985
2986        Setup one GSM cell configuration on MD8475A
2987        Setup two GSM waveforms on MG3710A
2988        Make Sure Phone camped on GSM
2989        Verify the number of neighbor cells reported by Phone
2990
2991        Returns:
2992            True if pass; False if fail
2993        """
2994        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2995        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid52_cell
2996        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid53_cell
2997        serving_cell['power'] = -20
2998        neighbor_cell_1['power'] = -24
2999        neighbor_cell_2['power'] = -22
3000
3001        expected_cell_info_list = [
3002            # Serving Cell
3003            {
3004                self.CID: serving_cell[self.CID],
3005                self.REPORT_RATE: 1,
3006                self.IS_REGISTERED: True,
3007                self.RAT: 'gsm',
3008                self.TARGET_RSSI:
3009                self._GSM_RSSI_OFFSET + serving_cell['power'],
3010                self.MAX_ERROR_RSSI: 3,
3011                self.MAX_ERROR_AVERAGE_RSSI: 3
3012            },
3013            # Neighbor Cells
3014            {
3015                self.CID: neighbor_cell_1[self.CID],
3016                self.REPORT_RATE: 0.1,
3017                self.IS_REGISTERED: False,
3018                self.RAT: 'gsm',
3019                self.TARGET_RSSI:
3020                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3021                self.MAX_ERROR_RSSI: 4,
3022                self.MAX_ERROR_AVERAGE_RSSI: 3
3023            },
3024            {
3025                self.CID: neighbor_cell_2[self.CID],
3026                self.REPORT_RATE: 0.1,
3027                self.IS_REGISTERED: False,
3028                self.RAT: 'gsm',
3029                self.TARGET_RSSI:
3030                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3031                self.MAX_ERROR_RSSI: 4,
3032                self.MAX_ERROR_AVERAGE_RSSI: 3
3033            }
3034        ]
3035        expected_cell_info_stats = {}
3036        for sample in expected_cell_info_list:
3037            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3038
3039        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3040        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3041                                      self.ad.sim_card)
3042        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3043        bts1.neighbor_cell_mode = "USERDATA"
3044        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3045        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
3046        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3047        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C512_F1930_CID53")
3048        set_usim_parameters(self.md8475a, self.ad.sim_card)
3049        self.md8475a.start_simulation()
3050
3051        if not ensure_network_rat(
3052                self.log,
3053                self.ad,
3054                NETWORK_MODE_GSM_ONLY,
3055                RAT_FAMILY_GSM,
3056                toggle_apm_after_setting=True):
3057            self.log.error("Failed to set rat family {}, preferred network:{}".
3058                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3059            return False
3060        self.md8475a.wait_for_registration_state()
3061        self.setup_3710a_waveform("1", "A", "1930.2MHz",
3062                                  neighbor_cell_1['power'], "GSM",
3063                                  "gsm_lac52_cid52")
3064
3065        self.setup_3710a_waveform("2", "A", "1930.2MHz",
3066                                  neighbor_cell_2['power'], "GSM",
3067                                  "gsm_lac53_cid53")
3068        self.turn_on_3710a_sg(1)
3069        self.turn_on_3710a_sg(2)
3070        time.sleep(self._SETTLING_TIME)
3071        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3072
3073    @test_tracker_info(uuid="3ff3439a-2e45-470a-a2d6-c63e37379f19")
3074    @TelephonyBaseTest.tel_test_wrap
3075    def test_neighbor_cell_reporting_gsm_intrafreq_3_tmo(self):
3076        """ Test Number of neighbor cells reported by Phone when three neighbor
3077        cells are present (Phone camped on GSM)
3078
3079        Setup one GSM cell configuration on MD8475A
3080        Setup three GSM waveforms on MG3710A
3081        Make Sure Phone camped on GSM
3082        Verify the number of neighbor cells reported by Phone
3083
3084        Returns:
3085            True if pass; False if fail
3086        """
3087        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3088        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid52_cell
3089        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid53_cell
3090        neighbor_cell_3 = gsm_band1900_ch512_fr1930_cid54_cell
3091        serving_cell['power'] = -20
3092        neighbor_cell_1['power'] = -24
3093        neighbor_cell_2['power'] = -22
3094        neighbor_cell_3['power'] = -24
3095
3096        expected_cell_info_list = [
3097            # Serving Cell
3098            {
3099                self.CID: serving_cell[self.CID],
3100                self.REPORT_RATE: 1,
3101                self.IS_REGISTERED: True,
3102                self.RAT: 'gsm',
3103                self.TARGET_RSSI:
3104                self._GSM_RSSI_OFFSET + serving_cell['power'],
3105                self.MAX_ERROR_RSSI: 3,
3106                self.MAX_ERROR_AVERAGE_RSSI: 3
3107            },
3108            # Neighbor Cells
3109            {
3110                self.CID: neighbor_cell_1[self.CID],
3111                self.REPORT_RATE: 0.1,
3112                self.IS_REGISTERED: False,
3113                self.RAT: 'gsm',
3114                self.TARGET_RSSI:
3115                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3116                self.MAX_ERROR_RSSI: 4,
3117                self.MAX_ERROR_AVERAGE_RSSI: 3
3118            },
3119            {
3120                self.CID: neighbor_cell_2[self.CID],
3121                self.REPORT_RATE: 0.1,
3122                self.IS_REGISTERED: False,
3123                self.RAT: 'gsm',
3124                self.TARGET_RSSI:
3125                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3126                self.MAX_ERROR_RSSI: 4,
3127                self.MAX_ERROR_AVERAGE_RSSI: 3
3128            },
3129            {
3130                self.CID: neighbor_cell_3[self.CID],
3131                self.REPORT_RATE: 0.1,
3132                self.IS_REGISTERED: False,
3133                self.RAT: 'gsm',
3134                self.TARGET_RSSI:
3135                self._GSM_RSSI_OFFSET + neighbor_cell_3['power'],
3136                self.MAX_ERROR_RSSI: 4,
3137                self.MAX_ERROR_AVERAGE_RSSI: 3
3138            }
3139        ]
3140        expected_cell_info_stats = {}
3141        for sample in expected_cell_info_list:
3142            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3143
3144        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3145        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3146                                      self.ad.sim_card)
3147        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3148        bts1.neighbor_cell_mode = "USERDATA"
3149        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3150        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
3151        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3152        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C512_F1930_CID53")
3153        bts1.set_neighbor_cell_type("GSM", 3, "CELLNAME")
3154        bts1.set_neighbor_cell_name("GSM", 3, "GSM_1900_C512_F1930_CID53")
3155        set_usim_parameters(self.md8475a, self.ad.sim_card)
3156        self.md8475a.start_simulation()
3157
3158        if not ensure_network_rat(
3159                self.log,
3160                self.ad,
3161                NETWORK_MODE_GSM_ONLY,
3162                RAT_FAMILY_GSM,
3163                toggle_apm_after_setting=True):
3164            self.log.error("Failed to set rat family {}, preferred network:{}".
3165                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3166            return False
3167        self.md8475a.wait_for_registration_state()
3168        self.setup_3710a_waveform("1", "A", "1930.2MHz",
3169                                  neighbor_cell_1['power'], "GSM",
3170                                  "gsm_lac52_cid52")
3171
3172        self.setup_3710a_waveform("2", "A", "1930.2MHz",
3173                                  neighbor_cell_2['power'], "GSM",
3174                                  "gsm_lac53_cid53")
3175
3176        self.setup_3710a_waveform("2", "B", "1930.2MHz",
3177                                  neighbor_cell_3['power'], "GSM",
3178                                  "gsm_lac54_cid54")
3179        self.turn_on_3710a_sg(1)
3180        self.turn_on_3710a_sg(2)
3181        time.sleep(self._SETTLING_TIME)
3182        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3183
3184    @test_tracker_info(uuid="0cac1370-144e-40a4-b6bc-66691926f898")
3185    @TelephonyBaseTest.tel_test_wrap
3186    def test_neighbor_cell_reporting_gsm_interfreq_1_tmo(self):
3187        """ Test Number of neighbor cells reported by Phone when one neighbor
3188        cells(inter frequency) is present (Phone camped on GSM)
3189
3190        Setup one GSM cell configuration on MD8475A
3191        Setup two GSM waveforms on MG3710A
3192        Make Sure Phone camped on GSM
3193        Verify the number of neighbor cells reported by Phone
3194
3195        Returns:
3196            True if pass; False if fail
3197        """
3198        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3199        neighbor_cell_1 = gsm_band1900_ch640_fr1955_cid56_cell
3200        serving_cell['power'] = -20
3201        neighbor_cell_1['power'] = -24
3202
3203        expected_cell_info_list = [
3204            # Serving Cell
3205            {
3206                self.CID: serving_cell[self.CID],
3207                self.REPORT_RATE: 1,
3208                self.IS_REGISTERED: True,
3209                self.RAT: 'gsm',
3210                self.TARGET_RSSI:
3211                self._GSM_RSSI_OFFSET + serving_cell['power'],
3212                self.MAX_ERROR_RSSI: 3,
3213                self.MAX_ERROR_AVERAGE_RSSI: 3
3214            },
3215            # Neighbor Cells
3216            {
3217                self.CID: neighbor_cell_1[self.CID],
3218                self.REPORT_RATE: 0.1,
3219                self.IS_REGISTERED: False,
3220                self.RAT: 'gsm',
3221                self.TARGET_RSSI:
3222                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3223                self.MAX_ERROR_RSSI: 4,
3224                self.MAX_ERROR_AVERAGE_RSSI: 3
3225            }
3226        ]
3227        expected_cell_info_stats = {}
3228        for sample in expected_cell_info_list:
3229            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3230
3231        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3232        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3233                                      self.ad.sim_card)
3234        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3235        bts1.neighbor_cell_mode = "USERDATA"
3236        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3237        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C640_F1955_CID56")
3238        set_usim_parameters(self.md8475a, self.ad.sim_card)
3239        self.md8475a.start_simulation()
3240
3241        self.ad.droid.telephonyToggleDataConnection(False)
3242        if not ensure_network_rat(
3243                self.log,
3244                self.ad,
3245                NETWORK_MODE_GSM_ONLY,
3246                RAT_FAMILY_GSM,
3247                toggle_apm_after_setting=True):
3248            self.log.error("Failed to set rat family {}, preferred network:{}".
3249                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3250            return False
3251        self.md8475a.wait_for_registration_state()
3252        self.setup_3710a_waveform("1", "A", "1955.8MHz",
3253                                  neighbor_cell_1['power'], "GSM",
3254                                  "gsm_lac56_cid56")
3255
3256        self.turn_on_3710a_sg(1)
3257        time.sleep(self._SETTLING_TIME)
3258        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3259
3260    @test_tracker_info(uuid="5f0367dd-08b5-4871-a784-51a0f76e229b")
3261    @TelephonyBaseTest.tel_test_wrap
3262    def test_neighbor_cell_reporting_gsm_interfreq_2_tmo(self):
3263        """ Test Number of neighbor cells reported by Phone when two neighbor
3264        cells(inter frequency) are present (Phone camped on GSM)
3265
3266        Setup one GSM cell configuration on MD8475A
3267        Setup two GSM waveforms on MG3710A
3268        Make Sure Phone camped on GSM
3269        Verify the number of neighbor cells reported by Phone
3270
3271        Returns:
3272            True if pass; False if fail
3273        """
3274        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3275        neighbor_cell_1 = gsm_band1900_ch640_fr1955_cid56_cell
3276        neighbor_cell_2 = gsm_band1900_ch750_fr1977_cid57_cell
3277        serving_cell['power'] = -20
3278        neighbor_cell_1['power'] = -24
3279        neighbor_cell_2['power'] = -22
3280
3281        expected_cell_info_list = [
3282            # Serving Cell
3283            {
3284                self.CID: serving_cell[self.CID],
3285                self.REPORT_RATE: 1,
3286                self.IS_REGISTERED: True,
3287                self.RAT: 'gsm',
3288                self.TARGET_RSSI:
3289                self._GSM_RSSI_OFFSET + serving_cell['power'],
3290                self.MAX_ERROR_RSSI: 3,
3291                self.MAX_ERROR_AVERAGE_RSSI: 3
3292            },
3293            # Neighbor Cells
3294            {
3295                self.CID: neighbor_cell_1[self.CID],
3296                self.REPORT_RATE: 0.1,
3297                self.IS_REGISTERED: False,
3298                self.RAT: 'gsm',
3299                self.TARGET_RSSI:
3300                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3301                self.MAX_ERROR_RSSI: 4,
3302                self.MAX_ERROR_AVERAGE_RSSI: 3
3303            },
3304            {
3305                self.CID: neighbor_cell_2[self.CID],
3306                self.REPORT_RATE: 0.1,
3307                self.IS_REGISTERED: False,
3308                self.RAT: 'gsm',
3309                self.TARGET_RSSI:
3310                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3311                self.MAX_ERROR_RSSI: 4,
3312                self.MAX_ERROR_AVERAGE_RSSI: 3
3313            }
3314        ]
3315        expected_cell_info_stats = {}
3316        for sample in expected_cell_info_list:
3317            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3318
3319        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3320        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3321                                      self.ad.sim_card)
3322        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3323        bts1.neighbor_cell_mode = "USERDATA"
3324        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3325        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C640_F1955_CID56")
3326        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3327        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C750_F1977_CID57")
3328        set_usim_parameters(self.md8475a, self.ad.sim_card)
3329        self.md8475a.start_simulation()
3330
3331        self.ad.droid.telephonyToggleDataConnection(False)
3332        if not ensure_network_rat(
3333                self.log,
3334                self.ad,
3335                NETWORK_MODE_GSM_ONLY,
3336                RAT_FAMILY_GSM,
3337                toggle_apm_after_setting=True):
3338            self.log.error("Failed to set rat family {}, preferred network:{}".
3339                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3340            return False
3341        self.md8475a.wait_for_registration_state()
3342        self.setup_3710a_waveform("1", "A", "1955.8MHz",
3343                                  neighbor_cell_1['power'], "GSM",
3344                                  "gsm_lac56_cid56")
3345
3346        self.setup_3710a_waveform("2", "A", "1977.8MHz",
3347                                  neighbor_cell_2['power'], "GSM",
3348                                  "gsm_lac57_cid57")
3349        self.turn_on_3710a_sg(1)
3350        self.turn_on_3710a_sg(2)
3351        time.sleep(self._SETTLING_TIME)
3352        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3353
3354    @test_tracker_info(uuid="b195153f-f6a0-4ec4-bb53-29c30ec0a034")
3355    @TelephonyBaseTest.tel_test_wrap
3356    def test_neighbor_cell_reporting_gsm_interband_2_tmo(self):
3357        """ Test Number of neighbor cells reported by Phone when two neighbor
3358        cells(inter band) are present (Phone camped on GSM)
3359
3360        Setup one GSM cell configuration on MD8475A
3361        Setup two GSM waveforms on MG3710A
3362        Make Sure Phone camped on GSM
3363        Verify the number of neighbor cells reported by Phone
3364
3365        Returns:
3366            True if pass; False if fail
3367        """
3368        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3369        neighbor_cell_1 = gsm_band850_ch128_fr869_cid58_cell
3370        neighbor_cell_2 = gsm_band850_ch251_fr893_cid59_cell
3371        serving_cell['power'] = -20
3372        neighbor_cell_1['power'] = -24
3373        neighbor_cell_2['power'] = -22
3374
3375        expected_cell_info_list = [
3376            # Serving Cell
3377            {
3378                self.CID: serving_cell[self.CID],
3379                self.REPORT_RATE: 1,
3380                self.IS_REGISTERED: True,
3381                self.RAT: 'gsm',
3382                self.TARGET_RSSI:
3383                self._GSM_RSSI_OFFSET + serving_cell['power'],
3384                self.MAX_ERROR_RSSI: 3,
3385                self.MAX_ERROR_AVERAGE_RSSI: 3
3386            },
3387            # Neighbor Cells
3388            {
3389                self.CID: neighbor_cell_1[self.CID],
3390                self.REPORT_RATE: 0.1,
3391                self.IS_REGISTERED: False,
3392                self.RAT: 'gsm',
3393                self.TARGET_RSSI:
3394                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3395                self.MAX_ERROR_RSSI: 4,
3396                self.MAX_ERROR_AVERAGE_RSSI: 3
3397            },
3398            {
3399                self.CID: neighbor_cell_2[self.CID],
3400                self.REPORT_RATE: 0.1,
3401                self.IS_REGISTERED: False,
3402                self.RAT: 'gsm',
3403                self.TARGET_RSSI:
3404                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3405                self.MAX_ERROR_RSSI: 4,
3406                self.MAX_ERROR_AVERAGE_RSSI: 3
3407            }
3408        ]
3409        expected_cell_info_stats = {}
3410        for sample in expected_cell_info_list:
3411            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3412
3413        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3414        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3415                                      self.ad.sim_card)
3416        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3417        bts1.neighbor_cell_mode = "USERDATA"
3418        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3419        bts1.set_neighbor_cell_name("GSM", 1, "GSM_850_C128_F869_CID58")
3420        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3421        bts1.set_neighbor_cell_name("GSM", 2, "GSM_850_C251_F893_CID59")
3422        set_usim_parameters(self.md8475a, self.ad.sim_card)
3423        self.md8475a.start_simulation()
3424
3425        self.ad.droid.telephonyToggleDataConnection(False)
3426        if not ensure_network_rat(
3427                self.log,
3428                self.ad,
3429                NETWORK_MODE_GSM_ONLY,
3430                RAT_FAMILY_GSM,
3431                toggle_apm_after_setting=True):
3432            self.log.error("Failed to set rat family {}, preferred network:{}".
3433                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3434            return False
3435        self.md8475a.wait_for_registration_state()
3436        self.setup_3710a_waveform("1", "A", "869MHz", neighbor_cell_1['power'],
3437                                  "GSM", "gsm_lac58_cid58")
3438
3439        self.setup_3710a_waveform("2", "A", "893MHz", neighbor_cell_2['power'],
3440                                  "GSM", "gsm_lac59_cid59")
3441        self.turn_on_3710a_sg(1)
3442        self.turn_on_3710a_sg(2)
3443        time.sleep(self._SETTLING_TIME)
3444        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3445
3446    @test_tracker_info(uuid="209f62c1-7950-447c-9101-abe930da20ba")
3447    @TelephonyBaseTest.tel_test_wrap
3448    def test_neighbor_cell_reporting_gsm_interrat_2_tmo(self):
3449        """ Test Number of neighbor cells reported by Phone when no neighbor
3450        cells(inter RAT) are present (Phone camped on GSM)
3451
3452        Setup one GSM cell configuration on MD8475A
3453        Setup one LTE and one GSM waveforms on MG3710A
3454        Make Sure Phone camped on GSM
3455        Verify the number of neighbor cells reported by Phone
3456
3457        Returns:
3458            True if pass; False if fail
3459        """
3460        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3461        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid1_cell
3462        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid31_cell
3463        serving_cell['power'] = -20
3464        neighbor_cell_1['power'] = -24
3465        neighbor_cell_2['power'] = -22
3466
3467        expected_cell_info_list = [
3468            # Serving Cell
3469            {
3470                self.CID: serving_cell[self.CID],
3471                self.REPORT_RATE: 1,
3472                self.IS_REGISTERED: True,
3473                self.RAT: 'gsm',
3474                self.TARGET_RSSI:
3475                self._GSM_RSSI_OFFSET + serving_cell['power'],
3476                self.MAX_ERROR_RSSI: 3,
3477                self.MAX_ERROR_AVERAGE_RSSI: 3
3478            },
3479            # Neighbor Cells
3480            {
3481                self.PCID: neighbor_cell_1[self.PCID],
3482                self.REPORT_RATE: 0.1,
3483                self.IS_REGISTERED: False,
3484                self.RAT: 'lte',
3485                self.TARGET_RSSI:
3486                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
3487                self.MAX_ERROR_RSSI: 4,
3488                self.MAX_ERROR_AVERAGE_RSSI: 3
3489            },
3490            {
3491                self.PSC: neighbor_cell_2[self.PSC],
3492                self.REPORT_RATE: 0.1,
3493                self.IS_REGISTERED: False,
3494                self.RAT: 'wcdma',
3495                self.TARGET_RSSI:
3496                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
3497                self.MAX_ERROR_RSSI: 4,
3498                self.MAX_ERROR_AVERAGE_RSSI: 3
3499            }
3500        ]
3501        expected_cell_info_stats = {}
3502        for sample in expected_cell_info_list:
3503            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3504
3505        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3506        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3507                                      self.ad.sim_card)
3508        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3509        bts1.neighbor_cell_mode = "USERDATA"
3510        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
3511        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
3512        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
3513        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID31")
3514        set_usim_parameters(self.md8475a, self.ad.sim_card)
3515        self.md8475a.start_simulation()
3516        self.ad.droid.telephonyToggleDataConnection(False)
3517        if not ensure_network_rat(
3518                self.log,
3519                self.ad,
3520                NETWORK_MODE_GSM_ONLY,
3521                RAT_FAMILY_GSM,
3522                toggle_apm_after_setting=True):
3523            self.log.error("Failed to set rat family {}, preferred network:{}".
3524                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3525            return False
3526        self.md8475a.wait_for_registration_state()
3527        self.setup_3710a_waveform("1", "A", "2115MHz",
3528                                  neighbor_cell_1['power'], "LTE",
3529                                  "lte_1_ch2000_pcid1")
3530
3531        self.setup_3710a_waveform("2", "A", "2140MHz",
3532                                  neighbor_cell_2['power'], "WCDMA",
3533                                  "wcdma_1_psc31_cid31")
3534        self.turn_on_3710a_sg(1)
3535        self.turn_on_3710a_sg(2)
3536        time.sleep(self._SETTLING_TIME)
3537        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3538
3539    """ Tests End """
3540