1#!/usr/bin/env python3
2#
3#   Copyright 2021 - 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"""Lab GNSS Hot Start Sensitivity Test"""
17
18import os
19from acts_contrib.test_utils.gnss.GnssBlankingBase import GnssBlankingBase
20from acts_contrib.test_utils.gnss.dut_log_test_utils import get_gpstool_logs
21from acts_contrib.test_utils.gnss.gnss_test_utils import execute_eecoexer_function
22
23
24class GnssHsSenTest(GnssBlankingBase):
25    """ LAB GNSS Cellular coex hot start sensitivity search"""
26
27    def __init__(self, controllers):
28        super().__init__(controllers)
29        self.cell_tx_ant = None
30        self.cell_pwr = None
31        self.eecoex_func = ''
32        self.coex_stop_cmd = ''
33        self.coex_params = {}
34
35    def setup_class(self):
36        super().setup_class()
37        self.coex_params = self.user_params.get('coex_params', {})
38        self.cell_tx_ant = self.coex_params.get('cell_tx_ant', 'PRIMARY')
39        self.cell_pwr = self.coex_params.get('cell_pwr', 'Infinity')
40
41    def gnss_hot_start_sensitivity_search_base(self, coex_enable=False):
42        """
43        Perform GNSS hot start sensitivity search.
44
45        Args:
46                cellular_enable: argument to identify if Tx cellular signal is required or not.
47                Type, bool.
48                Default, False.
49        """
50        # Get parameters from user_params.
51        first_wait = self.user_params.get('first_wait', 300)
52        wait_between_pwr = self.user_params.get('wait_between_pwr', 60)
53        ttft_iteration = self.user_params.get('ttff_iteration', 25)
54
55        # Start the test item with gnss_init_power_setting.
56        ret, pwr_lvl = self.gnss_init_power_setting(first_wait)
57        if ret:
58            self.log.info(f'Successfully set the GNSS power level to {pwr_lvl}')
59            # Create gnss log folders for init and cellular sweep
60            gnss_init_log_dir = os.path.join(self.gnss_log_path, 'GNSS_init')
61
62            # Pull all exist GPStool logs into GNSS_init folder
63            get_gpstool_logs(self.dut, gnss_init_log_dir, False)
64        if coex_enable:
65            self.log.info('Start coexistence test.')
66            eecoex_cmd_file_str = self.eecoex_func.replace(',', '_')
67            execute_eecoexer_function(self.dut, self.eecoex_func)
68        else:
69            self.log.info('Start stand alone test.')
70            eecoex_cmd_file_str = 'Stand_alone'
71        for i, gnss_pwr_swp in enumerate(self.gnss_pwr_sweep_fine_sweep_ls):
72            self.log.info(f'Start fine GNSS power level sweep part {i + 1}')
73            result, sensitivity = self.hot_start_gnss_power_sweep(
74                gnss_pwr_swp, wait_between_pwr, ttft_iteration, True,
75                eecoex_cmd_file_str)
76            if not result:
77                break
78        self.log.info(f'The sensitivity level is: {sensitivity}')
79
80    def test_hot_start_sensitivity_search(self):
81        """
82        GNSS hot start stand alone sensitivity search.
83        """
84        self.gnss_hot_start_sensitivity_search_base(False)
85
86    def test_hot_start_sensitivity_search_gsm850(self):
87        """
88        GNSS hot start GSM850 Ch190 coexistence sensitivity search.
89        """
90        self.eecoex_func = f'CELLR,2,850,190,1,{self.cell_tx_ant},{self.cell_pwr}'
91        self.coex_stop_cmd = 'CELLR,19'
92        msg = f'Running GSM850 with {self.cell_tx_ant} antenna \
93                and GNSS coexistence sensitivity search.'
94
95        self.log.info(msg)
96        self.gnss_hot_start_sensitivity_search_base(True)
97
98    def test_hot_start_sensitivity_search_gsm900(self):
99        """
100        GNSS hot start GSM900 Ch20 coexistence sensitivity search.
101        """
102        self.eecoex_func = f'CELLR,2,900,20,1,{self.cell_tx_ant},{self.cell_pwr}'
103        self.coex_stop_cmd = 'CELLR,19'
104        msg = f'Running GSM900 with {self.cell_tx_ant} \
105                antenna and GNSS coexistence sensitivity search.'
106
107        self.log.info(msg)
108        self.gnss_hot_start_sensitivity_search_base(True)
109
110    def test_hot_start_sensitivity_search_gsm1800(self):
111        """
112        GNSS hot start GSM1800 Ch699 coexistence sensitivity search.
113        """
114        self.eecoex_func = f'CELLR,2,1800,699,1,{self.cell_tx_ant},{self.cell_pwr}'
115        self.coex_stop_cmd = 'CELLR,19'
116        msg = f'Running GSM1800 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
117        self.log.info(msg)
118        self.gnss_hot_start_sensitivity_search_base(True)
119
120    def test_hot_start_sensitivity_search_gsm1900(self):
121        """
122        GNSS hot start GSM1900 Ch661 coexistence sensitivity search.
123        """
124        self.eecoex_func = f'CELLR,2,1900,661,1,{self.cell_tx_ant},{self.cell_pwr}'
125        self.coex_stop_cmd = 'CELLR,19'
126        msg = f'Running GSM1900 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
127        self.log.info(msg)
128        self.gnss_hot_start_sensitivity_search_base(True)
129
130    def test_hot_start_sensitivity_search_lte_b38(self):
131        """
132        GNSS hot start LTE B38 Ch38000 coexistence sensitivity search.
133        """
134        self.eecoex_func = f'CELLR,5,38,38000,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
135        self.coex_stop_cmd = 'CELLR,19'
136        msg = f'Running LTE B38 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
137        self.log.info(msg)
138        self.gnss_hot_start_sensitivity_search_base(True)
139
140    def test_hot_start_sensitivity_search_lte_b39(self):
141        """
142        GNSS hot start LTE B39 Ch38450 coexistence sensitivity search.
143        """
144        self.eecoex_func = f'CELLR,5,39,38450,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
145        self.coex_stop_cmd = 'CELLR,19'
146        msg = f'Running LTE B38 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
147        self.log.info(msg)
148        self.gnss_hot_start_sensitivity_search_base(True)
149
150    def test_hot_start_sensitivity_search_lte_b40(self):
151        """
152        GNSS hot start LTE B40 Ch39150 coexistence sensitivity search.
153        """
154        self.eecoex_func = f'CELLR,5,40,39150,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
155        self.coex_stop_cmd = 'CELLR,19'
156        msg = f'Running LTE B38 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
157        self.log.info(msg)
158        self.gnss_hot_start_sensitivity_search_base(True)
159
160    def test_hot_start_sensitivity_search_lte_b41(self):
161        """
162        GNSS hot start LTE B41 Ch40620 coexistence sensitivity search.
163        """
164        self.eecoex_func = f'CELLR,5,41,40620,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
165        self.coex_stop_cmd = 'CELLR,19'
166        msg = f'Running LTE B41 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
167        self.log.info(msg)
168        self.gnss_hot_start_sensitivity_search_base(True)
169
170    def test_hot_start_sensitivity_search_lte_b42(self):
171        """
172        GNSS hot start LTE B42 Ch42590 coexistence sensitivity search.
173        """
174        self.eecoex_func = f'CELLR,5,42,42590,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
175        self.coex_stop_cmd = 'CELLR,19'
176        msg = f'Running LTE B42 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
177        self.log.info(msg)
178        self.gnss_hot_start_sensitivity_search_base(True)
179
180    def test_hot_start_sensitivity_search_lte_b48(self):
181        """
182        GNSS hot start LTE B48 Ch55990 coexistence sensitivity search.
183        """
184        self.eecoex_func = f'CELLR,5,48,55990,true,{self.cell_tx_ant},{self.cell_pwr},10MHz,0,12'
185        self.coex_stop_cmd = 'CELLR,19'
186        msg = f'Running LTE B48 {self.cell_tx_ant} antenna and GNSS coexistence sensitivity search.'
187        self.log.info(msg)
188        self.gnss_hot_start_sensitivity_search_base(True)
189
190    def test_hot_start_sensitivity_search_fr2_n2605(self):
191        """
192        GNSS hot start 5G NR B260 CH2234165 coexistence sensitivity search.
193        """
194        self.eecoex_func = f'CELLR,30,260,2234165,183,{self.cell_pwr}'
195        self.coex_stop_cmd = 'CELLR,19'
196        msg = 'Running 5G NR B260 CH2234165 and GNSS coexistence sensitivity search.'
197        self.log.info(msg)
198        self.gnss_hot_start_sensitivity_search_base(True)
199
200    def test_hot_start_sensitivity_custom_case(self):
201        """
202        GNSS hot start custom case coexistence sensitivity search.
203        """
204        cust_cmd = self.coex_params.get('custom_cmd', '')
205        cust_stop_cmd = self.coex_params.get('custom_stop_cmd', '')
206        if cust_cmd and cust_stop_cmd:
207            self.eecoex_func = cust_cmd
208            self.coex_stop_cmd = cust_stop_cmd
209            msg = f'Running custom {self.eecoex_func} and GNSS coexistence sensitivity search.'
210            self.log.info(msg)
211            self.gnss_hot_start_sensitivity_search_base(True)
212        else:
213            self.log.warning('No custom coex command is provided')
214