summaryrefslogtreecommitdiff
path: root/test/lid_sw.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-29 00:55:36 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-01 08:16:34 +0000
commitc77575ac0daa5966772779cedbaab6f607cf9a98 (patch)
treef1e7cf3ca7f232e4be95b7bd57e652253eddaacc /test/lid_sw.c
parent2d856c51039153effe4b9e9d7924c841fb741da5 (diff)
downloadchrome-ec-c77575ac0daa5966772779cedbaab6f607cf9a98.tar.gz
Emulator support of fake GPIO input
For all GPIOs, the current values are recorded. A test can then change the value of a GPIO input by gpio_set_level(). The changed value is recorded and also interrupt is fired if the change fits the interrupt flags defined in board/host/board.c. BUG=chrome-os-partner:19235 TEST=Pass all tests BRANCH=None Change-Id: If8e547e5adf4a20dcb118f5fe2187293005d4ca3 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/170907 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test/lid_sw.c')
-rw-r--r--test/lid_sw.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/test/lid_sw.c b/test/lid_sw.c
index 52a4d033cb..dbd009990d 100644
--- a/test/lid_sw.c
+++ b/test/lid_sw.c
@@ -7,6 +7,7 @@
#include "common.h"
#include "console.h"
+#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "lid_switch.h"
@@ -14,16 +15,8 @@
#include "timer.h"
#include "util.h"
-static int mock_lid;
static int lid_hook_count;
-int gpio_get_level(enum gpio_signal signal)
-{
- if (signal == GPIO_LID_OPEN)
- return mock_lid;
- return 0;
-}
-
static void lid_change_hook(void)
{
lid_hook_count++;
@@ -39,14 +32,12 @@ int lid_memmap_state(void)
static int test_hook(void)
{
/* Close lid for testing */
- mock_lid = 0;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 0);
msleep(100);
lid_hook_count = 0;
host_clear_events(0xffffffff);
- mock_lid = 1;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 1);
msleep(50);
TEST_ASSERT(lid_hook_count == 1);
TEST_ASSERT(lid_is_open());
@@ -54,8 +45,7 @@ static int test_hook(void)
TEST_ASSERT(host_get_events() &
EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN));
- mock_lid = 0;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 0);
msleep(50);
TEST_ASSERT(lid_hook_count == 2);
TEST_ASSERT(!lid_is_open());
@@ -69,14 +59,12 @@ static int test_hook(void)
static int test_debounce(void)
{
/* Close lid for testing */
- mock_lid = 0;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 0);
msleep(100);
lid_hook_count = 0;
host_clear_events(0xffffffff);
- mock_lid = 1;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 1);
msleep(20);
TEST_ASSERT(lid_hook_count == 0);
TEST_ASSERT(!lid_is_open());
@@ -84,8 +72,7 @@ static int test_debounce(void)
TEST_ASSERT(!(host_get_events() &
EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)));
- mock_lid = 0;
- lid_interrupt(GPIO_LID_OPEN);
+ gpio_set_level(GPIO_LID_OPEN, 0);
msleep(50);
TEST_ASSERT(lid_hook_count == 0);
TEST_ASSERT(!lid_is_open());