diff options
author | Fabien Lahoudere <fabien.lahoudere@collabora.com> | 2019-11-28 12:27:48 +0100 |
---|---|---|
committer | Enric Balletbo i Serra <enric.balletbo@collabora.com> | 2019-12-06 09:23:42 +0100 |
commit | 6d9520ed79401be481362b3ad75afa46ebfc7d5c (patch) | |
tree | 3e44eff2909fc914c6d865b4d7f19cbb80366f5d | |
parent | cca9287feb245474029b832cea5d2f525e643d6b (diff) | |
download | cros-ec-tests-6d9520ed79401be481362b3ad75afa46ebfc7d5c.tar.gz |
Add helper to convert kernel release
Add one function to convert version major and minor
to an integer.
Add a function to get the running kernel version and
convert it using the previous function.
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 | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test-cros-ec.py b/test-cros-ec.py index 65f0533..11bb13e 100755 --- a/test-cros-ec.py +++ b/test-cros-ec.py @@ -131,6 +131,28 @@ def read_file(name): fd.close() return contents +# Return an int froom kernel version to allow to compare +def version_to_int(version, major, minor): + pattern = "{0:03d}{1:03d}{2:03d}" + return int(pattern.format(version, major, minor)) + +# Return the running kernel version +def current_kernel_version(): + fd = open("/proc/version", 'r') + current = fd.read().split()[2].split('-')[0].split('.') + fd.close() + return version_to_int(int(current[0]), int(current[1]), int(current[2])) + +def kernel_lower_than(version, major, minor): + if version_to_int(version, major, minor) > current_kernel_version(): + return True + return False + +def kernel_greater_than(version, major, minor): + if version_to_int(version, major, minor) < current_kernel_version(): + return True + return False + ############################################################################### # TEST RUNNERS ############################################################################### |