diff options
author | Tzung-Bi Shih <tzungbi@kernel.org> | 2023-03-22 12:29:27 +0800 |
---|---|---|
committer | Tzung-Bi Shih <tzungbi@kernel.org> | 2023-03-22 12:46:46 +0800 |
commit | bae2cbb108f14fc3ca599997646ff8600d667d7c (patch) | |
tree | e05fdc98e2f5e0c2689c643964fbecbe5b0b1be4 | |
parent | 8806bf749a4c6212042ef65034aa7a1ce2581ec5 (diff) | |
download | cros-ec-tests-bae2cbb108f14fc3ca599997646ff8600d667d7c.tar.gz |
cros_ec_rtc: simplify test_cros_ec_rtc_abi()
- Use glob instead of os.listdir().
- Eliminate try-catch.
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
-rw-r--r-- | cros/tests/cros_ec_rtc.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/cros/tests/cros_ec_rtc.py b/cros/tests/cros_ec_rtc.py index af6f353..85b7a8b 100644 --- a/cros/tests/cros_ec_rtc.py +++ b/cros/tests/cros_ec_rtc.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import unittest +import glob import os +import unittest from cros.helpers.ec_cmd import EC_FEATURE_RTC from cros.helpers.ec_cmd import is_feature_supported @@ -13,26 +14,25 @@ class TestCrosECRTC(unittest.TestCase): """ Check the cros RTC ABI. """ if not is_feature_supported(EC_FEATURE_RTC): self.skipTest("EC_FEATURE_RTC not supported, skipping") + + files = [ + "date", + "hctosys", + "max_user_freq", + "since_epoch", + "time", + "wakealarm", + ] + match = 0 - try: - basepath = "/sys/class/rtc" - for devname in os.listdir(basepath): - dev_basepath = os.path.join(basepath, devname) - with open(os.path.join(dev_basepath, "name")) as fh: - devtype = fh.read() - if devtype.startswith("cros-ec-rtc"): - files = [ - "date", - "hctosys", - "max_user_freq", - "since_epoch", - "time", - "wakealarm", - ] - match += 1 - for filename in files: - p = os.path.join(dev_basepath, filename) - self.assertTrue(os.path.exists(p), msg=f"{p} not found") - except IOError as e: - self.skipTest(f"{e}") + for dev in glob.glob("/sys/class/rtc/*"): + with open(os.path.join(dev, "name")) as fh: + devtype = fh.read() + if not devtype.startswith("cros-ec-rtc"): + continue + + match += 1 + for filename in files: + p = os.path.join(dev, filename) + self.assertTrue(os.path.exists(p), msg=f"{p} not found") self.assertNotEqual(match, 0, msg="No RTC device found") |