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 indoor channels case.
16
17This is about the feature - using indoor channels for WFD, for details, refer to
18https://docs.google.com/presentation/d/18Fl0fY4piq_sfXfo3rCr2Ca55AJHEOvB7rC-rV3SQ9E/edit?usp=sharing
19and config_wifiEnableStaIndoorChannelForPeerNetwork -
20https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml;l=1147
21In this case, the feature is disable for the device; The WFD will be started on
22a 2G channel, but the STA is using the 5G channel.
23
24The device requirements:
25  support 5G: true
26  using indoor channels for peer network: false
27The AP requirements:
28  wifi channel: 36 (5180)
29"""
30
31import datetime
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 Mcc2gWfdIndoor5gStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
50  """Test class for wifi MCC with 2G WFD and indoor 5G STA."""
51
52  def _get_country_code(self) -> str:
53    return 'JP'
54
55  def setup_class(self):
56    super().setup_class()
57    self._is_mcc = True
58    self._is_2g_d2d_wifi_medium = True
59    self.performance_test_iterations = getattr(
60        self.test_mcc_2g_wfd_indoor_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.SCC_PERFORMANCE_TEST_COUNT,
68      max_consecutive_error=nc_constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
69  )
70  def test_mcc_2g_wfd_indoor_5g_sta(self):
71    """Test the performance for wifi MCC with 2G WFD and indoor 5G STA."""
72    self._test_connection_medium_performance(
73        nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT,
74        wifi_ssid=self.test_parameters.wifi_5g_ssid,
75        wifi_password=self.test_parameters.wifi_5g_password,
76    )
77
78  def _get_transfer_file_size(self) -> int:
79    # For 2G wifi medium
80    return nc_constants.TRANSFER_FILE_SIZE_20MB
81
82  def _get_file_transfer_timeout(self) -> datetime.timedelta:
83    return nc_constants.WIFI_2G_20M_PAYLOAD_TRANSFER_TIMEOUT
84
85  def _get_file_transfer_failure_tip(self) -> str:
86    return (
87        'The Wifi Direct connection might be broken, check related logs, '
88        f'{self._get_throughput_low_tip()}'
89    )
90
91  def _get_throughput_low_tip(self) -> str:
92    return (
93        f'{self._throughput_low_string}. This is a MCC test case where WFD uses'
94        ' a 2G channel and the STA uses a 5G indoor channel. Check with the'
95        ' wifi chip vendor about the possible firmware Tx/Rx issues in MCC'
96        ' mode.'
97    )
98
99  def _is_wifi_ap_ready(self) -> bool:
100    return True if self.test_parameters.wifi_5g_ssid else False
101
102  @property
103  def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]:
104    return {
105        'discoverer': {
106            'supports_5g': True,
107        },
108        'advertiser': {
109            'supports_5g': True,
110            'enable_sta_indoor_channel_for_peer_network': False,
111        },
112    }
113
114
115if __name__ == '__main__':
116  test_runner.main()
117