• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import time
2
3from acts import asserts
4from acts import signals
5from acts.base_test import BaseTestClass
6from acts.utils import get_current_epoch_time
7from acts_contrib.test_utils.gnss import gnss_constant
8from acts_contrib.test_utils.gnss import gnss_test_utils as gutils
9from acts_contrib.test_utils.gnss.testtracker_util import log_testtracker_uuid
10from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
11from acts_contrib.test_utils.tel import tel_logging_utils
12from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
13from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
14
15
16class GnssVendorFeaturesTest(BaseTestClass):
17    """Validate vendor specific features."""
18    def setup_class(self):
19        super().setup_class()
20        self.ad = self.android_devices[0]
21        req_params = ["pixel_lab_network", "default_gnss_signal_attenuation", "pixel_lab_location",
22                      "qdsp6m_path", "collect_logs", "ttff_test_cycle", "standalone_cs_criteria",
23                      "xtra_cs_criteria",  "xtra_ws_criteria", "xtra_hs_criteria",
24                      "set_attenuator"]
25        self.unpack_userparams(req_param_names=req_params)
26        # create hashmap for SSID
27        self.ssid_map = {}
28        for network in self.pixel_lab_network:
29            SSID = network["SSID"]
30            self.ssid_map[SSID] = network
31        self.init_device()
32
33    def init_device(self):
34        """Init GNSS test devices for vendor features suite."""
35        gutils._init_device(self.ad)
36        gutils.disable_supl_mode(self.ad)
37        gutils.enable_vendor_orbit_assistance_data(self.ad)
38        gutils.reboot(self.ad)
39
40    def setup_test(self):
41        gutils.log_current_epoch_time(self.ad, "test_start_time")
42        log_testtracker_uuid(self.ad, self.current_test_name)
43        gutils.clear_logd_gnss_qxdm_log(self.ad)
44        gutils.get_baseband_and_gms_version(self.ad)
45        toggle_airplane_mode(self.ad.log, self.ad, new_state=False)
46        if gutils.is_wearable_btwifi(self.ad):
47            wutils.wifi_toggle_state(self.ad, True)
48            gutils.connect_to_wifi_network(self.ad,
49                                           self.ssid_map[self.pixel_lab_network[0]["SSID"]])
50        else:
51            wutils.wifi_toggle_state(self.ad, False)
52            gutils.set_mobile_data(self.ad, state=True)
53        if not verify_internet_connection(self.ad.log, self.ad, retries=3,
54                                          expected_state=True):
55            raise signals.TestFailure("Fail to connect to internet.")
56
57    def teardown_test(self):
58        if self.collect_logs:
59            gutils.stop_pixel_logger(self.ad)
60            tel_logging_utils.stop_adb_tcpdump(self.ad)
61        if self.set_attenuator:
62            gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
63                                              self.default_gnss_signal_attenuation)
64        gutils.log_current_epoch_time(self.ad, "test_end_time")
65
66    def on_fail(self, test_name, begin_time):
67        if self.collect_logs:
68            self.ad.take_bug_report(test_name, begin_time)
69            gutils.get_gnss_qxdm_log(self.ad, self.qdsp6m_path)
70            tel_logging_utils.get_tcpdump_log(self.ad, test_name, begin_time)
71
72    def connect_to_wifi_with_airplane_mode_on(self):
73        self.ad.log.info("Turn airplane mode on")
74        toggle_airplane_mode(self.ad.log, self.ad, new_state=True)
75        wutils.wifi_toggle_state(self.ad, True)
76        gutils.connect_to_wifi_network(self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
77
78    def ttff_with_assist(self, mode, criteria):
79        """Verify CS/WS TTFF functionality with Assist data.
80
81        Args:
82            mode: "csa" or "ws"
83            criteria: Criteria for the test.
84        """
85        begin_time = get_current_epoch_time()
86        gutils.process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
87        gutils.check_xtra_download(self.ad, begin_time)
88        self.ad.log.info("Turn airplane mode on")
89        toggle_airplane_mode(self.ad.log, self.ad, new_state=True)
90        gutils.start_gnss_by_gtw_gpstool(self.ad, True)
91        gutils.start_ttff_by_gtw_gpstool(self.ad, mode, iteration=self.ttff_test_cycle)
92        ttff_data = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time, self.pixel_lab_location)
93        result = gutils.check_ttff_data(self.ad, ttff_data, mode, criteria)
94        asserts.assert_true(
95            result, "TTFF %s fails to reach designated criteria of %d "
96                    "seconds." % (gnss_constant.TTFF_MODE.get(mode), criteria))
97
98    def test_xtra_ttff_cs_mobile_data(self):
99        """Verify XTRA/LTO functionality of TTFF Cold Start with mobile data.
100
101        Steps:
102            1. TTFF Cold Start for 10 iteration.
103
104        Expected Results:
105            XTRA/LTO TTFF Cold Start results should be within xtra_cs_criteria.
106        """
107        gutils.run_ttff(self.ad, mode="cs", criteria=self.xtra_cs_criteria,
108                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
109                        collect_logs=self.collect_logs)
110
111    def test_xtra_ttff_ws_mobile_data(self):
112        """Verify XTRA/LTO functionality of TTFF Warm Start with mobile data.
113
114        Steps:
115            1. TTFF Warm Start for 10 iteration.
116
117        Expected Results:
118            XTRA/LTO TTFF Warm Start results should be within xtra_ws_criteria.
119        """
120        gutils.run_ttff(self.ad, mode="ws", criteria=self.xtra_ws_criteria,
121                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
122                        collect_logs=self.collect_logs)
123
124    def test_xtra_ttff_hs_mobile_data(self):
125        """Verify XTRA/LTO functionality of TTFF Hot Start with mobile data.
126
127        Steps:
128            1. TTFF Hot Start for 10 iteration.
129
130        Expected Results:
131            XTRA/LTO TTFF Hot Start results should be within xtra_hs_criteria.
132        """
133        gutils.run_ttff(self.ad, mode="hs", criteria=self.xtra_hs_criteria,
134                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
135                        collect_logs=self.collect_logs)
136
137    def test_xtra_ttff_cs_wifi(self):
138        """Verify XTRA/LTO functionality of TTFF Cold Start with WiFi.
139
140        Steps:
141            1. Turn airplane mode on.
142            2. Connect to WiFi.
143            3. TTFF Cold Start for 10 iteration.
144
145        Expected Results:
146            XTRA/LTO TTFF Cold Start results should be within
147            xtra_cs_criteria.
148        """
149        self.connect_to_wifi_with_airplane_mode_on()
150        gutils.run_ttff(self.ad, mode="cs", criteria=self.xtra_cs_criteria,
151                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
152                        collect_logs=self.collect_logs)
153
154    def test_xtra_ttff_ws_wifi(self):
155        """Verify XTRA/LTO functionality of TTFF Warm Start with WiFi.
156
157        Steps:
158            1. Turn airplane mode on.
159            2. Connect to WiFi.
160            3. TTFF Warm Start for 10 iteration.
161
162        Expected Results:
163            XTRA/LTO TTFF Warm Start results should be within xtra_ws_criteria.
164        """
165        self.connect_to_wifi_with_airplane_mode_on()
166        gutils.run_ttff(self.ad, mode="ws", criteria=self.xtra_ws_criteria,
167                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
168                        collect_logs=self.collect_logs)
169
170    def test_xtra_ttff_hs_wifi(self):
171        """Verify XTRA/LTO functionality of TTFF Hot Start with WiFi.
172
173        Steps:
174            1. Turn airplane mode on.
175            2. Connect to WiFi.
176            3. TTFF Hot Start for 10 iteration.
177
178        Expected Results:
179            XTRA/LTO TTFF Hot Start results should be within xtra_hs_criteria.
180        """
181        self.connect_to_wifi_with_airplane_mode_on()
182        gutils.run_ttff(self.ad, mode="hs", criteria=self.xtra_hs_criteria,
183                        test_cycle=self.ttff_test_cycle, base_lat_long=self.pixel_lab_location,
184                        collect_logs=self.collect_logs)
185
186    def test_xtra_download_mobile_data(self):
187        """Verify XTRA/LTO data could be downloaded via mobile data.
188
189        Steps:
190            1. Delete all GNSS aiding data.
191            2. Get location fixed.
192            3. Verify whether XTRA/LTO is downloaded and injected.
193            4. Repeat Step 1. to Step 3. for 5 times.
194
195        Expected Results:
196            XTRA/LTO data is properly downloaded and injected via mobile data.
197        """
198        mobile_xtra_result_all = []
199        gutils.start_qxdm_and_tcpdump_log(self.ad, self.collect_logs)
200        for i in range(1, 6):
201            begin_time = get_current_epoch_time()
202            gutils.process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
203            time.sleep(5)
204            gutils.start_gnss_by_gtw_gpstool(self.ad, False)
205            mobile_xtra_result = gutils.check_xtra_download(self.ad, begin_time)
206            self.ad.log.info("Iteration %d => %s" % (i, mobile_xtra_result))
207            mobile_xtra_result_all.append(mobile_xtra_result)
208        asserts.assert_true(all(mobile_xtra_result_all),
209                            "Fail to Download and Inject XTRA/LTO File.")
210
211    def test_xtra_download_wifi(self):
212        """Verify XTRA/LTO data could be downloaded via WiFi.
213
214        Steps:
215            1. Connect to WiFi.
216            2. Delete all GNSS aiding data.
217            3. Get location fixed.
218            4. Verify whether XTRA/LTO is downloaded and injected.
219            5. Repeat Step 2. to Step 4. for 5 times.
220
221        Expected Results:
222            XTRA data is properly downloaded and injected via WiFi.
223        """
224        wifi_xtra_result_all = []
225        gutils.start_qxdm_and_tcpdump_log(self.ad, self.collect_logs)
226        self.connect_to_wifi_with_airplane_mode_on()
227        for i in range(1, 6):
228            begin_time = get_current_epoch_time()
229            gutils.process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
230            time.sleep(5)
231            gutils.start_gnss_by_gtw_gpstool(self.ad, False)
232            wifi_xtra_result = gutils.check_xtra_download(self.ad, begin_time)
233            wifi_xtra_result_all.append(wifi_xtra_result)
234            self.ad.log.info("Iteration %d => %s" % (i, wifi_xtra_result))
235        asserts.assert_true(all(wifi_xtra_result_all),
236                            "Fail to Download and Inject XTRA/LTO File.")
237
238    def test_lto_download_after_reboot(self):
239        """Verify LTO data could be downloaded and injected after device reboot.
240
241        Steps:
242            1. Reboot device.
243            2. Verify whether LTO is auto downloaded and injected without trigger GPS.
244            3. Repeat Step 1 to Step 2 for 5 times.
245
246        Expected Results:
247            LTO data is properly downloaded and injected at the first time tether to phone.
248        """
249        reboot_lto_test_results_all = []
250        for times in range(1, 6):
251            gutils.delete_lto_file(self.ad)
252            gutils.reboot(self.ad)
253            gutils.start_qxdm_and_tcpdump_log(self.ad, self.collect_logs)
254            # Wait 20 seconds for boot busy and lto auto-download time
255            time.sleep(20)
256            begin_time = get_current_epoch_time()
257            reboot_lto_test_result = gutils.check_xtra_download(self.ad, begin_time)
258            self.ad.log.info("Iteration %d => %s" % (times, reboot_lto_test_result))
259            reboot_lto_test_results_all.append(reboot_lto_test_result)
260            gutils.stop_pixel_logger(self.ad)
261            tel_logging_utils.stop_adb_tcpdump(self.ad)
262        asserts.assert_true(all(reboot_lto_test_results_all),
263                                "Fail to Download and Inject LTO File.")
264
265    def test_ws_with_assist(self):
266        """Verify Warm Start functionality with existed LTO data.
267
268        Steps:
269            2. Make LTO is downloaded.
270            3. Turn on AirPlane mode to make sure there's no network connection.
271            4. TTFF Warm Start with Assist for 10 iteration.
272
273        Expected Results:
274            All TTFF Warm Start with Assist results should be within
275            xtra_ws_criteria.
276        """
277        self.ttff_with_assist("ws", self.xtra_ws_criteria)
278
279    def test_cs_with_assist(self):
280        """Verify Cold Start functionality with existed LTO data.
281
282        Steps:
283            2. Make sure LTO is downloaded.
284            3. Turn on AirPlane mode to make sure there's no network connection.
285            4. TTFF Cold Start with Assist for 10 iteration.
286
287        Expected Results:
288            All TTFF Cold Start with Assist results should be within
289            standalone_cs_criteria.
290        """
291        self.ttff_with_assist("csa", self.standalone_cs_criteria)
292