utils: Replace usage of "mosys ec info" to get version
The command "mosys ec info" is deprecated and will eventually be
removed.
Implement reading the EC version directly from the chardev, since it's
simple enough.
BUG=b:267394061
TEST=CQ
Change-Id: Ia720e4b5048223bc44721e3bc48d13a578dff918
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/autotest-drone/+/4234799
Auto-Submit: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Gregory Nisbet <gregorynisbet@google.com>
Tested-by: Jeremy Bettis <jbettis@chromium.org>
diff --git a/client/bin/utils.py b/client/bin/utils.py
index 4396c01..3fe928e 100644
--- a/client/bin/utils.py
+++ b/client/bin/utils.py
@@ -1808,16 +1808,34 @@
utils.run)
+def get_ec_version_from_chardev_contents(contents):
+ """Given the contents of /dev/cros_ec, interpret the active version.
+
+ @param contents: The contents of a cros_ec chardev.
+
+ @returns The active EC version, or an empty string upon error.
+ """
+ lines = contents.splitlines()
+ if len(lines) != 4:
+ return ""
+ _, ro_version, rw_version, active_copy = lines
+ if active_copy == "read-only":
+ return ro_version
+ if active_copy == "read-write":
+ return rw_version
+ return ""
+
+
def get_ec_version():
"""Get the ec version as strings.
@returns a string representing this host's ec version.
"""
- command = 'mosys ec info -s fw_version'
- result = utils.run(command, ignore_status=True)
- if result.exit_status != 0:
- return ''
- return result.stdout.strip()
+ try:
+ contents = utils.read_file("/dev/cros_ec")
+ except FileNotFoundError:
+ return ""
+ return get_ec_version_from_chardev_contents(contents)
def get_firmware_version():
diff --git a/client/bin/utils_unittest.py b/client/bin/utils_unittest.py
index ddafd84..8d59f82 100755
--- a/client/bin/utils_unittest.py
+++ b/client/bin/utils_unittest.py
@@ -174,3 +174,24 @@
'transfers_per_s': 4.45,
'written_kb': 188458.0,
}, statistics)
+
+ def test_ec_version_from_chardev_contents_ro(self):
+ contents = "1.0.0\nRO_VERSION\nRW_VERSION\nread-only\n"
+ self.assertEqual(
+ utils.get_ec_version_from_chardev_contents(contents),
+ "RO_VERSION",
+ )
+
+ def test_ec_version_from_chardev_contents_rw(self):
+ contents = "1.0.0\nRO_VERSION\nRW_VERSION\nread-write\n"
+ self.assertEqual(
+ utils.get_ec_version_from_chardev_contents(contents),
+ "RW_VERSION",
+ )
+
+ def test_ec_version_from_chardev_contents_garbage(self):
+ contents = "garbage\n"
+ self.assertEqual(
+ utils.get_ec_version_from_chardev_contents(contents),
+ "",
+ )
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index 3c6732c..2870a5a 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -2537,11 +2537,8 @@
@returns a string representing this host's ec version.
"""
- command = 'mosys ec info -s fw_version'
- result = self.run(command, ignore_status=True)
- if result.exit_status != 0:
- return ''
- return result.stdout.strip()
+ result = self.run("cat /dev/cros_ec", ignore_status=True)
+ return utils.get_ec_version_from_chardev_contents(result.stdout)
def get_firmware_version(self):