Files
OpenCellular/test/extpwr_gpio.c
Vic Yang c77575ac0d 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>
2013-10-01 08:16:34 +00:00

62 lines
1.2 KiB
C

/* 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 ac_hook_count;
static void set_ac(int val)
{
gpio_set_level(GPIO_AC_PRESENT, val);
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();
}