From 13df3cff9033eb55640ca773a785ce716f252e65 Mon Sep 17 00:00:00 2001 From: John Richardson Date: Fri, 20 May 2016 11:26:21 +0100 Subject: [PATCH] Add workload validate step to check dependencies Check that dependent files for the workload are present in the dependencies folder before starting the workload. Move cleanup of dependent files to finalize method. --- wlauto/workloads/gmail/__init__.py | 30 +++++++++++-------- wlauto/workloads/googlephotos/__init__.py | 17 +++++++---- wlauto/workloads/reader/__init__.py | 36 ++++++++++++++--------- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/wlauto/workloads/gmail/__init__.py b/wlauto/workloads/gmail/__init__.py index 168d62eb..16cbaea4 100755 --- a/wlauto/workloads/gmail/__init__.py +++ b/wlauto/workloads/gmail/__init__.py @@ -20,6 +20,7 @@ import time from wlauto import AndroidUiAutoBenchmark, Parameter from wlauto.exceptions import DeviceError +from wlauto.exceptions import NotFoundError __version__ = '0.1.0' @@ -83,12 +84,17 @@ class Gmail(AndroidUiAutoBenchmark): if not self.device.is_wifi_connected(): raise DeviceError('Wifi is not connected for device {}'.format(self.device.name)) - self.storage_dir = self.device.path.join(self.device.working_directory) + # Check for workload dependencies before proceeding + jpeg_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".jpg")] - for file in os.listdir(self.dependencies_directory): - if file.endswith(".jpg"): - self.device.push_file(os.path.join(self.dependencies_directory, file), - os.path.join(self.storage_dir, file), timeout=300) + if len(jpeg_files) < 5: + raise NotFoundError("This workload requires a minimum of five {} files in {}".format('jpg', + self.dependencies_directory)) + else: + for entry in jpeg_files: + self.device.push_file(os.path.join(self.dependencies_directory, entry), + os.path.join(self.device.working_directory, entry), + timeout=300) # Force a re-index of the mediaserver cache to pick up new files self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard') @@ -114,17 +120,17 @@ class Gmail(AndroidUiAutoBenchmark): def teardown(self, context): super(Gmail, self).teardown(context) - for file in self.device.listdir(self.device.working_directory): - if file.endswith(".log"): - self.device.pull_file(os.path.join(self.device.working_directory, file), context.output_directory) - self.device.delete_file(os.path.join(self.device.working_directory, file)) + for entry in self.device.listdir(self.device.working_directory): + if entry.endswith(".log"): + self.device.pull_file(os.path.join(self.device.working_directory, entry), context.output_directory) + self.device.delete_file(os.path.join(self.device.working_directory, entry)) def finalize(self, context): super(Gmail, self).finalize(context) - for file in self.device.listdir(self.device.working_directory): - if file.endswith(".jpg"): - self.device.delete_file(os.path.join(self.device.working_directory, file)) + for entry in self.device.listdir(self.device.working_directory): + if entry.endswith(".jpg"): + self.device.delete_file(os.path.join(self.device.working_directory, entry)) # Force a re-index of the mediaserver cache to pick up new files self.device.execute('am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard') diff --git a/wlauto/workloads/googlephotos/__init__.py b/wlauto/workloads/googlephotos/__init__.py index 7e6bdd16..286e5e14 100755 --- a/wlauto/workloads/googlephotos/__init__.py +++ b/wlauto/workloads/googlephotos/__init__.py @@ -18,6 +18,7 @@ import re from wlauto import AndroidUiAutoBenchmark, Parameter from wlauto.exceptions import DeviceError +from wlauto.exceptions import NotFoundError __version__ = '0.1.0' @@ -65,7 +66,6 @@ class Googlephotos(AndroidUiAutoBenchmark): ] instrumentation_log = ''.join([name, '_instrumentation.log']) - file_prefix = 'wa_test_' def __init__(self, device, **kwargs): super(Googlephotos, self).__init__(device, **kwargs) @@ -84,11 +84,16 @@ class Googlephotos(AndroidUiAutoBenchmark): if not self.device.is_wifi_connected(): raise DeviceError('Wifi is not connected for device {}'.format(self.device.name)) - for entry in os.listdir(self.dependencies_directory): - wa_file = ''.join([self.file_prefix, entry]) - if entry.endswith(".jpg"): + # Check for workload dependencies before proceeding + jpeg_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".jpg")] + + if len(jpeg_files) < 4: + raise NotFoundError("This workload requires a minimum of four {} files in {}".format('jpg', + self.dependencies_directory)) + else: + for entry in jpeg_files: self.device.push_file(os.path.join(self.dependencies_directory, entry), - os.path.join(self.device.working_directory, wa_file), + os.path.join(self.device.working_directory, entry), timeout=300) # Force a re-index of the mediaserver cache to pick up new files @@ -126,7 +131,7 @@ class Googlephotos(AndroidUiAutoBenchmark): super(Googlephotos, self).finalize(context) for entry in self.device.listdir(self.device.working_directory): - if entry.startswith(self.file_prefix) and entry.endswith(".jpg"): + if entry.endswith(".jpg"): self.device.delete_file(os.path.join(self.device.working_directory, entry)) # Force a re-index of the mediaserver cache to removed cached files diff --git a/wlauto/workloads/reader/__init__.py b/wlauto/workloads/reader/__init__.py index f5cd3535..82df995d 100755 --- a/wlauto/workloads/reader/__init__.py +++ b/wlauto/workloads/reader/__init__.py @@ -20,6 +20,7 @@ import time from wlauto import AndroidUiAutoBenchmark, Parameter from wlauto.exceptions import DeviceError +from wlauto.exceptions import NotFoundError __version__ = '0.1.0' @@ -86,16 +87,19 @@ class Reader(AndroidUiAutoBenchmark): if not self.device.is_wifi_connected(): raise DeviceError('Wifi is not connected for device {}'.format(self.device.name)) - def setup(self, context): - super(Reader, self).setup(context) - self.reader_local_dir = self.device.path.join(self.device.external_storage_directory, 'Android/data/com.adobe.reader/files/') - for file in os.listdir(self.dependencies_directory): - if file.endswith(".pdf"): - self.device.push_file(os.path.join(self.dependencies_directory, file), - os.path.join(self.reader_local_dir, file), timeout=300) + # Check for workload dependencies before proceeding + pdf_files = [entry for entry in os.listdir(self.dependencies_directory) if entry.endswith(".pdf")] + + if not len(pdf_files): + raise NotFoundError("Cannot find {} file(s) in {}".format('pdf', self.dependencies_directory)) + else: + for entry in pdf_files: + self.device.push_file(os.path.join(self.dependencies_directory, entry), + os.path.join(self.reader_local_dir, entry), + timeout=300) def update_result(self, context): super(Reader, self).update_result(context) @@ -117,11 +121,15 @@ class Reader(AndroidUiAutoBenchmark): def teardown(self, context): super(Reader, self).teardown(context) - for file in self.device.listdir(self.reader_local_dir): - if file.endswith(".pdf"): - self.device.delete_file(os.path.join(self.reader_local_dir, file)) - for file in self.device.listdir(self.device.working_directory): - if file.endswith(".log"): - self.device.pull_file(os.path.join(self.device.working_directory, file), context.output_directory) - self.device.delete_file(os.path.join(self.device.working_directory, file)) + for entry in self.device.listdir(self.device.working_directory): + if entry.endswith(".log"): + self.device.pull_file(os.path.join(self.device.working_directory, entry), context.output_directory) + self.device.delete_file(os.path.join(self.device.working_directory, entry)) + + def finalize(self, context): + super(Reader, self).finalize(context) + + for entry in self.device.listdir(self.reader_local_dir): + if entry.endswith(".pdf"): + self.device.delete_file(os.path.join(self.reader_local_dir, entry))