mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
72
test/extpwr_gpio.c
Normal file
72
test/extpwr_gpio.c
Normal file
@@ -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();
|
||||
}
|
||||
17
test/extpwr_gpio.tasklist
Normal file
17
test/extpwr_gpio.tasklist
Normal file
@@ -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 */
|
||||
Reference in New Issue
Block a user