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"""Provides the actor base for all function tests.""" 16 17from typing import Tuple 18 19from mobly.controllers import android_device 20 21from betocq import nc_constants 22 23 24class FunctionTestActorBase: 25 """Base class of actors for running all function tests.""" 26 27 def __init__(self, 28 test_parameters: nc_constants.TestParameters, 29 discoverer: android_device.AndroidDevice, 30 advertiser: android_device.AndroidDevice 31 ): 32 self.test_parameters: nc_constants.TestParameters = test_parameters 33 self.advertiser: android_device.AndroidDevice = advertiser 34 self.discoverer: android_device.AndroidDevice = discoverer 35 self._test_result: nc_constants.SingleTestResult = ( 36 nc_constants.SingleTestResult() 37 ) 38 self._test_failure_reason: nc_constants.SingleTestFailureReason = ( 39 nc_constants.SingleTestFailureReason.UNINITIALIZED 40 ) 41 self._wifi_medium_under_test = None 42 self._skipped: bool = False 43 44 def _get_wifi_ssid_password(self) -> Tuple[str, str]: 45 """Returns the available wifi username and password.""" 46 if self.test_parameters.wifi_ssid: 47 return ( 48 self.test_parameters.wifi_ssid, 49 self.test_parameters.wifi_password, 50 ) 51 if self.test_parameters.wifi_5g_ssid: 52 return ( 53 self.test_parameters.wifi_5g_ssid, 54 self.test_parameters.wifi_5g_password, 55 ) 56 if self.test_parameters.wifi_dfs_5g_ssid: 57 return ( 58 self.test_parameters.wifi_dfs_5g_ssid, 59 self.test_parameters.wifi_dfs_5g_password, 60 ) 61 if self.test_parameters.wifi_2g_ssid: 62 return ( 63 self.test_parameters.wifi_2g_ssid, 64 self.test_parameters.wifi_2g_password, 65 ) 66 return ('', '') 67 68 def get_test_result_message(self) -> str: 69 """Returns the message about the test result.""" 70 return 'Unknown' 71 72 def _get_test_failure_reason(self) -> nc_constants.SingleTestFailureReason: 73 """Returns the test failure reason.""" 74 return self._test_failure_reason 75