1#  Copyright (C) 2024 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15"""This Test is to test the Wifi SCC in a general case.
16
17In this case, even though the expected wifi medium is the WFD, but the wifi D2D
18could be any mediums, such as WFD, HOTSPOT, STA; Once the WFD is failed, other
19mediums will be tried. Also, though the WLAN is connected with 2G channel,
20as the devices support DBS, which don't need to switch between 5G and 2G, it is
21still a SCC case.
22
23The device requirements:
24  support 5G: true
25  support DBS (target device): true
26The AP requirements:
27  wifi channel: 6 (2437)
28"""
29
30import logging
31import os
32import sys
33
34# Allows local imports to be resolved via relative path, so the test can be run
35# without building.
36_betocq_dir = os.path.dirname(os.path.dirname(__file__))
37if _betocq_dir not in sys.path:
38  sys.path.append(_betocq_dir)
39
40from mobly  import base_test
41from mobly import test_runner
42
43from betocq import d2d_performance_test_base
44from betocq import nc_constants
45
46
47class Scc5gAllWifiDbs2gStaTest(
48    d2d_performance_test_base.D2dPerformanceTestBase):
49  """Test class for CUJ SCC with 5G D2D medium and 2G WLAN test.
50  """
51
52  def _get_country_code(self) -> str:
53    return 'US'
54
55  def setup_class(self):
56    super().setup_class()
57    self._is_dbs_mode = True
58    self.performance_test_iterations = getattr(
59        self.test_scc_5g_all_wifi_dbs_2g_sta, base_test.ATTR_REPEAT_CNT
60    )
61    logging.info(
62        'performance test iterations: %s', self.performance_test_iterations
63    )
64
65  @base_test.repeat(
66      count=nc_constants.SCC_PERFORMANCE_TEST_COUNT,
67      max_consecutive_error=nc_constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
68  )
69  def test_scc_5g_all_wifi_dbs_2g_sta(self):
70    self._test_connection_medium_performance(
71        upgrade_medium_under_test=nc_constants.NearbyMedium.UPGRADE_TO_ALL_WIFI,
72        wifi_ssid=self.test_parameters.wifi_2g_ssid,
73        wifi_password=self.test_parameters.wifi_2g_password,
74    )
75
76  def _get_file_transfer_failure_tip(self) -> str:
77    upgraded_medium_name = None
78    if (self._current_test_result.quality_info.upgrade_medium
79        is not None):
80      upgraded_medium_name = (
81          self._current_test_result.quality_info.upgrade_medium.name
82      )
83    return (
84        f'The upgraded wifi medium {upgraded_medium_name} might be broken, '
85        f'check the related log, Or {self._get_throughput_low_tip()}'
86    )
87
88  def _get_throughput_low_tip(self) -> str:
89    upgraded_medium_name = None
90    if (self._current_test_result.quality_info.upgrade_medium
91        is not None):
92      upgraded_medium_name = (
93          self._current_test_result.quality_info.upgrade_medium.name
94      )
95    return (
96        f'{self._throughput_low_string}. The upgraded medium is'
97        f' {upgraded_medium_name}. This is a 5G SCC DBS case, In the'
98        ' configuration file, DBS support is set to true on the target side.'
99        ' Check if the device does support DBS with STA + WFD concurrency.'
100    )
101
102  def _is_wifi_ap_ready(self) -> bool:
103    return True if self.test_parameters.wifi_2g_ssid else False
104
105  @property
106  def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]:
107    return {
108        'discoverer': {
109            'supports_5g': True,
110        },
111        'advertiser': {
112            'supports_5g': True,
113            'supports_dbs_sta_wfd': True,
114        },
115    }
116
117
118if __name__ == '__main__':
119  test_runner.main()
120