diff options
author | Fabien Lahoudere <fabien.lahoudere@collabora.com> | 2019-11-21 18:16:01 +0100 |
---|---|---|
committer | Enric Balletbo i Serra <enric.balletbo@collabora.com> | 2019-12-06 00:08:35 +0100 |
commit | 87b985129937cce8a759c5267104cd705ec069fc (patch) | |
tree | 9dc6ba7ecaefc28a3fb7fd0882b882a5b6d58683 | |
parent | 8f502f83ca7be85c080e631f2f24b328ee190b66 (diff) | |
download | cros-ec-tests-87b985129937cce8a759c5267104cd705ec069fc.tar.gz |
test_cros_ec_accel_iio_data_is_valid: test data validity
In order to verify that accelerometer data are consistent, we
compute the magnitude that should beclose to 1G.
This patch is inspired from kernel_CrosECSysfsAccel.py [1]
[1] https://chromium.googlesource.com/chromiumos/third_party/autotest/+/refs/heads/master/client/site_tests/kernel_CrosECSysfs/kernel_CrosECSysfs.py
Signed-off-by: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
-rwxr-xr-x | test-cros-ec.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test-cros-ec.py b/test-cros-ec.py index 78eaa1d..bb3734e 100755 --- a/test-cros-ec.py +++ b/test-cros-ec.py @@ -4,6 +4,7 @@ from ctypes import * import errno import fcntl +import math import os import sys import unittest @@ -253,6 +254,34 @@ class TestCrosEC(unittest.TestCase): if match == 0: self.skipTest("No accelerometer found, skipping") + # This function validate accelerometer data by computing the magnitude. + # If the magnitude is not closed to 1G, that means data are invalid or + # the machine is in movement or there is a earth quake. + def test_cros_ec_accel_iio_data_is_valid(self): + ACCEL_1G_IN_MS2 = 9.8185 + ACCEL_MAG_VALID_OFFSET = .25 + match = 0 + for devname in os.listdir("/sys/bus/iio/devices"): + fd = open("/sys/bus/iio/devices/" + devname + "/name", 'r') + devtype = fd.read() + if devtype.startswith("cros-ec-accel"): + location = read_sysfs_file(base_path + "location") + accel_scale = float(read_sysfs_file(base_path + "scale")) + exp = self.ACCEL_1G_IN_MS2 + err = exp * self.ACCEL_MAG_VALID_OFFSET + mag = 0 + for axis in ['x', 'y', 'z']: + axis_path = base_path + "in_accel_" + axis + "_raw" + value = int(read_sysfs_file(axis_path)) + value *= accel_scale + mag += value * value + mag = math.sqrt(mag) + self.assertTrue(abs(mag - exp) <= err) + match += 1 + fd.close() + if match == 0: + self.skipTest("No accelerometer found, skipping") + def test_cros_ec_gyro_iio_abi(self): match = 0 for devname in os.listdir("/sys/bus/iio/devices"): |