From b7c7c258402bc3b6f93d29b5791018958c8a1fbd Mon Sep 17 00:00:00 2001 From: Air9 Date: Fri, 29 May 2020 14:17:49 +0800 Subject: [PATCH 1/4] fix bug of failing to get CPU nums with LANG=zh_CN.UTF8 --- tests/cpufreq/cpufreq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpufreq/cpufreq.py b/tests/cpufreq/cpufreq.py index 923efd1..a87d57e 100755 --- a/tests/cpufreq/cpufreq.py +++ b/tests/cpufreq/cpufreq.py @@ -35,7 +35,7 @@ class CPU: def get_info(self): cmd = Command("lscpu") try: - nums = cmd.get_str('CPU\(s\):\s+(?P\d+)', 'cpus', False) + nums = cmd.get_str('^CPU\S*:\s+(?P\d+)$', 'cpus', False) except: return False self.nums = int(nums) -- Gitee From 0478baa1c1707a08e856ff4f9289db519cc6240a Mon Sep 17 00:00:00 2001 From: zhangwenhao Date: Fri, 29 May 2020 14:35:02 +0800 Subject: [PATCH 2/4] add r prefix for RE pattern --- tests/cpufreq/cpufreq.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100755 => 100644 tests/cpufreq/cpufreq.py diff --git a/tests/cpufreq/cpufreq.py b/tests/cpufreq/cpufreq.py old mode 100755 new mode 100644 index a87d57e..ad60cbd --- a/tests/cpufreq/cpufreq.py +++ b/tests/cpufreq/cpufreq.py @@ -35,7 +35,7 @@ class CPU: def get_info(self): cmd = Command("lscpu") try: - nums = cmd.get_str('^CPU\S*:\s+(?P\d+)$', 'cpus', False) + nums = cmd.get_str(r'^CPU\S*:\s+(?P\d+)$', 'cpus', False) except: return False self.nums = int(nums) @@ -68,7 +68,7 @@ class CPU: def get_freq(self, cpu): cmd = Command("cpupower -c %s frequency-info -w" % cpu) try: - return int(cmd.get_str('.* frequency: (?P\d+) .*', 'freq', False)) + return int(cmd.get_str(r'.* frequency: (?P\d+) .*', 'freq', False)) except: return False @@ -83,7 +83,7 @@ class CPU: def get_governor(self, cpu): cmd = Command("cpupower -c %s frequency-info -p" % cpu) try: - return cmd.get_str('.* governor "(?P\w+)".*', 'governor', False) + return cmd.get_str(r'.* governor "(?P\w+)".*', 'governor', False) except: return False -- Gitee From a9da62e70ced9667257f78e22e71da43f8fc990b Mon Sep 17 00:00:00 2001 From: zhangwenhao Date: Fri, 29 May 2020 15:11:00 +0800 Subject: [PATCH 3/4] fix codesmell --- tests/cpufreq/cpufreq.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/cpufreq/cpufreq.py b/tests/cpufreq/cpufreq.py index ad60cbd..bf6f690 100644 --- a/tests/cpufreq/cpufreq.py +++ b/tests/cpufreq/cpufreq.py @@ -17,12 +17,11 @@ from time import sleep from hwcert.env import CertEnv from hwcert.test import Test -from hwcert.command import Command +from hwcert.command import Command, CertCommandError class CPU: def __init__(self): - self.requirements = ['util-linux', 'kernel-tools'] self.cpu = None self.nums = None self.list = None @@ -36,7 +35,8 @@ class CPU: cmd = Command("lscpu") try: nums = cmd.get_str(r'^CPU\S*:\s+(?P\d+)$', 'cpus', False) - except: + except CertCommandError as e: + print(e) return False self.nums = int(nums) self.list = range(self.nums) @@ -44,14 +44,16 @@ class CPU: cmd = Command("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq") try: max_freq = cmd.get_str() - except: + except CertCommandError as e: + print(e) return False self.max_freq = int(max_freq) cmd = Command("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq") try: min_freq = cmd.get_str() - except: + except CertCommandError as e: + print(e) return False self.min_freq = int(min_freq) @@ -62,14 +64,16 @@ class CPU: try: cmd.run() return cmd.returncode - except: + except CertCommandError as e: + print(e) return False def get_freq(self, cpu): cmd = Command("cpupower -c %s frequency-info -w" % cpu) try: return int(cmd.get_str(r'.* frequency: (?P\d+) .*', 'freq', False)) - except: + except CertCommandError as e: + print(e) return False def set_governor(self, governor, cpu='all'): @@ -77,14 +81,16 @@ class CPU: try: cmd.run() return cmd.returncode - except: + except CertCommandError as e: + print(e) return False def get_governor(self, cpu): cmd = Command("cpupower -c %s frequency-info -p" % cpu) try: return cmd.get_str(r'.* governor "(?P\w+)".*', 'governor', False) - except: + except CertCommandError as e: + print(e) return False def find_path(self, parent_dir, target_name): @@ -92,7 +98,8 @@ class CPU: try: cmd.run() return cmd.returncode - except: + except CertCommandError as e: + print(e) return False @@ -119,6 +126,12 @@ class Load: class CPUFreqTest(Test): + def __init__(self): + Test.__init__(self) + self.requirements = ['util-linux', 'kernel-tools'] + self.cpu = CPU() + self.original_governor = self.cpu.get_governor(0) + def test_userspace(self): target_cpu = randint(0, self.cpu.nums-1) target_freq = randint(self.cpu.min_freq, self.cpu.max_freq) @@ -335,9 +348,6 @@ class CPUFreqTest(Test): return True def test(self): - self.cpu = CPU() - self.original_governor = self.cpu.get_governor(0) - if not self.cpu.get_info(): print("[X] Fail to get CPU info." \ " Please check if the CPU supports cpufreq.") -- Gitee From 1f45220c542c0e2e231bbe4fc9359d0a7c0b1bfe Mon Sep 17 00:00:00 2001 From: Air9 Date: Thu, 4 Jun 2020 20:36:54 +0800 Subject: [PATCH 4/4] update hwcert to hwcompatible --- tests/cpufreq/cpufreq.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cpufreq/cpufreq.py b/tests/cpufreq/cpufreq.py index bf6f690..d950cfb 100644 --- a/tests/cpufreq/cpufreq.py +++ b/tests/cpufreq/cpufreq.py @@ -15,9 +15,9 @@ from random import randint from time import sleep -from hwcert.env import CertEnv -from hwcert.test import Test -from hwcert.command import Command, CertCommandError +from hwcompatible.env import CertEnv +from hwcompatible.test import Test +from hwcompatible.command import Command, CertCommandError class CPU: -- Gitee