1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

fw/execution: record resource hashes in metadata

As part of resolving a resource, record its MD5 hash in the output
metadata. In order to enable this, resource resolution is now done via
the context, rather than directly via the ResourceResolver (in order not
to introduce a context dependency in the Gui object, context now
emulates the resolver interface).
This commit is contained in:
Sergei Trofimov 2018-05-24 14:51:04 +01:00 committed by Marc Bonnici
parent e5e8406e1f
commit 2ff06af632
13 changed files with 30 additions and 18 deletions

View File

@ -15,6 +15,7 @@
# pylint: disable=no-member
import hashlib
import logging
import os
import shutil
@ -181,6 +182,17 @@ class ExecutionContext(object):
def write_state(self):
self.run_output.write_state()
def get_resource(self, resource, strict=True):
result = self.resolver.get(resource, strict)
if os.path.isfile(result):
with open(result, 'rb') as fh:
md5hash = hashlib.md5(fh.read())
key = '{}/{}'.format(resource.owner, os.path.basename(result))
self.update_metadata('hashes', key, md5hash.hexdigest())
return result
get = get_resource # alias to allow a context to act as a resolver
def get_metric(self, name):
try:
return self.output.get_metric(name)

View File

@ -73,7 +73,7 @@ class Workload(TargetedPlugin):
self.asset_files = []
self.deployed_assets = []
def init_resources(self, context):
def init_resources(self, resolver):
"""
This method may be used to perform early resource discovery and
initialization. This is invoked during the initial loading stage and
@ -83,7 +83,7 @@ class Workload(TargetedPlugin):
"""
for asset in self.deployable_assets:
self.asset_files.append(context.resolver.get(File(self, asset)))
self.asset_files.append(resolver.get(File(self, asset)))
@once_per_instance
def initialize(self, context):
@ -689,7 +689,7 @@ class PackageHandler(object):
def resolve_package_from_host(self, context):
self.logger.debug('Resolving package on host system')
if self.package_name:
self.apk_file = context.resolver.get(ApkFile(self.owner,
self.apk_file = context.get_resource(ApkFile(self.owner,
variant=self.variant,
version=self.version,
package=self.package_name,
@ -699,7 +699,7 @@ class PackageHandler(object):
else:
available_packages = []
for package in self.owner.package_names:
apk_file = context.resolver.get(ApkFile(self.owner,
apk_file = context.get_resource(ApkFile(self.owner,
variant=self.variant,
version=self.version,
package=package,

View File

@ -70,7 +70,7 @@ class FilePoller(Instrument):
def initialize(self, context):
if not self.target.is_rooted and self.as_root:
raise ConfigError('The target is not rooted, cannot run poller as root.')
host_poller = context.resolver.get(Executable(self, self.target.abi,
host_poller = context.get_resource(Executable(self, self.target.abi,
"poller"))
target_poller = self.target.install(host_poller)

View File

@ -76,7 +76,7 @@ class Dhrystone(Workload):
@once
def initialize(self, context):
resource = Executable(self, self.target.abi, 'dhrystone')
host_exe = context.resolver.get(resource)
host_exe = context.get_resource(resource)
Dhrystone.target_exe = self.target.install(host_exe)
def setup(self, context):

View File

@ -62,7 +62,7 @@ class Hackbench(Workload):
@once
def initialize(self, context):
host_binary = context.resolver.get(Executable(self, self.target.abi, self.binary_name))
host_binary = context.get_resource(Executable(self, self.target.abi, self.binary_name))
Hackbench.target_binary = self.target.install(host_binary)
def setup(self, context):

View File

@ -63,7 +63,7 @@ class HWUITest(Workload):
@once
def initialize(self, context):
host_exe = context.resolver.get(Executable(self,
host_exe = context.get_resource(Executable(self,
self.target.abi,
BINARY))
HWUITest.target_exe = self.target.install(host_exe)

View File

@ -308,7 +308,7 @@ class Meabo(Workload):
@once
def _install_executable(self, context):
resource = Executable(self, self.target.abi, 'meabo')
host_exe = context.resolver.get(resource)
host_exe = context.get_resource(resource)
Meabo.target_exe = self.target.install(host_exe)
@once

View File

@ -65,7 +65,7 @@ class Memcpy(Workload):
def initialize(self, context):
self.binary_name = 'memcpy'
resource = Executable(self, self.target.abi, self.binary_name)
host_binary = context.resolver.get(resource)
host_binary = context.get_resource(resource)
Memcpy.target_exe = self.target.install_if_needed(host_binary)
def setup(self, context):

View File

@ -62,7 +62,7 @@ class Openssl(Workload):
Openssl.target_exe = 'openssl'
else:
resource = Executable(self, self.target.abi, 'openssl')
host_exe = context.resolver.get(resource)
host_exe = context.get_resource(resource)
Openssl.target_exe = self.target.install(host_exe)
def setup(self, context):

View File

@ -71,9 +71,9 @@ class Recentfling(Workload):
raise WorkloadError("This workload relies on ``dumpsys gfxinfo`` \
only present in Android M and onwards")
defs_host = context.resolver.get(File(self, "defs.sh"))
defs_host = context.get_resource(File(self, "defs.sh"))
Recentfling.defs_target = self.target.install(defs_host)
recentfling_host = context.resolver.get(File(self, "recentfling.sh"))
recentfling_host = context.get_resource(File(self, "recentfling.sh"))
Recentfling.recentfling_target = self.target.install(recentfling_host)
def setup(self, context):

View File

@ -149,10 +149,10 @@ class RtApp(Workload):
# available to other instances of the workload
RtApp.target_working_directory = self.target.path.join(self.target.working_directory,
'rt-app-working')
RtApp.host_binary = context.resolver.get(Executable(self,
RtApp.host_binary = context.get_resource(Executable(self,
self.target.abi,
BINARY_NAME), strict=False)
RtApp.workgen_script = context.resolver.get(File(self, 'workgen'))
RtApp.workgen_script = context.get_resource(File(self, 'workgen'))
self.target.execute('mkdir -p {}'.format(self.target_working_directory))
self._deploy_rt_app_binary_if_necessary()
@ -228,7 +228,7 @@ class RtApp(Workload):
RtApp.target_binary = self.target.install(self.host_binary)
def _load_json_config(self, context):
user_config_file = self._get_raw_json_config(context.resolver)
user_config_file = self._get_raw_json_config(context)
config_file = self._generate_workgen_config(user_config_file,
context.output_directory)
with open(config_file) as fh:

View File

@ -80,7 +80,7 @@ class StressNg(Workload):
raise WorkloadError('stress-ng requires root premissions to run')
resource = Executable(self, self.target.abi, 'stress-ng')
host_exe = context.resolver.get(resource)
host_exe = context.get_resource(resource)
StressNg.binary = self.target.install(host_exe)
def setup(self, context):

View File

@ -106,7 +106,7 @@ class Sysbench(Workload):
@once
def initialize(self, context):
exe = Executable(self, self.target.abi, 'sysbench')
host_binary = context.resolver.get(exe)
host_binary = context.get_resource(exe)
Sysbench.target_binary = self.target.install(host_binary)
def setup(self, context):