1# Lint as: python3 2"""Connectivity multi devices tests.""" 3import sys 4from mobly import base_test 5from mobly import test_runner 6from mobly import utils 7from mobly.controllers import android_device 8import tether_utils 9from tether_utils import UpstreamType 10 11CONNECTIVITY_MULTI_DEVICES_SNIPPET_PACKAGE = "com.google.snippet.connectivity" 12 13 14class ConnectivityMultiDevicesTest(base_test.BaseTestClass): 15 16 def setup_class(self): 17 # Declare that two Android devices are needed. 18 self.clientDevice, self.serverDevice = self.register_controller( 19 android_device, min_number=2 20 ) 21 22 def setup_device(device): 23 device.load_snippet( 24 "connectivity_multi_devices_snippet", 25 CONNECTIVITY_MULTI_DEVICES_SNIPPET_PACKAGE, 26 ) 27 28 # Set up devices in parallel to save time. 29 utils.concurrent_exec( 30 setup_device, 31 ((self.clientDevice,), (self.serverDevice,)), 32 max_workers=2, 33 raise_on_exception=True, 34 ) 35 36 def test_hotspot_upstream_wifi(self): 37 tether_utils.assume_hotspot_test_preconditions( 38 self.serverDevice, self.clientDevice, UpstreamType.WIFI 39 ) 40 try: 41 # Connectivity of the client verified by asserting the validated capability. 42 tether_utils.setup_hotspot_and_client_for_upstream_type( 43 self.serverDevice, self.clientDevice, UpstreamType.WIFI 44 ) 45 finally: 46 tether_utils.cleanup_tethering_for_upstream_type( 47 self.serverDevice, UpstreamType.WIFI 48 ) 49 50 def test_hotspot_upstream_cellular(self): 51 tether_utils.assume_hotspot_test_preconditions( 52 self.serverDevice, self.clientDevice, UpstreamType.CELLULAR 53 ) 54 try: 55 # Connectivity of the client verified by asserting the validated capability. 56 tether_utils.setup_hotspot_and_client_for_upstream_type( 57 self.serverDevice, self.clientDevice, UpstreamType.CELLULAR 58 ) 59 finally: 60 tether_utils.cleanup_tethering_for_upstream_type( 61 self.serverDevice, UpstreamType.CELLULAR 62 ) 63 64 65if __name__ == "__main__": 66 # Take test args 67 if "--" in sys.argv: 68 index = sys.argv.index("--") 69 sys.argv = sys.argv[:1] + sys.argv[index + 1 :] 70 test_runner.main() 71