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 MCC in a general case.
16
17In this case, even though the STA is connected to a 2G channel, and the WFD is
18using the 5G channel, as both devices support DBS, which can handle the 5G and
192G at the same time, this is still a SCC case.
20
21The device requirements:
22  support 5G: true
23  support DBS(target): true
24The AP requirements:
25  wifi channel: 6 (2437)
26"""
27
28import logging
29import os
30import sys
31
32# Allows local imports to be resolved via relative path, so the test can be run
33# without building.
34_betocq_dir = os.path.dirname(os.path.dirname(__file__))
35if _betocq_dir not in sys.path:
36  sys.path.append(_betocq_dir)
37
38from mobly  import base_test
39from mobly import test_runner
40
41from betocq import d2d_performance_test_base
42from betocq import nc_constants
43
44
45class Scc5gWfdDbs2gStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
46  """Test class for SCC with 5G WFD and 2G STA."""
47
48  def _get_country_code(self) -> str:
49    return 'US'
50
51  def setup_class(self):
52    super().setup_class()
53    self._is_dbs_mode = True
54    self.performance_test_iterations = getattr(
55        self.test_scc_5g_wfd_dbs_2g_sta, base_test.ATTR_REPEAT_CNT
56    )
57    logging.info(
58        'performance test iterations: %s', self.performance_test_iterations
59    )
60
61  @base_test.repeat(
62      count=nc_constants.SCC_PERFORMANCE_TEST_COUNT,
63      max_consecutive_error=nc_constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
64  )
65  def test_scc_5g_wfd_dbs_2g_sta(self):
66    """Test the performance for wifi SCC with 5G WFD and 2G STA."""
67    self._test_connection_medium_performance(
68        nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT,
69        wifi_ssid=self.test_parameters.wifi_2g_ssid,
70        wifi_password=self.test_parameters.wifi_2g_password,
71    )
72
73  def _get_file_transfer_failure_tip(self) -> str:
74    return (
75        'The Wifi Direct connection might be broken, check related logs, '
76        f'{self._get_throughput_low_tip()}'
77    )
78
79  def _get_throughput_low_tip(self) -> str:
80    return (
81        f'{self._throughput_low_string}. This is a SCC 5G test case with WFD'
82        ' medium operating at 5G and STA operating at 2G. In the configuration'
83        ' file, DBS support is set to true. Check if the device does support'
84        ' DBS with STA + WFD concurrency. Check with the wifi chipvendor about'
85        ' the possible firmware Tx/Rx issues in this mode.'
86    )
87
88  def _is_wifi_ap_ready(self) -> bool:
89    return True if self.test_parameters.wifi_2g_ssid else False
90
91  @property
92  def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]:
93    return {
94        'discoverer': {
95            'supports_5g': True,
96        },
97        'advertiser': {
98            'supports_5g': True,
99            'supports_dbs_sta_wfd': True,
100        },
101    }
102
103
104if __name__ == '__main__':
105  test_runner.main()
106