summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-07-01 20:48:48 +0800
committerGerrit <chrome-bot@google.com>2012-07-02 20:36:57 -0700
commited9d6282d46d8216ae6f81477171324fcbdc94aa (patch)
tree1b82197c912cb2577564dc6f170f24d3347701bc
parentf44db828733e942efeb61305e24231b88ac500b4 (diff)
downloadchrome-ec-ed9d6282d46d8216ae6f81477171324fcbdc94aa.tar.gz
Add a function to check no specific message comes from EC
This function has been defined and used in several tests. Let's consolidate them into the helper class. BUG=none TEST=The four tests passed Change-Id: I069bec84e0f2ce12ef9e8b7fe610f54bb58af0de Reviewed-on: https://gerrit.chromium.org/gerrit/26534 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Ready: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
-rw-r--r--test/kb_debounce.py14
-rw-r--r--test/kb_deghost.py12
-rw-r--r--test/power_button.py28
-rw-r--r--test/typematic.py12
-rwxr-xr-xutil/run_qemu_test9
5 files changed, 26 insertions, 49 deletions
diff --git a/test/kb_debounce.py b/test/kb_debounce.py
index 4ca8b616c3..e7801a30fc 100644
--- a/test/kb_debounce.py
+++ b/test/kb_debounce.py
@@ -11,14 +11,6 @@ SHORTER_THAN_DEBOUNCE_TIME = 0.005 # 5ms
LONGER_THAN_DEBOUNCE_TIME = 0.020 # 20ms
KEYPRESS_REGEX = "\[KB raw state: (?P<km>[0-9\s-]*)\]"
-def check_no_output(helper, reg_ex):
- success = False
- try:
- helper.wait_output(reg_ex, use_re=True, timeout=1)
- except:
- success = True
- return success
-
def consume_output(helper, reg_ex):
done = False
while not done:
@@ -55,7 +47,7 @@ def test(helper):
helper.ec_command("mockmatrix 1 1 1")
time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
helper.ec_command("mockmatrix 1 1 0")
- if not check_no_output(helper, KEYPRESS_REGEX):
+ if not helper.check_no_output(KEYPRESS_REGEX, use_re=True):
return False
# Press for a longer period and check keypress is accepted
@@ -82,7 +74,7 @@ def test(helper):
return False
if not expect_key_count(helper, 0): # Release
return False
- if not check_no_output(helper, KEYPRESS_REGEX):
+ if not helper.check_no_output(KEYPRESS_REGEX, use_re=True):
return False
# Hold down a key and press another key for a short period. Expect
@@ -94,7 +86,7 @@ def test(helper):
helper.ec_command("mockmatrix 2 2 1")
time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
helper.ec_command("mockmatrix 2 2 0")
- if not check_no_output(helper, KEYPRESS_REGEX):
+ if not helper.check_no_output(KEYPRESS_REGEX, use_re=True):
return False
helper.ec_command("mockmatrix 1 1 0")
if not expect_key_count(helper, 0):
diff --git a/test/kb_deghost.py b/test/kb_deghost.py
index c9241e063e..b7ad9973c7 100644
--- a/test/kb_deghost.py
+++ b/test/kb_deghost.py
@@ -7,14 +7,6 @@
import time
-def check_no_output(helper, reg_ex):
- success = False
- try:
- helper.wait_output(reg_ex, use_re=True, timeout=1)
- except:
- success = True
- return success
-
def test(helper):
# Wait for EC initialized
helper.wait_output("--- UART initialized")
@@ -33,13 +25,13 @@ def test(helper):
# Expect this is ignored
helper.ec_command("mockmatrix 2 1 1")
helper.ec_command("mockmatrix 1 2 1")
- if not check_no_output(helper, "KB raw"):
+ if not helper.check_no_output("KB raw"):
return False
# Now release (1, 2) which should cause (2, 1) to be released also
# Expect this is ignored
helper.ec_command("mockmatrix 2 1 0")
helper.ec_command("mockmatrix 1 2 0")
- if not check_no_output(helper, "KB raw"):
+ if not helper.check_no_output("KB raw"):
return False
# Done testing with (1, 1) and (2, 2). Release them.
diff --git a/test/power_button.py b/test/power_button.py
index 7f5c3b9fb0..0f5766ca96 100644
--- a/test/power_button.py
+++ b/test/power_button.py
@@ -15,14 +15,6 @@ SHORTER_THAN_T0 = 0.01
LONGER_THAN_T0 = 0.05
LONGER_THAN_T1 = 5
-def check_no_output(helper, reg_ex):
- success = False
- try:
- helper.wait_output(reg_ex, use_re=True, timeout=1)
- except:
- success = True
- return success
-
def consume_output(helper, reg_ex):
done = False
while not done:
@@ -44,7 +36,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 0")
time.sleep(SHORTER_THAN_T0)
helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not check_no_output(helper, "PB released"):
+ if not helper.check_no_output("PB released"):
return False
helper.trace("Press power button for longer than T0 and check this\n" +
@@ -54,7 +46,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 1")
helper.wait_output("PB released", timeout=1)
# Expect shown only once
- if not check_no_output(helper, "PB released"):
+ if not helper.check_no_output("PB released"):
return False
helper.trace("Press power button for two consecutive SHORTER_THAN_T0\n" +
@@ -66,7 +58,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 0")
time.sleep(SHORTER_THAN_T0)
helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not check_no_output(helper, "PB released"):
+ if not helper.check_no_output("PB released"):
return False
helper.trace("Hold down power button for LONGER_THAN_T0 and check a\n" +
@@ -77,7 +69,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 1")
helper.wait_output("pwrbtn=LOW", timeout=1)
helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not check_no_output(helper, "pwrbtn=LOW"):
+ if not helper.check_no_output("pwrbtn=LOW"):
return False
helper.trace("Press power button for SHORTER_THAN_T0, release for\n" +
@@ -92,7 +84,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 1")
helper.wait_output("pwrbtn=LOW", timeout=1)
helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not check_no_output(helper, "pwrbtn=LOW"):
+ if not helper.check_no_output("pwrbtn=LOW"):
return False
helper.trace("Hold down power button, wait for power button press\n" +
@@ -104,7 +96,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 1")
time.sleep(SHORTER_THAN_T0)
helper.ec_command("gpiomock POWER_BUTTONn 0")
- if not check_no_output(helper, "PB released"):
+ if not helper.check_no_output("PB released"):
return False
helper.ec_command("gpiomock POWER_BUTTONn 1")
helper.wait_output("PB released", timeout=1)
@@ -119,7 +111,7 @@ def test(helper):
use_re=True)["t"]
t_high = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=HIGH\]",
use_re=True)["t"]
- if not check_no_output(helper, "pwrbtn=LOW"):
+ if not helper.check_no_output("pwrbtn=LOW"):
return False
if float(t_high) - float(t_low) <= LONGER_THAN_T0 - 0.1:
return False
@@ -130,7 +122,7 @@ def test(helper):
helper.ec_command("gpiomock POWER_BUTTONn 0")
time.sleep(LONGER_THAN_T0)
helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not check_no_output(helper, "i8042 SEND"):
+ if not helper.check_no_output("i8042 SEND"):
return False
helper.trace("While powered on, hold down power button for\n" +
@@ -144,7 +136,7 @@ def test(helper):
use_re=True)["t"]
t_high = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=HIGH\]",
use_re=True)["t"]
- if not check_no_output(helper, "pwrbtn=LOW"):
+ if not helper.check_no_output("pwrbtn=LOW"):
return False
if float(t_high) - float(t_low) >= 0.1:
return False
@@ -168,7 +160,7 @@ def test(helper):
helper.wait_output("pwrbtn=HIGH", timeout=1)
helper.wait_output("pwrbtn=LOW", timeout=1)
helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not check_no_output(helper, "pwrbtn=LOW"):
+ if not helper.check_no_output("pwrbtn=LOW"):
return False
return True # PASS !
diff --git a/test/typematic.py b/test/typematic.py
index 6943f43628..f61f0ccd86 100644
--- a/test/typematic.py
+++ b/test/typematic.py
@@ -9,21 +9,13 @@ import time
KEY_PRESS_MSG = "i8042 SEND"
-def check_no_output(helper, reg_ex):
- success = False
- try:
- helper.wait_output(reg_ex, use_re=True, timeout=1)
- except:
- success = True
- return success
-
def expect_keypress(helper, lower_bound, upper_bound):
for i in xrange(lower_bound + 1): # Plus 1 break code
helper.wait_output(KEY_PRESS_MSG)
for i in xrange(upper_bound - lower_bound):
- if check_no_output(helper, KEY_PRESS_MSG):
+ if helper.check_no_output(KEY_PRESS_MSG):
return True
- if not check_no_output(helper, KEY_PRESS_MSG):
+ if not helper.check_no_output(KEY_PRESS_MSG):
return False
return True
diff --git a/util/run_qemu_test b/util/run_qemu_test
index ffc82215d2..00af61e7e2 100755
--- a/util/run_qemu_test
+++ b/util/run_qemu_test
@@ -167,6 +167,15 @@ class EcTest:
signal.signal(signal.SIGALRM, old_handler)
return
+ def check_no_output(self, string, use_re = False, timeout = 1):
+ success = False
+ try:
+ self.wait_output(string, use_re=use_re, timeout=timeout)
+ except:
+ success = True
+ return success
+
+
def wait_prompt(self):
self.wait_output("> ")