diff options
author | Vic Yang <victoryang@chromium.org> | 2013-09-29 00:55:36 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-10-01 08:16:34 +0000 |
commit | c77575ac0daa5966772779cedbaab6f607cf9a98 (patch) | |
tree | f1e7cf3ca7f232e4be95b7bd57e652253eddaacc /test/power_button.c | |
parent | 2d856c51039153effe4b9e9d7924c841fb741da5 (diff) | |
download | chrome-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/power_button.c')
-rw-r--r-- | test/power_button.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/test/power_button.c b/test/power_button.c index 5f7231b9f4..1205cfcca4 100644 --- a/test/power_button.c +++ b/test/power_button.c @@ -7,6 +7,7 @@ #include "common.h" #include "console.h" +#include "gpio.h" #include "hooks.h" #include "host_command.h" #include "power_button.h" @@ -14,20 +15,11 @@ #include "timer.h" #include "util.h" -static int mock_power_button = 1; -static int mock_lid = 1; static int pb_hook_count; -int gpio_get_level(enum gpio_signal signal) -{ - if (signal == GPIO_POWER_BUTTON_L) - return mock_power_button; - return 0; -} - int lid_is_open(void) { - return mock_lid; + return 1; } static void pb_change_hook(void) @@ -45,14 +37,12 @@ int pb_memmap_state(void) static int test_hook(void) { /* Release power button for testing */ - mock_power_button = 1; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 1); msleep(100); pb_hook_count = 0; host_clear_events(0xffffffff); - mock_power_button = 0; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 0); msleep(50); TEST_ASSERT(pb_hook_count == 1); TEST_ASSERT(power_button_is_pressed()); @@ -61,8 +51,7 @@ static int test_hook(void) EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)); host_clear_events(0xffffffff); - mock_power_button = 1; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 1); msleep(50); TEST_ASSERT(pb_hook_count == 2); TEST_ASSERT(!power_button_is_pressed()); @@ -76,14 +65,12 @@ static int test_hook(void) static int test_debounce(void) { /* Release power button for testing */ - mock_power_button = 1; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 1); msleep(100); pb_hook_count = 0; host_clear_events(0xffffffff); - mock_power_button = 0; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 0); msleep(20); TEST_ASSERT(pb_hook_count == 0); TEST_ASSERT(!power_button_is_pressed()); @@ -91,8 +78,7 @@ static int test_debounce(void) TEST_ASSERT(!(host_get_events() & EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON))); - mock_power_button = 1; - power_button_interrupt(GPIO_POWER_BUTTON_L); + gpio_set_level(GPIO_POWER_BUTTON_L, 1); msleep(50); TEST_ASSERT(pb_hook_count == 0); TEST_ASSERT(!power_button_is_pressed()); |