summaryrefslogtreecommitdiff
path: root/cros_ec/test/ec_keyboard_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'cros_ec/test/ec_keyboard_test.c')
-rw-r--r--cros_ec/test/ec_keyboard_test.c54
1 files changed, 48 insertions, 6 deletions
diff --git a/cros_ec/test/ec_keyboard_test.c b/cros_ec/test/ec_keyboard_test.c
index bcdb83cc6d..a425c0781a 100644
--- a/cros_ec/test/ec_keyboard_test.c
+++ b/cros_ec/test/ec_keyboard_test.c
@@ -5,21 +5,63 @@
* Testing code. Running at Linux environment.
*/
#include "cros_ec/include/ec_common.h"
+#include "chip_interface/ec_uart.h"
#include "cros_ec/include/core.h"
-#include "cros_ec/chip_stub/keyboard.h"
+#include "cros_ec/chip_stub/include/host.h"
+#include "cros_ec/chip_stub/include/keyboard.h"
+#define RUN_TEST(func) do { \
+ int ret; \
+ ret = func(); \
+ if (ret != EC_SUCCESS) { \
+ EcUartPrintf("Test %s() failed, retval = %d\n", #func, ret); \
+ return ret; \
+ } \
+ } while (0)
-int run_test_cases() {
- /* Just a simple test */
+
+EcError testKeyMade() {
+ uint8_t buf;
+
+ SimulateKeyStateChange(2, 3, 1);
+ EC_ASSERT(EC_SUCCESS == PullI8042ScanCode(&buf));
+ EC_ASSERT(buf == 2 * 13 + 3);
+
+ /* The duplicate press event will be ignored. */
SimulateKeyStateChange(2, 3, 1);
- /* Expect KeyboardStateChanged() in cros_ec/keyboard.c shows something. */
+ EC_ASSERT(EC_ERROR_BUFFER_EMPTY == PullI8042ScanCode(&buf));
- return 0;
+ return EC_SUCCESS;
}
+EcError testKeyReleased() {
+ uint8_t buf;
-int main(int argc, char **argv) {
+ /* The key is not pressed yet. A release event doesn't send out a code. */
+ SimulateKeyStateChange(7, 12, 0);
+ EC_ASSERT(EC_ERROR_BUFFER_EMPTY == PullI8042ScanCode(&buf));
+
+ /* Press and release it. Expect a release code. */
+ SimulateKeyStateChange(7, 12, 1);
+ SimulateKeyStateChange(7, 12, 0);
+ EC_ASSERT(EC_SUCCESS == PullI8042ScanCode(&buf));
+ EC_ASSERT(buf == 7 * 13 + 12);
+ EC_ASSERT(EC_SUCCESS == PullI8042ScanCode(&buf));
+ EC_ASSERT(buf == 7 * 13 + 12 + 0x80);
+
+ return EC_SUCCESS;
+}
+
+
+int run_test_cases() {
+ RUN_TEST(testKeyMade);
+ RUN_TEST(testKeyReleased);
+ return EC_SUCCESS;
+}
+
+
+int main(int argc, char **argv) {
EcError ret;
/* Call Google EC core initial code. */