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"""Group all function tests.""" 16 17import os 18import sys 19 20# Allows local imports to be resolved via relative path, so the test can be run 21# without building. 22_betocq_dir = os.path.dirname(os.path.dirname(__file__)) 23if _betocq_dir not in sys.path: 24 sys.path.append(_betocq_dir) 25 26from mobly import test_runner 27 28from betocq import nc_base_test 29from betocq import nc_constants 30from betocq import setup_utils 31from betocq import version 32from betocq.function_tests import bt_ble_function_test_actor 33from betocq.function_tests import bt_multiplex_function_test_actor 34from betocq.function_tests import fixed_wifi_medium_function_test_actor 35from betocq.function_tests import function_test_actor_base 36 37 38class BetoCqFunctionGroupTest(nc_base_test.NCBaseTestClass): 39 """The test class to group all function tests in one mobly test.""" 40 41 def __init__(self, configs): 42 super().__init__(configs) 43 44 self._test_result_messages: dict[str, str] = {} 45 46 def test_bt_ble_function(self): 47 """Test the NC with the BT/BLE medium only.""" 48 self._current_test_actor = self.bt_ble_test_actor 49 self.bt_ble_test_actor.test_bt_ble_connection() 50 51 def test_wifilan_function(self): 52 """Test the NC with upgrading to the Wifi LAN medium. 53 54 step 1: connect to wifi 55 step 2: set up a nearby connection with the WifiLAN medium and transfer a 56 small file. 57 """ 58 self._current_test_actor = self.fixed_wifi_medium_test_actor 59 self.fixed_wifi_medium_test_actor.connect_to_wifi() 60 self.fixed_wifi_medium_test_actor.run_fixed_wifi_medium_test( 61 nc_constants.NearbyMedium.WIFILAN_ONLY) 62 63 def test_d2d_hotspot_function(self): 64 """Test the NC with upgrading to the HOTSPOT as connection medium. 65 """ 66 self._current_test_actor = self.fixed_wifi_medium_test_actor 67 self.fixed_wifi_medium_test_actor.run_fixed_wifi_medium_test( 68 nc_constants.NearbyMedium.UPGRADE_TO_WIFIHOTSPOT) 69 70 def test_wifi_direct_function(self): 71 """Test the NC with upgrading to the WiFi Direct as connection medium. 72 """ 73 self._current_test_actor = self.fixed_wifi_medium_test_actor 74 self.fixed_wifi_medium_test_actor.run_fixed_wifi_medium_test( 75 nc_constants.NearbyMedium.UPGRADE_TO_WIFIDIRECT) 76 77 def test_bt_multiplex_connections(self): 78 """Test the BT multiplex function of nearby connection. 79 80 set up 2 Bluetooth connections with NearbyConnection APIs. 81 """ 82 self._current_test_actor = self.bt_multiplex_test_actor 83 self.bt_multiplex_test_actor.test_bt_multiplex_connections() 84 85 def setup_class(self): 86 super().setup_class() 87 88 self.bt_ble_test_actor = bt_ble_function_test_actor.BtBleFunctionTestActor( 89 self.test_parameters, self.discoverer, self.advertiser 90 ) 91 self.fixed_wifi_medium_test_actor = ( 92 fixed_wifi_medium_function_test_actor.FixedWifiMediumFunctionTestActor( 93 self.test_parameters, self.discoverer, self.advertiser 94 ) 95 ) 96 self.bt_multiplex_test_actor = ( 97 bt_multiplex_function_test_actor.BtMultiplexFunctionTestActor( 98 self.test_parameters, self.discoverer, self.advertiser 99 ) 100 ) 101 self._current_test_actor: function_test_actor_base.FunctionTestActorBase = ( 102 None 103 ) 104 105 def teardown_test(self) -> None: 106 self._test_result_messages[self.current_test_info.name] = ( 107 self._current_test_actor.get_test_result_message() 108 ) 109 self.record_data({ 110 'Test Name': self.current_test_info.name, 111 'properties': { 112 'result': self._current_test_actor.get_test_result_message(), 113 }, 114 }) 115 super().teardown_test() 116 117 # @typing.override 118 def _summary_test_results(self): 119 """Summarizes test results of all function tests.""" 120 121 self.record_data({ 122 'Test Class': self.TAG, 123 'properties': { 124 '00_test_script_verion': version.TEST_SCRIPT_VERSION, 125 '01_source_device_serial': self.discoverer.serial, 126 '02_target_device_serial': self.advertiser.serial, 127 '03_source_GMS_version': setup_utils.dump_gms_version( 128 self.discoverer 129 ), 130 '04_target_GMS_version': setup_utils.dump_gms_version( 131 self.advertiser 132 ), 133 '05_test_result': self._test_result_messages, 134 }, 135 }) 136 137 138if __name__ == '__main__': 139 test_runner.main() 140