summaryrefslogtreecommitdiff
path: root/util/test-inject-keys.sh
diff options
context:
space:
mode:
authorLuigi Semenzato <semenzato@chromium.org>2016-01-15 13:33:06 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-02-05 06:02:49 -0800
commit4ec554dd8fbdd47871dcd04374fb04018b24b7b5 (patch)
treea786237f2c8a04e1a64efee04e42d39c222b4264 /util/test-inject-keys.sh
parentc68e5a7c9bc0c1ae131303a41e51b6e13ca25e31 (diff)
downloadchrome-ec-4ec554dd8fbdd47871dcd04374fb04018b24b7b5.tar.gz
ectool: add inject-keys.py
A simple wrapper for "ectool kbpress" to do basic automation when working remotely (for instance, logging in). Includes a test script. BUG=b:26349756 TEST=ran on platform in various ways BRANCH=none Signed-off-by: Luigi Semenzato <semenzato@chromium.org> Change-Id: I96fdd99aa228b51cf22f9323facdc4ddb59db9ff Reviewed-on: https://chromium-review.googlesource.com/322286 Commit-Ready: Luigi Semenzato <semenzato@chromium.org> Tested-by: Luigi Semenzato <semenzato@chromium.org> Reviewed-by: Luigi Semenzato <semenzato@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util/test-inject-keys.sh')
-rwxr-xr-xutil/test-inject-keys.sh111
1 files changed, 111 insertions, 0 deletions
diff --git a/util/test-inject-keys.sh b/util/test-inject-keys.sh
new file mode 100755
index 0000000000..031452150e
--- /dev/null
+++ b/util/test-inject-keys.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+#
+# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Regression test for inject-keys.py. Works by creating a "fake" ectool
+# and comparing expected ectool commands with expected ones.
+
+TMPX=/tmp/inject-key-test$$_x
+TMPY=/tmp/inject-key-test$$_y
+
+cleanup() {
+ rm -f ./ectool $TMPX $TMPY
+}
+
+fail() {
+ echo $*
+ exit 1
+}
+
+trap cleanup SIGINT
+
+PATH=.:$PATH
+
+if [ -e ectool ]; then
+ if [ "$(echo $(cat ectool))" != '#! /bin/bash echo $*' ]; then
+ echo "./ectool exists, please remove it to run this script"
+ exit 1
+ fi
+fi
+
+echo "#! /bin/bash" > ectool
+echo 'echo $*' >> ectool
+chmod a+x ectool
+
+# tests that should fail
+
+# bad args
+./inject-keys.py >& /dev/null && fail "undetected zero args"
+./inject-keys.py -k >& /dev/null && fail "undetected mismatched args (1)"
+./inject-keys.py -k a b >& /dev/null && fail "undetected mismatched args (2)"
+./inject-keys.py -z a >& /dev/null && fail "undetected bad flag"
+
+# bad key
+./inject-keys.py -p foobar >& /dev/null && fail "undetected bad key"
+
+# tests that should succeed with the expected output
+
+# simple string
+./inject-keys.py -s abcd > $TMPX
+
+cat > $TMPY <<EOF
+kbpress 4 1 1
+kbpress 4 1 0
+kbpress 0 3 1
+kbpress 0 3 0
+kbpress 5 2 1
+kbpress 5 2 0
+kbpress 4 2 1
+kbpress 4 2 0
+EOF
+
+cmp $TMPX $TMPY || fail $TMPX and $TMPY differ
+
+# string with shifted characters
+./inject-keys.py -s A@%Bx > $TMPX
+
+cat > $TMPY <<EOF
+kbpress 5 7 1
+kbpress 4 1 1
+kbpress 4 1 0
+kbpress 5 7 0
+kbpress 5 7 1
+kbpress 6 4 1
+kbpress 6 4 0
+kbpress 5 7 0
+kbpress 5 7 1
+kbpress 3 3 1
+kbpress 3 3 0
+kbpress 5 7 0
+kbpress 5 7 1
+kbpress 0 3 1
+kbpress 0 3 0
+kbpress 5 7 0
+kbpress 5 4 1
+kbpress 5 4 0
+EOF
+
+cmp $TMPX $TMPY || fail $TMPX and $TMPY differ
+
+# keystroke injection
+./inject-keys.py -k enter > $TMPX
+
+cat > $TMPY <<EOF
+kbpress 4 11 1
+kbpress 4 11 0
+EOF
+
+cmp $TMPX $TMPY || fail $TMPX and $TMPY differ
+
+# key event injection
+./inject-keys.py -p enter > $TMPX
+
+cat > $TMPY <<EOF
+kbpress 4 11 1
+EOF
+
+cmp $TMPX $TMPY || fail $TMPX and $TMPY differ
+
+cleanup