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, the WFD is using the 5G channel, but STA is connected to 2G
18channel, as the device(don't support DBS) can not handle the 5G and 2G at
19the same time, there is concurrent contention for the 5G channel and 2G
20channel handling in firmware, the firmware needs to switch 5G and 2G from time
21to time.
22
23The device requirements:
24  support 5G: true
25  support DBS(Target Device): False
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 Mcc5gWfdNonDbs2gStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
48  """Test class for MCC case with 5G WFD and 2G STA."""
49
50  def _get_country_code(self) -> str:
51    return 'US'
52
53  def setup_class(self):
54    super().setup_class()
55    self._is_mcc = True
56    self.performance_test_iterations = getattr(
57        self.test_mcc_5g_wfd_non_dbs_2g_sta, base_test.ATTR_REPEAT_CNT
58    )
59    logging.info(
60        'performance test iterations: %s', self.performance_test_iterations
61    )
62
63  @base_test.repeat(
64      count=nc_constants.MCC_PERFORMANCE_TEST_COUNT,
65      max_consecutive_error=nc_constants.MCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
66  )
67  def test_mcc_5g_wfd_non_dbs_2g_sta(self):
68    """Test the performance for wifi MCC with 5G WFD and 2G STA."""
69    self._test_connection_medium_performance(
70        nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT,
71        wifi_ssid=self.test_parameters.wifi_2g_ssid,
72        wifi_password=self.test_parameters.wifi_2g_password,
73    )
74
75  def _get_file_transfer_failure_tip(self) -> str:
76    return (
77        'The Wifi Direct connection might be broken, check related logs, '
78        f'{self._get_throughput_low_tip()}'
79    )
80
81  def _get_throughput_low_tip(self) -> str:
82    return (
83        f'{self._throughput_low_string}.'
84        ' This is a MCC test case where WFD uses a 5G channel and STA uses a'
85        ' 2G channel. Check with the wifi chip vendor'
86        ' about the possible firmware Tx/Rx issues in MCC mode.'
87    )
88
89  def _is_wifi_ap_ready(self) -> bool:
90    return True if self.test_parameters.wifi_2g_ssid else False
91
92  @property
93  def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]:
94    return {
95        'discoverer': {
96            'supports_5g': True,
97        },
98        'advertiser': {
99            'supports_5g': True,
100            'supports_dbs_sta_wfd': False,
101        },
102    }
103
104
105if __name__ == '__main__':
106  test_runner.main()
107