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 in a general case.
16
17In this case, both the WFD and WLAN are using the smae 2G channel
18Note that The country code is set to JP so that 5G is not available for
19any D2D mediums.
20
21The device requirements: N/A.
22"""
23
24import datetime
25import logging
26import os
27import sys
28
29# Allows local imports to be resolved via relative path, so the test can be run
30# without building.
31_betocq_dir = os.path.dirname(os.path.dirname(__file__))
32if _betocq_dir not in sys.path:
33  sys.path.append(_betocq_dir)
34
35from mobly  import base_test
36from mobly import test_runner
37
38from betocq import d2d_performance_test_base
39from betocq import nc_constants
40
41
42class Scc2gWfdStaTest(d2d_performance_test_base.D2dPerformanceTestBase):
43  """Test class for Wifi SCC with 2G WFD and STA."""
44
45  def _get_country_code(self) -> str:
46    return 'JP'
47
48  def setup_class(self):
49    super().setup_class()
50    self._is_2g_d2d_wifi_medium = True
51    self.performance_test_iterations = getattr(
52        self.test_scc_2g_wfd_sta, base_test.ATTR_REPEAT_CNT
53    )
54    logging.info(
55        'performance test iterations: %s', self.performance_test_iterations
56    )
57
58  @base_test.repeat(
59      count=nc_constants.SCC_PERFORMANCE_TEST_COUNT,
60      max_consecutive_error=nc_constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR,
61  )
62  def test_scc_2g_wfd_sta(self):
63    """Test the performance for Wifi SCC with 2G WFD and STA."""
64    self._test_connection_medium_performance(
65        nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT,
66        wifi_ssid=self.test_parameters.wifi_2g_ssid,
67        wifi_password=self.test_parameters.wifi_2g_password,
68    )
69
70  def _get_transfer_file_size(self) -> int:
71    # For 2G wifi medium
72    return nc_constants.TRANSFER_FILE_SIZE_20MB
73
74  def _get_file_transfer_timeout(self) -> datetime.timedelta:
75    return nc_constants.WIFI_2G_20M_PAYLOAD_TRANSFER_TIMEOUT
76
77  def _get_file_transfer_failure_tip(self) -> str:
78    return (
79        'The Wifi Direct connection might be broken, check related logs, '
80        f'{self._get_throughput_low_tip()}'
81    )
82
83  def _get_throughput_low_tip(self) -> str:
84    return (
85        f'{self._throughput_low_string}.'
86        ' This is a SCC 2G test case with WFD medium. Check with the wifi chip'
87        ' vendor about the possible firmware Tx/Rx issues in this mode.'
88    )
89
90  def _is_wifi_ap_ready(self) -> bool:
91    return True if self.test_parameters.wifi_2g_ssid else False
92
93if __name__ == '__main__':
94  test_runner.main()
95