pytests/update_cr50_firmware: Succeed when actual version is newer.

Cr50 implemented "anti-rollback" logic in their firmware update process.

However, in 'CHECK_VERSION' stage, it expects the version is exact match
between running version and target version. So it will always fail.

We can make it succeed when actual version is greater than or equal to
the target version.

BUG=b:140272960
TEST=make test, manual test

Change-Id: I214086af18ce014a63a3bf96eefbcd7b8fe62717
Reviewed-on: https://chromium-review.googlesource.com/1782280
Tested-by: Yilin Yang <kerker@chromium.org>
Commit-Ready: Yilin Yang <kerker@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Yong Hong <yhong@chromium.org>
(cherry picked from commit a1cc1aa43e2e2876afda2c0e4d51092ba004a475)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory/+/1804699
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
Commit-Queue: Wei-Han Chen <stimim@chromium.org>
Tested-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/py/test/pytests/update_cr50_firmware.py b/py/test/pytests/update_cr50_firmware.py
index 14d857c..655491a 100644
--- a/py/test/pytests/update_cr50_firmware.py
+++ b/py/test/pytests/update_cr50_firmware.py
@@ -11,7 +11,7 @@
 1. In `update mode`, this test calls `gsctool` on DUT to update Cr50 firmware
    in upstart mode (the actuall upgration will happen in the next reboot).
 2. In `check mode`, this test calls `gsctool` on DUT to check if the cr50
-   firmware version is equal to the given firmware image.
+   firmware version is greater than or equal to the given firmware image.
 
 The Cr50 firmware image to update or compare is either from a given path in
 station or DUT, or from the release partition on DUT.
@@ -31,7 +31,8 @@
 4. If `method` is set to `UPDATE`, DUT runs `gsctool` to update
    Cr50 firmware using the specified Cr50 image.
 5. If `method` is set to `CHECK_VERSION`, DUT runs `gsctool` to check
-   whether the Cr50 firmware version equals to the specified Cr50 image.
+   whether the Cr50 firmware version is greater than or equals to the
+   specified Cr50 image.
 
 Dependency
 ----------
@@ -58,8 +59,8 @@
     }
   }
 
-To check if Cr50 firmware version equals to the Cr50 image in the release
-image::
+To check if Cr50 firmware version is greater than or equals to the Cr50 image
+in the release image::
 
   {
     "pytest_name": "update_cr50_firmware",
@@ -69,6 +70,7 @@
   }
 """
 
+from distutils import version
 import functools
 import logging
 import os
@@ -209,9 +211,9 @@
       for name in ('ro', 'rw'):
         actual = getattr(fw_ver, name + '_version')
         expect = getattr(image_info, name + '_fw_version')
-        if actual != expect:
+        if version.StrictVersion(actual) < version.StrictVersion(expect):
           raise type_utils.TestFailure(
-              '%s FW version mismatched (actual=%r, expect=%r)' %
+              '%s FW version is old (actual=%r, expect=%r)' %
               (name.upper(), actual, expect))
 
     try:
@@ -219,7 +221,7 @@
     except type_utils.TestFailure:
       if self.args.check_version_retry_timeout <= 0:
         raise
-      self.ui.SetState('Version mismatch, sleep for %d seconds and re-check.' %
+      self.ui.SetState('Version is old, sleep for %d seconds and re-check.' %
                        self.args.check_version_retry_timeout)
       self.Sleep(self.args.check_version_retry_timeout)
       _Check()