Skip to contentSkip to conversation

oeqa/cpu_utilization_test : add test for cpu utilization after standby state

PATCH New Teoh, Jay Shen 1 participant 1 message Jan 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oeqa/cpu_utilization_test : add test for cpu utilization after standby state

From: Teoh Jay Shen <[email protected]>

This test is checking the cpu utilization before and after standby state. The check_CPU_utilization_after_standby manual test case from oeqa/manual/bsp-hw can be replace by this runtime test.

---
 .../lib/oeqa/runtime/cases/cpu_utilization_test.py | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 meta/lib/oeqa/runtime/cases/cpu_utilization_test.py
meta/lib/oeqa/runtime/cases/cpu_utilization_test.py new file +23 -0
new file mode 100644
index 0000000..a44b4ec
@@ -0,0 +1,23 @@
+from oeqa.runtime.case import OERuntimeTestCase
+from oeqa.core.decorator.depends import OETestDepends
+from oeqa.core.decorator.data import skipIfQemu
+
+
+class CPU_utilization_test(OERuntimeTestCase):
+      
+    def set_standby(self): 
+        (status, output) = self.target.run('rtcwake -m mem -s 10')
+        self.assertEqual(status, 0,  msg = 'Failed to set your system into standby mode, output : %s' % output)
+    
+    @skipIfQemu('qemuall', 'Test only runs on real hardware')
+    @OETestDepends(['ssh.SSHTest.test_ssh'])
+    def test_CPU_utilization_after_standby(self):
+        (status, cpu_usage_before_standby) = self.target.run("export TERM=xterm && top -b -n2 | grep 'Cpu(s)' | tail -n 1 | awk '{print $2 + $6}'")
+        self.assertEqual(status, 0,  msg = 'Failed to run the top command, output : %s' % cpu_usage_before_standby)
+        self.set_standby()
+        (status, cpu_usage_after_standby) = self.target.run("export TERM=xterm && top -b -n2 | grep 'Cpu(s)' | tail -n 1 | awk '{print $2 + $6}'")
+        self.assertEqual(status, 0,  msg = 'Failed to run the top command, output : %s' % cpu_usage_after_standby)
+        cpu_usage_before_standby = int(float(cpu_usage_before_standby))
+        cpu_usage_after_standby = int(float(cpu_usage_after_standby))
+        cpu_usage_comparison = ((cpu_usage_before_standby - 5) <= cpu_usage_after_standby <= (cpu_usage_before_standby + 5))
+        self.assertTrue(cpu_usage_comparison, msg='There should be no big difference in the cpu utilization before/after standby, cpu usage before standby : % s, cpu usage after standby : % s' % (cpu_usage_before_standby , cpu_usage_after_standby))
Signature · 1 line
2.7.4