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 with the DFS channels case.
16
17This is about the feature - using DFS channels for WFD, for details, refer to
18https://docs.google.com/presentation/d/18Fl0fY4piq_sfXfo3rCr2Ca55AJHEOvB7rC-rV3SQ9E/edit?usp=sharing
19and config_wifiEnableStaDfsChannelForPeerNetwork -
20https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml;l=1151
21In this case, the feature is disable for the device; The STA is using the DFS 5G
22channel, but the WFD will be started on another 5G channel.
23
24The device requirements:
25  support 5G: true
26  using DFS channels for peer network: false
27The AP requirements:
28  wifi channel: 52 (5260)
29"""
30
31import logging
32import os
33import sys
34
35# Allows local imports to be resolved via relative path, so the test can be run
36# without building.
37_betocq_dir = os.path.dirname(os.path.dirname(__file__))
38if _betocq_dir not in sys.path:
39  sys.path.append(_betocq_dir)
40
41from mobly  import base_test
42from mobly import test_runner
43
44from betocq import d2d_performance_test_base
45from betocq import nc_constants
46
47
48class Mcc5gWfdDfs5gStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
49  """Test class for MCC with 5G WFD and DFS 5G STA."""
50
51  def _get_country_code(self) -> str:
52    return 'GB'
53
54  def setup_class(self):
55    super().setup_class()
56    self._is_mcc = True
57    self.performance_test_iterations = getattr(
58        self.test_mcc_5g_wfd_dfs_5g_sta, base_test.ATTR_REPEAT_CNT
59    )
60    logging.info(
61        'performance test iterations: %s', self.performance_test_iterations
62    )
63
64  @base_test.repeat(
65      count=nc_constants.MCC_PERFORMANCE_TEST_COUNT,
66      max_consecutive_error=nc_constants.MCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
67  )
68  def test_mcc_5g_wfd_dfs_5g_sta(self):
69    """Test the performance for wifi MCC with 5G WFD and DFS 5G STA."""
70    self._test_connection_medium_performance(
71        nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT,
72        wifi_ssid=self.test_parameters.wifi_dfs_5g_ssid,
73        wifi_password=self.test_parameters.wifi_dfs_5g_password,
74    )
75
76  def _get_file_transfer_failure_tip(self) -> str:
77    return (
78        'The Wifi Direct connection might be broken, check the related log, '
79        f'{self._get_throughput_low_tip()}'
80    )
81
82  def _get_throughput_low_tip(self) -> str:
83    return (
84        f'{self._throughput_low_string}. This is a MCC test case where WFD uses'
85        ' a 5G non-DFS channel and STA uses a5G DFS channel. Check with the'
86        ' wifi chip vendorabout 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_dfs_5g_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            'enable_sta_dfs_channel_for_peer_network': False,
101        },
102    }
103
104
105if __name__ == '__main__':
106  test_runner.main()
107