Files
OpenCellular/test/extpwr_gpio.c
Vic Yang 7864372297 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>
2013-07-11 22:32:52 -07:00

73 lines
1.4 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 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();
}