|
| 1 | +# Copyright 2014-2020 ARM Limited |
| 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 | +import os |
| 16 | +import re |
| 17 | + |
| 18 | +from wa import ApkUiautoWorkload, Parameter |
| 19 | +from wa.framework.exception import ValidationError, WorkloadError |
| 20 | +from wa.utils.types import list_of_strs |
| 21 | +from wa.utils.misc import unique |
| 22 | + |
| 23 | + |
| 24 | +class Jetstream(ApkUiautoWorkload): |
| 25 | + |
| 26 | + name = 'jetstream' |
| 27 | + package_names = ['com.android.chrome'] |
| 28 | + regex = re.compile(r'Jetstream Score ([\d.]+)') |
| 29 | + tests = ['3d-cube-SP', '3d-raytrace-SP', 'acorn-wtb', 'ai-astar', 'Air', 'async-fs', 'Babylon', 'babylon-wtb', |
| 30 | + 'base64-SP', 'Basic', 'bomb-workers', 'Box2D', 'cdjs', 'chai-wtb', 'coffeescript-wtb', 'crypto', |
| 31 | + 'crypto-aes-SP', 'crypto-md5-SP', 'crypto-sha1-SP', 'date-format-tofte-SP', 'date-format-xparb-SP', 'delta-blue', |
| 32 | + 'earley-boyer', 'espree-wtb', 'first-inspector-code-load', 'FlightPlanner', 'float-mm.c', 'gaussian-blur', |
| 33 | + 'gbemu', 'hash-map', 'jshint-wtb', 'json-parse-inspector', |
| 34 | + 'json-stringify-inspector', 'lebab-wtb', 'mandreel', 'ML', 'multi-inspector-code-load', 'n-body-SP', |
| 35 | + 'navier-stokes', 'octane-code-load', 'octane-zlib', 'OfflineAssembler', 'pdfjs', 'prepack-wtb', 'raytrace', |
| 36 | + 'regex-dna-SP', 'regexp', 'richards', 'segmentation', |
| 37 | + 'splay', 'stanford-crypto-aes', 'stanford-crypto-pbkdf2', 'stanford-crypto-sha256', 'string-unpack-code-SP', |
| 38 | + 'tagcloud-SP', 'typescript', 'uglify-js-wtb', 'UniPoker'] |
| 39 | + description = ''' |
| 40 | + A workload to execute the jetstream web based benchmark |
| 41 | +
|
| 42 | + Test description: |
| 43 | + 1. Open chrome |
| 44 | + 2. Navigate to the jetstream website - https://browserbench.org/JetStream/ |
| 45 | + 3. Execute the benchmark |
| 46 | +
|
| 47 | + known working chrome version 80.0.3987.149 |
| 48 | + ''' |
| 49 | + requires_network = True |
| 50 | + |
| 51 | + def __init__(self, target, **kwargs): |
| 52 | + super(Jetstream, self).__init__(target, **kwargs) |
| 53 | + self.gui.timeout = 1500 |
| 54 | + self.regex_tests = [] |
| 55 | + for test in self.tests: |
| 56 | + formatted_string = 'text="([\d.]+)" resource-id="results-cell-({})-score"'.format(test) |
| 57 | + self.regex_tests.append(re.compile(formatted_string)) |
| 58 | + # Add regex for tests with annoyingly different resource id's |
| 59 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="wasm-score-id(gcc-loops-wasm)"')) |
| 60 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="wasm-score-id(HashSet-wasm)"')) |
| 61 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="wasm-score-id(quicksort-wasm)"')) |
| 62 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="wasm-score-id(richards-wasm)"')) |
| 63 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="wasm-score-id(tsf-wasm)"')) |
| 64 | + self.regex_tests.append(re.compile(r'text="([\d.]+)" resource-id="(wsl)-score-score"')) |
| 65 | + |
| 66 | + def extract_results(self, context): |
| 67 | + self.target.execute("uiautomator dump") |
| 68 | + self.target.pull('/sdcard/window_dump.xml', os.path.join(context.output_directory, 'screenDump.xml')) |
| 69 | + |
| 70 | + def update_output(self, context): |
| 71 | + super(Jetstream, self).update_output(context) |
| 72 | + screen_xml = os.path.join(context.output_directory, 'screenDump.xml') |
| 73 | + total_score_regex = re.compile(r'text="([\d.]+)" resource-id=""') |
| 74 | + with open(screen_xml, 'r') as fh: |
| 75 | + xml_str = fh.read() |
| 76 | + total_score_match = total_score_regex.search(xml_str) |
| 77 | + if total_score_match: |
| 78 | + total_score = float(total_score_match.group(1)) |
| 79 | + context.add_metric('jetstream', total_score, 'score', lower_is_better=False) |
| 80 | + else: |
| 81 | + raise WorkloadError('Total score for jetstream could not be found') |
| 82 | + for regex in self.regex_tests: |
| 83 | + match = regex.search(xml_str) |
| 84 | + if match: |
| 85 | + result = float(match.group(1)) |
| 86 | + test_name = match.group(2) |
| 87 | + context.add_metric(test_name, result, 'score', lower_is_better=False) |
| 88 | + else: |
| 89 | + raise WorkloadError('score {} cannot be found'.format(regex)) |
| 90 | + |
0 commit comments