From 69db2f2f41a679db6865ccc693b3b350336d943c Mon Sep 17 00:00:00 2001 From: John Richardson Date: Thu, 2 Jun 2016 12:35:37 +0100 Subject: [PATCH] Add network connectivity check Add a more general check that pings a network host rather than checking the status of dumpsys wifi. This is because not all devices are connected via wifi. --- wlauto/common/android/device.py | 15 ++++++++++++--- wlauto/workloads/gmail/__init__.py | 3 +++ wlauto/workloads/googlephotos/__init__.py | 3 +++ wlauto/workloads/googleplaybooks/__init__.py | 3 +++ wlauto/workloads/multiapp/__init__.py | 3 +++ wlauto/workloads/reader/__init__.py | 3 +++ wlauto/workloads/skype/__init__.py | 3 +++ 7 files changed, 30 insertions(+), 3 deletions(-) diff --git a/wlauto/common/android/device.py b/wlauto/common/android/device.py index 33551af7..60fb13bf 100644 --- a/wlauto/common/android/device.py +++ b/wlauto/common/android/device.py @@ -649,9 +649,18 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223 except KeyError: return None - def is_wifi_connected(self): - self.logger.debug('Checking for wi-fi connectivity.') - return self.execute('dumpsys wifi| grep curState=ConnectedState') + def is_network_connected(self): + network_host = 'www.google.com' + self.logger.debug('Checking for internet connectivity.') + output = adb_shell(self.adb_name, 'ping -q -w 1 -c 1 {}'.format(network_host), + timeout=self.default_timeout) + + if not 'unknown host' in output: + self.logger.debug('Found network host {}'.format(network_host)) + return True + else: + self.logger.debug('Cannot find network host {}'.format(network_host)) + return False # Internal methods: do not use outside of the class. diff --git a/wlauto/workloads/gmail/__init__.py b/wlauto/workloads/gmail/__init__.py index 0d60e4fd..40596e55 100755 --- a/wlauto/workloads/gmail/__init__.py +++ b/wlauto/workloads/gmail/__init__.py @@ -81,6 +81,9 @@ class Gmail(AndroidUiAutoBenchmark): def initialize(self, context): super(Gmail, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + # Check for workload dependencies before proceeding jpeg_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".jpg")] diff --git a/wlauto/workloads/googlephotos/__init__.py b/wlauto/workloads/googlephotos/__init__.py index c591aa52..f4e53c93 100755 --- a/wlauto/workloads/googlephotos/__init__.py +++ b/wlauto/workloads/googlephotos/__init__.py @@ -81,6 +81,9 @@ class Googlephotos(AndroidUiAutoBenchmark): def initialize(self, context): super(Googlephotos, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + # Check for workload dependencies before proceeding jpeg_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".jpg")] diff --git a/wlauto/workloads/googleplaybooks/__init__.py b/wlauto/workloads/googleplaybooks/__init__.py index ade5b96f..64ca9443 100644 --- a/wlauto/workloads/googleplaybooks/__init__.py +++ b/wlauto/workloads/googleplaybooks/__init__.py @@ -88,6 +88,9 @@ class Googleplaybooks(AndroidUiAutoBenchmark): def initialize(self, context): super(Googleplaybooks, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + def update_result(self, context): super(Googleplaybooks, self).update_result(context) diff --git a/wlauto/workloads/multiapp/__init__.py b/wlauto/workloads/multiapp/__init__.py index b545588e..47ce77b8 100644 --- a/wlauto/workloads/multiapp/__init__.py +++ b/wlauto/workloads/multiapp/__init__.py @@ -124,6 +124,9 @@ class Multiapp(AndroidUiAutoBenchmark): def initialize(self, context): super(Multiapp, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + # Check for workload dependencies before proceeding jpeg_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".jpg")] diff --git a/wlauto/workloads/reader/__init__.py b/wlauto/workloads/reader/__init__.py index 855a366e..a6199ce6 100755 --- a/wlauto/workloads/reader/__init__.py +++ b/wlauto/workloads/reader/__init__.py @@ -102,6 +102,9 @@ class Reader(AndroidUiAutoBenchmark): def initialize(self, context): super(Reader, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + self.reader_local_dir = self.device.path.join(self.device.external_storage_directory, 'Android/data/com.adobe.reader/files/') diff --git a/wlauto/workloads/skype/__init__.py b/wlauto/workloads/skype/__init__.py index 57efb933..85b5e1ce 100755 --- a/wlauto/workloads/skype/__init__.py +++ b/wlauto/workloads/skype/__init__.py @@ -96,6 +96,9 @@ class Skype(AndroidUiAutoBenchmark): def initialize(self, context): super(Skype, self).initialize(context) + if not self.device.is_network_connected(): + raise DeviceError('Network is not connected for device {}'.format(self.device.name)) + def setup(self, context): self.logger.info('===== setup() ======') super(Skype, self).setup(context)