def setup(self, context): if self.loglevel: self.old_loglevel = self.target.read_int(self.loglevel_file) self.target.write_value(self.loglevel_file, self.loglevel, verify=False) self.before_file = _f( os.path.join(context.output_directory, 'dmesg', 'before')) self.after_file = _f( os.path.join(context.output_directory, 'dmesg', 'after'))
def create_uiauto_project(path, name): package_name = 'com.arm.wa.uiauto.' + name.lower() copy_tree(os.path.join(TEMPLATES_DIR, 'uiauto', 'uiauto_workload_template'), path) manifest_path = os.path.join(path, 'app', 'src', 'main') mainifest = os.path.join(_d(manifest_path), 'AndroidManifest.xml') with open(mainifest, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_AndroidManifest.xml'), {'package_name': package_name})) build_gradle_path = os.path.join(path, 'app') build_gradle = os.path.join(_d(build_gradle_path), 'build.gradle') with open(build_gradle, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_build.gradle'), {'package_name': package_name})) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_build_script'), {'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f(os.path.join(path, 'app', 'src', 'main', 'java', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'UiAutomation.java'), {'name': name, 'package_name': package_name}))
def diff_sysfs_dirs(before, after, result): # pylint: disable=R0914 before_files = [] for root, _, files in os.walk(before): before_files.extend([os.path.join(root, f) for f in files]) before_files = list(filter(os.path.isfile, before_files)) files = [os.path.relpath(f, before) for f in before_files] after_files = [os.path.join(after, f) for f in files] diff_files = [os.path.join(result, f) for f in files] for bfile, afile, dfile in zip(before_files, after_files, diff_files): if not os.path.isfile(afile): logger.debug('sysfs_diff: {} does not exist or is not a file'.format(afile)) continue with open(bfile) as bfh, open(afile) as afh: # pylint: disable=C0321 with open(_f(dfile), 'w') as dfh: for i, (bline, aline) in enumerate(zip_longest(bfh, afh), 1): if aline is None: logger.debug('Lines missing from {}'.format(afile)) break bchunks = re.split(r'(\W+)', bline) achunks = re.split(r'(\W+)', aline) if len(bchunks) != len(achunks): logger.debug('Token length mismatch in {} on line {}'.format(bfile, i)) dfh.write('xxx ' + bline) continue if ((len([c for c in bchunks if c.strip()]) == len([c for c in achunks if c.strip()]) == 2) and (bchunks[0] == achunks[0])): # if there are only two columns and the first column is the # same, assume it's a "header" column and do not diff it. dchunks = [bchunks[0]] + [diff_tokens(b, a) for b, a in zip(bchunks[1:], achunks[1:])] else: dchunks = [diff_tokens(b, a) for b, a in zip(bchunks, achunks)] dfh.write(''.join(dchunks))
def update_output(self, context): context.add_artifact('interrupts [before]', self.before_file, kind='data', classifiers={'stage': 'before'}) # If workload execution failed, the after_file may not have been created. if os.path.isfile(self.after_file): diff_interrupt_files(self.before_file, self.after_file, _f(self.diff_file)) context.add_artifact('interrupts [after]', self.after_file, kind='data', classifiers={'stage': 'after'}) context.add_artifact('interrupts [diff]', self.diff_file, kind='data', classifiers={'stage': 'diff'})
def download_asset(self, asset, owner_name): url = urljoin(self.url, owner_name, asset['path']) local_path = _f( os.path.join(settings.dependencies_directory, '__remote', owner_name, asset['path'].replace('/', os.sep))) if os.path.exists(local_path) and not self.always_fetch: local_sha = sha256(local_path) if local_sha == asset['sha256']: self.logger.debug('Local SHA256 matches; not re-downloading') return local_path self.logger.debug('Downloading {}'.format(url)) response = self.geturl(url, stream=True) if response.status_code != http.client.OK: message = 'Could not download asset "{}"; recieved "{} {}"' self.logger.warning( message.format(url, response.status_code, response.reason)) return with open(local_path, 'wb') as wfh: for chunk in response.iter_content(chunk_size=self.chunk_size): wfh.write(chunk) return local_path
def download_asset(self, asset, owner_name): url = urljoin(self.url, owner_name, asset['path']) local_path = _f(os.path.join(settings.dependencies_directory, '__remote', owner_name, asset['path'].replace('/', os.sep))) if os.path.exists(local_path) and not self.always_fetch: local_sha = sha256(local_path) if local_sha == asset['sha256']: self.logger.debug('Local SHA256 matches; not re-downloading') return local_path self.logger.debug('Downloading {}'.format(url)) response = self.geturl(url, stream=True) if response.status_code != http.client.OK: message = 'Could not download asset "{}"; recieved "{} {}"' self.logger.warning(message.format(url, response.status_code, response.reason)) return with open(local_path, 'wb') as wfh: for chunk in response.iter_content(chunk_size=self.chunk_size): wfh.write(chunk) return local_path
def create_uiauto_project(path, name): package_name = 'com.arm.wa.uiauto.' + name.lower() copy_tree( os.path.join(TEMPLATES_DIR, 'uiauto', 'uiauto_workload_template'), path) manifest_path = os.path.join(path, 'app', 'src', 'main') mainifest = os.path.join(_d(manifest_path), 'AndroidManifest.xml') with open(mainifest, 'w') as wfh: wfh.write( render_template( os.path.join('uiauto', 'uiauto_AndroidManifest.xml'), {'package_name': package_name})) build_gradle_path = os.path.join(path, 'app') build_gradle = os.path.join(_d(build_gradle_path), 'build.gradle') with open(build_gradle, 'w') as wfh: wfh.write( render_template(os.path.join('uiauto', 'uiauto_build.gradle'), {'package_name': package_name})) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: wfh.write( render_template(os.path.join('uiauto', 'uiauto_build_script'), {'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f( os.path.join(path, 'app', 'src', 'main', 'java', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write( render_template(os.path.join('uiauto', 'UiAutomation.java'), { 'name': name, 'package_name': package_name }))
def stop(self, context): with open(_f(self.after_file), 'w') as wfh: wfh.write(self.target.execute('cat /proc/interrupts'))
def setup(self, context): if self.loglevel: self.old_loglevel = self.target.read_int(self.loglevel_file) self.target.write_value(self.loglevel_file, self.loglevel, verify=False) self.before_file = _f(os.path.join(context.output_directory, 'dmesg', 'before')) self.after_file = _f(os.path.join(context.output_directory, 'dmesg', 'after'))
def update_output(self, context): # If workload execution failed, the after_file may not have been created. if os.path.isfile(self.after_file): diff_interrupt_files(self.before_file, self.after_file, _f(self.diff_file))