diff options
author | Vic Yang <victoryang@chromium.org> | 2013-07-11 16:06:18 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-11 22:32:52 -0700 |
commit | 786437229728ffeeda19d533941d813f74ba9441 (patch) | |
tree | 0e16373408829ea410467a87fd04628fb12c14d3 | |
parent | 2475cce9ad0e505a45562189e5427683d4ebd65c (diff) | |
download | chrome-ec-786437229728ffeeda19d533941d813f74ba9441.tar.gz |
Add extpower-gpio unit test
This tests host event and hook are triggered when AC status changes.
BUG=chrome-os-partner:19236
TEST=Pass the test.
BRANCH=None
Change-Id: I9e4263f3f6e273bfb0b24671a4e5c56b20a04e1a
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/61554
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | board/host/board.c | 13 | ||||
-rw-r--r-- | board/host/board.h | 2 | ||||
-rw-r--r-- | test/build.mk | 3 | ||||
-rw-r--r-- | test/extpwr_gpio.c | 72 | ||||
-rw-r--r-- | test/extpwr_gpio.tasklist | 17 |
5 files changed, 101 insertions, 6 deletions
diff --git a/board/host/board.c b/board/host/board.c index bb3f3a1821..609d29bb84 100644 --- a/board/host/board.c +++ b/board/host/board.c @@ -8,12 +8,15 @@ #include "gpio.h" #include "temp_sensor.h" +#define MOCK_GPIO(x) {#x, 0, 0, 0, 0} + const struct gpio_info gpio_list[GPIO_COUNT] = { - {"EC_INT", 0, 0, 0, 0}, - {"LID_OPEN", 0, 0, 0, 0}, - {"POWER_BUTTON_L", 0, 0, 0, 0}, - {"WP", 0, 0, 0, 0}, - {"ENTERING_RW", 0, 0, 0, 0}, + MOCK_GPIO(EC_INT), + MOCK_GPIO(LID_OPEN), + MOCK_GPIO(POWER_BUTTON_L), + MOCK_GPIO(WP), + MOCK_GPIO(ENTERING_RW), + MOCK_GPIO(AC_PRESENT), }; static int dummy_temp_get_val(int idx, int *temp_ptr) diff --git a/board/host/board.h b/board/host/board.h index 9d4d3257a8..7ef70bd3a7 100644 --- a/board/host/board.h +++ b/board/host/board.h @@ -13,6 +13,7 @@ #define CONFIG_ASSERT_HELP /* Optional features */ +#define CONFIG_EXTPOWER_GPIO #define CONFIG_HOSTCMD #define CONFIG_HOST_EMU #define CONFIG_LID_SWITCH @@ -34,6 +35,7 @@ enum gpio_signal { GPIO_POWER_BUTTON_L, GPIO_WP, GPIO_ENTERING_RW, + GPIO_AC_PRESENT, GPIO_COUNT }; diff --git a/test/build.mk b/test/build.mk index ed2e437c5b..5145c54e73 100644 --- a/test/build.mk +++ b/test/build.mk @@ -29,8 +29,9 @@ test-list-$(BOARD_wolf)= # Emulator tests test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw power_button hooks -test-list-host+=thermal flash queue kb_8042 +test-list-host+=thermal flash queue kb_8042 extpwr_gpio +extpwr_gpio-y=extpwr_gpio.o flash-y=flash.o hooks-y=hooks.o kb_8042-y=kb_8042.o diff --git a/test/extpwr_gpio.c b/test/extpwr_gpio.c new file mode 100644 index 0000000000..c10dad6627 --- /dev/null +++ b/test/extpwr_gpio.c @@ -0,0 +1,72 @@ +/* Copyright (c) 2013 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. + * + * Test GPIO extpower module. + */ + +#include "common.h" +#include "console.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "host_command.h" +#include "test_util.h" +#include "timer.h" +#include "util.h" + +static int mock_ac; +static int ac_hook_count; + +int gpio_get_level(enum gpio_signal signal) +{ + if (signal == GPIO_AC_PRESENT) + return mock_ac; + return 0; +} + +static void set_ac(int val) +{ + if (val == mock_ac) + return; + mock_ac = val; + extpower_interrupt(GPIO_AC_PRESENT); + msleep(50); +} + +static void ac_change_hook(void) +{ + ac_hook_count++; +} +DECLARE_HOOK(HOOK_AC_CHANGE, ac_change_hook, HOOK_PRIO_DEFAULT); + +static int test_hook(void) +{ + /* Remove AC for testing */ + set_ac(0); + ac_hook_count = 0; + host_clear_events(0xffffffff); + + set_ac(1); + TEST_ASSERT(ac_hook_count == 1); + TEST_ASSERT(extpower_is_present()); + TEST_ASSERT(host_get_events() & + EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_CONNECTED)); + + set_ac(0); + TEST_ASSERT(ac_hook_count == 2); + TEST_ASSERT(!extpower_is_present()); + TEST_ASSERT(host_get_events() & + EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED)); + + return EC_SUCCESS; +} + +void run_test(void) +{ + test_reset(); + + RUN_TEST(test_hook); + + test_print_result(); +} diff --git a/test/extpwr_gpio.tasklist b/test/extpwr_gpio.tasklist new file mode 100644 index 0000000000..26cfc53453 --- /dev/null +++ b/test/extpwr_gpio.tasklist @@ -0,0 +1,17 @@ +/* Copyright (c) 2013 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. + */ + +/** + * List of enabled tasks in the priority order + * + * The first one has the lowest priority. + * + * For each task, use the macro TASK_TEST(n, r, d, s) where : + * 'n' in the name of the task + * 'r' in the main routine of the task + * 'd' in an opaque parameter passed to the routine at startup + * 's' is the stack size in bytes; must be a multiple of 8 + */ +#define CONFIG_TEST_TASK_LIST /* No test task */ |