From e96450d2260585b877e4774237db553556042549 Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Fri, 6 May 2016 13:14:28 +0100 Subject: [PATCH 1/4] adb_shell: Fixed getting return codes They way we were attempting to get return codes before always gave us a return code of the previous echo, therefore always `0`. This commit adds the newline into the last echo. --- wlauto/utils/android.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wlauto/utils/android.py b/wlauto/utils/android.py index 6760fdbb..42a068c2 100644 --- a/wlauto/utils/android.py +++ b/wlauto/utils/android.py @@ -276,7 +276,7 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=Fals full_command = 'adb {} shell "{}"'.format(device_string, escape_double_quotes(command)) logger.debug(full_command) if check_exit_code: - actual_command = "adb {} shell '({}); echo; echo $?'".format(device_string, escape_single_quotes(command)) + actual_command = "adb {} shell '({}); echo \"\n$?\"'".format(device_string, escape_single_quotes(command)) try: raw_output, error = check_output(actual_command, timeout, shell=True) except CalledProcessErrorWithStderr as e: From ef61f16896fd8f7153ca844e66ecf756e4480e4d Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Fri, 6 May 2016 13:18:32 +0100 Subject: [PATCH 2/4] AndroidDevice: Fixed screen lock disable Due to the previous commits, this command no longer works properly. It turns out there is an issue with using multiple levels of escaping. It seems that bash handles the backslashes and single quotes separately incorrectly processing our escaping. To get around this we are writing the sqlite command to a shell script file and running that. This seems to be the only case in WA at the moment that requires this, if more show up/when WA moves to devlib it should use the devlib shutil mechanism. --- wlauto/common/android/device.py | 10 +++++++++- wlauto/devices/android/gem5/__init__.py | 10 ---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/wlauto/common/android/device.py b/wlauto/common/android/device.py index 7444b435..9bab60d9 100644 --- a/wlauto/common/android/device.py +++ b/wlauto/common/android/device.py @@ -637,7 +637,15 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223 """ lockdb = '/data/system/locksettings.db' sqlcommand = "update locksettings set value='0' where name='screenlock.disabled';" - self.execute('{} {} "{}"'.format(self.sqlite, lockdb, sqlcommand), as_root=True) + f = tempfile.NamedTemporaryFile() + try: + f.write('{} {} "{}"'.format(self.sqlite, lockdb, sqlcommand)) + f.flush() + on_device_executable = self.install_executable(f.name, + with_name="disable_screen_lock") + finally: + f.close() + self.execute(on_device_executable, as_root=True) def disable_selinux(self): # This may be invoked from intialize() so we can't use execute() or the diff --git a/wlauto/devices/android/gem5/__init__.py b/wlauto/devices/android/gem5/__init__.py index caadad63..e5371e00 100644 --- a/wlauto/devices/android/gem5/__init__.py +++ b/wlauto/devices/android/gem5/__init__.py @@ -199,16 +199,6 @@ class Gem5AndroidDevice(BaseGem5Device, AndroidDevice): props = self._get_android_properties(context) return props - def disable_screen_lock(self): - """ - Attempts to disable he screen lock on the device. - - Overridden here as otherwise we have issues with too many backslashes. - """ - lockdb = '/data/system/locksettings.db' - sqlcommand = "update locksettings set value=\'0\' where name=\'screenlock.disabled\';" - self.execute('{} {} "{}"'.format(self.sqlite, lockdb, sqlcommand), as_root=True) - def capture_screen(self, filepath): if BaseGem5Device.capture_screen(self, filepath): return From 87cbce4244c1d0485656c917e1e1a065e382c46a Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Fri, 6 May 2016 13:52:38 +0100 Subject: [PATCH 3/4] hwmon: Added allowed values to `sensors` parameter Previously the sensor name was just appeneded to the end of the previous sensors name. --- wlauto/instrumentation/hwmon/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wlauto/instrumentation/hwmon/__init__.py b/wlauto/instrumentation/hwmon/__init__.py index d1bde4e5..20844f39 100644 --- a/wlauto/instrumentation/hwmon/__init__.py +++ b/wlauto/instrumentation/hwmon/__init__.py @@ -64,6 +64,7 @@ class HwmonInstrument(Instrument): parameters = [ Parameter('sensors', kind=list_of_strs, default=['energy', 'temp'], global_alias='hwmon_sensors', + allowed_values=HWMON_SENSORS.keys(), description='The kinds of sensors hwmon instrument will look for') ] @@ -73,11 +74,7 @@ class HwmonInstrument(Instrument): if self.sensors: self.sensor_kinds = {} for kind in self.sensors: - if kind in HWMON_SENSORS: - self.sensor_kinds[kind] = HWMON_SENSORS[kind] - else: - message = 'Unexpected sensor type: {}; must be in {}'.format(kind, HWMON_SENSORS.keys()) - raise ConfigError(message) + self.sensor_kinds[kind] = HWMON_SENSORS[kind] else: self.sensor_kinds = HWMON_SENSORS From 8abf39762dfdf4fc986ba3e90e41d573ee8055ee Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Fri, 6 May 2016 14:04:29 +0100 Subject: [PATCH 4/4] hwmon: Fixed sensor naming Previously the sensor name was just appeneded to the end of the previous sensors name. Now the hwmon name is added as a classifier of the metric. If the hwmon sensor has a label, the metric will use this for its name, if it does not then the sensors kind and ID will be used e.g. temp3 --- wlauto/instrumentation/hwmon/__init__.py | 12 ++++++++---- wlauto/utils/hwmon.py | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/wlauto/instrumentation/hwmon/__init__.py b/wlauto/instrumentation/hwmon/__init__.py index 20844f39..37f3d70f 100644 --- a/wlauto/instrumentation/hwmon/__init__.py +++ b/wlauto/instrumentation/hwmon/__init__.py @@ -107,13 +107,17 @@ class HwmonInstrument(Instrument): if report_type == 'diff': before, after = sensor.readings diff = conversion(after - before) - context.result.add_metric(sensor.label, diff, units) + context.result.add_metric(sensor.label, diff, units, + classifiers={"hwmon_device": sensor.device_name}) elif report_type == 'before/after': before, after = sensor.readings mean = conversion((after + before) / 2) - context.result.add_metric(sensor.label, mean, units) - context.result.add_metric(sensor.label + ' before', conversion(before), units) - context.result.add_metric(sensor.label + ' after', conversion(after), units) + context.result.add_metric(sensor.label, mean, units, + classifiers={"hwmon_device": sensor.device_name}) + context.result.add_metric(sensor.label + ' before', conversion(before), units, + classifiers={"hwmon_device": sensor.device_name}) + context.result.add_metric(sensor.label + ' after', conversion(after), units, + classifiers={"hwmon_device": sensor.device_name}) else: raise InstrumentError('Unexpected report_type: {}'.format(report_type)) except ValueError, e: diff --git a/wlauto/utils/hwmon.py b/wlauto/utils/hwmon.py index 90998ab3..43d07e3b 100644 --- a/wlauto/utils/hwmon.py +++ b/wlauto/utils/hwmon.py @@ -22,9 +22,10 @@ HWMON_ROOT = '/sys/class/hwmon' class HwmonSensor(object): - def __init__(self, device, kind, label, filepath): + def __init__(self, device, kind, device_name, label, filepath): self.device = device self.kind = kind + self.device_name = device_name self.label = label self.filepath = filepath self.readings = [] @@ -58,10 +59,10 @@ def discover_sensors(device, sensor_kinds): for hwmon_device in hwmon_devices: try: device_path = path.join(HWMON_ROOT, hwmon_device, 'device') - name = device.get_sysfile_value(path.join(device_path, 'name')) + base_name = device.get_sysfile_value(path.join(device_path, 'name')) except DeviceError: # probably a virtual device device_path = path.join(HWMON_ROOT, hwmon_device) - name = device.get_sysfile_value(path.join(device_path, 'name')) + base_name = device.get_sysfile_value(path.join(device_path, 'name')) for sensor_kind in sensor_kinds: i = 1 @@ -69,9 +70,17 @@ def discover_sensors(device, sensor_kinds): while device.file_exists(input_path): label_path = path.join(device_path, '{}{}_label'.format(sensor_kind, i)) if device.file_exists(label_path): - name += ' ' + device.get_sysfile_value(label_path) - sensors.append(HwmonSensor(device, sensor_kind, name, input_path)) + sensors.append(HwmonSensor(device, + sensor_kind, + base_name, + device.get_sysfile_value(label_path), + input_path)) + else: + sensors.append(HwmonSensor(device, + sensor_kind, + base_name, + "{}{}".format(sensor_kind, i), + input_path)) i += 1 input_path = path.join(device_path, '{}{}_input'.format(sensor_kind, i)) return sensors -