From fefaa3c86db6f0dd9124b2b7cf0ec8889693e905 Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Wed, 28 Aug 2024 16:35:02 +0100 Subject: [PATCH] [workload/jetnews] Use Jank testing classes to implement jank testing in a simpler way Modify the JetNews workload to use the new jank testing classes. This allows simplification of the code and also makes it more straightforward to implement new workloads that also need to gather frame metrics. --- wa/workloads/jetnews/__init__.py | 42 ++++++++------------------------ 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/wa/workloads/jetnews/__init__.py b/wa/workloads/jetnews/__init__.py index 7bc2fa93..2ae94bdb 100755 --- a/wa/workloads/jetnews/__init__.py +++ b/wa/workloads/jetnews/__init__.py @@ -13,13 +13,13 @@ # limitations under the License. # -from wa import ApkUiautoWorkload, Parameter, TestPackageHandler +from wa import Parameter, ApkUiautoJankTestWorkload, TestPackageHandler from wa.utils.types import list_of_strs import re -class Jetnews(ApkUiautoWorkload): +class Jetnews(ApkUiautoJankTestWorkload): name = 'jetnews' package_names = ['com.example.jetnews'] @@ -34,18 +34,15 @@ class Jetnews(ApkUiautoWorkload): There are 3 available tests, two in portrait mode and 1 in landscape mode. ''' - _OUTPUT_SECTION_REGEX = re.compile( - r'(\s*INSTRUMENTATION_STATUS: gfx-[\w-]+=[-+\d.]+\n)+' - r'\s*INSTRUMENTATION_STATUS_CODE: (?P[-+\d]+)\n?', re.M) - _OUTPUT_GFXINFO_REGEX = re.compile( - r'INSTRUMENTATION_STATUS: (?P[\w-]+)=(?P[-+\d.]+)') - default_test_strings = [ 'PortraitVerticalTest', 'PortraitHorizontalTest', 'LandscapeVerticalTest', ] + # List of jank tests to invoke for this workload. + jetnews_jank_tests = ['test1'] + parameters = [ Parameter('tests', kind=list_of_strs, description=""" @@ -69,35 +66,16 @@ class Jetnews(ApkUiautoWorkload): def __init__(self, target, **kwargs): super(Jetnews, self).__init__(target, **kwargs) - # This test uses the androidx library. - self.gui.uiauto_runner = 'androidx.test.runner.AndroidJUnitRunner' - # Class for the regular instrumented tests. - self.gui.uiauto_class = 'UiAutomation' - # Class containing the jank tests. - self.gui.uiauto_jank_class = 'UiAutomationJankTests' - # A list of all the individual jank tests contained in the jetnews - # uiauto apk. - self.gui.jank_stages = ['test1'] + self.gui.jank_tests = jetnews_jank_tests self.gui.uiauto_params['tests'] = self.tests self.gui.uiauto_params['flingspeed'] = self.flingspeed self.gui.uiauto_params['repeat'] = self.repeat - # Declared here so we can hold the test output for later processing. - self.output = {} def run(self, context): - # Run the jank tests and capture the output so we can parse it - # into the output result file. - self.output['test1'] = self.gui._execute('test1', self.gui.timeout) + # Run the jank tests. + self.gui.run() def update_output(self, context): super(Jetnews, self).update_output(context) - # Parse the test result and filter out the results so we can output - # a meaningful result file. - for test, test_output in self.output.items(): - for section in self._OUTPUT_SECTION_REGEX.finditer(test_output): - if int(section.group('code')) != -1: - msg = 'Run failed (INSTRUMENTATION_STATUS_CODE: {}). See log.' - raise RuntimeError(msg.format(section.group('code'))) - for metric in self._OUTPUT_GFXINFO_REGEX.finditer(section.group()): - context.add_metric(metric.group('name'), metric.group('value'), - classifiers={'test_name': test}) + # Parse the frame metrics and output the results file. + self.gui.parse_metrics(context)