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