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 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
20and config_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 enabled for the target device.
23
24The device requirements:
25  support 5G: true
26  using DFS channels for peer network(target device): true
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 SccDfs5gHotspotStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
49  """Test class for SCC with Hotspot on a 5G DFS channel."""
50
51  def _get_country_code(self) -> str:
52    return 'GB'
53
54  def setup_class(self):
55    super().setup_class()
56    self.performance_test_iterations = getattr(
57        self.test_scc_dfs_5g_hotspot_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.SCC_PERFORMANCE_TEST_COUNT,
65      max_consecutive_error=nc_constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
66  )
67  def test_scc_dfs_5g_hotspot_sta(self):
68    """Test the performance for wifi SCC with DFS 5G Hotspot and STA."""
69    self._test_connection_medium_performance(
70        nc_constants.NearbyMedium.UPGRADE_TO_WIFIHOTSPOT,
71        wifi_ssid=self.test_parameters.wifi_dfs_5g_ssid,
72        wifi_password=self.test_parameters.wifi_dfs_5g_password,
73    )
74
75  def _get_file_transfer_failure_tip(self) -> str:
76    return (
77        'The Wifi Hotspot 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}. This is 5G SCC DFS hotspot test case.'
84        ' Check STA and WFD GO frequencies in the target logs (dumpsys'
85        ' wifip2p) and ensure they have the same value. In the configuration'
86        ' file, enable_sta_dfs_channel_for_peer_network is set to true. Check'
87        ' if the target device does support WFD group owner in the'
88        ' STA-associated DFS channel. Check if'
89        ' config_wifiEnableStaDfsChannelForPeerNetwork'
90        ' https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml'
91        ' is set to true and has the correct driver/FW implementation.'
92    )
93
94  def _is_wifi_ap_ready(self) -> bool:
95    return True if self.test_parameters.wifi_dfs_5g_ssid else False
96
97  @property
98  def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]:
99    return {
100        'discoverer': {
101            'supports_5g': True,
102        },
103        'advertiser': {
104            'supports_5g': True,
105            'enable_sta_dfs_channel_for_peer_network': True,
106        },
107    }
108
109
110if __name__ == '__main__':
111  test_runner.main()
112